// Run the precapture sequence for capturing a still image. This method should be called when
 // we get a response in {@link #mCaptureCallback} from {@link #lockFocus()}.
 public void RunPrecaptureSequence()
 {
     try
     {
         // This is how to tell the camera to trigger.
         mPreviewRequestBuilder.Set(CaptureRequest.ControlAePrecaptureTrigger, (int)ControlAEPrecaptureTrigger.Start);
         // Tell #mCaptureCallback to wait for the precapture sequence to be set.
         mState = CameraConstants.CameraStates.STATE_WAITING_PRECAPTURE;
         mCaptureSession.Capture(mPreviewRequestBuilder.Build(), mCaptureCallback, mBackgroundHandler);
     }
     catch (CameraAccessException e)
     {
         e.PrintStackTrace();
     }
 }
 // Lock the focus as the first step for a still image capture.
 private void LockFocus()
 {
     try
     {
         mPreviewRequestBuilder.Set(CaptureRequest.ControlAfTrigger, (int)ControlAFTrigger.Start);
         // Tell #mCaptureCallback to wait for the lock.
         mState = CameraConstants.CameraStates.STATE_WAITING_LOCK;
         mCaptureSession.Capture(mPreviewRequestBuilder.Build(), mCaptureCallback,
                                 mBackgroundHandler);
     }
     catch (CameraAccessException e)
     {
         e.PrintStackTrace();
     }
 }
 // Unlock the focus. This method should be called when still image capture sequence is
 // finished.
 public void UnlockFocus()
 {
     try
     {
         if (mCaptureSession != null)
         {
             // Reset the auto-focus trigger
             mPreviewRequestBuilder.Set(CaptureRequest.ControlAfTrigger, (int)ControlAFTrigger.Cancel);
             SetAutoFlash(mPreviewRequestBuilder);
             mCaptureSession.Capture(mPreviewRequestBuilder.Build(), mCaptureCallback,
                                     mBackgroundHandler);
             // After this, the camera will go back to the normal state of preview.
             mState = CameraConstants.CameraStates.STATE_PREVIEW;
             mCaptureSession.SetRepeatingRequest(mPreviewRequest, mCaptureCallback,
                                                 mBackgroundHandler);
         }
     }
     catch (CameraAccessException e)
     {
         e.PrintStackTrace();
     }
 }