diff options
author | Ben Lin <linben@google.com> | 2021-03-06 04:21:31 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2021-03-06 04:21:31 +0000 |
commit | a4cd16baad020c20ec1036e38ab7fc7b36574305 (patch) | |
tree | c28c5a7f7fe38a83dcd3a3bb7410232dbd02bbe1 | |
parent | 4c38e34d86b353fe9927fc1b47aa384e3a721c6d (diff) | |
parent | bc696ba302352a09ddfc61ea8bfb7d6e1badc63a (diff) |
Merge "PiP: Refine pinch-resizing by damping rotation." into sc-dev
-rw-r--r-- | libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java | 48 |
1 files changed, 41 insertions, 7 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java index 31057f8d5fb8..c726c012c6a0 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java @@ -65,6 +65,8 @@ public class PipResizeGestureHandler { private static final int PINCH_RESIZE_SNAP_DURATION = 250; private static final int PINCH_RESIZE_MAX_ANGLE_ROTATION = 45; private static final float PINCH_RESIZE_AUTO_MAX_RATIO = 0.9f; + private static final float OVERROTATE_DAMP_FACTOR = 0.4f; + private static final float ANGLE_THRESHOLD = 5f; private final Context mContext; private final PipBoundsAlgorithm mPipBoundsAlgorithm; @@ -423,26 +425,28 @@ public class PipResizeGestureHandler { float down1X = mDownSecondaryPoint.x; float down1Y = mDownSecondaryPoint.y; + float angle = 0; if (down0X > focusX && down0Y < focusY && down1X < focusX && down1Y > focusY) { // Top right + Bottom left pinch to zoom. - mAngle = calculateRotationAngle(mLastResizeBounds.centerX(), + angle = calculateRotationAngle(mLastResizeBounds.centerX(), mLastResizeBounds.centerY(), x0, y0, x1, y1, true); } else if (down1X > focusX && down1Y < focusY && down0X < focusX && down0Y > focusY) { // Top right + Bottom left pinch to zoom. - mAngle = calculateRotationAngle(mLastResizeBounds.centerX(), + angle = calculateRotationAngle(mLastResizeBounds.centerX(), mLastResizeBounds.centerY(), x1, y1, x0, y0, true); } else if (down0X < focusX && down0Y < focusY && down1X > focusX && down1Y > focusY) { // Top left + bottom right pinch to zoom. - mAngle = calculateRotationAngle(mLastResizeBounds.centerX(), + angle = calculateRotationAngle(mLastResizeBounds.centerX(), mLastResizeBounds.centerY(), x0, y0, x1, y1, false); } else if (down1X < focusX && down1Y < focusY && down0X > focusX && down0Y > focusY) { // Top left + bottom right pinch to zoom. - mAngle = calculateRotationAngle(mLastResizeBounds.centerX(), + angle = calculateRotationAngle(mLastResizeBounds.centerX(), mLastResizeBounds.centerY(), x1, y1, x0, y0, false); } + mAngle = angle; mLastResizeBounds.set(PipPinchResizingAlgorithm.pinchResize(x0, y0, x1, y1, mDownPoint.x, mDownPoint.y, mDownSecondaryPoint.x, mDownSecondaryPoint.y, @@ -477,10 +481,40 @@ public class PipResizeGestureHandler { } // Calculate the percentage difference of [0, 90] compare to the base angle. - double diff0 = (Math.max(0, Math.min(angle0, 90)) - baseAngle) / 90; - double diff1 = (Math.max(0, Math.min(angle1, 90)) - baseAngle) / 90; + double diff0 = (Math.max(-90, Math.min(angle0, 90)) - baseAngle) / 90; + double diff1 = (Math.max(-90, Math.min(angle1, 90)) - baseAngle) / 90; - return (float) (diff0 + diff1) / 2 * PINCH_RESIZE_MAX_ANGLE_ROTATION * (positive ? 1 : -1); + final float angle = + (float) (diff0 + diff1) / 2 * PINCH_RESIZE_MAX_ANGLE_ROTATION * (positive ? 1 : -1); + + // Remove some degrees so that user doesn't immediately start rotating until a threshold + return angle / Math.abs(angle) + * Math.max(0, (Math.abs(dampedRotate(angle)) - ANGLE_THRESHOLD)); + } + + /** + * Given the current rotation angle, dampen it so that as it approaches the maximum angle, + * dampen it. + */ + private float dampedRotate(float amount) { + if (Float.compare(amount, 0) == 0) return 0; + + float f = amount / PINCH_RESIZE_MAX_ANGLE_ROTATION; + f = f / (Math.abs(f)) * (overRotateInfluenceCurve(Math.abs(f))); + + // Clamp this factor, f, to -1 < f < 1 + if (Math.abs(f) >= 1) { + f /= Math.abs(f); + } + return OVERROTATE_DAMP_FACTOR * f * PINCH_RESIZE_MAX_ANGLE_ROTATION; + } + + /** + * Returns a value that corresponds to y = (f - 1)^3 + 1. + */ + private float overRotateInfluenceCurve(float f) { + f -= 1.0f; + return f * f * f + 1.0f; } private void onDragCornerResize(MotionEvent ev) { |