Updating the virtual preloader UX.

> No click feedback when in preloader mode
> No preloader UI when drawn in drag layer
> The preloader consists of a background 9 patch image and a circular progress
is drawn in the content region of the background.
> The preloader is drawn in a slightly larget area than the actual bounds to
make the circular progress more prominent compared to the icon.

issue: 15835307
Change-Id: Ifec3d93ecf1fac994d1128b517da3797247e7ed6
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index ab94814..5c2bb99 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -19,6 +19,7 @@
 import android.content.Context;
 import android.content.res.ColorStateList;
 import android.content.res.Resources;
+import android.content.res.Resources.Theme;
 import android.content.res.TypedArray;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
@@ -28,6 +29,7 @@
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.util.Log;
+import android.util.SparseArray;
 import android.util.TypedValue;
 import android.view.MotionEvent;
 import android.view.ViewConfiguration;
@@ -39,6 +41,9 @@
  * too aggressive.
  */
 public class BubbleTextView extends TextView {
+
+    private static SparseArray<Theme> sPreloaderThemes = new SparseArray<>(2);
+
     static final float SHADOW_LARGE_RADIUS = 4.0f;
     static final float SHADOW_SMALL_RADIUS = 1.75f;
     static final float SHADOW_Y_OFFSET = 2.0f;
@@ -128,10 +133,7 @@
         LauncherAppState app = LauncherAppState.getInstance();
 
         FastBitmapDrawable iconDrawable = Utilities.createIconDrawable(b);
-        if (info.isDisabled) {
-            iconDrawable.setSaturation(0);
-            iconDrawable.setBrightness(20);
-        }
+        iconDrawable.setGhostModeEnabled(info.isDisabled);
 
         setCompoundDrawables(null, iconDrawable, null, null);
         if (setDefaultPadding) {
@@ -315,7 +317,9 @@
     }
 
     void setCellLayoutPressedOrFocusedIcon() {
-        if (getParent() instanceof ShortcutAndWidgetContainer) {
+        // Disable pressed state when the icon is in preloader state.
+        if ((getParent() instanceof ShortcutAndWidgetContainer) &&
+                !(getCompoundDrawables()[1] instanceof PreloadIconDrawable)){
             ShortcutAndWidgetContainer parent = (ShortcutAndWidgetContainer) getParent();
             if (parent != null) {
                 CellLayout layout = (CellLayout) parent.getParent();
@@ -385,7 +389,13 @@
     @Override
     protected void onAttachedToWindow() {
         super.onAttachedToWindow();
+
         if (mBackground != null) mBackground.setCallback(this);
+        Drawable top = getCompoundDrawables()[1];
+
+        if (top instanceof PreloadIconDrawable) {
+            ((PreloadIconDrawable) top).applyTheme(getPreloaderTheme());
+        }
         mSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
     }
 
@@ -466,7 +476,7 @@
                 if (top instanceof PreloadIconDrawable) {
                     preloadDrawable = (PreloadIconDrawable) top;
                 } else {
-                    preloadDrawable = new PreloadIconDrawable(top, getResources());
+                    preloadDrawable = new PreloadIconDrawable(top, getPreloaderTheme());
                     setCompoundDrawables(drawables[0], preloadDrawable, drawables[2], drawables[3]);
                 }
 
@@ -478,4 +488,18 @@
             }
         }
     }
+
+    private Theme getPreloaderTheme() {
+        Object tag = getTag();
+        int style = ((tag != null) && (tag instanceof ShortcutInfo) &&
+                (((ShortcutInfo) tag).container >= 0)) ? R.style.PreloadIcon_Folder
+                        : R.style.PreloadIcon;
+        Theme theme = sPreloaderThemes.get(style);
+        if (theme == null) {
+            theme = getResources().newTheme();
+            theme.applyStyle(style, true);
+            sPreloaderThemes.put(style, theme);
+        }
+        return theme;
+    }
 }