summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJorge Ruesga <jorge@ruesga.com>2013-06-22 13:05:37 +0200
committerJorge Ruesga <jorge@ruesga.com>2013-06-22 13:05:37 +0200
commit1221b2faf3122c854ae1dcc5e00ce6a05f7f6fd8 (patch)
treedb85a058503ae507f3904013a87559e64be27752
parent73c303e92d43cb74824f25b8158c65765b1a421b (diff)
downloadpackages_apps_trebuchet-1221b2faf3122c854ae1dcc5e00ce6a05f7f6fd8.zip
packages_apps_trebuchet-1221b2faf3122c854ae1dcc5e00ce6a05f7f6fd8.tar.gz
packages_apps_trebuchet-1221b2faf3122c854ae1dcc5e00ce6a05f7f6fd8.tar.bz2
Trebuchet: Remove workspace items of hidden apps
Remove the shortcut and widget associated to an app when this become hidden for user setting. Change-Id: I4ce8f545ef879d711fbbd8ab8572dcd7386dfa75 Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
-rw-r--r--src/com/cyanogenmod/trebuchet/LauncherModel.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/com/cyanogenmod/trebuchet/LauncherModel.java b/src/com/cyanogenmod/trebuchet/LauncherModel.java
index 923842c..323be71 100644
--- a/src/com/cyanogenmod/trebuchet/LauncherModel.java
+++ b/src/com/cyanogenmod/trebuchet/LauncherModel.java
@@ -46,6 +46,8 @@ import android.os.RemoteException;
import android.os.SystemClock;
import android.util.Log;
+import com.cyanogenmod.trebuchet.preference.PreferencesProvider;
+
import java.lang.ref.WeakReference;
import java.net.URISyntaxException;
import java.text.Collator;
@@ -1647,6 +1649,79 @@ public class LauncherModel extends BroadcastReceiver {
});
}
+ private void removeHiddenAppsWorkspaceItems(
+ final ArrayList<ItemInfo> workspaceItems,
+ final ArrayList<LauncherAppWidgetInfo> appWidgets,
+ final HashMap<Long, FolderInfo> folders) {
+
+ // Get hidden apps
+ ArrayList<ComponentName> mHiddenApps = new ArrayList<ComponentName>();
+ ArrayList<String> mHiddenAppsPackages = new ArrayList<String>();
+ String[] flattened = PreferencesProvider.Interface.Drawer.getHiddenApps().split("\\|");
+ for (String flat : flattened) {
+ ComponentName cmp = ComponentName.unflattenFromString(flat);
+ if (cmp != null) {
+ mHiddenApps.add(cmp);
+ mHiddenAppsPackages.add(cmp.getPackageName());
+ }
+ }
+
+ // Shortcuts
+ int N = workspaceItems.size() - 1;
+ for (int i = N; i >= 0; i--) {
+ final ItemInfo item = workspaceItems.get(i);
+ if (item instanceof ShortcutInfo) {
+ ShortcutInfo shortcut = (ShortcutInfo)item;
+ if (shortcut.intent != null && shortcut.intent.getComponent() != null) {
+ if (mHiddenApps.contains(shortcut.intent.getComponent())) {
+ LauncherModel.deleteItemFromDatabase(mContext, shortcut);
+ workspaceItems.remove(i);
+ }
+ }
+ } else {
+ final FolderInfo folder = (FolderInfo)item;
+ List<ShortcutInfo> shortcuts = folder.contents;
+ int NN = shortcuts.size() - 1;
+ for (int j = NN; j >= 0; j--) {
+ ShortcutInfo sci = shortcuts.get(j);
+ if (sci.intent != null && sci.intent.getComponent() != null) {
+ if (mHiddenApps.contains(sci.intent.getComponent())) {
+ LauncherModel.deleteItemFromDatabase(mContext, sci);
+ folder.remove(sci);
+ }
+ }
+ }
+
+ if (folder.contents.size() == 1) {
+ ShortcutInfo finalItem = folder.contents.get(0);
+ finalItem.container = folder.container;
+ LauncherModel.deleteItemFromDatabase(mContext, folder);
+ LauncherModel.addOrMoveItemInDatabase(mContext, finalItem, folder.container,
+ folder.screen, folder.cellX, folder.cellY);
+ workspaceItems.remove(i);
+ workspaceItems.add(finalItem);
+ folders.remove(Long.valueOf(item.id));
+ } else if (folder.contents.size() == 0) {
+ LauncherModel.deleteFolderContentsFromDatabase(mContext, folder);
+ workspaceItems.remove(i);
+ folders.remove(Long.valueOf(item.id));
+ }
+ }
+ }
+
+ // AppWidgets
+ N = appWidgets.size() - 1;
+ for (int i = N; i >= 0; i--) {
+ final LauncherAppWidgetInfo item = appWidgets.get(i);
+ if (item.providerName != null) {
+ if (mHiddenAppsPackages.contains(item.providerName.getPackageName())) {
+ LauncherModel.deleteItemFromDatabase(mContext, item);
+ appWidgets.remove(i);
+ }
+ }
+ }
+ }
+
private void bindWorkspaceItems(final Callbacks oldCallbacks,
final ArrayList<ItemInfo> workspaceItems,
final ArrayList<LauncherAppWidgetInfo> appWidgets,
@@ -1655,6 +1730,8 @@ public class LauncherModel extends BroadcastReceiver {
final boolean postOnMainThread = (deferredBindRunnables != null);
+ removeHiddenAppsWorkspaceItems(workspaceItems, appWidgets, folders);
+
// Bind the workspace items
int N = workspaceItems.size();
for (int i = 0; i < N; i += ITEMS_CHUNK) {