Loading iconloaderlib/src/com/android/launcher3/icons/BitmapInfo.java +40 −12 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.Canvas; import android.graphics.Path; import android.graphics.drawable.Drawable; import androidx.annotation.IntDef; Loading Loading @@ -153,6 +154,19 @@ public class BitmapInfo { * Creates a drawable for the provided BitmapInfo */ public FastBitmapDrawable newIcon(Context context, @DrawableCreationFlags int creationFlags) { return newIcon(context, creationFlags, null); } /** * Creates a drawable for the provided BitmapInfo * * @param context Context * @param creationFlags Flags for creating the FastBitmapDrawable * @param badgeShape Optional Path for masking icon badges to a shape. Should be 100x100. * @return FastBitmapDrawable */ public FastBitmapDrawable newIcon(Context context, @DrawableCreationFlags int creationFlags, @Nullable Path badgeShape) { FastBitmapDrawable drawable; if (isLowRes()) { drawable = new PlaceHolderIconDrawable(this, context); Loading @@ -161,54 +175,68 @@ public class BitmapInfo { } else { drawable = new FastBitmapDrawable(this); } applyFlags(context, drawable, creationFlags); applyFlags(context, drawable, creationFlags, badgeShape); return drawable; } protected void applyFlags(Context context, FastBitmapDrawable drawable, @DrawableCreationFlags int creationFlags) { @DrawableCreationFlags int creationFlags, @Nullable Path badgeShape) { this.creationFlags = creationFlags; drawable.mDisabledAlpha = GraphicsUtils.getFloat(context, R.attr.disabledIconAlpha, 1f); drawable.mCreationFlags = creationFlags; if ((creationFlags & FLAG_NO_BADGE) == 0) { Drawable badge = getBadgeDrawable(context, (creationFlags & FLAG_THEMED) != 0, (creationFlags & FLAG_SKIP_USER_BADGE) != 0); (creationFlags & FLAG_SKIP_USER_BADGE) != 0, badgeShape); if (badge != null) { drawable.setBadge(badge); } } } public Drawable getBadgeDrawable(Context context, boolean isThemed) { return getBadgeDrawable(context, isThemed, false); /** * Gets Badge drawable based on current flags * @param context Context * @param isThemed If Drawable is themed. * @param badgeShape Optional Path to mask badges to a shape. Should be 100x100. * @return Drawable for the badge. */ public Drawable getBadgeDrawable(Context context, boolean isThemed, @Nullable Path badgeShape) { return getBadgeDrawable(context, isThemed, false, badgeShape); } /** * Returns a drawable representing the badge for this info * Creates a Drawable for an icon badge for this BitmapInfo * @param context Context * @param isThemed If the drawable is themed. * @param skipUserBadge If should skip User Profile badging. * @param badgeShape Optional Path to mask badge Drawable to a shape. Should be 100x100. * @return Drawable for an icon Badge. */ @Nullable private Drawable getBadgeDrawable(Context context, boolean isThemed, boolean skipUserBadge) { private Drawable getBadgeDrawable(Context context, boolean isThemed, boolean skipUserBadge, @Nullable Path badgeShape) { if (badgeInfo != null) { int creationFlag = isThemed ? FLAG_THEMED : 0; if (skipUserBadge) { creationFlag |= FLAG_SKIP_USER_BADGE; } return badgeInfo.newIcon(context, creationFlag); return badgeInfo.newIcon(context, creationFlag, badgeShape); } if (skipUserBadge) { return null; } else if ((flags & FLAG_INSTANT) != 0) { return new UserBadgeDrawable(context, R.drawable.ic_instant_app_badge, R.color.badge_tint_instant, isThemed); R.color.badge_tint_instant, isThemed, badgeShape); } else if ((flags & FLAG_WORK) != 0) { return new UserBadgeDrawable(context, R.drawable.ic_work_app_badge, R.color.badge_tint_work, isThemed); R.color.badge_tint_work, isThemed, badgeShape); } else if ((flags & FLAG_CLONE) != 0) { return new UserBadgeDrawable(context, R.drawable.ic_clone_app_badge, R.color.badge_tint_clone, isThemed); R.color.badge_tint_clone, isThemed, badgeShape); } else if ((flags & FLAG_PRIVATE) != 0) { return new UserBadgeDrawable(context, R.drawable.ic_private_profile_app_badge, R.color.badge_tint_private, isThemed); R.color.badge_tint_private, isThemed, badgeShape); } return null; } Loading iconloaderlib/src/com/android/launcher3/icons/ClockDrawableWrapper.java +3 −2 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Rect; import android.graphics.drawable.AdaptiveIconDrawable; import android.graphics.drawable.ColorDrawable; Loading Loading @@ -283,7 +284,7 @@ public class ClockDrawableWrapper extends AdaptiveIconDrawable implements Bitmap @Override @TargetApi(Build.VERSION_CODES.TIRAMISU) public FastBitmapDrawable newIcon(Context context, @DrawableCreationFlags int creationFlags) { @DrawableCreationFlags int creationFlags, Path badgeShape) { AnimationInfo info; Bitmap bg; int themedFgColor; Loading @@ -308,7 +309,7 @@ public class ClockDrawableWrapper extends AdaptiveIconDrawable implements Bitmap ClockIconDrawable.ClockConstantState cs = new ClockIconDrawable.ClockConstantState( this, themedFgColor, boundsOffset, info, bg, bgFilter); FastBitmapDrawable d = cs.newDrawable(); applyFlags(context, d, creationFlags); applyFlags(context, d, creationFlags, null); return d; } Loading iconloaderlib/src/com/android/launcher3/icons/GraphicsUtils.java +0 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ import java.io.IOException; public class GraphicsUtils { private static final String TAG = "GraphicsUtils"; private static final float MASK_SIZE = 100f; public static Runnable sOnNewBitmapRunnable = () -> { }; Loading iconloaderlib/src/com/android/launcher3/icons/UserBadgeDrawable.java +26 −6 Original line number Diff line number Diff line Loading @@ -25,8 +25,11 @@ import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.ColorMatrix; import android.graphics.ColorMatrixColorFilter; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.graphics.drawable.DrawableWrapper; Loading Loading @@ -57,13 +60,24 @@ public class UserBadgeDrawable extends DrawableWrapper { private final int mBaseColor; private final int mBgColor; private boolean mShouldDrawBackground = true; @Nullable private Path mShape; private Matrix mShapeMatrix = new Matrix(); @VisibleForTesting public final boolean mIsThemed; public UserBadgeDrawable(Context context, int badgeRes, int colorRes, boolean isThemed) { public UserBadgeDrawable(Context context, int badgeRes, int colorRes, boolean isThemed, @Nullable Path shape) { super(context.getDrawable(badgeRes)); mShape = shape; mShapeMatrix = new Matrix(); if (mShape != null) { mShapeMatrix.setRectToRect(new RectF(0f, 0f, 100f, 100f), new RectF(0f, 0f, CENTER * 2, CENTER * 2), Matrix.ScaleToFit.CENTER); mShape.transform(mShapeMatrix); } mIsThemed = isThemed; if (isThemed) { mutate(); Loading Loading @@ -94,11 +108,17 @@ public class UserBadgeDrawable extends DrawableWrapper { canvas.scale(b.width() / VIEWPORT_SIZE, b.height() / VIEWPORT_SIZE); mPaint.setColor(blendDrawableAlpha(SHADOW_COLOR)); if (mShape != null) { canvas.drawPath(mShape, mPaint); } else { canvas.drawCircle(CENTER, CENTER + SHADOW_OFFSET_Y, SHADOW_RADIUS, mPaint); } mPaint.setColor(blendDrawableAlpha(mBgColor)); if (mShape != null) { canvas.drawPath(mShape, mPaint); } else { canvas.drawCircle(CENTER, CENTER, BG_RADIUS, mPaint); } canvas.restoreToCount(saveCount); } super.draw(canvas); Loading Loading
iconloaderlib/src/com/android/launcher3/icons/BitmapInfo.java +40 −12 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import android.content.Context; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.Canvas; import android.graphics.Path; import android.graphics.drawable.Drawable; import androidx.annotation.IntDef; Loading Loading @@ -153,6 +154,19 @@ public class BitmapInfo { * Creates a drawable for the provided BitmapInfo */ public FastBitmapDrawable newIcon(Context context, @DrawableCreationFlags int creationFlags) { return newIcon(context, creationFlags, null); } /** * Creates a drawable for the provided BitmapInfo * * @param context Context * @param creationFlags Flags for creating the FastBitmapDrawable * @param badgeShape Optional Path for masking icon badges to a shape. Should be 100x100. * @return FastBitmapDrawable */ public FastBitmapDrawable newIcon(Context context, @DrawableCreationFlags int creationFlags, @Nullable Path badgeShape) { FastBitmapDrawable drawable; if (isLowRes()) { drawable = new PlaceHolderIconDrawable(this, context); Loading @@ -161,54 +175,68 @@ public class BitmapInfo { } else { drawable = new FastBitmapDrawable(this); } applyFlags(context, drawable, creationFlags); applyFlags(context, drawable, creationFlags, badgeShape); return drawable; } protected void applyFlags(Context context, FastBitmapDrawable drawable, @DrawableCreationFlags int creationFlags) { @DrawableCreationFlags int creationFlags, @Nullable Path badgeShape) { this.creationFlags = creationFlags; drawable.mDisabledAlpha = GraphicsUtils.getFloat(context, R.attr.disabledIconAlpha, 1f); drawable.mCreationFlags = creationFlags; if ((creationFlags & FLAG_NO_BADGE) == 0) { Drawable badge = getBadgeDrawable(context, (creationFlags & FLAG_THEMED) != 0, (creationFlags & FLAG_SKIP_USER_BADGE) != 0); (creationFlags & FLAG_SKIP_USER_BADGE) != 0, badgeShape); if (badge != null) { drawable.setBadge(badge); } } } public Drawable getBadgeDrawable(Context context, boolean isThemed) { return getBadgeDrawable(context, isThemed, false); /** * Gets Badge drawable based on current flags * @param context Context * @param isThemed If Drawable is themed. * @param badgeShape Optional Path to mask badges to a shape. Should be 100x100. * @return Drawable for the badge. */ public Drawable getBadgeDrawable(Context context, boolean isThemed, @Nullable Path badgeShape) { return getBadgeDrawable(context, isThemed, false, badgeShape); } /** * Returns a drawable representing the badge for this info * Creates a Drawable for an icon badge for this BitmapInfo * @param context Context * @param isThemed If the drawable is themed. * @param skipUserBadge If should skip User Profile badging. * @param badgeShape Optional Path to mask badge Drawable to a shape. Should be 100x100. * @return Drawable for an icon Badge. */ @Nullable private Drawable getBadgeDrawable(Context context, boolean isThemed, boolean skipUserBadge) { private Drawable getBadgeDrawable(Context context, boolean isThemed, boolean skipUserBadge, @Nullable Path badgeShape) { if (badgeInfo != null) { int creationFlag = isThemed ? FLAG_THEMED : 0; if (skipUserBadge) { creationFlag |= FLAG_SKIP_USER_BADGE; } return badgeInfo.newIcon(context, creationFlag); return badgeInfo.newIcon(context, creationFlag, badgeShape); } if (skipUserBadge) { return null; } else if ((flags & FLAG_INSTANT) != 0) { return new UserBadgeDrawable(context, R.drawable.ic_instant_app_badge, R.color.badge_tint_instant, isThemed); R.color.badge_tint_instant, isThemed, badgeShape); } else if ((flags & FLAG_WORK) != 0) { return new UserBadgeDrawable(context, R.drawable.ic_work_app_badge, R.color.badge_tint_work, isThemed); R.color.badge_tint_work, isThemed, badgeShape); } else if ((flags & FLAG_CLONE) != 0) { return new UserBadgeDrawable(context, R.drawable.ic_clone_app_badge, R.color.badge_tint_clone, isThemed); R.color.badge_tint_clone, isThemed, badgeShape); } else if ((flags & FLAG_PRIVATE) != 0) { return new UserBadgeDrawable(context, R.drawable.ic_private_profile_app_badge, R.color.badge_tint_private, isThemed); R.color.badge_tint_private, isThemed, badgeShape); } return null; } Loading
iconloaderlib/src/com/android/launcher3/icons/ClockDrawableWrapper.java +3 −2 Original line number Diff line number Diff line Loading @@ -29,6 +29,7 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Rect; import android.graphics.drawable.AdaptiveIconDrawable; import android.graphics.drawable.ColorDrawable; Loading Loading @@ -283,7 +284,7 @@ public class ClockDrawableWrapper extends AdaptiveIconDrawable implements Bitmap @Override @TargetApi(Build.VERSION_CODES.TIRAMISU) public FastBitmapDrawable newIcon(Context context, @DrawableCreationFlags int creationFlags) { @DrawableCreationFlags int creationFlags, Path badgeShape) { AnimationInfo info; Bitmap bg; int themedFgColor; Loading @@ -308,7 +309,7 @@ public class ClockDrawableWrapper extends AdaptiveIconDrawable implements Bitmap ClockIconDrawable.ClockConstantState cs = new ClockIconDrawable.ClockConstantState( this, themedFgColor, boundsOffset, info, bg, bgFilter); FastBitmapDrawable d = cs.newDrawable(); applyFlags(context, d, creationFlags); applyFlags(context, d, creationFlags, null); return d; } Loading
iconloaderlib/src/com/android/launcher3/icons/GraphicsUtils.java +0 −1 Original line number Diff line number Diff line Loading @@ -31,7 +31,6 @@ import java.io.IOException; public class GraphicsUtils { private static final String TAG = "GraphicsUtils"; private static final float MASK_SIZE = 100f; public static Runnable sOnNewBitmapRunnable = () -> { }; Loading
iconloaderlib/src/com/android/launcher3/icons/UserBadgeDrawable.java +26 −6 Original line number Diff line number Diff line Loading @@ -25,8 +25,11 @@ import android.graphics.Color; import android.graphics.ColorFilter; import android.graphics.ColorMatrix; import android.graphics.ColorMatrixColorFilter; import android.graphics.Matrix; import android.graphics.Paint; import android.graphics.Path; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.graphics.drawable.DrawableWrapper; Loading Loading @@ -57,13 +60,24 @@ public class UserBadgeDrawable extends DrawableWrapper { private final int mBaseColor; private final int mBgColor; private boolean mShouldDrawBackground = true; @Nullable private Path mShape; private Matrix mShapeMatrix = new Matrix(); @VisibleForTesting public final boolean mIsThemed; public UserBadgeDrawable(Context context, int badgeRes, int colorRes, boolean isThemed) { public UserBadgeDrawable(Context context, int badgeRes, int colorRes, boolean isThemed, @Nullable Path shape) { super(context.getDrawable(badgeRes)); mShape = shape; mShapeMatrix = new Matrix(); if (mShape != null) { mShapeMatrix.setRectToRect(new RectF(0f, 0f, 100f, 100f), new RectF(0f, 0f, CENTER * 2, CENTER * 2), Matrix.ScaleToFit.CENTER); mShape.transform(mShapeMatrix); } mIsThemed = isThemed; if (isThemed) { mutate(); Loading Loading @@ -94,11 +108,17 @@ public class UserBadgeDrawable extends DrawableWrapper { canvas.scale(b.width() / VIEWPORT_SIZE, b.height() / VIEWPORT_SIZE); mPaint.setColor(blendDrawableAlpha(SHADOW_COLOR)); if (mShape != null) { canvas.drawPath(mShape, mPaint); } else { canvas.drawCircle(CENTER, CENTER + SHADOW_OFFSET_Y, SHADOW_RADIUS, mPaint); } mPaint.setColor(blendDrawableAlpha(mBgColor)); if (mShape != null) { canvas.drawPath(mShape, mPaint); } else { canvas.drawCircle(CENTER, CENTER, BG_RADIUS, mPaint); } canvas.restoreToCount(saveCount); } super.draw(canvas); Loading