Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4741d5b7 authored by PeterCxy's avatar PeterCxy Committed by Andy Mast
Browse files

IconPackHelper: Respect the original size of bitmap icons

When use icon packs on low-resolution devices, for example, my HDPI
phone, it seems that using the size returned by
getLauncherLargeIconSize() will cause a blurness on
some icons that are not included in the icon pack because of the compose
function.

This patch respects the original size of the icon if the icon is an
instance of BitmapDrawable but use the size returned by
getLauncherLargeIconSize() if the icon is an instance of PaintDrawable.
This will remove icon blurness on low-resolution devices.

Change-Id: Ifcb39020d934a9c7cb409e1206a179d64f99aa37
parent 36672e70
Loading
Loading
Loading
Loading
+14 −3
Original line number Diff line number Diff line
@@ -479,10 +479,15 @@ public class IconPackHelper {
            canvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.ANTI_ALIAS_FLAG,
                    Paint.FILTER_BITMAP_FLAG));

            int width = 0, height = 0;
            if (icon instanceof PaintDrawable) {
                PaintDrawable painter = (PaintDrawable) icon;
                painter.setIntrinsicWidth(iconSize);
                painter.setIntrinsicHeight(iconSize);

                // A PaintDrawable does not have an exact size
                width = iconSize;
                height = iconSize;
            } else if (icon instanceof BitmapDrawable) {
                // Ensure the bitmap has a density.
                BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
@@ -491,18 +496,24 @@ public class IconPackHelper {
                    bitmapDrawable.setTargetDensity(res.getDisplayMetrics());
                }
                canvas.setDensity(bitmap.getDensity());

                // Respect the original size of an icon
                width = bitmap.getWidth();
                height = bitmap.getHeight();
            }

            Bitmap bitmap = Bitmap.createBitmap(iconSize, iconSize,
            if (width <= 0 || height <= 0) return null;

            Bitmap bitmap = Bitmap.createBitmap(width, height,
                    Bitmap.Config.ARGB_8888);
            canvas.setBitmap(bitmap);

            // Scale the original
            Rect oldBounds = new Rect();
            oldBounds.set(icon.getBounds());
            icon.setBounds(0, 0, iconSize, iconSize);
            icon.setBounds(0, 0, width, height);
            canvas.save();
            canvas.scale(scale, scale, iconSize / 2, iconSize / 2);
            canvas.scale(scale, scale, width / 2, height / 2);
            icon.draw(canvas);
            canvas.restore();