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.material.icons.Icons
23 import androidx.compose.material.icons.outlined.AirplanemodeActive
24 import androidx.compose.runtime.Composable
25 import androidx.compose.ui.Alignment
26 import androidx.compose.ui.Modifier
27 import com.android.settingslib.spa.framework.common.SettingsEntry
28 import com.android.settingslib.spa.framework.common.SettingsEntryBuilder
29 import com.android.settingslib.spa.framework.common.SettingsPageProvider
30 import com.android.settingslib.spa.framework.common.createSettingsPage
31 import com.android.settingslib.spa.framework.compose.navigator
32 import com.android.settingslib.spa.widget.preference.IntroPreference
33 import com.android.settingslib.spa.widget.preference.Preference
34 import com.android.settingslib.spa.widget.preference.PreferenceModel
35 
36 private const val TITLE = "Sample IntroPreference"
37 
38 object IntroPreferencePageProvider : SettingsPageProvider {
39     override val name = "IntroPreference"
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("IntroPreference", owner)
46                 .setUiLayoutFn { SampleIntroPreference() }
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
SampleIntroPreferencenull67 private fun SampleIntroPreference() {
68     Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.Center) {
69         IntroPreference(
70             title = "Preferred network type",
71             descriptions = listOf("Description"),
72             imageVector = Icons.Outlined.AirplanemodeActive,
73         )
74     }
75 }
76