Skip to content

Update to the 1.4/1.6 releases of android.wear.{protolayout,tiles}#1359

Draft
ithinkihaveacat wants to merge 8 commits intoandroid:mainfrom
ithinkihaveacat:tiles-1.6-update
Draft

Update to the 1.4/1.6 releases of android.wear.{protolayout,tiles}#1359
ithinkihaveacat wants to merge 8 commits intoandroid:mainfrom
ithinkihaveacat:tiles-1.6-update

Conversation

@ithinkihaveacat
Copy link
Copy Markdown
Contributor

Also updates:
- Compose to 1.10.3
- Android Gradle Plugin to 8.13.2
- Refactor MessagingTileService to inherit from Material3TileService
- Move resource loading and tile construction into tileResponse
- Refactor tileLayout to be an extension on MaterialScope
- Remove dependency on Horologist's SuspendingTileService for this component
- Use MaterialScope.image with ProtoLayoutScope for automatic resource registration
- Simplify tileResponse to leverage the new automated system in Material3TileService
- Fix Ali's avatar URL extension (.png -> .jpg) to resolve 404 error
- Ensure contacts without avatars correctly fallback to themed initials
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @ithinkihaveacat, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request primarily focuses on upgrading the Android Wear OS Protobuf Layout and Tiles libraries to their latest beta versions (1.4 and 1.6 respectively). This update necessitates significant refactoring across the codebase, particularly in how tile services are implemented and how image resources are managed and provided. The changes aim to align the sample code with the latest best practices and API changes introduced in these new library versions, ensuring compatibility and leveraging new features for more efficient resource handling and simplified tile creation.

Highlights

  • Dependency Updates: Updated androidx-wear-tiles to 1.6.0-beta01 and androidx-wear-protolayout to 1.4.0-beta01 in gradle/libs.versions.toml.
  • API Migration for Tile Services: Migrated BaseTileService implementations to the new TileService or Material3TileService APIs, specifically changing layout and resources overrides to onTileRequest or tileResponse.
  • Resource Handling Refactor: Refactored image resource handling across all golden tile examples. This includes replacing materialScope with materialScopeWithResources, introducing ProtoLayoutScope for resource collection, and updating image references from context.resources.getResourceName(R.drawable.xyz) to imageResource(androidImageResource(R.drawable.xyz)).
  • Simplified Image Mapping: Removed explicit resources functions and addIdToImageMapping calls from most tile examples, as the new materialScopeWithResources and ProtoLayoutScope now manage resource collection more efficiently.
  • TilePreviewData Updates: Adjusted TilePreviewData constructors to align with the new API, now accepting lambda functions for onTileRequest and onTileResourceRequest.
  • Messaging Tile Service Enhancements: The MessagingTileService now extends Material3TileService and uses the tileResponse method, simplifying the tile and resource request logic. Image loading for contacts was also streamlined.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • WearTilesKotlin/app/src/debug/java/com/example/wear/tiles/golden/Alarm.kt
    • Updated imports for new ProtoLayout and Tiles APIs.
    • Replaced materialScope with materialScopeWithResources.
    • Modified layout function signature to include ProtoLayoutScope.
    • Updated image resource references to use imageResource(androidImageResource(...)).
    • Removed the resources function and related addIdToImageMapping calls.
    • Migrated AlarmTileService from BaseTileService to TileService and updated layout to onTileRequest.
  • WearTilesKotlin/app/src/debug/java/com/example/wear/tiles/golden/Calendar.kt
    • Updated imports for new ProtoLayout and Tiles APIs.
    • Replaced materialScope with materialScopeWithResources.
    • Modified layout function signature to include ProtoLayoutScope.
    • Updated image resource references to use imageResource(androidImageResource(...)).
    • Removed the resources function and related addIdToImageMapping calls.
    • Migrated Calendar1TileService and Calendar2TileService from BaseTileService to TileService and updated layout to onTileRequest.
  • WearTilesKotlin/app/src/debug/java/com/example/wear/tiles/golden/Goal.kt
    • Updated imports for new ProtoLayout and Tiles APIs.
    • Replaced materialScope with materialScopeWithResources.
    • Modified layout function signature to include ProtoLayoutScope.
    • Updated image resource references to use imageResource(androidImageResource(...)).
    • Removed the resources function and related addIdToImageMapping calls.
    • Migrated GoalTileService from BaseTileService to TileService and updated layout to onTileRequest.
  • WearTilesKotlin/app/src/debug/java/com/example/wear/tiles/golden/Hike.kt
    • Updated imports for new ProtoLayout and Tiles APIs.
    • Replaced materialScope with materialScopeWithResources.
    • Modified layout function signature to include ProtoLayoutScope.
    • Updated image resource references to use imageResource(androidImageResource(...)).
    • Removed the resources function and related addIdToImageMapping calls.
    • Migrated HikeTileService from BaseTileService to TileService and updated layout to onTileRequest.
  • WearTilesKotlin/app/src/debug/java/com/example/wear/tiles/golden/Media.kt
    • Updated imports for new ProtoLayout and Tiles APIs.
    • Replaced materialScope with materialScopeWithResources.
    • Modified layout function signature to include ProtoLayoutScope.
    • Updated image resource references to use imageResource(androidImageResource(...)).
    • Removed the resources function and related addIdToImageMapping calls.
    • Migrated MediaTileService from BaseTileService to TileService and updated layout to onTileRequest.
    • Updated Playlist data class to use @DrawableRes Int? for imageId.
  • WearTilesKotlin/app/src/debug/java/com/example/wear/tiles/golden/Meditation.kt
    • Updated imports for new ProtoLayout and Tiles APIs.
    • Replaced materialScope with materialScopeWithResources.
    • Modified listLayout function signature to include ProtoLayoutScope.
    • Updated image resource references to use imageResource(androidImageResource(...)).
    • Removed the resources function and related addIdToImageMapping calls.
    • Migrated MindfulnessTileService from BaseTileService to TileService and updated layout to onTileRequest.
    • Updated MeditationTask data class to use @DrawableRes Int for iconId.
  • WearTilesKotlin/app/src/debug/java/com/example/wear/tiles/golden/News.kt
    • Updated imports for new ProtoLayout and Tiles APIs.
    • Replaced materialScope with materialScopeWithResources.
    • Modified layout function signature to include ProtoLayoutScope.
    • Updated image resource references to use imageResource(androidImageResource(...)).
    • Removed the resources function and related addIdToImageMapping calls.
    • Migrated NewsTileService from BaseTileService to TileService and updated layout to onTileRequest.
    • Updated ArticleData and newsCard to use @DrawableRes Int for imageResourceId.
  • WearTilesKotlin/app/src/debug/java/com/example/wear/tiles/golden/Ski.kt
    • Updated imports for new ProtoLayout and Tiles APIs.
    • Replaced materialScope with materialScopeWithResources.
    • Modified layout function signature to include ProtoLayoutScope.
    • Removed the resources function.
    • Migrated SkiTileService from BaseTileService to TileService and updated layout to onTileRequest.
  • WearTilesKotlin/app/src/debug/java/com/example/wear/tiles/golden/Social.kt
    • Updated imports for new ProtoLayout and Tiles APIs.
    • Replaced materialScope with materialScopeWithResources.
    • Modified layout function signature to include ProtoLayoutScope.
    • Removed the resources function and related addIdToImageMapping calls.
    • Migrated SocialTileService* from BaseTileService to TileService and updated layout to onTileRequest.
    • Updated Contact data class to remove avatarId: String? and adjusted contactButton logic accordingly.
  • WearTilesKotlin/app/src/debug/java/com/example/wear/tiles/golden/Timer.kt
    • Updated imports for new ProtoLayout and Tiles APIs.
    • Replaced materialScope with materialScopeWithResources.
    • Modified timer1Layout and timer2Layout function signatures to include ProtoLayoutScope.
    • Updated image resource references to use imageResource(androidImageResource(...)).
    • Removed the resources function and related addIdToImageMapping calls.
    • Migrated Timer1TileService and Timer2TileService from BaseTileService to TileService and updated layout to onTileRequest.
  • WearTilesKotlin/app/src/debug/java/com/example/wear/tiles/golden/Weather.kt
    • Updated imports for new ProtoLayout and Tiles APIs.
    • Replaced materialScope with materialScopeWithResources.
    • Modified layout function signature to include ProtoLayoutScope.
    • Updated image resource references to use imageResource(androidImageResource(...)).
    • Removed the resources function and related addIdToImageMapping calls.
    • Migrated WeatherTileService from BaseTileService to TileService and updated layout to onTileRequest.
    • Updated Forecast and Conditions data classes to use @DrawableRes Int for weatherIconId.
    • Extracted weather data creation into a private helper function weatherData().
  • WearTilesKotlin/app/src/debug/java/com/example/wear/tiles/golden/Workout.kt
    • Updated imports for new ProtoLayout and Tiles APIs.
    • Replaced materialScope with materialScopeWithResources.
    • Modified layout1 and layout2 function signatures to include ProtoLayoutScope.
    • Updated image resource references to use imageResource(androidImageResource(...)).
    • Removed the resources function and related addIdToImageMapping calls.
    • Migrated WorkoutTileService1 and WorkoutTileService2 from BaseTileService to TileService and updated layout to onTileRequest.
    • Updated workoutGraphicDataCard to use @DrawableRes Int for iconId.
  • WearTilesKotlin/app/src/main/java/com/example/wear/tiles/messaging/Contact.kt
    • Updated the avatar image extension for 'Ali C' from .png to .jpg.
  • WearTilesKotlin/app/src/main/java/com/example/wear/tiles/messaging/Layout.kt
    • Updated contactButton function signature to accept an ImageResource for avatar display.
    • Modified tileLayout to be an extension function of MaterialScope and accept a map of image resources.
    • Updated TilePreviewData to use materialScope and pass the collected image resources to tileLayout.
  • WearTilesKotlin/app/src/main/java/com/example/wear/tiles/messaging/Service.kt
    • Changed the base class from SuspendingTileService to Material3TileService.
    • Replaced tileRequest and resourcesRequest methods with a single tileResponse method.
    • Simplified the logic for loading and providing image resources within the tileResponse method.
    • Removed the DEBUG_RESOURCES constant.
  • WearTilesKotlin/app/src/main/java/com/example/wear/tiles/tools/Extensions.kt
    • Added a tile extension function for MaterialScope to simplify tile creation.
    • Added a MaterialScope.image extension function and deprecated the old image function.
  • WearTilesKotlin/gradle/libs.versions.toml
    • Updated android-gradle-plugin from 8.13.1 to 8.13.2.
    • Updated compose from 1.9.4 to 1.10.3.
    • Updated androidx-wear-tiles from 1.5.0 to 1.6.0-beta01.
    • Updated androidx-wear-protolayout from 1.3.0 to 1.4.0-beta01.
Activity
  • The pull request was created by ithinkihaveacat to update Android Wear OS library versions and associated code.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the android.wear.protolayout and android.wear.tiles dependencies to new major versions and refactors the codebase to adopt the new APIs. The changes are extensive, moving from manual resource management and BaseTileService to the more integrated TileService and materialScopeWithResources. Overall, the migration is well-executed across most of the tile implementations.

However, I've identified a few critical issues. There's a bug in Calendar.kt where an image resource is hardcoded due to an incomplete migration of its data model. Additionally, messaging/Layout.kt contains a couple of errors: a call to a non-existent method setImageResource and incorrect syntax for Kotlin's associate function, both of which will prevent the code from compiling. Please address these points to ensure the migration is complete and correct.

setWidth(expand())
setModifiers(LayoutModifier.clip(shapes.full).toProtoLayoutModifiers())
setResourceId(contact.imageResourceId())
setImageResource(imageResource, contact.imageResourceId())
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.

critical

The method setImageResource does not exist on LayoutElementBuilders.Image.Builder. This will cause a compilation error. It seems you intended to set the image resource for the avatar.

With the new protolayout API, you should use setResourceId. The ImageResource objects created in Service.kt need to be part of the tile's resource bundle. Since you are using Material3TileService, resource collection is mostly automatic when using composables like imageResource() inside the layout. However, you are creating ImageResource objects outside the layout lambda.

To fix this, you should ensure the ImageResource objects are correctly registered with an ID, and then use setResourceId(contact.imageResourceId()) here.

Comment on lines +147 to 155
data.imageId?.let {
{
backgroundImage(
protoLayoutResourceId = id,
resource = imageResource(
androidImageResource(R.drawable.photo_38)
),
contentScaleMode = CONTENT_SCALE_MODE_CROP
)
}
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.

high

The imageId from the Event data is being ignored here. The let block checks if data.imageId is not null, but then a hardcoded drawable R.drawable.photo_38 is used for the background image. This means the tile will always show the same background image regardless of the imageId provided in the Event data.

This seems to be due to an incomplete migration for this file. To fix this, you should update the Event data class to use an Int? for imageId instead of String?, and update its call sites. This is the pattern used in other files in this PR, like Media.kt.

After updating the data class, this block should be changed to use the imageId from the data, for example:

data.imageId?.let { imageResId ->
    {
        backgroundImage(
            resource = imageResource(
                androidImageResource(imageResId)
            ),
            contentScaleMode = CONTENT_SCALE_MODE_CROP
        )
    }
}

addIdToImageMapping(it.imageResourceId(), it.avatarSource.resourceId)
}
return TilePreviewData {
val imageResources = contacts.associate<Contact, String, ResourceBuilders.ImageResource> {
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.

medium

The explicit type arguments for associate are unnecessary and syntactically incorrect. The compiler can infer the types from the lambda expression. Please remove the explicit type arguments.

Suggested change
val imageResources = contacts.associate<Contact, String, ResourceBuilders.ImageResource> {
val imageResources = contacts.associate {

- Update Gradle to 9.3.1
- Update Android Gradle Plugin to 9.1.0
- Update Kotlin to 2.2.10
- Add recommended build features and compatibility flags to gradle.properties
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.

1 participant