O Google tem o compromisso de promover a igualdade racial para as comunidades negras. Saiba como.

ComplicationDrawable

class ComplicationDrawable : Drawable
kotlin.Any
   ↳ android.graphics.drawable.Drawable
   ↳ androidx.wear.watchface.complications.rendering.ComplicationDrawable

A styleable drawable object that draws complications. 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 constructor. Afterwards, styling attributes you want to modify can be set via set methods.

public void onCreate(SurfaceHolder holder) {
    ...
    ComplicationDrawable complicationDrawable = new ComplicationDrawable(WatchFaceService.this);
    complicationDrawable.setBackgroundColorActive(backgroundColor);
    complicationDrawable.setTextColorActive(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.complications.rendering.ComplicationDrawable
    xmlns:app="http://schemas.android.com/apk/res-auto"
    app:textColor="#FFFF0000"
    app:titleColor="#FFFFFFFF">
    <ambient
      app:textColor="#FFFFFFFF" />
  </android.support.wearable.complications.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.complications.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(Context, int) 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.complications.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.complications.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 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 constructors

Default constructor.

<init>(@NonNull context: Context)

Creates a ComplicationDrawable using the given context.

<init>(@NonNull drawable: ComplicationDrawable)

Public methods
Unit
draw(@NonNull canvas: Canvas)

Draws the complication for the last known time.

ComplicationStyle

Returns complication style for active mode.

ComplicationStyle

Returns complication style for ambient mode.

ComplicationData?

Returns the ComplicationData to be drawn by this ComplicationDrawable.

ComplicationRenderer?

Returns complication renderer.

Context?

Returns the Context used to render the complication.

Long

Returns the time in milliseconds since the epoch used for rendering ComplicationData with time dependent text.

static ComplicationDrawable?
getDrawable(@NonNull context: Context, id: Int)

Creates a ComplicationDrawable from a resource.

Long

Returns the highlight duration.

CharSequence?

Int

Unit
inflate(@NonNull r: Resources, @NonNull parser: XmlPullParser, @NonNull attrs: AttributeSet, @Nullable theme: Theme?)

Inflates this ComplicationDrawable from an XML resource.

Boolean

Whether the complication, when rendering in ambient mode, should apply a style suitable for display on devices with burn in protection.

Boolean

Returns whether the complication is currently highlighted.

Boolean

Returns whether the complication is rendered in ambient mode.

Boolean

Returns whether the complication, when rendering in ambient mode, should apply a style suitable for low bit ambient mode.

Boolean

Returns true if the ranged value progress is hidden, false otherwise.

Boolean
onTap(@Px x: Int, @Px y: Int)

Sends the tap action for the complication if tap coordinates are inside the complication bounds.

Unit
setAlpha(alpha: Int)

Does nothing.

Unit
setBurnInProtection(burnInProtection: Boolean)

Sets whether the complication, when rendering in ambient mode, should apply a style suitable for display on devices with burn in protection.