Skip to content

Add WearWidget sample#1371

Merged
ithinkihaveacat merged 42 commits into
android:mainfrom
ithinkihaveacat:hello-widget
May 18, 2026
Merged

Add WearWidget sample#1371
ithinkihaveacat merged 42 commits into
android:mainfrom
ithinkihaveacat:hello-widget

Conversation

@ithinkihaveacat

@ithinkihaveacat ithinkihaveacat commented May 5, 2026

Copy link
Copy Markdown
Contributor

This PR adds a new sample, WearWidget, to demonstrate building Wear Widgets using Remote Compose for Wear OS.

Key Features

The WearWidget sample includes:

  • HelloWidget: A simple "Hello World" widget implementation.
  • WeatherWidget: A widget that displays dynamic content based on stored state, demonstrating state management and updates.

These widgets leverage Remote Compose.

Also includes some code to improve the appearance of widget previews in Android Studio:

Screenshot 2026-05-12 at 10 10 35 Screenshot 2026-05-12 at 10 10 29

Verification

  • Verified that the sample builds successfully using ./gradlew clean build in the WearWidget directory.

gemini-code-assist[bot]

This comment was marked as outdated.

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.
gemini-code-assist[bot]

This comment was marked as outdated.

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.
gemini-code-assist[bot]

This comment was marked as outdated.

- 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.
gemini-code-assist[bot]

This comment was marked as outdated.

- 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.
@ithinkihaveacat ithinkihaveacat marked this pull request as ready for review May 7, 2026 22:50
Add screenshots of HelloWidget and WeatherWidget to illustrate what the
user gets when running the sample.

@garanj garanj left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is great!

Comment thread WearWidget/README.md
Comment thread WearWidget/README.md
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 kul3r4 removed the request for review from shumelchyk May 11, 2026 13:01
Comment thread WearWidget/app/build.gradle.kts Outdated
- 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.
Comment thread WearWidget/app/src/main/java/com/google/example/wear_widget/HelloWidget.kt Outdated
Comment thread WearWidget/app/src/main/java/com/google/example/wear_widget/HelloWidget.kt Outdated
Comment thread WearWidget/app/src/test/screenshots/WeatherWidgetPreview.png
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.
@ithinkihaveacat ithinkihaveacat merged commit 7a11e6d into android:main May 18, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants