HeadlessWatchFaceClient


public interface HeadlessWatchFaceClient extends 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 methods

abstract void

Registers a ClientDisconnectListener.

default static final @NonNull HeadlessWatchFaceClient
abstract @NonNull Map<@NonNull Integer, @NonNull ComplicationSlotState>

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

abstract @NonNull Instant

The Instant to use when rendering previews.

default @NonNull UserStyleFlavors

Returns the watch face's UserStyleFlavors if any.

abstract @NonNull UserStyleSchema

The watch face's UserStyleSchema.

default @NonNull byte[]

A SHA-1 MessageDigest hash of the UserStyleSchema.

abstract boolean

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

default boolean

Whether or not the watch face supports renderWatchFaceToSurface.

abstract void

Removes a ClientDisconnectListener previously registered by addClientDisconnectListener.

abstract Bitmap
@RequiresApi(value = 27)
renderComplicationToBitmap(
    int complicationSlotId,
    @NonNull RenderParameters renderParameters,
    @NonNull Instant instant,
    @NonNull ComplicationData complicationData,
    UserStyle userStyle
)

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

abstract @NonNull Bitmap
@RequiresApi(value = 27)
renderWatchFaceToBitmap(
    @NonNull RenderParameters renderParameters,
    @NonNull Instant instant,
    UserStyle userStyle,
    Map<@NonNull Integer, @NonNull ComplicationData> slotIdToComplicationData
)

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

abstract @NonNull Bundle

Stores the underlying connection in a Bundle.

Inherited methods

From java.lang.AutoCloseable
abstract void

Public methods

addClientDisconnectListener

Added in 1.0.0
@AnyThread
abstract void addClientDisconnectListener(
    @NonNull HeadlessWatchFaceClient.ClientDisconnectListener listener,
    @NonNull Executor executor
)

Registers a ClientDisconnectListener.

createFromBundle

Added in 1.0.0
default static final @NonNull HeadlessWatchFaceClient createFromBundle(@NonNull Bundle bundle)

getComplicationSlotsState

Added in 1.0.0
abstract @NonNull Map<@NonNull Integer, @NonNull ComplicationSlotStategetComplicationSlotsState()

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.

getPreviewReferenceInstant

Added in 1.0.0
abstract @NonNull Instant getPreviewReferenceInstant()

The Instant to use when rendering previews.

getUserStyleFlavors

Added in 1.2.0
default @NonNull UserStyleFlavors getUserStyleFlavors()

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.

getUserStyleSchema

Added in 1.0.0
abstract @NonNull UserStyleSchema getUserStyleSchema()

The watch face's UserStyleSchema.

getUserStyleSchemaDigestHash

Added in 1.1.0
default @NonNull byte[] getUserStyleSchemaDigestHash()

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
abstract boolean isConnectionAlive()

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

isRenderWatchFaceToSurfaceSupported

Added in 1.2.0
default boolean isRenderWatchFaceToSurfaceSupported()

Whether or not the watch face supports renderWatchFaceToSurface.

removeClientDisconnectListener

Added in 1.0.0
@AnyThread
abstract void removeClientDisconnectListener(
    @NonNull HeadlessWatchFaceClient.ClientDisconnectListener listener
)

Removes a ClientDisconnectListener previously registered by addClientDisconnectListener.

renderComplicationToBitmap

Added in 1.0.0
@RequiresApi(value = 27)
abstract Bitmap renderComplicationToBitmap(
    int complicationSlotId,
    @NonNull RenderParameters renderParameters,
    @NonNull Instant instant,
    @NonNull ComplicationData complicationData,
    UserStyle userStyle
)

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
int complicationSlotId

The id of the complication to render

@NonNull RenderParameters renderParameters

The RenderParameters to draw with

@NonNull Instant instant

The Instant to render with

@NonNull 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)
abstract @NonNull Bitmap renderWatchFaceToBitmap(
    @NonNull RenderParameters renderParameters,
    @NonNull Instant instant,
    UserStyle userStyle,
    Map<@NonNull Integer, @NonNull ComplicationData> slotIdToComplicationData
)

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

Parameters
@NonNull RenderParameters renderParameters

The RenderParameters to draw with.

@NonNull Instant instant

The Instant to render with

UserStyle userStyle

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

Map<@NonNull Integer, @NonNull ComplicationData> slotIdToComplicationData

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

Returns
@NonNull Bitmap

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

toBundle

Added in 1.0.0
abstract @NonNull Bundle toBundle()

Stores the underlying connection in a Bundle.