GridTemplate.Builder

public static final class GridTemplate.Builder
extends Object

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


A builder of GridTemplate.

Summary

Public constructors

Builder()

Returns an empty GridTemplate.Builder instance.

Public methods

GridTemplate build()

Constructs the template defined by this builder.

GridTemplate.Builder setActionStrip(ActionStrip actionStrip)

Sets the ActionStrip for this template.

GridTemplate.Builder setHeaderAction(Action headerAction)

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

GridTemplate.Builder setLoading(boolean isLoading)

Sets whether the template is in a loading state.

GridTemplate.Builder setSingleList(ItemList list)

Sets a single ItemList to show in the template.

GridTemplate.Builder setTitle(CharSequence title)

Sets the title of the template.

Inherited methods

Public constructors

Builder

public Builder ()

Returns an empty GridTemplate.Builder instance.

Public methods

build

public GridTemplate build ()

Constructs the template defined by this builder.

Requirements

The number of items in the ItemList should be smaller or equal than the limit provided by ConstraintManager.CONTENT_LIMIT_TYPE_GRID. The host will ignore any items over that limit.

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

Returns
GridTemplate

Throws
IllegalStateException if the template is in a loading state but there are lists added, or vice versa, or if the template does not have either a title or header Action set.
IllegalArgumentException if the added ItemList does not meet the template's requirements.

setActionStrip

public GridTemplate.Builder setActionStrip (ActionStrip actionStrip)

Sets the ActionStrip for this template.

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
GridTemplate.Builder

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

setHeaderAction

public GridTemplate.Builder setHeaderAction (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 of Action.APP_ICON and Action.BACK as a header Action.

Parameters
headerAction Action

Returns
GridTemplate.Builder

Throws
IllegalArgumentException if headerAction does not meet the template's requirements
NullPointerException if headerAction is null

setLoading

public GridTemplate.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 grid content 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. If set to false, the UI shows the ItemList contents added via setSingleList(ItemList).

Parameters
isLoading boolean

Returns
GridTemplate.Builder

setSingleList

public GridTemplate.Builder setSingleList (ItemList list)

Sets a single ItemList to show in the template.

Parameters
list ItemList

Returns
GridTemplate.Builder

Throws
NullPointerException if list is null

setTitle

public GridTemplate.Builder setTitle (CharSequence title)

Sets the title of the template.

Unless set with this method, the template will not have a title.

Spans are not supported in the input string and will be ignored.

Parameters
title CharSequence

Returns
GridTemplate.Builder

Throws
NullPointerException if title is null