Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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: 15 additions & 0 deletions wear/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,21 @@
android:resource="@drawable/tile_preview" />
</service>

<service
android:name=".snippets.tile.FeatureFallback"
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>

<activity
android:name=".snippets.alwayson.AlwaysOnActivity"
android:label="0 Stopwatch"
Expand Down
46 changes: 46 additions & 0 deletions wear/src/main/java/com/example/wear/snippets/tile/Tile.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ import android.content.Context
import androidx.annotation.RequiresPermission
import androidx.wear.protolayout.ColorBuilders.argb
import androidx.wear.protolayout.DimensionBuilders
import androidx.wear.protolayout.DimensionBuilders.degrees
import androidx.wear.protolayout.DimensionBuilders.dp
import androidx.wear.protolayout.LayoutElementBuilders
import androidx.wear.protolayout.LayoutElementBuilders.Arc
import androidx.wear.protolayout.LayoutElementBuilders.ArcLine
import androidx.wear.protolayout.LayoutElementBuilders.DashedArcLine
import androidx.wear.protolayout.ResourceBuilders.Resources
import androidx.wear.protolayout.TimelineBuilders
import androidx.wear.protolayout.TimelineBuilders.Timeline
Expand All @@ -30,6 +35,8 @@ import androidx.wear.protolayout.expression.DynamicBuilders
import androidx.wear.protolayout.expression.PlatformHealthSources
import androidx.wear.protolayout.material.Text
import androidx.wear.protolayout.material.Typography
import androidx.wear.protolayout.material3.materialScope
import androidx.wear.protolayout.material3.primaryLayout
import androidx.wear.tiles.RequestBuilders
import androidx.wear.tiles.RequestBuilders.ResourcesRequest
import androidx.wear.tiles.TileBuilders.Tile
Expand Down Expand Up @@ -200,3 +207,42 @@ class DynamicHeartRate : TileService() {
)
// [END android_wear_tile_dynamic_heart_rate]
}

class FeatureFallback : TileService() {
override fun onTileRequest(requestParams: RequestBuilders.TileRequest): ListenableFuture<Tile> {

// [START android_wear_tile_version_fallback]
val rendererVersion = requestParams.deviceConfiguration.rendererSchemaVersion

val arcElement =
if (
rendererVersion.major > 1 ||
(rendererVersion.major == 1 && rendererVersion.minor >= 500)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the significance of the 1 and 500 - can these be extracted to descriptive constants?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there's any way to usefully move them to constants. I moved and improved a comment to hopefully provide better context though, see 5ac6874.

) {
// Use DashedArcLine if the renderer supports it …
DashedArcLine.Builder() // Has @RequiresSchemaVersion(major = 1, minor = 500)
.setLength(degrees(270f))
.setThickness(8f)
.setLinePattern(
LayoutElementBuilders.DashedLinePattern.Builder()
.setGapSize(8f)
.setGapInterval(10f)
.build()
)
.build()
} else {
// … otherwise use ArcLine.
ArcLine.Builder().setLength(degrees(270f)).setThickness(dp(8f)).build()
}
// [END android_wear_tile_version_fallback]

val layout =
materialScope(this, requestParams.deviceConfiguration) {
primaryLayout(mainSlot = { Arc.Builder().addContent(arcElement).build() })
}

return Futures.immediateFuture(
Tile.Builder().setTileTimeline(Timeline.fromLayoutElement(layout)).build()
)
}
}