Skip to content

Update to 1.5.0-beta01 #514

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ google-maps = "19.2.0"
gradle-versions = "0.52.0"
guava = "33.4.8-jre"
hilt = "2.56.2"
horologist = "0.6.23"
horologist = "0.7.10-alpha"
junit = "4.13.2"
kotlin = "2.1.20"
kotlinCoroutinesOkhttp = "1.0"
Expand All @@ -60,18 +60,19 @@ media3 = "1.6.1"
minSdk = "21"
okHttp = "4.12.0"
playServicesWearable = "19.0.0"
protolayout = "1.2.1"
protolayout = "1.3.0-beta02"
recyclerview = "1.4.0"
# @keep
androidx-xr-arcore = "1.0.0-alpha04"
androidx-xr-scenecore = "1.0.0-alpha04"
androidx-xr-compose = "1.0.0-alpha04"
targetSdk = "34"
tiles = "1.4.1"
tiles = "1.5.0-beta01"
version-catalog-update = "1.0.0"
wear = "1.3.0"
wearComposeFoundation = "1.4.1"
wearComposeMaterial = "1.4.1"
wearComposeFoundation = "1.5.0-beta01"
wearComposeMaterial = "1.5.0-beta01"
wearComposeMaterial3 = "1.5.0-beta01"
wearToolingPreview = "1.0.0"
webkit = "1.13.0"

Expand Down Expand Up @@ -135,6 +136,7 @@ androidx-paging-compose = { module = "androidx.paging:paging-compose", version.r
androidx-protolayout = { module = "androidx.wear.protolayout:protolayout", version.ref = "protolayout" }
androidx-protolayout-expression = { module = "androidx.wear.protolayout:protolayout-expression", version.ref = "protolayout" }
androidx-protolayout-material = { module = "androidx.wear.protolayout:protolayout-material", version.ref = "protolayout" }
androidx-protolayout-material3 = { module = "androidx.wear.protolayout:protolayout-material3", version.ref = "protolayout" }
androidx-recyclerview = { module = "androidx.recyclerview:recyclerview", version.ref = "recyclerview" }
androidx-startup-runtime = { module = "androidx.startup:startup-runtime", version.ref = "androidx-startup-runtime" }
androidx-test-core = { module = "androidx.test:core", version.ref = "androidx-test" }
Expand All @@ -159,7 +161,7 @@ androidx-xr-scenecore = { module = "androidx.xr.scenecore:scenecore", version.re
appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
coil-kt-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil" }
compose-foundation = { module = "androidx.wear.compose:compose-foundation", version.ref = "wearComposeFoundation" }
compose-material = { module = "androidx.wear.compose:compose-material", version.ref = "wearComposeMaterial" }
wear-compose-material = { module = "androidx.wear.compose:compose-material", version.ref = "wearComposeMaterial" }
compose-ui-tooling = { module = "androidx.wear.compose:compose-ui-tooling", version.ref = "composeUiTooling" }
glide-compose = { module = "com.github.bumptech.glide:compose", version.ref = "glide" }
google-android-material = { module = "com.google.android.material:material", version.ref = "material" }
Expand All @@ -179,6 +181,7 @@ kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-t
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okHttp" }
play-services-wearable = { module = "com.google.android.gms:play-services-wearable", version.ref = "playServicesWearable" }
wear-compose-material3 = { module = "androidx.wear.compose:compose-material3", version.ref = "wearComposeMaterial3" }

[plugins]
android-application = { id = "com.android.application", version.ref = "androidGradlePlugin" }
Expand Down
4 changes: 3 additions & 1 deletion wear/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ dependencies {
implementation(libs.androidx.wear)
implementation(libs.androidx.protolayout)
implementation(libs.androidx.protolayout.material)
implementation(libs.androidx.protolayout.material3)
implementation(libs.androidx.protolayout.expression)
debugImplementation(libs.androidx.tiles.renderer)
testImplementation(libs.androidx.tiles.testing)
Expand All @@ -69,7 +70,8 @@ dependencies {
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.ui.tooling.preview)
implementation(libs.compose.material)
implementation(libs.wear.compose.material)
implementation(libs.wear.compose.material3)
implementation(libs.compose.foundation)
implementation(libs.androidx.activity.compose)
implementation(libs.androidx.core.splashscreen)
Expand Down
19 changes: 18 additions & 1 deletion wear/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
android:value="true" />

<activity
android:name=".snippets.MainActivity"
android:name=".snippets.m3.MainActivity"
android:exported="true"
android:taskAffinity=""
android:theme="@android:style/Theme.DeviceDefault">
Expand Down Expand Up @@ -52,6 +52,23 @@
</service>
<!-- [END android_wear_tile_manifest] -->

<!-- [START android_wear_m3_tile_manifest] -->
<service
android:name=".snippets.m3.tile.MyTileService"
android:label="@string/tile_label"
android:description="@string/tile_description"
android:icon="@mipmap/ic_launcher"
android:exported="true"
android:permission="com.google.android.wearable.permission.BIND_TILE_PROVIDER">
<intent-filter>
<action android:name="androidx.wear.tiles.action.BIND_TILE_PROVIDER" />
</intent-filter>

<meta-data android:name="androidx.wear.tiles.PREVIEW"
android:resource="@drawable/tile_preview" />
</service>
<!-- [END android_wear_m3_tile_manifest] -->

</application>

</manifest>
39 changes: 39 additions & 0 deletions wear/src/main/java/com.example.wear.snippets.m3/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Copyright 2021 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.m3

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.runtime.Composable
import com.example.wear.snippets.m3.list.ComposeList

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

setContent {
WearApp()
}
}
}

@Composable
fun WearApp() {
// insert here the snippet you want to test
ComposeList()
}
175 changes: 175 additions & 0 deletions wear/src/main/java/com.example.wear.snippets.m3/list/List.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/*
* 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.m3.list

import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Build
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.text.style.TextOverflow
import androidx.wear.compose.foundation.lazy.TransformingLazyColumn
import androidx.wear.compose.foundation.lazy.rememberTransformingLazyColumnState
import androidx.wear.compose.material3.Button
import androidx.wear.compose.material3.Icon
import androidx.wear.compose.material3.ListHeader
import androidx.wear.compose.material3.ScreenScaffold
import androidx.wear.compose.material3.SurfaceTransformation
import androidx.wear.compose.material3.Text
import androidx.wear.compose.material3.lazy.rememberTransformationSpec
import androidx.wear.compose.material3.lazy.transformedHeight
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.ColumnItemType
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.rememberResponsiveColumnPadding
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

@Composable
fun ComposeList() {
// [START android_wear_list]
val columnState = rememberTransformingLazyColumnState()
val contentPadding = rememberResponsiveColumnPadding(
first = ColumnItemType.ListHeader,
last = ColumnItemType.Button,
)
val transformationSpec = rememberTransformationSpec()
ScreenScaffold(
scrollState = columnState,
contentPadding = contentPadding
) { contentPadding ->
TransformingLazyColumn(
state = columnState,
contentPadding = contentPadding
) {
item {
ListHeader(
modifier = Modifier.fillMaxWidth().transformedHeight(this, transformationSpec),
transformation = SurfaceTransformation(transformationSpec)
) {
Text(text = "Header")
}
}
// ... other items
item {
Button(
modifier = Modifier.fillMaxWidth().transformedHeight(this, transformationSpec),
transformation = SurfaceTransformation(transformationSpec),
onClick = { /* ... */ },
icon = {
Icon(
imageVector = Icons.Default.Build,
contentDescription = "build",
)
},
) {
Text(
text = "Build",
maxLines = 1,
overflow = TextOverflow.Ellipsis,
)
}
}
}
}
// [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()) {
androidx.wear.compose.material.Text(text = "Header")
}
}
// ... other items
item {
Button(
imageVector = Icons.Default.Build,
contentDescription = "Example Button",
onClick = { }
)
}
// [END_EXCLUDE]
}
}
// [END android_wear_snap]
}

// [START android_wear_list_breakpoint]
const val LARGE_DISPLAY_BREAKPOINT = 225

@Composable
fun isLargeDisplay() =
LocalConfiguration.current.screenWidthDp >= LARGE_DISPLAY_BREAKPOINT

// [START_EXCLUDE]
@Composable
fun breakpointDemo() {
// [END_EXCLUDE]
// ... use in your Composables:
if (isLargeDisplay()) {
// Show additional content.
} else {
// Show content only for smaller displays.
}
// [START_EXCLUDE]
}
// [END_EXCLUDE]
// [END android_wear_list_breakpoint]

// [START android_wear_list_preview]
@WearPreviewDevices
@WearPreviewFontScales
@Composable
fun ComposeListPreview() {
ComposeList()
}
// [END android_wear_list_preview]

@WearPreviewDevices
@WearPreviewFontScales
@Composable
fun SnapAndFlingComposeListPreview() {
SnapAndFlingComposeList()
}
Loading