Add Footer for SpaLib

Footer text always at the end of page.

Bug: 235727273
Test: Manual with Codelab App
Change-Id: Id5a3990bcb8259d4acaa8e982b931f63ebd15581
This commit is contained in:
Chaohui Wang
2022-08-15 14:01:51 +08:00
parent 573398eddf
commit 2b942b0394
7 changed files with 211 additions and 0 deletions

View File

@@ -0,0 +1,71 @@
/*
* Copyright (C) 2022 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.codelab.page
import android.os.Bundle
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.runtime.Composable
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.android.settingslib.spa.framework.api.SettingsPageProvider
import com.android.settingslib.spa.framework.compose.navigator
import com.android.settingslib.spa.framework.compose.stateOf
import com.android.settingslib.spa.framework.theme.SettingsTheme
import com.android.settingslib.spa.widget.preference.Preference
import com.android.settingslib.spa.widget.preference.PreferenceModel
import com.android.settingslib.spa.widget.ui.Footer
object FooterPageProvider : SettingsPageProvider {
override val name = "Footer"
@Composable
override fun Page(arguments: Bundle?) {
FooterPage()
}
@Composable
fun EntryItem() {
Preference(object : PreferenceModel {
override val title = "Sample Footer"
override val onClick = navigator(name)
})
}
}
@Composable
private fun FooterPage() {
Column(Modifier.verticalScroll(rememberScrollState())) {
Preference(remember {
object : PreferenceModel {
override val title = "Some Preference"
override val summary = stateOf("Some summary")
}
})
Footer(footerText = "Footer text always at the end of page.")
}
}
@Preview(showBackground = true)
@Composable
private fun FooterPagePreview() {
SettingsTheme {
FooterPage()
}
}

View File

@@ -54,6 +54,7 @@ private fun HomePage() {
ArgumentPageProvider.EntryItem(stringParam = "foo", intParam = 0)
SliderPageProvider.EntryItem()
FooterPageProvider.EntryItem()
}
}

View File

@@ -33,6 +33,7 @@ val codelabPageRepository = SettingsPageRepository(
SwitchPreferencePageProvider,
ArgumentPageProvider,
SliderPageProvider,
FooterPageProvider,
),
startDestination = Destinations.Home,
)

View File

@@ -20,6 +20,7 @@ import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.ui.unit.dp
object SettingsDimension {
val itemIconSize = 24.dp
val itemIconContainerSize = 72.dp
val itemPaddingStart = 24.dp
val itemPaddingEnd = 16.dp

View File

@@ -0,0 +1,47 @@
/*
* Copyright (C) 2022 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.ui
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.Info
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import com.android.settingslib.spa.framework.theme.SettingsDimension
import com.android.settingslib.spa.framework.theme.SettingsTheme
@Composable
fun Footer(footerText: String) {
if (footerText.isEmpty()) return
Column(Modifier.padding(SettingsDimension.itemPadding)) {
SettingsIcon(imageVector = Icons.Outlined.Info, contentDescription = null)
Spacer(modifier = Modifier.height(SettingsDimension.itemPaddingVertical))
SettingsBody(footerText)
}
}
@Preview
@Composable
private fun FooterPreview() {
SettingsTheme {
Footer("Footer text always at the end of page.")
}
}

View File

@@ -0,0 +1,38 @@
/*
* Copyright (C) 2022 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.ui
import androidx.compose.foundation.layout.size
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.vector.ImageVector
import com.android.settingslib.spa.framework.theme.SettingsDimension
@Composable
fun SettingsIcon(
imageVector: ImageVector,
contentDescription: String?,
) {
Icon(
imageVector = imageVector,
contentDescription = contentDescription,
modifier = Modifier.size(SettingsDimension.itemIconSize),
tint = MaterialTheme.colorScheme.onSurface,
)
}

View File

@@ -0,0 +1,52 @@
/*
* Copyright (C) 2022 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.ui
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.State
@Composable
fun SettingsTitle(title: State<String>) {
SettingsTitle(title.value)
}
@Composable
fun SettingsTitle(title: String) {
Text(
text = title,
color = MaterialTheme.colorScheme.onSurface,
style = MaterialTheme.typography.titleMedium,
)
}
@Composable
fun SettingsBody(body: State<String>) {
SettingsBody(body.value)
}
@Composable
fun SettingsBody(body: String) {
if (body.isNotEmpty()) {
Text(
text = body,
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodyMedium,
)
}
}