HeadlessWatchFaceClient


interface HeadlessWatchFaceClient : AutoCloseable


Controls a stateless remote headless watch face. This is mostly intended for use by watch face editor UIs which need to generate screenshots for various styling configurations without affecting the current watchface.

Note clients should call close when finished.

Summary

Nested types

Callback that observes when the client disconnects.

Public companion functions

HeadlessWatchFaceClient

Public functions

Unit

Registers a ClientDisconnectListener.

open UserStyleFlavors

Returns the watch face's UserStyleFlavors if any.

open ByteArray

A SHA-1 MessageDigest hash of the UserStyleSchema.

Boolean

Returns true if the connection to the server side is alive.

Unit

Removes a ClientDisconnectListener previously registered by addClientDisconnectListener.

Bitmap?
@RequiresApi(value = 27)
renderComplicationToBitmap(
    complicationSlotId: Int,
    renderParameters: RenderParameters,
    instant: Instant,
    complicationData: ComplicationData,
    userStyle: UserStyle?
)

Renders the androidx.wear.watchface.ComplicationSlot to a shared memory backed Bitmap with the given settings.

Bitmap
@RequiresApi(value = 27)
renderWatchFaceToBitmap(
    renderParameters: RenderParameters,
    instant: Instant,
    userStyle: UserStyle?,
    slotIdToComplicationData: Map<IntComplicationData>?
)

Renders the watchface to a shared memory backed Bitmap with the given settings.

Bundle

Stores the underlying connection in a Bundle.

Public properties

Map<IntComplicationSlotState>

Map of androidx.wear.watchface.ComplicationSlot ids to ComplicationSlotState for each ComplicationSlot registered with the watch face's ComplicationSlotsManager.

open Boolean

Whether or not the watch face supports renderWatchFaceToSurface.

Instant

The Instant to use when rendering previews.

UserStyleSchema

The watch face's UserStyleSchema.

Inherited functions

From java.lang.AutoCloseable

Public companion functions

createFromBundle

Added in 1.0.0
fun createFromBundle(bundle: Bundle): HeadlessWatchFaceClient

Public functions

addClientDisconnectListener

Added in 1.0.0
@AnyThread
fun addClientDisconnectListener(
    listener: HeadlessWatchFaceClient.ClientDisconnectListener,
    executor: Executor
): Unit

Registers a ClientDisconnectListener.

getUserStyleFlavors

Added in 1.2.0
open fun getUserStyleFlavors(): UserStyleFlavors

Returns the watch face's UserStyleFlavors if any.

Throws
kotlin.RuntimeException

if the watch face threw an exception while trying to service the request or there was a communication problem with watch face process.

getUserStyleSchemaDigestHash

Added in 1.1.0
open fun getUserStyleSchemaDigestHash(): ByteArray

A SHA-1 MessageDigest hash of the UserStyleSchema. Note that for performance reasons where possible the resource id or url for Icons in the schema are used rather than the image bytes. This means that this hash should be considered insensitive to changes to the contents of icons between APK versions, which the user should account for accordingly.

This gives the same result as calling UserStyleSchema.computeDigestHash on userStyleSchema but is slightly faster since less data is passed over AIDL.

isConnectionAlive

Added in 1.0.0
@AnyThread
fun isConnectionAlive(): Boolean

Returns true if the connection to the server side is alive.

removeClientDisconnectListener

Added in 1.0.0
@AnyThread
fun removeClientDisconnectListener(
    listener: HeadlessWatchFaceClient.ClientDisconnectListener
): Unit

Removes a ClientDisconnectListener previously registered by addClientDisconnectListener.

renderComplicationToBitmap

Added in 1.0.0
@RequiresApi(value = 27)
fun renderComplicationToBitmap(
    complicationSlotId: Int,
    renderParameters: RenderParameters,
    instant: Instant,
    complicationData: ComplicationData,
    userStyle: UserStyle?
): Bitmap?

Renders the androidx.wear.watchface.ComplicationSlot to a shared memory backed Bitmap with the given settings. The complication will be rendered at the same scale as it would be when the watch face is full screen.

Parameters
complicationSlotId: Int

The id of the complication to render

renderParameters: RenderParameters

The RenderParameters to draw with

instant: Instant

The Instant to render with

complicationData: ComplicationData

the ComplicationData to render with

userStyle: UserStyle?

Optional UserStyle to render with, if null the default style is used

Returns
Bitmap?

A shared memory backed Bitmap containing a screenshot of the watch face with the given settings, or null if complicationSlotId is unrecognized.

renderWatchFaceToBitmap

@RequiresApi(value = 27)
fun renderWatchFaceToBitmap(
    renderParameters: RenderParameters,
    instant: Instant,
    userStyle: UserStyle?,
    slotIdToComplicationData: Map<IntComplicationData>?
): Bitmap

Renders the watchface to a shared memory backed Bitmap with the given settings.

Parameters
renderParameters: RenderParameters

The RenderParameters to draw with.

instant: Instant

The Instant to render with

userStyle: UserStyle?

Optional UserStyle to render with, if null the default style is used.

slotIdToComplicationData: Map<IntComplicationData>?

Map of androidx.wear.watchface.ComplicationSlot ids to ComplicationData to render with, or if null androidx.wear.watchface.ComplicationSlot are not rendered.

Returns
Bitmap

A shared memory backed Bitmap containing a screenshot of the watch face with the given settings.

toBundle

Added in 1.0.0
fun toBundle(): Bundle

Stores the underlying connection in a Bundle.

Public properties

complicationSlotsState

Added in 1.0.0
val complicationSlotsStateMap<IntComplicationSlotState>

Map of androidx.wear.watchface.ComplicationSlot ids to ComplicationSlotState for each ComplicationSlot registered with the watch face's ComplicationSlotsManager. The ComplicationSlotState is based on the initial state of each androidx.wear.watchface.ComplicationSlot plus any overrides from the default style's ComplicationSlotsUserStyleSetting. Because the style can't change, ComplicationSlotState is immutable for a headless watch face.

isRenderWatchFaceToSurfaceSupported

Added in 1.2.0
open val isRenderWatchFaceToSurfaceSupportedBoolean

Whether or not the watch face supports renderWatchFaceToSurface.

previewReferenceInstant

Added in 1.0.0
val previewReferenceInstantInstant

The Instant to use when rendering previews.

userStyleSchema

Added in 1.0.0
val userStyleSchemaUserStyleSchema

The watch face's UserStyleSchema.