Adding a circular progress bar for preloader icons

Change-Id: I1b5ba61c01a16a8cb5d3f9e31f827f8c99a1ffc9
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index 57dcea0..3f619a8 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -136,7 +136,8 @@
             setContentDescription(info.contentDescription);
         }
         setTag(info);
-        if (info.isPromise()) {
+
+        if (info.wasPromise) {
             applyState();
         }
     }
@@ -431,42 +432,55 @@
     }
 
     public void applyState() {
-        int alpha = getResources().getInteger(R.integer.promise_icon_alpha);
+        final int progressLevel;
         final int state = getState();
         if (DEBUG) Log.d(TAG, "applying icon state: " + state);
 
         switch(state) {
             case ShortcutInfo.PACKAGE_STATE_DEFAULT:
                 super.setText(mDefaultText);
-                alpha = 255;
+                progressLevel = 100;
                 break;
 
             case ShortcutInfo.PACKAGE_STATE_ENQUEUED:
                 setText(R.string.package_state_enqueued);
+                progressLevel = 0;
                 break;
 
             case ShortcutInfo.PACKAGE_STATE_DOWNLOADING:
                 setText(R.string.package_state_downloading);
+                // TODO(sunnygoyal): fix progress
+                progressLevel = 30;
                 break;
 
             case ShortcutInfo.PACKAGE_STATE_INSTALLING:
                 setText(R.string.package_state_installing);
+                progressLevel = 100;
                 break;
 
             case ShortcutInfo.PACKAGE_STATE_ERROR:
                 setText(R.string.package_state_error);
+                progressLevel = 0;
                 break;
 
             case ShortcutInfo.PACKAGE_STATE_UNKNOWN:
             default:
+                progressLevel = 0;
                 setText(R.string.package_state_unknown);
                 break;
         }
-        if (DEBUG) Log.d(TAG, "setting icon alpha to: " + alpha);
+
         Drawable[] drawables = getCompoundDrawables();
-        for (int i = 0; i < drawables.length; i++) {
-            if (drawables[i] != null) {
-                drawables[i].setAlpha(alpha);
+        Drawable top = drawables[1];
+        if ((top != null) && !(top instanceof PreloadIconDrawable)) {
+            top = new PreloadIconDrawable(top, getResources());
+            setCompoundDrawables(drawables[0], top, drawables[2], drawables[3]);
+        }
+        if (top != null) {
+            top.setLevel(progressLevel);
+            if ((top instanceof PreloadIconDrawable)
+                    && (state == ShortcutInfo.PACKAGE_STATE_DEFAULT)) {
+                ((PreloadIconDrawable) top).maybePerformFinishedAnimation();
             }
         }
     }