导航菜单

页面标题

页面副标题

Cashalo v2.25.0.0 - PortraitCameraActivity.java 源代码

正在查看: Cashalo v2.25.0.0 应用的 PortraitCameraActivity.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 androidx.camera.core.Camera;
import androidx.camera.core.CameraSelector;
import androidx.camera.core.FocusMeteringAction;
import androidx.camera.core.ImageAnalysis;
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.adapter.page.LoadingEvent;
import com.oriente.cashalo.service.CommonService;
import com.oriente.cashalo.utils.FileUploadHelper;
import com.oriente.cashalo.utils.FormatUtils;
import com.oriente.cashalo.utils.OrientUtils;
import com.oriente.core.debug.log.Logger;
import com.oriente.core.page.PageTarget;
import com.oriente.core.page.jump.Jumper;
import com.oriente.core.task.Worker;
import com.oriente.http.callback.RequestCallback;
import com.oriente.http.image.ImageDisplay;
import com.oriente.http.model.RequestContext;
import com.oriente.http.model.RequestResult;
import com.oriente.uikit.utils.ViewUtils;
import com.oriente.uimodule.alert.Alert;
import com.oriente.uimodule.alert.AlertBuilder;
import com.oriente.utils.ImageUtils;
import com.oriente.utils.PathUtil;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.SocketTimeoutException;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import org.greenrobot.eventbus.EventBus;
import top.zibin.luban.Luban;
import top.zibin.luban.OnCompressListener;

public class PortraitCameraActivity extends BaseActivity {
    private ExecutorService executor = Executors.newSingleThreadExecutor();
    ImageView mCancelBtn;
    ImageView mCaptureImage;
    private Uri mCaptureUri;
    LinearLayout mHandleImgLayout;
    ImageView mOkBtn;
    private String mOriginUrl;
    PreviewView mPreviewView;
    SimpleDraweeView mSimpleDraweeView;

    @Override
    protected void onCreate(Bundle bundle) {
        requestWindowFeature(1);
        getWindow().setFlags(1024, 1024);
        super.onCreate(bundle);
        setContentView(R.layout.fragment_holding_id_camera);
        initView();
        startCamera();
    }

    private void initView() {
        this.mPreviewView = findViewById(R.id.previewView);
        this.mCaptureImage = (ImageView) findViewById(R.id.captureImg);
        this.mCancelBtn = (ImageView) findViewById(R.id.cancelBtn);
        this.mOkBtn = (ImageView) findViewById(R.id.okBtn);
        this.mSimpleDraweeView = findViewById(R.id.simpleDraweeView);
        this.mHandleImgLayout = (LinearLayout) findViewById(R.id.handleImgLayout);
        findViewById(R.id.camera_close).setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PortraitCameraActivity.this.lambda$initView$0(view);
            }
        });
        this.mCancelBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PortraitCameraActivity.this.lambda$initView$1(view);
            }
        });
        this.mOkBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PortraitCameraActivity.this.lambda$initView$2(view);
            }
        });
    }

    public void lambda$initView$0(View view) {
        if (this.mPreviewView.getVisibility() == 0) {
            finish();
        } else {
            back();
        }
    }

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

    public void lambda$initView$2(View view) {
        Uri uri = this.mCaptureUri;
        if (uri != null) {
            checkFaceCount(this, uri, "1", new FileUploadHelper.OnFaceCountListener() {
                @Override
                public void onFaceCountCallback(boolean z) {
                    if (z) {
                        PortraitCameraActivity.this.uploadCapture();
                    }
                }
            });
        }
    }

    public void checkFaceCount(final PageTarget pageTarget, Uri uri, final String str, final FileUploadHelper.OnFaceCountListener onFaceCountListener) {
        if (pageTarget == null || uri == null) {
            return;
        }
        File uri2File = ImageUtils.INSTANCE.uri2File(pageTarget.getContext(), uri);
        if (!uri2File.exists()) {
            CommonAnalytics.analyticsImportantStep(CommonAnalytics.toProperties("upload_path_null", "true", new Object[0]));
        } else {
            Luban.with(pageTarget.getContext()).setTargetDir(ValueConfig.getCompressImageCache()).load(uri2File).setCompressListener(new OnCompressListener() {
                public void onStart() {
                    EventBus.getDefault().post(new LoadingEvent(true));
                }

                public void onSuccess(File file) {
                    EventBus.getDefault().post(new LoadingEvent(false));
                    PortraitCameraActivity.this.checkFaceCountImpl(pageTarget, FormatUtils.encodeBase64File(file), str, onFaceCountListener);
                }

                public void onError(Throwable th) {
                    EventBus.getDefault().post(new LoadingEvent(false));
                    Logger.error(th);
                }
            }).launch();
        }
    }

    public void checkFaceCountImpl(final PageTarget pageTarget, String str, String str2, final FileUploadHelper.OnFaceCountListener onFaceCountListener) {
        CommonService.faceCount(str, str2, new RequestContext.Builder(pageTarget).build(new RequestCallback<Object>() {
            public void onRequestFinished(RequestContext<Object> requestContext, RequestResult<Object> requestResult) {
                if (requestResult.isSuccessFull()) {
                    FileUploadHelper.OnFaceCountListener onFaceCountListener2 = onFaceCountListener;
                    if (onFaceCountListener2 != null) {
                        onFaceCountListener2.onFaceCountCallback(true);
                        return;
                    }
                    return;
                }
                if ((requestResult.getError() instanceof SocketTimeoutException) || (requestResult.getError() instanceof TimeoutException)) {
                    requestResult.markAsHandled();
                    OrientUtils.showUploadPicFailureMsg(requestResult.getMessage());
                }
                if (requestResult.getCode() == 1129) {
                    Alert.from(pageTarget.getContext(), (String) null, requestResult.getMessage(), new CharSequence[0]).buttonIds(new int[]{R.string.ori_common_btn_cancel, R.string.ori_upload_btn_reupload_photo}).callback(new Alert.IAlertAction() {
                        public void onAlertAction(AlertBuilder alertBuilder, int i) {
                            if (4 == i) {
                                PortraitCameraActivity.this.back();
                            }
                        }
                    }).dismissBackpress(false).dismissTouchOut(false).show();
                    requestResult.markAsHandled();
                }
            }
        }));
    }

    public void uploadCapture() {
        Intent intent = new Intent();
        intent.putExtra("bundle", Jumper.obtain(new Object[]{"data", this.mCaptureUri}));
        setResult(-1, intent);
        finish();
    }

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

    public void showPreViewCaptureImage() {
        ViewUtils.setVisibility(this.mPreviewView, 8);
        ViewUtils.setVisibility(this.mCaptureImage, 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 {
                    PortraitCameraActivity.this.bindPreview((ProcessCameraProvider) processCameraProvider.get());
                } catch (InterruptedException | ExecutionException unused) {
                }
            }
        }, ContextCompat.getMainExecutor(this));
    }

    void bindPreview(ProcessCameraProvider processCameraProvider) {
        UseCase build = new Preview.Builder().build();
        CameraSelector build2 = new CameraSelector.Builder().requireLensFacing(1).build();
        new ImageAnalysis.Builder().build();
        ImageCapture.Builder builder = new ImageCapture.Builder();
        new Preview.Builder();
        final UseCase build3 = builder.setTargetRotation(getWindowManager().getDefaultDisplay().getRotation()).build();
        build.setSurfaceProvider(this.mPreviewView.getSurfaceProvider());
        Camera bindToLifecycle = processCameraProvider.bindToLifecycle(this, build2, new UseCase[]{build, build3});
        this.mCaptureImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PortraitCameraActivity.this.lambda$bindPreview$3(build3, view);
            }
        });
        autoFocusAfterMeasure(bindToLifecycle);
    }

    public void lambda$bindPreview$3(ImageCapture imageCapture, View view) {
        final File file = new File(PathUtil.getCacheDirectory(this), System.currentTimeMillis() + ".jpg");
        imageCapture.takePicture(new ImageCapture.OutputFileOptions.Builder(file).build(), this.executor, new ImageCapture.OnImageSavedCallback() {
            public void onImageSaved(ImageCapture.OutputFileResults outputFileResults) {
                PortraitCameraActivity.this.mCaptureUri = outputFileResults.getSavedUri() != null ? outputFileResults.getSavedUri() : Uri.fromFile(file);
                ImageUtils imageUtils = ImageUtils.INSTANCE;
                ?? r0 = PortraitCameraActivity.this;
                final File uri2File = imageUtils.uri2File((Context) r0, ((PortraitCameraActivity) r0).mCaptureUri);
                PortraitCameraActivity.this.mOriginUrl = uri2File.getAbsolutePath();
                try {
                    Bitmap decodeFile = BitmapFactory.decodeFile(PortraitCameraActivity.this.mOriginUrl);
                    ?? r1 = PortraitCameraActivity.this;
                    Bitmap rotateImageIfRequired = PortraitCameraActivity.rotateImageIfRequired(r1, decodeFile, ((PortraitCameraActivity) r1).mCaptureUri);
                    FileOutputStream fileOutputStream = new FileOutputStream(PortraitCameraActivity.this.mOriginUrl);
                    if (rotateImageIfRequired != null) {
                        rotateImageIfRequired.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
                    }
                    fileOutputStream.flush();
                    fileOutputStream.close();
                    if (rotateImageIfRequired != null) {
                        FS.bitmap_recycle(rotateImageIfRequired);
                    }
                    if (decodeFile != null) {
                        FS.bitmap_recycle(decodeFile);
                    }
                    if (uri2File != null) {
                        Worker.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                PortraitCameraActivity.this.showPreViewCaptureImage();
                                ImageDisplay.with(PortraitCameraActivity.this.mSimpleDraweeView).scaleType(ScalingUtils.ScaleType.FIT_XY).display(Uri.fromFile(uri2File));
                            }
                        }, 16L);
                    }
                } catch (IOException e) {
                    CommonAnalytics.analyticsImportantStep(CommonAnalytics.toProperties(" selfie rotate image", true, new Object[0]));
                    throw new RuntimeException(e);
                }
            }

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

    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);
    }

    private 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.executor;
        if (executorService != null) {
            executorService.shutdown();
        }
    }
}