Skip to content

Commit

Permalink
Merge branch 'android:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
kul3r4 authored Mar 8, 2024
2 parents c6821ea + 603ea7b commit dd98dbe
Show file tree
Hide file tree
Showing 45 changed files with 154 additions and 54 deletions.
4 changes: 2 additions & 2 deletions AlwaysOnKotlin/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
[versions]
android-gradle-plugin = "8.3.0"
androidx-activity = "1.8.2"
androidx-compose-bom = "2024.02.01"
androidx-compose-bom = "2024.02.02"
androidx-lifecycle = "2.7.0"
androidx-wear-compose = "1.3.0"
compose-compiler = "1.5.10"
compose-ui-tooling = "1.3.0"
horologist-compose-layout = "0.5.22"
horologist-compose-layout = "0.5.24"
ktlint = "0.50.0"
org-jetbrains-kotlin = "1.9.22"
org-jetbrains-kotlinx = "1.8.0"
Expand Down
6 changes: 3 additions & 3 deletions ComposeAdvanced/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
android-gradle-plugin = "8.3.0"
androidx-activity = "1.8.2"
androidx-benchmark = "1.2.3"
androidx-compose-bom = "2024.02.01"
androidx-compose-bom = "2024.02.02"
androidx-lifecycle = "2.7.0"
androidx-test-espresso = "3.5.1"
androidx-test-ext = "1.1.5"
androidx-test-uiautomator = "2.3.0"
androidx-wear-compose = "1.3.0"
compose = "1.6.2"
compose = "1.6.3"
compose-compiler = "1.5.10"
horologist = "0.5.22"
horologist = "0.5.24"
ktlint = "0.50.0"
navigation = "2.7.7"
org-jetbrains-kotlin = "1.9.22"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@file:OptIn(ExperimentalHorologistApi::class)
@file:OptIn(ExperimentalHorologistApi::class, ExperimentalWearFoundationApi::class)

package com.example.android.wearable.composestarter.presentation

Expand All @@ -30,16 +30,19 @@ import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Build
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.wear.compose.material.ListHeader
import androidx.wear.compose.foundation.ExperimentalWearFoundationApi
import androidx.wear.compose.material.MaterialTheme
import androidx.wear.compose.material.Text
import androidx.wear.compose.material.TitleCard
import androidx.wear.compose.material.dialog.Dialog
import androidx.wear.compose.navigation.SwipeDismissableNavHost
import androidx.wear.compose.navigation.composable
import androidx.wear.compose.navigation.rememberSwipeDismissableNavController
Expand All @@ -50,10 +53,15 @@ import com.example.android.wearable.composestarter.presentation.theme.WearAppThe
import com.google.android.horologist.annotations.ExperimentalHorologistApi
import com.google.android.horologist.compose.layout.AppScaffold
import com.google.android.horologist.compose.layout.ScalingLazyColumn
import com.google.android.horologist.compose.layout.ScalingLazyColumnDefaults
import com.google.android.horologist.compose.layout.ScalingLazyColumnDefaults.ItemType
import com.google.android.horologist.compose.layout.ScreenScaffold
import com.google.android.horologist.compose.layout.rememberColumnState
import com.google.android.horologist.compose.layout.rememberResponsiveColumnState
import com.google.android.horologist.compose.material.AlertContent
import com.google.android.horologist.compose.material.Button
import com.google.android.horologist.compose.material.Chip
import com.google.android.horologist.compose.material.ListHeaderDefaults.firstItemPadding
import com.google.android.horologist.compose.material.ResponsiveListHeader
import com.google.android.horologist.compose.rotaryinput.rotaryWithScroll

/**
Expand Down Expand Up @@ -89,7 +97,10 @@ fun WearApp() {
AppScaffold {
SwipeDismissableNavHost(navController = navController, startDestination = "menu") {
composable("menu") {
GreetingScreen("Android", onShowList = { navController.navigate("list") })
GreetingScreen(
"Android",
onShowList = { navController.navigate("list") }
)
}
composable("list") {
ListScreen()
Expand All @@ -103,20 +114,21 @@ fun WearApp() {
fun GreetingScreen(greetingName: String, onShowList: () -> Unit) {
val scrollState = ScrollState(0)

// Wear design guidelines specify a 5.2% horizontal padding on each side of the list.
val horizontalPadding = (0.052f * LocalConfiguration.current.screenWidthDp).dp

/* If you have enough items in your list, use [ScalingLazyColumn] which is an optimized
* version of LazyColumn for wear devices with some added features. For more information,
* see d.android.com/wear/compose.
*/
ScreenScaffold(scrollState = scrollState) {
val padding = ScalingLazyColumnDefaults.padding(
first = ItemType.Text,
last = ItemType.Chip
)()
Column(
modifier = Modifier
.fillMaxSize()
.verticalScroll(scrollState)
.rotaryWithScroll(scrollState)
.padding(horizontal = horizontalPadding),
.padding(padding),
verticalArrangement = Arrangement.Center
) {
Greeting(greetingName = greetingName)
Expand All @@ -127,7 +139,18 @@ fun GreetingScreen(greetingName: String, onShowList: () -> Unit) {

@Composable
fun ListScreen() {
val columnState = rememberColumnState()
var showDialog by remember { mutableStateOf(false) }

/*
* Specifying the types of items that appear at the start and end of the list ensures that the
* appropriate padding is used.
*/
val columnState = rememberResponsiveColumnState(
contentPadding = ScalingLazyColumnDefaults.padding(
first = ItemType.Text,
last = ItemType.SingleButton
)
)

ScreenScaffold(scrollState = columnState) {
/*
Expand All @@ -141,8 +164,8 @@ fun ListScreen() {
.fillMaxSize()
) {
item {
ListHeader {
Text("Header")
ResponsiveListHeader(contentPadding = firstItemPadding()) {
Text(text = "Header")
}
}
item {
Expand All @@ -157,21 +180,72 @@ fun ListScreen() {
Button(
imageVector = Icons.Default.Build,
contentDescription = "Example Button",
onClick = { }
onClick = { showDialog = true }
)
}
}
}

SampleDialog(
showDialog = showDialog,
onDismiss = { showDialog = false },
onCancel = {},
onOk = {}
)
}

@Composable
fun Greeting(greetingName: String) {
Text(
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
color = MaterialTheme.colors.primary,
text = stringResource(R.string.hello_world, greetingName)
)
ResponsiveListHeader(contentPadding = firstItemPadding()) {
Text(
modifier = Modifier.fillMaxWidth(),
textAlign = TextAlign.Center,
color = MaterialTheme.colors.primary,
text = stringResource(R.string.hello_world, greetingName)
)
}
}

@Composable
fun SampleDialog(
showDialog: Boolean,
onDismiss: () -> Unit,
onCancel: () -> Unit,
onOk: () -> Unit
) {
val state = rememberResponsiveColumnState()

Dialog(
showDialog = showDialog,
onDismissRequest = onDismiss,
scrollState = state.state
) {
SampleDialogContent(onCancel, onDismiss, onOk)
}
}

@Composable
fun SampleDialogContent(
onCancel: () -> Unit,
onDismiss: () -> Unit,
onOk: () -> Unit
) {
AlertContent(
icon = {},
title = "Title",
onCancel = {
onCancel()
onDismiss()
},
onOk = {
onOk()
onDismiss()
}
) {
item {
Text(text = "An unknown error occurred during the request.")
}
}
}

@WearPreviewDevices
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,13 @@
*/
package presentation

import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.unit.dp
import androidx.wear.compose.material.TimeSource
import androidx.wear.compose.material.TimeText

/**
* Provides a [TimeText] composable that applies the correct percentage-based padding.
* TODO: This composable should be removed when ResponsiveTimeText is available in Horologist 0.5.x
* Provides a fixed time source for use with [ResponsiveTimeText]
*/
@Composable
fun ResponsiveFixedSourceTimeText() {
val height = LocalConfiguration.current.screenHeightDp
val padding = height * 0.021
TimeText(
contentPadding = PaddingValues(padding.dp),
timeSource = object : TimeSource {
override val currentTime: String
@Composable get() = "10:10"
}
)
val FixedTimeSource = object : TimeSource {
override val currentTime: String
@Composable get() = "10:10"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package presentation

import com.example.android.wearable.composestarter.presentation.GreetingScreen
import com.google.android.horologist.compose.layout.AppScaffold
import com.google.android.horologist.compose.layout.ResponsiveTimeText
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.ParameterizedRobolectricTestRunner
Expand All @@ -28,7 +29,7 @@ class GreetingScreenTest(override val device: WearDevice) : WearScreenshotTest()
@Test
fun greetingScreenTest() = runTest {
AppScaffold(
timeText = { ResponsiveFixedSourceTimeText() }
timeText = { ResponsiveTimeText(timeSource = FixedTimeSource) }
) {
GreetingScreen(greetingName = "screenshot", onShowList = {})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.ui.test.performTouchInput
import androidx.compose.ui.test.swipeUp
import com.example.android.wearable.composestarter.presentation.ListScreen
import com.google.android.horologist.compose.layout.AppScaffold
import com.google.android.horologist.compose.layout.ResponsiveTimeText
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.ParameterizedRobolectricTestRunner
Expand All @@ -33,7 +34,7 @@ class ListScreenTest(override val device: WearDevice) : WearScreenshotTest() {
fun listScreenTest() {
runTest {
AppScaffold(
timeText = { ResponsiveFixedSourceTimeText() }
timeText = { ResponsiveTimeText(timeSource = FixedTimeSource) }
) {
ListScreen()
}
Expand Down
37 changes: 37 additions & 0 deletions ComposeStarter/app/src/test/java/presentation/SampleDialogTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 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
*
* https://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 presentation

import com.example.android.wearable.composestarter.presentation.SampleDialogContent
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.ParameterizedRobolectricTestRunner

@RunWith(ParameterizedRobolectricTestRunner::class)
class SampleDialogTest(override val device: WearDevice) : WearScreenshotTest() {
override val tolerance = 0.02f

@Test
fun greetingScreenTest() = runTest {
SampleDialogContent(onCancel = { }, onDismiss = { }, onOk = {})
}

companion object {
@JvmStatic
@ParameterizedRobolectricTestRunner.Parameters
fun devices() = WearDevice.entries
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 4 additions & 4 deletions ComposeStarter/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
[versions]
android-gradle-plugin = "8.3.0"
androidx-activity = "1.8.2"
androidx-compose-bom = "2024.02.01"
androidx-compose-bom = "2024.02.02"
androidx-wear-compose = "1.3.0"
compose-compiler = "1.5.10"
compose-ui-tooling = "1.3.0"
horologist = "0.5.22"
horologist = "0.5.24"
ktlint = "0.50.0"
org-jetbrains-kotlin = "1.9.22"
robolectric = "4.11.1"
roborazzi = "1.10.1"
ui-test-junit4 = "1.6.2"
ui-test-manifest = "1.6.2"
ui-test-junit4 = "1.6.3"
ui-test-manifest = "1.6.3"

[libraries]
androidx-activity-compose = { module = "androidx.activity:activity-compose", version.ref = "androidx-activity" }
Expand Down
2 changes: 1 addition & 1 deletion DataLayer/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
android-gradle-plugin = "8.3.0"
androidx-activity = "1.8.2"
androidx-compose-bom = "2024.02.01"
androidx-compose-bom = "2024.02.02"
androidx-lifecycle = "2.7.0"
androidx-wear-compose = "1.3.0"
compose-compiler = "1.5.10"
Expand Down
2 changes: 1 addition & 1 deletion WearOAuth/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ androidx-test = "1.5.2"
androidx-wear-compose = "1.3.0"
androidx-wear-tiles = "1.3.0"
androidx-wear-watchface = "1.2.1"
compose = "1.6.2"
compose = "1.6.3"
compose-compiler = "1.5.10"
org-jetbrains-kotlin = "1.9.22"
org-jetbrains-kotlinx = "1.8.0"
Expand Down
2 changes: 1 addition & 1 deletion WearSpeakerSample/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
android-gradle-plugin = "8.3.0"
androidx-activity = "1.8.2"
androidx-compose-bom = "2024.02.01"
androidx-compose-bom = "2024.02.02"
androidx-lifecycle = "2.7.0"
androidx-wear-compose = "1.3.0"
compose-compiler = "1.5.10"
Expand Down
2 changes: 1 addition & 1 deletion WearStandaloneGoogleSignIn/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
android-gradle-plugin = "8.3.0"
androidx-activity = "1.8.2"
androidx-compose-bom = "2024.02.01"
androidx-compose-bom = "2024.02.02"
androidx-wear-compose = "1.3.0"
compose-compiler = "1.5.10"
ktlint = "0.50.0"
Expand Down
Loading

0 comments on commit dd98dbe

Please sign in to comment.