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

ComplicationText

interface ComplicationText
androidx.wear.complications.data.ComplicationText

The text within a complication.

This text may change over time and this interface provides both a way to determine the current text to show with getTextAt but also a way to know whether the text needs to be re-rendered, by means of returnsSameText, getNextChangeTime, and isAlwaysEmpty.

Summary

Public methods
abstract WireComplicationText

Converts this value to WireComplicationText object used for serialization.

abstract Long
getNextChangeTime(fromDateTimeMillis: Long)

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

abstract CharSequence
getTextAt(resources: Resources, dateTimeMillis: Long)

Returns the text that should be displayed for the given timestamp.

abstract Boolean

abstract Boolean
returnsSameText(firstDateTimeMillis: Long, secondDateTimeMillis: Long)

Returns true if the result of getTextAt will be the same for both firstDateTimeMillis and secondDateTimeMillis.

Companion functions
ComplicationText

Returns a ComplicationText that represent a plain CharSequence.

TimeDifferenceComplicationText.Builder

Returns a builder for a ComplicationText representing a time difference, which can be either a count up or a count down.

TimeFormatComplicationText.Builder

Returns a builder for a ComplicationText representing the current time.

Public methods

asWireComplicationText

abstract fun asWireComplicationText(): WireComplicationText

Converts this value to WireComplicationText object used for serialization.

getNextChangeTime

abstract fun getNextChangeTime(fromDateTimeMillis: Long): Long

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

getTextAt

abstract fun getTextAt(
    resources: Resources,
    dateTimeMillis: Long
): CharSequence

Returns the text that should be displayed for the given timestamp.

Parameters
resources: Resources Resources from the current context
dateTimeMillis: Long milliseconds since epoch, e.g. from System.currentTimeMillis

isAlwaysEmpty

abstract fun isAlwaysEmpty(): Boolean

returnsSameText

abstract fun returnsSameText(
    firstDateTimeMillis: Long,
    secondDateTimeMillis: Long
): Boolean

Returns true if the result of getTextAt will be the same for both firstDateTimeMillis and secondDateTimeMillis.

Companion functions

plain

@JvmStatic fun plain(text: CharSequence): ComplicationText

Returns a ComplicationText that represent a plain CharSequence.

timeDifferenceBuilder

@JvmStatic fun timeDifferenceBuilder(
    style: TimeDifferenceStyle,
    reference: TimeReference
): TimeDifferenceComplicationText.Builder

Returns a builder for a ComplicationText representing a time difference, which can be either a count up or a count down.

Parameters
style: TimeDifferenceStyle the style of the time difference to be displayed.

timeFormatBuilder

@JvmStatic fun timeFormatBuilder(format: String): TimeFormatComplicationText.Builder

Returns a builder for a ComplicationText representing the current time.

Parameters
format: String the format in which the time should be displayed. This should be a pattern as used by java.text.SimpleDateFormat.