diff options
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}. |