导航菜单

页面标题

页面副标题

SpeedCash v6.5.1482 - CaptureManager.java 源代码

正在查看: SpeedCash v6.5.1482 应用的 CaptureManager.java JAVA 源代码文件

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


package com.journeyapps.barcodescanner;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.os.Handler;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.google.zxing.ResultMetadataType;
import com.google.zxing.ResultPoint;
import com.google.zxing.client.android.BeepManager;
import com.google.zxing.client.android.InactivityTimer;
import com.google.zxing.client.android.Intents;
import com.google.zxing.client.android.R;
import com.journeyapps.barcodescanner.CameraPreview;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

public class CaptureManager {
    public static final String m = "CaptureManager";
    public static int n = 250;
    public Activity a;
    public DecoratedBarcodeView b;
    public InactivityTimer f;
    public BeepManager g;
    public Handler h;
    public final CameraPreview.StateListener k;
    public boolean l;
    public int c = -1;
    public boolean d = false;
    public boolean e = false;
    public boolean i = false;
    public BarcodeCallback j = new a();

    public class a implements BarcodeCallback {

        public class RunnableC0082a implements Runnable {
            public final BarcodeResult a;

            public RunnableC0082a(BarcodeResult barcodeResult) {
                this.a = barcodeResult;
            }

            @Override
            public void run() {
                CaptureManager.this.returnResult(this.a);
            }
        }

        public a() {
        }

        @Override
        public void barcodeResult(BarcodeResult barcodeResult) {
            CaptureManager.this.b.pause();
            CaptureManager.this.g.playBeepSoundAndVibrate();
            CaptureManager.this.h.post(new RunnableC0082a(barcodeResult));
        }

        @Override
        public void possibleResultPoints(List<ResultPoint> list) {
        }
    }

    public class b implements CameraPreview.StateListener {
        public b() {
        }

        @Override
        public void cameraClosed() {
            if (CaptureManager.this.i) {
                String unused = CaptureManager.m;
                CaptureManager.this.g();
            }
        }

        @Override
        public void cameraError(Exception exc) {
            CaptureManager.this.displayFrameworkBugMessageAndExit();
        }

        @Override
        public void previewSized() {
        }

        @Override
        public void previewStarted() {
        }

        @Override
        public void previewStopped() {
        }
    }

    public class c implements Runnable {
        public c() {
        }

        @Override
        public void run() {
            String unused = CaptureManager.m;
            CaptureManager.this.g();
        }
    }

    public class d implements Runnable {
        public d() {
        }

        @Override
        public void run() {
            CaptureManager.this.returnResultTimeout();
        }
    }

    public class e implements DialogInterface.OnClickListener {
        public e() {
        }

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            CaptureManager.this.g();
        }
    }

    public class f implements DialogInterface.OnCancelListener {
        public f() {
        }

        @Override
        public void onCancel(DialogInterface dialogInterface) {
            CaptureManager.this.g();
        }
    }

    public CaptureManager(Activity activity, DecoratedBarcodeView decoratedBarcodeView) {
        b bVar = new b();
        this.k = bVar;
        this.l = false;
        this.a = activity;
        this.b = decoratedBarcodeView;
        decoratedBarcodeView.getBarcodeView().addStateListener(bVar);
        this.h = new Handler();
        this.f = new InactivityTimer(activity, new c());
        this.g = new BeepManager(activity);
    }

    public static int getCameraPermissionReqCode() {
        return n;
    }

    public static Intent resultIntent(BarcodeResult barcodeResult, String str) {
        Intent intent = new Intent(Intents.Scan.ACTION);
        intent.addFlags(524288);
        intent.putExtra(Intents.Scan.RESULT, barcodeResult.toString());
        intent.putExtra(Intents.Scan.RESULT_FORMAT, barcodeResult.getBarcodeFormat().toString());
        byte[] rawBytes = barcodeResult.getRawBytes();
        if (rawBytes != null && rawBytes.length > 0) {
            intent.putExtra(Intents.Scan.RESULT_BYTES, rawBytes);
        }
        Map<ResultMetadataType, Object> resultMetadata = barcodeResult.getResultMetadata();
        if (resultMetadata != null) {
            ResultMetadataType resultMetadataType = ResultMetadataType.UPC_EAN_EXTENSION;
            if (resultMetadata.containsKey(resultMetadataType)) {
                intent.putExtra(Intents.Scan.RESULT_UPC_EAN_EXTENSION, resultMetadata.get(resultMetadataType).toString());
            }
            Number number = (Number) resultMetadata.get(ResultMetadataType.ORIENTATION);
            if (number != null) {
                intent.putExtra(Intents.Scan.RESULT_ORIENTATION, number.intValue());
            }
            String str2 = (String) resultMetadata.get(ResultMetadataType.ERROR_CORRECTION_LEVEL);
            if (str2 != null) {
                intent.putExtra(Intents.Scan.RESULT_ERROR_CORRECTION_LEVEL, str2);
            }
            Iterable iterable = (Iterable) resultMetadata.get(ResultMetadataType.BYTE_SEGMENTS);
            if (iterable != null) {
                Iterator it = iterable.iterator();
                int i = 0;
                while (it.hasNext()) {
                    intent.putExtra(Intents.Scan.RESULT_BYTE_SEGMENTS_PREFIX + i, (byte[]) it.next());
                    i++;
                }
            }
        }
        if (str != null) {
            intent.putExtra(Intents.Scan.RESULT_BARCODE_IMAGE_PATH, str);
        }
        return intent;
    }

    public static void setCameraPermissionReqCode(int i) {
        n = i;
    }

    public void closeAndFinish() {
        if (this.b.getBarcodeView().isCameraClosed()) {
            g();
        } else {
            this.i = true;
        }
        this.b.pause();
        this.f.cancel();
    }

    public void decode() {
        this.b.decodeSingle(this.j);
    }

    public void displayFrameworkBugMessageAndExit() {
        if (this.a.isFinishing() || this.e || this.i) {
            return;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(this.a);
        builder.setTitle(this.a.getString(R.string.zxing_app_name));
        builder.setMessage(this.a.getString(R.string.zxing_msg_camera_framework_bug));
        builder.setPositiveButton(R.string.zxing_button_ok, new e());
        builder.setOnCancelListener(new f());
        builder.show();
    }

    public final void g() {
        this.a.finish();
    }

    public final String h(BarcodeResult barcodeResult) {
        if (this.d) {
            Bitmap bitmap = barcodeResult.getBitmap();
            try {
                File createTempFile = File.createTempFile("barcodeimage", ".jpg", this.a.getCacheDir());
                FileOutputStream fileOutputStream = new FileOutputStream(createTempFile);
                bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fileOutputStream);
                fileOutputStream.close();
                return createTempFile.getAbsolutePath();
            } catch (IOException e2) {
                StringBuilder sb = new StringBuilder();
                sb.append("Unable to create temporary file and store bitmap! ");
                sb.append(e2);
            }
        }
        return null;
    }

    @TargetApi(23)
    public final void i() {
        if (ContextCompat.checkSelfPermission(this.a, "android.permission.CAMERA") == 0) {
            this.b.resume();
        } else {
            if (this.l) {
                return;
            }
            ActivityCompat.requestPermissions(this.a, new String[]{"android.permission.CAMERA"}, n);
            this.l = true;
        }
    }

    public void initializeFromIntent(Intent intent, Bundle bundle) {
        this.a.getWindow().addFlags(128);
        if (bundle != null) {
            this.c = bundle.getInt("SAVED_ORIENTATION_LOCK", -1);
        }
        if (intent != null) {
            if (intent.getBooleanExtra(Intents.Scan.ORIENTATION_LOCKED, true)) {
                lockOrientation();
            }
            if (Intents.Scan.ACTION.equals(intent.getAction())) {
                this.b.initializeFromIntent(intent);
            }
            if (!intent.getBooleanExtra(Intents.Scan.BEEP_ENABLED, true)) {
                this.g.setBeepEnabled(false);
            }
            if (intent.hasExtra(Intents.Scan.TIMEOUT)) {
                this.h.postDelayed(new d(), intent.getLongExtra(Intents.Scan.TIMEOUT, 0L));
            }
            if (intent.getBooleanExtra(Intents.Scan.BARCODE_IMAGE_ENABLED, false)) {
                this.d = true;
            }
        }
    }

    public void lockOrientation() {
        if (this.c == -1) {
            int rotation = this.a.getWindowManager().getDefaultDisplay().getRotation();
            int i = this.a.getResources().getConfiguration().orientation;
            int i2 = 0;
            if (i == 2) {
                if (rotation != 0 && rotation != 1) {
                    i2 = 8;
                }
            } else if (i == 1) {
                i2 = (rotation == 0 || rotation == 3) ? 1 : 9;
            }
            this.c = i2;
        }
        this.a.setRequestedOrientation(this.c);
    }

    public void onDestroy() {
        this.e = true;
        this.f.cancel();
        this.h.removeCallbacksAndMessages(null);
    }

    public void onPause() {
        this.f.cancel();
        this.b.pauseAndWait();
    }

    public void onRequestPermissionsResult(int i, String[] strArr, int[] iArr) {
        if (i == n) {
            if (iArr.length <= 0 || iArr[0] != 0) {
                displayFrameworkBugMessageAndExit();
            } else {
                this.b.resume();
            }
        }
    }

    public void onResume() {
        i();
        this.f.start();
    }

    public void onSaveInstanceState(Bundle bundle) {
        bundle.putInt("SAVED_ORIENTATION_LOCK", this.c);
    }

    public void returnResult(BarcodeResult barcodeResult) {
        this.a.setResult(-1, resultIntent(barcodeResult, h(barcodeResult)));
        closeAndFinish();
    }

    public void returnResultTimeout() {
        Intent intent = new Intent(Intents.Scan.ACTION);
        intent.putExtra(Intents.Scan.TIMEOUT, true);
        this.a.setResult(0, intent);
        closeAndFinish();
    }
}