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

Commit 237ef6c8 authored by Andrew Cole's avatar Andrew Cole
Browse files

Always Return AdaptiveIconDrawable

As part of the legacy icon format cleanup we are making normalizeAndWrapToAdaptiveIcon always return an adaptive icon so no further checks need to be made. We have also removed a optimization here for simplicity that would return the legacy icon if it was square and the icon shape was square.

Bug: 318867282
Flag: None
Test: AllAppsSearchImageTest
Change-Id: Id9bef4b99c618ed34d4d49257faa1e16807e65ed
parent b74f6c83
Loading
Loading
Loading
Loading
+22 −30
Original line number Diff line number Diff line
@@ -62,7 +62,8 @@ public class BaseIconFactory implements AutoCloseable {

    @Retention(SOURCE)
    @IntDef({MODE_DEFAULT, MODE_ALPHA, MODE_WITH_SHADOW, MODE_HARDWARE_WITH_SHADOW, MODE_HARDWARE})
    @interface BitmapGenerationMode {}
    @interface BitmapGenerationMode {
    }

    private static final float ICON_BADGE_SCALE = 0.444f;

@@ -164,7 +165,6 @@ public class BaseIconFactory implements AutoCloseable {
     *
     * @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) {
        AdaptiveIconDrawable drawable = new AdaptiveIconDrawable(
@@ -234,6 +234,7 @@ public class BaseIconFactory implements AutoCloseable {

    /**
     * Returns a monochromatic version of the given drawable or null, if it is not supported
     *
     * @param base the original icon
     */
    @TargetApi(Build.VERSION_CODES.TIRAMISU)
@@ -311,31 +312,18 @@ public class BaseIconFactory implements AutoCloseable {
    }

    @Nullable
    protected Drawable normalizeAndWrapToAdaptiveIcon(@Nullable Drawable icon,
    protected AdaptiveIconDrawable normalizeAndWrapToAdaptiveIcon(@Nullable Drawable icon,
            @Nullable final RectF outIconBounds, @NonNull final float[] outScale) {
        if (icon == null) {
            return null;
        }

        AdaptiveIconDrawable adaptiveIcon;
        float scale;
        if (!(icon instanceof AdaptiveIconDrawable)) {
            EmptyWrapper foreground = new EmptyWrapper();
            AdaptiveIconDrawable dr = new AdaptiveIconDrawable(
                    new ColorDrawable(mWrapperBackgroundColor), foreground);
            dr.setBounds(0, 0, 1, 1);
            boolean[] outShape = new boolean[1];
            scale = getNormalizer().getScale(icon, outIconBounds, dr.getIconMask(), outShape);
            if (!outShape[0]) {
                foreground.setDrawable(createScaledDrawable(icon, scale * LEGACY_ICON_SCALE));
                icon = dr;
                scale = getNormalizer().getScale(icon, outIconBounds, null, null);
            }
        } else {
            scale = getNormalizer().getScale(icon, outIconBounds, null, null);
        }

        adaptiveIcon = wrapToAdaptiveIcon(icon, outIconBounds);
        scale = getNormalizer().getScale(adaptiveIcon, outIconBounds, null, null);
        outScale[0] = scale;
        return icon;
        return adaptiveIcon;
    }

    /**
@@ -359,7 +347,8 @@ public class BaseIconFactory implements AutoCloseable {
    /**
     * Wraps the provided icon in an adaptive icon drawable
     */
    public AdaptiveIconDrawable wrapToAdaptiveIcon(@NonNull Drawable icon) {
    public AdaptiveIconDrawable wrapToAdaptiveIcon(@NonNull Drawable icon,
            @Nullable final RectF outIconBounds) {
        if (icon instanceof AdaptiveIconDrawable aid) {
            return aid;
        } else {
@@ -368,7 +357,7 @@ public class BaseIconFactory implements AutoCloseable {
                    new ColorDrawable(mWrapperBackgroundColor), foreground);
            dr.setBounds(0, 0, 1, 1);
            boolean[] outShape = new boolean[1];
            float scale = getNormalizer().getScale(icon, null, dr.getIconMask(), outShape);
            float scale = getNormalizer().getScale(icon, outIconBounds, dr.getIconMask(), outShape);
            if (!outShape[0]) {
                foreground.setDrawable(createScaledDrawable(icon, scale * LEGACY_ICON_SCALE));
            } else {
@@ -418,7 +407,8 @@ public class BaseIconFactory implements AutoCloseable {
        mOldBounds.set(icon.getBounds());

        if (icon instanceof AdaptiveIconDrawable) {
            // We are ignoring KEY_SHADOW_DISTANCE because regular icons ignore this at the moment b/298203449
            // We are ignoring KEY_SHADOW_DISTANCE because regular icons ignore this at the
            // moment b/298203449
            int offset = Math.max((int) Math.ceil(BLUR_FACTOR * size),
                    Math.round(size * (1 - scale) / 2));
            // b/211896569: AdaptiveIconDrawable do not work properly for non top-left bounds
@@ -512,12 +502,14 @@ public class BaseIconFactory implements AutoCloseable {
        @BitmapGenerationMode
        int mGenerationMode = MODE_WITH_SHADOW;

        @Nullable UserHandle mUserHandle;
        @Nullable
        UserHandle mUserHandle;
        @Nullable
        UserIconInfo mUserIconInfo;

        @ColorInt
        @Nullable Integer mExtractedColor;
        @Nullable
        Integer mExtractedColor;


        /**