Remove deprecated colors from AndroidColorScheme (1/2)
Bug: 370422346
Test: existing screenshot tests
Flag: NONE pure refactoring
Change-Id: Ie725546f4054d49f734dbf9634635d698b2f68a7
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 b28655b..37c37b0 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
@@ -84,40 +84,8 @@
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 {
+ internal fun getColor(context: Context, attr: Int): Color {
val ta = context.obtainStyledAttributes(intArrayOf(attr))
@ColorInt val color = ta.getColor(0, 0)
ta.recycle()
diff --git a/packages/SystemUI/compose/core/tests/src/com/android/compose/theme/PlatformThemeTest.kt b/packages/SystemUI/compose/core/tests/src/com/android/compose/theme/PlatformThemeTest.kt
index 68ce444..23538e3 100644
--- a/packages/SystemUI/compose/core/tests/src/com/android/compose/theme/PlatformThemeTest.kt
+++ b/packages/SystemUI/compose/core/tests/src/com/android/compose/theme/PlatformThemeTest.kt
@@ -40,9 +40,7 @@
@Test
fun testAndroidColorsAreAvailableInsideTheme() {
composeRule.setContent {
- PlatformTheme {
- Text("foo", color = LocalAndroidColorScheme.current.deprecated.colorAccent)
- }
+ PlatformTheme { Text("foo", color = LocalAndroidColorScheme.current.primaryFixed) }
}
composeRule.onNodeWithText("foo").assertIsDisplayed()
@@ -52,7 +50,7 @@
fun testAccessingAndroidColorsWithoutThemeThrows() {
assertThrows(IllegalStateException::class.java) {
composeRule.setContent {
- Text("foo", color = LocalAndroidColorScheme.current.deprecated.colorAccent)
+ Text("foo", color = LocalAndroidColorScheme.current.primaryFixed)
}
}
}
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 b808044..4f1acdc 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
@@ -46,7 +46,7 @@
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.lifecycle.compose.collectAsStateWithLifecycle
-import com.android.compose.theme.LocalAndroidColorScheme
+import com.android.compose.theme.colorAttr
import com.android.systemui.compose.modifiers.sysuiResTag
import com.android.systemui.people.ui.viewmodel.PeopleTileViewModel
import com.android.systemui.people.ui.viewmodel.PeopleViewModel
@@ -60,10 +60,7 @@
* the Activity/Fragment/View hosting this Composable once a result is available.
*/
@Composable
-fun PeopleScreen(
- viewModel: PeopleViewModel,
- onResult: (PeopleViewModel.Result) -> Unit,
-) {
+fun PeopleScreen(viewModel: PeopleViewModel, onResult: (PeopleViewModel.Result) -> Unit) {
val priorityTiles by viewModel.priorityTiles.collectAsStateWithLifecycle()
val recentTiles by viewModel.recentTiles.collectAsStateWithLifecycle()
@@ -79,10 +76,9 @@
// 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.deprecated
Surface(
- color = androidColors.colorBackground,
- contentColor = androidColors.textColorPrimary,
+ color = colorAttr(com.android.internal.R.attr.colorBackground),
+ contentColor = colorAttr(com.android.internal.R.attr.textColorPrimary),
modifier = Modifier.fillMaxSize(),
) {
if (priorityTiles.isNotEmpty() || recentTiles.isNotEmpty()) {
@@ -99,9 +95,7 @@
recentTiles: List<PeopleTileViewModel>,
onTileClicked: (PeopleTileViewModel) -> Unit,
) {
- Column(
- Modifier.sysuiResTag("top_level_with_conversations"),
- ) {
+ Column(Modifier.sysuiResTag("top_level_with_conversations")) {
Column(
Modifier.fillMaxWidth().padding(PeopleSpacePadding),
horizontalAlignment = Alignment.CenterHorizontally,
@@ -126,12 +120,7 @@
Modifier.fillMaxWidth()
.sysuiResTag("scroll_view")
.verticalScroll(rememberScrollState())
- .padding(
- top = 16.dp,
- bottom = PeopleSpacePadding,
- start = 8.dp,
- end = 8.dp,
- ),
+ .padding(top = 16.dp, bottom = PeopleSpacePadding, start = 8.dp, end = 8.dp)
) {
val hasPriorityConversations = priorityTiles.isNotEmpty()
if (hasPriorityConversations) {
@@ -153,13 +142,13 @@
private fun ConversationList(
@StringRes headerTextResource: Int,
tiles: List<PeopleTileViewModel>,
- onTileClicked: (PeopleTileViewModel) -> Unit
+ onTileClicked: (PeopleTileViewModel) -> Unit,
) {
Text(
stringResource(headerTextResource),
Modifier.padding(start = 16.dp),
style = MaterialTheme.typography.labelLarge,
- color = LocalAndroidColorScheme.current.deprecated.colorAccentPrimaryVariant,
+ color = colorAttr(com.android.internal.R.attr.colorAccentPrimaryVariant),
)
Spacer(Modifier.height(10.dp))
@@ -167,7 +156,7 @@
tiles.forEachIndexed { index, tile ->
if (index > 0) {
Divider(
- color = LocalAndroidColorScheme.current.deprecated.colorBackground,
+ color = colorAttr(com.android.internal.R.attr.colorBackground),
thickness = 2.dp,
)
}
@@ -190,14 +179,13 @@
withTopCornerRadius: Boolean,
withBottomCornerRadius: Boolean,
) {
- 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
Surface(
- color = androidColors.colorSurface,
- contentColor = androidColors.textColorPrimary,
+ color = colorAttr(com.android.internal.R.attr.colorSurface),
+ contentColor = colorAttr(com.android.internal.R.attr.textColorPrimary),
shape =
RoundedCornerShape(
topStart = topCornerRadius,
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 26cc9b9..d483f88 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
@@ -41,13 +41,11 @@
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.unit.dp
-import com.android.compose.theme.LocalAndroidColorScheme
+import com.android.compose.theme.colorAttr
import com.android.systemui.res.R
@Composable
-internal fun PeopleScreenEmpty(
- onGotItClicked: () -> Unit,
-) {
+internal fun PeopleScreenEmpty(onGotItClicked: () -> Unit) {
Column(
Modifier.fillMaxSize().padding(PeopleSpacePadding),
horizontalAlignment = Alignment.CenterHorizontally,
@@ -70,15 +68,14 @@
ExampleTile()
Spacer(Modifier.weight(1f))
- val androidColors = LocalAndroidColorScheme.current
Button(
onGotItClicked,
Modifier.fillMaxWidth().defaultMinSize(minHeight = 56.dp),
colors =
ButtonDefaults.buttonColors(
- containerColor = androidColors.deprecated.colorAccentPrimary,
- contentColor = androidColors.deprecated.textColorOnAccent,
- )
+ containerColor = colorAttr(com.android.internal.R.attr.colorAccentPrimary),
+ contentColor = colorAttr(com.android.internal.R.attr.textColorOnAccent),
+ ),
) {
Text(stringResource(R.string.got_it))
}
@@ -87,11 +84,10 @@
@Composable
private fun ExampleTile() {
- val androidColors = LocalAndroidColorScheme.current
Surface(
shape = RoundedCornerShape(28.dp),
- color = androidColors.deprecated.colorSurface,
- contentColor = androidColors.deprecated.textColorPrimary,
+ color = colorAttr(com.android.internal.R.attr.colorSurface),
+ contentColor = colorAttr(com.android.internal.R.attr.textColorPrimary),
) {
Row(
Modifier.padding(vertical = 20.dp, horizontal = 16.dp),