Merge "ColorSchemeTransition now updates the ripple color" into tm-dev

This commit is contained in:
TreeHugger Robot
2022-05-03 03:46:07 +00:00
committed by Android (Google) Code Review
3 changed files with 19 additions and 3 deletions

View File

@@ -22,6 +22,7 @@ import android.animation.ValueAnimator
import android.content.Context import android.content.Context
import android.content.res.ColorStateList import android.content.res.ColorStateList
import android.graphics.drawable.GradientDrawable import android.graphics.drawable.GradientDrawable
import android.graphics.drawable.RippleDrawable
import com.android.internal.R import com.android.internal.R
import com.android.internal.annotations.VisibleForTesting import com.android.internal.annotations.VisibleForTesting
import com.android.settingslib.Utils import com.android.settingslib.Utils
@@ -38,7 +39,7 @@ interface ColorTransition {
/** A generic implementation of [ColorTransition] so that we can define a factory method. */ /** A generic implementation of [ColorTransition] so that we can define a factory method. */
open class GenericColorTransition( open class GenericColorTransition(
private val applyTheme: (ColorScheme?) -> Unit private val applyTheme: (ColorScheme?) -> Unit
) : ColorTransition { ) : ColorTransition {
override fun updateColorScheme(scheme: ColorScheme?) = applyTheme(scheme) override fun updateColorScheme(scheme: ColorScheme?) = applyTheme(scheme)
} }
@@ -130,8 +131,19 @@ class ColorSchemeTransition internal constructor(
) { accentPrimary -> ) { accentPrimary ->
val accentColorList = ColorStateList.valueOf(accentPrimary) val accentColorList = ColorStateList.valueOf(accentPrimary)
mediaViewHolder.actionPlayPause.backgroundTintList = accentColorList mediaViewHolder.actionPlayPause.backgroundTintList = accentColorList
mediaViewHolder.seamlessButton.backgroundTintList = accentColorList
mediaViewHolder.gutsViewHolder.setAccentPrimaryColor(accentPrimary) mediaViewHolder.gutsViewHolder.setAccentPrimaryColor(accentPrimary)
mediaViewHolder.seamlessButton.backgroundTintList = accentColorList
}
val accentSecondary = animatingColorTransitionFactory(
loadDefaultColor(R.attr.textColorPrimary),
::accentSecondaryFromScheme
) { accentSecondary ->
val colorList = ColorStateList.valueOf(accentSecondary)
(mediaViewHolder.seamlessButton.background as? RippleDrawable)?.let {
it.setColor(colorList)
it.effectColor = colorList
}
} }
val textPrimary = animatingColorTransitionFactory( val textPrimary = animatingColorTransitionFactory(
@@ -203,6 +215,7 @@ class ColorSchemeTransition internal constructor(
val colorTransitions = arrayOf( val colorTransitions = arrayOf(
surfaceColor, surfaceColor,
accentPrimary, accentPrimary,
accentSecondary,
textPrimary, textPrimary,
textPrimaryInverse, textPrimaryInverse,
textSecondary, textSecondary,

View File

@@ -24,6 +24,9 @@ internal fun surfaceFromScheme(scheme: ColorScheme) = scheme.accent2[9] // A2-80
/** Returns the primary accent color for media controls based on the scheme. */ /** Returns the primary accent color for media controls based on the scheme. */
internal fun accentPrimaryFromScheme(scheme: ColorScheme) = scheme.accent1[2] // A1-100 internal fun accentPrimaryFromScheme(scheme: ColorScheme) = scheme.accent1[2] // A1-100
/** Returns the secondary accent color for media controls based on the scheme. */
internal fun accentSecondaryFromScheme(scheme: ColorScheme) = scheme.accent1[3] // A1-200
/** Returns the primary text color for media controls based on the scheme. */ /** Returns the primary text color for media controls based on the scheme. */
internal fun textPrimaryFromScheme(scheme: ColorScheme) = scheme.neutral1[1] // N1-50 internal fun textPrimaryFromScheme(scheme: ColorScheme) = scheme.neutral1[1] // N1-50

View File

@@ -149,7 +149,7 @@ class ColorSchemeTransitionTest : SysuiTestCase() {
@Test @Test
fun testColorSchemeTransition_update() { fun testColorSchemeTransition_update() {
colorSchemeTransition.updateColorScheme(colorScheme) colorSchemeTransition.updateColorScheme(colorScheme)
verify(mockAnimatingTransition, times(6)).updateColorScheme(colorScheme) verify(mockAnimatingTransition, times(7)).updateColorScheme(colorScheme)
verify(mockGenericTransition).updateColorScheme(colorScheme) verify(mockGenericTransition).updateColorScheme(colorScheme)
} }
} }