TimeDifferenceComplicationText.Builder

public static final class TimeDifferenceComplicationText.Builder
extends Object

java.lang.Object
   ↳ com.google.wear.services.complications.TimeDifferenceComplicationText.Builder


Builder for TimeDifferenceComplicationText.

Summary

Public constructors

Builder()
Builder(long referencePeriodStartMillis, long referencePeriodEndMillis)

Public methods

TimeDifferenceComplicationText build()

Builds a TimeDifferenceComplicationText.

TimeDifferenceComplicationText.Builder setMinimumUnit(TimeUnit minimumUnit)

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

TimeDifferenceComplicationText.Builder setReferencePeriodEndMillis(long refPeriodEndMillis)

Sets the end of the reference period from which the time difference will be calculated.

TimeDifferenceComplicationText.Builder setReferencePeriodStartMillis(long refPeriodStartMillis)

Sets the start of the reference period from which the time difference will be calculated.

TimeDifferenceComplicationText.Builder setShowNowText(boolean showNowText)

Sets whether text saying "now" (appropriately localized) should be shown when the given time is within the reference period.

TimeDifferenceComplicationText.Builder setStyle(int style)

Sets the style in which the time difference will be displayed.

TimeDifferenceComplicationText.Builder setSurroundingText(CharSequence surroundingText)

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

Inherited methods

Public constructors

Builder

Added in API level 36
public Builder ()

Builder

Added in API level 36
public Builder (long referencePeriodStartMillis, 
                long referencePeriodEndMillis)

Parameters
referencePeriodStartMillis long: The start of the reference period (in milliseconds since the epoch) from which the time difference will be calculated.

referencePeriodEndMillis long: The end of the reference period (in milliseconds since the epoch) from which the time difference will be calculated.

Public methods

setMinimumUnit

Added in API level 36
public TimeDifferenceComplicationText.Builder setMinimumUnit (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 TimeDifferenceComplicationText.STYLE_SHORT_SINGLE_UNIT then "12d" or "5h" would be shown as normal, but "35m" would be shown as "1h".

This is optional. If not specified, or if set to null, 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 TimeDifferenceComplicationText.STYLE_SHORT_SINGLE_UNIT, then a minimum unit of TimeUnit.SECONDS will have no effect.

Parameters
minimumUnit TimeUnit

Returns
TimeDifferenceComplicationText.Builder

setReferencePeriodEndMillis

Added in API level 36
public TimeDifferenceComplicationText.Builder setReferencePeriodEndMillis (long refPeriodEndMillis)

Sets the end of the reference period from which the time difference will be calculated. Defaults to Long.MAX_VALUE, effectively making the period unbounded at the end.

Parameters
refPeriodEndMillis long: the end of the reference period, given as UTC milliseconds since the epoch.

Returns
TimeDifferenceComplicationText.Builder this builder for chaining.

setReferencePeriodStartMillis

Added in API level 36
public TimeDifferenceComplicationText.Builder setReferencePeriodStartMillis (long refPeriodStartMillis)

Sets the start of the reference period from which the time difference will be calculated. Defaults to 0, effectively making the period unbounded at the start.

Parameters
refPeriodStartMillis long: the end of the reference period, given as UTC milliseconds since the epoch.

Returns
TimeDifferenceComplicationText.Builder this builder for chaining.

setShowNowText

Added in API level 36
public TimeDifferenceComplicationText.Builder setShowNowText (boolean showNowText)

Sets whether text saying "now" (appropriately localized) should be shown when the given time is within the reference period. If showNowText is 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 TimeDifferenceComplicationText.STYLE_STOPWATCH.

Parameters
showNowText boolean

Returns
TimeDifferenceComplicationText.Builder

setStyle

Added in API level 36
public TimeDifferenceComplicationText.Builder setStyle (int style)

Sets the style in which the time difference will be displayed. If not set, defaults to TimeDifferenceComplicationText.STYLE_SHORT_DUAL_UNIT.

Parameters
style int: Value is one of the following:
Returns
TimeDifferenceComplicationText.Builder this builder for chaining.

setSurroundingText

Added in API level 36
public TimeDifferenceComplicationText.Builder setSurroundingText (CharSequence surroundingText)

Sets the text within which the time difference will be displayed. This is optional.

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

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

If the text contains spans, some of them may not be rendered by the complication drawable. Supported spans are ForegroundColorSpan, LocaleSpan, SubscriptSpan, SuperscriptSpan, StyleSpan, StrikethroughSpan, TypefaceSpan and UnderlineSpan.

Parameters
surroundingText CharSequence: text within which the time difference value will be displayed, with ^1 in place of the time difference.

Returns
TimeDifferenceComplicationText.Builder this builder for chaining.