public final class

MessageTemplate.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.car.app.model.MessageTemplate.Builder

Overview

A builder of MessageTemplate.

Summary

Constructors
publicBuilder(CarText message)

Returns a MessageTemplate.Builder instance.

publicBuilder(java.lang.CharSequence message)

Returns a MessageTemplate.Builder instance.

Methods
public MessageTemplate.BuilderaddAction(Action action)

Adds an Action to display along with the message.

public MessageTemplatebuild()

Constructs the MessageTemplate defined by this builder.

public MessageTemplate.BuildersetActionStrip(ActionStrip actionStrip)

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

public MessageTemplate.BuildersetDebugMessage(java.lang.String debugMessage)

Sets a debug message for debugging purposes.

public MessageTemplate.BuildersetDebugMessage(java.lang.Throwable cause)

Sets a java.lang.Throwable for debugging purposes.

public MessageTemplate.BuildersetHeader(Header header)

Sets the Header for this template.

public MessageTemplate.BuildersetHeaderAction(Action headerAction)

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

public MessageTemplate.BuildersetIcon(CarIcon icon)

Sets the icon to be displayed along with the message.

public MessageTemplate.BuildersetLoading(boolean isLoading)

Sets whether the template is in a loading state.

public MessageTemplate.BuildersetTitle(java.lang.CharSequence title)

Sets the title of the template.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder(java.lang.CharSequence message)

Returns a MessageTemplate.Builder instance.

Parameters:

message: the text message to display in the template

public Builder(CarText message)

Returns a MessageTemplate.Builder instance.

Parameters:

message: the text message to display in the template

Methods

public MessageTemplate.Builder setLoading(boolean isLoading)

Sets whether the template is in a loading state.

If set to true, the UI shows a loading indicator where the icon would be otherwise. The caller is expected to call Screen.invalidate() and send the new template content to the host once the data is ready.

public MessageTemplate.Builder setTitle(java.lang.CharSequence title)

Deprecated: Use Header.Builder.setTitle(CarText)

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.

See also: CarText

public MessageTemplate.Builder setHeader(Header header)

Sets the Header for this template.

The end header actions will show up differently inside vs outside of a map template. See Header.Builder.addEndHeaderAction(Action) for more details.

public MessageTemplate.Builder setDebugMessage(java.lang.Throwable cause)

Sets a java.lang.Throwable for debugging purposes.

The cause will be displayed along with the message set in MessageTemplate.Builder.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.

public MessageTemplate.Builder setDebugMessage(java.lang.String debugMessage)

Sets a debug message for debugging purposes.

The debug message will be displayed along with the cause set in MessageTemplate.Builder.setDebugMessage(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.

public MessageTemplate.Builder setIcon(CarIcon icon)

Sets the icon to be displayed along with the message.

Unless set with this method, an icon will not be displayed.

Icon Sizing Guidance

To minimize scaling artifacts across a wide range of car screens, apps should provide icons targeting a 128 x 128 dp bounding box. If the icon exceeds this maximum size in either one of the dimensions, it will be scaled down to be centered inside the bounding box while preserving its aspect ratio.

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

public MessageTemplate.Builder setHeaderAction(Action headerAction)

Deprecated: Use Header.Builder.setStartHeaderAction(Action)

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.

public MessageTemplate.Builder setActionStrip(ActionStrip actionStrip)

Deprecated: Use for each action

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(CharSequence). Otherwise, only Actions with icons are allowed.

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.

public MessageTemplate build()

Constructs the MessageTemplate defined by this builder.

Requirements

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

If none of the header Action, the header title or the action strip have been set on the template, the header is hidden.