diff options
author | Sunny Goyal <sunnygoyal@google.com> | 2017-10-06 13:29:57 -0700 |
---|---|---|
committer | Sunny Goyal <sunnygoyal@google.com> | 2017-10-16 13:06:52 -0700 |
commit | 1797af41d162413dc98c33fab8ba19f96b63874b (patch) | |
tree | a9003b1952e98db0ec53dab673e00499e46bb6f7 /src/com/android/launcher3/dragndrop/DragController.java | |
parent | cbdfc598fae13f5aa7f7263351872d160004fbe7 (diff) | |
download | android_packages_apps_Trebuchet-1797af41d162413dc98c33fab8ba19f96b63874b.tar.gz android_packages_apps_Trebuchet-1797af41d162413dc98c33fab8ba19f96b63874b.tar.bz2 android_packages_apps_Trebuchet-1797af41d162413dc98c33fab8ba19f96b63874b.zip |
Cleaning up drag state management.
When the drag is started, the UI automatically goes into spring loaded mode. On a successful
drop, it is the responsibility of the {@link DropTarget} to exit out of the spring loaded
mode. If the drop was cancelled for some reason, the UI will automatically exit out of this mode.
Bug: 34692289
Change-Id: Ic611739a43bb8d9279b587aaee3039326c143e8b
Diffstat (limited to 'src/com/android/launcher3/dragndrop/DragController.java')
-rw-r--r-- | src/com/android/launcher3/dragndrop/DragController.java | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java index db8f903af..31255b7f0 100644 --- a/src/com/android/launcher3/dragndrop/DragController.java +++ b/src/com/android/launcher3/dragndrop/DragController.java @@ -120,6 +120,9 @@ public class DragController implements DragDriver.EventListener, TouchController /** * Starts a drag. + * When the drag is started, the UI automatically goes into spring loaded mode. On a successful + * drop, it is the responsibility of the {@link DropTarget} to exit out of the spring loaded + * mode. If the drop was cancelled for some reason, the UI will automatically exit out of this mode. * * @param b The bitmap to display as the drag image. It will be re-scaled to the * enlarged size. @@ -248,12 +251,24 @@ public class DragController implements DragDriver.EventListener, TouchController mDragObject.cancelled = true; mDragObject.dragComplete = true; if (!mIsInPreDrag) { - mDragObject.dragSource.onDropCompleted(null, mDragObject, false, false); + dispatchDropComplete(null, false); } } endDrag(); } + private void dispatchDropComplete(View dropTarget, boolean accepted) { + if (!accepted) { + // If it was not accepted, cleanup the state. If it was accepted, it is the + // responsibility of the drop target to cleanup the state. + mLauncher.exitSpringLoadedDragMode(false, + Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT); + mDragObject.deferDragViewCleanupPostAnimation = false; + } + + mDragObject.dragSource.onDropCompleted(dropTarget, mDragObject, accepted); + } + public void onAppsRemoved(ItemInfoMatcher matcher) { // Cancel the current drag if we are removing an app that we are dragging if (mDragObject != null) { @@ -583,8 +598,7 @@ public class DragController implements DragDriver.EventListener, TouchController final View dropTargetAsView = dropTarget instanceof View ? (View) dropTarget : null; if (!mIsInPreDrag) { mLauncher.getUserEventDispatcher().logDragNDrop(mDragObject, dropTargetAsView); - mDragObject.dragSource.onDropCompleted( - dropTargetAsView, mDragObject, flingAnimation != null, accepted); + dispatchDropComplete(dropTargetAsView, accepted); } } |