Adding support for dynamic calendar and clock icons

Change-Id: Icdba34340a27a4f6dff7310d0bf9fd29aef1330c
diff --git a/src/com/android/launcher3/FastBitmapDrawable.java b/src/com/android/launcher3/FastBitmapDrawable.java
index 2e57f71..5091684 100644
--- a/src/com/android/launcher3/FastBitmapDrawable.java
+++ b/src/com/android/launcher3/FastBitmapDrawable.java
@@ -20,6 +20,7 @@
 import static com.android.launcher3.anim.Interpolators.DEACCEL;
 
 import android.animation.ObjectAnimator;
+import android.content.Context;
 import android.graphics.Bitmap;
 import android.graphics.Canvas;
 import android.graphics.Color;
@@ -35,6 +36,7 @@
 import android.util.Property;
 import android.util.SparseArray;
 
+import com.android.launcher3.graphics.PlaceHolderIconDrawable;
 import com.android.launcher3.icons.BitmapInfo;
 
 public class FastBitmapDrawable extends Drawable {
@@ -361,7 +363,7 @@
         }
 
         @Override
-        public Drawable newDrawable() {
+        public FastBitmapDrawable newDrawable() {
             return new FastBitmapDrawable(mBitmap, mIconColor, mIsDisabled);
         }
 
@@ -370,4 +372,37 @@
             return 0;
         }
     }
+
+    /**
+     * Interface to be implemented by custom {@link BitmapInfo} to handle drawable construction
+     */
+    public interface Factory {
+
+        /**
+         * Called to create a new drawable
+         */
+        FastBitmapDrawable newDrawable();
+    }
+
+    /**
+     * Returns a FastBitmapDrawable with the icon.
+     */
+    public static FastBitmapDrawable newIcon(Context context, ItemInfoWithIcon info) {
+        FastBitmapDrawable drawable = newIcon(context, info.bitmap);
+        drawable.setIsDisabled(info.isDisabled());
+        return drawable;
+    }
+
+    /**
+     * Creates a drawable for the provided BitmapInfo
+     */
+    public static FastBitmapDrawable newIcon(Context context, BitmapInfo info) {
+        if (info instanceof Factory) {
+            return ((Factory) info).newDrawable();
+        } else if (info.isLowRes()) {
+            return new PlaceHolderIconDrawable(info, context);
+        } else {
+            return new FastBitmapDrawable(info);
+        }
+    }
 }