GridTemplate.Builder


public final class GridTemplate.Builder


A builder of GridTemplate.

Summary

Public constructors

Returns an empty Builder instance.

Public methods

@NonNull GridTemplate.Builder

Adds a template scoped action outside of the grid items.

@NonNull GridTemplate

Constructs the template defined by this builder.

@NonNull GridTemplate.Builder

This method is deprecated.

Use for each action

@NonNull GridTemplate.Builder
@RequiresCarApi(value = 7)
setHeader(@NonNull Header header)

Sets the Header for this template.

@NonNull GridTemplate.Builder

This method is deprecated.

Use setStartHeaderAction

@NonNull GridTemplate.Builder

Sets the item image shape for this template.

@NonNull GridTemplate.Builder
@ExperimentalCarApi
setItemSize(int gridItemSize)

Sets a relative size of all grid items in the template.

@NonNull GridTemplate.Builder
setLoading(boolean isLoading)

Sets whether the template is in a loading state.

@NonNull GridTemplate.Builder

Sets a single ItemList to show in the template.

@NonNull GridTemplate.Builder

This method is deprecated.

Use setTitle

Public constructors

Builder

Added in 1.0.0
public Builder()

Returns an empty Builder instance.

Public methods

addAction

Added in 1.4.0
@ExperimentalCarApi
@RequiresCarApi(value = 7)
public @NonNull GridTemplate.Builder addAction(@NonNull Action action)

Adds a template scoped action outside of the grid items. This action will be displayed as a floating action button.

Throws
java.lang.IllegalArgumentException

if action contains unsupported Action types, or does not contain a valid CarIcon and background CarColor, or if exceeds the maximum number of allowed actions for the template.

build

Added in 1.0.0
public @NonNull 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 CONTENT_LIMIT_TYPE_GRID. The host will ignore any items over that limit.

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 template is in a loading state but there are lists added, or vice versa.

java.lang.IllegalArgumentException

if the added ItemList does not meet the template's requirements.

See also
getContentLimit

setActionStrip

Added in 1.0.0
Deprecated in 1.7.0-beta02
public @NonNull GridTemplate.Builder setActionStrip(@NonNull 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 setTitle. Otherwise, only Actions with icons are allowed.
Throws
java.lang.IllegalArgumentException

if actionStrip does not meet the requirements

java.lang.NullPointerException

if actionStrip is null

setHeader

Added in 1.7.0-beta02
@RequiresCarApi(value = 7)
public @NonNull GridTemplate.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 header is null

setHeaderAction

Added in 1.0.0
Deprecated in 1.7.0-beta02
public @NonNull GridTemplate.Builder setHeaderAction(@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 of APP_ICON and BACK as a header Action.
Throws
java.lang.IllegalArgumentException

if headerAction does not meet the template's requirements

java.lang.NullPointerException

if headerAction is null

setItemImageShape

Added in 1.4.0
@ExperimentalCarApi
public @NonNull GridTemplate.Builder setItemImageShape(int itemImageShape)

Sets the item image shape for this template.

Grid item images will all be cropped to the specified shape. If set to ITEM_IMAGE_SHAPE_UNSET, the images will be rendered as-is without changing the shape.

If not set, default to ITEM_IMAGE_SHAPE_UNSET.

setItemSize

Added in 1.4.0
@ExperimentalCarApi
public @NonNull GridTemplate.Builder setItemSize(int gridItemSize)

Sets a relative size of all grid items in the template.

This setting will affect the grid item image size and minimum width of each item. It can also impact the number of items displayed per row depending on screen size. These values may change in the future.

This setting takes precedence over the IMAGE_TYPE_LARGE setting for determining the grid item image size.

If this is not called, the default value is ITEM_SIZE_SMALL

setLoading

Added in 1.0.0
public @NonNull 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 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.

setSingleList

Added in 1.0.0
public @NonNull GridTemplate.Builder setSingleList(@NonNull ItemList list)

Sets a single ItemList to show in the template.

Throws
java.lang.NullPointerException

if list is null

setTitle

Added in 1.0.0
Deprecated in 1.7.0-beta02
public @NonNull GridTemplate.Builder setTitle(@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 title is null

java.lang.IllegalArgumentException

if title contains unsupported spans