summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Ben Lin <linben@google.com> 2021-01-28 17:45:33 -0800
committer Ben Lin <linben@google.com> 2021-02-01 12:41:14 -0800
commit6930fd5cbcd2246368437d981ded419d54eb0ca5 (patch)
tree84eda92ff53bf18d90ba94176b6a2684a9633523
parentdd5d0798ff0ceb0eec4bb88e5b1baf6b29c2ad88 (diff)
PiP: Allow stashing via dropping on the edge.
Changes so that: 1) PiP now can be stashed when the user releases/let go of input when PiP is currently floating on top of the left/right edge of the device. Currently, 1/3 of the PiP needs to be off-screen in order for stash to happen. 2) Stashing is now allowed from one edge to the other (e.g. user flings from left to right, right to left), with VERY high velocity (>= 18000.f). Bug: 178752503 Test: Let go of PiP when off screen, stashes Test: fling from left to right with extremely high velocity, stashes Change-Id: Ia0b701b75f598965d79b07b10f09118f80562f09
-rw-r--r--core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java6
-rw-r--r--libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java47
2 files changed, 44 insertions, 9 deletions
diff --git a/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java b/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java
index 13358daf05a1..36993b59d2b1 100644
--- a/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java
+++ b/core/java/com/android/internal/config/sysui/SystemUiDeviceConfigFlags.java
@@ -420,6 +420,12 @@ public final class SystemUiDeviceConfigFlags {
public static final String PIP_STASHING = "pip_stashing";
/**
+ * (float) The threshold velocity to cause PiP to be stashed when flinging from one edge to the
+ * other.
+ */
+ public static final String PIP_STASH_MINIMUM_VELOCITY_THRESHOLD = "pip_velocity_threshold";
+
+ /**
* (float) Bottom height in DP for Back Gesture.
*/
public static final String BACK_GESTURE_BOTTOM_HEIGHT = "back_gesture_bottom_height";
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 128d13c2ce2e..8cfefd85ed21 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
@@ -17,6 +17,7 @@
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.phone.PhonePipMenuController.MENU_STATE_CLOSE;
import static com.android.wm.shell.pip.phone.PhonePipMenuController.MENU_STATE_FULL;
@@ -62,9 +63,8 @@ import java.util.function.Consumer;
*/
public class PipTouchHandler {
private static final String TAG = "PipTouchHandler";
-
- private static final float STASH_MINIMUM_VELOCITY_X = 3000.f;
private static final float MINIMUM_SIZE_PERCENT = 0.4f;
+ private static final float DEFAULT_STASH_VELOCITY_THRESHOLD = 18000.f;
// Allow PIP to resize to a slightly bigger state upon touch
private final boolean mEnableResize;
@@ -87,6 +87,8 @@ public class PipTouchHandler {
*/
private boolean mEnableStash = true;
+ private float mStashVelocityThreshold;
+
// The reference inset bounds, used to determine the dismiss fraction
private final Rect mInsetBounds = new Rect();
private int mExpandedShortestEdgeSize;
@@ -205,6 +207,19 @@ public class PipTouchHandler {
PIP_STASHING, /* defaultValue = */ true);
}
});
+ mStashVelocityThreshold = DeviceConfig.getFloat(
+ DeviceConfig.NAMESPACE_SYSTEMUI,
+ PIP_STASH_MINIMUM_VELOCITY_THRESHOLD,
+ DEFAULT_STASH_VELOCITY_THRESHOLD);
+ DeviceConfig.addOnPropertiesChangedListener(DeviceConfig.NAMESPACE_SYSTEMUI,
+ mainExecutor,
+ properties -> {
+ if (properties.getKeyset().contains(PIP_STASH_MINIMUM_VELOCITY_THRESHOLD)) {
+ mStashVelocityThreshold = properties.getFloat(
+ PIP_STASH_MINIMUM_VELOCITY_THRESHOLD,
+ DEFAULT_STASH_VELOCITY_THRESHOLD);
+ }
+ });
}
private void reloadResources() {
@@ -826,14 +841,8 @@ public class PipTouchHandler {
// Reset the touch state on up before the fling settles
mTouchState.reset();
- // 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))) {
+ && shouldStash(vel, getPossiblyMotionBounds())) {
mMotionHelper.stashToEdge(vel.x, this::stashEndAction /* endAction */);
} else {
mMotionHelper.flingToSnapTarget(vel.x, vel.y,
@@ -895,6 +904,26 @@ public class PipTouchHandler {
mPipExclusionBoundsChangeListener.get().accept(new Rect());
}
}
+
+ 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.
+ final boolean stashFromFlingToEdge = ((vel.x < -mStashVelocityThreshold
+ && mDownSavedFraction > 1f && mDownSavedFraction < 2f)
+ || (vel.x > mStashVelocityThreshold
+ && mDownSavedFraction > 3f && mDownSavedFraction < 4f));
+
+ // If User releases the PIP window while it's out of the display bounds, put
+ // PIP into stashed mode.
+ final int offset = motionBounds.width() / 2;
+ final boolean stashFromDroppingOnEdge =
+ (motionBounds.right > mPipBoundsState.getDisplayBounds().right + offset
+ || motionBounds.left
+ < mPipBoundsState.getDisplayBounds().left - offset);
+
+ return stashFromFlingToEdge || stashFromDroppingOnEdge;
+ }
}
void setPipExclusionBoundsChangeListener(Consumer<Rect> pipExclusionBoundsChangeListener) {