Google is committed to advancing racial equity for Black communities. See how.

MessageTemplate.Builder

public static final class MessageTemplate.Builder
extends Object

java.lang.Object
   ↳ com.google.android.libraries.car.app.model.MessageTemplate.Builder


A builder of MessageTemplate.

Summary

Public methods

MessageTemplate build()

Constructs the MessageTemplate defined by this builder.

MessageTemplate.Builder setActions(List<Action> actions)

Sets a list of Actions to display along with the message.

MessageTemplate.Builder setDebugCause(Throwable cause)

Sets a Throwable for debugging purposes, or null to not show it.

MessageTemplate.Builder setDebugMessage(String debugMessage)

Sets a debug message for debugging purposes, or null to not show a debug message.

MessageTemplate.Builder setHeaderAction(Action headerAction)

Sets the Action that will be displayed in the header of the template, or null to not display an action.

MessageTemplate.Builder setIcon(CarIcon icon)

Sets the icon to be displayed along with the message, or null to not display any icons.

MessageTemplate.Builder setMessage(CharSequence message)

Sets the CharSequence to display as the message in the template.

MessageTemplate.Builder setTitle(CharSequence title)

Sets the CharSequence to show as the template's title, or null to not show a title.

Inherited methods

Public methods

build

public MessageTemplate build ()

Constructs the MessageTemplate defined by this builder.

Requirements

A non-empty message must be set on the template with setMessage(CharSequence).

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

Returns
MessageTemplate

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

setActions

public MessageTemplate.Builder setActions (List<Action> actions)

Sets a list of Actions to display along with the message.

Any actions above the maximum limit of 2 will be ignored.

Parameters
actions List

Returns
MessageTemplate.Builder

Throws
NullPointerException if actions is null.

setDebugCause

public MessageTemplate.Builder setDebugCause (Throwable cause)

Sets a Throwable for debugging purposes, or null to not show it.

The cause will be displayed along with the message set in setDebugMessage(String).

The host may choose to not display this debugging information if it doesn't deem it appropriate, for example, when running on a production environment rather than in a simulator such as the Desktop Head Unit.

Parameters
cause Throwable

Returns
MessageTemplate.Builder

setDebugMessage

public MessageTemplate.Builder setDebugMessage (String debugMessage)

Sets a debug message for debugging purposes, or null to not show a debug message.

The debug message will be displayed along with the cause set in setDebugCause(Throwable).

The host may choose to not display this debugging information if it doesn't deem it appropriate, for example, when running on a production environment rather than in a simulator such as the Desktop Head Unit.

Parameters
debugMessage String

Returns
MessageTemplate.Builder

setHeaderAction

public MessageTemplate.Builder setHeaderAction (Action headerAction)

Sets the Action that will be displayed in the header of the template, or null to not display an action.

Requirements

This template only supports either either one of Action.APP_ICON and Action.BACK as a header Action.

Parameters
headerAction Action

Returns
MessageTemplate.Builder

Throws
IllegalArgumentException if headerAction does not meet the template's requirements.

setIcon

public MessageTemplate.Builder setIcon (CarIcon icon)

Sets the icon to be displayed along with the message, or null to not display any icons.

Icon Sizing Guidance

The provided icon should have a maximum size of 64 x 64 dp. If the icon exceeds this maximum size in either one of the dimensions, it will be scaled down and centered inside the bounding box while preserving the aspect ratio.

See CarIcon for more details related to providing icon and image resources that work with different car screen pixel densities.

Parameters
icon CarIcon

Returns
MessageTemplate.Builder

setMessage

public MessageTemplate.Builder setMessage (CharSequence message)

Sets the CharSequence to display as the message in the template.

Parameters
message CharSequence

Returns
MessageTemplate.Builder

Throws
NullPointerException if message is null.

setTitle

public MessageTemplate.Builder setTitle (CharSequence title)

Sets the CharSequence to show as the template's title, or null to not show a title.

Parameters
title CharSequence

Returns
MessageTemplate.Builder