/** Send a decode request for realtime OCR mode */
  private void restartOcrPreviewAndDecode() {
    // Continue capturing camera frames
    cameraManager.startPreview();

    // Continue requesting decode of images
    cameraManager.requestOcrDecode(decodeThread.getHandler(), R.id.ocr_continuous_decode);
    activity.drawViewfinder();
  }
  void quitSynchronously() {
    setState(State.DONE);
    if (cameraManager != null) {
      cameraManager.stopPreview();
    }
    // Message quit = Message.obtain(decodeThread.getHandler(), R.id.quit);
    try {
      // quit.sendToTarget(); // This always gives "sending message to a Handler on a dead thread"

      // Wait at most half a second; should be enough time, and onPause() will timeout quickly
      decodeThread.join(500L);
    } catch (InterruptedException e) {
      Log.w(TAG, "Caught InterruptedException in quitSyncronously()", e);
      // continue
    } catch (RuntimeException e) {
      Log.w(TAG, "Caught RuntimeException in quitSyncronously()", e);
      // continue
    } catch (Exception e) {
      Log.w(TAG, "Caught unknown Exception in quitSynchronously()", e);
    }

    // Be absolutely sure we don't send any queued up messages
    removeMessages(R.id.auto_focus);
    removeMessages(R.id.ocr_continuous_decode);
    removeMessages(R.id.ocr_decode);
  }
  CaptureActivityHandler(
      CaptureActivity activity,
      CameraManager cameraManager,
      TessBaseAPI baseApi,
      boolean isContinuousModeActive) {
    this.activity = activity;
    v = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
    this.cameraManager = cameraManager;
    // Start ourselves capturing previews (and decoding if using continuous recognition mode).

    cameraManager.startPreview();

    decodeThread =
        new DecodeThread(
            activity,
            // new ViewfinderResultPointCallback(activity.getViewfinderView()),
            baseApi);
    decodeThread.start();

    /*if (isContinuousModeActive) {
      state = State.CONTINUOUS;

      // Show the shutter and torch buttons
      activity.setButtonVisibility(true);

      // Display a "be patient" message while first recognition request is running
      activity.setStatusViewForContinuous();

      cameraManager.requestAutoFocus(this, R.id.auto_focus);
      restartOcrPreviewAndDecode();
    } else {*/
    setState(State.SUCCESS);

    // Show the shutter and torch buttons
    activity.setButtonVisibility(true);

    restartOcrPreview();
    //  }
  }
 /**
  * Request autofocus from the CameraManager if we're in an appropriate state.
  *
  * @param message The message to deliver
  */
 void requestAutofocus(int message) {
   //	   setState(State.PREVIEW);
   //    if (getState() == State.PREVIEW || getState() == State.CONTINUOUS){
   //      if (getState() == State.PREVIEW) {
   //        setState(State.PREVIEW_FOCUSING);
   //      } else if (getState() == State.CONTINUOUS){
   //        setState(State.CONTINUOUS_FOCUSING);
   //      }
   cameraManager.requestAutoFocus(this, message);
   //    } else {
   //      // If we're bumping up against a user-requested focus, enqueue another focus request,
   //      // otherwise stop autofocusing until the next restartOcrPreview()
   //      if (getState() == State.PREVIEW_FOCUSING && message == R.id.auto_focus) {
   //        //Log.d(TAG, "focusing now, so Requesting a new delayed autofocus");
   //        requestDelayedAutofocus(CaptureActivity.AUTOFOCUS_FAILURE_INTERVAL_MS, message);
   //      } else if (getState() == State.CONTINUOUS_FOCUSING && message == R.id.auto_focus) {
   //        requestDelayedAutofocus(CaptureActivity.AUTOFOCUS_FAILURE_INTERVAL_MS, message);
   //      } else if (message == R.id.auto_focus) {
   //        isAutofocusLoopStarted = false;
   //      }
   //    }
 }
 /** Request OCR on the current preview frame. */
 private void ocrDecode() {
   setState(State.PREVIEW);
   cameraManager.requestOcrDecode(decodeThread.getHandler(), R.id.ocr_decode);
 }