思特奇智慧酒店云平台 v0.0.5版本的 MD5 值为:dedb172bb322639d79d7e0e26262fb5c
以下内容为反编译后的 SaveImageJSHandler.java 源代码,内容仅作参考
package com.sitech.core.util.js.handler;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.AsyncTask;
import android.text.TextUtils;
import com.sitech.core.util.Log;
import com.sitech.oncon.widget.WebViewUI;
import com.sitech.onloc.common.util.Base64;
import java.io.File;
import java.io.InputStream;
import java.net.URL;
import java.util.ArrayList;
import org.json.JSONException;
import org.json.JSONObject;
public class SaveImageJSHandler extends BaseJSHandler {
public abstract class SaveAsyncTask extends AsyncTask<String, Integer, JSONObject> {
public String value;
public SaveAsyncTask(String str) {
this.value = str;
}
@Override
public void onPreExecute() {
super.onPreExecute();
try {
SaveImageJSHandler.this.showProgressDialog();
} catch (Throwable th) {
Log.a(th);
}
}
@Override
public void onPostExecute(JSONObject jSONObject) {
try {
SaveImageJSHandler.this.hideProgressDialog();
SaveImageJSHandler.this.returnRes(jSONObject);
} catch (Exception e) {
Log.a((Throwable) e);
}
}
}
public class SaveBase64AsyncTask extends SaveAsyncTask {
public SaveBase64AsyncTask(String str) {
super(str);
}
@Override
public JSONObject doInBackground(String... strArr) {
String str;
byte[] decode;
String str2;
JSONObject jSONObject = new JSONObject();
try {
if (this.value.startsWith("data:image/jpg;base64,")) {
str = this.value.replace("data:image/jpg;base64,", "");
} else if (this.value.startsWith("data:image/jpeg;base64,")) {
str = this.value.replace("data:image/jpeg;base64,", "");
} else if (this.value.startsWith("data:image/png;base64,")) {
str = this.value.replace("data:image/png;base64,", "");
} else if (this.value.startsWith("data:image/gif;base64,")) {
str = this.value.replace("data:image/gif;base64,", "");
} else if (this.value.startsWith("data:image/x-icon;base64,")) {
str = this.value.replace("data:image/x-icon;base64,", "");
} else {
str = this.value;
}
decode = Base64.decode(str);
} catch (Throwable th) {
Log.a(th);
try {
jSONObject.put("status", "0");
jSONObject.put("errorMsg", "deal type1 value error:" + th.getMessage());
} catch (Throwable th2) {
Log.a(th2);
}
}
if (decode == null) {
jSONObject.put("status", "0");
jSONObject.put("errorMsg", "value(base64) is invalid");
return jSONObject;
}
String str3 = ck0.v() + ("oncon_" + System.currentTimeMillis());
sk0.a(decode, str3, false);
String g = sk0.g(str3);
if (TextUtils.isEmpty(g)) {
str2 = str3;
} else {
str2 = str3 + "." + g;
new File(str3).renameTo(new File(str2));
}
dl0.a(SaveImageJSHandler.this.webView.getContext(), str2);
jSONObject.put("status", "1");
return jSONObject;
}
}
public class SaveURLAsyncTask extends SaveAsyncTask {
public SaveURLAsyncTask(String str) {
super(str);
}
@Override
public JSONObject doInBackground(String... strArr) {
String str = "";
JSONObject jSONObject = new JSONObject();
try {
String replace = Uri.encode(this.value).replace("%3A", ":").replace("%2F", "/");
Log.d(replace);
boolean z = false;
try {
InputStream openStream = new URL(replace).openStream();
Bitmap decodeStream = BitmapFactory.decodeStream(openStream);
openStream.close();
str = ck0.v() + WebViewUI.a(replace, "");
dl0.a(str, decodeStream);
z = true;
} catch (Exception e) {
Log.a((Throwable) e);
}
if (!z) {
File file = new File(str);
if (file.exists() && file.isFile()) {
file.delete();
}
jSONObject.put("status", "0");
jSONObject.put("errorMsg", "download fail");
} else {
String g = sk0.g(str);
if (!TextUtils.isEmpty(g)) {
File file2 = new File(str);
str = str + "." + g;
file2.renameTo(new File(str));
}
jSONObject.put("status", "1");
dl0.a(SaveImageJSHandler.this.webView.getContext(), str);
}
} catch (Throwable th) {
Log.a(th);
try {
jSONObject.put("status", "0");
jSONObject.put("errorMsg", "deal type2 value error:" + th.getMessage());
} catch (Throwable th2) {
Log.a(th2);
}
}
return jSONObject;
}
}
public void process() throws JSONException {
JSONObject jSONObject = this.req.getJSONObject("params");
if (jSONObject == null) {
JSONObject jSONObject2 = new JSONObject();
jSONObject2.put("status", "0");
jSONObject2.put("errorMsg", "req params not exists");
returnRes(jSONObject2);
return;
}
String string = jSONObject.has("type") ? jSONObject.getString("type") : "";
if (TextUtils.isEmpty(string)) {
JSONObject jSONObject3 = new JSONObject();
jSONObject3.put("status", "0");
jSONObject3.put("errorMsg", "req param type is empty");
returnRes(jSONObject3);
return;
}
boolean equals = TextUtils.equals("1", string);
boolean equals2 = TextUtils.equals("2", string);
if (!equals && !equals2) {
JSONObject jSONObject4 = new JSONObject();
jSONObject4.put("status", "0");
jSONObject4.put("errorMsg", "req param type must be 1 or 2");
returnRes(jSONObject4);
return;
}
String string2 = jSONObject.has("value") ? jSONObject.getString("value") : "";
if (TextUtils.isEmpty(string2)) {
JSONObject jSONObject5 = new JSONObject();
jSONObject5.put("status", "0");
jSONObject5.put("errorMsg", "req param value is empty");
returnRes(jSONObject5);
} else if (equals) {
new SaveBase64AsyncTask(string2).execute(new String[0]);
} else if (equals2) {
new SaveURLAsyncTask(string2).execute(new String[0]);
}
}
@Override
public void deal() throws JSONException {
ArrayList arrayList = new ArrayList();
arrayList.add("android.permission.WRITE_EXTERNAL_STORAGE");
String[] strArr = new String[arrayList.size()];
arrayList.toArray(strArr);
kk0.a(new bk1() {
@Override
public void onDenied(String[] strArr2) {
try {
JSONObject jSONObject = new JSONObject();
jSONObject.put("status", "0");
jSONObject.put("errorMsg", "no write ext file permission");
SaveImageJSHandler.this.returnRes(jSONObject);
} catch (Throwable th) {
Log.a(th);
}
}
@Override
public void onPermissionGranted(String[] strArr2) {
try {
SaveImageJSHandler.this.process();
} catch (Throwable th) {
Log.a(th);
}
}
}, strArr);
}
}