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

Commit 0f5e5439 authored by Beth Thibodeau's avatar Beth Thibodeau Committed by Android (Google) Code Review
Browse files

Merge "Use artwork theme color for background and scrim" into main

parents ee076892 8b325898
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -257,6 +257,7 @@ constructor(
            MediaColorScheme(
                Color(colorScheme.materialScheme.getPrimaryFixed()),
                Color(colorScheme.materialScheme.getOnPrimaryFixed()),
                Color(colorScheme.materialScheme.getOnSurface()),
            )
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -18,4 +18,4 @@ package com.android.systemui.media.remedia.shared.model

import androidx.compose.ui.graphics.Color

data class MediaColorScheme(val primary: Color, val onPrimary: Color)
data class MediaColorScheme(val primary: Color, val onPrimary: Color, val background: Color)
+25 −9
Original line number Diff line number Diff line
@@ -135,7 +135,6 @@ import com.android.compose.animation.scene.transitions
import com.android.compose.gesture.effect.rememberOffsetOverscrollEffect
import com.android.compose.gesture.overscrollToDismiss
import com.android.compose.modifiers.thenIf
import com.android.compose.theme.LocalAndroidColorScheme
import com.android.compose.ui.graphics.painter.rememberDrawablePainter
import com.android.mechanics.spec.builder.rememberMotionBuilderContext
import com.android.systemui.animation.Expandable
@@ -321,6 +320,8 @@ private fun Card(
            transitions = Media.Transitions,
        )

    val colorScheme = rememberAnimatedColorScheme(viewModel.colorScheme)

    // Each time the presentation style changes, animate to the corresponding scene.
    LaunchedEffect(presentationStyle) {
        stlState.setTargetScene(targetScene = presentationStyle.toScene(), animationScope = this)
@@ -328,7 +329,11 @@ private fun Card(

    Box(modifier) {
        if (stlState.currentScene != Media.Scenes.Compact) {
            CardBackground(image = viewModel.background, modifier = Modifier.matchParentSize())
            CardBackground(
                image = viewModel.background,
                colorScheme = colorScheme,
                modifier = Modifier.matchParentSize(),
            )
        }

        Expandable(
@@ -342,6 +347,7 @@ private fun Card(
                        CardForeground(
                            expandable = it,
                            viewModel = viewModel,
                            colorScheme = colorScheme,
                            threeRows = true,
                            fillHeight = false,
                        )
@@ -351,6 +357,7 @@ private fun Card(
                        CardForeground(
                            expandable = it,
                            viewModel = viewModel,
                            colorScheme = colorScheme,
                            threeRows = false,
                            fillHeight = false,
                        )
@@ -367,10 +374,12 @@ private fun Card(

@Composable
private fun rememberAnimatedColorScheme(colorScheme: MediaColorScheme?): AnimatedColorScheme {
    val primaryColor = colorScheme?.primary ?: LocalAndroidColorScheme.current.primaryFixed
    val onPrimaryColor = colorScheme?.onPrimary ?: LocalAndroidColorScheme.current.onPrimaryFixed
    val primaryColor = colorScheme?.primary ?: MaterialTheme.colorScheme.primaryFixed
    val onPrimaryColor = colorScheme?.onPrimary ?: MaterialTheme.colorScheme.onPrimaryFixed
    val backgroundColor = colorScheme?.background ?: MaterialTheme.colorScheme.onSurface
    val animatedPrimary by animateColorAsState(targetValue = primaryColor)
    val animatedOnPrimary by animateColorAsState(targetValue = onPrimaryColor)
    val animatedBackground by animateColorAsState(targetValue = backgroundColor)

    return remember {
        object : AnimatedColorScheme {
@@ -379,6 +388,9 @@ private fun rememberAnimatedColorScheme(colorScheme: MediaColorScheme?): Animate

            override val onPrimary: Color
                get() = animatedOnPrimary

            override val background: Color
                get() = animatedBackground
        }
    }
}
@@ -396,6 +408,7 @@ private fun rememberAnimatedColorScheme(colorScheme: MediaColorScheme?): Animate
private fun ContentScope.CardForeground(
    expandable: Expandable,
    viewModel: MediaCardViewModel,
    colorScheme: AnimatedColorScheme,
    threeRows: Boolean,
    fillHeight: Boolean,
    modifier: Modifier = Modifier,
@@ -406,8 +419,6 @@ private fun ContentScope.CardForeground(
    val isGutsVisible = viewModel.guts.isVisible
    LaunchedEffect(isGutsVisible) { gutsAlphaAnimatable.animateTo(if (isGutsVisible) 1f else 0f) }

    val colorScheme = rememberAnimatedColorScheme(viewModel.colorScheme)

    // Use a custom layout to measure the content even if the content is being hidden because the
    // internal guts are showing. This is needed because only the content knows the size the of the
    // card and the guts are set to be the same size of the content.
@@ -732,11 +743,15 @@ private fun ContentScope.CompactCardForeground(

/** Renders the background of a card, loading the artwork and showing an overlay on top of it. */
@Composable
private fun CardBackground(image: ImageBitmap?, modifier: Modifier = Modifier) {
private fun CardBackground(
    image: ImageBitmap?,
    colorScheme: AnimatedColorScheme,
    modifier: Modifier = Modifier,
) {
    Crossfade(targetState = image, modifier = modifier) { imageOrNull ->
        if (imageOrNull != null) {
            // Loaded art.
            val gradientBaseColor = MaterialTheme.colorScheme.onSurface
            val gradientBaseColor = colorScheme.background
            Image(
                bitmap = imageOrNull,
                contentDescription = null,
@@ -762,7 +777,7 @@ private fun CardBackground(image: ImageBitmap?, modifier: Modifier = Modifier) {
            )
        } else {
            // Placeholder.
            Box(Modifier.background(MaterialTheme.colorScheme.onSurface).fillMaxSize())
            Box(Modifier.background(colorScheme.background).fillMaxSize())
        }
    }
}
@@ -1398,6 +1413,7 @@ data class MediaUiBehavior(
private interface AnimatedColorScheme {
    val primary: Color
    val onPrimary: Color
    val background: Color
}

private object Media {