diff options
Diffstat (limited to 'iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java')
-rw-r--r-- | iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java | 76 |
1 files changed, 3 insertions, 73 deletions
diff --git a/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java b/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java index 9ce9975..31a923e 100644 --- a/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java +++ b/iconloaderlib/src/com/android/launcher3/icons/BaseIconFactory.java @@ -12,7 +12,6 @@ import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.Color; -import android.graphics.Paint; import android.graphics.PaintFlagsDrawFilter; import android.graphics.Rect; import android.graphics.RectF; @@ -20,15 +19,12 @@ import android.graphics.drawable.AdaptiveIconDrawable; import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; -import android.graphics.drawable.InsetDrawable; import android.os.Build; import android.os.Process; import android.os.UserHandle; import androidx.annotation.NonNull; -import com.android.launcher3.icons.BitmapInfo.Extender; - /** * This class will be moved to androidx library. There shouldn't be any dependency outside * this package. @@ -59,11 +55,6 @@ public class BaseIconFactory implements AutoCloseable { private Drawable mWrapperIcon; private int mWrapperBackgroundColor = DEFAULT_WRAPPER_BACKGROUND; - private Bitmap mUserBadgeBitmap; - - private final Paint mTextPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.FILTER_BITMAP_FLAG); - private static final float PLACEHOLDER_TEXT_SIZE = 20f; - private static int PLACEHOLDER_BACKGROUND_COLOR = Color.rgb(240, 240, 240); protected BaseIconFactory(Context context, int fillResIconDpi, int iconBitmapSize, boolean shapeDetection) { @@ -77,14 +68,10 @@ public class BaseIconFactory implements AutoCloseable { mCanvas = new Canvas(); mCanvas.setDrawFilter(new PaintFlagsDrawFilter(DITHER_FLAG, FILTER_BITMAP_FLAG)); - mTextPaint.setTextAlign(Paint.Align.CENTER); - mTextPaint.setColor(PLACEHOLDER_BACKGROUND_COLOR); - mTextPaint.setTextSize(context.getResources().getDisplayMetrics().density * - PLACEHOLDER_TEXT_SIZE); clear(); } - public BaseIconFactory(Context context, int fillResIconDpi, int iconBitmapSize) { + protected BaseIconFactory(Context context, int fillResIconDpi, int iconBitmapSize) { this(context, fillResIconDpi, iconBitmapSize, false); } @@ -126,28 +113,6 @@ public class BaseIconFactory implements AutoCloseable { return null; } - /** - * Create a placeholder icon using the passed in text. - * - * @param placeholder used for foreground element in the icon bitmap - * @param color used for the foreground text color - * @return - */ - public BitmapInfo createIconBitmap(String placeholder, int color) { - if (!ATLEAST_OREO) return null; - - Bitmap placeholderBitmap = Bitmap.createBitmap(mIconBitmapSize, mIconBitmapSize, - Bitmap.Config.ARGB_8888); - mTextPaint.setColor(color); - Canvas canvas = new Canvas(placeholderBitmap); - canvas.drawText(placeholder, mIconBitmapSize / 2, mIconBitmapSize * 5 / 8, mTextPaint); - AdaptiveIconDrawable drawable = new AdaptiveIconDrawable( - new ColorDrawable(PLACEHOLDER_BACKGROUND_COLOR), - new BitmapDrawable(mContext.getResources(), placeholderBitmap)); - Bitmap icon = createIconBitmap(drawable, 1f); - return BitmapInfo.of(icon, extractColor(icon)); - } - public BitmapInfo createIconBitmap(Bitmap icon) { if (mIconBitmapSize != icon.getWidth() || mIconBitmapSize != icon.getHeight()) { icon = createIconBitmap(new BitmapDrawable(mContext.getResources(), icon), 1f); @@ -156,20 +121,6 @@ public class BaseIconFactory implements AutoCloseable { return BitmapInfo.of(icon, extractColor(icon)); } - /** - * Creates an icon from the bitmap cropped to the current device icon shape - */ - public BitmapInfo createShapedIconBitmap(Bitmap icon, UserHandle user) { - Drawable d = new FixedSizeBitmapDrawable(icon); - if (ATLEAST_OREO) { - float inset = AdaptiveIconDrawable.getExtraInsetFraction(); - inset = inset / (1 + 2 * inset); - d = new AdaptiveIconDrawable(new ColorDrawable(Color.BLACK), - new InsetDrawable(d, inset, inset, inset, inset)); - } - return createBadgedIconBitmap(d, user, true); - } - public BitmapInfo createBadgedIconBitmap(Drawable icon, UserHandle user, boolean shrinkNonAdaptiveIcons) { return createBadgedIconBitmap(icon, user, shrinkNonAdaptiveIcons, false, null); @@ -236,27 +187,10 @@ public class BaseIconFactory implements AutoCloseable { } int color = extractColor(bitmap); return icon instanceof BitmapInfo.Extender - ? ((BitmapInfo.Extender) icon).getExtendedInfo(bitmap, color, this, scale[0], user) + ? ((BitmapInfo.Extender) icon).getExtendedInfo(bitmap, color, this) : BitmapInfo.of(bitmap, color); } - public Bitmap getUserBadgeBitmap(UserHandle user) { - if (mUserBadgeBitmap == null) { - Bitmap bitmap = Bitmap.createBitmap( - mIconBitmapSize, mIconBitmapSize, Bitmap.Config.ARGB_8888); - Drawable badgedDrawable = mPm.getUserBadgedIcon( - new FixedSizeBitmapDrawable(bitmap), user); - if (badgedDrawable instanceof BitmapDrawable) { - mUserBadgeBitmap = ((BitmapDrawable) badgedDrawable).getBitmap(); - } else { - badgedDrawable.setBounds(0, 0, mIconBitmapSize, mIconBitmapSize); - mUserBadgeBitmap = BitmapRenderer.createSoftwareBitmap( - mIconBitmapSize, mIconBitmapSize, badgedDrawable::draw); - } - } - return mUserBadgeBitmap; - } - public Bitmap createScaledBitmapWithoutShadow(Drawable icon, boolean shrinkNonAdaptiveIcons) { RectF iconBounds = new RectF(); float[] scale = new float[1]; @@ -362,11 +296,7 @@ public class BaseIconFactory implements AutoCloseable { int offset = Math.max((int) Math.ceil(BLUR_FACTOR * size), Math.round(size * (1 - scale) / 2 )); icon.setBounds(offset, offset, size - offset, size - offset); - if (icon instanceof BitmapInfo.Extender) { - ((Extender) icon).drawForPersistence(mCanvas); - } else { - icon.draw(mCanvas); - } + icon.draw(mCanvas); } else { if (icon instanceof BitmapDrawable) { BitmapDrawable bitmapDrawable = (BitmapDrawable) icon; |