From 61b19a25bc4bfded2add524834d02f6146d20810 Mon Sep 17 00:00:00 2001 From: Danesh Mondegarian Date: Sat, 2 Nov 2013 22:52:52 -0700 Subject: Trebuchet : Check item placement when setting defaultWorkspace In its current state, the launcher blindly adds any item specified in the default workspace (even those that overlap). Consequently, it throws an error each time it tries to load the database. This patchset addresses that by dismissing insertion of overlapping items. This allows for fallbacks to be specified in the default_workspace.xml Change-Id: I08a6bd699defb908565ca2f47c855516eecf5643 --- src/com/cyanogenmod/trebuchet/LauncherModel.java | 64 +++++++++++----------- .../cyanogenmod/trebuchet/LauncherProvider.java | 28 ++++++++++ 2 files changed, 60 insertions(+), 32 deletions(-) diff --git a/src/com/cyanogenmod/trebuchet/LauncherModel.java b/src/com/cyanogenmod/trebuchet/LauncherModel.java index 51fac6f7a..5d6d902ee 100644 --- a/src/com/cyanogenmod/trebuchet/LauncherModel.java +++ b/src/com/cyanogenmod/trebuchet/LauncherModel.java @@ -1028,6 +1028,38 @@ public class LauncherModel extends BroadcastReceiver { return false; } + // check & update map of what's occupied; used to discard overlapping/invalid items + public boolean checkItemPlacement(ItemInfo occupied[][][], ItemInfo item) { + int containerIndex = item.screen; + if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { + containerIndex += Launcher.MAX_WORKSPACE_SCREEN_COUNT; + } else if (item.container != LauncherSettings.Favorites.CONTAINER_DESKTOP) { + // Skip further checking if it is not the hotseat or workspace container + return true; + } + + // 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 (occupied[containerIndex][x][y] != null) { + Log.e(TAG, "Error loading shortcut " + item + + " into cell (" + containerIndex + "-" + item.screen + ":" + + x + "," + y + + ") occupied by " + + occupied[containerIndex][x][y]); + return false; + } + } + } + for (int x = item.cellX; x < (item.cellX+item.spanX); x++) { + for (int y = item.cellY; y < (item.cellY+item.spanY); y++) { + occupied[containerIndex][x][y] = item; + } + } + + return true; + } + /** * Runnable for the thread that loads the contents of the launcher: * - workspace icons @@ -1267,38 +1299,6 @@ public class LauncherModel extends BroadcastReceiver { } } - // check & update map of what's occupied; used to discard overlapping/invalid items - private boolean checkItemPlacement(ItemInfo occupied[][][], ItemInfo item) { - int containerIndex = item.screen; - if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { - containerIndex += Launcher.MAX_WORKSPACE_SCREEN_COUNT; - } else if (item.container != LauncherSettings.Favorites.CONTAINER_DESKTOP) { - // Skip further checking if it is not the hotseat or workspace container - return true; - } - - // 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 (occupied[containerIndex][x][y] != null) { - Log.e(TAG, "Error loading shortcut " + item - + " into cell (" + containerIndex + "-" + item.screen + ":" - + x + "," + y - + ") occupied by " - + occupied[containerIndex][x][y]); - return false; - } - } - } - for (int x = item.cellX; x < (item.cellX+item.spanX); x++) { - for (int y = item.cellY; y < (item.cellY+item.spanY); y++) { - occupied[containerIndex][x][y] = item; - } - } - - return true; - } - private void loadWorkspace() { final long t = DEBUG_LOADERS ? SystemClock.uptimeMillis() : 0; diff --git a/src/com/cyanogenmod/trebuchet/LauncherProvider.java b/src/com/cyanogenmod/trebuchet/LauncherProvider.java index 260a16a6b..823221f80 100644 --- a/src/com/cyanogenmod/trebuchet/LauncherProvider.java +++ b/src/com/cyanogenmod/trebuchet/LauncherProvider.java @@ -615,6 +615,13 @@ public class LauncherProvider extends ContentProvider { final int depth = parser.getDepth(); + LauncherApplication app = ((LauncherApplication) mContext); + final ItemInfo occupied[][][] = + new ItemInfo[Launcher.MAX_SCREEN_COUNT][Math.max( + LauncherModel.getWorkspaceCellCountX(), LauncherModel.getHotseatCellCount())] + [Math.max(LauncherModel.getWorkspaceCellCountX(), + LauncherModel.getHotseatCellCount())]; + int type; while (((type = parser.next()) != XmlPullParser.END_TAG || parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) { @@ -643,6 +650,27 @@ public class LauncherProvider extends ContentProvider { values.put(LauncherSettings.Favorites.CELLX, x); values.put(LauncherSettings.Favorites.CELLY, y); + ItemInfo info = new ItemInfo(); + info.container = container; + info.cellX = values.getAsInteger(LauncherSettings.Favorites.CELLX); + info.cellY = values.getAsInteger(LauncherSettings.Favorites.CELLY); + info.screen = values.getAsInteger(LauncherSettings.Favorites.SCREEN); + + if (values.containsKey(LauncherSettings.Favorites.SPANX)) { + info.spanX = values.getAsInteger(LauncherSettings.Favorites.SPANX); + } else { + info.spanX = 1; + } + if (values.containsKey(LauncherSettings.Favorites.SPANY)) { + info.spanY = values.getAsInteger(LauncherSettings.Favorites.SPANY); + } else { + info.spanY = 1; + } + + if (!app.getModel().checkItemPlacement(occupied, info)) { + continue; + } + if (TAG_FAVORITE.equals(name)) { long id = addAppShortcut(db, values, a, packageManager, intent); added = id >= 0; -- cgit v1.2.3