CommandButton.Builder


public final class CommandButton.Builder


A builder for CommandButton.

Summary

Public constructors

[will be deprecated] Use Builder instead to define the Icon for this button.

Creates a builder.

Public methods

CommandButton

Builds a CommandButton.

CommandButton.Builder

Sets the resource id of an icon that is used when the predefined Icon is not available or set to ICON_UNDEFINED.

CommandButton.Builder

Sets a display name of this button.

CommandButton.Builder

Sets whether the button is enabled.

CommandButton.Builder

Sets an extra Bundle of this button.

CommandButton.Builder

[will be deprecated] The icon should be defined with the constructor Icon parameter in Builder instead.

CommandButton.Builder

Sets a content Uri for the icon of this button.

CommandButton.Builder

Sets the Player.Command that is required to be available when the button is clicked.

CommandButton.Builder

Sets the SessionCommand that is required to be available when the button is clicked.

CommandButton.Builder

Sets the allowed Slot positions for this button.

Public constructors

Builder

public Builder()

[will be deprecated] Use Builder instead to define the Icon for this button. A separate resource id via setIconResId is no longer required unless for ICON_UNDEFINED.

Builder

@UnstableApi
public Builder(@CommandButton.Icon int icon)

Creates a builder.

Parameters
@CommandButton.Icon int icon

The Icon that should be shown for this button.

Public methods

build

public CommandButton build()

Builds a CommandButton.

setCustomIconResId

@UnstableApi
@CanIgnoreReturnValue
public CommandButton.Builder setCustomIconResId(@DrawableRes int resId)

Sets the resource id of an icon that is used when the predefined Icon is not available or set to ICON_UNDEFINED.

Parameters
@DrawableRes int resId

The resource id of a custom icon.

Returns
CommandButton.Builder

This builder for chaining.

setDisplayName

@CanIgnoreReturnValue
public CommandButton.Builder setDisplayName(CharSequence displayName)

Sets a display name of this button.

Parameters
CharSequence displayName

The display name.

Returns
CommandButton.Builder

This builder for chaining.

setEnabled

@CanIgnoreReturnValue
public CommandButton.Builder setEnabled(boolean enabled)

Sets whether the button is enabled.

Note that this value will be set to false for MediaController instances if the corresponding command is not available to this controller (see setPlayerCommand and setSessionCommand).

The default value is true.

Parameters
boolean enabled

Whether the button is enabled.

Returns
CommandButton.Builder

This builder for chaining.

setExtras

@CanIgnoreReturnValue
public CommandButton.Builder setExtras(Bundle extras)

Sets an extra Bundle of this button.

Parameters
Bundle extras

The extra Bundle.

Returns
CommandButton.Builder

This builder for chaining.

setIconResId

@CanIgnoreReturnValue
public CommandButton.Builder setIconResId(@DrawableRes int resId)

[will be deprecated] The icon should be defined with the constructor Icon parameter in Builder instead. Only in case the existing list of icons is not sufficient, use ICON_UNDEFINED and set a separate resource id with setCustomIconResId.

setIconUri

@UnstableApi
@CanIgnoreReturnValue
public CommandButton.Builder setIconUri(Uri uri)

Sets a content Uri for the icon of this button.

Note that this Uri may be used when the predefined Icon is not available or set to ICON_UNDEFINED. It can be used in addition to setCustomIconResId for consumers that are capable of loading the content Uri.

Parameters
Uri uri

The uri to an icon.

Returns
CommandButton.Builder

This builder for chaining.

setPlayerCommand

@CanIgnoreReturnValue
public CommandButton.Builder setPlayerCommand(@Player.Command int playerCommand)

Sets the Player.Command that is required to be available when the button is clicked.

Cannot set this if a session command is already set via setSessionCommand.

Parameters
@Player.Command int playerCommand

The Player.Command.

Returns
CommandButton.Builder

This builder for chaining.

setSessionCommand

@CanIgnoreReturnValue
public CommandButton.Builder setSessionCommand(SessionCommand sessionCommand)

Sets the SessionCommand that is required to be available when the button is clicked.

Cannot set this if a player command is already set via setPlayerCommand.

Parameters
SessionCommand sessionCommand

The SessionCommand.

Returns
CommandButton.Builder

This builder for chaining.

setSlots

@UnstableApi
@CanIgnoreReturnValue
public CommandButton.Builder setSlots(@CommandButton.Slot int[] slots)

Sets the allowed Slot positions for this button.

The button is only allowed in the defined slots. If none of the slots can display the button, either because the slots do not exist, are already occupied or the UI surface does not allow the specific type of button in these slots, the button will not be displayed at all.

When multiple slots are provided, they define a preference order. The button will be placed in the first slot in the list that exists, isn't already occupied and that allows this type of button.

When not specified, the default value depends on the associated player command and the Icon set in the constructor:

Parameters
@CommandButton.Slot int[] slots

The list of allowed Slot positions. Must not be empty.

Returns
CommandButton.Builder

This builder for chaining.