@Override
  public void onShutterClick() {
    if (needAutoFocusCall() && !focusOnShutterDisabled()) {
      if (mState == STATE_IDLE
          && !(preferenceFocusMode == CameraParameters.AF_MODE_CONTINUOUS_PICTURE
              || preferenceFocusMode == CameraParameters.AF_MODE_CONTINUOUS_VIDEO)
          && !ApplicationScreen.instance.getAutoFocusLock()) {
        if (preferenceFocusMode == CameraParameters.AF_MODE_CONTINUOUS_PICTURE
            || preferenceFocusMode == CameraParameters.AF_MODE_CONTINUOUS_VIDEO) {
          CameraController.setCameraFocusMode(CameraParameters.AF_MODE_AUTO);
        }
        setFocusParameters();
        setMeteringParameters();
        autoFocus();
      } else if (mState == STATE_FAIL) ApplicationScreen.getGUIManager().lockControls = false;
    } else {
      int focusMode = getFocusMode();
      if (focusMode == CameraParameters.AF_MODE_CONTINUOUS_PICTURE
          && (CameraController.isGalaxyS6
              || CameraController.isGalaxyS5
              || CameraController.isGalaxyNote4)) {
        final int[] supported_focus = CameraController.getSupportedFocusModes();
        int afMode = -1;
        if (CameraController.isModeAvailable(supported_focus, CameraParameters.AF_MODE_AUTO))
          afMode = CameraParameters.AF_MODE_AUTO;
        else if (CameraController.isModeAvailable(supported_focus, CameraParameters.AF_MODE_MACRO))
          afMode = CameraParameters.AF_MODE_MACRO;
        else afMode = supported_focus[0];

        CameraController.setCameraFocusMode(afMode);
        ApplicationScreen.instance.setAutoFocusLock(true);
      }
    }
  }
  @Override
  public void onCameraParametersSetup() {
    // replace here with [CF] mode as default.
    // Also, check if [CF] is available, and if not - set [AF], if [AF] is
    // not available - set first available
    preferenceFocusMode =
        ApplicationScreen.instance.getFocusModePref(ApplicationScreen.sDefaultFocusValue);

    int[] supportedFocusModes = CameraController.getSupportedFocusModes();
    if (supportedFocusModes != null && supportedFocusModes.length > 0) {
      if (!CameraController.isModeAvailable(supportedFocusModes, preferenceFocusMode)
          && preferenceFocusMode != CameraParameters.MF_MODE) {
        if (CameraController.isModeAvailable(supportedFocusModes, CameraParameters.AF_MODE_AUTO))
          preferenceFocusMode = CameraParameters.AF_MODE_AUTO;
        else preferenceFocusMode = supportedFocusModes[0];
      }
    }

    initializeParameters();

    initialize(CameraController.isFrontCamera(), 90);
    initializeSoundPlayers(
        ApplicationScreen.getAppResources().openRawResourceFd(R.raw.plugin_vf_focus_ok),
        ApplicationScreen.getAppResources().openRawResourceFd(R.raw.plugin_vf_focus_false));

    cancelAutoFocus();

    // Set the length of focus indicator according to preview frame size.
    int len = Math.min(mPreviewWidth, mPreviewHeight) / 25;
    ViewGroup.LayoutParams layout = mFocusIndicator.getLayoutParams();
    layout.width =
        (int)
            (len
                * ApplicationScreen.getAppResources()
                    .getInteger(R.integer.focusIndicator_cropFactor));
    layout.height =
        (int)
            (len
                * ApplicationScreen.getAppResources()
                    .getInteger(R.integer.focusIndicator_cropFactor));
    mFocusIndicator.requestLayout();

    layout = mMeteringIndicator.getLayoutParams();
    layout.width =
        (int)
            (len
                * ApplicationScreen.getAppResources()
                    .getInteger(R.integer.focusIndicator_cropFactor));
    layout.height =
        (int)
            (len
                * ApplicationScreen.getAppResources()
                    .getInteger(R.integer.focusIndicator_cropFactor));
    mMeteringIndicator.requestLayout();
  }