From 574d20ec84551370987dde530c27ec493bdef564 Mon Sep 17 00:00:00 2001 From: Romain Guy Date: Mon, 1 Jun 2009 15:34:04 -0700 Subject: [PATCH] Fixes #1890155. Remove shortcuts from folders (closed and opened) whenever the user uninstalls an application. Home was removing shortcuts from the workspace and the database but was not updating the UI correctly when running. --- src/com/android/launcher/Folder.java | 8 ++++-- src/com/android/launcher/Workspace.java | 34 ++++++++++++++++++++++++- 2 files changed, 39 insertions(+), 3 deletions(-) diff --git a/src/com/android/launcher/Folder.java b/src/com/android/launcher/Folder.java index bcbccf71b3..fb4e8d6c54 100644 --- a/src/com/android/launcher/Folder.java +++ b/src/com/android/launcher/Folder.java @@ -24,7 +24,7 @@ import android.widget.AdapterView; import android.widget.Button; import android.widget.LinearLayout; import android.widget.AbsListView; -import android.widget.ListAdapter; +import android.widget.BaseAdapter; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemLongClickListener; @@ -122,10 +122,14 @@ public class Folder extends LinearLayout implements DragSource, OnItemLongClickL * * @param adapter The list of applications to display in the folder. */ - void setContentAdapter(ListAdapter adapter) { + void setContentAdapter(BaseAdapter adapter) { mContent.setAdapter(adapter); } + void notifyDataSetChanged() { + ((BaseAdapter) mContent.getAdapter()).notifyDataSetChanged(); + } + void setLauncher(Launcher launcher) { mLauncher = launcher; } diff --git a/src/com/android/launcher/Workspace.java b/src/com/android/launcher/Workspace.java index fe309dedbc..e4d2560281 100644 --- a/src/com/android/launcher/Workspace.java +++ b/src/com/android/launcher/Workspace.java @@ -1222,32 +1222,64 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag final ArrayList childrenToRemove = new ArrayList(); final LauncherModel model = Launcher.getModel(); final int count = getChildCount(); + for (int i = 0; i < count; i++) { final CellLayout layout = (CellLayout) getChildAt(i); int childCount = layout.getChildCount(); + childrenToRemove.clear(); + for (int j = 0; j < childCount; j++) { final View view = layout.getChildAt(j); Object tag = view.getTag(); + if (tag instanceof ApplicationInfo) { - ApplicationInfo info = (ApplicationInfo) tag; + final ApplicationInfo info = (ApplicationInfo) tag; // We need to check for ACTION_MAIN otherwise getComponent() might // return null for some shortcuts (for instance, for shortcuts to // web pages.) final Intent intent = info.intent; final ComponentName name = intent.getComponent(); + if (Intent.ACTION_MAIN.equals(intent.getAction()) && name != null && packageName.equals(name.getPackageName())) { model.removeDesktopItem(info); LauncherModel.deleteItemFromDatabase(mLauncher, info); childrenToRemove.add(view); } + } else if (tag instanceof UserFolderInfo) { + final UserFolderInfo info = (UserFolderInfo) tag; + final ArrayList contents = info.contents; + final ArrayList toRemove = new ArrayList(1); + final int contentsCount = contents.size(); + boolean removedFromFolder = false; + + for (int k = 0; k < contentsCount; k++) { + final ApplicationInfo appInfo = contents.get(k); + final Intent intent = appInfo.intent; + final ComponentName name = intent.getComponent(); + + if (Intent.ACTION_MAIN.equals(intent.getAction()) && + name != null && packageName.equals(name.getPackageName())) { + toRemove.add(appInfo); + LauncherModel.deleteItemFromDatabase(mLauncher, appInfo); + removedFromFolder = true; + } + } + + contents.removeAll(toRemove); + if (removedFromFolder) { + final Folder folder = getOpenFolder(); + if (folder != null) folder.notifyDataSetChanged(); + } } } + childCount = childrenToRemove.size(); for (int j = 0; j < childCount; j++) { layout.removeViewInLayout(childrenToRemove.get(j)); } + if (childCount > 0) { layout.requestLayout(); layout.invalidate();