Define the Compose MaterialTheme for SystemUI
Fix: 230605885
Test: TBD
Change-Id: Icff75c7f9173b56160c8f09f4c8892699da385d1
diff --git a/packages/SystemUI/compose/core/src/com/android/compose/PlatformButtons.kt b/packages/SystemUI/compose/core/src/com/android/compose/PlatformButtons.kt
index d1ee18a..25269dc 100644
--- a/packages/SystemUI/compose/core/src/com/android/compose/PlatformButtons.kt
+++ b/packages/SystemUI/compose/core/src/com/android/compose/PlatformButtons.kt
@@ -85,7 +85,7 @@
@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 @@
@Composable
private fun outlineButtonColors(): ButtonColors {
- val colors = LocalAndroidColorScheme.current
+ val colors = LocalAndroidColorScheme.current.deprecated
return ButtonDefaults.outlinedButtonColors(
contentColor = colors.textColorPrimary,
)
@@ -102,7 +102,7 @@
@Composable
private fun outlineButtonBorder(): BorderStroke {
- val colors = LocalAndroidColorScheme.current
+ val colors = LocalAndroidColorScheme.current.deprecated
return BorderStroke(
width = 1.dp,
color = colors.colorAccentPrimaryVariant,
diff --git a/packages/SystemUI/compose/core/src/com/android/compose/theme/AndroidColorScheme.kt b/packages/SystemUI/compose/core/src/com/android/compose/theme/AndroidColorScheme.kt
index 4f1657f..1d6f813 100644
--- a/packages/SystemUI/compose/core/src/com/android/compose/theme/AndroidColorScheme.kt
+++ b/packages/SystemUI/compose/core/src/com/android/compose/theme/AndroidColorScheme.kt
@@ -37,33 +37,83 @@
* 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) {
- val colorPrimary = getColor(context, R.attr.colorPrimary)
- val colorPrimaryDark = getColor(context, R.attr.colorPrimaryDark)
- val colorAccent = getColor(context, R.attr.colorAccent)
- val colorAccentPrimary = getColor(context, R.attr.colorAccentPrimary)
- val colorAccentSecondary = getColor(context, R.attr.colorAccentSecondary)
- val colorAccentTertiary = getColor(context, R.attr.colorAccentTertiary)
- val colorAccentPrimaryVariant = getColor(context, R.attr.colorAccentPrimaryVariant)
- val colorAccentSecondaryVariant = getColor(context, R.attr.colorAccentSecondaryVariant)
- val colorAccentTertiaryVariant = getColor(context, R.attr.colorAccentTertiaryVariant)
- val colorSurface = getColor(context, R.attr.colorSurface)
- val colorSurfaceHighlight = getColor(context, R.attr.colorSurfaceHighlight)
- val colorSurfaceVariant = getColor(context, R.attr.colorSurfaceVariant)
- val colorSurfaceHeader = getColor(context, R.attr.colorSurfaceHeader)
- val colorError = getColor(context, R.attr.colorError)
- val colorBackground = getColor(context, R.attr.colorBackground)
- val colorBackgroundFloating = getColor(context, R.attr.colorBackgroundFloating)
- val panelColorBackground = getColor(context, R.attr.panelColorBackground)
- val textColorPrimary = getColor(context, R.attr.textColorPrimary)
- val textColorSecondary = getColor(context, R.attr.textColorSecondary)
- val textColorTertiary = getColor(context, R.attr.textColorTertiary)
- val textColorPrimaryInverse = getColor(context, R.attr.textColorPrimaryInverse)
- val textColorSecondaryInverse = getColor(context, R.attr.textColorSecondaryInverse)
- val textColorTertiaryInverse = getColor(context, R.attr.textColorTertiaryInverse)
- val textColorOnAccent = getColor(context, R.attr.textColorOnAccent)
- val colorForeground = getColor(context, R.attr.colorForeground)
- val colorForegroundInverse = getColor(context, R.attr.colorForegroundInverse)
+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)
+ val colorAccentPrimary = getColor(context, R.attr.colorAccentPrimary)
+ val colorAccentSecondary = getColor(context, R.attr.colorAccentSecondary)
+ val colorAccentTertiary = getColor(context, R.attr.colorAccentTertiary)
+ val colorAccentPrimaryVariant = getColor(context, R.attr.colorAccentPrimaryVariant)
+ val colorAccentSecondaryVariant = getColor(context, R.attr.colorAccentSecondaryVariant)
+ val colorAccentTertiaryVariant = getColor(context, R.attr.colorAccentTertiaryVariant)
+ val colorSurface = getColor(context, R.attr.colorSurface)
+ val colorSurfaceHighlight = getColor(context, R.attr.colorSurfaceHighlight)
+ val colorSurfaceVariant = getColor(context, R.attr.colorSurfaceVariant)
+ val colorSurfaceHeader = getColor(context, R.attr.colorSurfaceHeader)
+ val colorError = getColor(context, R.attr.colorError)
+ val colorBackground = getColor(context, R.attr.colorBackground)
+ val colorBackgroundFloating = getColor(context, R.attr.colorBackgroundFloating)
+ val panelColorBackground = getColor(context, R.attr.panelColorBackground)
+ val textColorPrimary = getColor(context, R.attr.textColorPrimary)
+ val textColorSecondary = getColor(context, R.attr.textColorSecondary)
+ val textColorTertiary = getColor(context, R.attr.textColorTertiary)
+ val textColorPrimaryInverse = getColor(context, R.attr.textColorPrimaryInverse)
+ val textColorSecondaryInverse = getColor(context, R.attr.textColorSecondaryInverse)
+ val textColorTertiaryInverse = getColor(context, R.attr.textColorTertiaryInverse)
+ 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 {
diff --git a/packages/SystemUI/compose/core/tests/src/com/android/compose/theme/SystemUIThemeTest.kt b/packages/SystemUI/compose/core/tests/src/com/android/compose/theme/SystemUIThemeTest.kt
index 9bc6856..fe34017 100644
--- a/packages/SystemUI/compose/core/tests/src/com/android/compose/theme/SystemUIThemeTest.kt
+++ b/packages/SystemUI/compose/core/tests/src/com/android/compose/theme/SystemUIThemeTest.kt
@@ -40,7 +40,9 @@
@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 @@
fun testAccessingAndroidColorsWithoutThemeThrows() {
assertThrows(IllegalStateException::class.java) {
composeRule.setContent {
- Text("foo", color = LocalAndroidColorScheme.current.colorAccent)
+ Text("foo", color = LocalAndroidColorScheme.current.deprecated.colorAccent)
}
}
}
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/people/ui/compose/PeopleScreen.kt b/packages/SystemUI/compose/features/src/com/android/systemui/people/ui/compose/PeopleScreen.kt
index a74e56b..f88fc21 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/people/ui/compose/PeopleScreen.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/people/ui/compose/PeopleScreen.kt
@@ -91,7 +91,7 @@
// 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 @@
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 @@
if (index > 0) {
item {
Divider(
- color = LocalAndroidColorScheme.current.colorBackground,
+ color = LocalAndroidColorScheme.current.deprecated.colorBackground,
thickness = 2.dp,
)
}
@@ -204,7 +204,7 @@
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
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/people/ui/compose/PeopleScreenEmpty.kt b/packages/SystemUI/compose/features/src/com/android/systemui/people/ui/compose/PeopleScreenEmpty.kt
index 0484ff4..1e6f4a2 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/people/ui/compose/PeopleScreenEmpty.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/people/ui/compose/PeopleScreenEmpty.kt
@@ -76,8 +76,8 @@
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 @@
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),
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/qs/footer/ui/compose/FooterActions.kt b/packages/SystemUI/compose/features/src/com/android/systemui/qs/footer/ui/compose/FooterActions.kt
index 349f5c3..75bf281 100644
--- a/packages/SystemUI/compose/features/src/com/android/systemui/qs/footer/ui/compose/FooterActions.kt
+++ b/packages/SystemUI/compose/features/src/com/android/systemui/qs/footer/ui/compose/FooterActions.kt
@@ -122,7 +122,7 @@
}
val backgroundColor = colorAttr(R.attr.underSurfaceColor)
- val contentColor = LocalAndroidColorScheme.current.textColorPrimary
+ val contentColor = LocalAndroidColorScheme.current.deprecated.textColorPrimary
val backgroundTopRadius = dimensionResource(R.dimen.qs_corner_radius)
val backgroundModifier =
remember(
@@ -287,7 +287,7 @@
number.toString(),
modifier = Modifier.align(Alignment.Center),
style = MaterialTheme.typography.bodyLarge,
- color = LocalAndroidColorScheme.current.textColorPrimary,
+ color = LocalAndroidColorScheme.current.deprecated.textColorPrimary,
// TODO(b/242040009): This should only use a standard text style instead and
// should not override the text size.
fontSize = 18.sp,
@@ -305,7 +305,7 @@
@Composable
private fun NewChangesDot(modifier: Modifier = Modifier) {
val contentDescription = stringResource(R.string.fgs_dot_content_description)
- val color = LocalAndroidColorScheme.current.colorAccentTertiary
+ val color = LocalAndroidColorScheme.current.deprecated.colorAccentTertiary
Canvas(modifier.size(12.dp).semantics { this.contentDescription = contentDescription }) {
drawCircle(color)
@@ -324,8 +324,9 @@
Expandable(
shape = CircleShape,
color = colorAttr(R.attr.underSurfaceColor),
- contentColor = LocalAndroidColorScheme.current.textColorSecondary,
- borderStroke = BorderStroke(1.dp, LocalAndroidColorScheme.current.colorBackground),
+ contentColor = LocalAndroidColorScheme.current.deprecated.textColorSecondary,
+ borderStroke =
+ BorderStroke(1.dp, LocalAndroidColorScheme.current.deprecated.colorBackground),
modifier = modifier.padding(horizontal = 4.dp),
onClick = onClick,
) {