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

Commit 1fff24df authored by Andreas Agvard's avatar Andreas Agvard
Browse files

NavHandleLongPressInputConsumer now cancels long press detection on intercept.

Before handling a touch event NavHandleLongPressInputConsumer now checks
mDelegate.allowInterceptByParent() to ensure a parent has not intercepted the
touch event.

Flag: LEGACY ENABLE_LONG_PRESS_NAV_HANDLE DISABLED
Bug: 305924072
Test: Manual
Change-Id: I0d7bcceba881a21ad00e56c3e18b4ebde878ee89
parent 9623aaa4
Loading
Loading
Loading
Loading
+12 −6
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@ public class NavHandleLongPressInputConsumer extends DelegateInputConsumer {
    private final NavHandleLongPressHandler mNavHandleLongPressHandler;
    private final float mNavHandleWidth;
    private final float mScreenWidth;
    private final ViewConfiguration mViewConfiguration;

    private final Runnable mTriggerLongPress = this::triggerLongPress;
    private final float mTouchSlopSquared;
@@ -49,7 +48,6 @@ public class NavHandleLongPressInputConsumer extends DelegateInputConsumer {
    public NavHandleLongPressInputConsumer(Context context, InputConsumer delegate,
            InputMonitorCompat inputMonitor, RecentsAnimationDeviceState deviceState) {
        super(delegate, inputMonitor);
        mViewConfiguration = ViewConfiguration.get(context);
        mNavHandleWidth = context.getResources().getDimensionPixelSize(
                R.dimen.navigation_home_handle_width);
        mScreenWidth = DisplayController.INSTANCE.get(context).getInfo().currentSize.x;
@@ -69,6 +67,18 @@ public class NavHandleLongPressInputConsumer extends DelegateInputConsumer {

    @Override
    public void onMotionEvent(MotionEvent ev) {
        if (mDelegate.allowInterceptByParent()) {
            handleMotionEvent(ev);
        } else if (MAIN_EXECUTOR.getHandler().hasCallbacks(mTriggerLongPress)) {
            cancelLongPress();
        }

        if (mState != STATE_ACTIVE) {
            mDelegate.onMotionEvent(ev);
        }
    }

    private void handleMotionEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN -> {
                if (mCurrentDownEvent != null) {
@@ -103,10 +113,6 @@ public class NavHandleLongPressInputConsumer extends DelegateInputConsumer {
            MAIN_EXECUTOR.getHandler().removeCallbacks(mTriggerLongPress);
            MAIN_EXECUTOR.getHandler().post(mTriggerLongPress);
        }

        if (mState != STATE_ACTIVE) {
            mDelegate.onMotionEvent(ev);
        }
    }

    private void triggerLongPress() {