Don't allow PiP to be interactive when stashed.

User can still move the PiP around, but disable:

- showing menu
- resizing
- double-tap gestures

Bug: 165793553
Test: Stash PIP
Change-Id: I899d8aa3ffffc4087c706f121dee69f63addc9ab
This commit is contained in:
Ben Lin
2020-10-30 18:31:03 -07:00
parent beefdec180
commit 1640ffd49d
3 changed files with 37 additions and 9 deletions

View File

@@ -37,6 +37,7 @@ public final class PipBoundsState {
private final @NonNull Rect mBounds = new Rect();
private float mAspectRatio;
private boolean mIsStashed;
private PipReentryState mPipReentryState;
private ComponentName mLastPipComponentName;
private final DisplayInfo mDisplayInfo = new DisplayInfo();
@@ -54,6 +55,20 @@ public final class PipBoundsState {
return new Rect(mBounds);
}
/**
* Dictate where PiP currently should be stashed or not.
*/
public void setStashed(boolean isStashed) {
mIsStashed = isStashed;
}
/**
* Whether PiP is stashed or not.
*/
public boolean isStashed() {
return mIsStashed;
}
public void setAspectRatio(float aspectRatio) {
mAspectRatio = aspectRatio;
}

View File

@@ -47,6 +47,7 @@ import androidx.annotation.VisibleForTesting;
import com.android.internal.policy.TaskResizingAlgorithm;
import com.android.wm.shell.R;
import com.android.wm.shell.pip.PipBoundsHandler;
import com.android.wm.shell.pip.PipBoundsState;
import com.android.wm.shell.pip.PipTaskOrganizer;
import com.android.wm.shell.pip.PipUiEventLogger;
@@ -67,6 +68,7 @@ public class PipResizeGestureHandler {
private final Context mContext;
private final PipBoundsHandler mPipBoundsHandler;
private final PipMotionHelper mMotionHelper;
private final PipBoundsState mPipBoundsState;
private final int mDisplayId;
private final Executor mMainExecutor;
private final ScaleGestureDetector mScaleGestureDetector;
@@ -107,13 +109,15 @@ public class PipResizeGestureHandler {
private int mCtrlType;
public PipResizeGestureHandler(Context context, PipBoundsHandler pipBoundsHandler,
PipMotionHelper motionHelper, PipTaskOrganizer pipTaskOrganizer,
Function<Rect, Rect> movementBoundsSupplier, Runnable updateMovementBoundsRunnable,
PipUiEventLogger pipUiEventLogger, PipMenuActivityController menuActivityController) {
PipBoundsState pipBoundsState, PipMotionHelper motionHelper,
PipTaskOrganizer pipTaskOrganizer, Function<Rect, Rect> movementBoundsSupplier,
Runnable updateMovementBoundsRunnable, PipUiEventLogger pipUiEventLogger,
PipMenuActivityController menuActivityController) {
mContext = context;
mDisplayId = context.getDisplayId();
mMainExecutor = context.getMainExecutor();
mPipBoundsHandler = pipBoundsHandler;
mPipBoundsState = pipBoundsState;
mMotionHelper = motionHelper;
mPipTaskOrganizer = pipTaskOrganizer;
mMovementBoundsSupplier = movementBoundsSupplier;
@@ -263,6 +267,11 @@ public class PipResizeGestureHandler {
}
private void onInputEvent(InputEvent ev) {
// Don't allow resize when PiP is stashed.
if (mPipBoundsState.isStashed()) {
return;
}
if (ev instanceof MotionEvent) {
if (mUsingPinchToZoom) {
mScaleGestureDetector.onTouchEvent((MotionEvent) ev);

View File

@@ -179,8 +179,8 @@ public class PipTouchHandler {
mMotionHelper = new PipMotionHelper(mContext, pipBoundsState, pipTaskOrganizer,
mMenuController, mPipBoundsHandler.getSnapAlgorithm(), floatingContentCoordinator);
mPipResizeGestureHandler =
new PipResizeGestureHandler(context, pipBoundsHandler, mMotionHelper,
pipTaskOrganizer, this::getMovementBounds,
new PipResizeGestureHandler(context, pipBoundsHandler, pipBoundsState,
mMotionHelper, pipTaskOrganizer, this::getMovementBounds,
this::updateMovementBounds, pipUiEventLogger, menuController);
mPipDismissTargetHandler = new PipDismissTargetHandler(context, pipUiEventLogger,
mMotionHelper, mHandler);
@@ -464,7 +464,7 @@ public class PipTouchHandler {
}
MotionEvent ev = (MotionEvent) inputEvent;
if (mPipResizeGestureHandler.willStartResizeGesture(ev)) {
if (!mPipBoundsState.isStashed() && mPipResizeGestureHandler.willStartResizeGesture(ev)) {
// Initialize the touch state for the gesture, but immediately reset to invalidate the
// gesture
mTouchState.onTouchEvent(ev);
@@ -554,6 +554,8 @@ public class PipTouchHandler {
}
}
shouldDeliverToMenu |= !mPipBoundsState.isStashed();
// Deliver the event to PipMenuActivity to handle button click if the menu has shown.
if (shouldDeliverToMenu) {
final MotionEvent cloneEvent = MotionEvent.obtain(ev);
@@ -716,7 +718,7 @@ public class PipTouchHandler {
// If the menu is still visible then just poke the menu
// so that it will timeout after the user stops touching it
if (mMenuState != MENU_STATE_NONE) {
if (mMenuState != MENU_STATE_NONE && !mPipBoundsState.isStashed()) {
mMenuController.pokeMenu();
}
}
@@ -728,6 +730,7 @@ public class PipTouchHandler {
}
if (touchState.startedDragging()) {
mPipBoundsState.setStashed(false);
mSavedSnapFraction = -1f;
mPipDismissTargetHandler.showDismissTargetMaybe();
}
@@ -786,12 +789,13 @@ public class PipTouchHandler {
if (mEnableStash
&& (animatingBounds.right > mPipBoundsState.getDisplayBounds().right
|| animatingBounds.left < mPipBoundsState.getDisplayBounds().left)) {
mPipBoundsState.setStashed(true);
mMotionHelper.stashToEdge(vel.x, vel.y, this::flingEndAction /* endAction */);
} else {
mMotionHelper.flingToSnapTarget(vel.x, vel.y,
this::flingEndAction /* endAction */);
}
} else if (mTouchState.isDoubleTap()) {
} else if (mTouchState.isDoubleTap() && !mPipBoundsState.isStashed()) {
// If using pinch to zoom, double-tap functions as resizing between max/min size
if (mPipResizeGestureHandler.isUsingPinchToZoom()) {
final boolean toExpand =
@@ -810,7 +814,7 @@ public class PipTouchHandler {
setTouchEnabled(false);
mMotionHelper.expandLeavePip();
}
} else if (mMenuState != MENU_STATE_FULL) {
} else if (mMenuState != MENU_STATE_FULL && !mPipBoundsState.isStashed()) {
if (!mTouchState.isWaitingForDoubleTap()) {
// User has stalled long enough for this not to be a drag or a double tap, just
// expand the menu