正在查看: bbinstant v6.24.0 应用的 Kapchatdownloadservice.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: bbinstant v6.24.0 应用的 Kapchatdownloadservice.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.adjetter.kapchatsdk.service;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.ThumbnailUtils;
import android.os.AsyncTask;
import android.os.Binder;
import android.os.Environment;
import android.os.IBinder;
import android.webkit.MimeTypeMap;
import com.adjetter.kapchatsdk.KapchatMessageList;
import com.adjetter.kapchatsdk.animation.TransparentProgressDialog;
import com.adjetter.kapchatsdk.helper.KapchatReadAllMesages;
import com.adjetter.kapchatsdk.helper.KapchatUpdateConversationId;
import com.adjetter.kapchatsdk.helper.Kapchatdownloadfile;
import com.adjetter.kapchatsdk.helper.Kapchatdownloadupdate;
import com.adjetter.kapchatsdk.interfaces.IUpdatenotify;
import com.adjetter.kapchatsdk.interfaces.IkapchatMessages;
import com.amazonaws.mobileconnectors.remoteconfiguration.Attributes;
import com.amazonaws.services.s3.model.InstructionFileId;
import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Calendar;
public class Kapchatdownloadservice extends Service implements IkapchatMessages, IUpdatenotify {
public String conversationid;
IUpdatenotify notify;
private final IBinder mbinder = new DownloadGroupbinder();
ArrayList<KapchatMessageList> downloadlist = new ArrayList<>();
IkapchatMessages ikapchatMessages = null;
public class ClicktoDownload extends AsyncTask<Kapchatdownloadfile, String, Kapchatdownloadfile> {
Context context;
TransparentProgressDialog dialog;
public ClicktoDownload(Context context) {
this.context = context;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
this.dialog = new TransparentProgressDialog(this.context);
}
@Override
public Kapchatdownloadfile doInBackground(Kapchatdownloadfile... kapchatdownloadfileArr) {
StringBuilder sb = new StringBuilder();
sb.append("download url ");
sb.append(kapchatdownloadfileArr[0].url);
sb.append(" file name ");
sb.append(kapchatdownloadfileArr[0].filename);
sb.append(" extension ");
sb.append(kapchatdownloadfileArr[0].extension);
try {
Kapchatdownloadservice kapchatdownloadservice = Kapchatdownloadservice.this;
Kapchatdownloadfile kapchatdownloadfile = kapchatdownloadfileArr[0];
if (kapchatdownloadservice.downloadImagesToSdCard(kapchatdownloadfile.url, kapchatdownloadfile.filename, kapchatdownloadfile.extension)) {
return kapchatdownloadfileArr[0];
}
Kapchatdownloadfile kapchatdownloadfile2 = new Kapchatdownloadfile();
kapchatdownloadfile2.setConversationid(Kapchatdownloadservice.this.conversationid);
kapchatdownloadfile2.setExtension(kapchatdownloadfileArr[0].conversationid);
kapchatdownloadfile2.setFilename(kapchatdownloadfileArr[0].filename);
kapchatdownloadfile2.setUrl(kapchatdownloadfileArr[0].url);
kapchatdownloadfile2.setMimeurl(kapchatdownloadfileArr[0].mimeurl);
kapchatdownloadfile2.setSucces(Boolean.FALSE);
return kapchatdownloadfile2;
} catch (Exception e) {
e.printStackTrace();
Kapchatdownloadfile kapchatdownloadfile3 = new Kapchatdownloadfile();
kapchatdownloadfile3.setConversationid(Kapchatdownloadservice.this.conversationid);
kapchatdownloadfile3.setExtension(kapchatdownloadfileArr[0].conversationid);
kapchatdownloadfile3.setFilename(kapchatdownloadfileArr[0].filename);
kapchatdownloadfile3.setUrl(kapchatdownloadfileArr[0].url);
kapchatdownloadfile3.setMimeurl(kapchatdownloadfileArr[0].mimeurl);
kapchatdownloadfile3.setSucces(Boolean.FALSE);
return kapchatdownloadfile3;
}
}
@Override
public void onPostExecute(Kapchatdownloadfile kapchatdownloadfile) {
super.onPostExecute((ClicktoDownload) kapchatdownloadfile);
if (this.dialog.isShowing()) {
this.dialog.dismiss();
}
if (kapchatdownloadfile == null || !kapchatdownloadfile.succes.booleanValue()) {
ArrayList arrayList = new ArrayList();
KapchatMessageList kapchatMessageList = new KapchatMessageList();
kapchatMessageList.setConversationId(kapchatdownloadfile.getConversationid());
kapchatMessageList.setMessageStatus("9");
kapchatMessageList.setMimeurl(kapchatdownloadfile.getMimeurl());
arrayList.add(kapchatMessageList);
new KapchatUpdateConversationId(this.context, null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList);
return;
}
ArrayList arrayList2 = new ArrayList();
KapchatMessageList kapchatMessageList2 = new KapchatMessageList();
kapchatMessageList2.conversationId = kapchatdownloadfile.getConversationid();
kapchatMessageList2.download = "Yes";
kapchatMessageList2.downloadPath = "/KapchatImages/kapchatimage_" + kapchatdownloadfile.getFilename() + InstructionFileId.DOT + kapchatdownloadfile.getExtension();
File file = new File("" + Environment.getExternalStorageDirectory() + "/KapchatImages/kapchatimage_" + kapchatdownloadfile.getFilename() + InstructionFileId.DOT + kapchatdownloadfile.getExtension());
try {
if (Kapchatdownloadservice.getMimeType("/KapchatImages/kapchatimage_" + kapchatdownloadfile.getFilename() + InstructionFileId.DOT + kapchatdownloadfile.getExtension()).split("/")[0].equalsIgnoreCase("image") && file.exists()) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
Bitmap extractThumbnail = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(file.getPath(), options), 500, 500);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
extractThumbnail.compress(Bitmap.CompressFormat.JPEG, 20, byteArrayOutputStream);
kapchatMessageList2.setBlob(byteArrayOutputStream.toByteArray());
} else {
kapchatMessageList2.setBlob(new byte[]{0});
}
} catch (Exception e) {
kapchatMessageList2.download = "0";
kapchatMessageList2.downloadPath = "0";
e.printStackTrace();
} catch (OutOfMemoryError e2) {
kapchatMessageList2.download = "0";
kapchatMessageList2.downloadPath = "0";
e2.printStackTrace();
}
kapchatMessageList2.setMessageStatus("1");
kapchatMessageList2.setMimeurl(kapchatdownloadfile.getUrl());
arrayList2.add(kapchatMessageList2);
new Kapchatdownloadupdate(this.context).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, arrayList2);
}
@Override
public void onProgressUpdate(String... strArr) {
super.onProgressUpdate((Object[]) strArr);
StringBuilder sb = new StringBuilder();
sb.append("progress download value ");
sb.append(strArr);
}
}
public class DownloadGroupbinder extends Binder {
public DownloadGroupbinder() {
}
public Kapchatdownloadservice getService() {
return Kapchatdownloadservice.this;
}
}
public boolean downloadImagesToSdCard(String str, String str2, String str3) throws IOException {
if (str.contains("/ios-files-kapture/")) {
String[] split = str.split("/ios-files-kapture/");
if (split.length > 1) {
str = split[0] + "/ios-files-kapture/" + URLEncoder.encode(split[1]);
}
}
URL url = new URL(str);
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
httpURLConnection.connect();
try {
try {
int contentLength = httpURLConnection.getContentLength();
BufferedInputStream bufferedInputStream = new BufferedInputStream(url.openStream(), 8192);
File file = new File(Environment.getExternalStorageDirectory() + File.separator + "/KapchatImages");
StringBuilder sb = new StringBuilder();
sb.append("folder absolutepath ");
sb.append(file.getAbsolutePath());
if (!file.exists()) {
file.mkdir();
getApplicationContext().getDir("KapchatImages", 0).mkdir();
}
FileOutputStream fileOutputStream = new FileOutputStream(Environment.getExternalStorageDirectory().getPath() + "/KapchatImages/kapchatimage_" + str2 + InstructionFileId.DOT + str3);
byte[] bArr = new byte[1024];
long j2 = 0;
while (true) {
int read = bufferedInputStream.read(bArr);
if (read == -1) {
fileOutputStream.flush();
fileOutputStream.close();
bufferedInputStream.close();
httpURLConnection.disconnect();
return true;
}
j2 += read;
StringBuilder sb2 = new StringBuilder();
sb2.append("downloaded ");
sb2.append((int) ((100 * j2) / contentLength));
fileOutputStream.write(bArr, 0, read);
}
} catch (Exception e) {
e.printStackTrace();
httpURLConnection.disconnect();
return false;
}
} catch (Throwable th) {
httpURLConnection.disconnect();
throw th;
}
}
public static String getMimeType(String str) {
StringBuilder sb = new StringBuilder();
sb.append("url ");
sb.append(str);
String fileExtensionFromUrl = MimeTypeMap.getFileExtensionFromUrl(str.replace(" ", "%20"));
if (fileExtensionFromUrl != null) {
return MimeTypeMap.getSingleton().getMimeTypeFromExtension(fileExtensionFromUrl);
}
return null;
}
@Override
public void clearMessages(Boolean bool) {
}
@Override
public void clearMultiple(Boolean bool, ArrayList<String> arrayList) {
}
public void downloadata(String str) {
this.notify = this;
this.conversationid = str;
new KapchatReadAllMesages(getApplicationContext(), this.ikapchatMessages, 0).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, new Void[0]);
}
public void downloadimage() {
if (this.downloadlist.size() != 0) {
ArrayList<KapchatMessageList> arrayList = this.downloadlist;
if (arrayList.get(arrayList.size() - 1).getMime().equalsIgnoreCase("0")) {
return;
}
Kapchatdownloadfile kapchatdownloadfile = new Kapchatdownloadfile();
String str = "" + Calendar.getInstance().getTimeInMillis();
StringBuilder sb = new StringBuilder();
ArrayList<KapchatMessageList> arrayList2 = this.downloadlist;
sb.append(arrayList2.get(arrayList2.size() - 1).getConversationId());
sb.append(Attributes.PREDEFINED_ATTRIBUTE_PREFIX);
sb.append(str);
kapchatdownloadfile.filename = sb.toString();
ArrayList<KapchatMessageList> arrayList3 = this.downloadlist;
kapchatdownloadfile.url = arrayList3.get(arrayList3.size() - 1).getMimeurl();
ArrayList<KapchatMessageList> arrayList4 = this.downloadlist;
kapchatdownloadfile.extension = arrayList4.get(arrayList4.size() - 1).getMime().split("/")[1];
ArrayList<KapchatMessageList> arrayList5 = this.downloadlist;
kapchatdownloadfile.conversationid = arrayList5.get(arrayList5.size() - 1).getConversationId();
ArrayList<KapchatMessageList> arrayList6 = this.downloadlist;
kapchatdownloadfile.mimeurl = arrayList6.get(arrayList6.size() - 1).getMimeurl();
kapchatdownloadfile.setSucces(Boolean.TRUE);
new ClicktoDownload(getApplicationContext()).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, kapchatdownloadfile);
}
}
@Override
public void getMessageList(ArrayList<KapchatMessageList> arrayList) {
ArrayList arrayList2 = new ArrayList();
if (arrayList.size() != 0) {
arrayList2.clear();
this.downloadlist.clear();
for (int i = 0; i < arrayList.size(); i++) {
if (arrayList.get(i).getMessageStatus().equalsIgnoreCase("11")) {
arrayList2.add(arrayList.get(i));
}
}
for (int i2 = 0; i2 < arrayList2.size(); i2++) {
if (((KapchatMessageList) arrayList2.get(i2)).getConversationId().equalsIgnoreCase(this.conversationid)) {
this.downloadlist.add(arrayList2.get(i2));
}
}
downloadimage();
}
}
@Override
public void getPaginationList(ArrayList<KapchatMessageList> arrayList) {
}
@Override
public IBinder onBind(Intent intent) {
return this.mbinder;
}
@Override
public void onCreate() {
super.onCreate();
this.ikapchatMessages = this;
}
@Override
public void readMessageList(int i) {
}
@Override
public void update(Boolean bool) {
sendBroadcast(new Intent("com.adjetter.kapchatupdate"));
}
@Override
public void updateMessageList(Boolean bool, ArrayList<KapchatMessageList> arrayList) {
}
}