MessageTemplate.Builder
public final class MessageTemplate.Builder
A builder of MessageTemplate.
Summary
Public constructors |
|---|
|
Returns a |
Builder(@NonNull CharSequence message)Returns a |
Public constructors
Builder
public Builder(@NonNull CarText message)
Returns a Builder instance.
| Throws | |
|---|---|
java.lang.NullPointerException |
if the |
Builder
public Builder(@NonNull CharSequence message)
Returns a Builder instance.
| Parameters | |
|---|---|
@NonNull CharSequence message |
the text message to display in the template |
| Throws | |
|---|---|
java.lang.NullPointerException |
if the |
Public methods
addAction
public @NonNull MessageTemplate.Builder addAction(@NonNull Action action)
Adds an Action to display along with the message.
Actions in its body. Each action's title color can be customized with ForegroundCarColorSpan instances. Any other span is not supported.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
java.lang.IllegalArgumentException |
if |
build
public @NonNull MessageTemplate build()
Constructs the MessageTemplate 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, or if the template is in loading state and an icon is specified. |
@RequiresCarApi(value = 2)
public @NonNull MessageTemplate.BuildersetActionStrip(@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 |
setDebugMessage
public @NonNull MessageTemplate.Builder setDebugMessage(@NonNull Throwable cause)
Sets a Throwable for debugging purposes.
The cause will be displayed along with the message set in setDebugMessage.
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.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
setDebugMessage
public @NonNull MessageTemplate.Builder setDebugMessage(@NonNull String debugMessage)
Sets a debug message for debugging purposes.
The debug message will be displayed along with the cause set in setDebugMessage.
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.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
setHeader
@RequiresCarApi(value = 7)
public @NonNull MessageTemplate.Builder setHeader(@NonNull Header header)
Sets the Header for this template.
The end header actions will show up differently inside vs outside of a map template. See addEndHeaderAction for more details.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
public @NonNull MessageTemplate.BuildersetHeaderAction(@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 |
setIcon
public @NonNull MessageTemplate.Builder setIcon(@NonNull 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.
| Throws | |
|---|---|
java.lang.NullPointerException |
if |
setLoading
@RequiresCarApi(value = 2)
public @NonNull 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 invalidate and send the new template content to the host once the data is ready.
public @NonNull MessageTemplate.BuildersetTitle(@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 |