CanvasComplicationDrawable

public class CanvasComplicationDrawable implements CanvasComplication


A complication rendered with ComplicationDrawable which renders complicationSlots in a material design style. This renderer can't be shared by multiple complicationSlots.

Summary

Public fields

final @NonNull ComplicationDrawable

The ComplicationDrawable to render with.

Public constructors

CanvasComplicationDrawable(
    @NonNull ComplicationDrawable drawable,
    @NonNull WatchState watchState,
    @NonNull CanvasComplication.InvalidateCallback invalidateCallback
)

Public methods

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

Draws a highlight for a ComplicationSlotBoundsType.ROUND_RECT complication.

@NonNull ComplicationData

Returns the ComplicationData to render with.

@CallSuper void
loadData(
    @NonNull ComplicationData complicationData,
    boolean loadDrawablesAsynchronous
)

Updates the ComplicationData used for rendering and loads any Drawables within the complicationData.

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

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

Inherited methods

From class CanvasComplication
@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.

Public fields

drawable

@NonNull
public final @NonNull ComplicationDrawable drawable

The ComplicationDrawable to render with.

Public constructors

CanvasComplicationDrawable

public final CanvasComplicationDrawable(
    @NonNull ComplicationDrawable drawable,
    @NonNull WatchState watchState,
    @NonNull CanvasComplication.InvalidateCallback invalidateCallback
)
Parameters
@NonNull ComplicationDrawable drawable

The ComplicationDrawable to render with.

@NonNull WatchState watchState

The watch's WatchState which contains details pertaining to (low-bit) ambient mode and burn in protection needed to render correctly.

@NonNull CanvasComplication.InvalidateCallback invalidateCallback

The CanvasComplication.InvalidateCallback associated with which can be used to request screen redrawing and to report updates

Public methods

drawHighlight

@NonNull
public void drawHighlight(
    @NonNull Canvas canvas,
    @NonNull Rect bounds,
    int boundsType,
    @NonNull 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
@NonNull Canvas canvas

The Canvas to render into

@NonNull Rect bounds

A Rect describing the bounds of the complication

int boundsType

The ComplicationSlotBoundsType of the complication

@NonNull ZonedDateTime zonedDateTime

The ZonedDateTime to render the highlight with

@ColorInt int color

The color to render the highlight with

getData

@NonNull
public ComplicationData getData()

Returns the ComplicationData to render with. This defaults to NoDataComplicationData.

loadData

@CallSuper
@NonNull
public @CallSuper void loadData(
    @NonNull ComplicationData complicationData,
    boolean loadDrawablesAsynchronous
)

Updates the ComplicationData used for rendering and loads any Drawables within the complicationData.

Parameters
@NonNull ComplicationData complicationData

The new ComplicationData for which any Drawables should be loaded

boolean loadDrawablesAsynchronous

Whether any Drawables within complicationData should be loaded asynchronously or not. If they are loaded asynchronously then upon completion, ComplicationDrawable.setComplicationData will call Drawable.Callback.invalidateDrawable registered in our init section above, which invalidates the attachedComplication and ultimately the watch face.

render

@NonNull
public void render(
    @NonNull Canvas canvas,
    @NonNull Rect bounds,
    @NonNull ZonedDateTime zonedDateTime,
    @NonNull 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
@NonNull Canvas canvas

The Canvas to render into

@NonNull Rect bounds

A Rect describing the bounds of the complication

@NonNull ZonedDateTime zonedDateTime

The ZonedDateTime to render with

@NonNull RenderParameters renderParameters

The current RenderParameters

int slotId

The Id of the ComplicationSlot being rendered