From 9f0e132f8f21c7de6df3f1e8f1500f594557bd9c Mon Sep 17 00:00:00 2001 From: Nebojsa Cvetkovic Date: Wed, 1 Jan 2014 16:22:41 +0000 Subject: Hotseat: Movable AllApps button Change-Id: I4273c460392c8329368a23ef6f0d9698f52adfea --- src/com/android/launcher3/LauncherModel.java | 132 +++++++++++++++++++++------ 1 file changed, 106 insertions(+), 26 deletions(-) (limited to 'src/com/android/launcher3/LauncherModel.java') diff --git a/src/com/android/launcher3/LauncherModel.java b/src/com/android/launcher3/LauncherModel.java index e26d405bc..00b6fbb8e 100644 --- a/src/com/android/launcher3/LauncherModel.java +++ b/src/com/android/launcher3/LauncherModel.java @@ -169,7 +169,6 @@ public class LauncherModel extends BroadcastReceiver { boolean matchPackageNamesOnly); public void bindPackagesUpdated(ArrayList widgetsAndShortcuts); public void bindSearchablesChanged(); - public boolean isAllAppsButtonRank(int rank); public void onPageBoundSynchronously(int page); public void dumpLogsToLocalData(); } @@ -586,6 +585,7 @@ public class LauncherModel extends BroadcastReceiver { case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: + case LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS: if (!sBgWorkspaceItems.contains(modelItem)) { sBgWorkspaceItems.add(modelItem); } @@ -874,6 +874,7 @@ public class LauncherModel extends BroadcastReceiver { // Fall through case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: + case LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS: if (item.container == LauncherSettings.Favorites.CONTAINER_DESKTOP || item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { sBgWorkspaceItems.add(item); @@ -896,6 +897,56 @@ public class LauncherModel extends BroadcastReceiver { runOnWorkerThread(r); } + /** + * Checks whether there is an all apps shortcut in the database + */ + static boolean hasAllAppsShortcut() { + for (ItemInfo info : sBgWorkspaceItems) { + if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS) { + return true; + } + } + return false; + } + + /** + * Checks whether there is more than 1 all apps shortcut in the database + */ + static boolean hasMultipleAllAppsShortcuts() { + boolean foundOne = false; + for (ItemInfo info : sBgWorkspaceItems) { + if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS) { + if (!foundOne) { + foundOne = true; + } else { + return true; + } + } + } + return false; + } + + /** + * Add an all apps shortcut to the database if there aren't any already + */ + private ItemInfo addAllAppsShortcutIfNecessary() { + if (hasAllAppsShortcut()) return null; + + DeviceProfile grid = mApp.getDynamicGrid().getDeviceProfile(); + int allAppsIndex = grid.hotseatAllAppsRank; + + ShortcutInfo allAppsShortcut = new ShortcutInfo(); + allAppsShortcut.itemType = LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS; + allAppsShortcut.title = mApp.getContext().getResources().getString(R.string.all_apps_button_label); + allAppsShortcut.container = ItemInfo.NO_ID; + allAppsShortcut.spanX = 1; + allAppsShortcut.spanY = 1; + LauncherModel.addOrMoveItemInDatabase(mApp.getContext(), allAppsShortcut, LauncherSettings.Favorites.CONTAINER_HOTSEAT, + allAppsIndex, allAppsIndex, 0); + + return allAppsShortcut; + } + /** * Creates a new unique child id, for a given cell span across all layouts. */ @@ -936,6 +987,7 @@ public class LauncherModel extends BroadcastReceiver { break; case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: + case LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS: sBgWorkspaceItems.remove(item); break; case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: @@ -1529,13 +1581,6 @@ public class LauncherModel extends BroadcastReceiver { long containerIndex = item.screenId; if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { - // Return early if we detect that an item is under the hotseat button - if (mCallbacks == null || - mCallbacks.get().isAllAppsButtonRank((int) item.screenId)) { - deleteOnItemOverlap.set(true); - return false; - } - if (occupied.containsKey(LauncherSettings.Favorites.CONTAINER_HOTSEAT)) { if (occupied.get(LauncherSettings.Favorites.CONTAINER_HOTSEAT) [(int) item.screenId][0] != null) { @@ -1544,7 +1589,11 @@ public class LauncherModel extends BroadcastReceiver { + item.cellY + ") occupied by " + occupied.get(LauncherSettings.Favorites.CONTAINER_HOTSEAT) [(int) item.screenId][0]); - return false; + 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]; @@ -1671,7 +1720,7 @@ public class LauncherModel extends BroadcastReceiver { LauncherAppWidgetInfo appWidgetInfo; int container; long id; - Intent intent; + Intent intent = null; while (!mStopped && c.moveToNext()) { AtomicBoolean deleteOnItemOverlap = new AtomicBoolean(false); @@ -1681,32 +1730,38 @@ public class LauncherModel extends BroadcastReceiver { switch (itemType) { case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: + case LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS: id = c.getLong(idIndex); intentDescription = c.getString(intentIndex); - try { - intent = Intent.parseUri(intentDescription, 0); - ComponentName cn = intent.getComponent(); - if (cn != null && !isValidPackageComponent(manager, cn)) { - if (!mAppsCanBeOnRemoveableStorage) { - // Log the invalid package, and remove it from the db - Launcher.addDumpLog(TAG, "Invalid package removed: " + cn, true); - itemsToRemove.add(id); - } else { - // If apps can be on external storage, then we just - // leave them for the user to remove (maybe add - // visual treatment to it) - Launcher.addDumpLog(TAG, "Invalid package found: " + cn, true); + if (itemType != LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS) { + try { + intent = Intent.parseUri(intentDescription, 0); + ComponentName cn = intent.getComponent(); + if (cn != null && !isValidPackageComponent(manager, cn)) { + if (!mAppsCanBeOnRemoveableStorage) { + // Log the invalid package, and remove it from the db + Launcher.addDumpLog(TAG, "Invalid package removed: " + cn, true); + itemsToRemove.add(id); + } else { + // If apps can be on external storage, then we just + // leave them for the user to remove (maybe add + // visual treatment to it) + Launcher.addDumpLog(TAG, "Invalid package found: " + cn, true); + } + continue; } + } catch (URISyntaxException e) { + Launcher.addDumpLog(TAG, "Invalid uri: " + intentDescription, true); continue; } - } catch (URISyntaxException e) { - Launcher.addDumpLog(TAG, "Invalid uri: " + intentDescription, true); - continue; } if (itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION) { info = getShortcutInfo(manager, intent, context, c, iconIndex, titleIndex, mLabelCache); + } else if (itemType == LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS) { + info = getShortcutInfo(c, context, + titleIndex); } else { info = getShortcutInfo(c, context, iconTypeIndex, iconPackageIndex, iconResourceIndex, iconIndex, @@ -1901,6 +1956,19 @@ public class LauncherModel extends BroadcastReceiver { return false; } + // Add an all apps button to the database if there isn't one already + ItemInfo allAppsButton = addAllAppsShortcutIfNecessary(); + if (allAppsButton != null) { + // Check if there was an icon occupying the default position and remove + if (occupied.containsKey(allAppsButton.container)) { + if (occupied.get(allAppsButton.container) + [(int) allAppsButton.screenId][0] != null) { + itemsToRemove.add(occupied.get(allAppsButton.container) + [(int) allAppsButton.screenId][0].id); + } + } + } + if (itemsToRemove.size() > 0) { ContentProviderClient client = contentResolver.acquireContentProviderClient( LauncherSettings.Favorites.CONTENT_URI); @@ -2813,6 +2881,18 @@ public class LauncherModel extends BroadcastReceiver { return false; } + /** + * Make an ShortcutInfo object for a shortcut that isn't an application. + */ + private ShortcutInfo getShortcutInfo(Cursor c, Context context, + int titleIndex) { + final ShortcutInfo info = new ShortcutInfo(); + info.itemType = LauncherSettings.Favorites.ITEM_TYPE_ALLAPPS; + + info.title = c.getString(titleIndex); + return info; + } + /** * Make an ShortcutInfo object for a shortcut that isn't an application. */ -- cgit v1.2.3