Skip to content

Commit

Permalink
Init Wear Tiles snippets (#400)
Browse files Browse the repository at this point in the history
* Init Wear Tiles snippets

* Add snippet markers

* Add manifest snippet markers

* Rename manifest snippet markers
  • Loading branch information
ithinkihaveacat authored Nov 27, 2024
1 parent 515b08e commit fb654a9
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 0 deletions.
22 changes: 22 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ coroutines = "1.9.0"
glide = "1.0.0-beta01"
google-maps = "19.0.0"
gradle-versions = "0.51.0"
guava = "33.2.1-android"
hilt = "2.52"
horologist = "0.6.20"
junit = "4.13.2"
Expand All @@ -44,12 +45,22 @@ media3 = "1.4.1"
# @keep
minSdk = "21"
playServicesWearable = "18.2.0"
protolayout = "1.3.0-alpha04"
protolayoutExpression = "1.3.0-alpha04"
protolayoutMaterial = "1.3.0-alpha04"
recyclerview = "1.3.2"
# @keep
targetSdk = "34"
tiles = "1.5.0-alpha04"
tilesRenderer = "1.5.0-alpha04"
tilesTesting = "1.5.0-alpha04"
tilesTooling = "1.5.0-alpha04"
tilesToolingPreview = "1.5.0-alpha04"
version-catalog-update = "0.8.5"
wear = "1.3.0"
wearComposeFoundation = "1.4.0"
wearComposeMaterial = "1.4.0"
wearToolingPreview = "1.0.0"

[libraries]
accompanist-adaptive = { module = "com.google.accompanist:accompanist-adaptive", version.ref = "accompanist" }
Expand Down Expand Up @@ -103,10 +114,20 @@ androidx-media3-common = { module = "androidx.media3:media3-common", version.ref
androidx-media3-exoplayer = { module = "androidx.media3:media3-exoplayer", version.ref = "media3" }
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "androidx-navigation" }
androidx-paging-compose = { module = "androidx.paging:paging-compose", version.ref = "androidx-paging" }
androidx-protolayout = { module = "androidx.wear.protolayout:protolayout", version.ref = "protolayout" }
androidx-protolayout-expression = { module = "androidx.wear.protolayout:protolayout-expression", version.ref = "protolayoutExpression" }
androidx-protolayout-material = { module = "androidx.wear.protolayout:protolayout-material", version.ref = "protolayoutMaterial" }
androidx-recyclerview = { module = "androidx.recyclerview:recyclerview", version.ref = "recyclerview" }
androidx-test-core = { module = "androidx.test:core", version.ref = "androidx-test" }
androidx-test-espresso-core = { module = "androidx.test.espresso:espresso-core", version.ref = "androidx-test-espresso" }
androidx-test-runner = "androidx.test:runner:1.6.2"
androidx-tiles = { module = "androidx.wear.tiles:tiles", version.ref = "tiles" }
androidx-tiles-renderer = { module = "androidx.wear.tiles:tiles-renderer", version.ref = "tilesRenderer" }
androidx-tiles-testing = { module = "androidx.wear.tiles:tiles-testing", version.ref = "tilesTesting" }
androidx-tiles-tooling = { module = "androidx.wear.tiles:tiles-tooling", version.ref = "tilesTooling" }
androidx-tiles-tooling-preview = { module = "androidx.wear.tiles:tiles-tooling-preview", version.ref = "tilesToolingPreview" }
androidx-wear = { module = "androidx.wear:wear", version.ref = "wear" }
androidx-wear-tooling-preview = { module = "androidx.wear:wear-tooling-preview", version.ref = "wearToolingPreview" }
androidx-window-core = { module = "androidx.window:window-core", version.ref = "androidx-window" }
androidx-work-runtime-ktx = "androidx.work:work-runtime-ktx:2.10.0"
coil-kt-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil" }
Expand All @@ -117,6 +138,7 @@ glide-compose = { module = "com.github.bumptech.glide:compose", version.ref = "g
google-android-material = { module = "com.google.android.material:material", version.ref = "material" }
googlemaps-compose = { module = "com.google.maps.android:maps-compose", version.ref = "maps-compose" }
googlemaps-maps = { module = "com.google.android.gms:play-services-maps", version.ref = "google-maps" }
guava = { module = "com.google.guava:guava", version.ref = "guava" }
hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt" }
hilt-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hilt" }
horologist-compose-layout = { module = "com.google.android.horologist:horologist-compose-layout", version.ref = "horologist" }
Expand Down
11 changes: 11 additions & 0 deletions wear/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,17 @@ dependencies {

implementation(libs.compose.ui.tooling)
implementation(libs.play.services.wearable)
implementation(libs.androidx.tiles)
implementation(libs.androidx.wear)
implementation(libs.androidx.protolayout)
implementation(libs.androidx.protolayout.material)
implementation(libs.androidx.protolayout.expression)
debugImplementation(libs.androidx.tiles.renderer)
testImplementation(libs.androidx.tiles.testing)
implementation(libs.androidx.wear.tooling.preview)
implementation(libs.androidx.tiles.tooling.preview)
debugImplementation(libs.androidx.tiles.tooling)
implementation(libs.guava)
implementation(platform(libs.androidx.compose.bom))
implementation(libs.androidx.compose.ui)
implementation(libs.androidx.compose.ui.tooling.preview)
Expand Down
18 changes: 18 additions & 0 deletions wear/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<!-- [START android_wear_tile_manifest] -->
<service
android:name=".snippets.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_tile_manifest] -->

</application>

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

import androidx.wear.protolayout.ColorBuilders.argb
import androidx.wear.protolayout.ResourceBuilders.Resources
import androidx.wear.protolayout.TimelineBuilders.Timeline
import androidx.wear.protolayout.material.Text
import androidx.wear.protolayout.material.Typography
import androidx.wear.tiles.RequestBuilders
import androidx.wear.tiles.RequestBuilders.ResourcesRequest
import androidx.wear.tiles.TileBuilders.Tile
import androidx.wear.tiles.TileService
import com.google.common.util.concurrent.Futures

private const val RESOURCES_VERSION = "1"

// [START android_wear_tile_mytileservice]
class MyTileService : TileService() {

override fun onTileRequest(requestParams: RequestBuilders.TileRequest) =
Futures.immediateFuture(Tile.Builder()
.setResourcesVersion(RESOURCES_VERSION)
.setTileTimeline(
Timeline.fromLayoutElement(
Text.Builder(this, "Hello World!")
.setTypography(Typography.TYPOGRAPHY_BODY1)
.setColor(argb(0xFFFFFFFF.toInt()))
.build()))
.build())

override fun onTileResourcesRequest(requestParams: ResourcesRequest) =
Futures.immediateFuture(Resources.Builder()
.setVersion(RESOURCES_VERSION)
.build()
)

}
// [END android_wear_tile_mytileservice]
Binary file added wear/src/main/res/drawable/tile_preview.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions wear/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
<string name="voice_text_entry_label">Voice Input</string>
<string name="voice_input_label">Voice Text Entry</string>
<string name="message_list">Message List</string>
<string name="tile_label">Hello Tile</string>
<string name="tile_description">Hello Tile Description</string>
</resources>

0 comments on commit fb654a9

Please sign in to comment.