1 /*
2  * Copyright (C) 2022 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.button
18 
19 import android.os.Bundle
20 import androidx.compose.material.icons.Icons
21 import androidx.compose.material.icons.automirrored.outlined.Launch
22 import androidx.compose.material.icons.outlined.Delete
23 import androidx.compose.material.icons.outlined.WarningAmber
24 import androidx.compose.runtime.Composable
25 import androidx.compose.ui.tooling.preview.Preview
26 import com.android.settingslib.spa.framework.common.SettingsPageProvider
27 import com.android.settingslib.spa.framework.compose.navigator
28 import com.android.settingslib.spa.framework.theme.SettingsTheme
29 import com.android.settingslib.spa.widget.button.ActionButton
30 import com.android.settingslib.spa.widget.button.ActionButtons
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.scaffold.RegularScaffold
34 
35 private const val TITLE = "Sample ActionButton"
36 
37 object ActionButtonPageProvider : SettingsPageProvider {
38     override val name = "ActionButton"
39 
getTitlenull40     override fun getTitle(arguments: Bundle?): String {
41         return TITLE
42     }
43 
44     @Composable
Pagenull45     override fun Page(arguments: Bundle?) {
46         RegularScaffold(title = TITLE) {
47             val actionButtons = listOf(
48                 ActionButton(text = "Open", imageVector = Icons.AutoMirrored.Outlined.Launch) {},
49                 ActionButton(text = "Uninstall", imageVector = Icons.Outlined.Delete) {},
50                 ActionButton(text = "Force stop", imageVector = Icons.Outlined.WarningAmber) {},
51             )
52             ActionButtons(actionButtons)
53         }
54     }
55 
56     @Composable
Entrynull57     fun Entry() {
58         Preference(object : PreferenceModel {
59             override val title = TITLE
60             override val onClick = navigator(name)
61         })
62     }
63 }
64 
65 @Preview(showBackground = true)
66 @Composable
ActionButtonPagePreviewnull67 private fun ActionButtonPagePreview() {
68     SettingsTheme {
69         ActionButtonPageProvider.Page(null)
70     }
71 }
72