From 90a5f092f19e4cbfc15dff7913fc9650305f5568 Mon Sep 17 00:00:00 2001 From: Hawkwood Glazier Date: Thu, 15 Sep 2022 16:53:33 +0000 Subject: 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 --- .../systemui/media/ColorSchemeTransition.kt | 12 +++++++---- .../android/systemui/media/MediaControlPanel.java | 9 ++++---- .../systemui/media/MediaControlPanelTest.kt | 24 ++++++++++++++++------ 3 files changed, 31 insertions(+), 14 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/media/ColorSchemeTransition.kt b/packages/SystemUI/src/com/android/systemui/media/ColorSchemeTransition.kt index d0826553ad2c..556560c3534c 100644 --- a/packages/SystemUI/src/com/android/systemui/media/ColorSchemeTransition.kt +++ b/packages/SystemUI/src/com/android/systemui/media/ColorSchemeTransition.kt @@ -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 } } diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java index b02393b4f73a..759795f84963 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java +++ b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java @@ -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(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/MediaControlPanelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/MediaControlPanelTest.kt index bef46953395b..7de5719c03ec 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/MediaControlPanelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/MediaControlPanelTest.kt @@ -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 -- cgit v1.2.3-59-g8ed1b