summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJorge Ruesga <jorge@ruesga.com>2013-02-24 23:23:24 +0100
committerGerrit Code Review <gerrit@cyanogenmod.org>2013-03-04 10:37:52 -0800
commit4b8d06f6be5c4ba2d069e69001f7032492df2e2c (patch)
tree2b23daa1cf453adb67066a8819350378a40b3e1b /src
parent251be3ae738b77c404712cc97045ca934cb0e295 (diff)
downloadandroid_packages_apps_Trebuchet-4b8d06f6be5c4ba2d069e69001f7032492df2e2c.tar.gz
android_packages_apps_Trebuchet-4b8d06f6be5c4ba2d069e69001f7032492df2e2c.tar.bz2
android_packages_apps_Trebuchet-4b8d06f6be5c4ba2d069e69001f7032492df2e2c.zip
Trebuchet: fix uninstall app from shortcut
When uninstalling an app from a shortcut, there are 2 incorrect cases: 1.- If the user proceeds with the uninstall process, all the shortcuts references are removed from the workspace, except the one used to start that process, because the shortcut is removed from the workspace, but not from the favorites database. A reboot of the device will restore the shortcut into the workspace again. 2.- If the user cancels the uninstall process, the shortcut used is not restored, because it was removed in the drag&drop process. This change restore the shortcut prior to start the uninstall process. For restoring the shortcuts the patchset verifies 3 conditions: 1.- If the shortcut was in the desktop, the shortcut is restored in the same position. 2.- If the shortcut was contained by a folder with one or two shortcuts, then the folder is removed in the darg&drop, so the folder is recreated in the same location, and all its shortcuts are restored 3.- If the shortcut was contained by a folder with more than 2 shortcuts, the shortcut is restored in the same folder. If the user proceeds with the uninstall process then as the shortcut is present in the workspace, the shortcut will be removed. Change-Id: I95e2684d01cabd0d5a04f17c896c72cad2b14d38 Signed-off-by: Jorge Ruesga <jorge@ruesga.com>
Diffstat (limited to 'src')
-rw-r--r--src/com/cyanogenmod/trebuchet/Folder.java6
-rw-r--r--src/com/cyanogenmod/trebuchet/Launcher.java93
-rw-r--r--src/com/cyanogenmod/trebuchet/ShortcutInfo.java8
3 files changed, 106 insertions, 1 deletions
diff --git a/src/com/cyanogenmod/trebuchet/Folder.java b/src/com/cyanogenmod/trebuchet/Folder.java
index 00152987b..181341bdd 100644
--- a/src/com/cyanogenmod/trebuchet/Folder.java
+++ b/src/com/cyanogenmod/trebuchet/Folder.java
@@ -696,6 +696,12 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
boolean success) {
if (success) {
if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon) {
+ // We need to inject the folder info to the shortcut because
+ // the folder is going to be removed from the workspace and the
+ // shortcut could need to be restored
+ if (d.dragInfo instanceof ShortcutInfo) {
+ ((ShortcutInfo)d.dragInfo).mFolderInfo = mInfo;
+ }
replaceFolderWithFinalItem();
}
} else {
diff --git a/src/com/cyanogenmod/trebuchet/Launcher.java b/src/com/cyanogenmod/trebuchet/Launcher.java
index 4b9f2406c..b1c1425dc 100644
--- a/src/com/cyanogenmod/trebuchet/Launcher.java
+++ b/src/com/cyanogenmod/trebuchet/Launcher.java
@@ -1079,6 +1079,87 @@ public final class Launcher extends Activity
}
}
+ private void restoreShortcut(ShortcutInfo info) {
+ final View view = createShortcut(info);
+ FolderInfo folderInfo = info.mFolderInfo;
+ if (info.container >= 0 && folderInfo != null) {
+ // The shortcut was contained by a folder
+ // It's necessary to recreate the folder or just to add to the existing one?
+ CellLayout layout = getCellLayout(folderInfo.container, folderInfo.screen);
+ View v = layout.getChildAt(folderInfo.cellX, folderInfo.cellY);
+ if (v == null) {
+ // Weird. Should not there be a shortcut or folder here?
+ return;
+ }
+ if (v.getTag() != null && v.getTag() instanceof ShortcutInfo) {
+ // Create a new folder
+ ShortcutInfo target = (ShortcutInfo)v.getTag();
+ // Remove the target item to allow to be occupied by the folder
+ layout.removeView(v);
+
+ // Create the folder and its new items
+ FolderIcon fi = addFolder(
+ layout, folderInfo.container, folderInfo.screen,
+ folderInfo.cellX, folderInfo.cellY);
+ int cellX = info.cellX;
+ int cellY = info.cellY;
+ info.cellX = -1;
+ info.cellY = -1;
+ target.cellX = -1;
+ target.cellY = -1;
+ if (cellX == 0 && cellY == 0) {
+ fi.addItem(info);
+ fi.addItem(target);
+ } else {
+ fi.addItem(target);
+ fi.addItem(info);
+ }
+ }
+ } else if (info.container >= 0) {
+ // The shortcut was contained by a folder and the folder still exists
+ FolderIcon folderIcon = null;
+
+ // We need to find the container in the workspace, because the shortcut has lost
+ // its information
+ ArrayList<ShortcutAndWidgetContainer> allSwc =
+ mWorkspace.getAllShortcutAndWidgetContainers();
+ for (ShortcutAndWidgetContainer swc : allSwc) {
+ int cc = swc.getChildCount();
+ for (int i = 0; i < cc; i++) {
+ View v = swc.getChildAt(i);
+ if (v instanceof FolderIcon) {
+ FolderInfo fi = (FolderInfo)v.getTag();
+ if (fi != null && fi.id == info.container) {
+ folderIcon = (FolderIcon)v;
+ break;
+ }
+ }
+ }
+ if (folderIcon != null) {
+ break;
+ }
+ }
+
+ if (folderIcon != null) {
+ folderIcon.addItem(info);
+ }
+
+ } else {
+ // Just restore the shortcut in its last position
+ long container = info.container;
+ int screen = info.screen;
+ int cellX = info.cellX;
+ int cellY = info.cellY;
+ int spanX = info.spanX;
+ int spanY = info.spanY;
+ mWorkspace.addInScreen(view, container, screen, cellX, cellY,
+ spanX, spanY, isWorkspaceLocked());
+ }
+
+ // The folder info is not needed any more
+ info.mFolderInfo = null;
+ }
+
/**
* Add a shortcut to the workspace.
*
@@ -2152,7 +2233,7 @@ public final class Launcher extends Activity
}
}
- void startShortcutUninstallActivity(ShortcutInfo shortcutInfo) {
+ void startShortcutUninstallActivity(final ShortcutInfo shortcutInfo) {
PackageManager pm = getPackageManager();
ResolveInfo resolveInfo = pm.resolveActivity(shortcutInfo.intent, 0);
if ((resolveInfo.activityInfo.applicationInfo.flags &
@@ -2170,6 +2251,16 @@ public final class Launcher extends Activity
Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
startActivity(intent);
}
+
+ // Restore the shortcut view prior to uninstall. Otherwise if the
+ // use cancels the uninstall process, the shortcut was removed from
+ // the workspace
+ mHandler.post(new Runnable() {
+ @Override
+ public void run() {
+ restoreShortcut(shortcutInfo);
+ }
+ });
}
boolean startActivity(View v, Intent intent, Object tag) {
diff --git a/src/com/cyanogenmod/trebuchet/ShortcutInfo.java b/src/com/cyanogenmod/trebuchet/ShortcutInfo.java
index 8f0d8d31b..d08700c02 100644
--- a/src/com/cyanogenmod/trebuchet/ShortcutInfo.java
+++ b/src/com/cyanogenmod/trebuchet/ShortcutInfo.java
@@ -69,6 +69,14 @@ class ShortcutInfo extends ItemInfo {
*/
private ShortcutListener mListener;
+ /**
+ * The shortcut folder information
+ *
+ * NOTE: For now only is filled when the shortcut is being dropped, so the shortcut
+ * can be restored if finally the item is not dropped. Only for internal use.
+ */
+ FolderInfo mFolderInfo = null;
+
ShortcutInfo() {
itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT;
}