MediaPlayer will now transition the background with color scheme

This change transitions the media player background whenever
the related color scheme has changed. Since the color scheme
is usually generated from the background, it should not trigger
superflous transitions.

Fixes: 246956968
Test: atest MediaControlPanelTest ColorSchemeTransitionTest
Change-Id: I963afcf4ba0fd8c2e9ebca4d634098f63454fab6
This commit is contained in:
Hawkwood Glazier
2022-09-15 16:53:33 +00:00
parent a753bdb1d8
commit 90a5f092f1
3 changed files with 31 additions and 14 deletions

View File

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

View File

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

View File

@@ -591,14 +591,20 @@ public class MediaControlPanelTest : SysuiTestCase() {
@Test
fun bindAlbumView_bitmapInLaterStates_setAfterExecutors() {
val bmp = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bmp)
canvas.drawColor(Color.RED)
val albumArt = Icon.createWithBitmap(bmp)
val redBmp = Bitmap.createBitmap(10, 10, Bitmap.Config.ARGB_8888)
val redCanvas = Canvas(redBmp)
redCanvas.drawColor(Color.RED)
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 state1 = mediaData.copy(artwork = albumArt)
val state2 = mediaData.copy(artwork = albumArt)
val state1 = mediaData.copy(artwork = redArt)
val state2 = mediaData.copy(artwork = redArt)
val state3 = mediaData.copy(artwork = greenArt)
player.attachPlayer(viewHolder)
// First binding sets (empty) drawable
@@ -627,6 +633,12 @@ public class MediaControlPanelTest : SysuiTestCase() {
bgExecutor.runAllReady()
mainExecutor.runAllReady()
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