Search in sources :

Example 1 with CameraManager

use of com.google.zxing.camera.CameraManager in project QRCode by 5peak2me.

the class CaptureActivity method onResume.

@Override
protected void onResume() {
    super.onResume();
    // CameraManager must be initialized here, not in onCreate(). This is
    // necessary because we don't
    // want to open the camera driver and measure the screen size if we're
    // going to show the help on
    // first launch. That led to bugs where the scanning rectangle was the
    // wrong size and partially
    // off screen.
    // 相机初始化的动作需要开启相机并测量屏幕大小,这些操作
    // 不建议放到onCreate中,因为如果在onCreate中加上首次启动展示帮助信息的代码的 话,
    // 会导致扫描窗口的尺寸计算有误的bug
    cameraManager = new CameraManager(getApplication());
    viewfinderView = (ViewfinderView) findViewById(R.id.capture_viewfinder_view);
    viewfinderView.setCameraManager(cameraManager);
    handler = null;
    lastResult = null;
    // 摄像头预览功能必须借助SurfaceView,因此也需要在一开始对其进行初始化
    // 如果需要了解SurfaceView的原理
    // 参考:http://blog.csdn.net/luoshengyang/article/details/8661317
    // 预览
    SurfaceView surfaceView = (SurfaceView) findViewById(R.id.capture_preview_view);
    SurfaceHolder surfaceHolder = surfaceView.getHolder();
    if (hasSurface) {
        // The activity was paused but not stopped, so the surface still
        // exists. Therefore
        // surfaceCreated() won't be called, so init the camera here.
        initCamera(surfaceHolder);
    } else {
        // 防止sdk8的设备初始化预览异常
        surfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
        // Install the callback and wait for surfaceCreated() to init the
        // camera.
        surfaceHolder.addCallback(this);
    }
    // 加载声音配置,其实在BeemManager的构造器中也会调用该方法,即在onCreate的时候会调用一次
    beepManager.updatePrefs();
    // 启动闪光灯调节器
    ambientLightManager.start(cameraManager);
    // 恢复活动监控器
    inactivityTimer.onResume();
    source = IntentSource.NONE;
    decodeFormats = null;
    characterSet = null;
}
Also used : SurfaceHolder(android.view.SurfaceHolder) CameraManager(com.google.zxing.camera.CameraManager) SurfaceView(android.view.SurfaceView)

Aggregations

SurfaceHolder (android.view.SurfaceHolder)1 SurfaceView (android.view.SurfaceView)1 CameraManager (com.google.zxing.camera.CameraManager)1