Google is committed to advancing racial equity for Black communities. See how.

Builder

class Builder
kotlin.Any
   ↳ androidx.wear.complications.data.TimeDifferenceComplicationText.Builder

Builder for ComplicationText representing a time difference.

Requires setting a TimeDifferenceStyle.

Summary

Public constructors

Builder for ComplicationText representing a time difference.

Public methods
TimeDifferenceComplicationText

Builds a TimeDifferenceComplicationText.

TimeDifferenceComplicationText.Builder
setDisplayAsNow(displayAsNow: Boolean)

Sets whether time difference should be displayed as "now" (appropriately localized) when the given time is within the reference period.

TimeDifferenceComplicationText.Builder
setMinimumUnit(minimumUnit: TimeUnit?)

Sets the smallest unit that may be shown in the time difference text.

TimeDifferenceComplicationText.Builder

Sets the text within which the time difference will be displayed.

Public constructors

<init>

Builder(
    style: TimeDifferenceStyle,
    reference: TimeReference)

Builder for ComplicationText representing a time difference.

Requires setting a TimeDifferenceStyle.

Public methods

setDisplayAsNow

fun setDisplayAsNow(displayAsNow: Boolean): TimeDifferenceComplicationText.Builder

Sets whether time difference should be displayed as "now" (appropriately localized) when the given time is within the reference period. If false, then text representing zero (e.g. 0 mins or 00:00) will be shown instead.

The default is true for all styles except for TimeDifferenceStyle.STOPWATCH.

setMinimumUnit

fun setMinimumUnit(minimumUnit: TimeUnit?): TimeDifferenceComplicationText.Builder

Sets the smallest unit that may be shown in the time difference text. If specified, units smaller than this minimum will not be included.

For example, if this is set to TimeUnit.HOURS, and the style is TimeDifferenceStyle.SHORT_SINGLE_UNIT then 12d or 5h would be shown as normal, but 35m would be shown as 1h.

If not specified the style will determine the smallest unit that will be shown.

If the specified minimum is smaller than the smallest unit supported by the style, then the minimum will be ignored. For example, if the style is TimeDifferenceStyle.SHORT_SINGLE_UNIT, then a minimum unit of TimeUnit.SECONDS will have no effect.

setText

fun setText(text: CharSequence?): TimeDifferenceComplicationText.Builder

Sets the text within which the time difference will be displayed.

Within the text, ^1 will be replaced with the time difference, so for example to show a result like "2 mins: meeting" the text would be "^1: meeting"

To use the ^ character within the text, escape it as ^^.

The text may contain spans, but the watch face is not required to respect them.

The allowed spans are ForegroundColorSpan, LocaleSpan, SubscriptSpan, SuperscriptSpan, StyleSpan, StrikethroughSpan, TypefaceSpan and UnderlineSpan.