diff options
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 18 | ||||
-rw-r--r-- | src/com/android/launcher3/dragndrop/DragController.java | 29 | ||||
-rw-r--r-- | src/com/android/launcher3/dragndrop/DragView.java | 16 | ||||
-rw-r--r-- | src/com/android/launcher3/folder/Folder.java | 14 |
4 files changed, 52 insertions, 25 deletions
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 95a5ee29f..5e7fe6bc8 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -2528,6 +2528,7 @@ public class Workspace extends PagedView onDropExternal(touchXY, d.dragInfo, dropTargetLayout, false, d); } else if (mDragInfo != null) { final View cell = mDragInfo.cell; + boolean droppedOnOriginalCellDuringTransition = false; if (dropTargetLayout != null && !d.cancelled) { // Move internally @@ -2570,6 +2571,10 @@ public class Workspace extends PagedView minSpanY = item.minSpanY; } + droppedOnOriginalCellDuringTransition = mIsSwitchingState + && item.screenId == screenId && item.container == container + && item.cellX == mTargetCell[0] && item.cellY == mTargetCell[1]; + int[] resultSpan = new int[2]; mTargetCell = dropTargetLayout.performReorder((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY, cell, @@ -2627,7 +2632,7 @@ public class Workspace extends PagedView && !d.accessibleDrag) { mDelayedResizeRunnable = new Runnable() { public void run() { - if (!isPageInTransition() && !mIsSwitchingState) { + if (!isPageInTransition()) { DragLayer dragLayer = mLauncher.getDragLayer(); dragLayer.addResizeFrame(hostView, cellLayout); } @@ -2662,6 +2667,17 @@ public class Workspace extends PagedView }; mAnimatingViewIntoPlace = true; if (d.dragView.hasDrawn()) { + if (droppedOnOriginalCellDuringTransition) { + // 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, + mStateTransitionAnimation.mSpringLoadedTransitionTime); + mLauncher.exitSpringLoadedDragMode(); + mLauncher.getDropTargetBar().onDragEnd(); + parent.onDropChild(cell); + return; + } final ItemInfo info = (ItemInfo) cell.getTag(); boolean isWidget = info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET || info.itemType == LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET; diff --git a/src/com/android/launcher3/dragndrop/DragController.java b/src/com/android/launcher3/dragndrop/DragController.java index e11bfc682..67ef5fc3c 100644 --- a/src/com/android/launcher3/dragndrop/DragController.java +++ b/src/com/android/launcher3/dragndrop/DragController.java @@ -295,10 +295,6 @@ public class DragController implements DragDriver.EventListener, TouchController mIsInPreDrag = false; } - public boolean isInPreDrag() { - return mIsInPreDrag; - } - /** * Call this from a drag source view like this: * @@ -361,6 +357,8 @@ public class DragController implements DragDriver.EventListener, TouchController isDeferred = mDragObject.deferDragViewCleanupPostAnimation; if (!isDeferred) { mDragObject.dragView.remove(); + } else if (mIsInPreDrag) { + animateDragViewToOriginalPosition(null, null, -1); } mDragObject.dragView = null; } @@ -374,6 +372,22 @@ public class DragController implements DragDriver.EventListener, TouchController releaseVelocityTracker(); } + public void animateDragViewToOriginalPosition(final Runnable onComplete, + final View originalIcon, int duration) { + Runnable onCompleteRunnable = new Runnable() { + @Override + public void run() { + if (originalIcon != null) { + originalIcon.setVisibility(View.VISIBLE); + } + if (onComplete != null) { + onComplete.run(); + } + } + }; + mDragObject.dragView.animateTo(mMotionDownX, mMotionDownY, onCompleteRunnable, duration); + } + private void callOnDragEnd() { if (mIsInPreDrag && mOptions.preDragCondition != null) { mOptions.preDragCondition.onPreDragEnd(false /* dragStarted*/); @@ -738,7 +752,7 @@ public class DragController implements DragDriver.EventListener, TouchController if (dropTarget.acceptDrop(mDragObject)) { if (flingVel != null) { dropTarget.onFlingToDelete(mDragObject, flingVel); - } else { + } else if (!mIsInPreDrag) { dropTarget.onDrop(mDragObject); } accepted = true; @@ -749,11 +763,6 @@ public class DragController implements DragDriver.EventListener, TouchController 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/DragView.java b/src/com/android/launcher3/dragndrop/DragView.java index 8a2ae94f6..22e077bb1 100644 --- a/src/com/android/launcher3/dragndrop/DragView.java +++ b/src/com/android/launcher3/dragndrop/DragView.java @@ -23,7 +23,6 @@ import android.animation.ValueAnimator; import android.animation.ValueAnimator.AnimatorUpdateListener; import android.annotation.SuppressLint; import android.annotation.TargetApi; -import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; @@ -38,12 +37,10 @@ import android.view.animation.DecelerateInterpolator; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAnimUtils; +import com.android.launcher3.R; import com.android.launcher3.Utilities; -import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.util.Thunk; -import com.android.launcher3.R; - import java.util.Arrays; public class DragView extends View { @@ -57,6 +54,8 @@ public class DragView extends View { @Thunk Paint mPaint; private final int mRegistrationX; private final int mRegistrationY; + private final float mInitialScale; + private final int[] mTempLoc = new int[2]; private Point mDragVisualizeOffset = null; private Rect mDragRegion = null; @@ -138,6 +137,8 @@ public class DragView extends View { mRegistrationX = registrationX; mRegistrationY = registrationY; + mInitialScale = initialScale; + // Force a measure, because Workspace uses getMeasuredHeight() before the layout pass int ms = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); measure(ms, ms); @@ -356,6 +357,13 @@ public class DragView extends View { applyTranslation(); } + public void animateTo(int toTouchX, int toTouchY, Runnable onCompleteRunnable, int duration) { + mTempLoc[0] = toTouchX - mRegistrationX; + mTempLoc[1] = toTouchY - mRegistrationY; + mDragLayer.animateViewIntoPosition(this, mTempLoc, 1f, mInitialScale, mInitialScale, + DragLayer.ANIMATION_END_DISAPPEAR, onCompleteRunnable, duration); + } + public void animateShift(final int shiftX, final int shiftY) { if (mAnim.isStarted()) { return; diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java index 2952196fa..53c12b5b1 100644 --- a/src/com/android/launcher3/folder/Folder.java +++ b/src/com/android/launcher3/folder/Folder.java @@ -1331,10 +1331,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC mIsExternalDrag = false; } else { currentDragView = mCurrentDragView; - // The view was never removed from this folder if we are still in the pre-drag. - if (!mDragController.isInPreDrag()) { - mContent.addViewForRank(currentDragView, si, mEmptyCellRank); - } + mContent.addViewForRank(currentDragView, si, mEmptyCellRank); } if (d.dragView.hasDrawn()) { @@ -1355,12 +1352,9 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC mItemsInvalidated = true; rearrangeChildren(); - // The ShortcutInfo was never removed if we are still in the pre-drag. - if (!mDragController.isInPreDrag()) { - // Temporarily suppress the listener, as we did all the work already here. - try (SuppressInfoChanges s = new SuppressInfoChanges()) { - mInfo.add(si, false); - } + // Temporarily suppress the listener, as we did all the work already here. + try (SuppressInfoChanges s = new SuppressInfoChanges()) { + mInfo.add(si, false); } // Clear the drag info, as it is no longer being dragged. |