From 5d990eedfd7013c9e3eb8cb6599b66d2c3053be3 Mon Sep 17 00:00:00 2001 From: Sebastian Franco Date: Tue, 1 Nov 2022 16:08:24 -0700 Subject: [PATCH] Ensure that the reorder preview and what gets submited uses the same solution. Design doc: https://docs.google.com/document/d/1RsId9OFGgkcImkkmDwWZBBvITWnGlxKVqniE3cimkqY/edit#heading=h.xzptrog8pyxf As can be seen in the diagram in b/256770363 on every reorder the first call in the process is MODE_SHOW_REORDER_HINT so if we make sure that only then a solution is calculated and we reuse that solution in the rest of the calls in the same reorder then we would have more consistency and the animation will always be the same and the logic state. Fix: 256770363 Bug: 188081026 Test: atest ReorderWidgets Change-Id: I93a1d09f5b8cbfbc461043ee3fc41b1cab294fed --- src/com/android/launcher3/CellLayout.java | 20 ++++++++++---------- src/com/android/launcher3/Workspace.java | 19 ++++++++----------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index 9d059bbb0e..455a2fe970 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -2543,21 +2543,21 @@ public class CellLayout extends ViewGroup { if (result == null) { result = new int[]{-1, -1}; } - ItemConfiguration finalSolution; - // When we are checking drop validity or actually dropping, we don't recompute the - // direction vector, since we want the solution to match the preview, and it's possible - // that the exact position of the item has changed to result in a new reordering outcome. - if ((mode == MODE_ON_DROP || mode == MODE_ON_DROP_EXTERNAL || mode == MODE_ACCEPT_DROP) - && mPreviousSolution != null) { + + ItemConfiguration finalSolution = null; + // We want the solution to match the animation of the preview and to match the drop so we + // only recalculate in mode MODE_SHOW_REORDER_HINT because that the first one to run in the + // reorder cycle. + if (mode == MODE_SHOW_REORDER_HINT || mPreviousSolution == null) { + finalSolution = calculateReorder(pixelX, pixelY, minSpanX, minSpanY, spanX, spanY, + dragView); + mPreviousSolution = finalSolution; + } else { finalSolution = mPreviousSolution; // We reset this vector after drop if (mode == MODE_ON_DROP || mode == MODE_ON_DROP_EXTERNAL) { mPreviousSolution = null; } - } else { - finalSolution = calculateReorder(pixelX, pixelY, minSpanX, minSpanY, spanX, spanY, - dragView); - mPreviousSolution = finalSolution; } if (finalSolution == null || !finalSolution.isSolution) { diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index b6eb58973d..b66f42e442 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -2467,23 +2467,20 @@ public class Workspace extends PagedView final View child = (mDragInfo == null) ? null : mDragInfo.cell; int reorderX = mTargetCell[0]; int reorderY = mTargetCell[1]; - if (!nearestDropOccupied) { - mDragTargetLayout.performReorder((int) mDragViewVisualCenter[0], - (int) mDragViewVisualCenter[1], minSpanX, minSpanY, item.spanX, item.spanY, - child, mTargetCell, new int[2], CellLayout.MODE_SHOW_REORDER_HINT); - mDragTargetLayout.visualizeDropLocation(mTargetCell[0], mTargetCell[1], - item.spanX, item.spanY, d); - } else if ((mDragMode == DRAG_MODE_NONE || mDragMode == DRAG_MODE_REORDER) - && !mReorderAlarm.alarmPending() + if ((mDragMode == DRAG_MODE_NONE || mDragMode == DRAG_MODE_REORDER) && (mLastReorderX != reorderX || mLastReorderY != reorderY) && targetCellDistance < mDragTargetLayout.getReorderRadius(mTargetCell, item.spanX, item.spanY)) { - - int[] resultSpan = new int[2]; mDragTargetLayout.performReorder((int) mDragViewVisualCenter[0], (int) mDragViewVisualCenter[1], minSpanX, minSpanY, item.spanX, item.spanY, - child, mTargetCell, resultSpan, CellLayout.MODE_SHOW_REORDER_HINT); + child, mTargetCell, new int[2], CellLayout.MODE_SHOW_REORDER_HINT); + } + if (!nearestDropOccupied) { + mDragTargetLayout.visualizeDropLocation(mTargetCell[0], mTargetCell[1], + item.spanX, item.spanY, d); + } else if ((mDragMode == DRAG_MODE_NONE || mDragMode == DRAG_MODE_REORDER) + && !mReorderAlarm.alarmPending()) { // Otherwise, if we aren't adding to or creating a folder and there's no pending // reorder, then we schedule a reorder ReorderAlarmListener listener = new ReorderAlarmListener(mDragViewVisualCenter,