Make sure to not call DragOver when the drag is still under PreDrag

Adding a flag so we can turn off this behavior if it break a drag functionallity

Fix: 299748096
Test: most of dragging test will test this
Change-Id: I4f45faea4f19bd99a946a28372546e18ca5f6a2f
This commit is contained in:
Sebastian Franco
2023-09-15 16:06:58 -07:00
parent 48c7efb1f7
commit 1be772df1d
2 changed files with 35 additions and 39 deletions
@@ -192,6 +192,10 @@ public final class FeatureFlags {
"ENABLE_PARAMETRIZE_REORDER", DISABLED,
"Enables generating the reorder using a set of parameters");
public static final BooleanFlag ENABLE_NO_LONG_PRESS_DRAG = getDebugFlag(299748096,
"ENABLE_NO_LONG_PRESS_DRAG", DISABLED,
"Don't trigger the drag if we are still under long press");
// TODO(Block 12): Clean up flags
public static final BooleanFlag ENABLE_MULTI_INSTANCE = getDebugFlag(270396680,
"ENABLE_MULTI_INSTANCE", DISABLED,
@@ -17,6 +17,7 @@
package com.android.launcher3.dragndrop;
import static com.android.launcher3.Utilities.ATLEAST_Q;
import static com.android.launcher3.config.FeatureFlags.ENABLE_NO_LONG_PRESS_DRAG;
import android.graphics.Point;
import android.graphics.Rect;
@@ -87,6 +88,10 @@ public abstract class DragController<T extends ActivityContext>
private int mLastTouchClassification;
protected int mDistanceSinceScroll = 0;
/**
* This variable is to differentiate between a long press and a drag, if it's true that means
* it's a long press and when it's false means that we are no longer in a long press.
*/
protected boolean mIsInPreDrag;
private final int DRAG_VIEW_SCALE_DURATION_MS = 500;
@@ -370,7 +375,7 @@ public abstract class DragController<T extends ActivityContext>
@Override
public void onDriverDragEnd(float x, float y) {
if (!endWithFlingAnimation()) {
drop(findDropTarget((int) x, (int) y, mCoordinatesTemp), null);
drop(findDropTarget((int) x, (int) y), null);
}
endDrag();
}
@@ -432,13 +437,6 @@ public abstract class DragController<T extends ActivityContext>
protected void handleMoveEvent(int x, int y) {
mDragObject.dragView.move(x, y);
// Drop on someone?
final int[] coordinates = mCoordinatesTemp;
DropTarget dropTarget = findDropTarget(x, y, coordinates);
mDragObject.x = coordinates[0];
mDragObject.y = coordinates[1];
checkTouchMove(dropTarget);
// Check if we are hovering over the scroll areas
mDistanceSinceScroll += Math.hypot(mLastTouch.x - x, mLastTouch.y - y);
mLastTouch.set(x, y);
@@ -451,6 +449,9 @@ public abstract class DragController<T extends ActivityContext>
&& mOptions.preDragCondition.shouldStartDrag(distanceDragged)) {
callOnDragStart();
}
// Drop on someone?
checkTouchMove(x, y);
}
public float getDistanceDragged() {
@@ -458,14 +459,15 @@ public abstract class DragController<T extends ActivityContext>
}
public void forceTouchMove() {
int[] placeholderCoordinates = mCoordinatesTemp;
DropTarget dropTarget = findDropTarget(mLastTouch.x, mLastTouch.y, placeholderCoordinates);
mDragObject.x = placeholderCoordinates[0];
mDragObject.y = placeholderCoordinates[1];
checkTouchMove(dropTarget);
checkTouchMove(mLastTouch.x, mLastTouch.y);
}
private void checkTouchMove(DropTarget dropTarget) {
private DropTarget checkTouchMove(final int x, final int y) {
// If we are in predrag, don't trigger any other event until we get out of it
if (ENABLE_NO_LONG_PRESS_DRAG.get() && mIsInPreDrag) {
return mLastDropTarget;
}
DropTarget dropTarget = findDropTarget(x, y);
if (dropTarget != null) {
if (mLastDropTarget != dropTarget) {
if (mLastDropTarget != null) {
@@ -474,12 +476,11 @@ public abstract class DragController<T extends ActivityContext>
dropTarget.onDragEnter(mDragObject);
}
dropTarget.onDragOver(mDragObject);
} else {
if (mLastDropTarget != null) {
mLastDropTarget.onDragExit(mDragObject);
}
} else if (mLastDropTarget != null) {
mLastDropTarget.onDragExit(mDragObject);
}
mLastDropTarget = dropTarget;
return mLastDropTarget;
}
/**
@@ -487,13 +488,8 @@ public abstract class DragController<T extends ActivityContext>
* we manually ensure appropriate drag and drop events get emulated for accessible drag.
*/
public void completeAccessibleDrag(int[] location) {
final int[] coordinates = mCoordinatesTemp;
// We make sure that we prime the target for drop.
DropTarget dropTarget = findDropTarget(location[0], location[1], coordinates);
mDragObject.x = coordinates[0];
mDragObject.y = coordinates[1];
checkTouchMove(dropTarget);
DropTarget dropTarget = checkTouchMove(location[0], location[1]);
dropTarget.prepareAccessibilityDrop();
// Perform the drop
@@ -502,10 +498,6 @@ public abstract class DragController<T extends ActivityContext>
}
protected void drop(DropTarget dropTarget, Runnable flingAnimation) {
final int[] coordinates = mCoordinatesTemp;
mDragObject.x = coordinates[0];
mDragObject.y = coordinates[1];
// Move dragging to the final target.
if (dropTarget != mLastDropTarget) {
if (mLastDropTarget != null) {
@@ -542,9 +534,9 @@ public abstract class DragController<T extends ActivityContext>
dispatchDropComplete(dropTargetAsView, accepted);
}
private DropTarget findDropTarget(int x, int y, int[] dropCoordinates) {
mDragObject.x = x;
mDragObject.y = y;
private DropTarget findDropTarget(final int x, final int y) {
mCoordinatesTemp[0] = x;
mCoordinatesTemp[1] = y;
final Rect r = mRectTemp;
final ArrayList<DropTarget> dropTargets = mDropTargets;
@@ -556,17 +548,17 @@ public abstract class DragController<T extends ActivityContext>
target.getHitRectRelativeToDragLayer(r);
if (r.contains(x, y)) {
dropCoordinates[0] = x;
dropCoordinates[1] = y;
mActivity.getDragLayer().mapCoordInSelfToDescendant((View) target, dropCoordinates);
mActivity.getDragLayer().mapCoordInSelfToDescendant((View) target,
mCoordinatesTemp);
mDragObject.x = mCoordinatesTemp[0];
mDragObject.y = mCoordinatesTemp[1];
return target;
}
}
// Pass all unhandled drag to workspace. Workspace finds the correct
// cell layout to drop to in the existing drag/drop logic.
dropCoordinates[0] = x;
dropCoordinates[1] = y;
return getDefaultDropTarget(dropCoordinates);
DropTarget dropTarget = getDefaultDropTarget(mCoordinatesTemp);
mDragObject.x = mCoordinatesTemp[0];
mDragObject.y = mCoordinatesTemp[1];
return dropTarget;
}
protected abstract DropTarget getDefaultDropTarget(int[] dropCoordinates);