1 /* 2 * Copyright (C) 2024 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.settingslib.spa.gallery.preference 18 19 import android.os.Bundle 20 import androidx.compose.foundation.layout.Box 21 import androidx.compose.foundation.layout.fillMaxSize 22 import androidx.compose.runtime.Composable 23 import androidx.compose.ui.Alignment 24 import androidx.compose.ui.Modifier 25 import com.android.settingslib.spa.gallery.R 26 import com.android.settingslib.spa.framework.common.SettingsEntry 27 import com.android.settingslib.spa.framework.common.SettingsEntryBuilder 28 import com.android.settingslib.spa.framework.common.SettingsPageProvider 29 import com.android.settingslib.spa.framework.common.createSettingsPage 30 import com.android.settingslib.spa.framework.compose.navigator 31 import com.android.settingslib.spa.widget.preference.Preference 32 import com.android.settingslib.spa.widget.preference.PreferenceModel 33 import com.android.settingslib.spa.widget.preference.TopIntroPreference 34 import com.android.settingslib.spa.widget.preference.TopIntroPreferenceModel 35 36 private const val TITLE = "Sample TopIntroPreference" 37 38 object TopIntroPreferencePageProvider : SettingsPageProvider { 39 override val name = "TopIntroPreference" 40 private val owner = createSettingsPage() 41 buildEntrynull42 override fun buildEntry(arguments: Bundle?): List<SettingsEntry> { 43 val entryList = mutableListOf<SettingsEntry>() 44 entryList.add( 45 SettingsEntryBuilder.create("TopIntroPreference", owner) 46 .setUiLayoutFn { SampleTopIntroPreference() } 47 .build() 48 ) 49 50 return entryList 51 } 52 53 @Composable Entrynull54 fun Entry() { 55 Preference(object : PreferenceModel { 56 override val title = TITLE 57 override val onClick = navigator(name) 58 }) 59 } 60 getTitlenull61 override fun getTitle(arguments: Bundle?): String { 62 return TITLE 63 } 64 } 65 66 @Composable SampleTopIntroPreferencenull67private fun SampleTopIntroPreference() { 68 Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) { 69 TopIntroPreference( 70 object : TopIntroPreferenceModel { 71 override val text = 72 "Additional text needed for the page. This can sit on the right side of the screen in 2 column.\n" + 73 "Example collapsed text area that you will not see until you expand this block." 74 override val expandText = "Expand" 75 override val collapseText = "Collapse" 76 override val labelText = R.string.label_with_two_links 77 } 78 ) 79 } 80 } 81