wjc
2025-01-10 2e91f8abdcb87feda9e237895d4460a19fd7aed8
app/src/main/java/com/hdl/photovoltaic/ui/device/ScanActivity.java
@@ -1,5 +1,6 @@
package com.hdl.photovoltaic.ui.device;
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
@@ -46,6 +47,7 @@
import com.hdl.photovoltaic.other.HdlCommonLogic;
import com.hdl.photovoltaic.uni.HDLUniMP;
import com.hdl.photovoltaic.utils.LocalManageUtil;
import com.hdl.photovoltaic.utils.PermissionUtils;
import com.jaeger.library.StatusBarUtil;
import com.zxing.IZxingActivity;
import com.zxing.camera.CameraManager;
@@ -122,7 +124,9 @@
        //设置根视图
        View mContentView = LayoutInflater.from(this).inflate(getRootLayoutId(), null);
        setContentView(mContentView);
        afterViewBind(mContentView, savedInstanceState);
    }
@@ -197,7 +201,9 @@
        }
        inactivityTimer.onPause();
        beepManager.close();
        cameraManager.closeDriver();
        if (cameraManager != null) {
            cameraManager.closeDriver();
        }
        if (!isHasSurface) {
            scanPreview.getHolder().removeCallback(this);
        }
@@ -247,31 +253,41 @@
    }
    private void initCamera(SurfaceHolder surfaceHolder) {
        if (surfaceHolder == null) {
            throw new IllegalStateException("No SurfaceHolder provided");
        }
        if (cameraManager.isOpen()) {
            Log.w(TAG, "initCamera() while already open -- late SurfaceView callback?");
            return;
        }
        try {
            cameraManager.openDriver(surfaceHolder);
            // Creating the handler starts the preview, which can also throw a
            // RuntimeException.
            if (handler == null) {
                handler = new CaptureActivityHandler(this, cameraManager, DecodeThread.ALL_MODE);
            }
        PermissionUtils.requestPermissionsResultCallback(this, Manifest.permission.CAMERA, new PermissionUtils.PermissionState() {
            @Override
            public void Success(int value) {
                if (value == PermissionUtils.STATUS_REFUSE_PERMANENT | value == PermissionUtils.STATUS_REFUSE) {
//                            HdlThreadLogic.toast(_mActivity, R.string.permission_open);
                    Toast.makeText(ScanActivity.this, R.string.capture_no_camera, Toast.LENGTH_SHORT).show();
                    return;
                }
            initCrop();
        } catch (IOException ioe) {
            Log.w(TAG, ioe);
            Toast.makeText(this, R.string.capture_no_camera, Toast.LENGTH_SHORT).show();
            finish();
        } catch (RuntimeException e) {
            Log.w(TAG, "Unexpected error initializing camera", e);
            Toast.makeText(this, R.string.capture_no_camera, Toast.LENGTH_SHORT).show();
            finish();
        }
                if (surfaceHolder == null) {
                    throw new IllegalStateException("No SurfaceHolder provided");
                }
                if (cameraManager.isOpen()) {
                    Log.w(TAG, "initCamera() while already open -- late SurfaceView callback?");
                    return;
                }
                try {
                    cameraManager.openDriver(surfaceHolder);
                    // Creating the handler starts the preview, which can also throw a
                    // RuntimeException.
                    if (handler == null) {
                        handler = new CaptureActivityHandler(ScanActivity.this, cameraManager, DecodeThread.ALL_MODE);
                    }
                    initCrop();
                } catch (IOException ioe) {
                    Log.w(TAG, ioe);
                    Toast.makeText(ScanActivity.this, R.string.capture_no_camera, Toast.LENGTH_SHORT).show();
                    finish();
                } catch (RuntimeException e) {
                    Log.w(TAG, "Unexpected error initializing camera", e);
                    Toast.makeText(ScanActivity.this, R.string.capture_no_camera, Toast.LENGTH_SHORT).show();
                    finish();
                }
            }
        }, true);
    }
    public void restartPreviewAfterDelay(long delayMS) {