@Override
  public void onAutoFocus(boolean focused) {
    if (mState == STATE_FOCUSING_SNAP_ON_FINISH) {
      // Take the picture no matter focus succeeds or fails. No need
      // to play the AF sound if we're about to play the shutter
      // sound.
      if (focused) {
        mState = STATE_SUCCESS;
      } else {
        mState = STATE_FAIL;
        ApplicationScreen.getGUIManager().lockControls = false;
      }
      updateFocusUI();
    } else if (mState == STATE_FOCUSING) {
      // This happens when (1) user is half-pressing the focus key or
      // (2) touch focus is triggered. Play the focus tone. Do not
      // take the picture now.
      if (focused) {
        mState = STATE_SUCCESS;
        /*
         * Note: we are always using full-focus scan, even in continuous
         * modes
         *
         * // Do not play the sound in continuous autofocus mode. It
         * does // not do a full scan. The focus callback arrives before
         * doSnap // so the state is always STATE_FOCUSING. if
         * (!Parameters.FOCUS_MODE_CONTINUOUS_PICTURE.equals(mFocusMode)
         * && mSoundPlayerOK != null)
         */
        if (mSoundPlayerOK != null && !splitMode && !currentTouch)
          if (!ApplicationScreen.instance.isShutterSoundEnabled()
              && !ApplicationScreen.getPluginManager().muteSounds()) mSoundPlayerOK.play();

        // With enabled preference 'Shot on tap' perform shutter button
        // click after success focusing.
        String modeID = PluginManager.getInstance().getActiveMode().modeID;
        if (ApplicationScreen.instance.isShotOnTap() == 1
            && !modeID.equals("video")
            && !splitMode
            && !currentTouch) ApplicationScreen.getGUIManager().onHardwareShutterButtonPressed();

        if (ApplicationScreen.instance.isShotOnTap() == 2
            && !modeID.equals("video")
            && !splitMode
            && !currentTouch) {
          if (isDoubleClick) {
            ApplicationScreen.getGUIManager().onHardwareShutterButtonPressed();
            isDoubleClick = false;
          }
        }
      } else {
        if (mSoundPlayerFalse != null)
          if (!ApplicationScreen.instance.isShutterSoundEnabled()
              && !PluginManager.getInstance().muteSounds()) mSoundPlayerFalse.play();
        mState = STATE_FAIL;
      }
      updateFocusUI();

      if (!splitMode) mHandler.sendEmptyMessageDelayed(RESET_TOUCH_FOCUS, RESET_TOUCH_FOCUS_DELAY);
      // If this is triggered by touch focus, cancel focus after a
      // while.
    } else if (mState == STATE_IDLE) {
      // User has released the focus key before focus completes.
      // Do nothing.
    }
  }