diff options
| author | 2021-05-17 17:44:23 -0700 | |
|---|---|---|
| committer | 2021-05-18 11:23:04 -0700 | |
| commit | ef11620ccfe17d723a5c88b1f49b9b253b046864 (patch) | |
| tree | af9b713f2b9b787ec7712f457281ccf13c7b99a8 | |
| parent | 63e732e89e6121b46f06efe33b55d29640566bdb (diff) | |
Snap the PIP window to the left or right edge after pinch resize
Restrict the PIP resize to the left and right edges only,
instead of allowing the top or bottom edges as snap targets.
Bug: 186610221
Test: pinch to resize and let go at the center top or bottom
edge - verify it snaps to either side of the screen
Change-Id: Ifbc96fddc000ccb2ae344755a9276f24e67d4571
| -rw-r--r-- | libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsAlgorithm.java | 10 | ||||
| -rw-r--r-- | libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java | 13 |
2 files changed, 21 insertions, 2 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsAlgorithm.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsAlgorithm.java index 7b834b294bb9..046c32071358 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsAlgorithm.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsAlgorithm.java @@ -367,7 +367,15 @@ public class PipBoundsAlgorithm { * the default stack bounds when first entering PiP. */ public float getSnapFraction(Rect stackBounds) { - return mSnapAlgorithm.getSnapFraction(stackBounds, getMovementBounds(stackBounds)); + return getSnapFraction(stackBounds, getMovementBounds(stackBounds)); + } + + /** + * @return the default snap fraction to apply instead of the default gravity when calculating + * the default stack bounds when first entering PiP. + */ + public float getSnapFraction(Rect stackBounds, Rect movementBounds) { + return mSnapAlgorithm.getSnapFraction(stackBounds, movementBounds); } /** 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 0878f54b7d27..ff5aeee5f521 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 @@ -514,7 +514,18 @@ public class PipResizeGestureHandler { || mLastResizeBounds.height() >= PINCH_RESIZE_AUTO_MAX_RATIO * mMaxSize.y) { resizeRectAboutCenter(mLastResizeBounds, mMaxSize.x, mMaxSize.y); } - final float snapFraction = mPipBoundsAlgorithm.getSnapFraction(mLastResizeBounds); + final int leftEdge = mLastResizeBounds.left; + final Rect movementBounds = + mPipBoundsAlgorithm.getMovementBounds(mLastResizeBounds); + final int fromLeft = Math.abs(leftEdge - movementBounds.left); + final int fromRight = Math.abs(movementBounds.right - leftEdge); + // The PIP will be snapped to either the right or left edge, so calculate which one + // is closest to the current position. + final int newLeft = fromLeft < fromRight + ? movementBounds.left : movementBounds.right; + mLastResizeBounds.offsetTo(newLeft, mLastResizeBounds.top); + final float snapFraction = mPipBoundsAlgorithm.getSnapFraction( + mLastResizeBounds, movementBounds); mPipBoundsAlgorithm.applySnapFraction(mLastResizeBounds, snapFraction); mPipTaskOrganizer.scheduleAnimateResizePip(startBounds, mLastResizeBounds, PINCH_RESIZE_SNAP_DURATION, mAngle, callback); |