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.
This commit is contained in:
Romain Guy 2009-06-01 15:34:04 -07:00
parent 8283ccff7c
commit 574d20ec84
2 changed files with 39 additions and 3 deletions

View File

@ -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;
}

View File

@ -1222,32 +1222,64 @@ public class Workspace extends ViewGroup implements DropTarget, DragSource, Drag
final ArrayList<View> childrenToRemove = new ArrayList<View>();
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<ApplicationInfo> contents = info.contents;
final ArrayList<ApplicationInfo> toRemove = new ArrayList<ApplicationInfo>(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();