From 1221b2faf3122c854ae1dcc5e00ce6a05f7f6fd8 Mon Sep 17 00:00:00 2001 From: Jorge Ruesga Date: Sat, 22 Jun 2013 13:05:37 +0200 Subject: 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 --- src/com/cyanogenmod/trebuchet/LauncherModel.java | 77 ++++++++++++++++++++++++ 1 file changed, 77 insertions(+) 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 workspaceItems, + final ArrayList appWidgets, + final HashMap folders) { + + // Get hidden apps + ArrayList mHiddenApps = new ArrayList(); + ArrayList mHiddenAppsPackages = new ArrayList(); + 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 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 workspaceItems, final ArrayList 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) { -- cgit v1.1