导航菜单

页面标题

页面副标题

Cashalo v2.25.0.0 - CustomCameraActivity.java 源代码

正在查看: Cashalo v2.25.0.0 应用的 CustomCameraActivity.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.oriente.cashalo.page.activity;

import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.media.ExifInterface;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import androidx.camera.core.Camera;
import androidx.camera.core.CameraInfoUnavailableException;
import androidx.camera.core.CameraSelector;
import androidx.camera.core.FocusMeteringAction;
import androidx.camera.core.ImageCapture;
import androidx.camera.core.ImageCaptureException;
import androidx.camera.core.Preview;
import androidx.camera.core.SurfaceOrientedMeteringPointFactory;
import androidx.camera.core.UseCase;
import androidx.camera.lifecycle.ProcessCameraProvider;
import androidx.camera.view.PreviewView;
import androidx.core.content.ContextCompat;
import com.facebook.drawee.drawable.ScalingUtils;
import com.facebook.drawee.view.SimpleDraweeView;
import com.fullstory.FS;
import com.google.common.util.concurrent.ListenableFuture;
import com.oriente.adapter.R;
import com.oriente.adapter.analytics.impl.CommonAnalytics;
import com.oriente.adapter.config.ValueConfig;
import com.oriente.adapter.page.BaseActivity;
import com.oriente.adapter.page.BaseActivity$$ExternalSyntheticApiModelOutline0;
import com.oriente.cashalo.page.activity.CustomCameraActivity;
import com.oriente.cashalo.service.model.common.OcrResult;
import com.oriente.cashalo.service.model.ver.KeyResult;
import com.oriente.cashalo.utils.EnhanceImageManager;
import com.oriente.core.internal.ScreenName;
import com.oriente.core.page.PageManager;
import com.oriente.core.page.jump.Jumper;
import com.oriente.core.task.Worker;
import com.oriente.core.utils.ResUtils;
import com.oriente.core.utils.StringUtils;
import com.oriente.core.utils.ToastUtils;
import com.oriente.http.image.ImageDisplay;
import com.oriente.manager.OrientManager;
import com.oriente.plugin.PluginResult;
import com.oriente.plugin.PluginResultCallback;
import com.oriente.plugin.module.VerifyPlugin;
import com.oriente.uikit.utils.ViewUtils;
import com.oriente.uimodule.alert.Alert;
import com.oriente.uimodule.alert.AlertBuilder;
import com.oriente.uimodule.loading.ProgressHelper;
import com.oriente.utils.ImageUtils;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.concurrent.Callable;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import top.zibin.luban.Luban;
import top.zibin.luban.OnCompressListener;

@ScreenName("Custom Camera")
public class CustomCameraActivity extends BaseActivity {
    public static final String BACK = "back";
    public static final String FRONT = "front";
    private static final float RATIO_16_9_VALUE = 1.7777778f;
    private static final float RATIO_4_3_VALUE = 1.3333334f;
    private boolean mBack;
    private RelativeLayout mCameraCrop;
    ImageView mCaptureImage;
    private File mCropCompressedFile;
    private String mCropImageUrl;
    private ExecutorService mExecutorService;
    LinearLayout mHandleImgLayout;
    private ImageView mImageLeft;
    private ImageView mImageRight;
    private ImageView mImageTop;
    private File mOriginCompressedFile;
    private String mOriginUrl;
    PreviewView mPreviewView;
    SimpleDraweeView mSimpleDraweeView;
    private TextView mTopTip;
    private String mTypeCode;
    private ExecutorService mExecutor = Executors.newSingleThreadExecutor();
    private CountDownLatch mLatch = new CountDownLatch(2);
    public String frontOrBack = null;

    @Override
    protected void onCreate(Bundle bundle) {
        requestWindowFeature(1);
        getWindow().setFlags(1024, 1024);
        super.onCreate(bundle);
        setContentView(R.layout.fragment_custom_camera);
        Bundle obtain = Jumper.obtain(this);
        this.mTypeCode = obtain.getString("typeCode");
        this.mBack = obtain.getBoolean("back", false);
        initView();
        startCamera();
        this.mExecutorService = Executors.newFixedThreadPool(2);
    }

    private void initView() {
        this.mPreviewView = findViewById(R.id.previewView);
        this.mCaptureImage = (ImageView) findViewById(R.id.captureImg);
        this.mSimpleDraweeView = findViewById(R.id.simpleDraweeView);
        this.mHandleImgLayout = (LinearLayout) findViewById(R.id.handleImgLayout);
        this.mTopTip = (TextView) findViewById(R.id.tv_top_tip);
        this.mImageTop = (ImageView) findViewById(R.id.imageTop);
        this.mImageLeft = (ImageView) findViewById(R.id.imageLeft);
        this.mImageRight = (ImageView) findViewById(R.id.imageRight);
        this.mCameraCrop = (RelativeLayout) findViewById(R.id.camera_crop);
        findViewById(R.id.btn_ok).setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                CustomCameraActivity.this.lambda$initView$0(view);
            }
        });
        findViewById(R.id.btn_cancel).setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                CustomCameraActivity.this.lambda$initView$1(view);
            }
        });
        findViewById(R.id.camera_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                CustomCameraActivity.this.lambda$initView$2(view);
            }
        });
        if (StringUtils.isNotEmpty(this.mTypeCode)) {
            String str = this.mTypeCode;
            str.hashCode();
            switch (str) {
                case "1":
                    if (!this.mBack) {
                        this.mImageTop.setVisibility(0);
                        RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) this.mImageTop.getLayoutParams();
                        layoutParams.leftMargin = ViewUtils.dp2px(32);
                        layoutParams.topMargin = ViewUtils.dp2px(20);
                        break;
                    } else {
                        this.mImageTop.setVisibility(8);
                        break;
                    }
                case "2":
                case "3":
                case "5":
                case "6":
                case "7":
                    if (!this.mBack) {
                        RelativeLayout.LayoutParams layoutParams2 = (RelativeLayout.LayoutParams) this.mImageLeft.getLayoutParams();
                        layoutParams2.leftMargin = ViewUtils.dp2px(48);
                        layoutParams2.topMargin = ViewUtils.dp2px(89);
                        this.mImageLeft.setVisibility(0);
                    } else {
                        this.mImageLeft.setVisibility(8);
                    }
                    if ("7".equals(this.mTypeCode)) {
                        this.mTopTip.setText(ResUtils.string(R.string.ori_verify_camera_certificate_for_ph_health));
                        break;
                    }
                    break;
                case "4":
                case "8":
                    if (!this.mBack) {
                        RelativeLayout.LayoutParams layoutParams3 = (RelativeLayout.LayoutParams) this.mImageRight.getLayoutParams();
                        layoutParams3.rightMargin = ViewUtils.dp2px(54);
                        layoutParams3.topMargin = ViewUtils.dp2px(102);
                        this.mImageRight.setVisibility(0);
                        break;
                    } else {
                        this.mImageRight.setVisibility(8);
                        break;
                    }
            }
        }
    }

    public void lambda$initView$0(View view) {
        if (this.mOriginUrl != null) {
            checkImageRuleWithImageUrl();
        }
    }

    public void lambda$initView$1(View view) {
        reTakePicture();
    }

    public void lambda$initView$2(View view) {
        finish();
    }

    private void checkImageRuleWithImageUrl() {
        final VerifyPlugin plugin = OrientManager.getPlugin(VerifyPlugin.class);
        plugin.checkImageRuleWithImageUrl(this, Jumper.obtain(new Object[]{"originUrl", this.mOriginUrl}), new PluginResultCallback() {
            public final void onPluginResult(PluginResult pluginResult) {
                CustomCameraActivity.this.lambda$checkImageRuleWithImageUrl$4(plugin, pluginResult);
            }
        });
    }

    public void lambda$checkImageRuleWithImageUrl$4(VerifyPlugin verifyPlugin, PluginResult pluginResult) {
        if (pluginResult.isSuccess()) {
            verifyPlugin.checkReflectiveAndBlur(this, Jumper.obtain(new Object[]{"enhanceUrl", this.mCropImageUrl}), new PluginResultCallback() {
                public final void onPluginResult(PluginResult pluginResult2) {
                    CustomCameraActivity.this.lambda$checkImageRuleWithImageUrl$3(pluginResult2);
                }
            });
        } else {
            Alert.from(this).message(String.format(ResUtils.string(R.string.ori_component_alert_check_image_valid), "ID")).button(ResUtils.string(R.string.ori_common_btn_ok)).callback(new Alert.IAlertAction() {
                public void onAlertAction(AlertBuilder alertBuilder, int i) {
                    if (i == 2) {
                        CustomCameraActivity.this.reTakePicture();
                    }
                }
            }).show();
        }
    }

    public void lambda$checkImageRuleWithImageUrl$3(PluginResult pluginResult) {
        if (pluginResult.isSuccess()) {
            Serializable serializable = pluginResult.getResult().getSerializable("data");
            if (serializable == null || !(serializable instanceof OcrResult)) {
                return;
            }
            OcrResult ocrResult = (OcrResult) serializable;
            if (ocrResult.resultType == 1) {
                reTakePicture();
                return;
            } else if (ocrResult.file != null && StringUtils.isVisibleUnNull(ocrResult.file.getAbsolutePath())) {
                executeCompressImageTasks(this.mOriginUrl, ocrResult.file.getAbsolutePath(), ocrResult);
                return;
            } else {
                executeCompressImageTasks(this.mOriginUrl, this.mCropImageUrl, ocrResult);
                return;
            }
        }
        executeCompressImageTasks(this.mOriginUrl, this.mCropImageUrl, null);
    }

    public void reTakePicture() {
        ViewUtils.setVisibility(this.mPreviewView, 0);
        ViewUtils.setVisibility(this.mCaptureImage, 0);
        ViewUtils.setVisibility(this.mCameraCrop, 0);
        ViewUtils.setVisibility(this.mSimpleDraweeView, 8);
        ViewUtils.setVisibility(this.mHandleImgLayout, 8);
    }

    private void showPreViewCaptureImage() {
        ViewUtils.setVisibility(this.mPreviewView, 8);
        ViewUtils.setVisibility(this.mCaptureImage, 8);
        ViewUtils.setVisibility(this.mCameraCrop, 8);
        ViewUtils.setVisibility(this.mSimpleDraweeView, 0);
        ViewUtils.setVisibility(this.mHandleImgLayout, 0);
    }

    private void startCamera() {
        final ListenableFuture processCameraProvider = ProcessCameraProvider.getInstance(this);
        processCameraProvider.addListener(new Runnable() {
            @Override
            public void run() {
                try {
                    CustomCameraActivity.this.bindPreview((ProcessCameraProvider) processCameraProvider.get());
                } catch (InterruptedException | ExecutionException unused) {
                }
            }
        }, ContextCompat.getMainExecutor(this));
    }

    void bindPreview(ProcessCameraProvider processCameraProvider) {
        Preview build = new Preview.Builder().build();
        this.mPreviewView.post(new AnonymousClass3(new ImageCapture.Builder(), build, processCameraProvider));
    }

    class AnonymousClass3 implements Runnable {
        final ProcessCameraProvider val$cameraProvider;
        final ImageCapture.Builder val$imageCaptureBuilder;
        final Preview val$preview;

        AnonymousClass3(ImageCapture.Builder builder, Preview preview, ProcessCameraProvider processCameraProvider) {
            this.val$imageCaptureBuilder = builder;
            this.val$preview = preview;
            this.val$cameraProvider = processCameraProvider;
        }

        @Override
        public void run() {
            ImageCapture.Builder targetRotation = this.val$imageCaptureBuilder.setTargetRotation(CustomCameraActivity.this.getWindowManager().getDefaultDisplay().getRotation());
            CustomCameraActivity customCameraActivity = CustomCameraActivity.this;
            final UseCase build = targetRotation.setTargetAspectRatio(customCameraActivity.aspectRatio(customCameraActivity.mPreviewView.getWidth(), CustomCameraActivity.this.mPreviewView.getHeight())).build();
            this.val$preview.setSurfaceProvider(CustomCameraActivity.this.mPreviewView.getSurfaceProvider());
            try {
                if (this.val$cameraProvider.hasCamera(CameraSelector.DEFAULT_BACK_CAMERA)) {
                    Camera bindToLifecycle = this.val$cameraProvider.bindToLifecycle(CustomCameraActivity.this, new CameraSelector.Builder().requireLensFacing(1).build(), new UseCase[]{this.val$preview, build});
                    CustomCameraActivity.this.mCaptureImage.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public final void onClick(View view) {
                            CustomCameraActivity.AnonymousClass3.this.lambda$run$0(build, view);
                        }
                    });
                    CustomCameraActivity.this.autoFocusAfterMeasure(bindToLifecycle);
                    return;
                }
                ToastUtils.pop("The rear camera is temporarily unavailable, please try again later.");
            } catch (CameraInfoUnavailableException e) {
                throw new RuntimeException((Throwable) e);
            }
        }

        public void lambda$run$0(ImageCapture imageCapture, View view) {
            File file = new File(PageManager.getApplicationContext().getCacheDir().getAbsolutePath() + File.separator + "profile");
            CustomCameraActivity.this.checkFileExist(file);
            final File file2 = new File(file, System.currentTimeMillis() + ".jpg");
            imageCapture.takePicture(new ImageCapture.OutputFileOptions.Builder(file2).build(), CustomCameraActivity.this.mExecutor, new ImageCapture.OnImageSavedCallback() {
                public void onImageSaved(ImageCapture.OutputFileResults outputFileResults) {
                    AnonymousClass3.this.onImageSavedImpl(outputFileResults, file2);
                }

                public void onError(ImageCaptureException imageCaptureException) {
                    imageCaptureException.printStackTrace();
                }
            });
        }

        public void lambda$onImageSavedImpl$1() {
            ProgressHelper.from(CustomCameraActivity.this).message("").show();
        }

        public void onImageSavedImpl(ImageCapture.OutputFileResults outputFileResults, File file) {
            Worker.runOnUiThread(new Runnable() {
                @Override
                public final void run() {
                    CustomCameraActivity.AnonymousClass3.this.lambda$onImageSavedImpl$1();
                }
            }, 0L);
            Uri savedUri = outputFileResults.getSavedUri() != null ? outputFileResults.getSavedUri() : Uri.fromFile(file);
            File uri2File = ImageUtils.INSTANCE.uri2File(CustomCameraActivity.this, savedUri);
            CustomCameraActivity.this.mOriginUrl = uri2File.getAbsolutePath();
            try {
                try {
                    Bitmap decodeFile = BitmapFactory.decodeFile(CustomCameraActivity.this.mOriginUrl);
                    Bitmap rotateImageIfRequired = CustomCameraActivity.rotateImageIfRequired(CustomCameraActivity.this, decodeFile, savedUri);
                    if (rotateImageIfRequired != null) {
                        FS.bitmap_recycle(rotateImageIfRequired);
                    }
                    if (decodeFile != null) {
                        FS.bitmap_recycle(decodeFile);
                    }
                } catch (IOException e) {
                    CommonAnalytics.analyticsImportantStep(CommonAnalytics.toProperties("idPhoto rotate image", true, new Object[0]));
                    throw new RuntimeException(e);
                }
            } finally {
                CustomCameraActivity.this.showCropImage(uri2File);
            }
        }
    }

    public static Bitmap rotateImageIfRequired(Context context, Bitmap bitmap, Uri uri) throws IOException {
        int attributeInt = (Build.VERSION.SDK_INT > 23 ? BaseActivity$$ExternalSyntheticApiModelOutline0.m(context.getContentResolver().openInputStream(uri)) : new ExifInterface(uri.getPath())).getAttributeInt("Orientation", 1);
        if (attributeInt == 3) {
            return rotateImage(bitmap, 180.0f);
        }
        if (attributeInt != 6) {
            return attributeInt != 8 ? bitmap : rotateImage(bitmap, 270.0f);
        }
        return rotateImage(bitmap, 90.0f);
    }

    public static Bitmap rotateImage(Bitmap bitmap, float f) {
        Matrix matrix = new Matrix();
        matrix.postRotate(f);
        return Bitmap.createBitmap(bitmap, 0, 0, bitmap.getWidth(), bitmap.getHeight(), matrix, true);
    }

    public void executeCompressImageTasks(final String str, final String str2, final OcrResult ocrResult) {
        if (StringUtils.isVisible(str2)) {
            this.mLatch = new CountDownLatch(2);
        } else {
            this.mLatch = new CountDownLatch(1);
        }
        ProgressHelper.from(this).message("").show();
        final ExecutorService newFixedThreadPool = Executors.newFixedThreadPool(2);
        Callable callable = new Callable() {
            @Override
            public final Object call() {
                File lambda$executeCompressImageTasks$5;
                lambda$executeCompressImageTasks$5 = CustomCameraActivity.this.lambda$executeCompressImageTasks$5(str);
                return lambda$executeCompressImageTasks$5;
            }
        };
        Callable callable2 = StringUtils.isVisible(str2) ? new Callable() {
            @Override
            public final Object call() {
                File lambda$executeCompressImageTasks$6;
                lambda$executeCompressImageTasks$6 = CustomCameraActivity.this.lambda$executeCompressImageTasks$6(str2);
                return lambda$executeCompressImageTasks$6;
            }
        } : null;
        newFixedThreadPool.submit(callable);
        if (StringUtils.isVisible(str2) && callable2 != null) {
            newFixedThreadPool.submit(callable2);
        }
        newFixedThreadPool.submit(new Runnable() {
            @Override
            public final void run() {
                CustomCameraActivity.this.lambda$executeCompressImageTasks$7(ocrResult, newFixedThreadPool);
            }
        });
    }

    public File lambda$executeCompressImageTasks$5(String str) throws Exception {
        Luban.with(this).setTargetDir(ValueConfig.getCompressImageCache()).load(str).setCompressListener(new OnCompressListener() {
            public void onStart() {
            }

            public void onSuccess(File file) {
                CustomCameraActivity.this.mOriginCompressedFile = file;
                CustomCameraActivity.this.mLatch.countDown();
            }

            public void onError(Throwable th) {
                CustomCameraActivity.this.mLatch.countDown();
            }
        }).launch();
        this.mLatch.await();
        return this.mOriginCompressedFile;
    }

    public File lambda$executeCompressImageTasks$6(String str) throws Exception {
        Luban.with(this).setTargetDir(ValueConfig.getCompressImageCache()).load(str).setCompressListener(new OnCompressListener() {
            public void onStart() {
            }

            public void onSuccess(File file) {
                CustomCameraActivity.this.mCropCompressedFile = file;
                CustomCameraActivity.this.mLatch.countDown();
            }

            public void onError(Throwable th) {
                CustomCameraActivity.this.mLatch.countDown();
            }
        }).launch();
        this.mLatch.await();
        return this.mCropCompressedFile;
    }

    public void lambda$executeCompressImageTasks$7(OcrResult ocrResult, ExecutorService executorService) {
        try {
            try {
                this.mLatch.await();
                afterBothTasksFinishedCallbackToH5(this.mOriginCompressedFile, this.mCropCompressedFile, ocrResult);
            } catch (InterruptedException unused) {
                Thread.currentThread().interrupt();
            }
        } finally {
            executorService.shutdown();
        }
    }

    private void afterBothTasksFinishedCallbackToH5(File file, File file2, OcrResult ocrResult) {
        String absolutePath = file.getAbsolutePath();
        String absolutePath2 = file2 == null ? absolutePath : file2.getAbsolutePath();
        ProgressHelper.from(this).hide();
        Intent intent = new Intent();
        Bundle obtain = Jumper.obtain(new Object[]{KeyResult.KEY_ENHANCE_DATA, absolutePath2, KeyResult.KEY_ENHANCE_ORIGINAL_DATA, absolutePath, ValueConfig.BUNDLE_ID_TYPE, this.mTypeCode});
        if (ocrResult != null) {
            obtain.putSerializable("ocrResult", ocrResult);
        }
        intent.putExtras(obtain);
        setResult(-1, intent);
        finish();
    }

    public void showCropImage(final File file) {
        Worker.runOnUiThread(new Runnable() {
            @Override
            public final void run() {
                CustomCameraActivity.this.lambda$showCropImage$8(file);
            }
        }, 16L);
    }

    public void lambda$showCropImage$8(File file) {
        ProgressHelper.from(this).message("").hide();
        ImageDisplay.with(this.mSimpleDraweeView).scaleType(ScalingUtils.ScaleType.FIT_CENTER).display(Uri.fromFile(file));
        showPreViewCaptureImage();
    }

    public void checkFileExist(File file) {
        if (file == null || file.exists()) {
            return;
        }
        file.mkdirs();
    }

    public int aspectRatio(int i, int i2) {
        FS.log_d(EnhanceImageManager.TAG, "width =" + i + "   height=" + i2);
        float f = (float) i;
        Float.valueOf(f).getClass();
        float f2 = (float) i2;
        Float.valueOf(f2).getClass();
        float max = Math.max(f, f2);
        Float.valueOf(f).getClass();
        Float.valueOf(f2).getClass();
        FS.log_d(EnhanceImageManager.TAG, "width =" + i + "   height=" + i2 + "   previewRatio =" + (max / Math.min(f, f2)));
        return 1;
    }

    public void autoFocusAfterMeasure(Camera camera) {
        FocusMeteringAction.Builder builder = new FocusMeteringAction.Builder(new SurfaceOrientedMeteringPointFactory(this.mPreviewView.getWidth(), this.mPreviewView.getHeight()).createPoint(this.mPreviewView.getWidth() / 2, this.mPreviewView.getHeight() / 2), 1);
        builder.setAutoCancelDuration(1L, TimeUnit.SECONDS);
        if (camera != null) {
            camera.getCameraControl().startFocusAndMetering(builder.build());
        }
    }

    protected void onDestroy() {
        super.onDestroy();
        ExecutorService executorService = this.mExecutor;
        if (executorService != null) {
            executorService.shutdown();
        }
    }

    protected void onActivityResult(int i, int i2, Intent intent) {
        super.onActivityResult(i, i2, intent);
        if (i2 == -1 && i == 19 && intent.getData() != null) {
            ProgressHelper.from(this).message("").show();
            File uri2File = ImageUtils.INSTANCE.uri2File(this, intent.getData());
            this.mOriginUrl = uri2File.getAbsolutePath();
            if (uri2File != null) {
                showCropImage(uri2File);
            }
        }
    }
}