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

Commit 22884d2f authored by Charlie Anderson's avatar Charlie Anderson
Browse files

Ensure pre-archived bitmaps are converted to Adaptive Icons without cropping by adding insets

Bug: 358123888
Test: locally testing B&R with pre-archiving
Flag: com.android.launcher3.use_new_icon_for_archived_apps
Change-Id: I6852c1367e9bc1156e57394323d8cd9f63ad5c95
parent 1d34c94a
Loading
Loading
Loading
Loading
+16 −6
Original line number Diff line number Diff line
@@ -186,13 +186,12 @@ public class BaseIconFactory implements AutoCloseable {
     * Creates an icon from the bitmap cropped to the current device icon shape
     */
    @NonNull
    public BitmapInfo createShapedIconBitmap(Bitmap icon, IconOptions options) {
        Drawable d = new FixedSizeBitmapDrawable(icon);
    public AdaptiveIconDrawable createShapedAdaptiveIcon(Bitmap iconBitmap) {
        Drawable drawable = new FixedSizeBitmapDrawable(iconBitmap);
        float inset = getExtraInsetFraction();
        inset = inset / (1 + 2 * inset);
        d = new AdaptiveIconDrawable(new ColorDrawable(Color.BLACK),
                new InsetDrawable(d, inset, inset, inset, inset));
        return createBadgedIconBitmap(d, options);
        return new AdaptiveIconDrawable(new ColorDrawable(Color.BLACK),
                new InsetDrawable(drawable, inset, inset, inset, inset));
    }

    @NonNull
@@ -212,7 +211,16 @@ public class BaseIconFactory implements AutoCloseable {
    public BitmapInfo createBadgedIconBitmap(@NonNull Drawable icon,
            @Nullable IconOptions options) {
        float[] scale = new float[1];
        AdaptiveIconDrawable adaptiveIcon = normalizeAndWrapToAdaptiveIcon(icon, null, scale);
        Drawable tempIcon = icon;
        if (options != null
                && options.mIsArchived
                && icon instanceof BitmapDrawable bitmapDrawable) {
            // b/358123888
            // Pre-archived apps can have BitmapDrawables without insets.
            // Need to convert to Adaptive Icon with insets to avoid cropping.
            tempIcon = createShapedAdaptiveIcon(bitmapDrawable.getBitmap());
        }
        AdaptiveIconDrawable adaptiveIcon = normalizeAndWrapToAdaptiveIcon(tempIcon, null, scale);
        Bitmap bitmap = createIconBitmap(adaptiveIcon, scale[0],
                options == null ? MODE_WITH_SHADOW : options.mGenerationMode);

@@ -497,6 +505,8 @@ public class BaseIconFactory implements AutoCloseable {

        boolean mIsInstantApp;

        boolean mIsArchived;

        @BitmapGenerationMode
        int mGenerationMode = MODE_WITH_SHADOW;

+4 −1
Original line number Diff line number Diff line
@@ -541,7 +541,10 @@ public abstract class BaseIconCache {
        }
        if (icon != null) {
            BaseIconFactory li = getIconFactory();
            entry.bitmap = li.createShapedIconBitmap(icon, new IconOptions().setUser(user));
            entry.bitmap = li.createBadgedIconBitmap(
                    li.createShapedAdaptiveIcon(icon),
                    new IconOptions().setUser(user)
            );
            li.close();
        }
        if (!TextUtils.isEmpty(title) && entry.bitmap.icon != null) {