Пример #1
0
 private boolean needAutoFocusCall() {
   int focusMode = getFocusMode();
   return !(focusMode == CameraParameters.AF_MODE_INFINITY
       || focusMode == CameraParameters.AF_MODE_FIXED
       || focusMode == CameraParameters.AF_MODE_EDOF // EDOF likely
       // needs
       // auto-focus
       // call
       || focusMode == CameraParameters.AF_MODE_CONTINUOUS_PICTURE
       || focusMode == CameraParameters.AF_MODE_CONTINUOUS_VIDEO
       || focusMode == CameraParameters.MF_MODE
       || mFocusDisabled
       || mFocusLocked
       || !CameraController.isFocusModeSupported());
 }
Пример #2
0
  @Override
  public boolean onTouch(View view, MotionEvent e) {
    if (CameraController.isRemoteCamera()) {
      if (e.getAction() == MotionEvent.ACTION_UP) {
        onTouchAreas(e);
      }
      return true;
    }

    updateCurrentTouch(e);

    if (e.getPointerCount() > 1) {
      splitMode = true;
      mHandler.removeMessages(START_TOUCH_FOCUS);

      onTouchMeteringArea(e);
      onTouchFocusArea(e);

      return true;
    }

    if (splitMode && e.getAction() == MotionEvent.ACTION_DOWN) {
      mMeteringIndicatorRotateLayout.setVisibility(View.GONE);
      ApplicationScreen.instance.setCameraMeteringMode(ApplicationScreen.getMeteringMode());
      splitMode = false;
    }

    if (splitMode) {
      return true;
    }

    // Check if it's double click
    if (e.getAction() == MotionEvent.ACTION_UP) {
      lastTouchTime1 = lastTouchTime2;
      lastTouchTime2 = System.currentTimeMillis();

      if (lastTouchTime2 - lastTouchTime1 < 1000) {
        isDoubleClick = true;

        // If shot on double click
        if (ApplicationScreen.instance.isShotOnTap() == 2) {
          // Cancel delayed focus, which was created by second click
          mHandler.removeMessages(START_TOUCH_FOCUS);

          // If state is Focused start capture
          if (mState == STATE_SUCCESS) {
            String modeID = PluginManager.getInstance().getActiveMode().modeID;
            if (!modeID.equals("video") && !currentTouch) {
              ApplicationScreen.getGUIManager().onHardwareShutterButtonPressed();
              isDoubleClick = false;
            }
          }
          return true;
        }
      } else {
        isDoubleClick = false;
      }
    }

    // Not handle touch event if no need of autoFocus and refuse 'shot on
    // tap' in video mode.
    if (!mInitialized
        || mState == STATE_FOCUSING_SNAP_ON_FINISH
        || mState == STATE_INACTIVE
        || mFocusDisabled
        || !CameraController.isFocusModeSupported()
        || (!(needAutoFocusCall() || isContinuousFocusMode())
            && !(ApplicationScreen.instance.isShotOnTap() > 0
                && !PluginManager.getInstance().getActiveMode().modeID.equals("video"))))
      return false;

    // Let users be able to cancel previous touch focus.
    if ((mState == STATE_FOCUSING)
        && !delayedFocus
        && ApplicationScreen.instance.isShotOnTap() != 2) {
      focusCanceled = true;
      cancelAutoFocus();
      int fm = CameraController.getFocusMode();
      if ((preferenceFocusMode == CameraParameters.AF_MODE_CONTINUOUS_PICTURE
              || preferenceFocusMode == CameraParameters.AF_MODE_CONTINUOUS_VIDEO)
          && fm != CameraParameters.AF_MODE_UNSUPPORTED
          && preferenceFocusMode != CameraController.getFocusMode()
          && preferenceFocusMode != CameraParameters.MF_MODE) {
        CameraController.setCameraFocusMode(preferenceFocusMode);
      } else if (CameraController.isGalaxyNote3 && preferenceFocusMode != CameraParameters.MF_MODE)
      // Kind of hack to
      // prevent Note 3 of
      // permanent 'auto focus
      // failed' state
      {
        CameraController.setCameraFocusMode(CameraParameters.AF_MODE_CONTINUOUS_PICTURE);
        CameraController.setCameraFocusMode(preferenceFocusMode);
      }
      return true;
    }

    switch (e.getAction()) {
      case MotionEvent.ACTION_DOWN:
        focusCanceled = false;
        delayedFocus = false;
        X = e.getX();
        Y = e.getY();

        lastEvent = MotionEvent.obtain(e);
        mHandler.sendEmptyMessageDelayed(START_TOUCH_FOCUS, START_TOUCH_FOCUS_DELAY);

        return true;
      case MotionEvent.ACTION_MOVE:
        {
          float difX = e.getX();
          float difY = e.getY();

          if ((Math.abs(difX - X) > 50 || Math.abs(difY - Y) > 50) && !focusCanceled) {
            focusCanceled = true;
            cancelAutoFocus();
            mHandler.removeMessages(START_TOUCH_FOCUS);
            return true;
          } else return true;
        }
      case MotionEvent.ACTION_UP:
        mHandler.removeMessages(START_TOUCH_FOCUS);
        if (focusCanceled || delayedFocus) return true;
        break;
      default:
        break;
    }

    onTouchAreas(e);

    return true;
  }