TimeDifferenceComplicationText.Builder

public final class TimeDifferenceComplicationText.Builder


Builder for ComplicationText representing a time difference.

Requires setting a TimeDifferenceStyle.

Summary

Public constructors

Builder(
    @NonNull TimeDifferenceStyle style,
    @NonNull CountDownTimeReference countDownTimeReference
)

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

Builder(
    @NonNull TimeDifferenceStyle style,
    @NonNull CountUpTimeReference countUpTimeReference
)

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

Public methods

final @NonNull TimeDifferenceComplicationText

Builds a TimeDifferenceComplicationText.

final @NonNull TimeDifferenceComplicationText.Builder
setDisplayAsNow(boolean displayAsNow)

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

final @NonNull TimeDifferenceComplicationText.Builder

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

final @NonNull TimeDifferenceComplicationText.Builder

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

Public constructors

Builder

Added in 1.0.0
public Builder(
    @NonNull TimeDifferenceStyle style,
    @NonNull CountDownTimeReference countDownTimeReference
)

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

Parameters
@NonNull TimeDifferenceStyle style

The TimeDifferenceStyle to use when rendering the time difference.

@NonNull CountDownTimeReference countDownTimeReference

The CountDownTimeReference to count down until.

Builder

Added in 1.0.0
public Builder(
    @NonNull TimeDifferenceStyle style,
    @NonNull CountUpTimeReference countUpTimeReference
)

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

Parameters
@NonNull TimeDifferenceStyle style

The TimeDifferenceStyle to use when rendering the time difference.

@NonNull CountUpTimeReference countUpTimeReference

The CountUpTimeReference to count up until.

Public methods

setDisplayAsNow

Added in 1.0.0
public final @NonNull TimeDifferenceComplicationText.Builder setDisplayAsNow(boolean displayAsNow)

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
public final @NonNull TimeDifferenceComplicationText.Builder setMinimumTimeUnit(TimeUnit minimumUnit)

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
public final @NonNull TimeDifferenceComplicationText.Builder setText(CharSequence text)

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.