MessageTemplate.Builder
class MessageTemplate.Builder
A builder of MessageTemplate.
Summary
Public constructors |
|---|
|
Returns a |
Builder(message: CharSequence)Returns a |
Public functions |
|
|---|---|
MessageTemplate.Builder |
Adds an |
MessageTemplate |
build()Constructs the |
MessageTemplate.Builder |
@RequiresCarApi(value = 2)This function is deprecated. Use |
MessageTemplate.Builder |
setDebugMessage(cause: Throwable)Sets a |
MessageTemplate.Builder |
setDebugMessage(debugMessage: String)Sets a debug message for debugging purposes. |
MessageTemplate.Builder |
@RequiresCarApi(value = 7)Sets the |
MessageTemplate.Builder |
This function is deprecated. |
MessageTemplate.Builder |
Sets the icon to be displayed along with the message. |
MessageTemplate.Builder |
@RequiresCarApi(value = 2)Sets whether the template is in a loading state. |
MessageTemplate.Builder |
This function is deprecated. Use |
Public constructors
Builder
Builder(message: CarText)
Returns a Builder instance.
| Parameters | |
|---|---|
message: CarText |
the text message to display in the template |
| Throws | |
|---|---|
java.lang.NullPointerException |
if the |
Builder
Builder(message: CharSequence)
Returns a Builder instance.
| Parameters | |
|---|---|
message: CharSequence |
the text message to display in the template |
| Throws | |
|---|---|
java.lang.NullPointerException |
if the |
Public functions
addAction
fun addAction(action: Action): MessageTemplate.Builder
Adds an Action to display along with the message.
Requirements
This template allows up to 2Actions 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
fun build(): MessageTemplate
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.
| 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)
funsetActionStrip(actionStrip: ActionStrip): MessageTemplate.Builder
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
fun setDebugMessage(cause: Throwable): MessageTemplate.Builder
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
fun setDebugMessage(debugMessage: String): MessageTemplate.Builder
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)
fun setHeader(header: Header): MessageTemplate.Builder
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 |
funsetHeaderAction(headerAction: Action): MessageTemplate.Builder
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
fun setIcon(icon: CarIcon): MessageTemplate.Builder
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)
fun setLoading(isLoading: Boolean): MessageTemplate.Builder
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.
funsetTitle(title: CharSequence): MessageTemplate.Builder
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 |