summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanesh Mondegarian <daneshm90@gmail.com>2013-11-06 03:52:47 +0000
committerGerrit Code Review <gerrit@cyanogenmod.org>2013-11-06 03:52:47 +0000
commit4506c81c6e62f4c1957f880506001efd2b78a6b0 (patch)
tree6fb4f9c16bcbd6dc3f44aa312b1847988b240ade
parent8d4ee4139a46d4235f2f9a876b754fa37d495257 (diff)
parent61b19a25bc4bfded2add524834d02f6146d20810 (diff)
downloadandroid_packages_apps_Trebuchet-4506c81c6e62f4c1957f880506001efd2b78a6b0.tar.gz
android_packages_apps_Trebuchet-4506c81c6e62f4c1957f880506001efd2b78a6b0.tar.bz2
android_packages_apps_Trebuchet-4506c81c6e62f4c1957f880506001efd2b78a6b0.zip
Merge "Trebuchet : Check item placement when setting defaultWorkspace" into cm-10.2
-rw-r--r--src/com/cyanogenmod/trebuchet/LauncherModel.java64
-rw-r--r--src/com/cyanogenmod/trebuchet/LauncherProvider.java28
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 263fbc25e..196e08da5 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;