Hi, When using Wear OS widgets with Remote Compos...
# compose-wear
m
Hi, When using Wear OS widgets with Remote Compose, is there any website or documentation showcasing examples of remote composables, such as
RemoteCard
, or demonstrating how to build custom layouts? I understand that this is different from migrating regular (non-remote) Wear OS composables to their remote equivalents. I'm specifically looking for examples and guidance on building custom layouts using Remote Compose. Thanks!
Also, I have a question about preview images for Wear OS widgets. When designing the preview images (small and large), what dimensions and specifications should we follow? While checking the Wear OS samples on GitHub (
WearWidget
and
hello-widget
), I found the following dimensions: • Fullscreen: 408 × 408 px, 96 PPI, 32-bit • Large: 609 × 378 px, 96 PPI, 32-bit • Small: 588 × 221 px, 96 PPI, 32-bit Are these the recommended or required dimensions? Is there any official documentation or design guidance for preparing these images when developing Wear OS widgets? Also, are there any specific requirements or quality checks for these preview images when publishing an app through Google Play Console?
And a component library here https://preview.coo.ee/remote-m3/
m
@yschimke i already checked the links you've provided, but, there are no official answers, these codes are experimental
y
Which ones? Most of the apis are now public. Let us know what you need that isn't.
y
cc @Michael Stillwell @chiara chiappini For the Preview Picker is it these ones that should be used?
Copy code
/**
 * A [PreviewParameterProvider] that provides Small-type widget configurations from the rectangular
 * specification with safe padding buffers.
 *
 * This set of parameters is purposely designed to help Wear widget developers generate and export
 * clean, rectangular screenshot preview assets for the Play Store and galleries where users can
 * choose their widgets. The preview configuration utilizes a square-cornered (rectangular)
 * specification and applies safe padding boundaries outside the content area to prevent clipping
 * when cropped to custom OEM widget shapes.
 */
public class RectangularSmallWidgetPreviewParams :
    BaseWidgetPreviewParams(RECTANGULAR_SMALL_PARAMS, WidgetPreviewConstants.RECTANGULAR_PREFIX)
which map to safe values to allow different OEM corner clipping on top of the preview image? cs.android.com/androidx/…/WidgetPreviewParams.kt;l=244?q=f:glance%20f:wear%20…
Copy code
private val RECTANGULAR_SMALL_PARAMS =
    sequenceOf(
        /**
         * A [WearWidgetParams] calculated as a safe grid-aligned (8dp/4dp) median configuration
         * with square corners to allow cropping to custom OEM shapes without clipping.
         */
        WearWidgetParams(
            instanceId = WidgetInstanceId(WidgetPreviewConstants.WIDGETS_NAMESPACE, 9),
            containerType = ContainerInfo.CONTAINER_TYPE_SMALL,
            widthDp = 192f,
            heightDp = 60f,
            verticalPaddingDp = 12f,
            horizontalPaddingDp = 16f,
            cornerRadiusDp = WidgetPreviewConstants.CORNER_RADIUS_RECTANGULAR_DP,
        )
    )

private val RECTANGULAR_LARGE_PARAMS =
    sequenceOf(
        /**
         * A [WearWidgetParams] calculated as a safe grid-aligned (8dp/4dp) median configuration
         * with square corners to allow cropping to custom OEM shapes without clipping.
         */
        WearWidgetParams(
            instanceId = WidgetInstanceId(WidgetPreviewConstants.WIDGETS_NAMESPACE, 10),
            containerType = ContainerInfo.CONTAINER_TYPE_LARGE,
            widthDp = 168f,
            heightDp = 112f,
            verticalPaddingDp = 16f,
            horizontalPaddingDp = 32f,
            cornerRadiusDp = WidgetPreviewConstants.CORNER_RADIUS_RECTANGULAR_DP,
        )
    )
Hence in WearWidget sample
Copy code
// Generates the uncropped rectangular preview images referenced by
// <container previewImage="@drawable/..." /> in res/xml/hello_widget_info.xml.
// Providing a full rectangular asset allows the system widget picker on each
// device (Pixel Watch, Galaxy Watch, etc.) to apply its own native shape mask.
@Preview(name = "Widget Picker Preview")
@Composable
fun HelloWidgetRectangularPreview(
    @PreviewParameter(RectangularSmallWidgetPreviewParams::class) params: WearWidgetParams
) {
    WearWidgetPreview(HelloWidget(), params)
}
c
yes, suggest to use the rectangular ones for the device picker
May I also recommend to try out our newly published skill github.com/android/skills/…/wear-widgets? And let us know if you have any feedback!
m
Hi, @chiara chiappini Question: The skill generate the images? Reading Build Wear OS widgets with Glance and Remote Compose, Step 4 url for skill implementation, i noticed that there are the guidelines for the preview container images. Question: How to write/execute ui tests for remote-compose for wearos? checking the official documentation, theres the dependencies for working, but not for the
androidTestImplementation
nor
testImplementation
y
We don't have stable APIs for it at the moment, but we have some test rules. // Source: mvnrepository.com/artifact/androidx.compose.remote/remote-testing androidTestImplementation("androidx.compose.remoteremote testing1.0.0-alpha22")
👍🏼 1
WearWidget sample uses the preview mechanism github.com/android/wear-os-samples/blob/…/HelloWidgetTest.kt
For interacting with the content, you will need to use ui-automator still testing.
m
@yschimke Understood. In the meantime, I'll continue reviewing the preview container images as outlined in the skill documentation.
I’m using the migration skill to migrate a Wear OS Tile UI (ProtoLayout) to a Widget (RemoteCompose / Glance), but the skill failed to reproduce my custom UI using Box or Surface containers. The AI agent in Android Studio even became unresponsive during the process. Is this UI migration supported by the current Widget architecture, or should I implement separate UIs for Tiles and Widgets? What is the recommended approach to preserve the original design while reusing as much code as possible?
Note: i’ve added an image of an ui for this scenario.
cc @chiara chiappini @yschimke
y
You have a choice. Dual Service: You can leave the Tile, and use all available space on older devices. On newer devices you’ll need to fit within the partial height format. developer.android.com/training/wearables/widgets/migration#… Single Service: But if you want to move to just a Wear Widget, it will put it inside a tile, but you can use all the space of the screen.
Can’t remember if you need to login, but this is Claude building a UI in about 3 minutes. ui.coo.ee/cranky-bandit
Code is
Copy code
// Generated from a Compose UI builder design. Do not edit by hand.

@RemoteComposable
@Composable
fun WearWidgetContent() {
    RemoteMaterialTheme {
        RemoteColumn(
            modifier = RemoteModifier.fillMaxSize(),
            verticalArrangement = RemoteArrangement.SpaceEvenly,
            horizontalAlignment = RemoteAlignment.CenterHorizontally,
        ) {
            RemoteText(
                text = "106500".rs,
                modifier = RemoteModifier.fillMaxWidth(),
                color = Color(0xFFA8C7FA).rc,
                style = RemoteMaterialTheme.typography.titleLarge,
                textAlign = TextAlign.Center,
                maxLines = 1,
            )
            RemoteRow(
                modifier = RemoteModifier.fillMaxWidth().weight(1.rf),
                horizontalArrangement = RemoteArrangement.SpaceEvenly,
                verticalAlignment = RemoteAlignment.CenterVertically,
            ) {
                RemoteBox(
                    modifier = RemoteModifier.weight(1.rf),
                    contentAlignment = RemoteAlignment.Center,
                ) {
                    RemoteText(
                        text = "−".rs,
                        color = Color(0xFFA8C7FA).rc,
                        style = RemoteMaterialTheme.typography.titleMedium,
                    )
                }
...
                RemoteBox(
                    modifier = RemoteModifier.weight(1.rf),
                    contentAlignment = RemoteAlignment.Center,
                ) {
                    RemoteText(
                        text = "=".rs,
                        color = Color(0xFFA8C7FA).rc,
                        style = RemoteMaterialTheme.typography.titleMedium,
                    )
                }
                RemoteBox(modifier = RemoteModifier.weight(1.rf))
            }
        }
    }
}

class WearWidget : GlanceWearWidget() {
    override suspend fun provideWidgetData(
        context: Context,
        params: WearWidgetParams,
    ): WearWidgetData {
        return WearWidgetDocument(background = WearWidgetBrush.color(Color(0xFF303038).rc)) {
            WearWidgetContent()
        }
    }
}

@Preview(name = "Rectangular Preview")
@Composable
fun WearWidgetRectangularPreview() =
    WearWidgetPreview(
        WearWidget(),
        RectangularLargeWidgetPreviewParams().values.maxBy { it.widthDp },
    )

@Preview(name = "Squircle Preview")
@Composable
fun WearWidgetSquirclePreview() =
    WearWidgetPreview(
        WearWidget(),
        SquircleLargeWidgetPreviewParams().values.maxBy { it.widthDp },
    )

@Preview(name = "Round Preview")
@Composable
fun WearWidgetRoundPreview() =
    WearWidgetPreview(
        WearWidget(),
        RoundLargeWidgetPreviewParams().values.maxBy { it.widthDp },
    )
m
@yschimke creo no se puede ver la url.
y
Ooops, give me an hour
Try that. There is a menu to toggle and see code
m
Parece que sigue inaacesible… > WebsiteNotVisibleException: El diseño remoto o la vista no es visible en el contexto actual. > at RemoteComposeRenderer.validateVisibility (/project/src/renderer/RemoteComposeRenderer.ts4215) > at RemoteComposeRenderer.renderDocument (/project/src/renderer/RemoteComposeRenderer.ts2522)
y
Ok, I'll export a gist.
I forgot to make it public. Sorry. Try one more time
m
Nice, already saw it, very accurate, it contains too many Box() composables and RemoteText, but, with all that, i can try implementing the ui i need, taking in mind of the preview and the available emulators in android studio @yschimke Thanks 🙂
y
Yep it's 100% agent coded and it tends to be verbose