From 5dc7435b3352ab6f5645a2450290ed317bf1b054 Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Tue, 6 Dec 2016 16:24:43 -0800 Subject: [PATCH] Move icon back to original cell if a quick drag would cause reorder. Most likely the user accidentally dragged the icon, so let's not rearrange their home screen. Bug: 30378199 Change-Id: I815a0817bca3b0d212324a58842b1f59dfdf0b91 --- src/com/android/launcher3/Workspace.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index bd21412392..85cb73678a 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -2569,10 +2569,19 @@ public class Workspace extends PagedView && item.screenId == screenId && item.container == container && item.cellX == mTargetCell[0] && item.cellY == mTargetCell[1]; + // When quickly moving an item, a user may accidentally rearrange their + // workspace. So instead we move the icon back safely to its original position. + boolean returnToOriginalCellToPreventShuffling = !isFinishedSwitchingState() + && !droppedOnOriginalCellDuringTransition && !dropTargetLayout + .isRegionVacant(mTargetCell[0], mTargetCell[1], spanX, spanY); int[] resultSpan = new int[2]; - mTargetCell = dropTargetLayout.performReorder((int) mDragViewVisualCenter[0], - (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY, cell, - mTargetCell, resultSpan, CellLayout.MODE_ON_DROP); + if (returnToOriginalCellToPreventShuffling) { + mTargetCell[0] = mTargetCell[1] = -1; + } else { + mTargetCell = dropTargetLayout.performReorder((int) mDragViewVisualCenter[0], + (int) mDragViewVisualCenter[1], minSpanX, minSpanY, spanX, spanY, cell, + mTargetCell, resultSpan, CellLayout.MODE_ON_DROP); + } boolean foundCell = mTargetCell[0] >= 0 && mTargetCell[1] >= 0; @@ -2638,7 +2647,9 @@ public class Workspace extends PagedView LauncherModel.modifyItemInDatabase(mLauncher, info, container, screenId, lp.cellX, lp.cellY, item.spanX, item.spanY); } else { - onNoCellFound(dropTargetLayout); + if (!returnToOriginalCellToPreventShuffling) { + onNoCellFound(dropTargetLayout); + } // If we can't find a drop location, we return the item to its original position CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams();