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

Commit a306e59c authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Fixing drag getting stuck due to mismatch touch events

Bug: 150825081
Change-Id: Ib0613ff145fe308800eae85f2148b22ee01db91d
parent ba1a2b9b
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -340,6 +340,7 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
            };

    private long mLastTouchUpTime = -1;
    private boolean mTouchInProgress;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
@@ -1840,13 +1841,28 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
        if (ev.getAction() == MotionEvent.ACTION_UP) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                mTouchInProgress = true;
                break;
            case MotionEvent.ACTION_UP:
                mLastTouchUpTime = System.currentTimeMillis();
                // Follow through
            case MotionEvent.ACTION_CANCEL:
                mTouchInProgress = false;
                break;
        }
        TestLogging.recordMotionEvent(TestProtocol.SEQUENCE_MAIN, "Touch event", ev);
        return super.dispatchTouchEvent(ev);
    }

    /**
     * Returns true if a touch interaction is in progress
     */
    public boolean isTouchInProgress() {
        return mTouchInProgress;
    }

    @Override
    public void onBackPressed() {
        if (finishAutoCancelActionMode()) {
+7 −1
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import static com.android.launcher3.AbstractFloatingView.TYPE_DISCOVERY_BOUNCE;
import static com.android.launcher3.LauncherAnimUtils.SPRING_LOADED_EXIT_DELAY;
import static com.android.launcher3.LauncherState.NORMAL;
import static com.android.launcher3.Utilities.ATLEAST_Q;
import static com.android.launcher3.util.Executors.MAIN_EXECUTOR;

import android.animation.ValueAnimator;
import android.content.ComponentName;
@@ -64,7 +65,7 @@ public class DragController implements DragDriver.EventListener, TouchController
    private final FlingToDeleteHelper mFlingToDeleteHelper;

    // temporaries to avoid gc thrash
    private Rect mRectTemp = new Rect();
    private final Rect mRectTemp = new Rect();
    private final int[] mCoordinatesTemp = new int[2];

    /**
@@ -217,6 +218,11 @@ public class DragController implements DragDriver.EventListener, TouchController

        handleMoveEvent(mLastTouch.x, mLastTouch.y);
        mLauncher.getUserEventDispatcher().resetActionDurationMillis();

        if (!mLauncher.isTouchInProgress() && options.simulatedDndStartPoint == null) {
            // If it is an internal drag and the touch is already complete, cancel immediately
            MAIN_EXECUTOR.submit(this::cancelDrag);
        }
        return dragView;
    }