CarText.Builder


public final class CarText.Builder


A builder of CarText.

Summary

Public constructors

Returns a new instance of a Builder.

Public methods

@NonNull CarText.Builder

Adds a text variant for the CarText instance.

@NonNull CarText

Constructs the CarText defined by this builder.

Public constructors

Builder

Added in 1.0.0
public Builder(@NonNull CharSequence text)

Returns a new instance of a Builder.

Only CarSpan type spans are allowed in a CarText, other spans will be removed from the provided CharSequence.

Parameters
@NonNull CharSequence text

the first variant of the text to use. This represents the app's preferred text variant. Other alternatives can be supplied with addVariant.

Throws
java.lang.NullPointerException

if the text is null

See also
addVariant

Public methods

addVariant

Added in 1.0.0
@RequiresCarApi(value = 2)
public @NonNull CarText.Builder addVariant(@NonNull CharSequence text)

Adds a text variant for the CarText instance.

Only CarSpan type spans are allowed in a CarText, other spans will be removed from the provided CharSequence.

The text variants should be added in order of preference, from most to least preferred (for instance, from longest to shortest). If the text provided via Builder does not fit in the screen, the host will display the first variant that fits in the screen.

For instance, if the variant order is ["long string", "shorter", "short"], and the screen can fit 7 characters, "shorter" will be chosen. However, if the order is ["short", "shorter", "long string"], "short" will be chosen, because "short" fits within the 7 character limit.

Throws
java.lang.NullPointerException

if the text is null

build

Added in 1.0.0
public @NonNull CarText build()

Constructs the CarText defined by this builder.