Loading src/com/android/launcher3/config/FeatureFlags.java +4 −0 Original line number Diff line number Diff line Loading @@ -190,6 +190,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, Loading src/com/android/launcher3/dragndrop/DragController.java +31 −39 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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(); } Loading Loading @@ -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); Loading @@ -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() { Loading @@ -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) { Loading @@ -474,12 +476,11 @@ public abstract class DragController<T extends ActivityContext> dropTarget.onDragEnter(mDragObject); } dropTarget.onDragOver(mDragObject); } else { if (mLastDropTarget != null) { } else if (mLastDropTarget != null) { mLastDropTarget.onDragExit(mDragObject); } } mLastDropTarget = dropTarget; return mLastDropTarget; } /** Loading @@ -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 Loading @@ -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) { Loading Loading @@ -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; Loading @@ -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); Loading Loading
src/com/android/launcher3/config/FeatureFlags.java +4 −0 Original line number Diff line number Diff line Loading @@ -190,6 +190,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, Loading
src/com/android/launcher3/dragndrop/DragController.java +31 −39 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -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; Loading Loading @@ -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(); } Loading Loading @@ -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); Loading @@ -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() { Loading @@ -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) { Loading @@ -474,12 +476,11 @@ public abstract class DragController<T extends ActivityContext> dropTarget.onDragEnter(mDragObject); } dropTarget.onDragOver(mDragObject); } else { if (mLastDropTarget != null) { } else if (mLastDropTarget != null) { mLastDropTarget.onDragExit(mDragObject); } } mLastDropTarget = dropTarget; return mLastDropTarget; } /** Loading @@ -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 Loading @@ -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) { Loading Loading @@ -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; Loading @@ -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); Loading