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

Commit c8aaae9e authored by Andrew Cole's avatar Andrew Cole Committed by Android (Google) Code Review
Browse files

Merge "Always Return AdaptiveIconDrawable" into main

parents e5041f55 237ef6c8
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;


        /**