summaryrefslogtreecommitdiffstats
path: root/src/com
diff options
context:
space:
mode:
authorDanesh M <daneshm90@gmail.com>2013-12-04 21:37:46 -0800
committerMichael Bestas <mikeioannina@gmail.com>2014-01-30 08:13:46 +0200
commitb54b34edd5c87e6d0702793b423b14dc24fb1076 (patch)
tree569cbfc176703f0a10bb105e394197a531d65a4c /src/com
parentcebd8d4ed0486127dc997e1b2ca25a173df3e4d1 (diff)
downloadandroid_packages_apps_Trebuchet-b54b34edd5c87e6d0702793b423b14dc24fb1076.tar.gz
android_packages_apps_Trebuchet-b54b34edd5c87e6d0702793b423b14dc24fb1076.tar.bz2
android_packages_apps_Trebuchet-b54b34edd5c87e6d0702793b423b14dc24fb1076.zip
Trebuchet : Default workspace improvements
Ported from cm-10.2 Adds support for fallback in default_workspace Change-Id: I2590ae2d5e3c1b6124061581b9ffa206d611c608
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/launcher3/LauncherModel.java126
-rw-r--r--src/com/android/launcher3/LauncherProvider.java35
2 files changed, 97 insertions, 64 deletions
diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java
index 70b6d55b1..5b2ba588c 100644
--- a/src/com/android/launcher3/LauncherModel.java
+++ b/src/com/android/launcher3/LauncherModel.java
@@ -1303,6 +1303,69 @@ public class LauncherModel extends BroadcastReceiver {
return false;
}
+ // check & update map of what's occupied; used to discard overlapping/invalid items
+ public boolean checkItemPlacement(HashMap<Long, ItemInfo[][]> occupied, ItemInfo item,
+ AtomicBoolean deleteOnItemOverlap) {
+ LauncherAppState app = LauncherAppState.getInstance();
+ DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
+ int countX = (int) grid.numColumns;
+ int countY = (int) grid.numRows;
+
+ long containerIndex = item.screenId;
+ if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
+ if (occupied.containsKey(LauncherSettings.Favorites.CONTAINER_HOTSEAT)) {
+ if (occupied.get(LauncherSettings.Favorites.CONTAINER_HOTSEAT)
+ [(int) item.screenId][0] != null) {
+ Log.e(TAG, "Error loading shortcut into hotseat " + item
+ + " into position (" + item.screenId + ":" + item.cellX + ","
+ + item.cellY + ") occupied by "
+ + occupied.get(LauncherSettings.Favorites.CONTAINER_HOTSEAT)
+ [(int) item.screenId][0]);
+ if (occupied.get(LauncherSettings.Favorites.CONTAINER_HOTSEAT)
+ [(int) item.screenId][0].itemType == LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS) {
+ deleteOnItemOverlap.set(true);
+ }
+ return false;
+ }
+ } else {
+ ItemInfo[][] items = new ItemInfo[countX + 1][countY + 1];
+ items[(int) item.screenId][0] = item;
+ occupied.put((long) LauncherSettings.Favorites.CONTAINER_HOTSEAT, items);
+ return true;
+ }
+ } else if (item.container != LauncherSettings.Favorites.CONTAINER_DESKTOP) {
+ // Skip further checking if it is not the hotseat or workspace container
+ return true;
+ }
+
+ if (!occupied.containsKey(item.screenId)) {
+ ItemInfo[][] items = new ItemInfo[countX + 1][countY + 1];
+ occupied.put(item.screenId, items);
+ }
+
+ ItemInfo[][] screens = occupied.get(item.screenId);
+ // 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 (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;
+ }
+ }
+ }
+ 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;
+ }
+ }
+
+ return true;
+ }
+
/**
* Runnable for the thread that loads the contents of the launcher:
* - workspace icons
@@ -1571,69 +1634,6 @@ public class LauncherModel extends BroadcastReceiver {
(info.cellY + info.spanY) > (int) grid.numRows;
}
- // check & update map of what's occupied; used to discard overlapping/invalid items
- private boolean checkItemPlacement(HashMap<Long, ItemInfo[][]> occupied, ItemInfo item,
- AtomicBoolean deleteOnItemOverlap) {
- LauncherAppState app = LauncherAppState.getInstance();
- DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
- int countX = (int) grid.numColumns;
- int countY = (int) grid.numRows;
-
- long containerIndex = item.screenId;
- if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
- if (occupied.containsKey(LauncherSettings.Favorites.CONTAINER_HOTSEAT)) {
- if (occupied.get(LauncherSettings.Favorites.CONTAINER_HOTSEAT)
- [(int) item.screenId][0] != null) {
- Log.e(TAG, "Error loading shortcut into hotseat " + item
- + " into position (" + item.screenId + ":" + item.cellX + ","
- + item.cellY + ") occupied by "
- + occupied.get(LauncherSettings.Favorites.CONTAINER_HOTSEAT)
- [(int) item.screenId][0]);
- if (occupied.get(LauncherSettings.Favorites.CONTAINER_HOTSEAT)
- [(int) item.screenId][0].itemType == LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS) {
- deleteOnItemOverlap.set(true);
- }
- return false;
- }
- } else {
- ItemInfo[][] items = new ItemInfo[countX + 1][countY + 1];
- items[(int) item.screenId][0] = item;
- occupied.put((long) LauncherSettings.Favorites.CONTAINER_HOTSEAT, items);
- return true;
- }
- } else if (item.container != LauncherSettings.Favorites.CONTAINER_DESKTOP) {
- // Skip further checking if it is not the hotseat or workspace container
- return true;
- }
-
- if (!occupied.containsKey(item.screenId)) {
- ItemInfo[][] items = new ItemInfo[countX + 1][countY + 1];
- occupied.put(item.screenId, items);
- }
-
- ItemInfo[][] screens = occupied.get(item.screenId);
- // 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 (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;
- }
- }
- }
- 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;
- }
- }
-
- return true;
- }
-
/** Clears all the sBg data structures */
private void clearSBgDataStructures() {
synchronized (sBgLock) {
diff --git a/src/com/android/launcher3/LauncherProvider.java b/src/com/android/launcher3/LauncherProvider.java
index 2ff612ff3..210bbf8bc 100644
--- a/src/com/android/launcher3/LauncherProvider.java
+++ b/src/com/android/launcher3/LauncherProvider.java
@@ -59,7 +59,9 @@ import org.xmlpull.v1.XmlPullParserException;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.concurrent.atomic.AtomicBoolean;
public class LauncherProvider extends ContentProvider {
private static final String TAG = "Launcher.LauncherProvider";
@@ -1034,6 +1036,10 @@ public class LauncherProvider extends ContentProvider {
final int depth = parser.getDepth();
+ final HashMap<Long, ItemInfo[][]> occupied = new HashMap<Long, ItemInfo[][]>();
+ LauncherModel model = LauncherAppState.getInstance().getModel();
+ AtomicBoolean deleteItem = new AtomicBoolean();
+
int type;
while (((type = parser.next()) != XmlPullParser.END_TAG ||
parser.getDepth() > depth) && type != XmlPullParser.END_DOCUMENT) {
@@ -1086,6 +1092,18 @@ 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.spanX = a.getInt(R.styleable.Favorite_spanX, 1);
+ info.spanY = a.getInt(R.styleable.Favorite_spanY, 1);
+ info.cellX = a.getInt(R.styleable.Favorite_x, 0);
+ info.cellY = a.getInt(R.styleable.Favorite_y, 0);
+ info.screenId = a.getInt(R.styleable.Favorite_screen, 0);
+
+ if (!model.checkItemPlacement(occupied, info, deleteItem)) {
+ continue;
+ }
+
if (LOGD) {
final String title = a.getString(R.styleable.Favorite_title);
final String pkg = a.getString(R.styleable.Favorite_packageName);
@@ -1172,7 +1190,22 @@ public class LauncherProvider extends ContentProvider {
added = false;
}
}
- if (added) i++;
+ if (added) {
+ i++;
+ } else {
+ long containerIndex = info.screenId;
+ if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
+ occupied.get((long) LauncherSettings.Favorites.CONTAINER_HOTSEAT)
+ [(int) info.screenId][0] = null;
+ } else {
+ ItemInfo[][] screens = occupied.get(info.screenId);
+ for (int gridX = info.cellX; gridX < (info.cellX+info.spanX); gridX++) {
+ for (int gridY = info.cellY; gridY < (info.cellY+info.spanY); gridY++) {
+ screens[gridX][gridY] = null;
+ }
+ }
+ }
+ }
a.recycle();
}
} catch (XmlPullParserException e) {