Marvil
Marvil

Reputation: 31

Make a SmallImage complication with an ambient image

I'm trying to make a WearOS Complication that is just an image. Ideally, it should display the image img1.png when on like this, and the image outlines.png when in ambient mode like this.

Right now, I've got

return when (request.complicationType) {

        ComplicationType.SMALL_IMAGE -> SmallImageComplicationData.Builder(
            smallImage = SmallImage.Builder(
                Icon.createWithResource(this, R.drawable.img1), SmallImageType.PHOTO).build(),
            contentDescription = PlainComplicationText
                .Builder(text = "Sample text").build()
        )
            .setTapAction(complicationPendingIntent)
            .build()

        else -> {
            if (Log.isLoggable(TAG, Log.WARN)) {
                Log.w(TAG, "Unexpected complication type ${request.complicationType}")
            }
            null
        }
    }

and I want to add the ambient image somewhere but don't know how. This code sample is inside the onComplicationRequest function, which returns ComplicationData? by the way. I have the same issue with

override fun getPreviewData(type: ComplicationType): ComplicationData {
    return SmallImageComplicationData.Builder(
        smallImage = SmallImage.Builder(
            Icon.createWithResource(this, R.drawable.img1), SmallImageType.PHOTO).build(),
        contentDescription = PlainComplicationText
            .Builder(text = "Your loved one's images!").build()
    )
        .setTapAction(null)
        .build()
}

which again, returns ComplicationData. Any ideas? Thanks! (The documentation for WearOS development is pretty incomplete imo :P)

Upvotes: 1

Views: 243

Answers (1)

Yuri Schimke
Yuri Schimke

Reputation: 13458

It's on SmallImage.Builder

https://developer.android.com/reference/androidx/wear/watchface/complications/data/SmallImage.Builder#setAmbientImage(android.graphics.drawable.Icon)

Try

        SmallImageComplicationData.Builder(
            smallImage = SmallImage.Builder(
                Icon.createWithResource(this, R.drawable.img1), SmallImageType.PHOTO)
              .setAmbientImage(...)
              .build(),
            contentDescription = PlainComplicationText
                .Builder(text = "Sample text").build()
        )
            .setTapAction(complicationPendingIntent)
            .build()

Upvotes: 1

Related Questions