ComplicationDrawable

public final class ComplicationDrawable


A styleable drawable object that draws complicationSlots. You can create a ComplicationDrawable from XML inflation or by using one of the constructor methods.

Constructing a ComplicationDrawable

To construct a ComplicationDrawable programmatically, use the ComplicationDrawable constructor. Afterwards, styling attributes you want to modify can be set via set methods.

val complicationDrawable = ComplicationDrawable(context)
complicationDrawable.activeStyle.backgroundColor = backgroundColor
complicationDrawable.activeStyle.textColor = textColor

Constructing a ComplicationDrawable from XML

Constructing a ComplicationDrawable from an XML file makes it easier to modify multiple styling attributes at once without calling any set methods. You may also use different XML files to switch between different styles your watch face supports.

To construct a ComplicationDrawable from a drawable XML file, you may create an XML file in your project's res/drawable folder. A ComplicationDrawable with red text and white title in active mode, and white text and white title in ambient mode would look like this:

<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.complication.rendering.ComplicationDrawable
xmlns:app="http://schemas.android.com/apk/res-auto"
app:textColor="#FFFF0000"
app:titleColor="#FFFFFFFF">
<ambient
app:textColor="#FFFFFFFF" />
</android.support.wearable.complication.rendering.ComplicationDrawable>

A top-level drawable tag with the class attribute may also be used to construct a ComplicationDrawable from an XML file:

<?xml version="1.0" encoding="utf-8"?>
<drawable
class="android.support.wearable.complication.rendering.ComplicationDrawable"
xmlns:app="http://schemas.android.com/apk/res-auto"
app:textColor="#FFFF0000"
app:titleColor="#FFFFFFFF">
<ambient
app:textColor="#FFFFFFFF" />
</drawable>

To inflate a ComplicationDrawable from XML file, use the .getDrawable method. ComplicationDrawable needs access to the current context in order to style and draw the complication.

public void onCreate(SurfaceHolder holder) {
...
ComplicationDrawable complicationDrawable = (ComplicationDrawable)
getDrawable(R.drawable.complication);
complicationDrawable.setContext(WatchFaceService.this);
...
}

Syntax:

<?xml version="1.0" encoding="utf-8"?>
<android.support.wearable.complication.rendering.ComplicationDrawable
xmlns:app="http://schemas.android.com/apk/res-auto"
app:backgroundColor="color"
app:backgroundDrawable="drawable"
app:borderColor="color"
app:borderDashGap="dimension"
app:borderDashWidth="dimension"
app:borderRadius="dimension"
app:borderStyle="none|solid|dashed"
app:borderWidth="dimension"
app:highlightColor="color"
app:iconColor="color"
app:rangedValuePrimaryColor="color"
app:rangedValueProgressHidden="boolean"
app:rangedValueRingWidth="dimension"
app:rangedValueSecondaryColor="color"
app:textColor="color"
app:textSize="dimension"
app:textTypeface="string"
app:titleColor="color"
app:titleSize="dimension"
app:titleTypeface="string">
<ambient
app:backgroundColor="color"
app:backgroundDrawable="drawable"
app:borderColor="color"
app:borderDashGap="dimension"
app:borderDashWidth="dimension"
app:borderRadius="dimension"
app:borderStyle="none|solid|dashed"
app:borderWidth="dimension"
app:highlightColor="color"
app:iconColor="color"
app:rangedValuePrimaryColor="color"
app:rangedValueRingWidth="dimension"
app:rangedValueSecondaryColor="color"
app:textColor="color"
app:textSize="dimension"
app:textTypeface="string"
app:titleColor="color"
app:titleSize="dimension"
app:titleTypeface="string" />
</android.support.wearable.complication.rendering.ComplicationDrawable>

Attributes of the top-level tag apply to both active and ambient modes while attributes of the inner ambient tag only apply to ambient mode. As an exception, top-level only rangedValueProgressHidden attribute applies to both modes, and cannot be overridden in ambient mode. To hide ranged value in only one of the active or ambient modes, you may consider setting rangedValuePrimaryColor and rangedValueSecondaryColor to android.graphics.Color.TRANSPARENT instead.

Drawing a ComplicationDrawable

Depending on the size and shape of the bounds, the layout of the complication may change. For instance, a short text complication with an icon that is drawn on square bounds would draw the icon above the short text, but a short text complication with an icon that is drawn on wide rectangular bounds might draw the icon to the left of the short text instead.

Summary

Public fields

final @NonNull ComplicationStyle

Returns complication style for active mode.

final @NonNull ComplicationStyle

Returns complication style for ambient mode.

final @NonNull ComplicationData

Returns the ComplicationData to be drawn by this ComplicationDrawable.

final Context

Returns the