diff options
author | d34d <clark@cyngn.com> | 2015-07-17 10:06:20 -0700 |
---|---|---|
committer | cretin45 <cretin45@gmail.com> | 2016-03-15 14:25:30 -0700 |
commit | 772f61de9ad6a86dcccbab308c7202e770975ce6 (patch) | |
tree | 4dc0f27c7e9d8a9cf461cf4aebedbab23d604df5 /src/com/android/launcher3/Workspace.java | |
parent | 1129f556e5097e777bd2071890cc622db6a14f5e (diff) | |
download | android_packages_apps_Trebuchet-772f61de9ad6a86dcccbab308c7202e770975ce6.tar.gz android_packages_apps_Trebuchet-772f61de9ad6a86dcccbab308c7202e770975ce6.tar.bz2 android_packages_apps_Trebuchet-772f61de9ad6a86dcccbab308c7202e770975ce6.zip |
Show apps as unavailable when on unmounted storage
This patch allows shortcuts to apps that are currently unavailable
due to being on unmounted external storage to remain on the workspace
and in folders. The icons will be disabled and grayed out until
the external storage is mounted.
Issue-id: CYNGNOS-1344
Change-Id: I971483806b27e3a75ef0d5bb89d8dfb86f97511e
Diffstat (limited to 'src/com/android/launcher3/Workspace.java')
-rw-r--r-- | src/com/android/launcher3/Workspace.java | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index 4364e6b1b..6114157e0 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -28,6 +28,7 @@ import android.appwidget.AppWidgetHostView; import android.appwidget.AppWidgetProviderInfo; import android.content.ComponentName; import android.content.Context; +import android.content.Intent; import android.content.SharedPreferences; import android.content.res.Resources; import android.content.res.TypedArray; @@ -4346,6 +4347,102 @@ public class Workspace extends PagedView stripEmptyScreens(); } + void updateUnvailableItemsInCellLayout(CellLayout parent, ArrayList<String> packages) { + final HashSet<String> packageNames = new HashSet<String>(); + packageNames.addAll(packages); + + ViewGroup layout = parent.getShortcutsAndWidgets(); + int childCount = layout.getChildCount(); + for (int i = 0; i < childCount; ++i) { + View view = layout.getChildAt(i); + if (view instanceof BubbleTextView) { + ItemInfo info = (ItemInfo) view.getTag(); + if (info instanceof ShortcutInfo) { + Intent intent = info.getIntent(); + ComponentName cn = intent != null ? intent.getComponent() : null; + if (cn != null && packageNames.contains(cn.getPackageName())) { + ShortcutInfo shortcut = (ShortcutInfo) info; + if (shortcut.isDisabled == 0) { + shortcut.isDisabled = 1; + ((BubbleTextView) view) + .applyFromShortcutInfo(shortcut, mIconCache, true); + } + } + } + } else if (view instanceof FolderIcon) { + final Folder folder = ((FolderIcon)view).getFolder(); + final FolderPagedView folderPagedView = (FolderPagedView)folder.getContent(); + final int N = folderPagedView.getItemCount(); + for (int page = 0; page < N; page++) { + final CellLayout cellLayout = folderPagedView.getPageAt(page); + updateUnvailableItemsInCellLayout(cellLayout, packages); + } + folder.invalidate(); + } + } + } + + void updateUnavailableItemsByPackageName(final ArrayList<String> packages) { + ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts(); + for (CellLayout layoutParent : cellLayouts) { + updateUnvailableItemsInCellLayout(layoutParent, packages); + } + } + + /** + * Updates shortcuts to an app that was previously unavailable in the given cell layout + * @param parent CellLayout to check childen for shortcuts to the available app + * @param appInfos List of item infos. Items are assumed to be of type AppInfo + */ + void updateAvailabeItemsInCellLayout(CellLayout parent, final ArrayList<ItemInfo> appInfos) { + ViewGroup layout = parent.getShortcutsAndWidgets(); + int childCount = layout.getChildCount(); + for (int i = 0; i < childCount; ++i) { + View view = layout.getChildAt(i); + if (view instanceof BubbleTextView) { + ItemInfo info = (ItemInfo) view.getTag(); + if (info instanceof ShortcutInfo) { + Intent intent = info.getIntent(); + ComponentName cn = intent != null ? intent.getComponent() : null; + for (ItemInfo itemInfo : appInfos) { + AppInfo appInfo = (AppInfo) itemInfo; + if (cn != null && cn.getPackageName().equals( + appInfo.componentName.getPackageName())) { + ShortcutInfo shortcut = (ShortcutInfo) info; + if (shortcut.isDisabled == 1) { + shortcut.isDisabled = 0; + ((BubbleTextView) view) + .applyFromShortcutInfo(shortcut, mIconCache, true); + } + } + } + } + } else if (view instanceof FolderIcon) { + final Folder folder = ((FolderIcon) view).getFolder(); + final FolderPagedView folderPagedView = (FolderPagedView) folder.getContent(); + final int N = folderPagedView.getItemCount(); + for (int page = 0; page < N; page++) { + final CellLayout cellLayout = folderPagedView.getPageAt(page); + if (cellLayout != null) { + updateAvailabeItemsInCellLayout(cellLayout, appInfos); + } + } + folder.invalidate(); + } + } + } + + /** + * Updates shortcuts to an app that was previously unavailable + * @param appInfos List of item infos. Items are assumed to be of type AppInfo + */ + void updateAvailableItems(final ArrayList<ItemInfo> appInfos) { + ArrayList<CellLayout> cellLayouts = getWorkspaceAndHotseatCellLayouts(); + for (CellLayout layoutParent : cellLayouts) { + updateAvailabeItemsInCellLayout(layoutParent, appInfos); + } + } + interface ItemOperator { /** * Process the next itemInfo, possibly with side-effect on {@link ItemOperator#value}. |