Ejemplo n.º 1
0
        @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);
          }
        }
Ejemplo n.º 2
0
        @Override
        public void run() {
          cameraManager.close();

          // cancel background thread
          cameraHandler.removeCallbacksAndMessages(null);
          cameraThread.quit();
        }
Ejemplo n.º 3
0
 @Override
 public void run() {
   cameraManager.requestPreviewFrame(
       new PreviewCallback() {
         @Override
         public void onPreviewFrame(final byte[] data, final Camera camera) {
           decode(data);
         }
       });
 }
Ejemplo n.º 4
0
        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();
          }
        }