Skip to content

Commit 5a16f7c

Browse files
authored
Merge pull request #286 from android/wear
Adds code for List using Horologist
2 parents 9754666 + 010a9f1 commit 5a16f7c

File tree

5 files changed

+116
-9
lines changed

5 files changed

+116
-9
lines changed

gradle/libs.versions.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ material3-adaptive-navigation-suite = "1.0.0-alpha07"
4141
media3 = "1.2.1"
4242
# @keep
4343
minSdk = "21"
44-
playServicesWearable = "18.1.0"
44+
playServicesWearable = "18.2.0"
4545
recyclerview = "1.3.2"
4646
# @keep
4747
targetSdk = "34"
@@ -123,6 +123,7 @@ kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutine
123123
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
124124
play-services-wearable = { module = "com.google.android.gms:play-services-wearable", version.ref = "playServicesWearable" }
125125
compose-ui-tooling = { group = "androidx.wear.compose", name = "compose-ui-tooling", version.ref = "composeUiTooling" }
126+
androidx-material-icons-core = { module = "androidx.compose.material:material-icons-core" }
126127

127128
[plugins]
128129
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }

gradle/wrapper/gradle-wrapper.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
44
networkTimeout=10000
55
validateDistributionUrl=true
66
zipStoreBase=GRADLE_USER_HOME

wear/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ dependencies {
6565
implementation(libs.androidx.core.splashscreen)
6666
implementation(libs.horologist.compose.layout)
6767
implementation(libs.horologist.compose.material)
68+
implementation(libs.androidx.material.icons.core)
6869
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
6970
debugImplementation(libs.androidx.compose.ui.tooling)
7071
debugImplementation(libs.androidx.compose.ui.test.manifest)

wear/src/main/java/com/example/wear/snippets/MainActivity.kt

+2-7
Original file line numberDiff line numberDiff line change
@@ -20,25 +20,20 @@ import android.os.Bundle
2020
import androidx.activity.ComponentActivity
2121
import androidx.activity.compose.setContent
2222
import androidx.compose.runtime.Composable
23-
import com.example.wear.snippets.rotary.TimePicker
24-
import com.google.android.horologist.annotations.ExperimentalHorologistApi
23+
import com.example.wear.snippets.list.ComposeList
2524

2625
class MainActivity : ComponentActivity() {
2726
override fun onCreate(savedInstanceState: Bundle?) {
28-
2927
super.onCreate(savedInstanceState)
3028

31-
setTheme(android.R.style.Theme_DeviceDefault)
32-
3329
setContent {
3430
WearApp()
3531
}
3632
}
3733
}
3834

39-
@OptIn(ExperimentalHorologistApi::class)
4035
@Composable
4136
fun WearApp() {
4237
// insert here the snippet you want to test
43-
TimePicker()
38+
ComposeList()
4439
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* Copyright 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+
* https://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.example.wear.snippets.list
18+
import androidx.compose.material.icons.Icons
19+
import androidx.compose.material.icons.filled.Build
20+
import androidx.compose.runtime.Composable
21+
import androidx.wear.compose.material.Text
22+
import androidx.wear.compose.ui.tooling.preview.WearPreviewDevices
23+
import androidx.wear.compose.ui.tooling.preview.WearPreviewFontScales
24+
import com.google.android.horologist.annotations.ExperimentalHorologistApi
25+
import com.google.android.horologist.compose.layout.ScalingLazyColumn
26+
import com.google.android.horologist.compose.layout.ScalingLazyColumnDefaults
27+
import com.google.android.horologist.compose.layout.ScalingLazyColumnState
28+
import com.google.android.horologist.compose.layout.ScreenScaffold
29+
import com.google.android.horologist.compose.layout.rememberResponsiveColumnState
30+
import com.google.android.horologist.compose.material.Button
31+
import com.google.android.horologist.compose.material.ListHeaderDefaults.firstItemPadding
32+
import com.google.android.horologist.compose.material.ResponsiveListHeader
33+
34+
@OptIn(ExperimentalHorologistApi::class)
35+
@Composable
36+
fun ComposeList() {
37+
// [START android_wear_list]
38+
val columnState = rememberResponsiveColumnState(
39+
contentPadding = ScalingLazyColumnDefaults.padding(
40+
first = ScalingLazyColumnDefaults.ItemType.Text,
41+
last = ScalingLazyColumnDefaults.ItemType.SingleButton
42+
)
43+
)
44+
ScreenScaffold(scrollState = columnState) {
45+
ScalingLazyColumn(
46+
columnState = columnState
47+
) {
48+
item {
49+
ResponsiveListHeader(contentPadding = firstItemPadding()) {
50+
Text(text = "Header")
51+
}
52+
}
53+
// ... other items
54+
item {
55+
Button(
56+
imageVector = Icons.Default.Build,
57+
contentDescription = "Example Button",
58+
onClick = { }
59+
)
60+
}
61+
}
62+
}
63+
// [END android_wear_list]
64+
}
65+
66+
@OptIn(ExperimentalHorologistApi::class)
67+
@Composable
68+
fun SnapAndFlingComposeList() {
69+
// [START android_wear_snap]
70+
val columnState = rememberResponsiveColumnState(
71+
// ...
72+
// [START_EXCLUDE]
73+
contentPadding = ScalingLazyColumnDefaults.padding(
74+
first = ScalingLazyColumnDefaults.ItemType.Text,
75+
last = ScalingLazyColumnDefaults.ItemType.SingleButton
76+
),
77+
// [END_EXCLUDE]
78+
rotaryMode = ScalingLazyColumnState.RotaryMode.Snap
79+
)
80+
ScreenScaffold(scrollState = columnState) {
81+
ScalingLazyColumn(
82+
columnState = columnState
83+
) {
84+
// ...
85+
// [START_EXCLUDE]
86+
item {
87+
ResponsiveListHeader(contentPadding = firstItemPadding()) {
88+
Text(text = "Header")
89+
}
90+
}
91+
// ... other items
92+
item {
93+
Button(
94+
imageVector = Icons.Default.Build,
95+
contentDescription = "Example Button",
96+
onClick = { }
97+
)
98+
}
99+
// [END_EXCLUDE]
100+
}
101+
}
102+
// [END android_wear_snap]
103+
}
104+
105+
@WearPreviewDevices
106+
@WearPreviewFontScales
107+
@Composable
108+
fun ComposeListPreview() {
109+
ComposeList()
110+
}

0 commit comments

Comments
 (0)