Merge "Disable touch events until resize bounds commit" into udc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
a584474ac4
@@ -70,6 +70,7 @@ public class PipResizeGestureHandler {
|
|||||||
private final PipBoundsAlgorithm mPipBoundsAlgorithm;
|
private final PipBoundsAlgorithm mPipBoundsAlgorithm;
|
||||||
private final PipMotionHelper mMotionHelper;
|
private final PipMotionHelper mMotionHelper;
|
||||||
private final PipBoundsState mPipBoundsState;
|
private final PipBoundsState mPipBoundsState;
|
||||||
|
private final PipTouchState mPipTouchState;
|
||||||
private final PipTaskOrganizer mPipTaskOrganizer;
|
private final PipTaskOrganizer mPipTaskOrganizer;
|
||||||
private final PhonePipMenuController mPhonePipMenuController;
|
private final PhonePipMenuController mPhonePipMenuController;
|
||||||
private final PipDismissTargetHandler mPipDismissTargetHandler;
|
private final PipDismissTargetHandler mPipDismissTargetHandler;
|
||||||
@@ -104,7 +105,6 @@ public class PipResizeGestureHandler {
|
|||||||
private boolean mAllowGesture;
|
private boolean mAllowGesture;
|
||||||
private boolean mIsAttached;
|
private boolean mIsAttached;
|
||||||
private boolean mIsEnabled;
|
private boolean mIsEnabled;
|
||||||
private boolean mEnableTouch;
|
|
||||||
private boolean mEnablePinchResize;
|
private boolean mEnablePinchResize;
|
||||||
private boolean mEnableDragCornerResize;
|
private boolean mEnableDragCornerResize;
|
||||||
private boolean mIsSysUiStateValid;
|
private boolean mIsSysUiStateValid;
|
||||||
@@ -122,7 +122,8 @@ public class PipResizeGestureHandler {
|
|||||||
|
|
||||||
public PipResizeGestureHandler(Context context, PipBoundsAlgorithm pipBoundsAlgorithm,
|
public PipResizeGestureHandler(Context context, PipBoundsAlgorithm pipBoundsAlgorithm,
|
||||||
PipBoundsState pipBoundsState, PipMotionHelper motionHelper,
|
PipBoundsState pipBoundsState, PipMotionHelper motionHelper,
|
||||||
PipTaskOrganizer pipTaskOrganizer, PipDismissTargetHandler pipDismissTargetHandler,
|
PipTouchState pipTouchState, PipTaskOrganizer pipTaskOrganizer,
|
||||||
|
PipDismissTargetHandler pipDismissTargetHandler,
|
||||||
Function<Rect, Rect> movementBoundsSupplier, Runnable updateMovementBoundsRunnable,
|
Function<Rect, Rect> movementBoundsSupplier, Runnable updateMovementBoundsRunnable,
|
||||||
PipUiEventLogger pipUiEventLogger, PhonePipMenuController menuActivityController,
|
PipUiEventLogger pipUiEventLogger, PhonePipMenuController menuActivityController,
|
||||||
ShellExecutor mainExecutor) {
|
ShellExecutor mainExecutor) {
|
||||||
@@ -132,6 +133,7 @@ public class PipResizeGestureHandler {
|
|||||||
mPipBoundsAlgorithm = pipBoundsAlgorithm;
|
mPipBoundsAlgorithm = pipBoundsAlgorithm;
|
||||||
mPipBoundsState = pipBoundsState;
|
mPipBoundsState = pipBoundsState;
|
||||||
mMotionHelper = motionHelper;
|
mMotionHelper = motionHelper;
|
||||||
|
mPipTouchState = pipTouchState;
|
||||||
mPipTaskOrganizer = pipTaskOrganizer;
|
mPipTaskOrganizer = pipTaskOrganizer;
|
||||||
mPipDismissTargetHandler = pipDismissTargetHandler;
|
mPipDismissTargetHandler = pipDismissTargetHandler;
|
||||||
mMovementBoundsSupplier = movementBoundsSupplier;
|
mMovementBoundsSupplier = movementBoundsSupplier;
|
||||||
@@ -139,7 +141,6 @@ public class PipResizeGestureHandler {
|
|||||||
mPhonePipMenuController = menuActivityController;
|
mPhonePipMenuController = menuActivityController;
|
||||||
mPipUiEventLogger = pipUiEventLogger;
|
mPipUiEventLogger = pipUiEventLogger;
|
||||||
mPinchResizingAlgorithm = new PipPinchResizingAlgorithm();
|
mPinchResizingAlgorithm = new PipPinchResizingAlgorithm();
|
||||||
mEnableTouch = true;
|
|
||||||
|
|
||||||
mUpdateResizeBoundsCallback = (rect) -> {
|
mUpdateResizeBoundsCallback = (rect) -> {
|
||||||
mUserResizeBounds.set(rect);
|
mUserResizeBounds.set(rect);
|
||||||
@@ -250,8 +251,8 @@ public class PipResizeGestureHandler {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mEnableTouch) {
|
if (!mPipTouchState.getAllowInputEvents()) {
|
||||||
// No need to handle anything if touches are not enabled for resizing.
|
// No need to handle anything if touches are not enabled
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -588,13 +589,13 @@ public class PipResizeGestureHandler {
|
|||||||
mLastResizeBounds, movementBounds);
|
mLastResizeBounds, movementBounds);
|
||||||
mPipBoundsAlgorithm.applySnapFraction(mLastResizeBounds, snapFraction);
|
mPipBoundsAlgorithm.applySnapFraction(mLastResizeBounds, snapFraction);
|
||||||
|
|
||||||
// disable the resizing until the final bounds are updated
|
// disable any touch events beyond resizing too
|
||||||
mEnableTouch = false;
|
mPipTouchState.setAllowInputEvents(false);
|
||||||
|
|
||||||
mPipTaskOrganizer.scheduleAnimateResizePip(startBounds, mLastResizeBounds,
|
mPipTaskOrganizer.scheduleAnimateResizePip(startBounds, mLastResizeBounds,
|
||||||
PINCH_RESIZE_SNAP_DURATION, mAngle, mUpdateResizeBoundsCallback, () -> {
|
PINCH_RESIZE_SNAP_DURATION, mAngle, mUpdateResizeBoundsCallback, () -> {
|
||||||
// reset the pinch resizing to its default state
|
// enable touch events
|
||||||
mEnableTouch = true;
|
mPipTouchState.setAllowInputEvents(true);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
mPipTaskOrganizer.scheduleFinishResizePip(mLastResizeBounds,
|
mPipTaskOrganizer.scheduleFinishResizePip(mLastResizeBounds,
|
||||||
|
|||||||
@@ -199,11 +199,6 @@ public class PipTouchHandler {
|
|||||||
mMotionHelper = pipMotionHelper;
|
mMotionHelper = pipMotionHelper;
|
||||||
mPipDismissTargetHandler = new PipDismissTargetHandler(context, pipUiEventLogger,
|
mPipDismissTargetHandler = new PipDismissTargetHandler(context, pipUiEventLogger,
|
||||||
mMotionHelper, mainExecutor);
|
mMotionHelper, mainExecutor);
|
||||||
mPipResizeGestureHandler =
|
|
||||||
new PipResizeGestureHandler(context, pipBoundsAlgorithm, pipBoundsState,
|
|
||||||
mMotionHelper, pipTaskOrganizer, mPipDismissTargetHandler,
|
|
||||||
this::getMovementBounds, this::updateMovementBounds, pipUiEventLogger,
|
|
||||||
menuController, mainExecutor);
|
|
||||||
mTouchState = new PipTouchState(ViewConfiguration.get(context),
|
mTouchState = new PipTouchState(ViewConfiguration.get(context),
|
||||||
() -> {
|
() -> {
|
||||||
if (mPipBoundsState.isStashed()) {
|
if (mPipBoundsState.isStashed()) {
|
||||||
@@ -220,6 +215,11 @@ public class PipTouchHandler {
|
|||||||
},
|
},
|
||||||
menuController::hideMenu,
|
menuController::hideMenu,
|
||||||
mainExecutor);
|
mainExecutor);
|
||||||
|
mPipResizeGestureHandler =
|
||||||
|
new PipResizeGestureHandler(context, pipBoundsAlgorithm, pipBoundsState,
|
||||||
|
mMotionHelper, mTouchState, pipTaskOrganizer, mPipDismissTargetHandler,
|
||||||
|
this::getMovementBounds, this::updateMovementBounds, pipUiEventLogger,
|
||||||
|
menuController, mainExecutor);
|
||||||
mConnection = new PipAccessibilityInteractionConnection(mContext, pipBoundsState,
|
mConnection = new PipAccessibilityInteractionConnection(mContext, pipBoundsState,
|
||||||
mMotionHelper, pipTaskOrganizer, mPipBoundsAlgorithm.getSnapAlgorithm(),
|
mMotionHelper, pipTaskOrganizer, mPipBoundsAlgorithm.getSnapAlgorithm(),
|
||||||
this::onAccessibilityShowMenu, this::updateMovementBounds,
|
this::onAccessibilityShowMenu, this::updateMovementBounds,
|
||||||
@@ -556,6 +556,11 @@ public class PipTouchHandler {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// do not process input event if not allowed
|
||||||
|
if (!mTouchState.getAllowInputEvents()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
MotionEvent ev = (MotionEvent) inputEvent;
|
MotionEvent ev = (MotionEvent) inputEvent;
|
||||||
if (!mPipBoundsState.isStashed() && mPipResizeGestureHandler.willStartResizeGesture(ev)) {
|
if (!mPipBoundsState.isStashed() && mPipResizeGestureHandler.willStartResizeGesture(ev)) {
|
||||||
// Initialize the touch state for the gesture, but immediately reset to invalidate the
|
// Initialize the touch state for the gesture, but immediately reset to invalidate the
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ public class PipTouchState {
|
|||||||
private final PointF mLastDelta = new PointF();
|
private final PointF mLastDelta = new PointF();
|
||||||
private final PointF mVelocity = new PointF();
|
private final PointF mVelocity = new PointF();
|
||||||
private boolean mAllowTouches = true;
|
private boolean mAllowTouches = true;
|
||||||
|
|
||||||
|
// Set to false to block both PipTouchHandler and PipResizeGestureHandler's input processing
|
||||||
|
private boolean mAllowInputEvents = true;
|
||||||
private boolean mIsUserInteracting = false;
|
private boolean mIsUserInteracting = false;
|
||||||
// Set to true only if the multiple taps occur within the double tap timeout
|
// Set to true only if the multiple taps occur within the double tap timeout
|
||||||
private boolean mIsDoubleTap = false;
|
private boolean mIsDoubleTap = false;
|
||||||
@@ -76,6 +79,20 @@ public class PipTouchState {
|
|||||||
mMainExecutor = mainExecutor;
|
mMainExecutor = mainExecutor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if input processing is enabled for PiP in general.
|
||||||
|
*/
|
||||||
|
public boolean getAllowInputEvents() {
|
||||||
|
return mAllowInputEvents;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param allowInputEvents true to enable input processing for PiP in general.
|
||||||
|
*/
|
||||||
|
public void setAllowInputEvents(boolean allowInputEvents) {
|
||||||
|
mAllowInputEvents = allowInputEvents;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resets this state.
|
* Resets this state.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ import android.graphics.Rect;
|
|||||||
import android.testing.AndroidTestingRunner;
|
import android.testing.AndroidTestingRunner;
|
||||||
import android.testing.TestableLooper;
|
import android.testing.TestableLooper;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
import android.view.ViewConfiguration;
|
||||||
|
|
||||||
import androidx.test.filters.SmallTest;
|
import androidx.test.filters.SmallTest;
|
||||||
|
|
||||||
@@ -90,6 +91,8 @@ public class PipResizeGestureHandlerTest extends ShellTestCase {
|
|||||||
|
|
||||||
private PipDisplayLayoutState mPipDisplayLayoutState;
|
private PipDisplayLayoutState mPipDisplayLayoutState;
|
||||||
|
|
||||||
|
private PipTouchState mPipTouchState;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
@@ -104,8 +107,12 @@ public class PipResizeGestureHandlerTest extends ShellTestCase {
|
|||||||
final PipMotionHelper motionHelper = new PipMotionHelper(mContext, mPipBoundsState,
|
final PipMotionHelper motionHelper = new PipMotionHelper(mContext, mPipBoundsState,
|
||||||
mPipTaskOrganizer, mPhonePipMenuController, pipSnapAlgorithm,
|
mPipTaskOrganizer, mPhonePipMenuController, pipSnapAlgorithm,
|
||||||
mMockPipTransitionController, mFloatingContentCoordinator);
|
mMockPipTransitionController, mFloatingContentCoordinator);
|
||||||
|
|
||||||
|
mPipTouchState = new PipTouchState(ViewConfiguration.get(mContext),
|
||||||
|
() -> {}, () -> {}, mMainExecutor);
|
||||||
mPipResizeGestureHandler = new PipResizeGestureHandler(mContext, pipBoundsAlgorithm,
|
mPipResizeGestureHandler = new PipResizeGestureHandler(mContext, pipBoundsAlgorithm,
|
||||||
mPipBoundsState, motionHelper, mPipTaskOrganizer, mPipDismissTargetHandler,
|
mPipBoundsState, motionHelper, mPipTouchState, mPipTaskOrganizer,
|
||||||
|
mPipDismissTargetHandler,
|
||||||
(Rect bounds) -> new Rect(), () -> {}, mPipUiEventLogger, mPhonePipMenuController,
|
(Rect bounds) -> new Rect(), () -> {}, mPipUiEventLogger, mPhonePipMenuController,
|
||||||
mMainExecutor) {
|
mMainExecutor) {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
Reference in New Issue
Block a user