diff options
-rw-r--r-- | src/com/android/launcher3/ButtonDropTarget.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher3/DragSource.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher3/DropTarget.java | 12 | ||||
-rw-r--r-- | src/com/android/launcher3/Launcher.java | 58 | ||||
-rw-r--r-- | src/com/android/launcher3/UninstallDropTarget.java | 10 | ||||
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 77 | ||||
-rw-r--r-- | src/com/android/launcher3/allapps/AllAppsContainerView.java | 19 | ||||
-rw-r--r-- | src/com/android/launcher3/dragndrop/BaseItemDragListener.java | 22 | ||||
-rw-r--r-- | src/com/android/launcher3/dragndrop/DragController.java | 20 | ||||
-rw-r--r-- | src/com/android/launcher3/dragndrop/DragLayer.java | 10 | ||||
-rw-r--r-- | src/com/android/launcher3/dragndrop/DragOptions.java | 6 | ||||
-rw-r--r-- | src/com/android/launcher3/folder/Folder.java | 29 | ||||
-rw-r--r-- | src/com/android/launcher3/folder/FolderIcon.java | 10 | ||||
-rw-r--r-- | src/com/android/launcher3/popup/PopupContainerWithArrow.java | 10 | ||||
-rw-r--r-- | src/com/android/launcher3/util/FlingAnimation.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher3/widget/BaseWidgetSheet.java | 16 |
16 files changed, 111 insertions, 194 deletions
diff --git a/src/com/android/launcher3/ButtonDropTarget.java b/src/com/android/launcher3/ButtonDropTarget.java index ffc2b02e2..e1b5e2c75 100644 --- a/src/com/android/launcher3/ButtonDropTarget.java +++ b/src/com/android/launcher3/ButtonDropTarget.java @@ -229,7 +229,7 @@ public abstract class ButtonDropTarget extends TextView public void run() { completeDrop(d); mDropTargetBar.onDragEnd(); - mLauncher.exitSpringLoadedDragModeDelayed(true, 0, null); + mLauncher.exitSpringLoadedDragMode(true, 0); } }; dragLayer.animateView(d.dragView, from, to, scale, 1f, 1f, 0.1f, 0.1f, diff --git a/src/com/android/launcher3/DragSource.java b/src/com/android/launcher3/DragSource.java index c6106c23e..93f865c9f 100644 --- a/src/com/android/launcher3/DragSource.java +++ b/src/com/android/launcher3/DragSource.java @@ -30,5 +30,5 @@ public interface DragSource extends LogContainerProvider { * A callback made back to the source after an item from this source has been dropped on a * DropTarget. */ - void onDropCompleted(View target, DragObject d, boolean isFlingToDelete, boolean success); + void onDropCompleted(View target, DragObject d, boolean success); } diff --git a/src/com/android/launcher3/DropTarget.java b/src/com/android/launcher3/DropTarget.java index 2307b8924..4d3047920 100644 --- a/src/com/android/launcher3/DropTarget.java +++ b/src/com/android/launcher3/DropTarget.java @@ -59,9 +59,6 @@ public interface DropTarget { /** The object is part of an accessible drag operation */ public boolean accessibleDrag; - /** Post drag animation runnable */ - public Runnable postAnimationRunnable = null; - /** Indicates that the drag operation was cancelled */ public boolean cancelled = false; @@ -105,7 +102,14 @@ public interface DropTarget { boolean isDropEnabled(); /** - * Handle an object being dropped on the DropTarget + * Handle an object being dropped on the DropTarget. + * + * This will be called only if this target previously returned true for {@link #acceptDrop}. It + * is the responsibility of this target to exit out of the spring loaded mode (either + * immediately or after any pending animations). + * + * If the drop was cancelled for some reason, onDrop will never get called, the UI will + * automatically exit out of this mode. */ void onDrop(DragObject dragObject, DragOptions options); diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 5c635ca51..bfcd82ace 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -582,8 +582,8 @@ public class Launcher extends BaseActivity Runnable exitSpringLoaded = new Runnable() { @Override public void run() { - exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), - EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); + exitSpringLoadedDragMode((resultCode != RESULT_CANCELED), + EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT); } }; @@ -635,7 +635,7 @@ public class Launcher extends BaseActivity final Runnable onComplete = new Runnable() { @Override public void run() { - exitSpringLoadedDragModeDelayed(false, 0, null); + exitSpringLoadedDragMode(false, 0); } }; @@ -763,8 +763,8 @@ public class Launcher extends BaseActivity @Override public void run() { completeAddAppWidget(appWidgetId, requestArgs, layout, null); - exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), - EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); + exitSpringLoadedDragMode((resultCode != RESULT_CANCELED), + EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT); } }; } else if (resultCode == RESULT_CANCELED) { @@ -1231,7 +1231,7 @@ public class Launcher extends BaseActivity // If appropriate, either create a folder or add to an existing folder if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, - true, null, null)) { + true, null)) { return; } DragObject dragObject = new DragObject(); @@ -1714,8 +1714,8 @@ public class Launcher extends BaseActivity @Override public void run() { // Exit spring loaded mode if necessary after adding the widget - exitSpringLoadedDragModeDelayed(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, - null); + exitSpringLoadedDragMode(true, EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT + ); } }; completeAddAppWidget(appWidgetId, info, boundWidget, addFlowHandler.getProviderInfo(this)); @@ -2598,16 +2598,36 @@ public class Launcher extends BaseActivity return; } + // Lock the orientation: + if (mRotationEnabled) { + setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); + } + + // Prevent any Un/InstallShortcutReceivers from updating the db while we are + // in spring loaded mode + InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_DRAG_AND_DROP); + mStateTransitionAnimation.startAnimationToWorkspace(mState, mWorkspace.getState(), Workspace.State.SPRING_LOADED, true /* animated */, null /* onCompleteRunnable */); setState(State.WORKSPACE_SPRING_LOADED); } - public void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, int delay, + public void exitSpringLoadedDragMode(final boolean successfulDrop, int delay) { + exitSpringLoadedDragMode(successfulDrop, delay, null); + } + + public void exitSpringLoadedDragMode(final boolean successfulDrop, int delay, final Runnable onCompleteRunnable) { if (!isStateSpringLoaded()) return; + // Unlock rotation lock + unlockScreenOrientation(false); + + // Re-enable any Un/InstallShortcutReceiver and now process any queued items + InstallShortcutReceiver.disableAndFlushInstallQueue( + InstallShortcutReceiver.FLAG_DRAG_AND_DROP, this); + if (mExitSpringLoadedModeRunnable != null) { mHandler.removeCallbacks(mExitSpringLoadedModeRunnable); } @@ -2621,8 +2641,10 @@ public class Launcher extends BaseActivity // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should // clean up our state transition functions showWorkspace(true, onCompleteRunnable); - } else { - exitSpringLoadedDragMode(); + } else if (mState == State.APPS_SPRING_LOADED) { + showAppsView(true /* animated */); + } else if (mState == State.WORKSPACE_SPRING_LOADED) { + showWorkspace(true); } mExitSpringLoadedModeRunnable = null; } @@ -2635,14 +2657,6 @@ public class Launcher extends BaseActivity || mState == State.WIDGETS_SPRING_LOADED; } - public void exitSpringLoadedDragMode() { - if (mState == State.APPS_SPRING_LOADED) { - showAppsView(true /* animated */); - } else if (mState == State.WORKSPACE_SPRING_LOADED) { - showWorkspace(true); - } - } - @Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { final boolean result = super.dispatchPopulateAccessibilityEvent(event); @@ -3398,12 +3412,6 @@ public class Launcher extends BaseActivity mModel.refreshAndBindWidgetsAndShortcuts(packageUser); } - public void lockScreenOrientation() { - if (mRotationEnabled) { - setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LOCKED); - } - } - public void unlockScreenOrientation(boolean immediate) { if (mRotationEnabled) { if (immediate) { diff --git a/src/com/android/launcher3/UninstallDropTarget.java b/src/com/android/launcher3/UninstallDropTarget.java index e8c452877..43938194e 100644 --- a/src/com/android/launcher3/UninstallDropTarget.java +++ b/src/com/android/launcher3/UninstallDropTarget.java @@ -97,9 +97,7 @@ public class UninstallDropTarget extends ButtonDropTarget { @Override public void onDrop(DragObject d, DragOptions options) { // Defer onComplete - if (options.deferCompleteForUninstall) { - d.dragSource = new DeferredOnComplete(d.dragSource, getContext()); - } + d.dragSource = new DeferredOnComplete(d.dragSource, getContext()); super.onDrop(d, options); } @@ -171,7 +169,7 @@ public class UninstallDropTarget extends ButtonDropTarget { } @Override - public void onDropCompleted(View target, DragObject d, boolean isFlingToDelete, + public void onDropCompleted(View target, DragObject d, boolean success) { mDragObject = d; } @@ -189,7 +187,7 @@ public class UninstallDropTarget extends ButtonDropTarget { .getApplicationInfo(mPackageName, PackageManager.MATCH_UNINSTALLED_PACKAGES, mDragObject.dragInfo.user) == null) { mDragObject.dragSource = mOriginal; - mOriginal.onDropCompleted(UninstallDropTarget.this, mDragObject, false, true); + mOriginal.onDropCompleted(UninstallDropTarget.this, mDragObject, true); } else { sendFailure(); } @@ -198,7 +196,7 @@ public class UninstallDropTarget extends ButtonDropTarget { public void sendFailure() { mDragObject.dragSource = mOriginal; mDragObject.cancelled = true; - mOriginal.onDropCompleted(UninstallDropTarget.this, mDragObject, false, false); + mOriginal.onDropCompleted(UninstallDropTarget.this, mDragObject, false); } } } diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 1f2696504..1525e41d2 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -237,8 +237,6 @@ public class Workspace extends PagedView final WallpaperOffsetInterpolator mWallpaperOffset; private boolean mUnlockWallpaperFromDefaultPageOnLayout; - @Thunk Runnable mDelayedResizeRunnable; - // Variables relating to the creation of user folders by hovering shortcuts over shortcuts private static final int FOLDER_CREATION_TIMEOUT = 0; public static final int REORDER_TIMEOUT = 350; @@ -401,9 +399,6 @@ public class Workspace extends PagedView } updateChildrenLayersEnabled(); - mLauncher.lockScreenOrientation(); - // Prevent any Un/InstallShortcutReceivers from updating the db while we are dragging - InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_DRAG_AND_DROP); // Do not add a new page if it is a accessible drag which was not started by the workspace. // We do not support accessibility drag from other sources and instead provide a direct @@ -453,12 +448,6 @@ public class Workspace extends PagedView } updateChildrenLayersEnabled(); - mLauncher.unlockScreenOrientation(false); - - // Re-enable any Un/InstallShortcutReceiver and now process any queued items - InstallShortcutReceiver.disableAndFlushInstallQueue( - InstallShortcutReceiver.FLAG_DRAG_AND_DROP, getContext()); - mOutlineProvider = null; mDragSourceInternal = null; } @@ -1087,11 +1076,6 @@ public class Workspace extends PagedView } } - if (mDelayedResizeRunnable != null && !mIsSwitchingState) { - mDelayedResizeRunnable.run(); - mDelayedResizeRunnable = null; - } - if (mStripScreensOnPageStopMoving) { stripEmptyScreens(); mStripScreensOnPageStopMoving = false; @@ -1744,7 +1728,6 @@ public class Workspace extends PagedView } }); } - options.deferCompleteForUninstall = true; beginDragShared(child, this, options); } @@ -1960,8 +1943,7 @@ public class Workspace extends PagedView } boolean createUserFolderIfNecessary(View newView, long container, CellLayout target, - int[] targetCell, float distance, boolean external, DragView dragView, - Runnable postAnimationRunnable) { + int[] targetCell, float distance, boolean external, DragView dragView) { if (distance > mMaxDistanceForFolderCreation) return false; View v = target.getChildAt(targetCell[0], targetCell[1]); @@ -2005,8 +1987,8 @@ public class Workspace extends PagedView // folder background to the newly created icon. This preserves animation state. fi.setFolderBackground(mFolderCreateBg); mFolderCreateBg = new PreviewBackground(); - fi.performCreateAnimation(destInfo, v, sourceInfo, dragView, folderLocation, scale, - postAnimationRunnable); + fi.performCreateAnimation(destInfo, v, sourceInfo, dragView, folderLocation, scale + ); } else { fi.prepareCreateAnimation(v); fi.addItem(destInfo); @@ -2060,13 +2042,14 @@ public class Workspace extends PagedView int snapScreen = -1; boolean resizeOnDrop = false; - if (d.dragSource != this) { + if (d.dragSource != this || mDragInfo == null) { final int[] touchXY = new int[] { (int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1] }; onDropExternal(touchXY, dropTargetLayout, d); - } else if (mDragInfo != null) { + } else { final View cell = mDragInfo.cell; boolean droppedOnOriginalCellDuringTransition = false; + Runnable onCompleteRunnable = null; if (dropTargetLayout != null && !d.cancelled) { // Move internally @@ -2090,12 +2073,11 @@ public class Workspace extends PagedView // If the item being dropped is a shortcut and the nearest drop // cell also contains a shortcut, then create a folder with the two shortcuts. if (createUserFolderIfNecessary(cell, container, - dropTargetLayout, mTargetCell, distance, false, d.dragView, null)) { - return; - } - - if (addToExistingFolderIfNecessary(cell, dropTargetLayout, mTargetCell, - distance, d, false)) { + dropTargetLayout, mTargetCell, distance, false, d.dragView) || + addToExistingFolderIfNecessary(cell, dropTargetLayout, mTargetCell, + distance, d, false)) { + mLauncher.exitSpringLoadedDragMode(true, + Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT); return; } @@ -2177,7 +2159,7 @@ public class Workspace extends PagedView AppWidgetProviderInfo pInfo = hostView.getAppWidgetInfo(); if (pInfo != null && pInfo.resizeMode != AppWidgetProviderInfo.RESIZE_NONE && !d.accessibleDrag) { - mDelayedResizeRunnable = new Runnable() { + onCompleteRunnable = new Runnable() { public void run() { if (!isPageInTransition()) { AppWidgetResizeFrame.showForWidget(hostView, cellLayout); @@ -2209,9 +2191,9 @@ public class Workspace extends PagedView // Animate the item to its original position, while simultaneously exiting // spring-loaded mode so the page meets the icon where it was picked up. mLauncher.getDragController().animateDragViewToOriginalPosition( - mDelayedResizeRunnable, cell, + onCompleteRunnable, cell, mStateTransitionAnimation.mSpringLoadedTransitionTime); - mLauncher.exitSpringLoadedDragMode(); + mLauncher.exitSpringLoadedDragMode(false, 0); mLauncher.getDropTargetBar().onDragEnd(); parent.onDropChild(cell); return; @@ -2226,14 +2208,18 @@ public class Workspace extends PagedView } else { int duration = snapScreen < 0 ? -1 : ADJACENT_SCREEN_DROP_DURATION; mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, cell, duration, - null, this); + this); } } else { d.deferDragViewCleanupPostAnimation = false; cell.setVisibility(VISIBLE); } parent.onDropChild(cell); + + mLauncher.exitSpringLoadedDragMode(true, + Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, onCompleteRunnable); } + if (d.stateAnnouncer != null && !droppedOnOriginalCell) { d.stateAnnouncer.completeAction(R.string.item_moved); } @@ -2741,14 +2727,6 @@ public class Workspace extends PagedView * to add an item to one of the workspace screens. */ private void onDropExternal(final int[] touchXY, final CellLayout cellLayout, DragObject d) { - final Runnable exitSpringLoadedRunnable = new Runnable() { - @Override - public void run() { - mLauncher.exitSpringLoadedDragModeDelayed(true, - Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); - } - }; - if (d.dragInfo instanceof PendingAddShortcutInfo) { ShortcutInfo si = ((PendingAddShortcutInfo) d.dragInfo) .activityInfo.createShortcutInfo(); @@ -2846,6 +2824,9 @@ public class Workspace extends PagedView animationStyle, finalView, true); } else { // This is for other drag/drop cases, like dragging from All Apps + mLauncher.exitSpringLoadedDragMode(true, + Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT); + View view; switch (info.itemType) { @@ -2874,9 +2855,8 @@ public class Workspace extends PagedView cellLayout, mTargetCell); float distance = cellLayout.getDistanceFromCell(mDragViewVisualCenter[0], mDragViewVisualCenter[1], mTargetCell); - d.postAnimationRunnable = exitSpringLoadedRunnable; if (createUserFolderIfNecessary(view, container, cellLayout, mTargetCell, distance, - true, d.dragView, d.postAnimationRunnable)) { + true, d.dragView)) { return; } if (addToExistingFolderIfNecessary(view, cellLayout, mTargetCell, distance, d, @@ -2909,7 +2889,7 @@ public class Workspace extends PagedView // the correct final location. setFinalTransitionTransform(cellLayout); mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, view, - exitSpringLoadedRunnable, this); + this); resetTransitionTransform(cellLayout); } } @@ -3085,7 +3065,7 @@ public class Workspace extends PagedView * Called at the end of a drag which originated on the workspace. */ public void onDropCompleted(final View target, final DragObject d, - final boolean isFlingToDelete, final boolean success) { + final boolean success) { if (success) { if (target != this && mDragInfo != null) { @@ -3105,13 +3085,6 @@ public class Workspace extends PagedView mDragInfo.cell.setVisibility(VISIBLE); } mDragInfo = null; - - if (!isFlingToDelete) { - // Fling to delete already exits spring loaded mode after the animation finishes. - mLauncher.exitSpringLoadedDragModeDelayed(success, - Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, mDelayedResizeRunnable); - mDelayedResizeRunnable = null; - } } /** diff --git a/src/com/android/launcher3/allapps/AllAppsContainerView.java b/src/com/android/launcher3/allapps/AllAppsContainerView.java index 91b196eea..4de31f4c2 100644 --- a/src/com/android/launcher3/allapps/AllAppsContainerView.java +++ b/src/com/android/launcher3/allapps/AllAppsContainerView.java @@ -31,10 +31,10 @@ import android.widget.RelativeLayout; import com.android.launcher3.AppInfo; import com.android.launcher3.BubbleTextView; import com.android.launcher3.ClickShadowView; -import com.android.launcher3.DeleteDropTarget; import com.android.launcher3.DeviceProfile; import com.android.launcher3.DragSource; import com.android.launcher3.DropTarget; +import com.android.launcher3.DropTarget.DragObject; import com.android.launcher3.Insettable; import com.android.launcher3.ItemInfo; import com.android.launcher3.Launcher; @@ -44,7 +44,6 @@ import com.android.launcher3.anim.SpringAnimationHandler; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.dragndrop.DragController; import com.android.launcher3.dragndrop.DragOptions; -import com.android.launcher3.folder.Folder; import com.android.launcher3.keyboard.FocusedItemDecorator; import com.android.launcher3.userevent.nano.LauncherLogProto.Target; import com.android.launcher3.util.PackageUserKey; @@ -322,21 +321,7 @@ public class AllAppsContainerView extends RelativeLayout implements DragSource, } @Override - public void onDropCompleted(View target, DropTarget.DragObject d, boolean isFlingToDelete, - boolean success) { - if (isFlingToDelete || !success || (target != mLauncher.getWorkspace() && - !(target instanceof DeleteDropTarget) && !(target instanceof Folder))) { - // Exit spring loaded mode if we have not successfully dropped or have not handled the - // drop in Workspace - mLauncher.exitSpringLoadedDragModeDelayed(true, - Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); - } - mLauncher.unlockScreenOrientation(false); - - if (!success) { - d.deferDragViewCleanupPostAnimation = false; - } - } + public void onDropCompleted(View target, DragObject d, boolean success) { } @Override public void fillInLogContainerData(View v, ItemInfo info, Target target, Target targetParent) { diff --git a/src/com/android/launcher3/dragndrop/BaseItemDragListener.java b/src/com/android/launcher3/dragndrop/BaseItemDragListener.java index 727fb51ce..96aaee03b 100644 --- a/src/com/android/launcher3/dragndrop/BaseItemDragListener.java +++ b/src/com/android/launcher3/dragndrop/BaseItemDragListener.java @@ -28,12 +28,10 @@ import android.util.Log; import android.view.DragEvent; import android.view.View; -import com.android.launcher3.DeleteDropTarget; import com.android.launcher3.DragSource; -import com.android.launcher3.DropTarget; +import com.android.launcher3.DropTarget.DragObject; import com.android.launcher3.Launcher; import com.android.launcher3.R; -import com.android.launcher3.folder.Folder; import com.android.launcher3.widget.PendingItemDragHelper; import java.util.UUID; @@ -141,7 +139,7 @@ public abstract class BaseItemDragListener implements } @Override - public void onPreDragStart(DropTarget.DragObject dragObject) { + public void onPreDragStart(DragObject dragObject) { // The predrag starts when the workspace is not yet loaded. In some cases we set // the dragLayer alpha to 0 to have a nice fade-in animation. But that will prevent the // dragView from being visible. Instead just skip the fade-in animation here. @@ -152,26 +150,14 @@ public abstract class BaseItemDragListener implements } @Override - public void onPreDragEnd(DropTarget.DragObject dragObject, boolean dragStarted) { + public void onPreDragEnd(DragObject dragObject, boolean dragStarted) { if (dragStarted) { dragObject.dragView.setColor(0); } } @Override - public void onDropCompleted(View target, DropTarget.DragObject d, boolean isFlingToDelete, - boolean success) { - if (isFlingToDelete || !success || (target != mLauncher.getWorkspace() && - !(target instanceof DeleteDropTarget) && !(target instanceof Folder))) { - // Exit spring loaded mode if we have not successfully dropped or have not handled the - // drop in Workspace - mLauncher.exitSpringLoadedDragModeDelayed(true, - Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); - } - - if (!success) { - d.deferDragViewCleanupPostAnimation = false; - } + public void onDropCompleted(View target, DragObject d, boolean success) { postCleanup(); } 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); } } diff --git a/src/com/android/launcher3/dragndrop/DragLayer.java b/src/com/android/launcher3/dragndrop/DragLayer.java index 60ce3c36a..95223c3f7 100644 --- a/src/com/android/launcher3/dragndrop/DragLayer.java +++ b/src/com/android/launcher3/dragndrop/DragLayer.java @@ -491,13 +491,12 @@ public class DragLayer extends InsettableFrameLayout { onFinishRunnable, animationEndStyle, duration, null); } - public void animateViewIntoPosition(DragView dragView, final View child, - final Runnable onFinishAnimationRunnable, View anchorView) { - animateViewIntoPosition(dragView, child, -1, onFinishAnimationRunnable, anchorView); + public void animateViewIntoPosition(DragView dragView, final View child, View anchorView) { + animateViewIntoPosition(dragView, child, -1, anchorView); } public void animateViewIntoPosition(DragView dragView, final View child, int duration, - final Runnable onFinishAnimationRunnable, View anchorView) { + View anchorView) { ShortcutAndWidgetContainer parentChildren = (ShortcutAndWidgetContainer) child.getParent(); CellLayout.LayoutParams lp = (CellLayout.LayoutParams) child.getLayoutParams(); parentChildren.measureChild(child); @@ -554,9 +553,6 @@ public class DragLayer extends InsettableFrameLayout { Runnable onCompleteRunnable = new Runnable() { public void run() { child.setVisibility(VISIBLE); - if (onFinishAnimationRunnable != null) { - onFinishAnimationRunnable.run(); - } } }; animateViewIntoPosition(dragView, fromX, fromY, toX, toY, 1, 1, 1, toScale, toScale, diff --git a/src/com/android/launcher3/dragndrop/DragOptions.java b/src/com/android/launcher3/dragndrop/DragOptions.java index 550f94830..f108f8b53 100644 --- a/src/com/android/launcher3/dragndrop/DragOptions.java +++ b/src/com/android/launcher3/dragndrop/DragOptions.java @@ -38,12 +38,6 @@ public class DragOptions { public float intrinsicIconScaleFactor = 1f; /** - * Whether or not to defer {@link com.android.launcher3.DragSource#onDropCompleted} until - * uninstall result is available when dropped on uninstall drop target. - */ - public boolean deferCompleteForUninstall = false; - - /** * Specifies a condition that must be met before DragListener#onDragStart() is called. * By default, there is no condition and onDragStart() is called immediately following * DragController#startDrag(). diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java index b930ad3ca..4a60d4c56 100644 --- a/src/com/android/launcher3/folder/Folder.java +++ b/src/com/android/launcher3/folder/Folder.java @@ -283,7 +283,6 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC } }); } - options.deferCompleteForUninstall = true; mLauncher.getWorkspace().beginDragShared(v, this, options); } @@ -850,7 +849,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC } public void onDropCompleted(final View target, final DragObject d, - final boolean isFlingToDelete, final boolean success) { + final boolean success) { if (success) { if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon && target != this) { @@ -898,12 +897,6 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, false, mLauncher.getModelWriter()); } - - if (!isFlingToDelete) { - // Fling to delete already exits spring loaded mode after the animation finishes. - mLauncher.exitSpringLoadedDragModeDelayed(success, - Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); - } } private void updateItemLocationsInDatabaseBatch() { @@ -1158,21 +1151,6 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC } public void onDrop(DragObject d, DragOptions options) { - Runnable cleanUpRunnable = null; - - // If we are coming from All Apps space, we defer removing the extra empty screen - // until the folder closes - if (d.dragSource != mLauncher.getWorkspace() && !(d.dragSource instanceof Folder)) { - cleanUpRunnable = new Runnable() { - @Override - public void run() { - mLauncher.exitSpringLoadedDragModeDelayed(true, - Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, - null); - } - }; - } - // If the icon was dropped while the page was being scrolled, we need to compute // the target location again such that the icon is placed of the final page. if (!mContent.rankOnCurrentPage(mEmptyCellRank)) { @@ -1238,8 +1216,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC float scaleY = getScaleY(); setScaleX(1.0f); setScaleY(1.0f); - mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, currentDragView, - cleanUpRunnable, null); + mLauncher.getDragLayer().animateViewIntoPosition(d.dragView, currentDragView, null); setScaleX(scaleX); setScaleY(scaleY); } else { @@ -1264,6 +1241,8 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC mInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, mLauncher.getModelWriter()); } + mLauncher.exitSpringLoadedDragMode(true, + Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT); if (d.stateAnnouncer != null) { d.stateAnnouncer.completeAction(R.string.item_moved); } diff --git a/src/com/android/launcher3/folder/FolderIcon.java b/src/com/android/launcher3/folder/FolderIcon.java index 399888899..d469eb254 100644 --- a/src/com/android/launcher3/folder/FolderIcon.java +++ b/src/com/android/launcher3/folder/FolderIcon.java @@ -254,7 +254,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { public void performCreateAnimation(final ShortcutInfo destInfo, final View destView, final ShortcutInfo srcInfo, final DragView srcView, Rect dstRect, - float scaleRelativeToDragLayer, Runnable postAnimationRunnable) { + float scaleRelativeToDragLayer) { prepareCreateAnimation(destView); addItem(destInfo); // This will animate the first item from it's position as an icon into its @@ -263,7 +263,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { .start(); // This will animate the dragView (srcView) into the new folder - onDrop(srcInfo, srcView, dstRect, scaleRelativeToDragLayer, 1, postAnimationRunnable, + onDrop(srcInfo, srcView, dstRect, scaleRelativeToDragLayer, 1, false /* itemReturnedOnFailedDrop */); } @@ -279,7 +279,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { } private void onDrop(final ShortcutInfo item, DragView animateView, Rect finalRect, - float scaleRelativeToDragLayer, int index, Runnable postAnimationRunnable, + float scaleRelativeToDragLayer, int index, boolean itemReturnedOnFailedDrop) { item.cellX = -1; item.cellY = -1; @@ -351,7 +351,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { dragLayer.animateView(animateView, from, to, finalAlpha, 1, 1, finalScale, finalScale, DROP_IN_ANIMATION_DURATION, new DecelerateInterpolator(2), new AccelerateInterpolator(2), - postAnimationRunnable, DragLayer.ANIMATION_END_DISAPPEAR, null); + null, DragLayer.ANIMATION_END_DISAPPEAR, null); mFolder.hideItem(item); @@ -381,7 +381,7 @@ public class FolderIcon extends FrameLayout implements FolderListener { item = (ShortcutInfo) d.dragInfo; } mFolder.notifyDrop(); - onDrop(item, d.dragView, null, 1.0f, mInfo.contents.size(), d.postAnimationRunnable, + onDrop(item, d.dragView, null, 1.0f, mInfo.contents.size(), itemReturnedOnFailedDrop); } diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java index 68b547d88..4435afb8f 100644 --- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java +++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java @@ -39,6 +39,7 @@ import android.view.View; import com.android.launcher3.BubbleTextView; import com.android.launcher3.DragSource; import com.android.launcher3.DropTarget; +import com.android.launcher3.DropTarget.DragObject; import com.android.launcher3.ItemInfo; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAnimUtils; @@ -487,14 +488,7 @@ public class PopupContainerWithArrow extends BaseActionPopup<BubbleTextView> imp } @Override - public void onDropCompleted(View target, DropTarget.DragObject d, boolean isFlingToDelete, - boolean success) { - if (!success) { - d.dragView.remove(); - mLauncher.showWorkspace(true); - mLauncher.getDropTargetBar().onDragEnd(); - } - } + public void onDropCompleted(View target, DragObject d, boolean success) { } @Override public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) { diff --git a/src/com/android/launcher3/util/FlingAnimation.java b/src/com/android/launcher3/util/FlingAnimation.java index d475ee9df..15f5af625 100644 --- a/src/com/android/launcher3/util/FlingAnimation.java +++ b/src/com/android/launcher3/util/FlingAnimation.java @@ -95,7 +95,7 @@ public class FlingAnimation implements AnimatorUpdateListener, Runnable { Runnable onAnimationEndRunnable = new Runnable() { @Override public void run() { - mLauncher.exitSpringLoadedDragMode(); + mLauncher.exitSpringLoadedDragMode(false, 0); mDropTarget.completeDrop(mDragObject); } }; diff --git a/src/com/android/launcher3/widget/BaseWidgetSheet.java b/src/com/android/launcher3/widget/BaseWidgetSheet.java index ee5dd66bd..b6b3089b0 100644 --- a/src/com/android/launcher3/widget/BaseWidgetSheet.java +++ b/src/com/android/launcher3/widget/BaseWidgetSheet.java @@ -159,21 +159,7 @@ abstract class BaseWidgetSheet extends AbstractFloatingView // @Override - public void onDropCompleted(View target, DragObject d, boolean isFlingToDelete, - boolean success) { - if (isFlingToDelete || !success || (target != mLauncher.getWorkspace() && - !(target instanceof DeleteDropTarget) && !(target instanceof Folder))) { - // Exit spring loaded mode if we have not successfully dropped or have not handled the - // drop in Workspace - mLauncher.exitSpringLoadedDragModeDelayed(true, - Launcher.EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT, null); - } - mLauncher.unlockScreenOrientation(false); - - if (!success) { - d.deferDragViewCleanupPostAnimation = false; - } - } + public void onDropCompleted(View target, DragObject d, boolean success) { } @Override |