diff options
Diffstat (limited to 'src/com/android/launcher3/dragndrop')
-rw-r--r-- | src/com/android/launcher3/dragndrop/DragController.java | 77 | ||||
-rw-r--r-- | src/com/android/launcher3/dragndrop/DragLayer.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher3/dragndrop/DragOptions.java | 42 |
3 files changed, 65 insertions, 56 deletions
diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java index c7b66e7bd..19a47e873 100644 --- a/src/com/android/launcher3/dragndrop/DragController.java +++ b/src/com/android/launcher3/dragndrop/DragController.java @@ -131,7 +131,7 @@ public class DragController implements DragDriver.EventListener, TouchController protected final int mFlingToDeleteThresholdVelocity; private VelocityTracker mVelocityTracker; - private boolean mIsDragDeferred; + private boolean mIsInPreDrag; /** * Interface to receive notifications when a drag starts or stops @@ -230,13 +230,14 @@ public class DragController implements DragDriver.EventListener, TouchController mDragObject = new DropTarget.DragObject(); - mIsDragDeferred = !mOptions.deferDragCondition.shouldStartDeferredDrag(0); + mIsInPreDrag = mOptions.preDragCondition != null + && !mOptions.preDragCondition.shouldStartDrag(0); final Resources res = mLauncher.getResources(); final float scaleDps = FeatureFlags.LAUNCHER3_LEGACY_WORKSPACE_DND ? res.getDimensionPixelSize(R.dimen.dragViewScale) - : mIsDragDeferred - ? res.getDimensionPixelSize(R.dimen.deferred_drag_view_scale) + : mIsInPreDrag + ? res.getDimensionPixelSize(R.dimen.pre_drag_view_scale) : 0f; final DragView dragView = mDragObject.dragView = new DragView(mLauncher, b, registrationX, registrationY, initialDragViewScale, scaleDps); @@ -271,10 +272,10 @@ public class DragController implements DragDriver.EventListener, TouchController dragView.show(mMotionDownX, mMotionDownY); mDistanceSinceScroll = 0; - if (!mIsDragDeferred) { - startDeferredDrag(); - } else { - mOptions.deferDragCondition.onDeferredDragStart(); + if (!mIsInPreDrag) { + callOnDragStart(); + } else if (mOptions.preDragCondition != null) { + mOptions.preDragCondition.onPreDragStart(); } mLastTouch[0] = mMotionDownX; @@ -284,16 +285,18 @@ public class DragController implements DragDriver.EventListener, TouchController return dragView; } - public boolean isDeferringDrag() { - return mIsDragDeferred; - } - - public void startDeferredDrag() { + private void callOnDragStart() { for (DragListener listener : new ArrayList<>(mListeners)) { listener.onDragStart(mDragObject, mOptions); } - mOptions.deferDragCondition.onDragStart(); - mIsDragDeferred = false; + if (mOptions.preDragCondition != null) { + mOptions.preDragCondition.onPreDragEnd(true /* dragStarted*/); + } + mIsInPreDrag = false; + } + + public boolean isInPreDrag() { + return mIsInPreDrag; } /** @@ -329,7 +332,9 @@ public class DragController implements DragDriver.EventListener, TouchController mDragObject.deferDragViewCleanupPostAnimation = false; mDragObject.cancelled = true; mDragObject.dragComplete = true; - mDragObject.dragSource.onDropCompleted(null, mDragObject, false, false); + if (!mIsInPreDrag) { + mDragObject.dragSource.onDropCompleted(null, mDragObject, false, false); + } } endDrag(); } @@ -350,7 +355,6 @@ public class DragController implements DragDriver.EventListener, TouchController private void endDrag() { if (isDragging()) { mDragDriver = null; - mOptions = null; clearScrollRunnable(); boolean isDeferred = false; if (mDragObject.dragView != null) { @@ -363,15 +367,24 @@ public class DragController implements DragDriver.EventListener, TouchController // Only end the drag if we are not deferred if (!isDeferred) { - for (DragListener listener : new ArrayList<>(mListeners)) { - listener.onDragEnd(); - } + callOnDragEnd(); } } releaseVelocityTracker(); } + private void callOnDragEnd() { + if (mIsInPreDrag && mOptions.preDragCondition != null) { + mOptions.preDragCondition.onPreDragEnd(false /* dragStarted*/); + } + mIsInPreDrag = false; + mOptions = null; + for (DragListener listener : new ArrayList<>(mListeners)) { + listener.onDragEnd(); + } + } + /** * This only gets called as a result of drag view cleanup being deferred in endDrag(); */ @@ -380,9 +393,7 @@ public class DragController implements DragDriver.EventListener, TouchController if (mDragObject.deferDragViewCleanupPostAnimation) { // If we skipped calling onDragEnd() before, do it now - for (DragListener listener : new ArrayList<>(mListeners)) { - listener.onDragEnd(); - } + callOnDragEnd(); } } @@ -536,9 +547,9 @@ public class DragController implements DragDriver.EventListener, TouchController mLastTouch[1] = y; checkScrollState(x, y); - if (mIsDragDeferred && mOptions.deferDragCondition.shouldStartDeferredDrag( - Math.hypot(x - mMotionDownX, y - mMotionDownY))) { - startDeferredDrag(); + if (mIsInPreDrag && mOptions.preDragCondition != null + && mOptions.preDragCondition.shouldStartDrag(mDistanceSinceScroll)) { + callOnDragStart(); } } @@ -701,7 +712,7 @@ public class DragController implements DragDriver.EventListener, TouchController (vec1.length() * vec2.length())); } - void drop(DropTarget dropTarget, float x, float y, PointF flingVel) { + private void drop(DropTarget dropTarget, float x, float y, PointF flingVel) { final int[] coordinates = mCoordinatesTemp; mDragObject.x = coordinates[0]; @@ -734,11 +745,15 @@ public class DragController implements DragDriver.EventListener, TouchController } } final View dropTargetAsView = dropTarget instanceof View ? (View) dropTarget : null; - mDragObject.dragSource.onDropCompleted( - dropTargetAsView, mDragObject, flingVel != null, accepted); mLauncher.getUserEventDispatcher().logDragNDrop(mDragObject, dropTargetAsView); - if (mIsDragDeferred) { - mOptions.deferDragCondition.onDropBeforeDeferredDrag(); + if (!mIsInPreDrag) { + mDragObject.dragSource.onDropCompleted( + dropTargetAsView, mDragObject, flingVel != null, accepted); + } else { + // Only defer the drag view cleanup if the drag source handles the drop. + if (!(mDragObject.dragSource instanceof DropTarget)) { + mDragObject.deferDragViewCleanupPostAnimation = false; + } } } diff --git a/src/com/android/launcher3/dragndrop/DragLayer.java b/src/com/android/launcher3/dragndrop/DragLayer.java index e1c74bf6d..15ee4118d 100644 --- a/src/com/android/launcher3/dragndrop/DragLayer.java +++ b/src/com/android/launcher3/dragndrop/DragLayer.java @@ -219,7 +219,7 @@ public class DragLayer extends InsettableFrameLayout { mLauncher.closeShortcutsContainer(); // We let touches on the original icon go through so that users can launch // the app with one tap if they don't find a shortcut they want. - return !isEventOverView(deepShortcutsContainer.getDeferredDragIcon(), ev); + return !isEventOverView(deepShortcutsContainer.getOriginalIcon(), ev); } } } diff --git a/src/com/android/launcher3/dragndrop/DragOptions.java b/src/com/android/launcher3/dragndrop/DragOptions.java index dbf46f338..906855a7c 100644 --- a/src/com/android/launcher3/dragndrop/DragOptions.java +++ b/src/com/android/launcher3/dragndrop/DragOptions.java @@ -17,6 +17,8 @@ package com.android.launcher3.dragndrop; import android.graphics.Point; +import android.support.annotation.CallSuper; +import android.view.View; /** * Set of options to control the drag and drop behavior. @@ -29,8 +31,8 @@ public class DragOptions { /** Specifies the start location for the system DnD, null when using internal DnD */ public Point systemDndStartPoint = null; - /** Determines when a deferred drag should start. By default, drags aren't deferred at all. */ - public DeferDragCondition deferDragCondition = new DeferDragCondition(); + /** Determines when a pre-drag should transition to a drag. By default, this is immediate. */ + public PreDragCondition preDragCondition = null; /** * Specifies a condition that must be met before DragListener#onDragStart() is called. @@ -38,34 +40,26 @@ public class DragOptions { * DragController#startDrag(). * * This condition can be overridden, and callbacks are provided for the following cases: - * - The drag starts, but onDragStart() is deferred (onDeferredDragStart()). - * - The drag ends before the condition is met (onDropBeforeDeferredDrag()). - * - The condition is met (onDragStart()). + * - The pre-drag starts, but onDragStart() is deferred (onPreDragStart()). + * - The pre-drag ends before the condition is met (onPreDragEnd(false)). + * - The actual drag starts when the condition is met (onPreDragEnd(true)). */ - public static class DeferDragCondition { - public boolean shouldStartDeferredDrag(double distanceDragged) { - return true; - } + public interface PreDragCondition { + + public boolean shouldStartDrag(double distanceDragged); /** - * The drag has started, but onDragStart() is deferred. - * This happens when shouldStartDeferredDrag() returns true. + * The pre-drag has started, but onDragStart() is + * deferred until shouldStartDrag() returns true. */ - public void onDeferredDragStart() { - // Do nothing. - } + void onPreDragStart(); /** - * User dropped before the deferred condition was met, - * i.e. before shouldStartDeferredDrag() returned true. + * The pre-drag has ended. This gets called at the same time as onDragStart() + * if the condition is met, otherwise at the same time as onDragEnd(). + * @param dragStarted Whether the pre-drag ended because the actual drag started. + * This will be true if the condition was met, otherwise false. */ - public void onDropBeforeDeferredDrag() { - // Do nothing - } - - /** onDragStart() has been called, now we are in a normal drag. */ - public void onDragStart() { - // Do nothing - } + void onPreDragEnd(boolean dragStarted); } } |