LongMessageTemplate.Builder

public static final class LongMessageTemplate.Builder
extends Object

java.lang.Object
   ↳ androidx.car.app.model.LongMessageTemplate.Builder


A builder of LongMessageTemplate.

Summary

Public constructors

Builder(CharSequence message)

Returns a LongMessageTemplate.Builder instance.

Public methods

LongMessageTemplate.Builder addAction(Action action)

Adds an Action to display along with the message.

LongMessageTemplate build()

Constructs the LongMessageTemplate defined by this builder.

LongMessageTemplate.Builder setActionStrip(ActionStrip actionStrip)

Sets the ActionStrip for this template or null to not display an ActionStrip.

LongMessageTemplate.Builder setHeaderAction(Action headerAction)

Sets the Action that will be displayed in the header of the template.

LongMessageTemplate.Builder setTitle(CharSequence title)

Sets the title of the template.

Inherited methods

Public constructors

Builder

public Builder (CharSequence message)

Returns a LongMessageTemplate.Builder instance.

Parameters
message CharSequence: the text message to display in the template. This message will only be displayed when the car is parked.

Throws
NullPointerException if the message is null

Public methods

addAction

public LongMessageTemplate.Builder addAction (Action action)

Adds an Action to display along with the message.

Requirements

This template allows up to 2 Actions in its body, and they must use a ParkedOnlyOnClickListener. Each action's title color can be customized with ForegroundCarColorSpan instances. Any other span is not supported.

Parameters
action Action

Returns
LongMessageTemplate.Builder

Throws
IllegalArgumentException if action does not meet the requirements
NullPointerException if action is null

build

public LongMessageTemplate build ()

Constructs the LongMessageTemplate defined by this builder.

Requirements

A non-empty message must be set on the template.

Either a header Action or title must be set on the template.

Returns
LongMessageTemplate

Throws
IllegalStateException if the message is empty, or if the template does not have either a title or header Action set

setActionStrip

public LongMessageTemplate.Builder setActionStrip (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 2 Actions in its ActionStrip. Of the 2 allowed Actions, one of them can contain a title as set via Action.Builder.setTitle(CarText). Otherwise, only Actions with icons are allowed.

Parameters
actionStrip ActionStrip

Returns
LongMessageTemplate.Builder

Throws
IllegalArgumentException if actionStrip does not meet the requirements
NullPointerException if actionStrip is null

setHeaderAction

public LongMessageTemplate.Builder setHeaderAction (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 of Action.APP_ICON and Action.BACK as a header Action.

Parameters
headerAction Action

Returns
LongMessageTemplate.Builder

Throws
IllegalArgumentException if headerAction does not meet the template's requirements
NullPointerException if headerAction is null

setTitle

public LongMessageTemplate.Builder setTitle (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.

Parameters
title CharSequence

Returns
LongMessageTemplate.Builder

Throws
NullPointerException if