LongMessageTemplate.Builder
@RequiresCarApi(value = 2)
public final class LongMessageTemplate.Builder
A builder of LongMessageTemplate.
Summary
Public constructors |
|---|
Builder(@NonNull CharSequence message)Returns a |
Public methods |
|
|---|---|
@NonNull LongMessageTemplate.Builder |
Adds an |
@NonNull LongMessageTemplate |
build()Constructs the |
@NonNull LongMessageTemplate.Builder |
setActionStrip(@NonNull ActionStrip actionStrip)Sets the |
@NonNull LongMessageTemplate.Builder |
setHeaderAction(@NonNull Action headerAction)Sets the |
@NonNull LongMessageTemplate.Builder |
setTitle(@NonNull CharSequence title)Sets the title of the template. |
Public constructors
Builder
public Builder(@NonNull CharSequence message)
Returns a Builder instance.
| Parameters | |
|---|---|
@NonNull CharSequence message |
the text message to display in the template. This message will only be displayed when the car is parked. |
| Throws | |
|---|---|
java.lang.NullPointerException |
if the |
Public methods
addAction
public @NonNull LongMessageTemplate.Builder addAction(@NonNull Action action)
Adds an Action to display along with the message.
Actions in its body, and they must use a androidx.car.app.model.ParkedOnlyOnClickListener. One of these actions can be declared as primary via setFlags. Each action's title color can be customized with ForegroundCarColorSpan instances. Any other span is not supported.
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if |
java.lang.NullPointerException |
if |
build
public @NonNull LongMessageTemplate build()
Constructs the LongMessageTemplate defined by this builder.
If none of the header Action, the header title or the action strip have been set on the template, the header is hidden.
| Throws | |
|---|---|
java.lang.IllegalStateException |
if the message is empty |
setActionStrip
public @NonNull LongMessageTemplate.Builder setActionStrip(@NonNull ActionStrip actionStrip)
Sets the ActionStrip for this template or null to not display an ActionStrip.
Unless set with this method, the template will not have an action strip.
Requirements This template allows up to 2Actions in its ActionStrip. Of the 2 allowed Actions, one of them can contain a title as set via setTitle. Otherwise, only Actions with icons are allowed.
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if |
java.lang.NullPointerException |
if |
setHeaderAction
public @NonNull LongMessageTemplate.Builder setHeaderAction(@NonNull Action headerAction)
Sets the Action that will be displayed in the header of the template.
Unless set with this method, the template will not have a header action.
Requirements This template only supports either one ofAPP_ICON and BACK as a header Action.
| Throws | |
|---|---|
java.lang.IllegalArgumentException |
if |
java.lang.NullPointerException |
if |
setTitle
public @NonNull LongMessageTemplate.Builder setTitle(@NonNull CharSequence title)
Sets the title of the template.
Unless set with this method, the template will not have a title.
Only DistanceSpans and DurationSpans are supported in the input string.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
java.lang.IllegalArgumentException |
if |
| See also | |
|---|---|
CarText |