diff options
author | Winson Chung <winsonc@google.com> | 2011-07-13 17:25:49 -0700 |
---|---|---|
committer | Winson Chung <winsonc@google.com> | 2011-07-20 14:12:20 -0700 |
commit | 3d503fbd9468fb2b9fa645f4f7b91e11229edbfa (patch) | |
tree | 38d8bb61f62a47a731b97520a274e07cefbec20c /src/com/android/launcher2/LauncherModel.java | |
parent | ec8a2eee50290e7d9c95936041b937b6e94bb152 (diff) | |
download | android_packages_apps_Trebuchet-3d503fbd9468fb2b9fa645f4f7b91e11229edbfa.tar.gz android_packages_apps_Trebuchet-3d503fbd9468fb2b9fa645f4f7b91e11229edbfa.tar.bz2 android_packages_apps_Trebuchet-3d503fbd9468fb2b9fa645f4f7b91e11229edbfa.zip |
Initial changes to add configurable hotseat.
Change-Id: I4c2ed4a1c122c057662fabc70bfef7c5c088460b
Diffstat (limited to 'src/com/android/launcher2/LauncherModel.java')
-rw-r--r-- | src/com/android/launcher2/LauncherModel.java | 58 |
1 files changed, 36 insertions, 22 deletions
diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java index b4e632a41..c8cf1f832 100644 --- a/src/com/android/launcher2/LauncherModel.java +++ b/src/com/android/launcher2/LauncherModel.java @@ -178,17 +178,24 @@ public class LauncherModel extends BroadcastReceiver { static void moveItemInDatabase(Context context, final ItemInfo item, final long container, final int screen, final int cellX, final int cellY) { item.container = container; - item.screen = screen; item.cellX = cellX; item.cellY = cellY; + // We store hotseat items in canonical form which is this orientation invariant position + // in the hotseat + if (context instanceof Launcher && screen < 0 && + container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { + item.screen = ((Launcher) context).getHotseat().getOrderInHotseat(cellX, cellY); + } else { + item.screen = screen; + } final Uri uri = LauncherSettings.Favorites.getContentUri(item.id, false); final ContentValues values = new ContentValues(); final ContentResolver cr = context.getContentResolver(); values.put(LauncherSettings.Favorites.CONTAINER, item.container); - values.put(LauncherSettings.Favorites.CELLX, cellX); - values.put(LauncherSettings.Favorites.CELLY, cellY); + values.put(LauncherSettings.Favorites.CELLX, item.cellX); + values.put(LauncherSettings.Favorites.CELLY, item.cellY); values.put(LauncherSettings.Favorites.SCREEN, item.screen); sWorker.post(new Runnable() { @@ -205,7 +212,8 @@ public class LauncherModel extends BroadcastReceiver { // Items are added/removed from the corresponding FolderInfo elsewhere, such // as in Workspace.onDrop. Here, we just add/remove them from the list of items // that are on the desktop, as appropriate - if (modelItem.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { + if (modelItem.container == LauncherSettings.Favorites.CONTAINER_DESKTOP || + modelItem.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { if (!sWorkspaceItems.contains(modelItem)) { sWorkspaceItems.add(modelItem); } @@ -356,12 +364,19 @@ public class LauncherModel extends BroadcastReceiver { * Add an item to the database in a specified container. Sets the container, screen, cellX and * cellY fields of the item. Also assigns an ID to the item. */ - static void addItemToDatabase(Context context, final ItemInfo item, long container, - int screen, int cellX, int cellY, final boolean notify) { + static void addItemToDatabase(Context context, final ItemInfo item, final long container, + final int screen, final int cellX, final int cellY, final boolean notify) { item.container = container; - item.screen = screen; item.cellX = cellX; item.cellY = cellY; + // We store hotseat items in canonical form which is this orientation invariant position + // in the hotseat + if (context instanceof Launcher && screen < 0 && + container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { + item.screen = ((Launcher) context).getHotseat().getOrderInHotseat(cellX, cellY); + } else { + item.screen = screen; + } final ContentValues values = new ContentValues(); final ContentResolver cr = context.getContentResolver(); @@ -371,7 +386,7 @@ public class LauncherModel extends BroadcastReceiver { LauncherApplication app = (LauncherApplication) l.getApplication(); item.id = app.getLauncherProvider().generateNewId(); values.put(LauncherSettings.Favorites._ID, item.id); - item.updateValuesWithCoordinates(values, cellX, cellY); + item.updateValuesWithCoordinates(values, item.cellX, item.cellY); sWorker.post(new Runnable() { public void run() { @@ -382,13 +397,11 @@ public class LauncherModel extends BroadcastReceiver { switch (item.itemType) { case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: sFolders.put(item.id, (FolderInfo) item); - if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { - sWorkspaceItems.add(item); - } - break; + // Fall through case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: - if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP) { + if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP || + item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { sWorkspaceItems.add(item); } break; @@ -404,8 +417,8 @@ public class LauncherModel extends BroadcastReceiver { * Creates a new unique child id, for a given cell span across all layouts. */ static int getCellLayoutChildId( - int cellId, int screen, int localCellX, int localCellY, int spanX, int spanY) { - return ((cellId & 0xFF) << 24) + long container, int screen, int localCellX, int localCellY, int spanX, int spanY) { + return (((int) container & 0xFF) << 24) | (screen & 0xFF) << 16 | (localCellX & 0xFF) << 8 | (localCellY & 0xFF); } @@ -928,6 +941,7 @@ public class LauncherModel extends BroadcastReceiver { switch (container) { case LauncherSettings.Favorites.CONTAINER_DESKTOP: + case LauncherSettings.Favorites.CONTAINER_HOTSEAT: sWorkspaceItems.add(info); break; default: @@ -972,6 +986,7 @@ public class LauncherModel extends BroadcastReceiver { } switch (container) { case LauncherSettings.Favorites.CONTAINER_DESKTOP: + case LauncherSettings.Favorites.CONTAINER_HOTSEAT: sWorkspaceItems.add(folderInfo); break; } @@ -1003,9 +1018,10 @@ public class LauncherModel extends BroadcastReceiver { appWidgetInfo.spanY = c.getInt(spanYIndex); container = c.getInt(containerIndex); - if (container != LauncherSettings.Favorites.CONTAINER_DESKTOP) { + if (container != LauncherSettings.Favorites.CONTAINER_DESKTOP && + container != LauncherSettings.Favorites.CONTAINER_HOTSEAT) { Log.e(TAG, "Widget found where container " - + "!= CONTAINER_DESKTOP -- ignoring!"); + + "!= CONTAINER_DESKTOP nor CONTAINER_HOTSEAT - ignoring!"); continue; } appWidgetInfo.container = c.getInt(containerIndex); @@ -1607,12 +1623,10 @@ public class LauncherModel extends BroadcastReceiver { } } - ShortcutInfo addShortcut(Context context, Intent data, - int screen, int cellX, int cellY, boolean notify) { - + ShortcutInfo addShortcut(Context context, Intent data, long container, int screen, + int cellX, int cellY, boolean notify) { final ShortcutInfo info = infoFromShortcutIntent(context, data, null); - addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP, - screen, cellX, cellY, notify); + addItemToDatabase(context, info, container, screen, cellX, cellY, notify); return info; } |