Making LauncherIcons thread safe

Creating a pool of LauncherIcons so that they can be used from multiple threads

Change-Id: Idc7b5ddb47b6e338a5389f3c4faa6f63de108c72
This commit is contained in:
Sunny Goyal
2018-01-09 15:34:38 -08:00
parent 383b7fa02a
commit 18a4e5aefb
21 changed files with 276 additions and 391 deletions

View File

@@ -46,17 +46,13 @@ public class ShadowGenerator {
private static final int AMBIENT_SHADOW_ALPHA = 30;
private static final Object LOCK = new Object();
// Singleton object guarded by {@link #LOCK}
private static ShadowGenerator sShadowGenerator;
private final int mIconSize;
private final Paint mBlurPaint;
private final Paint mDrawPaint;
private final BlurMaskFilter mDefaultBlurMaskFilter;
private ShadowGenerator(Context context) {
public ShadowGenerator(Context context) {
mIconSize = LauncherAppState.getIDP(context).iconBitmapSize;
mBlurPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
mDrawPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG);
@@ -86,18 +82,6 @@ public class ShadowGenerator {
out.drawBitmap(icon, 0, 0, mDrawPaint);
}
public static ShadowGenerator getInstance(Context context) {
// TODO: This currently fails as the system default icon also needs a shadow as it
// uses adaptive icon.
// Preconditions.assertNonUiThread();
synchronized (LOCK) {
if (sShadowGenerator == null) {
sShadowGenerator = new ShadowGenerator(context);
}
}
return sShadowGenerator;
}
/**
* Returns the minimum amount by which an icon with {@param bounds} should be scaled
* so that the shadows do not get clipped.