MessageTemplate.Builder

public static final class MessageTemplate.Builder
extends Object

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


A builder of MessageTemplate.

Summary

Public constructors

Builder(CharSequence message)

Returns a MessageTemplate.Builder instance.

Builder(CarText message)

Returns a MessageTemplate.Builder instance.

Public methods

MessageTemplate.Builder addAction(Action action)

Adds an Action to display along with the message.

MessageTemplate build()

Constructs the MessageTemplate defined by this builder.

MessageTemplate.Builder setActionStrip(ActionStrip actionStrip)

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

MessageTemplate.Builder setDebugMessage(String debugMessage)

Sets a debug message for debugging purposes.

MessageTemplate.Builder setDebugMessage(Throwable cause)

Sets a Throwable for debugging purposes.

MessageTemplate.Builder setHeaderAction(Action headerAction)

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

MessageTemplate.Builder setIcon(CarIcon icon)

Sets the icon to be displayed along with the message.

MessageTemplate.Builder setLoading(boolean isLoading)

Sets whether the template is in a loading state.

MessageTemplate.Builder setTitle(CharSequence title)

Sets the title of the template.

Inherited methods

Public constructors

Builder

public Builder (CharSequence message)

Returns a MessageTemplate.Builder instance.

Parameters
message CharSequence: the text message to display in the template

Throws
NullPointerException if the message is null

Builder

public Builder (CarText message)

Returns a MessageTemplate.Builder instance.

Parameters
message CarText: the text message to display in the template

Throws
NullPointerException if the message is null

Public methods

addAction

public MessageTemplate.Builder addAction (Action action)

Adds an Action to display along with the message.

Requirements

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

Parameters
action Action

Returns
MessageTemplate.Builder

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

build

public MessageTemplate build ()

Constructs the MessageTemplate 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
MessageTemplate

Throws
IllegalStateException if the message is empty, if the template does not have either a title or header Action set, or if the template is in loading state and an icon is specified.

setActionStrip

public MessageTemplate.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
MessageTemplate.Builder

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

setDebugMessage

public MessageTemplate.Builder setDebugMessage (String debugMessage)
<