diff options
author | Winson Chung <winsonc@google.com> | 2012-04-27 15:12:38 -0700 |
---|---|---|
committer | Winson Chung <winsonc@google.com> | 2012-04-27 15:15:11 -0700 |
commit | 11a4937fbff0dbc50fb022513dc3b6c643154445 (patch) | |
tree | a602fc06eae7006b840fc84c47c1497f15a6619c | |
parent | 9cfcb39bffaffe2123cc6e6a39b4e32ee440fda5 (diff) | |
download | android_packages_apps_Trebuchet-11a4937fbff0dbc50fb022513dc3b6c643154445.tar.gz android_packages_apps_Trebuchet-11a4937fbff0dbc50fb022513dc3b6c643154445.tar.bz2 android_packages_apps_Trebuchet-11a4937fbff0dbc50fb022513dc3b6c643154445.zip |
Fixing issue where shortcuts and widgets were not being removed when the package was uninstalled (Bug 2657997, Bug 6335843)
- Also fixes issue if we are dragging a shortcut/widget and it is removed.
- Also exposes App Info for shortcuts and widgets
Change-Id: I3bd5056f50f20e8b277dde6456df26eac815bcde
-rw-r--r-- | src/com/android/launcher2/DeleteDropTarget.java | 12 | ||||
-rw-r--r-- | src/com/android/launcher2/DragController.java | 11 | ||||
-rw-r--r-- | src/com/android/launcher2/InfoDropTarget.java | 11 | ||||
-rw-r--r-- | src/com/android/launcher2/Launcher.java | 3 | ||||
-rw-r--r-- | src/com/android/launcher2/LauncherAppWidgetInfo.java | 11 | ||||
-rw-r--r-- | src/com/android/launcher2/LauncherModel.java | 3 | ||||
-rw-r--r-- | src/com/android/launcher2/Workspace.java | 9 |
7 files changed, 35 insertions, 25 deletions
diff --git a/src/com/android/launcher2/DeleteDropTarget.java b/src/com/android/launcher2/DeleteDropTarget.java index d8ea6ef5c..eb831f6e9 100644 --- a/src/com/android/launcher2/DeleteDropTarget.java +++ b/src/com/android/launcher2/DeleteDropTarget.java @@ -91,7 +91,17 @@ public class DeleteDropTarget extends ButtonDropTarget { return (source instanceof AppsCustomizePagedView) && (info instanceof ApplicationInfo); } private boolean isAllAppsWidget(DragSource source, Object info) { - return (source instanceof AppsCustomizePagedView) && (info instanceof PendingAddWidgetInfo); + if (source instanceof AppsCustomizePagedView) { + if (info instanceof PendingAddItemInfo) { + PendingAddItemInfo addInfo = (PendingAddItemInfo) info; + switch (addInfo.itemType) { + case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: + case LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET: + return true; + } + } + } + return false; } private boolean isDragSourceWorkspaceOrFolder(DragObject d) { return (d.dragSource instanceof Workspace) || (d.dragSource instanceof Folder); diff --git a/src/com/android/launcher2/DragController.java b/src/com/android/launcher2/DragController.java index c9bebe3c5..4be4e8f7b 100644 --- a/src/com/android/launcher2/DragController.java +++ b/src/com/android/launcher2/DragController.java @@ -380,10 +380,13 @@ public class DragController { // Added null checks to prevent NPE we've seen in the wild if (dragInfo != null && dragInfo.intent != null && - info.intent != null && - dragInfo.intent.getComponent().equals(info.intent.getComponent())) { - cancelDrag(); - return; + info.intent != null) { + boolean isSamePackage = dragInfo.intent.getPackage().equals( + info.intent.getPackage()); + if (isSamePackage) { + cancelDrag(); + return; + } } } } diff --git a/src/com/android/launcher2/InfoDropTarget.java b/src/com/android/launcher2/InfoDropTarget.java index 2e0b5c827..134f4cb56 100644 --- a/src/com/android/launcher2/InfoDropTarget.java +++ b/src/com/android/launcher2/InfoDropTarget.java @@ -16,6 +16,7 @@ package com.android.launcher2; +import android.appwidget.AppWidgetProviderInfo; import android.content.ComponentName; import android.content.Context; import android.content.res.ColorStateList; @@ -62,8 +63,8 @@ public class InfoDropTarget extends ButtonDropTarget { } } - private boolean isAllAppsApplication(DragSource source, Object info) { - return (source instanceof AppsCustomizePagedView) && (info instanceof ApplicationInfo); + private boolean isFromAllApps(DragSource source) { + return (source instanceof AppsCustomizePagedView); } @Override @@ -76,6 +77,8 @@ public class InfoDropTarget extends ButtonDropTarget { componentName = ((ApplicationInfo) d.dragInfo).componentName; } else if (d.dragInfo instanceof ShortcutInfo) { componentName = ((ShortcutInfo) d.dragInfo).intent.getComponent(); + } else if (d.dragInfo instanceof PendingAddItemInfo) { + componentName = ((PendingAddItemInfo) d.dragInfo).componentName; } if (componentName != null) { mLauncher.startApplicationDetailsActivity(componentName); @@ -90,8 +93,8 @@ public class InfoDropTarget extends ButtonDropTarget { public void onDragStart(DragSource source, Object info, int dragAction) { boolean isVisible = true; - // If we are dragging a widget or shortcut, hide the info target - if (!isAllAppsApplication(source, info)) { + // Hide this button unless we are dragging something from AllApps + if (!isFromAllApps(source)) { isVisible = false; } diff --git a/src/com/android/launcher2/Launcher.java b/src/com/android/launcher2/Launcher.java index e5c62add7..ea974d3d1 100644 --- a/src/com/android/launcher2/Launcher.java +++ b/src/com/android/launcher2/Launcher.java @@ -1073,7 +1073,8 @@ public final class Launcher extends Activity } // Build Launcher-specific widget info and save to database - LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId); + LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId, + appWidgetInfo.provider); launcherInfo.spanX = spanXY[0]; launcherInfo.spanY = spanXY[1]; launcherInfo.minSpanX = mPendingAddInfo.minSpanX; diff --git a/src/com/android/launcher2/LauncherAppWidgetInfo.java b/src/com/android/launcher2/LauncherAppWidgetInfo.java index 844abb519..e5b947391 100644 --- a/src/com/android/launcher2/LauncherAppWidgetInfo.java +++ b/src/com/android/launcher2/LauncherAppWidgetInfo.java @@ -48,11 +48,9 @@ class LauncherAppWidgetInfo extends ItemInfo { */ AppWidgetHostView hostView = null; - /** - * Constructor for use with AppWidgets that haven't been instantiated yet. - */ - LauncherAppWidgetInfo(ComponentName providerName) { + LauncherAppWidgetInfo(int appWidgetId, ComponentName providerName) { itemType = LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET; + this.appWidgetId = appWidgetId; this.providerName = providerName; // Since the widget isn't instantiated yet, we don't know these values. Set them to -1 @@ -61,11 +59,6 @@ class LauncherAppWidgetInfo extends ItemInfo { spanY = -1; } - LauncherAppWidgetInfo(int appWidgetId) { - itemType = LauncherSettings.Favorites.ITEM_TYPE_APPWIDGET; - this.appWidgetId = appWidgetId; - } - @Override void onAddToDatabase(ContentValues values) { super.onAddToDatabase(values); diff --git a/src/com/android/launcher2/LauncherModel.java b/src/com/android/launcher2/LauncherModel.java index 37235e960..892faf01f 100644 --- a/src/com/android/launcher2/LauncherModel.java +++ b/src/com/android/launcher2/LauncherModel.java @@ -1158,7 +1158,8 @@ public class LauncherModel extends BroadcastReceiver { Launcher.sDumpLogs.add(log); itemsToRemove.add(id); } else { - appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId); + appWidgetInfo = new LauncherAppWidgetInfo(appWidgetId, + provider.provider); appWidgetInfo.id = id; appWidgetInfo.screen = c.getInt(screenIndex); appWidgetInfo.cellX = c.getInt(cellXIndex); diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java index 892000d39..aa378dfd2 100644 --- a/src/com/android/launcher2/Workspace.java +++ b/src/com/android/launcher2/Workspace.java @@ -3602,7 +3602,7 @@ public class Workspace extends SmoothPagedView final Intent intent = info.intent; final ComponentName name = intent.getComponent(); - if (Intent.ACTION_MAIN.equals(intent.getAction()) && name != null) { + if (name != null) { for (String packageName: packageNames) { if (packageName.equals(name.getPackageName())) { LauncherModel.deleteItemFromDatabase(mLauncher, info); @@ -3622,7 +3622,7 @@ public class Workspace extends SmoothPagedView final Intent intent = appInfo.intent; final ComponentName name = intent.getComponent(); - if (Intent.ACTION_MAIN.equals(intent.getAction()) && name != null) { + if (name != null) { for (String packageName: packageNames) { if (packageName.equals(name.getPackageName())) { appsToRemoveFromFolder.add(appInfo); @@ -3636,11 +3636,10 @@ public class Workspace extends SmoothPagedView } } else if (tag instanceof LauncherAppWidgetInfo) { final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) tag; - final AppWidgetProviderInfo provider = - widgets.getAppWidgetInfo(info.appWidgetId); + final ComponentName provider = info.providerName; if (provider != null) { for (String packageName: packageNames) { - if (packageName.equals(provider.provider.getPackageName())) { + if (packageName.equals(provider.getPackageName())) { LauncherModel.deleteItemFromDatabase(mLauncher, info); childrenToRemove.add(view); } |