From f9a6ac241a6d2725823b2661a7342acd1d9874ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebasti=C3=A1n=20Franco?= Date: Tue, 15 Nov 2022 22:56:37 +0000 Subject: [PATCH 1/2] Revert "Revert "Reorder widgets no longer overlaps when no space..." Revert "Revert "Reorder widgets no longer overlaps when no space..." Revert submission 20479526-revert-20427045-258023561-BPDASTWITO Reason for revert: Fix the issue that caused the first revert. Reverted Changes: Icecfd1d34:Revert "Reorder widgets no longer overlaps when no... I4cc552588:Revert "Reorder widgets no longer overlaps when no... Change-Id: I47c4cde42c19f50e2834660d843a8e2ae571c03c --- src/com/android/launcher3/CellLayout.java | 51 ++++++++++++------- src/com/android/launcher3/Workspace.java | 3 +- .../launcher3/folder/FolderPagedView.java | 2 +- 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index de2a1f91ed..e500e59369 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -1651,8 +1651,19 @@ public class CellLayout extends ViewGroup { } } - private ItemConfiguration findConfigurationNoShuffle(int pixelX, int pixelY, int minSpanX, int minSpanY, - int spanX, int spanY, View dragView, ItemConfiguration solution) { + /** + * Returns a "reorder" where we simply drop the item in the closest empty space, without moving + * any other item in the way. + * + * @param pixelX X coordinate in pixels in the screen + * @param pixelY Y coordinate in pixels in the screen + * @param spanX horizontal cell span + * @param spanY vertical cell span + * @return the configuration that represents the found reorder + */ + private ItemConfiguration closestEmptySpaceReorder(int pixelX, int pixelY, int minSpanX, + int minSpanY, int spanX, int spanY) { + ItemConfiguration solution = new ItemConfiguration(); int[] result = new int[2]; int[] resultSpan = new int[2]; findNearestVacantArea(pixelX, pixelY, minSpanX, minSpanY, spanX, spanY, result, @@ -1697,7 +1708,7 @@ public class CellLayout extends ViewGroup { boolean isNearestDropLocationOccupied(int pixelX, int pixelY, int spanX, int spanY, View dragView, int[] result) { - result = findNearestArea(pixelX, pixelY, spanX, spanY, result); + result = findNearestAreaIgnoreOccupied(pixelX, pixelY, spanX, spanY, result); getViewsIntersectingRegion(result[0], result[1], spanX, spanY, dragView, null, mIntersectingViews); return !mIntersectingViews.isEmpty(); @@ -2247,7 +2258,8 @@ public class CellLayout extends ViewGroup { //TODO(adamcohen) b/151776141 use the items visual center for the direction vector int[] targetDestination = new int[2]; - findNearestArea(dragViewCenterX, dragViewCenterY, spanX, spanY, targetDestination); + findNearestAreaIgnoreOccupied(dragViewCenterX, dragViewCenterY, spanX, spanY, + targetDestination); Rect dragRect = new Rect(); cellToRect(targetDestination[0], targetDestination[1], spanX, spanY, dragRect); dragRect.offset(dragViewCenterX - dragRect.centerX(), dragViewCenterY - dragRect.centerY()); @@ -2400,7 +2412,7 @@ public class CellLayout extends ViewGroup { // We find the nearest cell into which we would place the dragged item, assuming there's // nothing in its way. int result[] = new int[2]; - result = findNearestArea(pixelX, pixelY, spanX, spanY, result); + result = findNearestAreaIgnoreOccupied(pixelX, pixelY, spanX, spanY, result); boolean success; // First we try the exact nearest position of the item being dragged, @@ -2445,19 +2457,21 @@ public class CellLayout extends ViewGroup { } /** - * Returns a "reorder" where we simply drop the item in the closest empty space, without moving - * any other item in the way. + * Returns a "reorder" if there is empty space without rearranging anything. * * @param pixelX X coordinate in pixels in the screen * @param pixelY Y coordinate in pixels in the screen * @param spanX horizontal cell span * @param spanY vertical cell span + * @param dragView view being dragged in reorder * @return the configuration that represents the found reorder */ - public ItemConfiguration closestEmptySpaceReorder(int pixelX, int pixelY, int spanX, - int spanY) { + public ItemConfiguration dropInPlaceSolution(int pixelX, int pixelY, int spanX, + int spanY, View dragView) { int[] result = new int[2]; - result = findNearestArea(pixelX, pixelY, spanX, spanY, result); + if (isNearestDropLocationOccupied(pixelX, pixelY, spanX, spanY, dragView, result)) { + result[0] = result[1] = -1; + } ItemConfiguration solution = new ItemConfiguration(); copyCurrentStateToSolution(solution, false); solution.isSolution = result[0] != -1; @@ -2490,25 +2504,25 @@ public class CellLayout extends ViewGroup { int spanX, int spanY, View dragView) { getDirectionVectorForDrop(pixelX, pixelY, spanX, spanY, dragView, mDirectionVector); - ItemConfiguration closestSpaceSolution = closestEmptySpaceReorder(pixelX, pixelY, spanX, - spanY); + ItemConfiguration dropInPlaceSolution = dropInPlaceSolution(pixelX, pixelY, spanX, spanY, + dragView); // Find a solution involving pushing / displacing any items in the way ItemConfiguration swapSolution = findReorderSolution(pixelX, pixelY, minSpanX, minSpanY, spanX, spanY, mDirectionVector, dragView, true, new ItemConfiguration()); // We attempt the approach which doesn't shuffle views at all - ItemConfiguration noShuffleSolution = findConfigurationNoShuffle(pixelX, pixelY, minSpanX, - minSpanY, spanX, spanY, dragView, new ItemConfiguration()); + ItemConfiguration closestSpaceSolution = closestEmptySpaceReorder(pixelX, pixelY, minSpanX, + minSpanY, spanX, spanY); // If the reorder solution requires resizing (shrinking) the item being dropped, we instead // favor a solution in which the item is not resized, but - if (swapSolution.isSolution && swapSolution.area() >= noShuffleSolution.area()) { + if (swapSolution.isSolution && swapSolution.area() >= closestSpaceSolution.area()) { return swapSolution; - } else if (noShuffleSolution.isSolution) { - return noShuffleSolution; } else if (closestSpaceSolution.isSolution) { return closestSpaceSolution; + } else if (dropInPlaceSolution.isSolution) { + return dropInPlaceSolution; } return null; } @@ -2665,7 +2679,8 @@ public class CellLayout extends ViewGroup { * @return The X, Y cell of a vacant area that can contain this object, * nearest the requested location. */ - public int[] findNearestArea(int pixelX, int pixelY, int spanX, int spanY, int[] result) { + public int[] findNearestAreaIgnoreOccupied(int pixelX, int pixelY, int spanX, int spanY, + int[] result) { return findNearestArea(pixelX, pixelY, spanX, spanY, spanX, spanY, true, result, null); } diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 27e1ba143b..b31db82ab3 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -2615,7 +2615,6 @@ public class Workspace extends PagedView setDragMode(DRAG_MODE_REORDER); } - boolean resize = resultSpan[0] != spanX || resultSpan[1] != spanY; mDragTargetLayout.visualizeDropLocation(mTargetCell[0], mTargetCell[1], resultSpan[0], resultSpan[1], dragObject); } @@ -2972,7 +2971,7 @@ public class Workspace extends PagedView */ @Thunk int[] findNearestArea(int pixelX, int pixelY, int spanX, int spanY, CellLayout layout, int[] recycle) { - return layout.findNearestArea( + return layout.findNearestAreaIgnoreOccupied( pixelX, pixelY, spanX, spanY, recycle); } diff --git a/src/com/android/launcher3/folder/FolderPagedView.java b/src/com/android/launcher3/folder/FolderPagedView.java index efd511de37..b87ab17cb3 100644 --- a/src/com/android/launcher3/folder/FolderPagedView.java +++ b/src/com/android/launcher3/folder/FolderPagedView.java @@ -365,7 +365,7 @@ public class FolderPagedView extends PagedView implements Cli public int findNearestArea(int pixelX, int pixelY) { int pageIndex = getNextPage(); CellLayout page = getPageAt(pageIndex); - page.findNearestArea(pixelX, pixelY, 1, 1, sTmpArray); + page.findNearestAreaIgnoreOccupied(pixelX, pixelY, 1, 1, sTmpArray); if (mFolder.isLayoutRtl()) { sTmpArray[0] = page.getCountX() - sTmpArray[0] - 1; } From 9c74327e13b18a550dda6feec3f7651ed80edaa9 Mon Sep 17 00:00:00 2001 From: Sebastian Franco Date: Tue, 15 Nov 2022 15:03:25 -0800 Subject: [PATCH 2/2] Fixing the revert by not continuing the reorder if the solution is null. Fix: 258023561 Bug: 259234533 Test: atest testAddDeleteShortcutOnHotseat Change-Id: I63a2abf8a80e16fb45f4bbb3b2de413ef77b5e0c --- src/com/android/launcher3/CellLayout.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java index e500e59369..691184afc0 100644 --- a/src/com/android/launcher3/CellLayout.java +++ b/src/com/android/launcher3/CellLayout.java @@ -2559,8 +2559,8 @@ public class CellLayout extends ViewGroup { result[1] = finalSolution.cellY; resultSpan[0] = finalSolution.spanX; resultSpan[1] = finalSolution.spanY; + performReorder(finalSolution, dragView, mode); } - performReorder(finalSolution, dragView, mode); return result; }