ComplicationDrawable


public final class ComplicationDrawable extends Drawable


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.

use Watch Face Format instead

Summary

Public constructors

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

Public methods

void
draw(@NonNull Canvas canvas)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final @NonNull ComplicationStyle

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final @NonNull ComplicationStyle

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final @NonNull ComplicationData

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final Context

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final @NonNull Instant

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

static final ComplicationDrawable
getDrawable(@NonNull Context context, int id)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final long

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final CharSequence

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

int

This method is deprecated. This method is no longer used in graphics optimizations

void
inflate(
    @NonNull Resources r,
    @NonNull XmlPullParser parser,
    @NonNull AttributeSet attrs,
    Resources.Theme theme
)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final boolean

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final boolean

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final boolean

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final boolean

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final boolean

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final boolean
onTap(@Px int x, @Px int y)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void
setAlpha(@IntRange(from = 0, to = 255) int alpha)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final void
setBurnInProtectionOn(boolean isBurnInProtectionOn)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final void
setComplicationData(
    @NonNull ComplicationData complicationData,
    boolean loadDrawablesAsync
)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final void
setHighlightDuration(long highlightDuration)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final void
setHighlighted(boolean isHighlighted)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final void
setInAmbientMode(boolean isInAmbientMode)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final void
setLowBitAmbient(boolean isLowBitAmbient)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final void
setRangedValueProgressHidden(boolean isRangedValueProgressHidden)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

Protected methods

void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

Inherited methods

From android.graphics.drawable.Drawable
void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

boolean

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final @NonNull Rect

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

int

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final @NonNull Rect

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

@Nullable Drawable.Callback

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

int

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

@Nullable ColorFilter

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

@Nullable Drawable.ConstantState

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

@NonNull Drawable

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

@NonNull Rect

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

int

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

int

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

int

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final int

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

int

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

int

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

@NonNull Insets

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

boolean

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

@NonNull int[]

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

@Nullable Region

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

boolean

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void
inflate(
    @NonNull Resources p0,
    @NonNull XmlPullParser p1,
    @NonNull AttributeSet p2
)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

boolean

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

boolean

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

boolean

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

boolean

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final boolean

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

@NonNull Drawable

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

boolean

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

boolean
onLevelChange(int p0)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

boolean

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void
scheduleSelf(@NonNull Runnable p0, long p1)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void
setAutoMirrored(boolean p0)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void
setBounds(int p0, int p1, int p2, int p3)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void

This method is deprecated. Deprecated in Java

void
setDither(boolean p0)

This method is deprecated. Deprecated in Java

void
setFilterBitmap(boolean p0)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void
setHotspot(float p0, float p1)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void
setHotspotBounds(int p0, int p1, int p2, int p3)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final boolean

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

final boolean
setLevel(int p0)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

boolean
setState(@NonNull int[] p0)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void
setTint(int p0)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

boolean
setVisible(boolean p0, boolean p1)

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

void

This method is deprecated. AndroidX watchface libraries are deprecated, use Watch Face Format instead.

Public constructors

ComplicationDrawable

Added in 1.0.0
Deprecated in 1.3.0-alpha07
public ComplicationDrawable()

Default constructor.

ComplicationDrawable

Added in 1.0.0
Deprecated in 1.3.0-alpha07
public ComplicationDrawable(@NonNull Context context)

Creates a ComplicationDrawable using the given context. If this constructor is used, calling setContext may not be necessary.

Parameters
@NonNull Context context

The Context used to render th