Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3a2ffd7e authored by Hawkwood Glazier's avatar Hawkwood Glazier Committed by Android (Google) Code Review
Browse files

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

parents 63d803e6 50f82cd8
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ import com.android.systemui.util.getColorWithAlpha
 * is triggered.
 */
interface ColorTransition {
    fun updateColorScheme(scheme: ColorScheme?)
    fun updateColorScheme(scheme: ColorScheme?): Boolean
}

/**
@@ -67,14 +67,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 {
@@ -235,9 +237,11 @@ class ColorSchemeTransition internal constructor(
        return Utils.getColorAttr(context, id).defaultColor
    }

    fun updateColorScheme(colorScheme: ColorScheme?, enableGradient: Boolean) {
    fun updateColorScheme(colorScheme: ColorScheme?, enableGradient: Boolean): Boolean {
        isGradientEnabled = enableGradient
        colorTransitions.forEach { it.updateColorScheme(colorScheme) }
        var anyChanged = false
        colorTransitions.forEach { anyChanged = it.updateColorScheme(colorScheme) || anyChanged }
        colorScheme?.let { mediaViewHolder.gutsViewHolder.colorScheme = colorScheme }
        return anyChanged
    }
}
+6 −4
Original line number Diff line number Diff line
@@ -673,10 +673,15 @@ public class MediaControlPanel {
                }
                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
                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 {
@@ -699,9 +704,6 @@ public class MediaControlPanel {
                    mIsArtworkBound = isArtworkBound;
                }

                // Transition Colors to current color scheme
                mColorSchemeTransition.updateColorScheme(colorScheme, mIsArtworkBound);

                // App icon - use notification icon
                ImageView appIconView = mMediaViewHolder.getAppIcon();
                appIconView.clearColorFilter();
+18 −6
Original line number Diff line number Diff line
@@ -577,14 +577,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
@@ -613,6 +619,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