Merge "Fix issue where line alpha would be overridden" into tm-dev

This commit is contained in:
Lucas Dupin
2022-03-30 16:33:45 +00:00
committed by Android (Google) Code Review
2 changed files with 13 additions and 7 deletions

View File

@@ -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())
}
}

View File

@@ -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))
}
}