Merge "PiP: Polish stashing physics." into sc-dev

This commit is contained in:
Ben Lin
2021-02-17 02:39:54 +00:00
committed by Android (Google) Code Review
2 changed files with 18 additions and 13 deletions

View File

@@ -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(

View File

@@ -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.