Fixes bug where app suggestions incorrectly calculate available space when bottom row is full
Bug: 318417510
Flag: N/A
Test: manually tested toggling app suggestions with the bottom row filled / not filled
Change-Id: I25461aefa8db93a1c2548604c0ea15c9a12ae688
diff --git a/src/com/android/launcher3/CellLayout.java b/src/com/android/launcher3/CellLayout.java
index 5443ff9..5a51d8e 100644
--- a/src/com/android/launcher3/CellLayout.java
+++ b/src/com/android/launcher3/CellLayout.java
@@ -1718,7 +1718,7 @@
// First we determine if things have moved enough to cause a different layout
ItemConfiguration swapSolution = findReorderSolution(pixelXY[0], pixelXY[1], spanX, spanY,
- spanX, spanY, direction, dragView, true, new ItemConfiguration());
+ spanX, spanY, direction, dragView, true);
setUseTempCoords(true);
if (swapSolution != null && swapSolution.isSolution) {
@@ -1747,13 +1747,13 @@
}
protected ItemConfiguration findReorderSolution(int pixelX, int pixelY, int minSpanX,
- int minSpanY, int spanX, int spanY, int[] direction, View dragView, boolean decX,
- ItemConfiguration solution) {
+ int minSpanY, int spanX, int spanY, int[] direction, View dragView, boolean decX) {
ItemConfiguration configuration = new ItemConfiguration();
copyCurrentStateToSolution(configuration);
ReorderParameters parameters = new ReorderParameters(pixelX, pixelY, spanX, spanY, minSpanX,
minSpanY, dragView, configuration);
- return createReorderAlgorithm().findReorderSolution(parameters, decX);
+ int[] directionVector = direction != null ? direction : mDirectionVector;
+ return createReorderAlgorithm().findReorderSolution(parameters, directionVector, decX);
}
public void copyCurrentStateToSolution(ItemConfiguration solution) {
@@ -2077,7 +2077,7 @@
cellToPoint(cellX, cellY, cellPoint);
if (findReorderSolution(cellPoint[0], cellPoint[1], itemInfo.minSpanX,
itemInfo.minSpanY, itemInfo.spanX, itemInfo.spanY, mDirectionVector, null,
- true, new ItemConfiguration()).isSolution) {
+ true).isSolution) {
return true;
}
}
@@ -2092,9 +2092,18 @@
int[] cellPoint = new int[2];
int[] directionVector = new int[]{0, -1};
cellToPoint(0, mCountY, cellPoint);
- ItemConfiguration configuration = new ItemConfiguration();
- if (findReorderSolution(cellPoint[0], cellPoint[1], mCountX, 1, mCountX, 1,
- directionVector, null, false, configuration).isSolution) {
+ ItemConfiguration configuration = findReorderSolution(
+ cellPoint[0] /* pixelX */,
+ cellPoint[1] /* pixelY */,
+ mCountX /* minSpanX */,
+ 1 /* minSpanY */,
+ mCountX /* spanX */,
+ 1 /* spanY */,
+ directionVector /* direction */,
+ null /* dragView */,
+ false /* decX */
+ );
+ if (configuration.isSolution) {
if (commitConfig) {
copySolutionToTempState(configuration, null);
commitTempPlacement(null);
diff --git a/src/com/android/launcher3/celllayout/ReorderAlgorithm.java b/src/com/android/launcher3/celllayout/ReorderAlgorithm.java
index 8754b74..c303783 100644
--- a/src/com/android/launcher3/celllayout/ReorderAlgorithm.java
+++ b/src/com/android/launcher3/celllayout/ReorderAlgorithm.java
@@ -49,21 +49,37 @@
* When changing the size of the widget this method will try first subtracting -1 in the x
* dimension and then subtracting -1 in the y dimension until finding a possible solution or
* until it no longer can reduce the span.
- *
* @param decX whether it will decrease the horizontal or vertical span if it can't find a
* solution for the current span.
* @return the same solution variable
*/
public ItemConfiguration findReorderSolution(ReorderParameters reorderParameters,
boolean decX) {
+ return findReorderSolution(reorderParameters, mCellLayout.mDirectionVector, decX);
+ }
+
+ /**
+ * This method differs from closestEmptySpaceReorder and dropInPlaceSolution because this method
+ * will move items around and will change the shape of the item if possible to try to find a
+ * solution.
+ * <p>
+ * When changing the size of the widget this method will try first subtracting -1 in the x
+ * dimension and then subtracting -1 in the y dimension until finding a possible solution or
+ * until it no longer can reduce the span.
+ * @param direction Direction to attempt to push items if needed
+ * @param decX whether it will decrease the horizontal or vertical span if it can't find a
+ * solution for the current span.
+ * @return the same solution variable
+ */
+ public ItemConfiguration findReorderSolution(ReorderParameters reorderParameters,
+ int[] direction, boolean decX) {
return findReorderSolutionRecursive(reorderParameters.getPixelX(),
reorderParameters.getPixelY(), reorderParameters.getMinSpanX(),
reorderParameters.getMinSpanY(), reorderParameters.getSpanX(),
- reorderParameters.getSpanY(), mCellLayout.mDirectionVector,
+ reorderParameters.getSpanY(), direction,
reorderParameters.getDragView(), decX, reorderParameters.getSolution());
}
-
private ItemConfiguration findReorderSolutionRecursive(int pixelX, int pixelY, int minSpanX,
int minSpanY, int spanX, int spanY, int[] direction, View dragView, boolean decX,
ItemConfiguration solution) {