summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;
}