diff options
author | Jorge Ruesga <jorge@ruesga.com> | 2013-06-25 03:18:31 +0200 |
---|---|---|
committer | Jorge Ruesga <jorge@ruesga.com> | 2013-06-25 03:18:31 +0200 |
commit | 21d44da75e7b0d135033bab2aeab10f42b94ca8e (patch) | |
tree | 82f90d686846ec9a7e18f954f365c755d1af664f | |
parent | 7fd44abee142349dc97570f50851cbf0629706ca (diff) | |
download | packages_apps_trebuchet-21d44da75e7b0d135033bab2aeab10f42b94ca8e.zip packages_apps_trebuchet-21d44da75e7b0d135033bab2aeab10f42b94ca8e.tar.gz packages_apps_trebuchet-21d44da75e7b0d135033bab2aeab10f42b94ca8e.tar.bz2 |
Trebuchet: Make remove workspace items of hidden apps optional
Change-Id: Id5c1f7a105d4140747a9f841b210cd7a7d1825df
Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
-rw-r--r-- | res/values/cm_strings.xml | 5 | ||||
-rw-r--r-- | res/xml/preferences_drawer.xml | 24 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java | 12 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/LauncherModel.java | 86 | ||||
-rw-r--r-- | src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java | 12 |
5 files changed, 86 insertions, 53 deletions
diff --git a/res/values/cm_strings.xml b/res/values/cm_strings.xml index 511e0d5..136be54 100644 --- a/res/values/cm_strings.xml +++ b/res/values/cm_strings.xml @@ -111,8 +111,13 @@ <string name="preferences_interface_drawer_summary">Apps and widgets drawer</string> <string name="preferences_interface_drawer_orientation_title">Orientation</string> <string name="preferences_interface_drawer_orientation_summary">Choose which way the drawer scrolls</string> + <string name="preferences_interface_drawer_apps_category">Apps</string> <string name="preferences_interface_drawer_hidden_apps_title">Hidden apps</string> <string name="preferences_interface_drawer_hidden_apps_summary">Hide apps from the drawer</string> + <string name="preferences_interface_drawer_hidden_apps_shortcuts_title">Hidden apps (shortcuts)</string> + <string name="preferences_interface_drawer_hidden_apps_shortcuts_summary">Remove hidden apps\'s shortcuts from workspace</string> + <string name="preferences_interface_drawer_hidden_apps_widgets_title">Hidden apps (widgets)</string> + <string name="preferences_interface_drawer_hidden_apps_widgets_summary">Remove hidden apps\'s widgets from workspace</string> <string name="preferences_interface_drawer_widgets_category">Widgets</string> <string name="preferences_interface_drawer_widgets_join_apps_title">Join with apps</string> <string name="preferences_interface_drawer_widgets_join_apps_summary">Swipe from apps drawer to widgets drawer without changing tabs</string> diff --git a/res/xml/preferences_drawer.xml b/res/xml/preferences_drawer.xml index 3b4a3ef..82c589f 100644 --- a/res/xml/preferences_drawer.xml +++ b/res/xml/preferences_drawer.xml @@ -24,13 +24,23 @@ android:entries="@array/preferences_interface_drawer_orientation_entries" android:entryValues="@array/preferences_interface_drawer_orientation_values" android:defaultValue="horizontal" /> - <Preference android:key="ui_drawer_hidden_apps" - android:title="@string/preferences_interface_drawer_hidden_apps_title" - android:summary="@string/preferences_interface_drawer_hidden_apps_summary"> - <intent - android:targetPackage="com.cyanogenmod.trebuchet" - android:targetClass="com.cyanogenmod.trebuchet.preference.HiddenAppsActivity"/> - </Preference> + <PreferenceCategory android:title="@string/preferences_interface_drawer_apps_category"> + <Preference android:key="ui_drawer_hidden_apps" + android:title="@string/preferences_interface_drawer_hidden_apps_title" + android:summary="@string/preferences_interface_drawer_hidden_apps_summary"> + <intent + android:targetPackage="com.cyanogenmod.trebuchet" + android:targetClass="com.cyanogenmod.trebuchet.preference.HiddenAppsActivity"/> + </Preference> + <CheckBoxPreference android:key="ui_drawer_remove_hidden_apps_shortcuts" + android:title="@string/preferences_interface_drawer_hidden_apps_shortcuts_title" + android:summary="@string/preferences_interface_drawer_hidden_apps_shortcuts_summary" + android:defaultValue="true" /> + <CheckBoxPreference android:key="ui_drawer_remove_hidden_apps_widgets" + android:title="@string/preferences_interface_drawer_hidden_apps_widgets_title" + android:summary="@string/preferences_interface_drawer_hidden_apps_widgets_summary" + android:defaultValue="true" /> + </PreferenceCategory> <PreferenceCategory android:title="@string/preferences_interface_drawer_widgets_category"> <CheckBoxPreference android:key="ui_drawer_widgets_join_apps" android:title="@string/preferences_interface_drawer_widgets_join_apps_title" diff --git a/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java b/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java index 1b87c4f..42485a6 100644 --- a/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java +++ b/src/com/cyanogenmod/trebuchet/AppsCustomizePagedView.java @@ -263,6 +263,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen private ArrayList<ApplicationInfo> mApps; private ArrayList<ApplicationInfo> mFilteredApps; private ArrayList<ComponentName> mHiddenApps; + private ArrayList<String> mHiddenAppsPackages; private ArrayList<Object> mWidgets; // Cling @@ -370,6 +371,7 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen mApps = new ArrayList<ApplicationInfo>(); mFilteredApps = new ArrayList<ApplicationInfo>(); mHiddenApps = new ArrayList<ComponentName>(); + mHiddenAppsPackages = new ArrayList<String>(); mWidgets = new ArrayList<Object>(); mIconCache = ((LauncherApplication) context.getApplicationContext()).getIconCache(); mCanvas = new Canvas(); @@ -392,7 +394,9 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen String[] flattened = PreferencesProvider.Interface.Drawer.getHiddenApps().split("\\|"); for (String flat : flattened) { - mHiddenApps.add(ComponentName.unflattenFromString(flat)); + ComponentName cmp = ComponentName.unflattenFromString(flat); + mHiddenApps.add(cmp); + mHiddenAppsPackages.add(cmp.getPackageName()); } @@ -658,7 +662,11 @@ public class AppsCustomizePagedView extends PagedViewWithDraggableItems implemen int minSpanY = Math.min(spanXY[1], minSpanXY[1]); if (minSpanX <= LauncherModel.getWorkspaceCellCountX() && minSpanY <= LauncherModel.getWorkspaceCellCountY()) { - mWidgets.add(widget); + if (widget.provider != null) { + if (!mHiddenAppsPackages.contains(widget.provider.getPackageName())) { + mWidgets.add(widget); + } + } } else { Log.e(TAG, "Widget " + widget.provider + " can not fit on this device (" + widget.minWidth + ", " + widget.minHeight + ")"); diff --git a/src/com/cyanogenmod/trebuchet/LauncherModel.java b/src/com/cyanogenmod/trebuchet/LauncherModel.java index 323be71..6aa109a 100644 --- a/src/com/cyanogenmod/trebuchet/LauncherModel.java +++ b/src/com/cyanogenmod/trebuchet/LauncherModel.java @@ -1667,56 +1667,60 @@ public class LauncherModel extends BroadcastReceiver { } // 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); + if (PreferencesProvider.Interface.Drawer.getRemoveShortcutsOfHiddenApps()) { + 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); + } 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)); + 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); + if (PreferencesProvider.Interface.Drawer.getRemoveWidgetsOfHiddenApps()) { + int 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); + } } } } diff --git a/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java b/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java index 912d310..9f61f82 100644 --- a/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java +++ b/src/com/cyanogenmod/trebuchet/preference/PreferencesProvider.java @@ -144,12 +144,18 @@ public final class PreferencesProvider { public static boolean getVertical() { return getString("ui_drawer_orientation", "horizontal").equals("vertical"); } - public static boolean getJoinWidgetsApps() { - return getBoolean("ui_drawer_widgets_join_apps", true); - } public static String getHiddenApps() { return getString("ui_drawer_hidden_apps", ""); } + public static boolean getRemoveShortcutsOfHiddenApps() { + return getBoolean("ui_drawer_remove_hidden_apps_shortcuts", true); + } + public static boolean getRemoveWidgetsOfHiddenApps() { + return getBoolean("ui_drawer_remove_hidden_apps_widgets", true); + } + public static boolean getJoinWidgetsApps() { + return getBoolean("ui_drawer_widgets_join_apps", true); + } public static class Scrolling { public static AppsCustomizePagedView.TransitionEffect getTransitionEffect(String def) { try { |