Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 98fdd5a9 authored by Ikram Gabiyev's avatar Ikram Gabiyev Committed by Automerger Merge Worker
Browse files

Merge "Disable touch events until resize bounds commit" into udc-dev am: a584474a

parents 78d5457c a584474a
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -70,6 +70,7 @@ public class PipResizeGestureHandler {
    private final PipBoundsAlgorithm mPipBoundsAlgorithm;
    private final PipMotionHelper mMotionHelper;
    private final PipBoundsState mPipBoundsState;
    private final PipTouchState mPipTouchState;
    private final PipTaskOrganizer mPipTaskOrganizer;
    private final PhonePipMenuController mPhonePipMenuController;
    private final PipDismissTargetHandler mPipDismissTargetHandler;
@@ -104,7 +105,6 @@ public class PipResizeGestureHandler {
    private boolean mAllowGesture;
    private boolean mIsAttached;
    private boolean mIsEnabled;
    private boolean mEnableTouch;
    private boolean mEnablePinchResize;
    private boolean mEnableDragCornerResize;
    private boolean mIsSysUiStateValid;
@@ -122,7 +122,8 @@ public class PipResizeGestureHandler {

    public PipResizeGestureHandler(Context context, PipBoundsAlgorithm pipBoundsAlgorithm,
            PipBoundsState pipBoundsState, PipMotionHelper motionHelper,
            PipTaskOrganizer pipTaskOrganizer, PipDismissTargetHandler pipDismissTargetHandler,
            PipTouchState pipTouchState, PipTaskOrganizer pipTaskOrganizer,
            PipDismissTargetHandler pipDismissTargetHandler,
            Function<Rect, Rect> movementBoundsSupplier, Runnable updateMovementBoundsRunnable,
            PipUiEventLogger pipUiEventLogger, PhonePipMenuController menuActivityController,
            ShellExecutor mainExecutor) {
@@ -132,6 +133,7 @@ public class PipResizeGestureHandler {
        mPipBoundsAlgorithm = pipBoundsAlgorithm;
        mPipBoundsState = pipBoundsState;
        mMotionHelper = motionHelper;
        mPipTouchState = pipTouchState;
        mPipTaskOrganizer = pipTaskOrganizer;
        mPipDismissTargetHandler = pipDismissTargetHandler;
        mMovementBoundsSupplier = movementBoundsSupplier;
@@ -139,7 +141,6 @@ public class PipResizeGestureHandler {
        mPhonePipMenuController = menuActivityController;
        mPipUiEventLogger = pipUiEventLogger;
        mPinchResizingAlgorithm = new PipPinchResizingAlgorithm();
        mEnableTouch = true;

        mUpdateResizeBoundsCallback = (rect) -> {
            mUserResizeBounds.set(rect);
@@ -250,8 +251,8 @@ public class PipResizeGestureHandler {
            return;
        }

        if (!mEnableTouch) {
            // No need to handle anything if touches are not enabled for resizing.
        if (!mPipTouchState.getAllowInputEvents()) {
            // No need to handle anything if touches are not enabled
            return;
        }

@@ -588,13 +589,13 @@ public class PipResizeGestureHandler {
                        mLastResizeBounds, movementBounds);
                mPipBoundsAlgorithm.applySnapFraction(mLastResizeBounds, snapFraction);

                // disable the resizing until the final bounds are updated
                mEnableTouch = false;
                // disable any touch events beyond resizing too
                mPipTouchState.setAllowInputEvents(false);

                mPipTaskOrganizer.scheduleAnimateResizePip(startBounds, mLastResizeBounds,
                        PINCH_RESIZE_SNAP_DURATION, mAngle, mUpdateResizeBoundsCallback, () -> {
                            // reset the pinch resizing to its default state
                            mEnableTouch = true;
                            // enable touch events
                            mPipTouchState.setAllowInputEvents(true);
                        });
            } else {
                mPipTaskOrganizer.scheduleFinishResizePip(mLastResizeBounds,
+10 −5
Original line number Diff line number Diff line
@@ -199,11 +199,6 @@ public class PipTouchHandler {
        mMotionHelper = pipMotionHelper;
        mPipDismissTargetHandler = new PipDismissTargetHandler(context, pipUiEventLogger,
                mMotionHelper, mainExecutor);
        mPipResizeGestureHandler =
                new PipResizeGestureHandler(context, pipBoundsAlgorithm, pipBoundsState,
                        mMotionHelper, pipTaskOrganizer, mPipDismissTargetHandler,
                        this::getMovementBounds, this::updateMovementBounds, pipUiEventLogger,
                        menuController, mainExecutor);
        mTouchState = new PipTouchState(ViewConfiguration.get(context),
                () -> {
                    if (mPipBoundsState.isStashed()) {
@@ -220,6 +215,11 @@ public class PipTouchHandler {
                },
                menuController::hideMenu,
                mainExecutor);
        mPipResizeGestureHandler =
                new PipResizeGestureHandler(context, pipBoundsAlgorithm, pipBoundsState,
                        mMotionHelper, mTouchState, pipTaskOrganizer, mPipDismissTargetHandler,
                        this::getMovementBounds, this::updateMovementBounds, pipUiEventLogger,
                        menuController, mainExecutor);
        mConnection = new PipAccessibilityInteractionConnection(mContext, pipBoundsState,
                mMotionHelper, pipTaskOrganizer, mPipBoundsAlgorithm.getSnapAlgorithm(),
                this::onAccessibilityShowMenu, this::updateMovementBounds,
@@ -556,6 +556,11 @@ public class PipTouchHandler {
            return true;
        }

        // do not process input event if not allowed
        if (!mTouchState.getAllowInputEvents()) {
            return true;
        }

        MotionEvent ev = (MotionEvent) inputEvent;
        if (!mPipBoundsState.isStashed() && mPipResizeGestureHandler.willStartResizeGesture(ev)) {
            // Initialize the touch state for the gesture, but immediately reset to invalidate the
+17 −0
Original line number Diff line number Diff line
@@ -55,6 +55,9 @@ public class PipTouchState {
    private final PointF mLastDelta = new PointF();
    private final PointF mVelocity = new PointF();
    private boolean mAllowTouches = true;

    // Set to false to block both PipTouchHandler and PipResizeGestureHandler's input processing
    private boolean mAllowInputEvents = true;
    private boolean mIsUserInteracting = false;
    // Set to true only if the multiple taps occur within the double tap timeout
    private boolean mIsDoubleTap = false;
@@ -76,6 +79,20 @@ public class PipTouchState {
        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.
     */
+8 −1
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.graphics.Rect;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
import android.view.MotionEvent;
import android.view.ViewConfiguration;

import androidx.test.filters.SmallTest;

@@ -90,6 +91,8 @@ public class PipResizeGestureHandlerTest extends ShellTestCase {

    private PipDisplayLayoutState mPipDisplayLayoutState;

    private PipTouchState mPipTouchState;

    @Before
    public void setUp() throws Exception {
        MockitoAnnotations.initMocks(this);
@@ -104,8 +107,12 @@ public class PipResizeGestureHandlerTest extends ShellTestCase {
        final PipMotionHelper motionHelper = new PipMotionHelper(mContext, mPipBoundsState,
                mPipTaskOrganizer, mPhonePipMenuController, pipSnapAlgorithm,
                mMockPipTransitionController, mFloatingContentCoordinator);

        mPipTouchState = new PipTouchState(ViewConfiguration.get(mContext),
                () -> {}, () -> {}, mMainExecutor);
        mPipResizeGestureHandler = new PipResizeGestureHandler(mContext, pipBoundsAlgorithm,
                mPipBoundsState, motionHelper, mPipTaskOrganizer, mPipDismissTargetHandler,
                mPipBoundsState, motionHelper, mPipTouchState, mPipTaskOrganizer,
                mPipDismissTargetHandler,
                (Rect bounds) -> new Rect(), () -> {}, mPipUiEventLogger, mPhonePipMenuController,
                mMainExecutor) {
            @Override