Offer to delete broken promise icons.

Track state of promise in the info, not the view.
Fix bugs around moving promises to folders.
Fix bugs around filterign and removing promises.

Bug: 12764789
Change-Id: If5e8b6d315e463154b5bafe8aef7ef4f9889bb95
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index 95300c1..992ac58 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -74,8 +74,6 @@
     private CheckLongPressHelper mLongPressHelper;
     private int mInstallState;
 
-    private int mState;
-
     private CharSequence mDefaultText = "";
 
     public BubbleTextView(Context context) {
@@ -124,10 +122,9 @@
         Drawable iconDrawable = Utilities.createIconDrawable(b);
         setCompoundDrawables(null, iconDrawable, null, null);
         setCompoundDrawablePadding(grid.iconDrawablePaddingPx);
-        setText(info.title);
         setTag(info);
         if (info.isPromise()) {
-            setState(ShortcutInfo.PACKAGE_STATE_UNKNOWN); // TODO: persist this state somewhere
+            applyState();
         }
     }
 
@@ -150,6 +147,11 @@
             LauncherModel.checkItemInfo((ItemInfo) tag);
         }
         super.setTag(tag);
+        if (tag instanceof ShortcutInfo) {
+            final ShortcutInfo info = (ShortcutInfo) tag;
+            mDefaultText = info.title;
+            setText(mDefaultText);
+        }
     }
 
     @Override
@@ -415,19 +417,12 @@
         mLongPressHelper.cancelLongPress();
     }
 
-    public void setState(int state) {
-        if (mState == ShortcutInfo.PACKAGE_STATE_DEFAULT && mState != state) {
-            mDefaultText = getText();
-        }
-        mState = state;
-        applyState();
-    }
-
-    private void applyState() {
+    public void applyState() {
         int alpha = getResources().getInteger(R.integer.promise_icon_alpha);
-        if (DEBUG) Log.d(TAG, "applying icon state: " + mState);
+        final int state = getState();
+        if (DEBUG) Log.d(TAG, "applying icon state: " + state);
 
-        switch(mState) {
+        switch(state) {
             case ShortcutInfo.PACKAGE_STATE_DEFAULT:
                 super.setText(mDefaultText);
                 alpha = 255;
@@ -462,4 +457,13 @@
             }
         }
     }
+
+    private int getState() {
+        if (! (getTag() instanceof ShortcutInfo)) {
+            return ShortcutInfo.PACKAGE_STATE_DEFAULT;
+        } else {
+            ShortcutInfo info = (ShortcutInfo) getTag();
+            return info.getState();
+        }
+    }
 }