Add WearWidget sample#1371
Merged
Merged
Conversation
This commit adds a complete sample project demonstrating how to build Wear Widgets using Remote Compose for Wear OS. Key features included: - HelloWidget: A simple, static "Hello World" widget showing the minimal implementation required for a Wear Widget. - WeatherWidget: A widget that displays dynamic content based on stored state, demonstrating how to handle updates. - WeatherActivity: An in-app control panel to trigger weather condition updates manually. - WeatherUpdateReceiver: Allows simulating external data updates (like background sync) via ADB broadcasts. - Extensive UI previews and screenshots for documentation and testing. - Roborazzi tests for verifying widget rendering. This sample provides a foundation for building rich, interactive surfaces on Wear OS that complement main applications.
556f848 to
83d7305
Compare
Remove the static "Last updated: Just now" text from the Weather Widget as it is not needed for a sample and doesn't update. Also remove the corresponding string resource.
Update the broadcast command in README.md to use an explicit broadcast targeting WeatherUpdateReceiver, ensuring reliability on newer Android versions and when the app is stopped.
Update HelloWidget and WeatherWidget to use ColorScheme and RemoteColorScheme in provideWidgetData to set the document background to the theme's primary color (or fallback in WeatherWidget), ensuring rounded edges while using tokens. Update content functions to use onPrimary for text color.
Update the preview screenshots for the Hello and Weather widgets. The previous screenshots were reported as incorrect. Renamed the weather widget preview files from force_update_* to weather_widget_* to make them neater and updated the references in the manifest and XML configuration files. Took new screenshots for both widgets in all supported sizes (fullscreen, large, small) from the attached device.
Addressed comments from PR 1371: - Removed third-party preview plugin. - Parameterized HelloWidgetContent to use string resources. - Used enum for weather conditions instead of emojis. - Used constants for preference keys. - Used string resource with placeholders for weather text. - Removed unused string resource. - Kept both widget update options as requested. - Fixed formatting with Spotless. TAG=agy CONV=ef9976f5-6339-40df-8c55-2a10f8964496
Removed unused drawables and strings identified during audit, addressing reviewer feedback to clean up unused resources. These resources appeared to be leftovers from a removed catalog feature.
- Wrapped weatherStateFlow in remember to prevent redundant collection restarts. - Used entries instead of values() for enum iteration in WeatherCondition.fromEmoji.
- Removed redundant android.annotation. qualifier from SuppressLint. - Added comments explaining why RestrictedApi is suppressed. - Moved file-level comments to avoid Spotless failures.
- Used constants for intent actions and extras in WeatherUpdateReceiver. - Used shared coroutine scope in WeatherUpdateReceiver. - Fixed manifest indentation. - Removed extraneous comments in app/build.gradle.kts.
Removed app/screenshots and app/.compose-preview-history directories which contained unused previews and fonts, likely remnants of the removed preview plugin or older runs.
- Wrapped WeatherContent in a RemoteBox with a background in the preview to make white text readable. - Recorded new golden screenshots with Roborazzi.
- Explained that the shared scope in WeatherUpdateReceiver is a compromise for the sample. - Removed mention of the reviewer to keep justification standalone. - Applied formatting fixes with Spotless in WeatherWidget.
Upgrade remote-material3 to 1.0.0-alpha03 and core remote compose libraries to 1.0.0-alpha10. This resolves the ABI incompatibility issue, so the strictly pinned constraints are removed. Also upgrade glance wear to 1.0.0-alpha09 and tiles to 1.6.0.
Inline the logic of triggerUpdateOption2 directly into the calling sites in WeatherActivity and WeatherUpdateReceiver, removing the extracted functions. This adapts to breaking changes in triggerUpdate while avoiding unnecessary functions.
Add screenshots of HelloWidget and WeatherWidget to illustrate what the user gets when running the sample.
garanj
approved these changes
May 8, 2026
Remove unused `localColorScheme` and `remoteColorScheme` variables and imports in `WeatherWidget.kt`. Also simplify text color usage by removing `resolvedTextColor`.
Avoid repeating `WeatherWidget` class name by creating the instance first and using `widget::class` in `WeatherActivity` and `WeatherUpdateReceiver`.
Add WearWidgetPreviewSnapshot and WearWidgetParamsProviderSnapshot to support previewing widgets in different container sizes. These are temporary copies from a pending Gerrit change. Apply to HelloWidget.
Update comments in WearWidgetPreviewSnapshot and WearWidgetParamsProviderSnapshot to explicitly state that files should be removed and usages migrated to the library once the change lands.
Transition to standard @Preview and WearWidgetPreviewSnapshot, ensuring widgets are rendered at their appropriate sizes in Android Studio. - Remove WearPreviewDevices. - Update unit tests to use new preview functions. - Add RestrictedApi lint suppression to ParamsProvider.
- Applied the ee.schimke.composeai.preview plugin to the app module. - Refined WearWidgetPreviewSnapshot to wrap the preview in a simulated Wear OS watch face (circular, black background, pink border, Android logo, and title) to match the target look. - Added MockWeatherWidget to WeatherWidget.kt to hardcode temperature to 75 and condition to Sunny for the preview. This avoids changing production code. - This is a checkpoint commit.
kul3r4
reviewed
May 11, 2026
- Remove magenta border from WearWidgetPreviewSnapshot. - Fine-tune dimensions for PARAM_1 in WearWidgetParamsProviderSnapshot. - Adjust icon size and spacing in simulated watch face.
- Add optional title parameter to WearWidgetPreviewSnapshot. - Default title to class name with spaces. - Pass "Weather Widget" as title in WeatherWidgetPreview.
The ee.schimke.composeai.preview plugin was removed from the app's build configuration as it was not being used in the project. Verified by a successful build.
Add the missing small weather widget preview by copying the fullscreen version and referencing it in the XML.
- Centered widgets vertically on the watch face to prevent cropping. - Scaled watch face to 227dp. - Reduced large widget size to 180x90 dp to fit circular screen. - Made small widget width match large widget width (180dp).
Document that Wear Widgets are compatible with Wear OS 4 and above, leveraging the library's capability to translate them to Tiles on devices where native widgets are not supported.
Add a link to the Wear Widgets package summary on developer.android.com to address a review comment about missing documentation links.
yschimke
reviewed
May 12, 2026
yschimke
reviewed
May 12, 2026
yschimke
reviewed
May 12, 2026
yschimke
added a commit
to yschimke/homeassistant-remotecompose
that referenced
this pull request
May 15, 2026
Row 1's Wear S / Wear L cells now render through a new WatchFaceCell that mirrors the WearWidgetPreviewSnapshot helper from android/wear-os-samples#1371 — 227dp black circle, app icon + "Terrazzo slot" caption at the top, captured card offset 14dp below centre. Matches the SlotWidgetPreviews wear chrome so the matrix shows wear cells in their actual surface instead of as floating rectangles. The launcher-widget cells (row 2) are deliberately untouched — there is no equivalent home-screen frame in scope here. Per-preview heights bumped to fit the taller watch-face row 1. :previews can't depend on androidx.glance.wear without dragging the glance-wear stack into the previews module, so the watch-face chrome is duplicated locally rather than calling WearWidgetPreviewSnapshot through. Keep the two copies in sync if either side moves; both reference the same gerrit lineage in their KDoc.
yschimke
added a commit
to yschimke/homeassistant-remotecompose
that referenced
this pull request
May 15, 2026
* feat(wear): wrap slot widget previews in simulated watch face Mirrors the WearWidgetPreviewSnapshot helper from android/wear-os-samples#1371: a 227dp circular black surface with the app icon + label at the top and the captured Glance Wear widget rendered below. Gives slot widget @Preview entries the same watch-chrome context reviewers see in the wear-os-samples WearWidget sample so the slot card reads in its actual surface, not as a floating rectangle. SlotWidgetPreviewFixture now calls WearWidgetPreviewSnapshot instead of the bare WearWidgetPreview rectangle; the snapshot helper sits next to the existing vendored WearWidgetPreview / WearWidgetParamsProvider under androidx.glance.wear.tooling.preview. * feat(previews): frame matrix wear cells in watch-face chrome Row 1's Wear S / Wear L cells now render through a new WatchFaceCell that mirrors the WearWidgetPreviewSnapshot helper from android/wear-os-samples#1371 — 227dp black circle, app icon + "Terrazzo slot" caption at the top, captured card offset 14dp below centre. Matches the SlotWidgetPreviews wear chrome so the matrix shows wear cells in their actual surface instead of as floating rectangles. The launcher-widget cells (row 2) are deliberately untouched — there is no equivalent home-screen frame in scope here. Per-preview heights bumped to fit the taller watch-face row 1. :previews can't depend on androidx.glance.wear without dragging the glance-wear stack into the previews module, so the watch-face chrome is duplicated locally rather than calling WearWidgetPreviewSnapshot through. Keep the two copies in sync if either side moves; both reference the same gerrit lineage in their KDoc.
- Simplify ColorScheme usage in HelloWidget by using defaults. - Use stringResource in HelloWidgetContent. - Add comment in WeatherUpdateReceiver clarifying it's for sample use.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds a new sample,
WearWidget, to demonstrate building Wear Widgets using Remote Compose for Wear OS.Key Features
The
WearWidgetsample includes:These widgets leverage Remote Compose.
Also includes some code to improve the appearance of widget previews in Android Studio:
Verification
./gradlew clean buildin theWearWidgetdirectory.