/** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_capture);
    CameraManager.init(getApplication());

    viewfinderView = (ViewfinderView) findViewById(R.id.viewfinder_view);
    ImageButton btn = (ImageButton) findViewById(R.id.btn_cancel);
    btn.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            CaptureActivity.this.finish();
          }
        });

    Intent intent = getIntent();
    if (intent != null) {
      decodeFormats = DecodeFormatManager.parseDecodeFormats(intent);
    }

    hasSurface = false;
    inactivityTimer = new InactivityTimer(this);
  }
 @Override
 protected void onPause() {
   super.onPause();
   if (handler != null) {
     handler.quitSynchronously();
     handler = null;
   }
   CameraManager.get().closeDriver();
 }
 private void initCamera(SurfaceHolder surfaceHolder) {
   try {
     CameraManager.get().openDriver(surfaceHolder);
   } catch (IOException ioe) {
     return;
   } catch (RuntimeException e) {
     return;
   }
   if (handler == null) {
     if (decodeFormats == null) {
       Log.d(TAG, "decodeFormats is null");
     }
     handler = new CaptureActivityHandler(this, decodeFormats, characterSet);
   }
 }