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 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.

final @NonNull ComplicationDrawable

The ComplicationDrawable to render with.

void
@CallSuper
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.

final void

The ComplicationDrawable to render with.

Inherited methods

From androidx.wear.watchface.CanvasComplication
void
@ComplicationExperimental
drawHighlight(
    @NonNull Canvas canvas,
    @NonNull Rect bounds,
    int boundsType,
    @NonNull ZonedDateTime zonedDateTime,
    @ColorInt int color,
    BoundingArc boundingArc
)

Draws a highlight for a ComplicationSlotBoundsType.ROUND_RECT complication.

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 constructors

CanvasComplicationDrawable

Added in 1.0.0
public 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

Added in 1.0.0
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 ComplicationSlotBoundsTypeIntDef of the complication

@NonNull ZonedDateTime zonedDateTime

The ZonedDateTime to render the highlight with

@ColorInt int color

The color to render the highlight with

getData

Added in 1.0.0
public @NonNull ComplicationData getData()

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

getDrawable

Added in 1.0.0
public final @NonNull ComplicationDrawable getDrawable()

The ComplicationDrawable to render with.

loadData

Added in 1.0.0
@CallSuper
public 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

Added in 1.0.0
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

setDrawable

Added in 1.0.0
public final void setDrawable(@NonNull ComplicationDrawable drawable)

The ComplicationDrawable to render with.