TimeDifferenceComplicationText.Builder


class TimeDifferenceComplicationText.Builder


Builder for ComplicationText representing a time difference.

Requires setting a TimeDifferenceStyle.

Summary

Public constructors

Builder(
    style: TimeDifferenceStyle,
    countDownTimeReference: CountDownTimeReference
)

Constructs a TimeDifferenceComplicationText.Builder where the complication is counting down until countDownTimeReference.

Builder(
    style: TimeDifferenceStyle,
    countUpTimeReference: CountUpTimeReference
)

Constructs a TimeDifferenceComplicationText.Builder where the complication is counting up until countUpTimeReference.

Public functions

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

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

Builder

Added in 1.0.0
Builder(
    style: TimeDifferenceStyle,
    countDownTimeReference: CountDownTimeReference
)

Constructs a TimeDifferenceComplicationText.Builder where the complication is counting down until countDownTimeReference.

Parameters
style: TimeDifferenceStyle

The TimeDifferenceStyle to use when rendering the time difference.

countDownTimeReference: CountDownTimeReference

The CountDownTimeReference to count down until.

Builder

Added in 1.0.0
Builder(
    style: TimeDifferenceStyle,
    countUpTimeReference: CountUpTimeReference
)

Constructs a TimeDifferenceComplicationText.Builder where the complication is counting up until countUpTimeReference.

Parameters
style: TimeDifferenceStyle

The TimeDifferenceStyle to use when rendering the time difference.

countUpTimeReference: CountUpTimeReference

The CountUpTimeReference to count up until.

Public functions

setDisplayAsNow

Added in 1.0.0
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.

setMinimumTimeUnit

Added in 1.0.0
fun setMinimumTimeUnit(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

Added in 1.0.0
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 watch face is allowed to treat ForegroundColorSpan as a hint that it should render the affected text with an alternative color of its choosing.

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