summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorWinson Chung <winsonc@google.com>2012-05-03 11:20:19 -0700
committerWinson Chung <winsonc@google.com>2012-05-04 10:20:05 -0700
commitf561bdf68dd304e1d7c3f7796621a4cc39ca15f2 (patch)
tree2e1285c2dcafe9a00474082884e49a0b0ea9622d /src
parent2ceccf83f479d4e161a5f87ee51b21230600abef (diff)
downloadandroid_packages_apps_Trebuchet-f561bdf68dd304e1d7c3f7796621a4cc39ca15f2.tar.gz
android_packages_apps_Trebuchet-f561bdf68dd304e1d7c3f7796621a4cc39ca15f2.tar.bz2
android_packages_apps_Trebuchet-f561bdf68dd304e1d7c3f7796621a4cc39ca15f2.zip
Initial change to queue up install/uninstall operations while dragging (Bug 6276881)
Change-Id: I68ad881e38711d8d9a8903ab18d30ef4385833d7
Diffstat (limited to 'src')
-rw-r--r--src/com/android/launcher2/InstallShortcutReceiver.java63
-rw-r--r--src/com/android/launcher2/UninstallShortcutReceiver.java53
-rw-r--r--src/com/android/launcher2/Workspace.java10
3 files changed, 113 insertions, 13 deletions
diff --git a/src/com/android/launcher2/InstallShortcutReceiver.java b/src/com/android/launcher2/InstallShortcutReceiver.java
index 66b3f5f67..6d91602dc 100644
--- a/src/com/android/launcher2/InstallShortcutReceiver.java
+++ b/src/com/android/launcher2/InstallShortcutReceiver.java
@@ -28,6 +28,7 @@ import com.android.launcher.R;
import java.util.ArrayList;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Set;
public class InstallShortcutReceiver extends BroadcastReceiver {
@@ -47,16 +48,33 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
public static final String SHORTCUT_MIMETYPE =
"com.android.launcher/shortcut";
- private final int[] mCoordinates = new int[2];
+ // The set of shortcuts that are pending install
+ private static ArrayList<PendingInstallShortcutInfo> mInstallQueue =
+ new ArrayList<PendingInstallShortcutInfo>();
+
+ // Determines whether to defer installing shortcuts immediately until
+ // processAllPendingInstalls() is called.
+ private static boolean mUseInstallQueue = false;
+
+ private static class PendingInstallShortcutInfo {
+ Intent data;
+ Intent launchIntent;
+ String name;
+
+ public PendingInstallShortcutInfo(Intent rawData, String shortcutName,
+ Intent shortcutIntent) {
+ data = rawData;
+ name = shortcutName;
+ launchIntent = shortcutIntent;
+ }
+ }
public void onReceive(Context context, Intent data) {
if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
return;
}
- String spKey = LauncherApplication.getSharedPreferencesKey();
- SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
- final Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
+ Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
if (intent == null) {
return;
}
@@ -73,6 +91,36 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
}
}
+ PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
+ if (mUseInstallQueue) {
+ mInstallQueue.add(info);
+ } else {
+ processInstallShortcut(context, info);
+ }
+ }
+
+ static void enableInstallQueue() {
+ mUseInstallQueue = true;
+ }
+
+ static void disableAndFlushInstallQueue(Context context) {
+ mUseInstallQueue = false;
+ Iterator<PendingInstallShortcutInfo> iter = mInstallQueue.iterator();
+ while (iter.hasNext()) {
+ processInstallShortcut(context, iter.next());
+ iter.remove();
+ }
+ }
+
+ private static void processInstallShortcut(Context context,
+ PendingInstallShortcutInfo pendingInfo) {
+ String spKey = LauncherApplication.getSharedPreferencesKey();
+ SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
+
+ final Intent data = pendingInfo.data;
+ final Intent intent = pendingInfo.launchIntent;
+ final String name = pendingInfo.name;
+
// Lock on the app so that we don't try and get the items while apps are being added
LauncherApplication app = (LauncherApplication) context.getApplicationContext();
final int[] result = {INSTALL_SHORTCUT_SUCCESSFUL};
@@ -106,10 +154,11 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
}
}
- private boolean installShortcut(Context context, Intent data, ArrayList<ItemInfo> items,
+ private static boolean installShortcut(Context context, Intent data, ArrayList<ItemInfo> items,
String name, Intent intent, final int screen, boolean shortcutExists,
final SharedPreferences sharedPrefs, int[] result) {
- if (findEmptyCell(context, items, mCoordinates, screen)) {
+ int[] tmpCoordinates = new int[2];
+ if (findEmptyCell(context, items, tmpCoordinates, screen)) {
if (intent != null) {
if (intent.getAction() == null) {
intent.setAction(Intent.ACTION_VIEW);
@@ -145,7 +194,7 @@ public class InstallShortcutReceiver extends BroadcastReceiver {
LauncherApplication app = (LauncherApplication) context.getApplicationContext();
ShortcutInfo info = app.getModel().addShortcut(context, data,
LauncherSettings.Favorites.CONTAINER_DESKTOP, screen,
- mCoordinates[0], mCoordinates[1], true);
+ tmpCoordinates[0], tmpCoordinates[1], true);
if (info == null) {
return false;
}
diff --git a/src/com/android/launcher2/UninstallShortcutReceiver.java b/src/com/android/launcher2/UninstallShortcutReceiver.java
index 3f6de7c5a..84b1ad50e 100644
--- a/src/com/android/launcher2/UninstallShortcutReceiver.java
+++ b/src/com/android/launcher2/UninstallShortcutReceiver.java
@@ -17,38 +17,83 @@
package com.android.launcher2;
import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
-import android.content.ContentResolver;
import android.content.SharedPreferences;
import android.database.Cursor;
import android.net.Uri;
import android.widget.Toast;
+import com.android.launcher.R;
+
import java.net.URISyntaxException;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Set;
-import com.android.launcher.R;
-
public class UninstallShortcutReceiver extends BroadcastReceiver {
private static final String ACTION_UNINSTALL_SHORTCUT =
"com.android.launcher.action.UNINSTALL_SHORTCUT";
+ // The set of shortcuts that are pending uninstall
+ private static ArrayList<PendingUninstallShortcutInfo> mUninstallQueue =
+ new ArrayList<PendingUninstallShortcutInfo>();
+
+ // Determines whether to defer uninstalling shortcuts immediately until
+ // disableAndFlushUninstallQueue() is called.
+ private static boolean mUseUninstallQueue = false;
+
+ private static class PendingUninstallShortcutInfo {
+ Intent data;
+
+ public PendingUninstallShortcutInfo(Intent rawData) {
+ data = rawData;
+ }
+ }
+
public void onReceive(Context context, Intent data) {
if (!ACTION_UNINSTALL_SHORTCUT.equals(data.getAction())) {
return;
}
+
+ PendingUninstallShortcutInfo info = new PendingUninstallShortcutInfo(data);
+ if (mUseUninstallQueue) {
+ mUninstallQueue.add(info);
+ } else {
+ processUninstallShortcut(context, info);
+ }
+ }
+
+ static void enableUninstallQueue() {
+ mUseUninstallQueue = true;
+ }
+
+ static void disableAndFlushUninstallQueue(Context context) {
+ mUseUninstallQueue = false;
+ Iterator<PendingUninstallShortcutInfo> iter = mUninstallQueue.iterator();
+ while (iter.hasNext()) {
+ processUninstallShortcut(context, iter.next());
+ iter.remove();
+ }
+ }
+
+ private static void processUninstallShortcut(Context context,
+ PendingUninstallShortcutInfo pendingInfo) {
String spKey = LauncherApplication.getSharedPreferencesKey();
SharedPreferences sharedPrefs = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
+ final Intent data = pendingInfo.data;
+
LauncherApplication app = (LauncherApplication) context.getApplicationContext();
synchronized (app) {
removeShortcut(context, data, sharedPrefs);
}
}
- private void removeShortcut(Context context, Intent data, final SharedPreferences sharedPrefs) {
+ private static void removeShortcut(Context context, Intent data,
+ final SharedPreferences sharedPrefs) {
Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
boolean duplicate = data.getBooleanExtra(Launcher.EXTRA_SHORTCUT_DUPLICATE, true);
diff --git a/src/com/android/launcher2/Workspace.java b/src/com/android/launcher2/Workspace.java
index ec18fb3e3..ab8c26c85 100644
--- a/src/com/android/launcher2/Workspace.java
+++ b/src/com/android/launcher2/Workspace.java
@@ -38,8 +38,6 @@ import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.PointF;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.Region.Op;
import android.graphics.drawable.Drawable;
@@ -381,12 +379,20 @@ public class Workspace extends SmoothPagedView
mIsDragOccuring = true;
updateChildrenLayersEnabled();
mLauncher.lockScreenOrientation();
+
+ // Prevent any Un/InstallShortcutReceivers from updating the db while we are dragging
+ InstallShortcutReceiver.enableInstallQueue();
+ UninstallShortcutReceiver.enableUninstallQueue();
}
public void onDragEnd() {
mIsDragOccuring = false;
updateChildrenLayersEnabled();
mLauncher.unlockScreenOrientation(false);
+
+ // Re-enable any Un/InstallShortcutReceiver and now process any queued items
+ InstallShortcutReceiver.disableAndFlushInstallQueue(getContext());
+ UninstallShortcutReceiver.disableAndFlushUninstallQueue(getContext());
}
/**