From 05476b3ace0505841b00c36195bcb5e30aeb1ba0 Mon Sep 17 00:00:00 2001 From: Ben Lin Date: Fri, 6 Nov 2020 12:47:07 -0800 Subject: [PATCH] Change PiP stash to be based on velocity rather than position. Also only allow stashing if user starts dragging from that edge. Bug: 165793553 Test: Stash PIP via flinging Change-Id: Icfd6d8d580cfb96b148f7712d0aedfcee1f30b2d --- .../wm/shell/pip/phone/PipMotionHelper.java | 7 +++--- .../wm/shell/pip/phone/PipTouchHandler.java | 25 ++++++++++--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java index d211d6570025a..d7b56ae74b38c 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java @@ -368,12 +368,11 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, } /** - * Stash PiP to the closest edge. + * Stash PiP to the closest edge. We set velocityY to 0 to limit pure horizontal motion. */ - void stashToEdge( - float velocityX, float velocityY, @Nullable Runnable postBoundsUpdateCallback) { + void stashToEdge(float velocityX, @Nullable Runnable postBoundsUpdateCallback) { mPipBoundsState.setStashed(velocityX < 0 ? STASH_TYPE_LEFT : STASH_TYPE_RIGHT); - movetoTarget(velocityX, velocityY, postBoundsUpdateCallback, true /* isStash */); + movetoTarget(velocityX, 0 /* velocityY */, postBoundsUpdateCallback, true /* isStash */); } private void movetoTarget( diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java index ae1dd3873bded..b8d6b3cab8839 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java @@ -64,11 +64,7 @@ import java.util.function.Consumer; public class PipTouchHandler { private static final String TAG = "PipTouchHandler"; - /** Duration of the dismiss scrim fading in/out. */ - private static final int DISMISS_TRANSITION_DURATION_MS = 200; - - /* The multiplier to apply scale the target size by when applying the magnetic field radius */ - private static final float MAGNETIC_FIELD_RADIUS_MULTIPLIER = 1.25f; + private static final float STASH_MINIMUM_VELOCITY_X = 3000.f; // Allow PIP to resize to a slightly bigger state upon touch private final boolean mEnableResize; @@ -710,6 +706,7 @@ public class PipTouchHandler { private final Point mStartPosition = new Point(); private final PointF mDelta = new PointF(); private boolean mShouldHideMenuAfterFling; + private float mDownSavedFraction = -1f; @Override public void onDown(PipTouchState touchState) { @@ -722,6 +719,7 @@ public class PipTouchHandler { mStartPosition.set(bounds.left, bounds.top); mMovementWithinDismiss = touchState.getDownTouchPosition().y >= mMovementBounds.bottom; mMotionHelper.setSpringingToTouch(false); + mDownSavedFraction = mPipBoundsHandler.getSnapFraction(mPipBoundsState.getBounds()); // If the menu is still visible then just poke the menu // so that it will timeout after the user stops touching it @@ -790,13 +788,15 @@ public class PipTouchHandler { // Reset the touch state on up before the fling settles mTouchState.reset(); - final Rect animatingBounds = getPossiblyAnimatingBounds(); - // If User releases the PIP window while it's out of the display bounds, put - // PIP into stashed mode. - if (mEnableStash - && (animatingBounds.right > mPipBoundsState.getDisplayBounds().right - || animatingBounds.left < mPipBoundsState.getDisplayBounds().left)) { - mMotionHelper.stashToEdge(vel.x, vel.y, this::stashEndAction /* endAction */); + // If user flings the PIP window above the minimum velocity, stash PIP. + // Only allow stashing to the edge if the user starts dragging the PIP from that + // edge. + if (mEnableStash && !mPipBoundsState.isStashed() + && ((vel.x > STASH_MINIMUM_VELOCITY_X + && mDownSavedFraction > 1f && mDownSavedFraction < 2f) + || (vel.x < -STASH_MINIMUM_VELOCITY_X + && mDownSavedFraction > 3f && mDownSavedFraction < 4f))) { + mMotionHelper.stashToEdge(vel.x, this::stashEndAction /* endAction */); } else { mMotionHelper.flingToSnapTarget(vel.x, vel.y, this::flingEndAction /* endAction */); @@ -834,6 +834,7 @@ public class PipTouchHandler { mTouchState.scheduleDoubleTapTimeoutCallback(); } } + mDownSavedFraction = -1f; return true; }