diff options
author | Matt Garnes <matt@cyngn.com> | 2015-06-19 13:11:08 -0700 |
---|---|---|
committer | Matt Garnes <matt@cyngn.com> | 2015-06-22 19:09:38 +0000 |
commit | cae95210719c7d520afcf1b5c6f088d776c974d2 (patch) | |
tree | d80d3d0c99aa812060628175b1d65faa4b7589f3 /src/com/android/launcher3/LauncherModel.java | |
parent | e806def329c6a928f98923ddb021ffd8acfb0b65 (diff) | |
download | android_packages_apps_Trebuchet-cae95210719c7d520afcf1b5c6f088d776c974d2.tar.gz android_packages_apps_Trebuchet-cae95210719c7d520afcf1b5c6f088d776c974d2.tar.bz2 android_packages_apps_Trebuchet-cae95210719c7d520afcf1b5c6f088d776c974d2.zip |
Fix unintended dynamic grid resize side effects.
- Do not attempt to resize the grid unless the dynamic grid resize has
been explicitly triggered.
- Workspace Ids are 1 indexed not 0, so on resize, start at 1.
- After resizing the grid, persist the changes to the DB. The initial
implementation only did the resize in memory and did not persist this,
causing side effects later.
Bugs fixed:
1. Resize the dynamic grid from large to small. Add a new icon by
installing a new app or adding a shortcut from file manager. The new
icon will overlap one on one of the new pages.
2. Resize the grid from large to small in a previous version of
trebuchet (before the grid resize feature was added). Icons on the outer
edges of the grid will be lost but persist in the DB. Upgrade to a new
version of Trebuchet. The icons will return to the workspace.
Change-Id: I8b0defafb3299d1f3d534526a75f9253495d739d
Diffstat (limited to 'src/com/android/launcher3/LauncherModel.java')
-rw-r--r-- | src/com/android/launcher3/LauncherModel.java | 50 |
1 files changed, 43 insertions, 7 deletions
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index f67e828aa..fbacc3937 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -100,6 +100,7 @@ public class LauncherModel extends BroadcastReceiver public static final int LOADER_FLAG_NONE = 0; public static final int LOADER_FLAG_CLEAR_WORKSPACE = 1 << 0; public static final int LOADER_FLAG_MIGRATE_SHORTCUTS = 1 << 1; + public static final int LOADER_FLAG_RESIZE_GRID = 1 << 2; private static final int ITEMS_CHUNK = 6; // batch size for the workspace icons private static final long INVALID_SCREEN_ID = -1L; @@ -1857,7 +1858,8 @@ public class LauncherModel extends BroadcastReceiver // check & update map of what's occupied; used to discard overlapping/invalid items private boolean checkItemPlacement(HashMap<Long, ItemInfo[][]> occupied, ItemInfo item, - AtomicBoolean deleteOnInvalidPlacement) { + AtomicBoolean deleteOnInvalidPlacement, + boolean shouldResizeAndUpdateDB) { LauncherAppState app = LauncherAppState.getInstance(); DeviceProfile grid = app.getDynamicGrid().getDeviceProfile(); final int countX = (int) grid.numColumns; @@ -1914,12 +1916,21 @@ public class LauncherModel extends BroadcastReceiver // available position. if (item.cellX < 0 || item.cellY < 0 || item.cellX + item.spanX > countX || item.cellY + item.spanY > countY) { + // If we won't be resizing the grid, then just return, this item does not fit. + if (!shouldResizeAndUpdateDB) { + Log.e(TAG, "Error loading shortcut " + item + + " into cell (" + containerIndex + "-" + item.screenId + ":" + + item.cellX + "," + item.cellY + + ") out of screen bounds ( " + countX + "x" + countY + ")"); + return false; + } + if (item.itemType != LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET) { - // Place the item at 0 0 of screen 0 + // Place the item at 0 0 of screen 1 // if items overlap here, they will be moved later on item.cellX = 0; item.cellY = 0; - item.screenId = 0; + item.screenId = 1; item.wasMovedDueToReducedSpace = true; item.requiresDbUpdate = true; } else { @@ -1961,6 +1972,16 @@ public class LauncherModel extends BroadcastReceiver // Check if any workspace icons overlap with each other for (int x = item.cellX; x < (item.cellX + item.spanX); x++) { for (int y = item.cellY; y < (item.cellY + item.spanY); y++) { + // If we are not resizing the grid, overlapping items should be rejected. + if (!shouldResizeAndUpdateDB && screens[x][y] != null) { + Log.e(TAG, "Error loading shortcut " + item + + " into cell (" + containerIndex + "-" + item.screenId + ":" + + x + "," + y + + ") occupied by " + + screens[x][y]); + return false; + } + if (screens[x][y] != null) { ItemInfo occupiedItem = screens[x][y]; // If an item is overlapping another because one of them @@ -2008,7 +2029,8 @@ public class LauncherModel extends BroadcastReceiver for (int x = item.cellX; x < (item.cellX + item.spanX); x++) { for (int y = item.cellY; y < (item.cellY + item.spanY); y++) { screens[x][y] = item; - if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET) { + if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET + && shouldResizeAndUpdateDB) { // fill up the entire grid where the widget technically is for (int spanX = x; spanX < item.spanX; spanX++) { screens[spanX][y] = item; @@ -2056,6 +2078,8 @@ public class LauncherModel extends BroadcastReceiver int countX = (int) grid.numColumns; int countY = (int) grid.numRows; + boolean shouldResize = ((mFlags & LOADER_FLAG_RESIZE_GRID) != 0); + if ((mFlags & LOADER_FLAG_CLEAR_WORKSPACE) != 0) { Launcher.addDumpLog(TAG, "loadWorkspace: resetting launcher database", true); LauncherAppState.getLauncherProvider().deleteDatabase(); @@ -2320,7 +2344,8 @@ public class LauncherModel extends BroadcastReceiver // check & update map of what's occupied deleteOnInvalidPlacement.set(false); - if (!checkItemPlacement(occupied, info, deleteOnInvalidPlacement)) { + if (!checkItemPlacement(occupied, info, + deleteOnInvalidPlacement, shouldResize)) { if (deleteOnInvalidPlacement.get()) { itemsToRemove.add(id); } @@ -2367,7 +2392,7 @@ public class LauncherModel extends BroadcastReceiver // check & update map of what's occupied deleteOnInvalidPlacement.set(false); if (!checkItemPlacement(occupied, folderInfo, - deleteOnInvalidPlacement)) { + deleteOnInvalidPlacement, shouldResize)) { if (deleteOnInvalidPlacement.get()) { itemsToRemove.add(id); } @@ -2480,7 +2505,7 @@ public class LauncherModel extends BroadcastReceiver // check & update map of what's occupied deleteOnInvalidPlacement.set(false); if (!checkItemPlacement(occupied, appWidgetInfo, - deleteOnInvalidPlacement)) { + deleteOnInvalidPlacement, shouldResize)) { if (deleteOnInvalidPlacement.get()) { itemsToRemove.add(id); } @@ -2619,6 +2644,17 @@ public class LauncherModel extends BroadcastReceiver updateWorkspaceScreenOrder(context, sBgWorkspaceScreens); } + // If any items have been shifted and require a DB update, update them in the DB. + if (shouldResize) { + for (ItemInfo info : sBgWorkspaceItems) { + if (info != null && info.requiresDbUpdate) { + info.requiresDbUpdate = false; + LauncherModel.modifyItemInDatabase(mContext, info, info.container, + info.screenId, info.cellX, info.cellY, info.spanX, info.spanY); + } + } + } + if (DEBUG_LOADERS) { Log.d(TAG, "loaded workspace in " + (SystemClock.uptimeMillis()-t) + "ms"); Log.d(TAG, "workspace layout: "); |