From 0e06238a6ed9f88bdc407b2512186397af9142cd Mon Sep 17 00:00:00 2001 From: Ben Lin Date: Fri, 12 Feb 2021 17:47:04 -0800 Subject: [PATCH] PiP: Polish stashing physics. - Allow user to stash via flinging toward the edge PIP is currently snapped to - Bring back velocityY when user moving from stashed -> stashed (on same edge) - Don't allow stashing from left -> right or right -> left is already stashed Bug: 178881304 Test: Manual Change-Id: Icc13998044f5870fe631487a3b4d7c123957a06a --- .../wm/shell/pip/phone/PipMotionHelper.java | 9 ++++---- .../wm/shell/pip/phone/PipTouchHandler.java | 22 ++++++++++++------- 2 files changed, 18 insertions(+), 13 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 4bcd76fdf4e64..eae8945ce6be7 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 @@ -17,8 +17,7 @@ package com.android.wm.shell.pip.phone; import static com.android.wm.shell.pip.PipAnimationController.TRANSITION_DIRECTION_EXPAND_OR_UNEXPAND; -import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_LEFT; -import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_RIGHT; +import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_NONE; import android.annotation.NonNull; import android.annotation.Nullable; @@ -371,9 +370,9 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, /** * Stash PiP to the closest edge. We set velocityY to 0 to limit pure horizontal motion. */ - void stashToEdge(float velocityX, @Nullable Runnable postBoundsUpdateCallback) { - mPipBoundsState.setStashed(velocityX < 0 ? STASH_TYPE_LEFT : STASH_TYPE_RIGHT); - movetoTarget(velocityX, 0 /* velocityY */, postBoundsUpdateCallback, true /* isStash */); + void stashToEdge(float velX, float velY, @Nullable Runnable postBoundsUpdateCallback) { + velY = mPipBoundsState.getStashedState() == STASH_TYPE_NONE ? 0 : velY; + movetoTarget(velX, velY, 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 f3875ea10b519..afc7b5294a2f7 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 @@ -19,7 +19,9 @@ package com.android.wm.shell.pip.phone; import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.PIP_STASHING; import static com.android.internal.config.sysui.SystemUiDeviceConfigFlags.PIP_STASH_MINIMUM_VELOCITY_THRESHOLD; import static com.android.wm.shell.pip.PipAnimationController.TRANSITION_DIRECTION_TO_PIP; +import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_LEFT; import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_NONE; +import static com.android.wm.shell.pip.PipBoundsState.STASH_TYPE_RIGHT; import static com.android.wm.shell.pip.phone.PhonePipMenuController.MENU_STATE_CLOSE; import static com.android.wm.shell.pip.phone.PhonePipMenuController.MENU_STATE_FULL; import static com.android.wm.shell.pip.phone.PhonePipMenuController.MENU_STATE_NONE; @@ -810,7 +812,6 @@ public class PipTouchHandler { } if (touchState.startedDragging()) { - mPipBoundsState.setStashed(STASH_TYPE_NONE); mSavedSnapFraction = -1f; mPipDismissTargetHandler.showDismissTargetMaybe(); } @@ -863,10 +864,10 @@ public class PipTouchHandler { // Reset the touch state on up before the fling settles mTouchState.reset(); - if (mEnableStash && !mPipBoundsState.isStashed() - && shouldStash(vel, getPossiblyMotionBounds())) { - mMotionHelper.stashToEdge(vel.x, this::stashEndAction /* endAction */); + if (mEnableStash && shouldStash(vel, getPossiblyMotionBounds())) { + mMotionHelper.stashToEdge(vel.x, vel.y, this::stashEndAction /* endAction */); } else { + mPipBoundsState.setStashed(STASH_TYPE_NONE); mMotionHelper.flingToSnapTarget(vel.x, vel.y, this::flingEndAction /* endAction */); } @@ -920,6 +921,11 @@ public class PipTouchHandler { && mPipExclusionBoundsChangeListener.get() != null) { mPipExclusionBoundsChangeListener.get().accept(mPipBoundsState.getBounds()); } + if (mPipBoundsState.getBounds().left < 0) { + mPipBoundsState.setStashed(STASH_TYPE_LEFT); + } else { + mPipBoundsState.setStashed(STASH_TYPE_RIGHT); + } } private void flingEndAction() { @@ -937,12 +943,12 @@ public class PipTouchHandler { private boolean shouldStash(PointF vel, Rect motionBounds) { // 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 the - // opposite edge. + // Only allow stashing to the edge if PIP wasn't previously stashed on the opposite + // edge. final boolean stashFromFlingToEdge = ((vel.x < -mStashVelocityThreshold - && mDownSavedFraction > 1f && mDownSavedFraction < 2f) + && mPipBoundsState.getStashedState() != STASH_TYPE_RIGHT) || (vel.x > mStashVelocityThreshold - && mDownSavedFraction > 3f && mDownSavedFraction < 4f)); + && mPipBoundsState.getStashedState() != STASH_TYPE_LEFT)); // If User releases the PIP window while it's out of the display bounds, put // PIP into stashed mode.