Merge "MediaPlayer will now transition the background with color scheme" into tm-dev

This commit is contained in:
Hawkwood Glazier
2022-12-07 23:15:07 +00:00
committed by Android (Google) Code Review
3 changed files with 32 additions and 14 deletions

View File

@@ -37,7 +37,7 @@ import com.android.systemui.util.getColorWithAlpha
* is triggered. * is triggered.
*/ */
interface ColorTransition { interface ColorTransition {
fun updateColorScheme(scheme: ColorScheme?) fun updateColorScheme(scheme: ColorScheme?): Boolean
} }
/** /**
@@ -67,14 +67,16 @@ open class AnimatingColorTransition(
applyColor(currentColor) applyColor(currentColor)
} }
override fun updateColorScheme(scheme: ColorScheme?) { override fun updateColorScheme(scheme: ColorScheme?): Boolean {
val newTargetColor = if (scheme == null) defaultColor else extractColor(scheme) val newTargetColor = if (scheme == null) defaultColor else extractColor(scheme)
if (newTargetColor != targetColor) { if (newTargetColor != targetColor) {
sourceColor = currentColor sourceColor = currentColor
targetColor = newTargetColor targetColor = newTargetColor
valueAnimator.cancel() valueAnimator.cancel()
valueAnimator.start() valueAnimator.start()
return true
} }
return false
} }
init { init {
@@ -235,9 +237,11 @@ class ColorSchemeTransition internal constructor(
return Utils.getColorAttr(context, id).defaultColor return Utils.getColorAttr(context, id).defaultColor
} }
fun updateColorScheme(colorScheme: ColorScheme?, enableGradient: Boolean) { fun updateColorScheme(colorScheme: ColorScheme?, enableGradient: Boolean): Boolean {
isGradientEnabled = enableGradient isGradientEnabled = enableGradient
colorTransitions.forEach { it.updateColorScheme(colorScheme) } var anyChanged = false
colorTransitions.forEach { anyChanged = it.updateColorScheme(colorScheme) || anyChanged }
colorScheme?.let { mediaViewHolder.gutsViewHolder.colorScheme = colorScheme } colorScheme?.let { mediaViewHolder.gutsViewHolder.colorScheme = colorScheme }
return anyChanged
} }
} }

View File

@@ -673,10 +673,15 @@ public class MediaControlPanel {
} }
mArtworkBoundId = reqId; mArtworkBoundId = reqId;
// Transition Colors to current color scheme
boolean colorSchemeChanged = mColorSchemeTransition
.updateColorScheme(colorScheme, isArtworkBound);
// Bind the album view to the artwork or a transition drawable // Bind the album view to the artwork or a transition drawable
ImageView albumView = mMediaViewHolder.getAlbumView(); ImageView albumView = mMediaViewHolder.getAlbumView();
albumView.setPadding(0, 0, 0, 0); albumView.setPadding(0, 0, 0, 0);
if (updateBackground || (!mIsArtworkBound && isArtworkBound)) { if (updateBackground || colorSchemeChanged
|| (!mIsArtworkBound && isArtworkBound)) {
if (mPrevArtwork == null) { if (mPrevArtwork == null) {
albumView.setImageDrawable(artwork); albumView.setImageDrawable(artwork);
} else { } else {
@@ -699,9 +704,6 @@ public class MediaControlPanel {
mIsArtworkBound = isArtworkBound; mIsArtworkBound = isArtworkBound;
} }
// Transition Colors to current color scheme
mColorSchemeTransition.updateColorScheme(colorScheme, mIsArtworkBound);
// App icon - use notification icon // App icon - use notification icon
ImageView appIconView = mMediaViewHolder.getAppIcon(); ImageView appIconView = mMediaViewHolder.getAppIcon();
appIconView.clearColorFilter(); appIconView.clearColorFilter();

View File

@@ -577,14 +577,20 @@ public class MediaControlPanelTest : SysuiTestCase() {
@Test @Test
fun bindAlbumView_bitmapInLaterStates_setAfterExecutors() { fun bindAlbumView_bitmapInLaterStates_setAfterExecutors() {
val bmp = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888) val redBmp = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bmp) val redCanvas = Canvas(redBmp)
canvas.drawColor(Color.RED) redCanvas.drawColor(Color.RED)
val albumArt = Icon.createWithBitmap(bmp) val redArt = Icon.createWithBitmap(redBmp)
val greenBmp = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888)
val greenCanvas = Canvas(greenBmp)
greenCanvas.drawColor(Color.GREEN)
val greenArt = Icon.createWithBitmap(greenBmp)
val state0 = mediaData.copy(artwork = null) val state0 = mediaData.copy(artwork = null)
val state1 = mediaData.copy(artwork = albumArt) val state1 = mediaData.copy(artwork = redArt)
val state2 = mediaData.copy(artwork = albumArt) val state2 = mediaData.copy(artwork = redArt)
val state3 = mediaData.copy(artwork = greenArt)
player.attachPlayer(viewHolder) player.attachPlayer(viewHolder)
// First binding sets (empty) drawable // First binding sets (empty) drawable
@@ -613,6 +619,12 @@ public class MediaControlPanelTest : SysuiTestCase() {
bgExecutor.runAllReady() bgExecutor.runAllReady()
mainExecutor.runAllReady() mainExecutor.runAllReady()
verify(albumView, times(2)).setImageDrawable(any(Drawable::class.java)) verify(albumView, times(2)).setImageDrawable(any(Drawable::class.java))
// Fourth binding to new image runs transition due to color scheme change
player.bindPlayer(state3, PACKAGE)
bgExecutor.runAllReady()
mainExecutor.runAllReady()
verify(albumView, times(3)).setImageDrawable(any(Drawable::class.java))
} }
@Test @Test