DistanceSpan


@CarProtocol
class DistanceSpan : CarSpan


A span that replaces the text it is attached to with the string representation of a instance.

The Distance instance will be displayed by the host in a localized format, so that it will be consistent with the rest of the user interface where distance information are displayed.

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

String interpunct = "\\u00b7";
SpannableString string = new SpannableString("  " + interpunct + " Point-of-Interest 1");
string.setSpan(
  DistanceSpan.create(
    Distance.create(1000, "1.0", UNIT_KILOMETERS)), 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(
  DistanceSpan.create(
    Distance.create(1000, "1.0", UNIT_KILOMETERS)), 0, 1, SPAN_INCLUSIVE_INCLUSIVE);
string.setSpan(ForegroundCarColorSpan.create(CarColor.BLUE), 0, 1, SPAN_EXCLUSIVE_EXCLUSIVE);

Summary

Public functions

java-static DistanceSpan
create(distance: Distance)

Creates a DistanceSpan from a CarIcon.

Boolean
equals(other: Any?)
Distance

Returns the Distance instance associated with this span.

Int
String

Public functions

create

Added in 1.0.0
java-static fun create(distance: Distance): DistanceSpan

Creates a DistanceSpan from a CarIcon.

equals

fun equals(other: Any?): Boolean

getDistance

Added in 1.0.0
fun getDistance(): Distance

Returns the Distance instance associated with this span.

hashCode

fun hashCode(): Int

toString

fun toString(): String