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

Commit 137c193d authored by Lucas Dupin's avatar Lucas Dupin Committed by Android (Google) Code Review
Browse files

Merge "Define the Compose MaterialTheme for SystemUI" into udc-dev

parents be150360 e8963ae8
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -85,7 +85,7 @@ private val ButtonPaddings = PaddingValues(horizontal = 16.dp, vertical = 8.dp)

@Composable
private fun filledButtonColors(): ButtonColors {
    val colors = LocalAndroidColorScheme.current
    val colors = LocalAndroidColorScheme.current.deprecated
    return ButtonDefaults.buttonColors(
        containerColor = colors.colorAccentPrimary,
        contentColor = colors.textColorOnAccent,
@@ -94,7 +94,7 @@ private fun filledButtonColors(): ButtonColors {

@Composable
private fun outlineButtonColors(): ButtonColors {
    val colors = LocalAndroidColorScheme.current
    val colors = LocalAndroidColorScheme.current.deprecated
    return ButtonDefaults.outlinedButtonColors(
        contentColor = colors.textColorPrimary,
    )
@@ -102,7 +102,7 @@ private fun outlineButtonColors(): ButtonColors {

@Composable
private fun outlineButtonBorder(): BorderStroke {
    val colors = LocalAndroidColorScheme.current
    val colors = LocalAndroidColorScheme.current.deprecated
    return BorderStroke(
        width = 1.dp,
        color = colors.colorAccentPrimaryVariant,
+77 −27
Original line number Diff line number Diff line
@@ -37,7 +37,56 @@ val LocalAndroidColorScheme =
 * Important: Use M3 colors from MaterialTheme.colorScheme whenever possible instead. In the future,
 * most of the colors in this class will be removed in favor of their M3 counterpart.
 */
class AndroidColorScheme internal constructor(context: Context) {
class AndroidColorScheme(context: Context) {
    val onSecondaryFixedVariant = getColor(context, R.attr.materialColorOnSecondaryFixedVariant)
    val onTertiaryFixedVariant = getColor(context, R.attr.materialColorOnTertiaryFixedVariant)
    val surfaceContainerLowest = getColor(context, R.attr.materialColorSurfaceContainerLowest)
    val onPrimaryFixedVariant = getColor(context, R.attr.materialColorOnPrimaryFixedVariant)
    val onSecondaryContainer = getColor(context, R.attr.materialColorOnSecondaryContainer)
    val onTertiaryContainer = getColor(context, R.attr.materialColorOnTertiaryContainer)
    val surfaceContainerLow = getColor(context, R.attr.materialColorSurfaceContainerLow)
    val onPrimaryContainer = getColor(context, R.attr.materialColorOnPrimaryContainer)
    val secondaryFixedDim = getColor(context, R.attr.materialColorSecondaryFixedDim)
    val onErrorContainer = getColor(context, R.attr.materialColorOnErrorContainer)
    val onSecondaryFixed = getColor(context, R.attr.materialColorOnSecondaryFixed)
    val onSurfaceInverse = getColor(context, R.attr.materialColorOnSurfaceInverse)
    val tertiaryFixedDim = getColor(context, R.attr.materialColorTertiaryFixedDim)
    val onTertiaryFixed = getColor(context, R.attr.materialColorOnTertiaryFixed)
    val primaryFixedDim = getColor(context, R.attr.materialColorPrimaryFixedDim)
    val secondaryContainer = getColor(context, R.attr.materialColorSecondaryContainer)
    val errorContainer = getColor(context, R.attr.materialColorErrorContainer)
    val onPrimaryFixed = getColor(context, R.attr.materialColorOnPrimaryFixed)
    val primaryInverse = getColor(context, R.attr.materialColorPrimaryInverse)
    val secondaryFixed = getColor(context, R.attr.materialColorSecondaryFixed)
    val surfaceInverse = getColor(context, R.attr.materialColorSurfaceInverse)
    val surfaceVariant = getColor(context, R.attr.materialColorSurfaceVariant)
    val tertiaryContainer = getColor(context, R.attr.materialColorTertiaryContainer)
    val tertiaryFixed = getColor(context, R.attr.materialColorTertiaryFixed)
    val primaryContainer = getColor(context, R.attr.materialColorPrimaryContainer)
    val onBackground = getColor(context, R.attr.materialColorOnBackground)
    val primaryFixed = getColor(context, R.attr.materialColorPrimaryFixed)
    val onSecondary = getColor(context, R.attr.materialColorOnSecondary)
    val onTertiary = getColor(context, R.attr.materialColorOnTertiary)
    val surfaceDim = getColor(context, R.attr.materialColorSurfaceDim)
    val surfaceBright = getColor(context, R.attr.materialColorSurfaceBright)
    val onError = getColor(context, R.attr.materialColorOnError)
    val surface = getColor(context, R.attr.materialColorSurface)
    val surfaceContainerHigh = getColor(context, R.attr.materialColorSurfaceContainerHigh)
    val surfaceContainerHighest = getColor(context, R.attr.materialColorSurfaceContainerHighest)
    val onSurfaceVariant = getColor(context, R.attr.materialColorOnSurfaceVariant)
    val outline = getColor(context, R.attr.materialColorOutline)
    val outlineVariant = getColor(context, R.attr.materialColorOutlineVariant)
    val onPrimary = getColor(context, R.attr.materialColorOnPrimary)
    val onSurface = getColor(context, R.attr.materialColorOnSurface)
    val surfaceContainer = getColor(context, R.attr.materialColorSurfaceContainer)
    val primary = getColor(context, R.attr.materialColorPrimary)
    val secondary = getColor(context, R.attr.materialColorSecondary)
    val tertiary = getColor(context, R.attr.materialColorTertiary)

    @Deprecated("Use the new android tokens: go/sysui-colors")
    val deprecated = DeprecatedValues(context)

    class DeprecatedValues(context: Context) {
        val colorPrimary = getColor(context, R.attr.colorPrimary)
        val colorPrimaryDark = getColor(context, R.attr.colorPrimaryDark)
        val colorAccent = getColor(context, R.attr.colorAccent)
@@ -64,6 +113,7 @@ class AndroidColorScheme internal constructor(context: Context) {
        val textColorOnAccent = getColor(context, R.attr.textColorOnAccent)
        val colorForeground = getColor(context, R.attr.colorForeground)
        val colorForegroundInverse = getColor(context, R.attr.colorForegroundInverse)
    }

    companion object {
        fun getColor(context: Context, attr: Int): Color {
+4 −2
Original line number Diff line number Diff line
@@ -40,7 +40,9 @@ class SystemUIThemeTest {
    @Test
    fun testAndroidColorsAreAvailableInsideTheme() {
        composeRule.setContent {
            PlatformTheme { Text("foo", color = LocalAndroidColorScheme.current.colorAccent) }
            PlatformTheme {
                Text("foo", color = LocalAndroidColorScheme.current.deprecated.colorAccent)
            }
        }

        composeRule.onNodeWithText("foo").assertIsDisplayed()
@@ -50,7 +52,7 @@ class SystemUIThemeTest {
    fun testAccessingAndroidColorsWithoutThemeThrows() {
        assertThrows(IllegalStateException::class.java) {
            composeRule.setContent {
                Text("foo", color = LocalAndroidColorScheme.current.colorAccent)
                Text("foo", color = LocalAndroidColorScheme.current.deprecated.colorAccent)
            }
        }
    }
+4 −4
Original line number Diff line number Diff line
@@ -91,7 +91,7 @@ fun PeopleScreen(

    // Make sure to use the Android colors and not the default Material3 colors to have the exact
    // same colors as the View implementation.
    val androidColors = LocalAndroidColorScheme.current
    val androidColors = LocalAndroidColorScheme.current.deprecated
    Surface(
        color = androidColors.colorBackground,
        contentColor = androidColors.textColorPrimary,
@@ -170,7 +170,7 @@ private fun LazyListScope.ConversationList(
            stringResource(headerTextResource),
            Modifier.padding(start = 16.dp),
            style = MaterialTheme.typography.labelLarge,
            color = LocalAndroidColorScheme.current.colorAccentPrimaryVariant,
            color = LocalAndroidColorScheme.current.deprecated.colorAccentPrimaryVariant,
        )

        Spacer(Modifier.height(10.dp))
@@ -180,7 +180,7 @@ private fun LazyListScope.ConversationList(
        if (index > 0) {
            item {
                Divider(
                    color = LocalAndroidColorScheme.current.colorBackground,
                    color = LocalAndroidColorScheme.current.deprecated.colorBackground,
                    thickness = 2.dp,
                )
            }
@@ -204,7 +204,7 @@ private fun Tile(
    withTopCornerRadius: Boolean,
    withBottomCornerRadius: Boolean,
) {
    val androidColors = LocalAndroidColorScheme.current
    val androidColors = LocalAndroidColorScheme.current.deprecated
    val cornerRadius = dimensionResource(R.dimen.people_space_widget_radius)
    val topCornerRadius = if (withTopCornerRadius) cornerRadius else 0.dp
    val bottomCornerRadius = if (withBottomCornerRadius) cornerRadius else 0.dp
+4 −4
Original line number Diff line number Diff line
@@ -76,8 +76,8 @@ internal fun PeopleScreenEmpty(
            Modifier.fillMaxWidth().defaultMinSize(minHeight = 56.dp),
            colors =
                ButtonDefaults.buttonColors(
                    containerColor = androidColors.colorAccentPrimary,
                    contentColor = androidColors.textColorOnAccent,
                    containerColor = androidColors.deprecated.colorAccentPrimary,
                    contentColor = androidColors.deprecated.textColorOnAccent,
                )
        ) {
            Text(stringResource(R.string.got_it))
@@ -90,8 +90,8 @@ private fun ExampleTile() {
    val androidColors = LocalAndroidColorScheme.current
    Surface(
        shape = RoundedCornerShape(28.dp),
        color = androidColors.colorSurface,
        contentColor = androidColors.textColorPrimary,
        color = androidColors.deprecated.colorSurface,
        contentColor = androidColors.deprecated.textColorPrimary,
    ) {
        Row(
            Modifier.padding(vertical = 20.dp, horizontal = 16.dp),
Loading