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

Commit aad11054 authored by Yuchen Sun's avatar Yuchen Sun Committed by Android (Google) Code Review
Browse files

Merge "[expressive design] Create TopIntroPreference." into main

parents d8e644d5 584a910e
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -26,6 +26,8 @@
    <string name="single_line_summary_preference_summary" translatable="false">A very long summary to show case a preference which only shows a single line summary.</string>
    <!-- Footer text with two links. [DO NOT TRANSLATE] -->
    <string name="footer_with_two_links" translatable="false">Annotated string with <a href="https://www.android.com/">link 1</a> and <a href="https://source.android.com/">link 2</a>.</string>
    <!-- TopIntroPreference preview text. [DO NOT TRANSLATE] -->
    <string name="label_with_two_links" translatable="false"><a href="https://www.android.com/">Label</a></string>

    <!-- Sample title -->
    <string name="sample_title" translatable="false">Lorem ipsum</string>
+2 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import com.android.settingslib.spa.gallery.preference.MainSwitchPreferencePagePr
import com.android.settingslib.spa.gallery.preference.PreferenceMainPageProvider
import com.android.settingslib.spa.gallery.preference.PreferencePageProvider
import com.android.settingslib.spa.gallery.preference.SwitchPreferencePageProvider
import com.android.settingslib.spa.gallery.preference.TopIntroPreferencePageProvider
import com.android.settingslib.spa.gallery.preference.TwoTargetSwitchPreferencePageProvider
import com.android.settingslib.spa.gallery.preference.ZeroStatePreferencePageProvider
import com.android.settingslib.spa.gallery.scaffold.PagerMainPageProvider
@@ -113,6 +114,7 @@ class GallerySpaEnvironment(context: Context) : SpaEnvironment(context) {
                BannerPageProvider,
                CopyablePageProvider,
                IntroPreferencePageProvider,
                TopIntroPreferencePageProvider,
            ),
            rootPages = listOf(
                HomePageProvider.createSettingsPage(),
+1 −0
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ object PreferenceMainPageProvider : SettingsPageProvider {
                .setLink(fromPage = owner).build(),
            ZeroStatePreferencePageProvider.buildInjectEntry().setLink(fromPage = owner).build(),
            IntroPreferencePageProvider.buildInjectEntry().setLink(fromPage = owner).build(),
            TopIntroPreferencePageProvider.buildInjectEntry().setLink(fromPage = owner).build(),
        )
    }

+83 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.gallery.preference

import android.os.Bundle
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import com.android.settingslib.spa.gallery.R
import com.android.settingslib.spa.framework.common.SettingsEntry
import com.android.settingslib.spa.framework.common.SettingsEntryBuilder
import com.android.settingslib.spa.framework.common.SettingsPageProvider
import com.android.settingslib.spa.framework.common.createSettingsPage
import com.android.settingslib.spa.framework.compose.navigator
import com.android.settingslib.spa.widget.preference.Preference
import com.android.settingslib.spa.widget.preference.PreferenceModel
import com.android.settingslib.spa.widget.preference.TopIntroPreference
import com.android.settingslib.spa.widget.preference.TopIntroPreferenceModel

private const val TITLE = "Sample TopIntroPreference"

object TopIntroPreferencePageProvider : SettingsPageProvider {
    override val name = "TopIntroPreference"
    private val owner = createSettingsPage()

    override fun buildEntry(arguments: Bundle?): List<SettingsEntry> {
        val entryList = mutableListOf<SettingsEntry>()
        entryList.add(
            SettingsEntryBuilder.create("TopIntroPreference", owner)
                .setUiLayoutFn { SampleTopIntroPreference() }
                .build()
        )

        return entryList
    }

    fun buildInjectEntry(): SettingsEntryBuilder {
        return SettingsEntryBuilder.createInject(owner).setUiLayoutFn {
            Preference(
                object : PreferenceModel {
                    override val title = TITLE
                    override val onClick = navigator(name)
                }
            )
        }
    }

    override fun getTitle(arguments: Bundle?): String {
        return TITLE
    }
}

@Composable
private fun SampleTopIntroPreference() {
    Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
        TopIntroPreference(
            object : TopIntroPreferenceModel {
                override val text =
                    "Additional text needed for the page. This can sit on the right side of the screen in 2 column.\n" +
                        "Example collapsed text area that you will not see until you expand this block."
                override val expandText = "Expand"
                override val collapseText = "Collapse"
                override val labelText = R.string.label_with_two_links
            }
        )
    }
}
+2 −1
Original line number Diff line number Diff line
@@ -22,7 +22,8 @@ import androidx.compose.ui.unit.dp
object SettingsDimension {
    val paddingTiny = 2.dp
    val paddingExtraSmall = 4.dp
    val paddingSmall = 4.dp
    val paddingSmall = if (isSpaExpressiveEnabled) 8.dp else 4.dp
    val paddingExtraSmall5 = 10.dp
    val paddingLarge = 16.dp
    val paddingExtraLarge = 24.dp

Loading