Fix widget resize if it last for too long on Multipage CellLayout
We need to make sure the seam is added when the countX is even
checking for => and if you reszie for a while the occupied grid
starts to have incorrect values.
Fix: 270227019
Test: atest FoldableItemsIntegrity
Test: atest ReorderWidgets
Change-Id: I3faf5d23427dc966c48ce5c613e68e42a101f45b
diff --git a/src/com/android/launcher3/MultipageCellLayout.java b/src/com/android/launcher3/MultipageCellLayout.java
index 0d59848..6a518a7 100644
--- a/src/com/android/launcher3/MultipageCellLayout.java
+++ b/src/com/android/launcher3/MultipageCellLayout.java
@@ -70,7 +70,7 @@
boolean createAreaForResize(int cellX, int cellY, int spanX, int spanY, View dragView,
int[] direction, boolean commit) {
// Add seam to x position
- if (cellX > mCountX / 2) {
+ if (cellX >= mCountX / 2) {
cellX++;
}
int finalCellX = cellX;
@@ -109,7 +109,7 @@
lp.canReorder = false;
mCountX++;
mShortcutsAndWidgets.addViewInLayout(mSeam, lp);
- mOccupied = createGridOccupancy();
+ mOccupied = createGridOccupancyWithSeam(mOccupied);
mTmpOccupied = new GridOccupancy(mCountX, mCountY);
}
@@ -139,14 +139,19 @@
return solution;
}
- GridOccupancy createGridOccupancy() {
- GridOccupancy grid = new GridOccupancy(mCountX, mCountY);
- for (int i = 0; i < mShortcutsAndWidgets.getChildCount(); i++) {
- View view = mShortcutsAndWidgets.getChildAt(i);
- CellLayoutLayoutParams lp = (CellLayoutLayoutParams) view.getLayoutParams();
- int seamOffset = lp.getCellX() >= mCountX / 2 && lp.canReorder ? 1 : 0;
- grid.markCells(lp.getCellX() + seamOffset, lp.getCellY(), lp.cellHSpan, lp.cellVSpan,
- true);
+
+
+ GridOccupancy createGridOccupancyWithSeam(GridOccupancy gridOccupancy) {
+ GridOccupancy grid = new GridOccupancy(getCountX(), getCountY());
+ for (int x = 0; x < getCountX(); x++) {
+ for (int y = 0; y < getCountY(); y++) {
+ int offset = x >= getCountX() / 2 ? 1 : 0;
+ if (x == getCountX() / 2) {
+ grid.cells[x][y] = true;
+ } else {
+ grid.cells[x][y] = gridOccupancy.cells[x - offset][y];
+ }
+ }
}
return grid;
}