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

Commit 874b0f4a authored by Jordan Demeulenaere's avatar Jordan Demeulenaere Committed by Android (Google) Code Review
Browse files

Merge changes from topic "remove-deprecated-compose-colors" into main

* changes:
  Remove deprecated colors from AndroidColorScheme (1/2)
  Rename SystemUIThemeTest to PlatformThemeTest
parents 90d15d0a 69dae7aa
Loading
Loading
Loading
Loading
+1 −33
Original line number Diff line number Diff line
@@ -84,40 +84,8 @@ class AndroidColorScheme(context: Context) {
    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()
+3 −5
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class SystemUIThemeTest {
class PlatformThemeTest {
    @get:Rule val composeRule = createComposeRule()

    @Test
@@ -40,9 +40,7 @@ class SystemUIThemeTest {
    @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 @@ class SystemUIThemeTest {
    fun testAccessingAndroidColorsWithoutThemeThrows() {
        assertThrows(IllegalStateException::class.java) {
            composeRule.setContent {
                Text("foo", color = LocalAndroidColorScheme.current.deprecated.colorAccent)
                Text("foo", color = LocalAndroidColorScheme.current.primaryFixed)
            }
        }
    }
+11 −23
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ import androidx.compose.ui.res.stringResource
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 @@ import com.android.systemui.res.R
 *   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 @@ 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.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 @@ private fun PeopleScreenWithConversations(
    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 @@ private fun PeopleScreenWithConversations(
            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 PeopleScreenWithConversations(
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 @@ private fun ConversationList(
    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 @@ private fun Tile(
    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,
+7 −11
Original line number Diff line number Diff line
@@ -41,13 +41,11 @@ import androidx.compose.ui.res.stringResource
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 @@ internal fun PeopleScreenEmpty(
        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 @@ internal fun PeopleScreenEmpty(

@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),