CanvasComplication

interface CanvasComplication

Known direct subclasses
CanvasComplicationDrawable

A complication rendered with ComplicationDrawable which renders complicationSlots in a material design style.


Interface for rendering complicationSlots onto a Canvas. These should be created by CanvasComplicationFactory.create. If state needs to be shared with the Renderer that should be set up inside onRendererCreated.

Summary

Nested types

CanvasComplication.InvalidateCallback

Interface for observing when a CanvasComplication needs the screen to be redrawn.

Public methods

abstract void
drawHighlight(
    Canvas canvas,
    Rect bounds,
    @ComplicationSlotBoundsType int boundsType,
    ZonedDateTime zonedDateTime,
    @ColorInt int color
)

Draws a highlight for a ComplicationSlotBoundsType.ROUND_RECT complication.

abstract @NonNull ComplicationData

Returns the ComplicationData to render with.

abstract void
loadData(
    ComplicationData complicationData,
    boolean loadDrawablesAsynchronous
)

Sets the ComplicationData to render with and loads any Drawables contained within the ComplicationData.

default @WorkerThread void

Called once on a background thread before any subsequent UI thread rendering to inform the CanvasComplication of the Renderer which is useful if they need to share state.

abstract @UiThread void
render(
    Canvas canvas,
    Rect bounds,
    ZonedDateTime zonedDateTime,
    RenderParameters renderParameters,
    int slotId
)

Draws the complication defined by getData into the canvas with the specified bounds.

Public methods

drawHighlight

abstract void drawHighlight(
    Canvas canvas,
    Rect bounds,
    @ComplicationSlotBoundsType int boundsType,
    ZonedDateTime zonedDateTime,
    @ColorInt int color
)

Draws a highlight for a ComplicationSlotBoundsType.ROUND_RECT complication. The default implementation does this by drawing a dashed line around the complication, other visual effects may be used if desired.

Parameters
Canvas canvas

The Canvas to render into

Rect bounds

A Rect describing the bounds of the complication

@ComplicationSlotBoundsType int boundsType

The ComplicationSlotBoundsType of the complication

ZonedDateTime zonedDateTime

The ZonedDateTime to render the highlight with

@ColorInt int color

The color to render the highlight with

getData

abstract @NonNull ComplicationData getData()

Returns the ComplicationData to render with.

loadData

abstract void loadData(
    ComplicationData complicationData,
    boolean loadDrawablesAsynchronous
)

Sets the ComplicationData to render with and loads any Drawables contained within the ComplicationData. You can choose whether this is done synchronously or asynchronously via loadDrawablesAsynchronous. When any asynchronous loading has completed InvalidateCallback.onInvalidate must be called.

Parameters
ComplicationData complicationData

The ComplicationData to render with

boolean loadDrawablesAsynchronous

Whether or not any drawables should be loaded asynchronously

onRendererCreated

@WorkerThread
default void onRendererCreated(Renderer renderer)

Called once on a background thread before any subsequent UI thread rendering to inform the CanvasComplication of the Renderer which is useful if they need to share state. Note the Renderer is created asynchronously which is why we can't pass it in via CanvasComplicationFactory.create as it may not be available at that time.

render

@UiThread
abstract void render(
    Canvas canvas,
    Rect bounds,
    ZonedDateTime zonedDateTime,
    RenderParameters renderParameters,
    int slotId
)

Draws the complication defined by getData into the canvas with the specified bounds. This will usually be called by user watch face drawing code, but the system may also call it for complication selection UI rendering. The width and height will be the same as that computed by computeBounds but the translation and canvas size may differ.

Parameters
Canvas canvas

The Canvas to render into

Rect bounds

A Rect describing the bounds of the complication

ZonedDateTime zonedDateTime

The ZonedDateTime to render with

RenderParameters renderParameters

The current RenderParameters

int slotId

The Id of the ComplicationSlot being rendered