Updating the PreloadIconDrawable

> The drawable gets the path from MaskIconDrawable path, instead of
  using a circle
> The progress changes are animated as well

Bug: 34831873
Change-Id: I4e7f0b610f4fd94de8e0cfcf8b179b775cf0b4d8
This commit is contained in:
Sunny Goyal committed 2017-02-06 10:43:27 -08:00
1 parent e1fa0145d3
commit 96ac68a481
24 files changed
+443 -350

No files matched your search

@@ -21,12 +21,14 @@ import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Process;
import android.os.UserHandle;
import android.support.annotation.UiThread;
import android.util.Log;
import com.android.launcher3.FastBitmapDrawable;
import com.android.launcher3.ItemInfo;
@@ -41,9 +43,13 @@ import java.util.HashMap;
*/
public class DrawableFactory {
private static final String TAG = "DrawableFactory";
private static DrawableFactory sInstance;
private static final Object LOCK = new Object();
private Path mPreloadProgressPath;
public static DrawableFactory get(Context context) {
synchronized (LOCK) {
if (sInstance == null) {
@@ -61,9 +67,38 @@ public class DrawableFactory {
* Returns a FastBitmapDrawable with the icon.
*/
public FastBitmapDrawable newIcon(Bitmap icon, ItemInfo info) {
FastBitmapDrawable d = new FastBitmapDrawable(icon);
d.setFilterBitmap(true);
return d;
return new FastBitmapDrawable(icon);
}
/**
* Returns a FastBitmapDrawable with the icon.
*/
public PreloadIconDrawable newPendingIcon(Bitmap icon, Context context) {
if (mPreloadProgressPath == null) {
mPreloadProgressPath = getPreloadProgressPath(context);
}
return new PreloadIconDrawable(icon, mPreloadProgressPath);
}
protected Path getPreloadProgressPath(Context context) {
if (Utilities.isAtLeastO()) {
try {
// Try to load the path from Mask Icon
Drawable maskIcon = context.getDrawable(R.drawable.mask_drawable_wrapper);
maskIcon.setBounds(0, 0,
PreloadIconDrawable.PATH_SIZE, PreloadIconDrawable.PATH_SIZE);
return (Path) maskIcon.getClass().getMethod("getIconMask").invoke(maskIcon);
} catch (Exception e) {
Log.e(TAG, "Error loading mask icon", e);
}
}
// Create a circle static from top center and going clockwise.
Path p = new Path();
p.moveTo(PreloadIconDrawable.PATH_SIZE / 2, 0);
p.addArc(0, 0, PreloadIconDrawable.PATH_SIZE, PreloadIconDrawable.PATH_SIZE, -90, 360);
return p;
}
public AllAppsBackgroundDrawable getAllAppsBackground(Context context) {