Handling label and icon from SessionInfo.

> The ShortcutInfo stores state as bit flags and not as ints
> Intents of auto-install shortcut are automatically updated
upon installation
> Icons/titles for active sessions are cached in IconCache

Change-Id: I2047849f67d4a8aaf2bc346b58110325bb4807d4
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index d83f81d..a368796 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -26,7 +26,6 @@
 import android.graphics.Region;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
-import android.util.Log;
 import android.util.SparseArray;
 import android.util.TypedValue;
 import android.view.KeyEvent;
@@ -50,10 +49,6 @@
     private static final int SHADOW_SMALL_COLOUR = 0xCC000000;
     static final float PADDING_V = 3.0f;
 
-    private static final String TAG = "BubbleTextView";
-
-    private static final boolean DEBUG = false;
-
     private HolographicOutlineHelper mOutlineHelper;
     private Bitmap mPressedBackground;
 
@@ -118,6 +113,11 @@
 
     public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache,
             boolean setDefaultPadding) {
+        applyFromShortcutInfo(info, iconCache, setDefaultPadding, false);
+    }
+
+    public void applyFromShortcutInfo(ShortcutInfo info, IconCache iconCache,
+            boolean setDefaultPadding, boolean promiseStateChanged) {
         Bitmap b = info.getIcon(iconCache);
         LauncherAppState app = LauncherAppState.getInstance();
 
@@ -135,8 +135,8 @@
         setText(info.title);
         setTag(info);
 
-        if (info.wasPromise) {
-            applyState();
+        if (promiseStateChanged || info.isPromise()) {
+            applyState(promiseStateChanged);
         }
     }
 
@@ -377,31 +377,13 @@
         mLongPressHelper.cancelLongPress();
     }
 
-    public void applyState() {
+    public void applyState(boolean promiseStateChanged) {
         if (getTag() instanceof ShortcutInfo) {
             ShortcutInfo info = (ShortcutInfo) getTag();
-            final int state = info.getState();
-
-            final int progressLevel;
-            if (DEBUG) Log.d(TAG, "applying icon state: " + state);
-
-            switch(state) {
-                case ShortcutInfo.PACKAGE_STATE_DEFAULT:
-                    progressLevel = 100;
-                    break;
-
-                case ShortcutInfo.PACKAGE_STATE_INSTALLING:
-                    setText(R.string.package_state_installing);
-                    progressLevel = info.getProgress();
-                    break;
-
-                case ShortcutInfo.PACKAGE_STATE_ERROR:
-                case ShortcutInfo.PACKAGE_STATE_UNKNOWN:
-                default:
-                    progressLevel = 0;
-                    setText(R.string.package_state_unknown);
-                    break;
-            }
+            final boolean isPromise = info.isPromise();
+            final int progressLevel = isPromise ?
+                    ((info.hasStatusFlag(ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE) ?
+                            info.getInstallProgress() : 0)) : 100;
 
             Drawable[] drawables = getCompoundDrawables();
             Drawable top = drawables[1];
@@ -415,12 +397,9 @@
                 }
 
                 preloadDrawable.setLevel(progressLevel);
-                if ((state == ShortcutInfo.PACKAGE_STATE_DEFAULT) && info.wasPromise) {
-                    // Clear the promise flag as it is no longer different than a normal shortcut,
-                    // once the animation has been run.
-                    info.wasPromise = !preloadDrawable.maybePerformFinishedAnimation();
+                if (promiseStateChanged) {
+                    preloadDrawable.maybePerformFinishedAnimation();
                 }
-
             }
         }
     }