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

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

Merge "[Spa] Add BulletPreference" into main

parents 8ee552fb 4ca5b640
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.settingslib.spa.gallery.preference
import android.os.Bundle
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.DisabledByDefault
import androidx.compose.material.icons.outlined.StarOutline
import androidx.compose.runtime.Composable
import androidx.compose.runtime.IntState
import androidx.compose.runtime.LaunchedEffect
@@ -35,6 +36,7 @@ import com.android.settingslib.spa.framework.common.SpaEnvironmentFactory
import com.android.settingslib.spa.framework.compose.navigator
import com.android.settingslib.spa.framework.theme.SettingsTheme
import com.android.settingslib.spa.gallery.R
import com.android.settingslib.spa.widget.preference.BulletPreference
import com.android.settingslib.spa.widget.preference.ListPreferenceModel
import com.android.settingslib.spa.widget.preference.ListPreferenceOption
import com.android.settingslib.spa.widget.preference.Preference
@@ -124,6 +126,21 @@ object PreferencePageProvider : SettingsPageProvider {
                    }
                }
            )
            BulletPreference(
                title = "Bullet point title",
                summary = "",
                icon = Icons.Outlined.StarOutline
            )
            BulletPreference(
                title = "",
                summary = "Bullet point description. Supporting text to explain the main benefit of the feature.",
                icon = Icons.Outlined.StarOutline
            )
            BulletPreference(
                title = "Bullet point title",
                summary = "Bullet point description. Supporting text to explain the main benefit of the feature.",
                icon = Icons.Outlined.StarOutline
            )
        }
    }

+1 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ object SettingsDimension {
    val paddingExtraSmall = 4.dp
    val paddingExtraSmall1 = 6.dp
    val paddingSmall = if (isSpaExpressiveEnabled) 8.dp else 4.dp
    val paddingSmall1 = 16.dp
    val paddingExtraSmall5 = 10.dp
    val paddingExtraSmall6 = 12.dp
    val paddingLarge = 16.dp
+98 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settingslib.spa.widget.preference

import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.StarOutline
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.tooling.preview.Preview
import com.android.settingslib.spa.framework.theme.SettingsDimension
import com.android.settingslib.spa.framework.theme.SettingsTheme

@OptIn(ExperimentalMaterial3ExpressiveApi::class)
@Composable
fun BulletPreference(title: String, summary: String, icon: ImageVector) {
    Row(
        modifier =
            Modifier
                .fillMaxWidth()
                .semantics(mergeDescendants = true) {}
                .padding(SettingsDimension.paddingSmall1),
    ) {
        Icon(
            imageVector = icon,
            contentDescription = null,
            modifier = Modifier
                .padding(end = SettingsDimension.paddingSmall1)
                .size(SettingsDimension.itemIconSize),
            tint = MaterialTheme.colorScheme.onSurfaceVariant,
        )
        Column(
            modifier = Modifier.weight(1f)
        ) {
            if (title.isNotEmpty()) {
                Text(
                    text = title,
                    style = MaterialTheme.typography.bodyLargeEmphasized,
                )
            }
            if (summary.isNotEmpty()) {
                Text(
                    text = summary,
                    color = MaterialTheme.colorScheme.onSurfaceVariant,
                    style = MaterialTheme.typography.bodyMedium,
                )
            }
        }
    }
}

@Preview
@Composable
private fun BulletPreferencePreview() {
    SettingsTheme {
        Column {
            BulletPreference(
                title = "Bullet point title",
                summary = "",
                icon = Icons.Outlined.StarOutline,
            )
            BulletPreference(
                title = "",
                summary = "Bullet point description. Supporting text to explain the main benefit of the feature.",
                icon = Icons.Outlined.StarOutline,
            )
            BulletPreference(
                title = "Bullet point title",
                summary = "Bullet point description. Supporting text to explain the main benefit of the feature.",
                icon = Icons.Outlined.StarOutline,
            )
        }
    }
}
+64 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.settingslib.spa.widget.preference

import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.StarOutline
import androidx.compose.ui.test.assertIsDisplayed
import androidx.compose.ui.test.junit4.createComposeRule
import androidx.compose.ui.test.onNodeWithText
import androidx.test.ext.junit.runners.AndroidJUnit4
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith

@RunWith(AndroidJUnit4::class)
class BulletPreferenceTest {
    @get:Rule
    val composeTestRule = createComposeRule()

    @Test
    fun title_displayed() {
        composeTestRule.setContent {
            BulletPreference(
                title = TITLE,
                summary = "",
                icon = Icons.Outlined.StarOutline,
            )
        }

        composeTestRule.onNodeWithText(TITLE).assertIsDisplayed()
    }

    @Test
    fun summary_displayed() {
        composeTestRule.setContent {
            BulletPreference(
                title = TITLE,
                summary = SUMMARY,
                icon = Icons.Outlined.StarOutline,
            )
        }

        composeTestRule.onNodeWithText(SUMMARY).assertIsDisplayed()
    }

    private companion object {
        const val TITLE = "Title"
        const val SUMMARY = "Summary"
    }
}