TabTemplate.Builder


public final class TabTemplate.Builder


A builder of TabTemplate.

Summary

Public constructors

Creates a TabTemplate.Builder instance using the given TabCallback.

Builder(@NonNull TabTemplate tabTemplate)

Creates a new Builder, populated from the input TabTemplate

Public methods

@NonNull TabTemplate.Builder

Adds an Tab to display in the template.

@NonNull TabTemplate

Constructs the template defined by this builder.

@NonNull TabTemplate.Builder

Stores the given contentId as the "active tab" to show on the screen.

@NonNull TabTemplate.Builder

Sets the Action that will be displayed in the header of the template, or null to not display an action.

@NonNull TabTemplate.Builder
setLoading(boolean isLoading)

Sets whether the template is in a loading state.

@NonNull TabTemplate.Builder

Sets the TabContents to show in the template.

Public constructors

Builder

Added in 1.3.0
public Builder(@NonNull TabTemplate.TabCallback callback)

Creates a TabTemplate.Builder instance using the given TabCallback.

Note that the callback relates to UI events and will be executed on the main thread using getMainLooper.

Parameters
@NonNull TabTemplate.TabCallback callback

the callback to be invoked when the user selects a new tab in the header

Builder

Added in 1.4.0
public Builder(@NonNull TabTemplate tabTemplate)

Creates a new Builder, populated from the input TabTemplate

Public methods

addTab

Added in 1.3.0
public @NonNull TabTemplate.Builder addTab(@NonNull Tab tab)

Adds an Tab to display in the template.

Throws
java.lang.NullPointerException

if tab is null

build

Added in 1.3.0
public @NonNull TabTemplate build()

Constructs the template defined by this builder.

Requirements The number of Tabs provided in the template should be between 2 and 4, with only one tab marked as active.

A header Action of type TYPE_APP_ICON is required.

Throws
java.lang.IllegalStateException

if the template is in a loading state but there are tabs added or vice versa

java.lang.IllegalArgumentException

if the added Tab(s) or header Action does not meet the template's requirements

setActiveTabContentId

Added in 1.4.0
public @NonNull TabTemplate.Builder setActiveTabContentId(@NonNull String contentId)

Stores the given contentId as the "active tab" to show on the screen. The given ID must match a tab that was added by addTab.

setHeaderAction

Added in 1.3.0
public @NonNull TabTemplate.Builder setHeaderAction(@NonNull Action headerAction)

Sets the Action that will be displayed in the header of the template, or null to not display an action.

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

Requirements This template only supports APP_ICON as a header Action.
Throws
java.lang.IllegalArgumentException

if headerAction does not meet the template's requirements

java.lang.NullPointerException

if headerAction is null

setLoading

Added in 1.3.0
public @NonNull TabTemplate.Builder setLoading(boolean isLoading)

Sets whether the template is in a loading state.

If set to true, the UI will display a loading indicator where the 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 will display the contents of the template.

setTabContents

Added in 1.3.0
public @NonNull TabTemplate.Builder setTabContents(@NonNull TabContents tabContents)

Sets the TabContents to show in the template. Note that only certain templates may be used as content. See Builder for more details.

Throws
java.lang.NullPointerException

if tabContents is null