DurationSpan


@CarProtocol
class DurationSpan : CarSpan


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 DistanceSpan, DurationSpan, or 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 functions

java-static DurationSpan
@RequiresApi(value = 26)
create(duration: Duration)

Creates a DurationSpan with the given duration.

java-static DurationSpan
create(durationSeconds: Long)

Creates a DurationSpan with the given duration.

Boolean
equals(other: Any?)
Long

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

Int
String

Public functions

create

Added in 1.0.0
@RequiresApi(value = 26)
java-static fun create(duration: Duration): DurationSpan

Creates a DurationSpan with the given duration.

create

Added in 1.0.0
java-static fun create(durationSeconds: Long): DurationSpan

Creates a DurationSpan with the given duration.

equals

fun equals(other: Any?): Boolean

getDurationSeconds

Added in 1.0.0
fun getDurationSeconds(): Long

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

hashCode

fun hashCode(): Int

toString

fun toString(): String