# DurationSpan

Artifact: [androidx.car.app:app](https://developer.android.com/jetpack/androidx/releases/car-app) [View Source](https://cs.android.com/search?q=file:androidx/car/app/model/DurationSpan.java+class:androidx.car.app.model.DurationSpan) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/car-app#1.0.0)

*** ** * ** ***


```
@CarProtocol
public final class DurationSpan extends CarSpan
```

<br />

|---|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) ||||
| ↳ | [android.text.style.CharacterStyle](https://developer.android.com/reference/android/text/style/CharacterStyle.html) |||
|   | ↳ | [androidx.car.app.model.CarSpan](https://developer.android.com/reference/androidx/car/app/model/CarSpan) ||
|   |   | ↳ | [androidx.car.app.model.DurationSpan](https://developer.android.com/reference/androidx/car/app/model/DurationSpan) |

*** ** * ** ***

A span that replaces the text it is attached to with a localized duration string.

For example, the following code creates a string that shows the duration as the first text in the string before the interpunct:

```
String interpunct = "\\u00b7";
SpannableString string = new SpannableString("  " + interpunct + " Point-of-Interest 1");
string.setSpan(DurationSpan.create(300), 0, 1, SPAN_INCLUSIVE_INCLUSIVE);
```

The span flags (e.g. SPAN_EXCLUSIVE_EXCLUSIVE) will be ignored.

This span will be ignored if it overlaps with any span that replaces text, such as another `https://developer.android.com/reference/androidx/car/app/model/DistanceSpan`, `https://developer.android.com/reference/androidx/car/app/model/DurationSpan`, or `https://developer.android.com/reference/androidx/car/app/model/CarIconSpan`. However, it is possible to \* apply styling to the text, such as changing colors:

```
String interpunct = "\\u00b7";
SpannableString string = new SpannableString("  " + interpunct + " Point-of-Interest 1");
string.setSpan(DurationSpan.create(300), 0, 1, SPAN_INCLUSIVE_INCLUSIVE);
string.setSpan(ForegroundCarColorSpan.create(CarColor.BLUE), 0, 1, SPAN_EXCLUSIVE_EXCLUSIVE);
```

## Summary

| ### Public methods |
|---|---|
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/DurationSpan` | `@https://developer.android.com/reference/androidx/annotation/RequiresApi(value = 26) https://developer.android.com/reference/androidx/car/app/model/DurationSpan#create(java.time.Duration)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/time/Duration.html duration)` Creates a `https://developer.android.com/reference/androidx/car/app/model/DurationSpan` with the given duration. |
| `static @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/androidx/car/app/model/DurationSpan` | `https://developer.android.com/reference/androidx/car/app/model/DurationSpan#create(long)(long durationSeconds)` Creates a `https://developer.android.com/reference/androidx/car/app/model/DurationSpan` with the given duration. |
| `boolean` | `https://developer.android.com/reference/androidx/car/app/model/DurationSpan#equals(java.lang.Object)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/java/lang/Object.html other)` |
| `long` | `https://developer.android.com/reference/androidx/car/app/model/DurationSpan#getDurationSeconds()()` Returns the time duration associated with this span, in seconds. |
| `int` | `https://developer.android.com/reference/androidx/car/app/model/DurationSpan#hashCode()()` |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/car/app/model/DurationSpan#toString()()` |

| ### Inherited methods |
|---|
| From [androidx.car.app.model.CarSpan](https://developer.android.com/reference/androidx/car/app/model/CarSpan) |---|---| | `void` | `https://developer.android.com/reference/androidx/car/app/model/CarSpan#updateDrawState(android.text.TextPaint)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/text/TextPaint.html tp)` | |
| From [android.text.style.CharacterStyle](https://developer.android.com/reference/android/text/style/CharacterStyle.html) |---|---| | `https://developer.android.com/reference/android/text/style/CharacterStyle.html` | `https://developer.android.com/reference/android/text/style/CharacterStyle.html#getUnderlying()()` | | `abstract void` | `https://developer.android.com/reference/android/text/style/CharacterStyle.html#updateDrawState(android.text.TextPaint)(https://developer.android.com/reference/android/text/TextPaint.html p)` | | `static https://developer.android.com/reference/android/text/style/CharacterStyle.html` | `https://developer.android.com/reference/android/text/style/CharacterStyle.html#wrap(android.text.style.CharacterStyle)(https://developer.android.com/reference/android/text/style/CharacterStyle.html cs)` | |

## Public methods

### create

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

```
@RequiresApi(value = 26)
public static @NonNull DurationSpan create(@NonNull Duration duration)
```

Creates a `https://developer.android.com/reference/androidx/car/app/model/DurationSpan` with the given duration.

### create

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

```
public static @NonNull DurationSpan create(long durationSeconds)
```

Creates a `https://developer.android.com/reference/androidx/car/app/model/DurationSpan` with the given duration.

### equals

```
public boolean equals(@Nullable Object other)
```

### getDurationSeconds

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

```
public long getDurationSeconds()
```

Returns the time duration associated with this span, in seconds.

### hashCode

```
public int hashCode()
```

### toString

```
public @NonNull String toString()
```