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

Commit aedb3b8c authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix shaping of themed icons" into main

parents d015ca58 58974141
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -231,8 +231,14 @@ public class BaseIconFactory implements AutoCloseable {
        if (adaptiveIcon instanceof Extender extender) {
            info = extender.getExtendedInfo(bitmap, color, this, scale[0]);
        } else if (IconProvider.ATLEAST_T && mThemeController != null && adaptiveIcon != null) {
            info.setThemedBitmap(mThemeController.createThemedBitmap(
                    adaptiveIcon, info, this, options == null ? null : options.mSourceHint));
            info.setThemedBitmap(
                    mThemeController.createThemedBitmap(
                        adaptiveIcon,
                        info,
                        this,
                        options == null ? null : options.mSourceHint
                    )
            );
        }
        info = info.withFlags(getBitmapFlagOp(options));
        return info;
@@ -276,10 +282,14 @@ public class BaseIconFactory implements AutoCloseable {
    }

    @NonNull
    protected Path getShapePath(AdaptiveIconDrawable drawable, Rect iconBounds) {
    public Path getShapePath(AdaptiveIconDrawable drawable, Rect iconBounds) {
        return drawable.getIconMask();
    }

    public float getIconScale() {
        return 1f;
    }

    @NonNull
    public Bitmap getWhiteShadowLayer() {
        if (mWhiteShadowLayer == null) {
+3 −2
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.graphics.ColorFilter;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.drawable.AdaptiveIconDrawable;
@@ -99,12 +100,12 @@ public class MonochromeIconFactory extends Drawable {
     * Creates a monochrome version of the provided drawable
     */
    @WorkerThread
    public Drawable wrap(AdaptiveIconDrawable icon) {
    public Drawable wrap(AdaptiveIconDrawable icon, Path shapePath, Float iconScale) {
        mFlatCanvas.drawColor(Color.BLACK);
        drawDrawable(icon.getBackground());
        drawDrawable(icon.getForeground());
        generateMono();
        return new ClippedMonoDrawable(this);
        return new ClippedMonoDrawable(this, shapePath, iconScale);
    }

    @WorkerThread
+21 −9
Original line number Diff line number Diff line
@@ -24,7 +24,8 @@ import android.graphics.Bitmap.Config.HARDWARE
import android.graphics.BlendMode.SRC_IN
import android.graphics.BlendModeColorFilter
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Path
import android.graphics.Rect
import android.graphics.drawable.AdaptiveIconDrawable
import android.graphics.drawable.BitmapDrawable
import android.graphics.drawable.ColorDrawable
@@ -55,7 +56,14 @@ class MonoIconThemeController(
        factory: BaseIconFactory,
        sourceHint: SourceHint?,
    ): ThemedBitmap? {
        val mono = getMonochromeDrawable(icon, info, sourceHint?.isFileDrawable ?: false)
        val mono =
            getMonochromeDrawable(
                icon,
                info,
                factory.getShapePath(icon, Rect(0, 0, info.icon.width, info.icon.height)),
                factory.iconScale,
                sourceHint?.isFileDrawable ?: false,
            )
        if (mono != null) {
            return MonoThemedBitmap(
                factory.createIconBitmap(mono, ICON_VISIBLE_AREA_FACTOR, MODE_ALPHA),
@@ -74,14 +82,16 @@ class MonoIconThemeController(
    private fun getMonochromeDrawable(
        base: AdaptiveIconDrawable,
        info: BitmapInfo,
        shapePath: Path,
        iconScale: Float,
        isFileDrawable: Boolean,
    ): Drawable? {
        val mono = base.monochrome
        if (mono != null) {
            return ClippedMonoDrawable(mono)
            return ClippedMonoDrawable(mono, shapePath, iconScale)
        }
        if (Flags.forceMonochromeAppIcons() && !isFileDrawable) {
            return MonochromeIconFactory(info.icon.width).wrap(base)
            return MonochromeIconFactory(info.icon.width).wrap(base, shapePath, iconScale)
        }
        return null
    }
@@ -136,14 +146,16 @@ class MonoIconThemeController(
        return monoDrawable?.let { AdaptiveIconDrawable(ColorDrawable(colors[0]), it) }
    }

    class ClippedMonoDrawable(base: Drawable?) :
        InsetDrawable(base, -AdaptiveIconDrawable.getExtraInsetFraction()) {
        private val mCrop = AdaptiveIconDrawable(ColorDrawable(Color.BLACK), null)
    class ClippedMonoDrawable(
        base: Drawable?,
        private val shapePath: Path,
        private val iconScale: Float,
    ) : InsetDrawable(base, -AdaptiveIconDrawable.getExtraInsetFraction()) {

        override fun draw(canvas: Canvas) {
            mCrop.bounds = bounds
            val saveCount = canvas.save()
            canvas.clipPath(mCrop.iconMask)
            canvas.clipPath(shapePath)
            canvas.scale(iconScale, iconScale, canvas.width / 2f, canvas.height / 2f)
            super.draw(canvas)
            canvas.restoreToCount(saveCount)
        }