# TimeDifferenceComplicationText.Builder

Artifact: [androidx.wear.watchface:watchface-complications-data](https://developer.android.com/jetpack/androidx/releases/wear-watchface) [View Source](https://cs.android.com/search?q=file:androidx/wear/watchface/complications/data/Text.kt+class:androidx.wear.watchface.complications.data.TimeDifferenceComplicationText.Builder) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.0.0)

*** ** * ** ***


```
public final class TimeDifferenceComplicationText.Builder
```

<br />

*** ** * ** ***

Builder for `https://developer.android.com/reference/androidx/wear/watchface/complications/data/ComplicationText` representing a time difference.

Requires setting a `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceStyle`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#Builder(androidx.wear.watchface.complications.data.TimeDifferenceStyle,androidx.wear.watchface.complications.data.CountDownTimeReference)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceStyle style, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/watchface/complications/data/CountDownTimeReference countDownTimeReference )` Constructs a `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder` where the complication is counting down until `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#(androidx.wear.watchface.complications.data.TimeDifferenceStyle,androidx.wear.watchface.complications.data.CountDownTimeReference)`. |
| `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#Builder(androidx.wear.watchface.complications.data.TimeDifferenceStyle,androidx.wear.watchface.complications.data.CountUpTimeReference)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceStyle style, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/watchface/complications/data/CountUpTimeReference countUpTimeReference )` Constructs a `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder` where the complication is counting up until `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#(androidx.wear.watchface.complications.data.TimeDifferenceStyle,androidx.wear.watchface.complications.data.CountUpTimeReference)`. |

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText` | `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#build()()` Builds a `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText`. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder` | `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#setDisplayAsNow(kotlin.Boolean)(boolean displayAsNow)` Sets whether time difference should be displayed as "now" (appropriately localized) when the given time is within the reference period. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder` | `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#setMinimumTimeUnit(java.util.concurrent.TimeUnit)(https://developer.android.com/reference/java/util/concurrent/TimeUnit.html minimumUnit)` Sets the smallest unit that may be shown in the time difference text. |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder` | `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#setText(kotlin.CharSequence)(https://developer.android.com/reference/java/lang/CharSequence.html text)` Sets the text within which the time difference will be displayed. |

## Public constructors

### Builder

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.0.0)

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

Constructs a `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder` where the complication is counting down until `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#(androidx.wear.watchface.complications.data.TimeDifferenceStyle,androidx.wear.watchface.complications.data.CountDownTimeReference)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceStyle style` | The `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceStyle` to use when rendering the time difference. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/watchface/complications/data/CountDownTimeReference countDownTimeReference` | The `https://developer.android.com/reference/androidx/wear/watchface/complications/data/CountDownTimeReference` to count down until. |

### Builder

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.0.0)

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

Constructs a `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder` where the complication is counting up until `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText.Builder#(androidx.wear.watchface.complications.data.TimeDifferenceStyle,androidx.wear.watchface.complications.data.CountUpTimeReference)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceStyle style` | The `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceStyle` to use when rendering the time difference. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/wear/watchface/complications/data/CountUpTimeReference countUpTimeReference` | The `https://developer.android.com/reference/androidx/wear/watchface/complications/data/CountUpTimeReference` to count up until. |

## Public methods

### build

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#1.0.0)

```
public final @NonNull TimeDifferenceComplicationText build()
```

Builds a `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceComplicationText`.

### setDisplayAsNow

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#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 `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceStyle#STOPWATCH`.

### setMinimumTimeUnit

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#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 `https://developer.android.com/reference/java/util/concurrent/TimeUnit.html#HOURS`, and the style is `https://developer.android.com/reference/androidx/wear/watchface/complications/data/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 `https://developer.android.com/reference/androidx/wear/watchface/complications/data/TimeDifferenceStyle#SHORT_SINGLE_UNIT`, then a minimum unit of `https://developer.android.com/reference/java/util/concurrent/TimeUnit.html#SECONDS` will have no effect.

### setText

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-watchface#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 `https://developer.android.com/reference/android/text/style/ForegroundColorSpan.html` as a hint that it should render the affected text with an alternative color of its choosing.

The allowed spans are `https://developer.android.com/reference/android/text/style/ForegroundColorSpan.html`, `https://developer.android.com/reference/android/text/style/LocaleSpan.html`, `https://developer.android.com/reference/android/text/style/SubscriptSpan.html`, `https://developer.android.com/reference/android/text/style/SuperscriptSpan.html`, `https://developer.android.com/reference/android/text/style/StyleSpan.html`, `https://developer.android.com/reference/android/text/style/StrikethroughSpan.html`, `https://developer.android.com/reference/android/text/style/TypefaceSpan.html` and `https://developer.android.com/reference/android/text/style/UnderlineSpan.html`.