From 53b6e9dd1a97ea59a84e4c8b7172e1773d990ee5 Mon Sep 17 00:00:00 2001 From: d34d Date: Fri, 17 Jul 2015 10:06:20 -0700 Subject: 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. Change-Id: I971483806b27e3a75ef0d5bb89d8dfb86f97511e --- src/com/android/launcher3/Workspace.java | 84 ++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) (limited to 'src/com/android/launcher3/Workspace.java') diff --git a/src/com/android/launcher3/Workspace.java b/src/com/android/launcher3/Workspace.java index bfe555a63..8f5d9f0a2 100644 --- a/src/com/android/launcher3/Workspace.java +++ b/src/com/android/launcher3/Workspace.java @@ -4954,6 +4954,90 @@ public class Workspace extends SmoothPagedView stripEmptyScreens(); } + void updateUnvailableItemsInCellLayout(CellLayout parent, ArrayList packages) { + final HashSet packageNames = new HashSet(); + 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) { + shortcut.isDisabled = true; + ((BubbleTextView) view) + .applyFromShortcutInfo(shortcut, mIconCache, true); + } + } + } + } else if (view instanceof FolderIcon) { + final Folder folder = ((FolderIcon)view).getFolder(); + updateUnvailableItemsInCellLayout(folder.getContent(), packages); + folder.invalidate(); + } + } + } + + void updateUnavailableItemsByPackageName(final ArrayList packages) { + ArrayList 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 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) { + shortcut.isDisabled = false; + ((BubbleTextView) view) + .applyFromShortcutInfo(shortcut, mIconCache, true); + } + } + } + } + } else if (view instanceof FolderIcon) { + final Folder folder = ((FolderIcon)view).getFolder(); + updateAvailabeItemsInCellLayout(folder.getContent(), 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 appInfos) { + ArrayList cellLayouts = getWorkspaceAndHotseatCellLayouts(); + for (CellLayout layoutParent : cellLayouts) { + updateAvailabeItemsInCellLayout(layoutParent, appInfos); + } + } + interface ItemOperator { /** * Process the next itemInfo, possibly with side-effect on {@link ItemOperator#value}. -- cgit v1.2.3