@Override
        public void run() {
          try {
            final Camera camera = cameraManager.open(surfaceHolder, !DISABLE_CONTINUOUS_AUTOFOCUS);

            final Rect framingRect = cameraManager.getFrame();
            final Rect framingRectInPreview = cameraManager.getFramePreview();

            runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    scannerView.setFraming(framingRect, framingRectInPreview);
                  }
                });

            final String focusMode = camera.getParameters().getFocusMode();
            final boolean nonContinuousAutoFocus =
                Camera.Parameters.FOCUS_MODE_AUTO.equals(focusMode)
                    || Camera.Parameters.FOCUS_MODE_MACRO.equals(focusMode);

            if (nonContinuousAutoFocus) cameraHandler.post(new AutoFocusRunnable(camera));

            cameraHandler.post(fetchAndDecodeRunnable);
          } catch (final IOException x) {
            log.info("problem opening camera", x);
            showDialog(DIALOG_CAMERA_PROBLEM);
          } catch (final RuntimeException x) {
            log.info("problem opening camera", x);
            showDialog(DIALOG_CAMERA_PROBLEM);
          }
        }
        @Override
        public void run() {
          cameraManager.close();

          // cancel background thread
          cameraHandler.removeCallbacksAndMessages(null);
          cameraThread.quit();
        }
 @Override
 public void run() {
   cameraManager.requestPreviewFrame(
       new PreviewCallback() {
         @Override
         public void onPreviewFrame(final byte[] data, final Camera camera) {
           decode(data);
         }
       });
 }
        private void decode(final byte[] data) {
          final PlanarYUVLuminanceSource source = cameraManager.buildLuminanceSource(data);
          final BinaryBitmap bitmap = new BinaryBitmap(new HybridBinarizer(source));

          try {
            hints.put(
                DecodeHintType.NEED_RESULT_POINT_CALLBACK,
                new ResultPointCallback() {
                  @Override
                  public void foundPossibleResultPoint(final ResultPoint dot) {
                    runOnUiThread(
                        new Runnable() {
                          @Override
                          public void run() {
                            scannerView.addDot(dot);
                          }
                        });
                  }
                });
            final Result scanResult = reader.decode(bitmap, hints);

            final int thumbnailWidth = source.getThumbnailWidth();
            final int thumbnailHeight = source.getThumbnailHeight();
            final float thumbnailScaleFactor = (float) thumbnailWidth / source.getWidth();

            final Bitmap thumbnailImage =
                Bitmap.createBitmap(thumbnailWidth, thumbnailHeight, Bitmap.Config.ARGB_8888);
            thumbnailImage.setPixels(
                source.renderThumbnail(), 0, thumbnailWidth, 0, 0, thumbnailWidth, thumbnailHeight);

            runOnUiThread(
                new Runnable() {
                  @Override
                  public void run() {
                    handleResult(scanResult, thumbnailImage, thumbnailScaleFactor);
                  }
                });
          } catch (final ReaderException x) {
            // retry
            cameraHandler.post(fetchAndDecodeRunnable);
          } finally {
            reader.reset();
          }
        }