Creating a correctly populated mOccupied grid when reordering on foldables

On ag/21680045 I copy the previous mOccupied but the right thing to do is to
create a new one with all the views information.

Some test stoped running inadvertently that's why we didn't catch this issue.

There is a separate cl with the test to ensure we can catch it later on.

Fix: 289584301
Test: ReorderWidgets
Change-Id: I27b5a6e38a556d1c73ff8fbbdd552da6045e5b64
This commit is contained in:
Sebastian Franco
2023-07-12 12:46:53 -07:00
parent 551cbc4969
commit 1c5514b566
@@ -19,8 +19,10 @@ import android.view.View;
import com.android.launcher3.CellLayout;
import com.android.launcher3.MultipageCellLayout;
import com.android.launcher3.ShortcutAndWidgetContainer;
import com.android.launcher3.util.GridOccupancy;
import java.util.Arrays;
import java.util.function.Supplier;
/**
@@ -79,7 +81,7 @@ public class MulticellReorderAlgorithm extends ReorderAlgorithm {
lp.canReorder = false;
mcl.setCountX(mcl.getCountX() + 1);
mcl.getShortcutsAndWidgets().addViewInLayout(mSeam, lp);
mcl.setOccupied(createGridOccupancyWithSeam(mcl.getOccupied()));
mcl.setOccupied(createGridOccupancyWithSeam());
mcl.mTmpOccupied = new GridOccupancy(mcl.getCountX(), mcl.getCountY());
}
@@ -93,7 +95,8 @@ public class MulticellReorderAlgorithm extends ReorderAlgorithm {
/**
* The function supplied here will execute while the CellLayout has a simulated seam added.
* @param f function to run under simulation
*
* @param f function to run under simulation
* @param <T> return value of the supplied function
* @return Value of supplied function
*/
@@ -110,18 +113,17 @@ public class MulticellReorderAlgorithm extends ReorderAlgorithm {
return res;
}
GridOccupancy createGridOccupancyWithSeam(GridOccupancy gridOccupancy) {
GridOccupancy createGridOccupancyWithSeam() {
ShortcutAndWidgetContainer shortcutAndWidgets = mCellLayout.getShortcutsAndWidgets();
GridOccupancy grid = new GridOccupancy(mCellLayout.getCountX(), mCellLayout.getCountY());
for (int x = 0; x < mCellLayout.getCountX(); x++) {
for (int y = 0; y < mCellLayout.getCountY(); y++) {
int offset = x >= mCellLayout.getCountX() / 2 ? 1 : 0;
if (x == mCellLayout.getCountX() / 2) {
grid.cells[x][y] = true;
} else {
grid.cells[x][y] = gridOccupancy.cells[x - offset][y];
}
}
for (int i = 0; i < shortcutAndWidgets.getChildCount(); i++) {
View view = shortcutAndWidgets.getChildAt(i);
CellLayoutLayoutParams lp = (CellLayoutLayoutParams) view.getLayoutParams();
int seamOffset = lp.getCellX() >= mCellLayout.getCountX() / 2 && lp.canReorder ? 1 : 0;
grid.markCells(lp.getCellX() + seamOffset, lp.getCellY(), lp.cellHSpan, lp.cellVSpan,
true);
}
Arrays.fill(grid.cells[mCellLayout.getCountX() / 2], true);
return grid;
}
}