Example #1
0
 /*
  * For some reason, it's very difficult to create a layout that covers exactly the entire screen
  * and doesn't move when an unhandled key is pressed. The configuration we're using seems to
  * result in a layout that starts above the screen. So we split initialization into two
  * pieces, and here we find out where the overlay ended up and move it to be at the top
  * of the screen.
  * TODO(pweaver) Separating the menu and highlighting should be a cleaner way to solve this
  * issue
  */
 private void configureOverlayAfterShow() {
   int[] location = new int[2];
   mRelativeLayout.getLocationOnScreen(location);
   WindowManager.LayoutParams layoutParams = mOverlay.getParams();
   layoutParams.y -= location[1];
   mOverlay.setParams(layoutParams);
 }
  public void onTouchMeteringArea(MotionEvent e) {
    if (!mMeteringAreaSupported || CameraController.isGalaxyNote3) {
      if (e.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN
          || e.getActionMasked() == MotionEvent.ACTION_DOWN)
        Toast.makeText(
                ApplicationScreen.instance,
                R.string.manual_exposure_unsupported,
                Toast.LENGTH_SHORT)
            .show();

      return;
    }

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

    if (e.getPointerCount() > 1) {
      final int location[] = {0, 0};
      focusLayout.getLocationOnScreen(location);
      xRaw = (int) e.getX(1) + location[0];
      yRaw = (int) e.getY(1) + location[1];
    }

    int meteringWidth = mMeteringIndicatorRotateLayout.getWidth();
    int meteringHeight = mMeteringIndicatorRotateLayout.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 paramsLayoutHeight = 0;

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

    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) mMeteringIndicatorRotateLayout.getLayoutParams();
    int left =
        Util.clamp(
            xRaw - meteringWidth / 2 + xOffset,
            diffWidth / 2,
            (previewWidth - meteringWidth + xOffset * 2) - diffWidth / 2);
    int top =
        Util.clamp(
            yRaw - meteringHeight / 2 + yOffset - diffHeight / 2,
            0,
            previewHeight - meteringHeight + yOffset * 2);

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

    mMeteringIndicatorRotateLayout.setLayoutParams(p);

    // Convert the coordinates to driver format.
    calculateTapAreaByTopLeft(
        meteringWidth,
        meteringHeight,
        1f,
        top,
        left,
        ApplicationScreen.getPreviewSurfaceView().getWidth(),
        ApplicationScreen.getPreviewSurfaceView().getHeight(),
        mMeteringArea.get(0).rect);

    // Set the focus area and metering area.
    if (e.getActionMasked() == MotionEvent.ACTION_POINTER_DOWN
        || e.getActionMasked() == MotionEvent.ACTION_DOWN) {
      mMeteringIndicatorRotateLayout.setVisibility(View.VISIBLE);
    }

    if (e.getActionMasked() == MotionEvent.ACTION_POINTER_UP
        || e.getActionMasked() == MotionEvent.ACTION_UP) {
      setMeteringParameters();
    }

    mMeteringIndicatorRotateLayout.requestLayout();
  }
  public void onTouchFocusArea(MotionEvent e) {
    if (!mFocusAreaSupported) return;

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

    if (e.getPointerCount() > 1) {
      final int location[] = {0, 0};
      focusLayout.getLocationOnScreen(location);
      xRaw = (int) e.getX(0) + location[0];
      yRaw = (int) e.getY(0) + location[1];
    }

    // 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 paramsLayoutHeight = 0;

    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));
    }

    // 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);

    // Set the focus area and metering area.
    if (mFocusAreaSupported
        && (e.getActionMasked() == MotionEvent.ACTION_UP
            || e.getActionMasked() == MotionEvent.ACTION_POINTER_UP)) {
      setFocusParameters();

      int focusMode = CameraController.getFocusMode();
      if (focusMode == CameraParameters.AF_MODE_AUTO
          || focusMode == CameraParameters.AF_MODE_MACRO) {
        CameraController.cancelAutoFocus();
        autoFocus();
      } else {
        mState = STATE_FOCUSING;
        updateFocusUI();
      }
    }
    mFocusIndicatorRotateLayout.requestLayout();
  }