导航菜单

页面标题

页面副标题

EfectivoYa v2.3 - FFTakeSelfieActivity.java 源代码

正在查看: EfectivoYa v2.3 应用的 FFTakeSelfieActivity.java JAVA 源代码文件

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


package com.mxff.ffxxmm.activity;

import android.R;
import android.content.Intent;
import android.graphics.RectF;
import android.hardware.display.DisplayManager;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.HandlerThread;
import android.os.Looper;
import android.provider.MediaStore;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.Size;
import android.view.View;
import androidx.camera.core.CameraSelector;
import androidx.camera.core.ImageAnalysis;
import androidx.camera.core.ImageCapture;
import androidx.camera.core.ImageCaptureException;
import androidx.camera.core.Preview;
import androidx.camera.lifecycle.ProcessCameraProvider;
import androidx.camera.view.PreviewView;
import androidx.core.content.ContextCompat;
import com.google.android.material.card.MaterialCardViewHelper;
import com.google.common.util.concurrent.ListenableFuture;
import com.gyf.immersionbar.l;
import com.mxff.ffxxmm.activity.FFTakeSelfieActivity;
import com.mxff.ffxxmm.databinding.FfActivityCameraxFaceBinding;
import com.mxff.ffxxmm.utils.FFLuminosityAnalyzer;
import com.mxff.ffxxmm.utils.k;
import com.mxff.ffxxmm.utils.m;
import com.mxff.ffxxmm.viewmodel.BaseViewModel;
import java.io.File;
import java.util.concurrent.ExecutionException;
import me.jessyan.autosize.utils.AutoSizeUtils;

public class FFTakeSelfieActivity extends BaseActivity<BaseViewModel, FfActivityCameraxFaceBinding> {

    private Preview f2122m;

    private ProcessCameraProvider f2123n;

    private ImageCapture f2124o;

    private ImageAnalysis f2125p;

    private RectF f2126q;

    private Uri f2127r;

    private DisplayManager f2129t;

    private DisplayManager.DisplayListener f2130u;

    private int f2121l = 0;

    private final Handler f2128s = new Handler(Looper.getMainLooper());

    class a implements DisplayManager.DisplayListener {
        a() {
        }

        @Override
        public void onDisplayAdded(int i2) {
        }

        @Override
        public void onDisplayChanged(int i2) {
            if (i2 == FFTakeSelfieActivity.this.f2121l) {
                int rotation = FFTakeSelfieActivity.this.findViewById(R.id.content).getDisplay().getRotation();
                if (FFTakeSelfieActivity.this.f2122m != null) {
                    FFTakeSelfieActivity.this.f2122m.setTargetRotation(rotation);
                }
                if (FFTakeSelfieActivity.this.f2124o != null) {
                    FFTakeSelfieActivity.this.f2124o.setTargetRotation(rotation);
                }
                if (FFTakeSelfieActivity.this.f2125p != null) {
                    FFTakeSelfieActivity.this.f2125p.setTargetRotation(rotation);
                }
            }
        }

        @Override
        public void onDisplayRemoved(int i2) {
        }
    }

    class b implements View.OnAttachStateChangeListener {
        b() {
        }

        @Override
        public void onViewAttachedToWindow(View view) {
            FFTakeSelfieActivity.this.f2129t.registerDisplayListener(FFTakeSelfieActivity.this.f2130u, null);
        }

        @Override
        public void onViewDetachedFromWindow(View view) {
            FFTakeSelfieActivity.this.f2129t.unregisterDisplayListener(FFTakeSelfieActivity.this.f2130u);
        }
    }

    class c implements ImageCapture.OnImageSavedCallback {
        c() {
        }

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

        @Override
        public void onImageSaved(ImageCapture.OutputFileResults outputFileResults) {
            FFTakeSelfieActivity.this.f2065i.ivPreviewView.setVisibility(0);
            FFTakeSelfieActivity.this.f2065i.tvConfirm.setVisibility(0);
            FFTakeSelfieActivity.this.f2065i.tvCancel.setVisibility(0);
            FFTakeSelfieActivity.this.f2065i.tvTakePicture.setVisibility(4);
            FFTakeSelfieActivity.this.f2065i.ivPreviewView.setImageURI(outputFileResults.getSavedUri());
            FFTakeSelfieActivity.this.f2127r = outputFileResults.getSavedUri();
            Log.d("chenchao", "Photo saved in " + FFTakeSelfieActivity.this.f2127r);
        }
    }

    private void O(ProcessCameraProvider processCameraProvider, PreviewView previewView) {
        processCameraProvider.bindToLifecycle(this, CameraSelector.DEFAULT_FRONT_CAMERA, this.f2122m, this.f2124o, this.f2125p);
        this.f2122m.setSurfaceProvider(previewView.getSurfaceProvider());
    }

    public void P(View view) {
        finish();
    }

    public void Q() {
        this.f2121l = this.f2065i.viewFinder.getDisplay().getDisplayId();
        this.f2065i.viewFinder.addOnAttachStateChangeListener(new b());
        RectF rectF = new RectF(this.f2065i.viewFinder.getLeft(), this.f2065i.viewFinder.getTop(), this.f2065i.viewFinder.getRight(), this.f2065i.viewFinder.getBottom());
        this.f2126q = rectF;
        this.f2065i.fFinderBackground.b(rectF, AutoSizeUtils.dp2px(this, 25.0f));
        X();
    }

    public void R(View view) {
        Y();
    }

    public void S(View view) {
        V();
    }

    public void T(View view) {
        setResult(-1, new Intent().setData(this.f2127r));
        finish();
    }

    public void U(ListenableFuture listenableFuture, PreviewView previewView) {
        try {
            this.f2123n = (ProcessCameraProvider) listenableFuture.get();
            previewView.getDisplay().getRealMetrics(new DisplayMetrics());
            int rotation = previewView.getDisplay().getRotation();
            ProcessCameraProvider processCameraProvider = this.f2123n;
            this.f2122m = new Preview.Builder().setTargetResolution(new Size(MaterialCardViewHelper.DEFAULT_FADE_ANIM_DURATION, MaterialCardViewHelper.DEFAULT_FADE_ANIM_DURATION)).setTargetRotation(rotation).build();
            this.f2124o = new ImageCapture.Builder().setCaptureMode(0).setFlashMode(2).setTargetResolution(new Size(MaterialCardViewHelper.DEFAULT_FADE_ANIM_DURATION, MaterialCardViewHelper.DEFAULT_FADE_ANIM_DURATION)).setTargetRotation(rotation).build();
            ImageAnalysis build = new ImageAnalysis.Builder().setTargetResolution(new Size(MaterialCardViewHelper.DEFAULT_FADE_ANIM_DURATION, MaterialCardViewHelper.DEFAULT_FADE_ANIM_DURATION)).setTargetRotation(rotation).setBackpressureStrategy(0).build();
            this.f2125p = build;
            W(build);
            processCameraProvider.unbindAll();
            O(processCameraProvider, previewView);
        } catch (InterruptedException e2) {
            throw new RuntimeException(e2);
        } catch (ExecutionException e3) {
            throw new RuntimeException(e3);
        }
    }

    private void V() {
        this.f2065i.ivPreviewView.setVisibility(4);
        this.f2065i.tvCancel.setVisibility(8);
        this.f2065i.tvConfirm.setVisibility(8);
        this.f2065i.tvTakePicture.setVisibility(0);
    }

    private void W(ImageAnalysis imageAnalysis) {
        HandlerThread handlerThread = new HandlerThread("Luminosity");
        handlerThread.start();
        imageAnalysis.setAnalyzer(new m(new Handler(handlerThread.getLooper())), new FFLuminosityAnalyzer());
    }

    private void X() {
        final PreviewView previewView = this.f2065i.viewFinder;
        final ListenableFuture<ProcessCameraProvider> processCameraProvider = ProcessCameraProvider.getInstance(this);
        processCameraProvider.addListener(new Runnable() {
            @Override
            public final void run() {
                FFTakeSelfieActivity.this.U(processCameraProvider, previewView);
            }
        }, ContextCompat.getMainExecutor(this));
    }

    private void Y() {
        ImageCapture imageCapture = this.f2124o;
        if (imageCapture == null) {
            imageCapture = new ImageCapture.Builder().setTargetResolution(new Size(MaterialCardViewHelper.DEFAULT_FADE_ANIM_DURATION, MaterialCardViewHelper.DEFAULT_FADE_ANIM_DURATION)).setTargetRotation(this.f2065i.viewFinder.getDisplay().getRotation()).build();
        }
        ImageCapture.Metadata metadata = new ImageCapture.Metadata();
        metadata.setReversedHorizontal(true);
        MediaStore.Images.Media.EXTERNAL_CONTENT_URI.toString();
        File file = new File(getCacheDir() + "/camera/");
        if (!file.exists()) {
            file.mkdirs();
        }
        imageCapture.lambda$takePicture$4(new ImageCapture.OutputFileOptions.Builder(new File(file, System.currentTimeMillis() + ".jpg")).setMetadata(metadata).build(), new m(this.f2128s), new c());
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        this.f2129t.unregisterDisplayListener(this.f2130u);
    }

    @Override
    protected void r() {
    }

    @Override
    protected void u(Bundle bundle) {
        k.a(this.f2065i.customToolBar, c1.a.a("Autenticación biométrica"), new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                FFTakeSelfieActivity.this.P(view);
            }
        });
        l.l0(this).f0(this.f2065i.customToolBar).D();
        this.f2065i.tvTip.setText(c1.a.a("Asegúrese de que su rostro esté alineado con el marco de la cámara y haya una buena iluminación."));
        this.f2065i.tvTakePicture.setText(c1.a.a("Haga clic para empezar"));
        this.f2129t = (DisplayManager) getSystemService("display");
        a aVar = new a();
        this.f2130u = aVar;
        this.f2129t.registerDisplayListener(aVar, null);
        this.f2065i.viewFinder.post(new Runnable() {
            @Override
            public final void run() {
                FFTakeSelfieActivity.this.Q();
            }
        });
        this.f2065i.tvCancel.setVisibility(8);
        this.f2065i.tvConfirm.setVisibility(8);
        this.f2065i.tvTakePicture.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                FFTakeSelfieActivity.this.R(view);
            }
        });
        this.f2065i.tvCancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                FFTakeSelfieActivity.this.S(view);
            }
        });
        this.f2065i.tvConfirm.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                FFTakeSelfieActivity.this.T(view);
            }
        });
    }
}