Merge "MediaPlayer will now transition the background with color scheme" into tm-qpr-dev am: bd92f05e66

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/19967536

Change-Id: I54bbc4a7761d999c195e4b9a8fd6fd5bfd4f70a1
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Hawkwood Glazier
2022-09-19 17:07:47 +00:00
committed by Automerger Merge Worker
3 changed files with 31 additions and 14 deletions

View File

@@ -34,7 +34,7 @@ import com.android.systemui.monet.ColorScheme
* is triggered. * is triggered.
*/ */
interface ColorTransition { interface ColorTransition {
fun updateColorScheme(scheme: ColorScheme?) fun updateColorScheme(scheme: ColorScheme?): Boolean
} }
/** /**
@@ -64,14 +64,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 {
@@ -198,8 +200,10 @@ class ColorSchemeTransition internal constructor(
return Utils.getColorAttr(context, id).defaultColor return Utils.getColorAttr(context, id).defaultColor
} }
fun updateColorScheme(colorScheme: ColorScheme?) { fun updateColorScheme(colorScheme: ColorScheme?): Boolean {
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

@@ -741,10 +741,14 @@ public class MediaControlPanel {
} }
mArtworkBoundId = reqId; mArtworkBoundId = reqId;
// Transition Colors to current color scheme
boolean colorSchemeChanged = mColorSchemeTransition.updateColorScheme(colorScheme);
// 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 {
@@ -767,9 +771,6 @@ public class MediaControlPanel {
mIsArtworkBound = isArtworkBound; mIsArtworkBound = isArtworkBound;
} }
// Transition Colors to current color scheme
mColorSchemeTransition.updateColorScheme(colorScheme);
// App icon - use notification icon // App icon - use notification icon
ImageView appIconView = mMediaViewHolder.getAppIcon(); ImageView appIconView = mMediaViewHolder.getAppIcon();
appIconView.clearColorFilter(); appIconView.clearColorFilter();

View File

@@ -591,14 +591,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
@@ -627,6 +633,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