TimeDifferenceComplicationText

public final class TimeDifferenceComplicationText
extends Object implements TimeDependentText

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


Class to generate string representations of time differences.

Time differences greater than Integer.MAX_VALUE days are not supported.

Note: The preferred way to define dynamic data for complication text is to use a DynamicComplicationText. That will be the only supported way to create this type of ComplicationText in the future.

Summary

Nested classes

class TimeDifferenceComplicationText.Builder

Builder for TimeDifferenceComplicationText

Constants

int STYLE_SHORT_DUAL_UNIT

Style for time differences shown in a short alpha-numeric style, with up to two significant units included.

int STYLE_SHORT_SINGLE_UNIT

Style for time differences shown in a short alpha-numeric style, with only the most significant unit included.

int STYLE_SHORT_WORDS_SINGLE_UNIT

Style for time differences shown using (possibly abbreviated) words, with only the most significant unit included, that should fit within the character limit for a short text field.

int STYLE_STOPWATCH

Style for time differences shown in a numeric fashion like a timer.

int STYLE_WORDS_SINGLE_UNIT

Style for time differences shown using (possibly abbreviated) words, with only the most significant unit included.

Public methods

boolean equals(Object o)

TimeUnit getMinimumUnit()

Returns the minimum TimeUnit specified, or null if none has been specified.

long getNextChangeTimeMillis(long fromTime)

Returns the next time after fromTime at which the text may change.

long getPrecisionMillis()

Returns the time precision in milliseconds.

long getReferencePeriodEndMillis()

Returns the end of the reference period, as milliseconds since epoch.

long getReferencePeriodStartMillis()

Returns the start of the reference period, as milliseconds since epoch.

int getStyle()

Returns the time difference style to be used when formatting the text.

CharSequence getSurroundingText()
int hashCode()

boolean isShowNowText()

Returns true if text for "now" should be shown when within the reference period.

boolean returnsSameTextAt(long firstDateTimeMillis, long secondDateTimeMillis)

Returns true if the result of the calculation of the current text will be the same for both firstDateTimeMillis and secondDateTimeMillis.

String toString()

Inherited methods

Constants

STYLE_SHORT_DUAL_UNIT

Added in API level 36
public static final int STYLE_SHORT_DUAL_UNIT

Style for time differences shown in a short alpha-numeric style, with up to two significant units included.

For time difference t:

If t < 1 hour, the value will be shown as a number of minutes, such as 2m for 2 minutes. Seconds are not displayed.

If 1 hour <= t < 1 day, the value will be shown as hours and minutes, such as 4h 2m for 4 hours and 2 minutes.

If 1 day <= t < 10 days, the value will be shown as days and hours, such as 3d 4h for 3 days 4 hours.

If 10 days <= t, the value will be shown as a number of days, such as 13d for 13 days.

The characters used will be localised to match the default locale. If the representation of the time difference with two units would be too long in the default locale, just a single unit may be shown instead.

Constant Value: 3 (0x00000003)

STYLE_SHORT_SINGLE_UNIT

Added in API level 36
public static final int STYLE_SHORT_SINGLE_UNIT

Style for time differences shown in a short alpha-numeric style, with only the most significant unit included.

For time difference t:

If t < 1 hour, the value will be shown as a number of minutes, such as 2m for 2 minutes. Seconds are not displayed.

If 1 hour <= t < 1 day, the value will be shown as a number of hours, such as 4h for 4 hours.

If 1 days <= t, the value will be shown as a number of days, such as 13d for 13 days.

The characters used will be localised to match the default locale.

Constant Value: 2 (0x00000002)

STYLE_SHORT_WORDS_SINGLE_UNIT

Added in API level 36
public static final int STYLE_SHORT_WORDS_SINGLE_UNIT

Style for time differences shown using (possibly abbreviated) words, with only the most significant unit included, that should fit within the character limit for a short text field.

The output will be the same as for STYLE_WORDS_SINGLE_UNIT, except that if the text does not fit into the seven character limit then a shorter form will be used instead, e.g. "1356d" instead of "1356 days".

Constant Value: 5 (0x00000005)

STYLE_STOPWATCH

Added in API level 36
public static final int STYLE_STOPWATCH

Style for time differences shown in a numeric fashion like a timer.

For time difference t:

If t < 1 hour, the value will be shown as minutes and seconds, such as 02:35 for 2 minutes and 35 seconds.

If 1 hour <= t < 1 day, the value will be shown as hours and minutes, such as 4:02 for 4 hours and 2 minutes, or as 12:02 for 12 hours and 2 minutes.

If 1 day <= t < 10 days, the value will be shown as days and hours, such as 3d 4h for 3 days 4 hours.

If 10 days <= t, the value will be shown as just days, such as 13d for 13 days.

The characters used will be localised to match the default locale.

Constant Value: 1 (0x00000001)

STYLE_WORDS_SINGLE_UNIT

Added in API level 36
public static final int STYLE_WORDS_SINGLE_UNIT

Style for time differences shown using (possibly abbreviated) words, with only the most significant unit included.

For time difference t:

If t < 1 hour, the value will be shown as a number of minutes, such as 1 min for 1 minute or 2 mins for 2 minutes. Seconds are not displayed.

If 1 hour <= t < 1 day, the value will be shown as a number of hours, such as 1 hour for 1 hour or 4 hours for 4 hours.

If 1 days <= t, the value will be shown as a number of days, such as 1 day for 1 day or 13 days for 13 days.

The words used will be localised to match the default locale.

Constant Value: 4 (0x00000004)

Public methods

equals

Added in API level 36
public boolean equals (Object o)

Parameters
o Object

Returns
boolean

getMinimumUnit

Added in API level 36
public TimeUnit getMinimumUnit ()

Returns the minimum TimeUnit specified, or null if none has been specified.

Returns
TimeUnit

getNextChangeTimeMillis

Added in API level 36
public long getNextChangeTimeMillis (long fromTime)

Returns the next time after fromTime at which the text may change.

Parameters
fromTime long

Returns
long

getPrecisionMillis

Added in API level 36
public long getPrecisionMillis ()

Returns the time precision in milliseconds.

The result is max(getMinimumUnit(), 1000) for STYLE_STOPWATCH or 1000 otherwise.

Returns
long

getReferencePeriodEndMillis

Added in API level 36
public long getReferencePeriodEndMillis ()

Returns the end of the reference period, as milliseconds since epoch.

Returns
long

getReferencePeriodStartMillis

Added in API level 36
public long getReferencePeriodStartMillis ()

Returns the start of the reference period, as milliseconds since epoch.

Returns
long

getStyle

Added in API level 36
public int getStyle ()

Returns the time difference style to be used when formatting the text.

Returns
int Value is one of the following:

getSurroundingText

Added in API level 36
public CharSequence getSurroundingText ()

Returns
CharSequence

hashCode

Added in API level 36
public int hashCode ()

Returns
int

isShowNowText

Added in API level 36
public boolean isShowNowText ()

Returns true if text for "now" should be shown when within the reference period.

Returns
boolean

returnsSameTextAt

Added in API level 36
public boolean returnsSameTextAt (long firstDateTimeMillis, 
                long secondDateTimeMillis)

Returns true if the result of the calculation of the current text will be the same for both firstDateTimeMillis and secondDateTimeMillis.

Parameters
firstDateTimeMillis long

secondDateTimeMillis long

Returns
boolean

toString

Added in API level 36
public String toString ()

Returns
String