工作空间 v3.7.4.6版本的 MD5 值为:94c1c0052e9f2e949ae1349e6caf437b

以下内容为反编译后的 H5BaseActivity.java 源代码,内容仅作参考


package com.uusafe.h5app.library.browser.activity;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider;
import com.donkingliang.imageselector.ImageSelectorActivity;
import com.donkingliang.imageselector.entry.Image;
import com.uusafe.base.modulesdk.module.event.DecodeResultType;
import com.uusafe.base.modulesdk.module.event.ScanDecodeEvent;
import com.uusafe.commbase.global.BaseGlobal;
import com.uusafe.h5app.library.api.H5ApplicationInfo;
import com.uusafe.h5app.library.api.IConstants;
import com.uusafe.h5app.library.browser.fragment.ZlaWebFragment;
import com.uusafe.jsbridge.bean.JsCallback;
import com.uusafe.jsbridge.module.BarcodeModule;
import com.uusafe.jsbridge.module.DeviceModule;
import com.uusafe.jsbridge.module.JsModule;
import com.uusafe.net.model.Progress;
import com.uusafe.permission.AfterPermissionGranted;
import com.uusafe.permission.EasyPermissions;
import com.uusafe.secamera.common.Const;
import com.uusafe.thirdpartylibs.utils.ImageUtil;
import com.uusafe.utils.common.FileUtils;
import com.uusafe.utils.common.JsonUtil;
import com.uusafe.utils.common.PhotoUtils;
import com.uusafe.utils.common.StringUtils;
import com.yanzhenjie.album.c.h;
import com.zhizhangyi.platform.mdm.api.common.ResultConst;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import org.greenrobot.eventbus.ThreadMode;
import org.greenrobot.eventbus.e;
import org.greenrobot.eventbus.n;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public abstract class H5BaseActivity extends AppCompatActivity implements EasyPermissions.PermissionCallbacks {
    public static final int CODE_CAMERA_REQUEST = 161;
    public static final int CODE_CROP_REQUEST = 162;
    public static final int CODE_GALLERY_REQUEST = 160;
    public static final int REQUEST_CODE_SELECT_MEMBER = 164;
    public static final int REQUEST_CODE_UPLOAD = 163;
    public HashMap<String, JsCallback> currentCallback;
    public ZlaWebFragment mFragment;
    public HashMap<String, Object> normalArgs;
    public HashMap<String, JsCallback> photoFunArgs;
    public File imgFileUri = null;
    public File imgFileCropUri = null;
    public Uri imgChoiceUrl = null;
    public String photo_camera_param = "";

    private void singleChoiceCallback() {
        JSONObject jSONObject;
        int i;
        boolean z;
        JSONObject jSONObject2 = new JSONObject();
        int i2 = 300;
        if (StringUtils.areNotEmpty(this.photo_camera_param)) {
            try {
                jSONObject = new JSONObject(this.photo_camera_param);
            } catch (JSONException unused) {
                jSONObject = null;
            }
            int i3 = 200;
            int i4 = -1;
            if (jSONObject != null) {
                try {
                    i = jSONObject.getInt("width");
                } catch (JSONException e2) {
                    e2.printStackTrace();
                    i = -1;
                }
                try {
                    i4 = jSONObject.getInt("maxLength");
                } catch (JSONException unused2) {
                }
                try {
                    i2 = jSONObject.getInt("thumbnailWidth");
                } catch (JSONException unused3) {
                }
                try {
                    z = jSONObject.getBoolean("crop");
                } catch (JSONException unused4) {
                    z = false;
                }
                try {
                    i3 = jSONObject.getInt("cropWidth");
                } catch (JSONException unused5) {
                }
            } else {
                i = -1;
                z = false;
            }
            if (z) {
                this.imgFileCropUri = new File(getAppPhotoPath(this) + "crop_photo" + System.currentTimeMillis() + ".jpg");
                if (Build.VERSION.SDK_INT >= 24) {
                    this.imgChoiceUrl = FileProvider.getUriForFile(this, BaseGlobal.getInstance().getFileProvider(), this.imgFileUri);
                } else {
                    this.imgChoiceUrl = Uri.fromFile(this.imgFileUri);
                }
                PhotoUtils.cropImageUri(this, this.imgChoiceUrl, Uri.fromFile(this.imgFileCropUri), 1, 1, i3, i3, 162);
            } else if (this.imgFileUri.exists()) {
                if (i > 0 || i4 > 0) {
                    try {
                        String str = getAppPhotoPath(this) + "custom_photo" + System.currentTimeMillis() + ".jpg";
                        FileUtils.copyFile(this.imgFileUri.getAbsolutePath(), str);
                        this.imgFileUri = new File(str);
                    } catch (Exception unused6) {
                        JsModule.callBackFail(this.photoFunArgs, "获取图片失败");
                        return;
                    }
                }
                PhotoUtils.adjustPhoto(this.imgFileUri.getAbsolutePath(), 100);
                h hVar = new h(this);
                hVar.f7460c = new File(getAppPhotoPath(this));
                String a2 = hVar.a(this.imgFileUri.getAbsolutePath(), i2);
                if (StringUtils.areNotEmpty(a2)) {
                    jSONObject2.put("thumbnailPath", a2);
                }
                if (i > 0) {
                    ImageUtil.compressBoundsBitmap(this, Uri.fromFile(this.imgFileUri), i);
                }
                int length = ((int) this.imgFileUri.length()) / 1024;
                if (i4 > 0 && i4 < length) {
                    ImageUtil.compressAndGenImage(Uri.fromFile(this.imgFileUri), i4);
                }
                jSONObject2.put("imagePath", this.imgFileUri.getAbsolutePath());
                jSONObject2.put(Progress.FILE_PATH, this.imgFileUri.getAbsolutePath());
                jSONObject2.put(ResultConst.Key.sErrMessage, "imageselector_camera:ok");
                JsModule.callBackSuccess(this.photoFunArgs, jSONObject2);
            }
        } else if (this.imgFileUri.exists()) {
            try {
                h hVar2 = new h(this);
                hVar2.f7460c = new File(getAppPhotoPath(this));
                String a3 = hVar2.a(this.imgFileUri.getAbsolutePath(), 300);
                if (StringUtils.areNotEmpty(a3)) {
                    jSONObject2.put("thumbnailPath", a3);
                }
                jSONObject2.put(Progress.FILE_PATH, this.imgFileUri.getAbsolutePath());
                jSONObject2.put(ResultConst.Key.sErrMessage, "imageselector_camera:ok");
                JsModule.callBackSuccess(this.photoFunArgs, jSONObject2);
            } catch (Exception unused7) {
                JsModule.callBackFail(this.photoFunArgs, "获取图片失败");
            }
        } else {
            JsModule.callBackFail(this.photoFunArgs, "获取图片失败");
        }
    }

    public void album(JSONObject jSONObject, String str, HashMap<String, JsCallback> hashMap) {
        this.photo_camera_param = jSONObject.toString();
        this.photoFunArgs = hashMap;
        if (str.equals(Const.TAG_VIDEO)) {
            Intent intent = new Intent("android.intent.action.GET_CONTENT");
            intent.setType(IConstants.ACCEPT_TYPE_VIDEO);
            startActivityForResult(intent, 160);
        } else if (str.equals("all")) {
            Intent intent2 = new Intent("android.intent.action.GET_CONTENT");
            intent2.setType("video/*;image/*");
            startActivityForResult(intent2, 160);
        } else {
            Intent intent3 = new Intent("android.intent.action.GET_CONTENT");
            intent3.setType(IConstants.ACCEPT_TYPE_IMAGE);
            startActivityForResult(intent3, 160);
        }
    }

    public void camera() {
        Intent intent = new Intent();
        intent.setAction("android.media.action.IMAGE_CAPTURE");
        this.imgFileUri = new File(getAppPhotoPath(this) + System.currentTimeMillis() + ".jpg");
        intent.putExtra("output", getFileUri(this.imgFileUri));
        startActivityForResult(intent, 161);
    }

    public String getAppPhotoPath(Context context) {
        File externalFilesDir = context.getExternalFilesDir(null);
        String str = externalFilesDir.getAbsolutePath() + "/photo/";
        if (!new File(str).exists()) {
            FileUtils.createDir(str, context);
        }
        return str;
    }

    public Uri getFileUri(File file) {
        if (Build.VERSION.SDK_INT >= 24) {
            return FileProvider.getUriForFile(this, BaseGlobal.getInstance().getFileProvider(), file);
        }
        return Uri.fromFile(file);
    }

    public abstract int getLayoutResID();

    public abstract void initViewAndData();

    public void multiAlbum(String str, HashMap<String, JsCallback> hashMap) {
        this.photoFunArgs = hashMap;
        try {
            JSONObject jSONObject = new JSONObject(str);
            int i = JsonUtil.getInt(jSONObject, "max", 3);
            h.f7458a = JsonUtil.getInt(jSONObject, "thumbnailWidth");
            this.photo_camera_param = "";
            if (Build.VERSION.SDK_INT >= 23) {
                ImageSelectorActivity.a(this, 163, false, i, null);
            }
        } catch (JSONException | Exception unused) {
        }
    }

    @Override
    public void onActivityResult(int i, int i2, Intent intent) {
        ZlaWebFragment zlaWebFragment;
        int i3;
        super.onActivityResult(i, i2, intent);
        int i4 = -1;
        if (i2 == -1) {
            switch (i) {
                case 160:
                    Uri parse = Uri.parse(PhotoUtils.getPath(this, intent.getData(), "file:///"));
                    this.imgFileUri = new File(parse.getPath());
                    if (Build.VERSION.SDK_INT >= 24) {
                        parse = FileProvider.getUriForFile(this, BaseGlobal.getInstance().getFileProvider(), new File(parse.getPath()));
                    }
                    this.imgChoiceUrl = parse;
                    singleChoiceCallback();
                    break;
                case 161:
                    singleChoiceCallback();
                    break;
                case 162:
                    JSONObject jSONObject = new JSONObject();
                    if (this.imgFileCropUri.exists()) {
                        try {
                            jSONObject.put("imagePath", this.imgFileCropUri.getAbsolutePath());
                            jSONObject.put(Progress.FILE_PATH, this.imgFileCropUri.getAbsolutePath());
                            jSONObject.put("thumbnailPath", "");
                            jSONObject.put(ResultConst.Key.sErrMessage, "imageselector_camera:ok");
                        } catch (JSONException unused) {
                        }
                        JsModule.callBackSuccess(this.photoFunArgs, jSONObject);
                        break;
                    } else {
                        JsModule.callBackFail(this.photoFunArgs, "裁剪失败");
                        break;
                    }
                case 163:
                    h.f7458a = 300;
                    if (intent != null) {
                        ArrayList arrayList = (ArrayList) intent.getSerializableExtra("select_result");
                        arrayList.size();
                        if (StringUtils.areNotEmpty(this.photo_camera_param)) {
                            JSONObject jSONObject2 = new JSONObject();
                            try {
                                jSONObject2 = new JSONObject(this.photo_camera_param);
                            } catch (JSONException unused2) {
                            }
                            try {
                                i3 = jSONObject2.getInt("width");
                            } catch (JSONException e2) {
                                e2.printStackTrace();
                                i3 = -1;
                            }
                            try {
                                i4 = jSONObject2.getInt("maxLength");
                            } catch (JSONException e3) {
                                e3.printStackTrace();
                            }
                            if (i3 > 0 || i4 > 0) {
                                Iterator it = arrayList.iterator();
                                while (it.hasNext()) {
                                    Image image = (Image) it.next();
                                    String str = getAppPhotoPath(this) + "custom_photo" + System.currentTimeMillis() + ".jpg";
                                    FileUtils.copyFile(image.getPath(), str);
                                    image.setPath(str);
                                }
                            }
                            if (i3 > 0) {
                                Iterator it2 = arrayList.iterator();
                                while (it2.hasNext()) {
                                    ImageUtil.compressBoundsBitmap(this, Uri.fromFile(new File(((Image) it2.next()).getPath())), i3);
                                }
                            }
                            if (i4 > 0) {
                                Iterator it3 = arrayList.iterator();
                                while (it3.hasNext()) {
                                    File file = new File(((Image) it3.next()).getPath());
                                    if (i4 < ((int) file.length()) / 1024) {
                                        try {
                                            ImageUtil.compressAndGenImage(Uri.fromFile(file), i4);
                                        } catch (IOException unused3) {
                                        }
                                    }
                                }
                            }
                        }
                        try {
                            JSONArray jSONArray = new JSONArray();
                            Iterator it4 = arrayList.iterator();
                            while (it4.hasNext()) {
                                Image image2 = (Image) it4.next();
                                JSONObject jSONObject3 = new JSONObject();
                                if (image2.isVideo) {
                                    jSONObject3.put("type", Const.TAG_VIDEO);
                                } else {
                                    jSONObject3.put("type", "image");
                                }
                                jSONObject3.put(Progress.FILE_PATH, image2.getPath());
                                jSONObject3.put("thumbnailPath", image2.thumbnailPath);
                                jSONArray.put(jSONObject3);
                            }
                            JSONObject jSONObject4 = new JSONObject();
                            jSONObject4.put("datas", jSONArray);
                            JsModule.callBackSuccess(this.photoFunArgs, jSONObject4);
                            break;
                        } catch (Exception unused4) {
                            break;
                        }
                    } else {
                        JsModule.callBackFail(this.photoFunArgs, "获取失败");
                        break;
                    }
            }
        }
        if ((i == 1 || i == 2 || i == 3 || i == 4) && (zlaWebFragment = this.mFragment) != null) {
            zlaWebFragment.onActivityResult(i, i2, intent);
        }
    }

    @Override
    public void onCreate(@Nullable Bundle bundle) {
        H5ApplicationInfo h5ApplicationInfo;
        super.onCreate(bundle);
        if (getLayoutResID() != 0) {
            setContentView(getLayoutResID());
        }
        Bundle extras = getIntent().getExtras();
        if (extras != null && (h5ApplicationInfo = (H5ApplicationInfo) extras.getParcelable(IConstants.KEY_EXTRA_APPINFO)) != null) {
            int i = h5ApplicationInfo.screenOrientation;
            if (i == 1) {
                setRequestedOrientation(1);
            }
            if (i == 2) {
                setRequestedOrientation(0);
            }
        }
        initViewAndData();
        e.a().e(this);
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        e.a().g(this);
    }

    @n(threadMode = ThreadMode.MAIN)
    public void onMessageEventMainThread(ScanDecodeEvent scanDecodeEvent) {
        if (scanDecodeEvent == null || scanDecodeEvent.getResult() == null) {
            return;
        }
        scanDecodeEvent.getListioner().onResult(DecodeResultType.DECPDE_SUCESS);
        JSONObject jSONObject = new JSONObject();
        JsonUtil.putString(jSONObject, "result", scanDecodeEvent.getResult());
        JsonUtil.putString(jSONObject, "codeType", scanDecodeEvent.getType());
        JsModule.callBackSuccess(this.photoFunArgs, jSONObject);
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onPermissionsDenied(int i, List<String> list) {
    }

    @Override
    public void onPermissionsGranted(int i, List<String> list) {
    }

    @Override
    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        super.onRequestPermissionsResult(i, strArr, iArr);
        EasyPermissions.onRequestPermissionsResult(i, strArr, iArr, this);
        DeviceModule deviceModule = DeviceModule.deviceModule;
        if (deviceModule != null) {
            deviceModule.callBackRequestPermission(i, strArr, iArr);
        }
    }

    @Override
    protected void onRestart() {
        super.onRestart();
    }

    @Override
    public void onResume() {
        BarcodeModule barcodeModule = BarcodeModule.barcodeModule;
        if (barcodeModule != null) {
            barcodeModule.scanCallback(null);
        }
        super.onResume();
    }

    @AfterPermissionGranted(138)
    public void takePhoto() {
        camera();
    }
}