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

Commit 480028b1 authored by Sihua Ma's avatar Sihua Ma
Browse files

Fix an issue where forced theme icon will show blank

The icon mask of the drawable would not be ready until the bounds are
set

Test: Manual
Flag: com.android.launcher3.enable_launcher_icon_shapes
Bug: 399665497
Bug: 399666950
Change-Id: I337ffdb537605c3ea898d0aa972f450322acefe1
parent d2fbea88
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ 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
@@ -151,11 +152,18 @@ class MonoIconThemeController(
        private val shapePath: Path,
        private val iconScale: Float,
    ) : InsetDrawable(base, -AdaptiveIconDrawable.getExtraInsetFraction()) {
        // TODO(b/399666950): remove this after launcher icon shapes is fully enabled
        private val mCrop = AdaptiveIconDrawable(ColorDrawable(Color.BLACK), null)

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