diff options
| author | Sunny Goyal <sunnygoyal@google.com> | 2021-05-21 14:22:30 -0700 |
|---|---|---|
| committer | Sunny Goyal <sunnygoyal@google.com> | 2021-05-21 14:23:08 -0700 |
| commit | fc33a2fa7d8412352472a1e62efa68a52d822495 (patch) | |
| tree | 3f16a8de74161f581449edfe12af8266839da0b6 | |
| parent | ab267964d5e309e6653b2abc9cca11770d89d1c7 (diff) | |
Adding method to check if the drawable is themed or not
Bug: 188840653
Test: Manual
Change-Id: I1ed7fc0ff9e95558b73b94e08bda7156eb7ac178
3 files changed, 32 insertions, 12 deletions
diff --git a/iconloaderlib/src/com/android/launcher3/icons/ClockDrawableWrapper.java b/iconloaderlib/src/com/android/launcher3/icons/ClockDrawableWrapper.java index 41de147..a7894c9 100644 --- a/iconloaderlib/src/com/android/launcher3/icons/ClockDrawableWrapper.java +++ b/iconloaderlib/src/com/android/launcher3/icons/ClockDrawableWrapper.java @@ -281,15 +281,22 @@ public class ClockDrawableWrapper extends AdaptiveIconDrawable implements Bitmap public final Bitmap mFlattenedBackground; public final ThemeData themeData; + public final ColorFilter bgFilter; ClockBitmapInfo(Bitmap icon, int color, float scale, AnimationInfo animInfo, Bitmap background, ThemeData themeData) { + this(icon, color, scale, animInfo, background, themeData, null); + } + + ClockBitmapInfo(Bitmap icon, int color, float scale, AnimationInfo animInfo, + Bitmap background, ThemeData themeData, ColorFilter bgFilter) { super(icon, color); this.scale = scale; this.animInfo = animInfo; this.offset = (int) Math.ceil(ShadowGenerator.BLUR_FACTOR * icon.getWidth()); this.mFlattenedBackground = background; this.themeData = themeData; + this.bgFilter = bgFilter; } @Override @@ -299,18 +306,9 @@ public class ClockDrawableWrapper extends AdaptiveIconDrawable implements Bitmap if (wrapper != null) { int[] colors = getColors(context); ColorFilter bgFilter = new PorterDuffColorFilter(colors[0], Mode.SRC_ATOP); - ClockBitmapInfo bitmapInfo = new ClockBitmapInfo(icon, colors[1], scale, - wrapper.mAnimationInfo, mFlattenedBackground, themeData) { - - @Override - void drawBackground(Canvas canvas, Rect bounds, Paint paint) { - ColorFilter oldFilter = paint.getColorFilter(); - paint.setColorFilter(bgFilter); - super.drawBackground(canvas, bounds, paint); - paint.setColorFilter(oldFilter); - } - }; - return bitmapInfo.newIcon(context); + return new ClockBitmapInfo(icon, colors[1], scale, + wrapper.mAnimationInfo, mFlattenedBackground, themeData, bgFilter) + .newIcon(context); } } return super.newThemedIcon(context); @@ -331,7 +329,12 @@ public class ClockDrawableWrapper extends AdaptiveIconDrawable implements Bitmap void drawBackground(Canvas canvas, Rect bounds, Paint paint) { // draw the background that is already flattened to a bitmap + ColorFilter oldFilter = paint.getColorFilter(); + if (bgFilter != null) { + paint.setColorFilter(bgFilter); + } canvas.drawBitmap(mFlattenedBackground, null, bounds, paint); + paint.setColorFilter(oldFilter); } } @@ -379,6 +382,11 @@ public class ClockDrawableWrapper extends AdaptiveIconDrawable implements Bitmap } @Override + public boolean isThemed() { + return mInfo.bgFilter != null; + } + + @Override protected void updateFilter() { super.updateFilter(); mFullDrawable.setColorFilter(mPaint.getColorFilter()); diff --git a/iconloaderlib/src/com/android/launcher3/icons/FastBitmapDrawable.java b/iconloaderlib/src/com/android/launcher3/icons/FastBitmapDrawable.java index 72864c8..96ee291 100644 --- a/iconloaderlib/src/com/android/launcher3/icons/FastBitmapDrawable.java +++ b/iconloaderlib/src/com/android/launcher3/icons/FastBitmapDrawable.java @@ -120,6 +120,13 @@ public class FastBitmapDrawable extends Drawable { return mIconColor; } + /** + * Returns if this represents a themed icon + */ + public boolean isThemed() { + return false; + } + @Override public void setColorFilter(ColorFilter cf) { mColorFilter = cf; diff --git a/iconloaderlib/src/com/android/launcher3/icons/ThemedIconDrawable.java b/iconloaderlib/src/com/android/launcher3/icons/ThemedIconDrawable.java index b4d72d4..797a439 100644 --- a/iconloaderlib/src/com/android/launcher3/icons/ThemedIconDrawable.java +++ b/iconloaderlib/src/com/android/launcher3/icons/ThemedIconDrawable.java @@ -101,6 +101,11 @@ public class ThemedIconDrawable extends FastBitmapDrawable { } @Override + public boolean isThemed() { + return true; + } + + @Override public ConstantState getConstantState() { return new ThemedConstantState(bitmapInfo, colorBg, colorFg, mIsDisabled); } |
