public final class

GridTemplate.Builder

extends java.lang.Object

 java.lang.Object

↳androidx.car.app.model.GridTemplate.Builder

Overview

A builder of GridTemplate.

Summary

Constructors
publicBuilder()

Returns an empty GridTemplate.Builder instance.

Methods
public GridTemplate.BuilderaddAction(Action action)

Adds a template scoped action outside of the grid items.

public GridTemplatebuild()

Constructs the template defined by this builder.

public GridTemplate.BuildersetActionStrip(ActionStrip actionStrip)

Sets the ActionStrip for this template.

public GridTemplate.BuildersetHeader(Header header)

Sets the Header for this template.

public GridTemplate.BuildersetHeaderAction(Action headerAction)

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

public GridTemplate.BuildersetItemImageShape(int itemImageShape)

Sets the item image shape for this template.

public GridTemplate.BuildersetItemSize(int gridItemSize)

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

public GridTemplate.BuildersetLoading(boolean isLoading)

Sets whether the template is in a loading state.

public GridTemplate.BuildersetSingleList(ItemList list)

Sets a single ItemList to show in the template.

public GridTemplate.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()

Returns an empty GridTemplate.Builder instance.

Methods

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 GridTemplate.Builder.setSingleList(ItemList).

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

public GridTemplate.Builder setSingleList(ItemList list)

Sets a single ItemList to show in the template.

public GridTemplate.Builder setActionStrip(ActionStrip actionStrip)

Deprecated: Use for each action

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

public GridTemplate.Builder addAction(Action action)

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

See also: ActionsConstraints.ACTIONS_CONSTRAINTS_FAB

public 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 GridItem.IMAGE_TYPE_LARGE setting for determining the grid item image size.

If this is not called, the default value is GridTemplate.ITEM_SIZE_SMALL

public 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.

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

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

See also: ConstraintManager.getContentLimit(int)