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

Commit b2bd3d36 authored by Chaohui Wang's avatar Chaohui Wang Committed by Android (Google) Code Review
Browse files

Merge "[Spa] Fix ZeroStatePreference when multiple lines" into main

parents 38415849 39f35a7a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -21,4 +21,5 @@ import androidx.compose.ui.unit.dp
object SettingsSize {
    val small2 = 20.dp
    val medium3 = 40.dp
    val large2 = 64.dp
}
+2 −0
Original line number Diff line number Diff line
@@ -31,4 +31,6 @@ object SettingsSpace {
    val small2 = 18.dp
    val small3 = 20.dp
    val small4 = 24.dp

    val medium5 = 48.dp
}
+49 −35
Original line number Diff line number Diff line
@@ -17,11 +17,11 @@
package com.android.settingslib.spa.widget.preference

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.History
@@ -41,6 +41,7 @@ import androidx.compose.ui.graphics.Path
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.asComposePath
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.Density
import androidx.compose.ui.unit.LayoutDirection
@@ -49,7 +50,9 @@ import androidx.graphics.shapes.CornerRounding
import androidx.graphics.shapes.RoundedPolygon
import androidx.graphics.shapes.star
import androidx.graphics.shapes.toPath
import com.android.settingslib.spa.framework.theme.SettingsSize
import com.android.settingslib.spa.framework.theme.SettingsSpace
import com.android.settingslib.spa.framework.theme.SettingsTheme

@OptIn(ExperimentalMaterial3ExpressiveApi::class)
@Composable
@@ -58,16 +61,14 @@ fun ZeroStatePreference(icon: ImageVector, text: String = "", description: Strin
        RoundedPolygon.star(
            numVerticesPerRadius = 6,
            innerRadius = 0.8f,
            rounding = CornerRounding(0.3f)
            rounding = CornerRounding(0.3f),
        )
    }
    val clip = remember(zeroStateShape) {
        RoundedPolygonShape(polygon = zeroStateShape)
    }
    val clip = remember(zeroStateShape) { RoundedPolygonShape(polygon = zeroStateShape) }
    Column(modifier = Modifier.fillMaxWidth(), horizontalAlignment = Alignment.CenterHorizontally) {
        Box(
            modifier = Modifier
                .clip(clip)
            modifier =
                Modifier.clip(clip)
                    .background(MaterialTheme.colorScheme.surfaceBright)
                    .size(160.dp),
            contentAlignment = Alignment.Center,
@@ -75,49 +76,62 @@ fun ZeroStatePreference(icon: ImageVector, text: String = "", description: Strin
            Icon(
                imageVector = icon,
                contentDescription = null,
                modifier = Modifier.size(64.dp),
                modifier = Modifier.size(SettingsSize.large2),
                tint = MaterialTheme.colorScheme.onSurface,
            )
        }
        Spacer(Modifier.height(SettingsSpace.small4))
        Column(
            modifier =
                Modifier.padding(
                    start = SettingsSpace.medium5,
                    top = SettingsSpace.small4,
                    end = SettingsSpace.medium5,
                    bottom = SettingsSpace.small1,
                ),
            verticalArrangement = Arrangement.spacedBy(SettingsSpace.extraSmall2),
        ) {
            if (text.isNotEmpty()) {
                Text(
                    text = text,
                style = MaterialTheme.typography.titleMediumEmphasized,
                    color = MaterialTheme.colorScheme.onSurface,
                    textAlign = TextAlign.Center,
                    style = MaterialTheme.typography.titleMediumEmphasized,
                )
            }
        Spacer(Modifier.height(SettingsSpace.extraSmall2))
            if (description.isNotEmpty()) {
                Text(
                    text = description,
                style = MaterialTheme.typography.bodyMedium,
                    color = MaterialTheme.colorScheme.onSurface,
                    textAlign = TextAlign.Center,
                    style = MaterialTheme.typography.bodyMedium,
                )
            }
        Spacer(Modifier.height(SettingsSpace.small1))
        }
    }
}

@Preview
@Composable
private fun ZeroStatePreferencePreview() {
    SettingsTheme {
        ZeroStatePreference(
            Icons.Filled.History,
        "No recent search history",
        "Description"
            "No recent search history No recent search history",
            "Description Description Description Description Description",
        )
    }
}

private class RoundedPolygonShape(
    private val polygon: RoundedPolygon,
    private var matrix: Matrix = Matrix()
    private var matrix: Matrix = Matrix(),
) : Shape {
    private var path = Path()

    override fun createOutline(
        size: Size,
        layoutDirection: LayoutDirection,
        density: Density
        density: Density,
    ): Outline {
        path.rewind()
        path = polygon.toPath().asComposePath()