Пример #1
0
  @Override
  public void onGUICreate() {
    ApplicationScreen.getGUIManager().removeViews(modeSwitcher, R.id.specialPluginsLayout3);

    RelativeLayout.LayoutParams params =
        new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    params.addRule(RelativeLayout.ALIGN_PARENT_TOP);
    params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);

    if (!CameraController.isRemoteCamera()) {
      ((RelativeLayout) ApplicationScreen.instance.findViewById(R.id.specialPluginsLayout3))
          .addView(this.modeSwitcher, params);
    }

    this.modeSwitcher.setLayoutParams(params);

    if (ModePreference.compareTo("0") == 0)
      ApplicationScreen.getGUIManager()
          .showHelp(
              "Dro help",
              ApplicationScreen.getAppResources().getString(R.string.Dro_Help),
              R.drawable.plugin_help_dro,
              "droShowHelp");
  }
Пример #2
0
  @Override
  public void onCameraParametersSetup() {
    SharedPreferences prefs =
        PreferenceManager.getDefaultSharedPreferences(ApplicationScreen.getMainContext());
    if (ModePreference.equals("0")) {
      // FixMe: why not setting exposure if we are in dro-off mode?
      UpdateEv(true, singleModeEV);
    }

    if (CameraController.isRemoteCamera()) {
      Size imageSize = CameraController.getCameraImageSize();
      CameraController.setPictureSize(imageSize.getWidth(), imageSize.getHeight());
    }
  }
Пример #3
0
 @Override
 public void onStop() {
   if (!CameraController.isRemoteCamera()) {
     ApplicationScreen.getGUIManager().removeViews(modeSwitcher, R.id.specialPluginsLayout3);
   }
 }
Пример #4
0
  public void onTouchFocusAndMeteringArea(MotionEvent e) {
    if (!mFocusAreaSupported) return;

    int xRaw = (int) e.getRawX();
    int yRaw = (int) e.getRawY();

    // Initialize variables.
    int focusWidth = mFocusIndicatorRotateLayout.getWidth();
    int focusHeight = mFocusIndicatorRotateLayout.getHeight();
    int previewWidth = mPreviewWidth;
    int previewHeight = mPreviewHeight;
    int displayWidth = ApplicationScreen.getAppResources().getDisplayMetrics().widthPixels;
    int displayHeight = ApplicationScreen.getAppResources().getDisplayMetrics().heightPixels;
    int diffWidth = displayWidth - previewWidth;
    int diffHeight = displayHeight - previewHeight;

    // Initialize variables.
    int xOffset = (focusLayout.getWidth() - previewWidth) / 2;
    int yOffset = (focusLayout.getHeight() - previewHeight) / 2;

    if (mFocusArea == null) {
      mFocusArea = new ArrayList<Area>();
      mFocusArea.add(new Area(new Rect(), 1000));
    }

    if (mMeteringArea == null) {
      mMeteringArea = new ArrayList<Area>();
      mMeteringArea.add(new Area(new Rect(), 1000));
    }

    // Use margin to set the metering indicator to the touched area.
    RelativeLayout.LayoutParams p =
        (RelativeLayout.LayoutParams) mFocusIndicatorRotateLayout.getLayoutParams();
    int left =
        Util.clamp(
            xRaw - focusWidth / 2 + xOffset,
            diffWidth / 2,
            (previewWidth - focusWidth + xOffset * 2) - diffWidth / 2);
    int top =
        Util.clamp(
            yRaw - focusHeight / 2 + yOffset - diffHeight / 2,
            0,
            previewHeight - focusHeight + yOffset * 2);

    p.leftMargin = left;
    p.topMargin = top;

    int[] rules = p.getRules();
    rules[RelativeLayout.CENTER_IN_PARENT] = 0;

    mFocusIndicatorRotateLayout.setLayoutParams(p);

    calculateTapAreaByTopLeft(
        focusWidth,
        focusHeight,
        1f,
        top,
        left,
        ApplicationScreen.getPreviewSurfaceView().getWidth(),
        ApplicationScreen.getPreviewSurfaceView().getHeight(),
        mFocusArea.get(0).rect);

    if (ApplicationScreen.getMeteringMode() != -1
        && ApplicationScreen.getMeteringMode() == CameraParameters.meteringModeSpot)
      calculateTapAreaByTopLeft(
          focusWidth,
          focusHeight,
          1f,
          top,
          left,
          ApplicationScreen.getPreviewSurfaceView().getWidth(),
          ApplicationScreen.getPreviewSurfaceView().getHeight(),
          mMeteringArea.get(0).rect);
    else mMeteringArea = null;

    // Set the focus area and metering area.
    if ((mFocusAreaSupported && needAutoFocusCall() && (e.getAction() == MotionEvent.ACTION_UP))
        || CameraController.isRemoteCamera()) {
      CameraController.cancelAutoFocus();
      if (preferenceFocusMode == CameraParameters.AF_MODE_CONTINUOUS_PICTURE
          || preferenceFocusMode == CameraParameters.AF_MODE_CONTINUOUS_VIDEO) {
        CameraController.setCameraFocusMode(CameraParameters.AF_MODE_AUTO);
      }

      setFocusParameters();
      setMeteringParameters();
      autoFocus();

    } else if (e.getAction() == MotionEvent.ACTION_UP
        && ApplicationScreen.instance.isShotOnTap() == 1
        && !PluginManager.getInstance().getActiveMode().modeID.equals("video")
        && !currentTouch) {

      ApplicationScreen.getGUIManager().onHardwareShutterButtonPressed();
    } else if (e.getAction() == MotionEvent.ACTION_UP
        && ApplicationScreen.instance.isShotOnTap() == 2
        && !PluginManager.getInstance().getActiveMode().modeID.equals("video")
        && !currentTouch) {
      if (isDoubleClick) {
        ApplicationScreen.getGUIManager().onHardwareShutterButtonPressed();
        isDoubleClick = false;
      }
    } else if (e.getAction()
        == MotionEvent.ACTION_UP) { // Just show the indicator in all other cases.
      autoFocus();
      // updateFocusUI();
      // Reset the metering area in 3 seconds.
      mHandler.removeMessages(RESET_TOUCH_FOCUS);
      mHandler.sendEmptyMessageDelayed(RESET_TOUCH_FOCUS, RESET_TOUCH_FOCUS_DELAY);
    }

    mFocusIndicatorRotateLayout.requestLayout();
  }
Пример #5
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;
  }
Пример #6
0
 public void setFocusParameters() {
   if (mFocusAreaSupported || CameraController.isRemoteCamera())
     CameraController.setCameraFocusAreas(getFocusAreas());
 }