Merge "Fixing drag getting stuck due to mismatch touch events" into ub-launcher3-master
diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java
index 566a04c..ac5ba7a 100644
--- a/src/com/android/launcher3/Launcher.java
+++ b/src/com/android/launcher3/Launcher.java
@@ -325,6 +325,7 @@
private final Runnable mDeferredOverlayCallbacks = this::checkIfOverlayStillDeferred;
private long mLastTouchUpTime = -1;
+ private boolean mTouchInProgress;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -1826,13 +1827,28 @@
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
- if (ev.getAction() == MotionEvent.ACTION_UP) {
- mLastTouchUpTime = System.currentTimeMillis();
+ 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()) {
diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java
index d6b9b76..db61f59 100644
--- a/src/com/android/launcher3/dragndrop/DragController.java
+++ b/src/com/android/launcher3/dragndrop/DragController.java
@@ -20,6 +20,7 @@
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;
@@ -62,7 +63,7 @@
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];
/**
@@ -207,6 +208,11 @@
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;
}