Implement ability to uninstall shortcuts from workspace

Change-Id: I14ca94ea719825c4de19ab85d67537155098d50c
diff --git a/src/com/android/launcher3/Folder.java b/src/com/android/launcher3/Folder.java
index 4de9297..bb3993e 100644
--- a/src/com/android/launcher3/Folder.java
+++ b/src/com/android/launcher3/Folder.java
@@ -126,6 +126,10 @@
 
     private AutoScroller mAutoScroller;
 
+    private Runnable mDeferredAction;
+    private boolean mDeferDropAfterUninstall;
+    private boolean mUninstallSuccessful;
+
     /**
      * Used to inflate the Workspace from XML.
      *
@@ -743,9 +747,22 @@
         mDragMode = DRAG_MODE_NONE;
     }
 
-    public void onDropCompleted(View target, DragObject d, boolean isFlingToDelete,
-            boolean success) {
-        if (success) {
+    public void onDropCompleted(final View target, final DragObject d,
+            final boolean isFlingToDelete, final boolean success) {
+        if (mDeferDropAfterUninstall) {
+            mDeferredAction = new Runnable() {
+                    public void run() {
+                        onDropCompleted(target, d, isFlingToDelete, success);
+                        mDeferredAction = null;
+                    }
+                };
+            return;
+        }
+
+        boolean beingCalledAfterUninstall = mDeferredAction != null;
+        boolean successfulDrop =
+                success && (!beingCalledAfterUninstall || mUninstallSuccessful);
+        if (successfulDrop) {
             if (mDeleteFolderOnDropCompleted && !mItemAddedBackToSelfViaIcon) {
                 replaceFolderWithFinalItem();
             }
@@ -758,7 +775,7 @@
         if (target != this) {
             if (mOnExitAlarm.alarmPending()) {
                 mOnExitAlarm.cancelAlarm();
-                if (!success) {
+                if (successfulDrop) {
                     mSuppressFolderDeletion = true;
                 }
                 completeDragExit();
@@ -776,6 +793,18 @@
         updateItemLocationsInDatabaseBatch();
     }
 
+    public void deferCompleteDropAfterUninstallActivity() {
+        mDeferDropAfterUninstall = true;
+    }
+
+    public void onUninstallActivityReturned(boolean success) {
+        mDeferDropAfterUninstall = false;
+        mUninstallSuccessful = success;
+        if (mDeferredAction != null) {
+            mDeferredAction.run();
+        }
+    }
+
     @Override
     public boolean supportsFlingToDelete() {
         return true;