工作空间 v3.7.4.6版本的 MD5 值为:94c1c0052e9f2e949ae1349e6caf437b
以下内容为反编译后的 PhotoModule.java 源代码,内容仅作参考
package com.uusafe.jsbridge.module;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.util.Base64;
import androidx.core.app.ActivityOptionsCompat;
import androidx.core.content.FileProvider;
import com.donkingliang.imageselector.c.d;
import com.uusafe.commbase.global.BaseGlobal;
import com.uusafe.data.module.receiver.UpdateLocaleReceiver;
import com.uusafe.h5app.library.Env;
import com.uusafe.h5app.library.browser.activity.H5BaseActivity;
import com.uusafe.jsbridge.base.JavascriptMethod;
import com.uusafe.jsbridge.bean.JsCallback;
import com.uusafe.jsbridge.bean.WritableJsArray;
import com.uusafe.permission.util.PermissionsUtils;
import com.uusafe.secamera.common.Const;
import com.uusafe.thirdpartylibs.utils.ImageUtil;
import com.uusafe.utils.common.ZZLog;
import com.xiaomi.mipush.sdk.Constants;
import com.zhizhangyi.platform.mdm.api.common.ResultConst;
import imageshow.NSImageShowActivity;
import imageshow.b;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import org.json.JSONException;
import org.json.JSONObject;
public class PhotoModule extends JsModule {
private final String TAG = "PhotoModule";
@JavascriptMethod
public void album(HashMap<String, Object> hashMap, HashMap<String, JsCallback> hashMap2) {
ZZLog.i("PhotoModule", "album =", new Object[0]);
PermissionsUtils.requestPermission(getFragment(), 138, PermissionsUtils.CAMERA);
Context context = this.mContext;
if (context instanceof H5BaseActivity) {
((H5BaseActivity) context).album(JsModule.mapToJsonArgs(hashMap), JsModule.getStringArg(hashMap, "showType", "image"), hashMap2);
}
}
@JavascriptMethod
public void camera(HashMap<String, Object> hashMap, HashMap<String, JsCallback> hashMap2) {
ZZLog.i("PhotoModule", "camera =", new Object[0]);
PermissionsUtils.requestPermission(getFragment(), 138, PermissionsUtils.CAMERA);
Context context = this.mContext;
if (context instanceof H5BaseActivity) {
H5BaseActivity h5BaseActivity = (H5BaseActivity) context;
h5BaseActivity.photo_camera_param = JsModule.mapToJsonArgs(hashMap).toString();
h5BaseActivity.photoFunArgs = hashMap2;
if (PermissionsUtils.requestPermission(h5BaseActivity, 138, PermissionsUtils.CAMERA)) {
h5BaseActivity.camera();
}
}
}
@JavascriptMethod
public void getBase64Image(HashMap<String, Object> hashMap, HashMap<String, JsCallback> hashMap2) {
Bitmap decodeFile;
ByteArrayOutputStream byteArrayOutputStream;
String stringArg = JsModule.getStringArg(hashMap, "imagePath", "");
ZZLog.i("PhotoModule", "getBase64Image imagePath=" + stringArg, new Object[0]);
String appResFile = Env.getAppResFile(getContext(), getFragment().appId, stringArg);
int intArg = JsModule.getIntArg(hashMap, "width", -1);
int intArg2 = JsModule.getIntArg(hashMap, "maxLength", -1);
File file = new File(appResFile);
if (!file.exists()) {
JsModule.callBackFail(hashMap2, "文件不存在");
return;
}
if (intArg > 0) {
if (Build.VERSION.SDK_INT >= 24) {
decodeFile = ImageUtil.compressBoundsFile(getContext(), FileProvider.getUriForFile(getContext(), BaseGlobal.getInstance().getFileProvider(), file), intArg);
} else {
decodeFile = ImageUtil.compressBoundsFile(getContext(), Uri.fromFile(file), intArg);
}
} else {
decodeFile = BitmapFactory.decodeFile(appResFile);
}
if (decodeFile != null) {
try {
if (intArg2 > 0) {
byteArrayOutputStream = ImageUtil.compressAndGenImageBitmap(decodeFile, intArg2);
} else {
byteArrayOutputStream = new ByteArrayOutputStream();
decodeFile.compress(Bitmap.CompressFormat.JPEG, 100, byteArrayOutputStream);
}
if (byteArrayOutputStream != null) {
JSONObject jSONObject = new JSONObject();
jSONObject.put("data", "data:image/jpeg;base64," + Base64.encodeToString(byteArrayOutputStream.toByteArray(), 2));
jSONObject.put(ResultConst.Key.sErrMessage, "getBase64Image:ok");
JsModule.callBackSuccess(hashMap2, jSONObject);
byteArrayOutputStream.close();
return;
}
JsModule.callBackFail(hashMap2, "获取失败");
return;
} catch (Exception unused) {
JsModule.callBackFail(hashMap2, "获取失败");
return;
}
}
JsModule.callBackFail(hashMap2, "获取失败");
}
@Override
public String getModuleName() {
return Const.TAG_PHOTO;
}
@JavascriptMethod
public void miniVideo(HashMap<String, Object> hashMap, HashMap<String, JsCallback> hashMap2) {
ZZLog.i("PhotoModule", "miniVideo =", new Object[0]);
if (PermissionsUtils.hasPermission(getFragment(), PermissionsUtils.VIDEO)) {
Context context = this.mContext;
if (!(context instanceof H5BaseActivity)) {
return;
}
((H5BaseActivity) context).photoFunArgs = hashMap2;
try {
JSONObject mapToJsonArgs = JsModule.mapToJsonArgs(hashMap);
try {
mapToJsonArgs.getInt("minTime");
} catch (JSONException unused) {
}
try {
mapToJsonArgs.getInt("maxTime");
} catch (JSONException unused2) {
}
} catch (Exception e2) {
ZZLog.e("PhotoModule", "miniVideo =", e2);
e2.printStackTrace();
}
} else {
PermissionsUtils.requestPermission(getFragment(), 138, PermissionsUtils.VIDEO);
}
}
@JavascriptMethod
public void multiAlbum(HashMap<String, Object> hashMap, HashMap<String, JsCallback> hashMap2) {
ZZLog.i("PhotoModule", "multiAlbum =", new Object[0]);
PermissionsUtils.requestPermission(getFragment(), 138, PermissionsUtils.CAMERA);
Context context = this.mContext;
if (context instanceof H5BaseActivity) {
((H5BaseActivity) context).multiAlbum(JsModule.mapToJsonArgs(hashMap).toString(), hashMap2);
}
}
@JavascriptMethod
public void preview(HashMap<String, Object> hashMap, HashMap<String, JsCallback> hashMap2) {
try {
ZZLog.i("PhotoModule", "preview=", new Object[0]);
int intArg = JsModule.getIntArg(hashMap, UpdateLocaleReceiver.EXTRA_INDEX, 0);
WritableJsArray array = JsModule.getArray(hashMap, "urls");
ArrayList arrayList = new ArrayList();
if (array.size() > 0) {
for (int i = 0; i < array.size(); i++) {
arrayList.add(array.get(i).toString());
}
}
Intent intent = new Intent(this.mContext, NSImageShowActivity.class);
b bVar = new b();
bVar.a(arrayList);
bVar.b(true);
bVar.b(intArg);
bVar.c(false);
bVar.a(true);
bVar.a(1);
NSImageShowActivity.f7665a = bVar;
this.mContext.startActivity(intent, ActivityOptionsCompat.makeCustomAnimation(this.mContext, 17432576, 17432577).toBundle());
} catch (Exception unused) {
}
}
@JavascriptMethod
public void saveBase64ImageToAlbum(HashMap<String, Object> hashMap, HashMap<String, JsCallback> hashMap2) {
try {
ZZLog.i("PhotoModule", "saveBase64ImageToAlbum=", new Object[0]);
byte[] decode = Base64.decode(JsModule.getStringArg(hashMap, "data", "").split(Constants.ACCEPT_TIME_SEPARATOR_SP)[1], 0);
d.a(getContext(), BitmapFactory.decodeByteArray(decode, 0, decode.length), "");
JsModule.callBackSuccess(hashMap2, new JSONObject());
} catch (Exception e2) {
ZZLog.e("PhotoModule", "saveBase64ImageToAlbum=", e2);
JsModule.callBackFail(hashMap2, "保存失败");
}
}
}