Skip to content

Commit

Permalink
Adds code for List using Horologist
Browse files Browse the repository at this point in the history
  • Loading branch information
kul3r4 committed Jul 4, 2024
1 parent 184d434 commit 010a9f1
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 9 deletions.
3 changes: 2 additions & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ material3-adaptive-navigation-suite = "1.0.0-alpha07"
media3 = "1.2.1"
# @keep
minSdk = "21"
playServicesWearable = "18.1.0"
playServicesWearable = "18.2.0"
recyclerview = "1.3.2"
# @keep
targetSdk = "34"
Expand Down Expand Up @@ -123,6 +123,7 @@ kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutine
kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "coroutines" }
play-services-wearable = { module = "com.google.android.gms:play-services-wearable", version.ref = "playServicesWearable" }
compose-ui-tooling = { group = "androidx.wear.compose", name = "compose-ui-tooling", version.ref = "composeUiTooling" }
androidx-material-icons-core = { module = "androidx.compose.material:material-icons-core" }

[plugins]
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
1 change: 1 addition & 0 deletions wear/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ dependencies {
implementation(libs.androidx.core.splashscreen)
implementation(libs.horologist.compose.layout)
implementation(libs.horologist.compose.material)
implementation(libs.androidx.material.icons.core)
androidTestImplementation(libs.androidx.compose.ui.test.junit4)
debugImplementation(libs.androidx.compose.ui.tooling)
debugImplementation(libs.androidx.compose.ui.test.manifest)
Expand Down
9 changes: 2 additions & 7 deletions wear/src/main/java/com/example/wear/snippets/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,20 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import com.example.wear.snippets.rotary.TimePicker
import com.google.android.horologist.annotations.ExperimentalHorologistApi
import com.example.wear.snippets.list.ComposeList

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)

setTheme(android.R.style.Theme_DeviceDefault)

setContent {
WearApp()
}
}
}

@OptIn(ExperimentalHorologistApi::class)
@Composable
fun WearApp() {
// insert here the snippet you want to test
TimePicker()
ComposeList()
}
110 changes: 110 additions & 0 deletions wear/src/main/java/com/example/wear/snippets/list/List.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/*
* Copyright 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
*
* 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 com.example.wear.snippets.list
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Build
import androidx.compose.runtime.Composable
import androidx.wear.compose.material.Text
import androidx.wear.compose.ui.tooling.preview.WearPreviewDevices
import androidx.wear.compose.ui.tooling.preview.WearPreviewFontScales
import com.google.android.horologist.annotations.ExperimentalHorologistApi
import com.google.android.horologist.compose.layout.ScalingLazyColumn
import com.google.android.horologist.compose.layout.ScalingLazyColumnDefaults
import com.google.android.horologist.compose.layout.ScalingLazyColumnState
import com.google.android.horologist.compose.layout.ScreenScaffold
import com.google.android.horologist.compose.layout.rememberResponsiveColumnState
import com.google.android.horologist.compose.material.Button
import com.google.android.horologist.compose.material.ListHeaderDefaults.firstItemPadding
import com.google.android.horologist.compose.material.ResponsiveListHeader

@OptIn(ExperimentalHorologistApi::class)
@Composable
fun ComposeList() {
// [START android_wear_list]
val columnState = rememberResponsiveColumnState(
contentPadding = ScalingLazyColumnDefaults.padding(
first = ScalingLazyColumnDefaults.ItemType.Text,
last = ScalingLazyColumnDefaults.ItemType.SingleButton
)
)
ScreenScaffold(scrollState = columnState) {
ScalingLazyColumn(
columnState = columnState
) {
item {
ResponsiveListHeader(contentPadding = firstItemPadding()) {
Text(text = "Header")
}
}
// ... other items
item {
Button(
imageVector = Icons.Default.Build,
contentDescription = "Example Button",
onClick = { }
)
}
}
}
// [END android_wear_list]
}

@OptIn(ExperimentalHorologistApi::class)
@Composable
fun SnapAndFlingComposeList() {
// [START android_wear_snap]
val columnState = rememberResponsiveColumnState(
// ...
// [START_EXCLUDE]
contentPadding = ScalingLazyColumnDefaults.padding(
first = ScalingLazyColumnDefaults.ItemType.Text,
last = ScalingLazyColumnDefaults.ItemType.SingleButton
),
// [END_EXCLUDE]
rotaryMode = ScalingLazyColumnState.RotaryMode.Snap
)
ScreenScaffold(scrollState = columnState) {
ScalingLazyColumn(
columnState = columnState
) {
// ...
// [START_EXCLUDE]
item {
ResponsiveListHeader(contentPadding = firstItemPadding()) {
Text(text = "Header")
}
}
// ... other items
item {
Button(
imageVector = Icons.Default.Build,
contentDescription = "Example Button",
onClick = { }
)
}
// [END_EXCLUDE]
}
}
// [END android_wear_snap]
}

@WearPreviewDevices
@WearPreviewFontScales
@Composable
fun ComposeListPreview() {
ComposeList()
}

0 comments on commit 010a9f1

Please sign in to comment.