ComplicationDrawable
public
class
ComplicationDrawable
extends Drawable
implements
Parcelable
java.lang.Object | ||
↳ | android.graphics.drawable.Drawable | |
↳ | android.support.wearable.complications.rendering.ComplicationDrawable |
This class is deprecated.
use the Jetpack Wear
Watch Face libraries instead.
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 ComplicationDrawable(Context)
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 Context.getDrawable(int)
method. After loading the ComplicationDrawable, you should call setContext(Context)
right after. 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 Color.TRANSPARENT
instead.
Updating complication data
When WatchFaceService.Engine.onComplicationDataUpdate(int, ComplicationData)
is
called, you should call the setComplicationData(ComplicationData)
method to update
ComplicationData
drawn by this ComplicationDrawable.
public void onComplicationDataUpdate(int id, ComplicationData data) { mComplicationDrawable.setComplicationData(data); }
Going in and out of ambient mode
When WatchFaceService.Engine.onAmbientModeChanged(boolean)
is called, you should call
the setInAmbientMode(boolean)
method to update the styling of ComplicationDrawable.
public void onAmbientModeChanged(boolean inAmbientMode) { mComplicationDrawable.setInAmbientMode(inAmbientMode); }
Updating ambient properties
When the WatchFaceService.Engine.onPropertiesChanged(android.os.Bundle)
method is
called, you should call the setLowBitAmbient(boolean)
and setBurnInProtection(boolean)
methods to update ambient properties of the ComplicationDrawable.
These properties will be used to decide if antialiasing should be enabled or if images should be
drawn in ambient mode.
public void onPropertiesChanged(Bundle properties) { mComplicationDrawable.setLowBitAmbient( properties.getBoolean(PROPERTY_LOW_BIT_AMBIENT, false)); mComplicationDrawable.setBurnInProtection( properties.getBoolean(PROPERTY_BURN_IN_PROTECTION, false)); }
Drawing a ComplicationDrawable
Before calling the draw(Canvas, long)
method in your WatchFaceService
, you
should call Drawable.setBounds(Rect)
to update the position and size of the ComplicationDrawable
within the watch face canvas. The Drawable.setBounds(Rect)
method only needs to be called on the
first draw or if the bounds change.
public void onDraw(Canvas canvas, Rect bounds) { ... if (haveChanged(bounds)) { mComplicationDrawable.setBounds(complicationBoundsWithin(bounds)); } mComplicationDrawable.draw(canvas, currentTimeMillis); ... }
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.
Invalidating a watch face when this drawable invalidates
If you are using a ComplicationDrawable within aCanvasWatchFaceService
you may wish to invalidate the watch
face when the drawable invalidates, so that the watch face is redrawn when images load or when
taps are highlighted. To do this, call Drawable.setCallback(Drawable.Callback)
on the drawable with a Drawable.Callback
that invalidates the watch face.
Summary
Nested classes | ||
---|---|---|
@interface |
ComplicationDrawable.BorderStyle
This @interface is deprecated. use the Jetpack Wear Watch Face libraries instead. |
XML attributes | ||
---|---|---|
android.support.wearable:backgroundColor |
Defines the background color. | |
android.support.wearable:backgroundDrawable |
Defines the drawable to be used as a background. | |
android.support.wearable:borderColor |
Defines border color. | |
android.support.wearable:borderDashGap |
Defines dash gap for borders with style 'dashed'. | |
android.support.wearable:borderDashWidth |
Defines dash width for borders with style 'dashed'. | |
android.support.wearable:borderRadius |
Defines border radius. | |
android.support.wearable:borderStyle |
Defines border style. | |
android.support.wearable:borderWidth |
Defines stroke width for borders. | |
android.support.wearable:highlightColor |
Defines highlight color. | |
android.support.wearable:iconColor |
Defines icon tint color. | |
android.support.wearable:rangedValuePrimaryColor |
Defines main color for ranged value indicator. | |
android.support.wearable:rangedValueProgressHidden |
Defines visibility for ranged value indicator. | |
android.support.wearable:rangedValueRingWidth |
Defines stroke width for ranged value indicator. | |
android.support.wearable:rangedValueSecondaryColor |
Defines secondary color for ranged value indicator. | |
android.support.wearable:textColor |
Defines text color for short text and long text fields. | |
android.support.wearable:textSize |
Defines text size for short text and long text fields. | |
android.support.wearable:textTypeface |
Defines typeface for short text and long text fields. | |
android.support.wearable:titleColor |
Defines text color for short title and long title fields. | |
android.support.wearable:titleSize |
Defines text size for short title and long title fields. | |
android.support.wearable:titleTypeface |
Defines typeface for short title and long title fields. |
Constants | |
---|---|
int |
BORDER_STYLE_DASHED
Style where the borders are drawn as dashed lines. |
int |
BORDER_STYLE_NONE
Style where the borders are not drawn. |
int |
BORDER_STYLE_SOLID
Style where the borders are drawn without any gap. |
Inherited constants |
---|
Public constructors | |
---|---|
ComplicationDrawable()
Default constructor. |
|
ComplicationDrawable(Context context)
Creates a ComplicationDrawable using the given context. |
|
ComplicationDrawable(ComplicationDrawable drawable)
|
Public methods | |
---|---|
void
|
draw(Canvas canvas)
Draws the complication for the last known time. |
void
|
draw(Canvas canvas, long currentTimeMillis)
Draws the complication into bounds set via |
long
|
getHighlightDuration()
Returns the highlight duration. |
int
|
getOpacity()
|
void
|
inflate(Resources r, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)
Inflates this ComplicationDrawable from an XML resource. |
boolean
|
isHighlighted()
Returns |
boolean
|
isRangedValueProgressHidden()
Returns |
boolean
|
onTap(int x, int y)
Sends the tap action for the complication if tap coordinates are inside the complication bounds. |
boolean
|
onTap(int x, int y, long tapTimeMillis)
This method is deprecated.
Use |
void
|
setAlpha(int alpha)
Does nothing. |
void
|
setBackgroundColorActive(int backgroundColor)
Sets the background color used in active mode. |
void
|
setBackgroundColorAmbient(int backgroundColor)
Sets the background color used in ambient mode. |
void
|
setBackgroundDrawableActive(Drawable drawable)
Sets the background drawable used in active mode. |
void
|
setBackgroundDrawableAmbient(Drawable drawable)
Sets the background drawable used in ambient mode. |
void
|
setBorderColorActive(int borderColor)
Sets the border color used in active mode. |
void
|
setBorderColorAmbient(int borderColor)
Sets the border color used in ambient mode. |
void
|
setBorderDashGapActive(int borderDashGap)
Sets the dash gap used in active mode when drawing borders with style |
void
|
setBorderDashGapAmbient(int borderDashGap)
Sets the dash gap used in ambient mode when drawing borders with style |
void
|
setBorderDashWidthActive(int borderDashWidth)
Sets the dash width used in active mode when drawing borders with style |
void
|
setBorderDashWidthAmbient(int borderDashWidth)
Sets the dash width used in ambient mode when drawing borders with style |
void
|
setBorderRadiusActive(int borderRadius)
Sets the border radius to be applied to the corners of the bounds of the complication in active mode. |
void
|
setBorderRadiusAmbient(int borderRadius)
Sets the border radius to be applied to the corners of the bounds of the complication in ambient mode. |
void
|
setBorderStyleActive(int borderStyle)
Sets the border style used in active mode. |
void
|
setBorderStyleAmbient(int borderStyle)
Sets the border style used in ambient mode. |
void
|
setBorderWidthActive(int borderWidth)
Sets the border width for active mode. |
void
|
setBorderWidthAmbient(int borderWidth)
Sets the border width for ambient mode. |
void
|
setBurnInProtection(boolean burnInProtection)
Sets whether the complication, when rendering in ambient mode, should apply a style suitable for display on devices with burn in protection. |
void
|
setColorFilter(ColorFilter colorFilter)
Does nothing. |
void
|
setComplicationData(ComplicationData complicationData)
Sets the complication data to be drawn. |
void
|
setContext(Context context)
Sets the context used to render the complication. |
void
|
setCurrentTimeMillis(long currentTimeMillis)
Sets the current time. |
void
|
setHighlightColorActive(int highlightColor)
Sets the highlight color used in active mode, which is applied when |
void
|
setHighlightColorAmbient(int highlightColor)
Sets the highlight color used in ambient mode, which is applied when |
void
|
setHighlightDuration(long highlightDurationMillis)
Sets the duration for the complication to stay highlighted after calling the |
void
|
setIconColorActive(int iconColor)
Sets the icon color used for tinting icons in active mode. |
void
|
setIconColorAmbient(int iconColor)
Sets the icon color used for tinting icons in ambient mode. |
void
|
setImageColorFilterActive(ColorFilter colorFilter)
Sets the color filter used in active mode when rendering large images and small images with
style |
void
|
setImageColorFilterAmbient(ColorFilter colorFilter)
Sets the color filter used in ambient mode when rendering large images and small images with
style |
void
|
setInAmbientMode(boolean inAmbientMode)
Sets whether the complication should be rendered in ambient mode. |
void
|
setIsHighlighted(boolean isHighlighted)
Sets whether the complication is currently highlighted. |
void
|
setLowBitAmbient(boolean lowBitAmbient)
Sets whether the complication, when rendering in ambient mode, should apply a style suitable low bit ambient mode. |
void
|
setNoDataText(CharSequence noDataText)
Sets the text to be rendered when |
void
|
setRangedValuePrimaryColorActive(int rangedValuePrimaryColor)
Sets the main color for the ranged value indicator in active mode. |
void
|
setRangedValuePrimaryColorAmbient(int rangedValuePrimaryColor)
Sets the main color for the ranged value indicator in ambient mode. |
void
|
setRangedValueProgressHidden(boolean rangedValueProgressHidden)
Sets if the ranged value progress should be hidden when |
void
|
setRangedValueRingWidthActive(int rangedValueRingWidth)
Sets the stroke width used in active mode when rendering the ranged value indicator. |
void
|
setRangedValueRingWidthAmbient(int rangedValueRingWidth)
Sets the stroke width used in ambient mode when rendering the ranged value indicator. |
void
|
setRangedValueSecondaryColorActive(int rangedValueSecondaryColor)
Sets the secondary color for the ranged value indicator in active mode. |
void
|
setRangedValueSecondaryColorAmbient(int rangedValueSecondaryColor)
Sets the secondary color for the ranged value indicator in ambient mode. |
void
|
setTextColorActive(int textColor)
Sets the text color used in active mode. |
void
|
setTextColorAmbient(int textColor)
Sets the text color used in ambient mode. |
void
|
setTextSizeActive(int textSize)
Sets the text size used in active mode when rendering short text and long text fields. |
void
|
setTextSizeAmbient(int textSize)
Sets the text size used in ambient mode when rendering short text and long text fields. |
void
|
setTextTypefaceActive(Typeface textTypeface)
Sets the typeface used in active mode when rendering short text and long text fields. |
void
|
setTextTypefaceAmbient(Typeface textTypeface)
Sets the typeface used in ambient mode when rendering short text and long text fields. |
void
|
setTitleColorActive(int titleColor)
Sets the title color used in active mode. |
void
|
setTitleColorAmbient(int titleColor)
Sets the title color used in ambient mode. |
void
|
setTitleSizeActive(int titleSize)
Sets the text size used in active mode when rendering short title and long title fields. |
void
|
setTitleSizeAmbient(int titleSize)
Sets the text size used in ambient mode when rendering short title and long title fields. |
void
|
setTitleTypefaceActive(Typeface titleTypeface)
Sets the typeface used in active mode when rendering short text and long text fields. |
void
|
setTitleTypefaceAmbient(Typeface titleTypeface)
Sets the typeface used in ambient mode when rendering short text and long text fields. |
Protected methods | |
---|---|
void
|
onBoundsChange(Rect bounds)
|
Inherited methods | |
---|---|
XML attributes
android.support.wearable:backgroundColor
Defines the background color.
May be a color value, in the form of "#rgb
",
"#argb
", "#rrggbb
", or
"#aarrggbb
".
Related methods:
android.support.wearable:backgroundDrawable
Defines the drawable to be used as a background. Corners of the drawable will be rounded if border radius of the complication drawable is non-zero. Even if a background drawable is set, background color will still be used to fill background of the complication before drawing the drawable.
May be a reference to another resource, in the form
"@[+][package:]type/name
" or a theme
attribute in the form
"?[package:]type/name
".
Related methods:
android.support.wearable:borderColor
Defines border color.
May be a color value, in the form of "#rgb
",
"#argb
", "#rrggbb
", or
"#aarrggbb
".
Related methods:
android.support.wearable:borderDashGap
Defines dash gap for borders with style 'dashed'.
May be a dimension value, which is a floating point number appended with a
unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels),
sp (scaled pixels based on preferred font size), in (inches), and
mm (millimeters).
Related methods:
android.support.wearable:borderDashWidth
Defines dash width for borders with style 'dashed'.
May be a dimension value, which is a floating point number appended with a
unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels),
sp (scaled pixels based on preferred font size), in (inches), and
mm (millimeters).
Related methods:
android.support.wearable:borderRadius
Defines border radius. Padding will be applied to the content to avoid overflow if border radius is not zero.
May be a dimension value, which is a floating point number appended with a
unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels),
sp (scaled pixels based on preferred font size), in (inches), and
mm (millimeters).
Related methods:
android.support.wearable:borderStyle
Defines border style.
Must be one of the following constant values.
Constant | Value | Description |
---|---|---|
dashed | 2 | Draw dashed borders. borderDashWidth and borderDashGap attributes can be used to customize dashed borders. |
none | 0 | Do not draw any borders. |
solid | 1 | Draw solid borders. |
Related methods:
android.support.wearable:borderWidth
Defines stroke width for borders.
May be a dimension value, which is a floating point number appended with a
unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels),
sp (scaled pixels based on preferred font size), in (inches), and
mm (millimeters).
Related methods:
android.support.wearable:highlightColor
Defines highlight color.
May be a color value, in the form of "#rgb
",
"#argb
", "#rrggbb
", or
"#aarrggbb
".
Related methods:
android.support.wearable:iconColor
Defines icon tint color.
May be a color value, in the form of "#rgb
",
"#argb
", "#rrggbb
", or
"#aarrggbb
".
Related methods:
android.support.wearable:rangedValuePrimaryColor
Defines main color for ranged value indicator.
May be a color value, in the form of "#rgb
",
"#argb
", "#rrggbb
", or
"#aarrggbb
".
Related methods:
android.support.wearable:rangedValueProgressHidden
Defines visibility for ranged value indicator.
May be a boolean value, such as "true
" or
"false
".
Related methods:
android.support.wearable:rangedValueRingWidth
Defines stroke width for ranged value indicator.
May be a dimension value, which is a floating point number appended with a
unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels),
sp (scaled pixels based on preferred font size), in (inches), and
mm (millimeters).
Related methods:
android.support.wearable:rangedValueSecondaryColor
Defines secondary color for ranged value indicator.
May be a color value, in the form of "#rgb
",
"#argb
", "#rrggbb
", or
"#aarrggbb
".
Related methods:
android.support.wearable:textColor
Defines text color for short text and long text fields.
May be a color value, in the form of "#rgb
",
"#argb
", "#rrggbb
", or
"#aarrggbb
".
Related methods:
android.support.wearable:textSize
Defines text size for short text and long text fields.
May be a dimension value, which is a floating point number appended with a
unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels),
sp (scaled pixels based on preferred font size), in (inches), and
mm (millimeters).
Related methods:
android.support.wearable:textTypeface
Defines typeface for short text and long text fields.
May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;
Related methods:
android.support.wearable:titleColor
Defines text color for short title and long title fields.
May be a color value, in the form of "#rgb
",
"#argb
", "#rrggbb
", or
"#aarrggbb
".
Related methods:
android.support.wearable:titleSize
Defines text size for short title and long title fields.
May be a dimension value, which is a floating point number appended with a
unit such as "14.5sp
".
Available units are: px (pixels), dp (density-independent pixels),
sp (scaled pixels based on preferred font size), in (inches), and
mm (millimeters).
Related methods:
android.support.wearable:titleTypeface
Defines typeface for short title and long title fields.
May be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character;
Related methods:
Constants
BORDER_STYLE_DASHED
public static final int BORDER_STYLE_DASHED
Style where the borders are drawn as dashed lines. If this is set as current border style, dash
width and dash gap should also be set via setBorderDashWidthActive(int)
, setBorderDashGapActive(int)
, setBorderDashWidthAmbient(int)
, setBorderDashGapAmbient(int)
or XML attributes, or default values will be used.
Constant Value: 2 (0x00000002)
BORDER_STYLE_NONE
public static final int BORDER_STYLE_NONE
Style where the borders are not drawn.
Constant Value: 0 (0x00000000)
BORDER_STYLE_SOLID
public static final int BORDER_STYLE_SOLID
Style where the borders are drawn without any gap.
Constant Value: 1 (0x00000001)
Public constructors
ComplicationDrawable
public ComplicationDrawable ()
Default constructor.
ComplicationDrawable
public ComplicationDrawable (Context context)
Creates a ComplicationDrawable using the given context. If this constructor is used, calling
setContext(Context)
may not be necessary.
Parameters | |
---|---|
context |
Context |
ComplicationDrawable
public ComplicationDrawable (ComplicationDrawable drawable)
Parameters | |
---|---|
drawable |
ComplicationDrawable |
Public methods
draw
public void draw (Canvas canvas)
Draws the complication for the last known time. Last known time is derived from either draw(Canvas, long)
or setCurrentTimeMillis(long)
depending on which was called most recently.
Parameters | |
---|---|
canvas |
Canvas : Canvas for the complication to be drawn onto
|
draw
public void draw (Canvas canvas, long currentTimeMillis)
Draws the complication into bounds set via Drawable.setBounds(Rect)
for the given time. Calling
this method is equivalent to calling setCurrentTimeMillis(long)
followed by draw(Canvas)
, so it will update the last known time and any future calls to draw(Canvas)
will use the time passed to this method.
Parameters | |
---|---|
canvas |
Canvas : Canvas for the complication to be drawn onto |
currentTimeMillis |
long : The time complication is drawn at in milliseconds
|
getHighlightDuration
public long getHighlightDuration ()
Returns the highlight duration.
Returns | |
---|---|
long |
getOpacity
public int getOpacity ()
Returns | |
---|---|
int |
inflate
public void inflate (Resources r, XmlPullParser parser, AttributeSet attrs, Resources.Theme theme)
Inflates this ComplicationDrawable from an XML resource. This can't be called more than once for each ComplicationDrawable. Note that framework may have called this once to create the ComplicationDrawable instance from an XML resource.
Parameters | |
---|---|
r |
Resources : Resources used to resolve attribute values |
parser |
XmlPullParser : XML parser from which to inflate this ComplicationDrawable |
attrs |
AttributeSet : Base set of attribute values |
theme |
Resources.Theme : Ignored by ComplicationDrawable
|
Throws | |
---|---|
XmlPullParserException |
|
IOException |
isHighlighted
public boolean isHighlighted ()
Returns true
if the complication is highlighted.
Returns | |
---|---|
boolean |
isRangedValueProgressHidden
public boolean isRangedValueProgressHidden ()
Returns true
if the ranged value progress is hidden, false
otherwise.
Returns | |
---|---|
boolean |
onTap
public boolean onTap (int x, int y)
Sends the tap action for the complication if tap coordinates are inside the complication bounds.
This method will also highlight the complication. The highlight duration is 300 milliseconds
by default but can be modified using the setHighlightDuration(long)
method.
If ComplicationData
has the type ComplicationData.TYPE_NO_PERMISSION
, this
method will launch an intent to request complication permission for the watch face. This will
only work if the context set by setContext(Context)
or the constructor is an instance
of WatchFaceService
.
Parameters | |
---|---|
x |
int : X coordinate of the tap relative to screen origin |
y |
int : Y coordinate of the tap relative to screen origin |
Returns | |
---|---|
boolean |
true if the action was successful, false if complication data is not
set, the complication has no tap action, the tap action (i.e. PendingIntent ) is cancelled, or the given x and y are not inside the
complication bounds.
|
onTap
public boolean onTap (int x, int y, long tapTimeMillis)
This method is deprecated.
Use onTap(int, int)
instead.
Parameters | |
---|---|
x |
int |
y |
int |
tapTimeMillis |
long |
Returns | |
---|---|
boolean |
setAlpha
public void setAlpha (int alpha)
Does nothing.
Parameters | |
---|---|
alpha |
int |
setBackgroundColorActive
public void setBackgroundColorActive (int backgroundColor)
Sets the background color used in active mode.
Related XML Attributes:
Parameters | |
---|---|
backgroundColor |
int |
setBackgroundColorAmbient
public void setBackgroundColorAmbient (int backgroundColor)
Sets the background color used in ambient mode.
Related XML Attributes:
Parameters | |
---|---|
backgroundColor |
int |
setBackgroundDrawableActive
public void setBackgroundDrawableActive (Drawable drawable)
Sets the background drawable used in active mode.
Related XML Attributes:
Parameters | |
---|---|
drawable |
Drawable |
setBackgroundDrawableAmbient
public void setBackgroundDrawableAmbient (Drawable drawable)
Sets the background drawable used in ambient mode.
Related XML Attributes:
Parameters | |
---|---|
drawable |
Drawable |
setBorderColorActive
public void setBorderColorActive (int borderColor)
Sets the border color used in active mode.
Related XML Attributes:
Parameters | |
---|---|
borderColor |
int |
setBorderColorAmbient
public void setBorderColorAmbient (int borderColor)
Sets the border color used in ambient mode.
Related XML Attributes:
Parameters | |
---|---|
borderColor |
int |
setBorderDashGapActive
public void setBorderDashGapActive (int borderDashGap)
Sets the dash gap used in active mode when drawing borders with style BORDER_STYLE_DASHED
.
Related XML Attributes:
Parameters | |
---|---|
borderDashGap |
int : Dash gap in pixels |
setBorderDashGapAmbient
public void setBorderDashGapAmbient (int borderDashGap)
Sets the dash gap used in ambient mode when drawing borders with style BORDER_STYLE_DASHED
.
Related XML Attributes:
Parameters | |
---|---|
borderDashGap |
int : Dash gap in pixels |
setBorderDashWidthActive
public void setBorderDashWidthActive (int borderDashWidth)
Sets the dash width used in active mode when drawing borders with style BORDER_STYLE_DASHED
.
Related XML Attributes:
Parameters | |
---|---|
borderDashWidth |
int : Dash width in pixels |
setBorderDashWidthAmbient
public void setBorderDashWidthAmbient (int borderDashWidth)
Sets the dash width used in ambient mode when drawing borders with style BORDER_STYLE_DASHED
.
Related XML Attributes:
Parameters | |
---|---|
borderDashWidth |
int : Dash width in pixels |
setBorderRadiusActive
public void setBorderRadiusActive (int borderRadius)
Sets the border radius to be applied to the corners of the bounds of the complication in active mode. Border radius will be limited to the half of width or height, depending on which one is smaller.
Related XML Attributes:
Parameters | |
---|---|
borderRadius |
int : Border radius in pixels |
setBorderRadiusAmbient
public void setBorderRadiusAmbient (int borderRadius)
Sets the border radius to be applied to the corners of the bounds of the complication in ambient mode. Border radius will be limited to the half of width or height, depending on which one is smaller.
Related XML Attributes:
Parameters | |
---|---|
borderRadius |
int : Border radius in pixels |
setBorderStyleActive
public void setBorderStyleActive (int borderStyle)
Sets the border style used in active mode. It should be one of BORDER_STYLE_NONE
,
BORDER_STYLE_SOLID
, or BORDER_STYLE_DASHED
.
Related XML Attributes:
Parameters | |
---|---|
borderStyle |
int |
setBorderStyleAmbient
public void setBorderStyleAmbient (int borderStyle)
Sets the border style used in ambient mode. It should be one of BORDER_STYLE_NONE
,
BORDER_STYLE_SOLID
, or BORDER_STYLE_DASHED
.
Related XML Attributes:
Parameters | |
---|---|
borderStyle |
int |
setBorderWidthActive
public void setBorderWidthActive (int borderWidth)
Sets the border width for active mode.
Related XML Attributes:
Parameters | |
---|---|
borderWidth |
int : Border width in pixels |
setBorderWidthAmbient
public void setBorderWidthAmbient (int borderWidth)
Sets the border width for ambient mode.
Related XML Attributes:
Parameters | |
---|---|
borderWidth |
int : Border width in pixels |
setBurnInProtection
public void setBurnInProtection (boolean burnInProtection)
Sets whether the complication, when rendering in ambient mode, should apply a style suitable
for display on devices with burn in protection. This should be set when WatchFaceService.Engine.onPropertiesChanged(android.os.Bundle)
is called.
Parameters | |
---|---|
burnInProtection |
boolean |
setColorFilter
public void setColorFilter (ColorFilter colorFilter)
Does nothing. Use setImageColorFilterActive(ColorFilter)
or setImageColorFilterAmbient(ColorFilter)
instead to apply color filter to small and large
images.
Parameters | |
---|---|
colorFilter |
ColorFilter |
setComplicationData
public void setComplicationData (ComplicationData complicationData)
Sets the complication data to be drawn. If complicationData
is null
, nothing
will be drawn when draw(Canvas)
or draw(Canvas, long)
is called.
Parameters | |
---|---|
complicationData |
ComplicationData |
setContext
public void setContext (Context context)
Sets the context used to render the complication. If a context is not set, ComplicationDrawable
will throw an IllegalStateException
if one of draw(Canvas)
, draw(Canvas, long)
, Drawable.setBounds(Rect)
, or setComplicationData(ComplicationData)
is called.
While this can be called from any context, ideally, a WatchFaceService
object should
be passed here to allow creating permission dialogues by the onTap(int, int, long)
method, in case current watch face doesn't have the permission to receive complication data.
If this ComplicationDrawable is retrieved using Resources.getDrawable(int, Theme)
,
this method must be called before calling any of the methods mentioned above.
If this ComplicationDrawable is not inflated from an XML file, this method will reset the
style to match the default values, so if ComplicationDrawable()
is used to construct a
ComplicationDrawable, this method should be called right after.
Parameters | |
---|---|
context |
Context |
setCurrentTimeMillis
public void setCurrentTimeMillis (long currentTimeMillis)
Sets the current time. This will be used to render ComplicationData
with time dependent
text.
Parameters | |
---|---|
currentTimeMillis |
long : time in milliseconds
|
setHighlightColorActive
public void setHighlightColorActive (int highlightColor)
Sets the highlight color used in active mode, which is applied when setIsHighlighted(boolean)
is called.
Related XML Attributes:
Parameters | |
---|---|
highlightColor |
int : Highlight color |
setHighlightColorAmbient
public void setHighlightColorAmbient (int highlightColor)
Sets the highlight color used in ambient mode, which is applied when setIsHighlighted(boolean)
is called.
Related XML Attributes:
Parameters | |
---|---|
highlightColor |
int : Highlight color |
setHighlightDuration
public void setHighlightDuration (long highlightDurationMillis)
Sets the duration for the complication to stay highlighted after calling the onTap(int, int, long)
method. Default value is 300 milliseconds. Setting highlight duration to 0 disables
highlighting.
Parameters | |
---|---|
highlightDurationMillis |
long : highlight duration in milliseconds
|
setIconColorActive
public void setIconColorActive (int iconColor)
Sets the icon color used for tinting icons in active mode.
Related XML Attributes:
Parameters | |
---|---|
iconColor |
int |
setIconColorAmbient
public void setIconColorAmbient (int iconColor)
Sets the icon color used for tinting icons in ambient mode.
Related XML Attributes:
Parameters | |
---|---|
iconColor |
int |
setImageColorFilterActive
public void setImageColorFilterActive (ColorFilter colorFilter)
Sets the color filter used in active mode when rendering large images and small images with
style ComplicationData.IMAGE_STYLE_PHOTO
.
Parameters | |
---|---|
colorFilter |
ColorFilter |
setImageColorFilterAmbient
public void setImageColorFilterAmbient (ColorFilter colorFilter)
Sets the color filter used in ambient mode when rendering large images and small images with
style ComplicationData.IMAGE_STYLE_PHOTO
.
Parameters | |
---|---|
colorFilter |
ColorFilter |
setInAmbientMode
public void setInAmbientMode (boolean inAmbientMode)
Sets whether the complication should be rendered in ambient mode. Ideally, this should be set
when WatchFaceService.Engine.onAmbientModeChanged(boolean)
is called.
Parameters | |
---|---|
inAmbientMode |
boolean |
setIsHighlighted
public void setIsHighlighted (boolean isHighlighted)
Sets whether the complication is currently highlighted. This may be called by a watch face when a complication is tapped.
If watch face is in ambient mode, highlight will not be visible even if this is set to
true
, because it may cause burn-in or power inefficiency.
Parameters | |
---|---|
isHighlighted |
boolean |
setLowBitAmbient
public void setLowBitAmbient (boolean lowBitAmbient)
Sets whether the complication, when rendering in ambient mode, should apply a style suitable
low bit ambient mode. This should be set when WatchFaceService.Engine.onPropertiesChanged(android.os.Bundle)
is called.
Parameters | |
---|---|
lowBitAmbient |
boolean |
setNoDataText
public void setNoDataText (CharSequence noDataText)
Sets the text to be rendered when ComplicationData
is of type ComplicationData.TYPE_NO_DATA
. If no data text is null, an empty text will be rendered.
Parameters | |
---|---|
noDataText |
CharSequence |
setRangedValuePrimaryColorActive
public void setRangedValuePrimaryColorActive (int rangedValuePrimaryColor)
Sets the main color for the ranged value indicator in active mode.
Related XML Attributes:
Parameters | |
---|---|
rangedValuePrimaryColor |
int |
setRangedValuePrimaryColorAmbient
public void setRangedValuePrimaryColorAmbient (int rangedValuePrimaryColor)
Sets the main color for the ranged value indicator in ambient mode.
Related XML Attributes:
Parameters | |
---|---|
rangedValuePrimaryColor |
int |
setRangedValueProgressHidden
public void setRangedValueProgressHidden (boolean rangedValueProgressHidden)
Sets if the ranged value progress should be hidden when ComplicationData
is of type
ComplicationData.TYPE_RANGED_VALUE
.
Related XML Attributes:
Parameters | |
---|---|
rangedValueProgressHidden |
boolean : true if progress should be hidden, false
otherwise |
setRangedValueRingWidthActive
public void setRangedValueRingWidthActive (int rangedValueRingWidth)
Sets the stroke width used in active mode when rendering the ranged value indicator.
Related XML Attributes:
Parameters | |
---|---|
rangedValueRingWidth |
int : Ring width in pixels |
setRangedValueRingWidthAmbient
public void setRangedValueRingWidthAmbient (int rangedValueRingWidth)
Sets the stroke width used in ambient mode when rendering the ranged value indicator.
Related XML Attributes:
Parameters | |
---|---|
rangedValueRingWidth |
int : Ring width in pixels |
setRangedValueSecondaryColorActive
public void setRangedValueSecondaryColorActive (int rangedValueSecondaryColor)
Sets the secondary color for the ranged value indicator in active mode.
Related XML Attributes:
Parameters | |
---|---|
rangedValueSecondaryColor |
int |
setRangedValueSecondaryColorAmbient
public void setRangedValueSecondaryColorAmbient (int rangedValueSecondaryColor)
Sets the secondary color for the ranged value indicator in ambient mode.
Related XML Attributes:
Parameters | |
---|---|
rangedValueSecondaryColor |
int |
setTextColorActive
public void setTextColorActive (int textColor)
Sets the text color used in active mode. Text color is used for rendering short text and long text fields.
Related XML Attributes:
Parameters | |
---|---|
textColor |
int |
setTextColorAmbient
public void setTextColorAmbient (int textColor)
Sets the text color used in ambient mode. Text color is used for rendering short text and long text fields.
Related XML Attributes:
Parameters | |
---|---|
textColor |
int |
setTextSizeActive
public void setTextSizeActive (int textSize)
Sets the text size used in active mode when rendering short text and long text fields.
Related XML Attributes:
Parameters | |
---|---|
textSize |
int |
setTextSizeAmbient
public void setTextSizeAmbient (int textSize)
Sets the text size used in ambient mode when rendering short text and long text fields.
Related XML Attributes:
Parameters | |
---|---|
textSize |
int |
setTextTypefaceActive
public void setTextTypefaceActive (Typeface textTypeface)
Sets the typeface used in active mode when rendering short text and long text fields.
Related XML Attributes:
Parameters | |
---|---|
textTypeface |
Typeface |
setTextTypefaceAmbient
public void setTextTypefaceAmbient (Typeface textTypeface)
Sets the typeface used in ambient mode when rendering short text and long text fields.
Related XML Attributes:
Parameters | |
---|---|
textTypeface |
Typeface |
setTitleColorActive
public void setTitleColorActive (int titleColor)
Sets the title color used in active mode. Title color is used for rendering short title and long title fields.
Related XML Attributes:
Parameters | |
---|---|
titleColor |
int |
setTitleColorAmbient
public void setTitleColorAmbient (int titleColor)
Sets the title color used in ambient mode. Title color is used for rendering short title and long title fields.
Related XML Attributes:
Parameters | |
---|---|
titleColor |
int |
setTitleSizeActive
public void setTitleSizeActive (int titleSize)
Sets the text size used in active mode when rendering short title and long title fields.
Related XML Attributes:
Parameters | |
---|---|
titleSize |
int |
setTitleSizeAmbient
public void setTitleSizeAmbient (int titleSize)
Sets the text size used in ambient mode when rendering short title and long title fields.
Related XML Attributes:
Parameters | |
---|---|
titleSize |
int |
setTitleTypefaceActive
public void setTitleTypefaceActive (Typeface titleTypeface)
Sets the typeface used in active mode when rendering short text and long text fields.
Related XML Attributes:
Parameters | |
---|---|
titleTypeface |
Typeface |
setTitleTypefaceAmbient
public void setTitleTypefaceAmbient (Typeface titleTypeface)
Sets the typeface used in ambient mode when rendering short text and long text fields.
Related XML Attributes:
Parameters | |
---|---|
titleTypeface |
Typeface |
Protected methods
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2024-04-11 UTC.