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

Commit 41ea86f6 authored by Lucas Dupin's avatar Lucas Dupin
Browse files

Fix issue where line alpha would be overridden

A Paint doesn't have separate components for color and alpha, so when
setting a color, the alpha will be lost.

We need to take that into account when updating the tint.

Test: manual
Test: atest SquigglyProgressTest
Fixes: 227388771
Change-Id: Ibb85305a01c552c1476e502d23614de097f4680c
parent 74807869
Loading
Loading
Loading
Loading
+10 −6
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ import android.graphics.PixelFormat
import android.graphics.drawable.Drawable
import android.os.SystemClock
import androidx.annotation.VisibleForTesting
import com.android.internal.graphics.ColorUtils
import com.android.systemui.animation.Interpolators
import kotlin.math.abs
import kotlin.math.cos
@@ -157,8 +158,7 @@ class SquigglyProgress : Drawable() {
    }

    override fun setAlpha(alpha: Int) {
        wavePaint.alpha = alpha
        linePaint.alpha = (DISABLED_ALPHA * (alpha / 255f)).toInt()
        updateColors(wavePaint.color, alpha)
    }

    override fun getAlpha(): Int {
@@ -166,8 +166,7 @@ class SquigglyProgress : Drawable() {
    }

    override fun setTint(tintColor: Int) {
        wavePaint.color = tintColor
        linePaint.color = tintColor
        updateColors(tintColor, alpha)
    }

    override fun onLevelChange(level: Int): Boolean {
@@ -178,7 +177,12 @@ class SquigglyProgress : Drawable() {
        if (tint == null) {
            return
        }
        wavePaint.color = tint.defaultColor
        linePaint.color = tint.defaultColor
        updateColors(tint.defaultColor, alpha)
    }

    private fun updateColors(tintColor: Int, alpha: Int) {
        wavePaint.color = ColorUtils.setAlphaComponent(tintColor, alpha)
        linePaint.color = ColorUtils.setAlphaComponent(tintColor,
                (DISABLED_ALPHA * (alpha / 255f)).toInt())
    }
}
 No newline at end of file
+3 −1
Original line number Diff line number Diff line
@@ -8,6 +8,7 @@ import android.graphics.Rect
import android.testing.AndroidTestingRunner
import android.testing.TestableLooper
import androidx.test.filters.SmallTest
import com.android.internal.graphics.ColorUtils
import com.android.systemui.SysuiTestCase
import com.android.systemui.util.mockito.any
import com.google.common.truth.Truth.assertThat
@@ -113,6 +114,7 @@ class SquigglyProgressTest : SysuiTestCase() {
                linePaintCaptor.capture())

        assertThat(wavePaintCaptor.value.color).isEqualTo(tint)
        assertThat(linePaintCaptor.value.color).isEqualTo(tint)
        assertThat(linePaintCaptor.value.color).isEqualTo(
                ColorUtils.setAlphaComponent(tint, DISABLED_ALPHA))
    }
}
 No newline at end of file