@RequiresApi(value = 19)
public class SliceAction implements SliceAction


Class representing an action, supports tappable icons, custom toggle icons, and default toggles, as well as date and time pickers.

Summary

Public methods

static SliceAction
create(
    @NonNull PendingIntent action,
    @NonNull IconCompat actionIcon,
    int imageMode,
    @NonNull CharSequence actionTitle
)

Construct a SliceAction representing a tappable icon.

static SliceAction
create(
    @NonNull RemoteCallback action,
    @NonNull IconCompat actionIcon,
    int imageMode,
    @NonNull CharSequence actionTitle
)

Construct a SliceAction representing a tappable icon.

static SliceAction
createDeeplink(
    @NonNull PendingIntent action,
    @NonNull IconCompat actionIcon,
    int imageMode,
    @NonNull CharSequence actionTitle
)

Construct a SliceAction representing a tappable icon that launches an activity when clicked.

static SliceAction
createDeeplink(
    @NonNull RemoteCallback action,
    @NonNull IconCompat actionIcon,
    int imageMode,
    @NonNull CharSequence actionTitle
)

Construct a SliceAction representing a tappable icon that launches an activity when clicked.

static SliceAction
createToggle(
    @NonNull PendingIntent action,
    @NonNull CharSequence actionTitle,
    boolean isChecked
)

Construct a SliceAction representing a default toggle.

static SliceAction
createToggle(
    @NonNull RemoteCallback action,
    @NonNull CharSequence actionTitle,
    boolean isChecked
)

Construct a SliceAction representing a default toggle.

static SliceAction
createToggle(
    @NonNull PendingIntent action,
    @NonNull IconCompat actionIcon,
    @NonNull CharSequence actionTitle,
    boolean isChecked
)

Construct a SliceAction representing a custom toggle icon.

static SliceAction
createToggle(
    @NonNull RemoteCallback action,
    @NonNull IconCompat actionIcon,
    @NonNull CharSequence actionTitle,
    boolean isChecked
)

Construct a SliceAction representing a custom toggle icon.

@NonNull PendingIntent
@Nullable CharSequence
@Nullable IconCompat
int
int
@NonNull CharSequence
boolean
boolean
boolean
boolean
@NonNull SliceAction
setChecked(boolean isChecked)
@NonNull SliceAction
@NonNull SliceAction
setPriority(@IntRange(from = 0) int priority)

Sets the priority of this action, with the lowest priority having the highest ranking.

Public methods

create

Added in 1.1.0-alpha02
public static SliceAction create(
    @NonNull PendingIntent action,
    @NonNull IconCompat actionIcon,
    int imageMode,
    @NonNull CharSequence actionTitle
)

Construct a SliceAction representing a tappable icon.

Parameters
@NonNull PendingIntent action

the pending intent to invoke for this action.

@NonNull IconCompat actionIcon

the icon to display for this action.

int imageMode

the mode this icon should be displayed in.

@NonNull CharSequence actionTitle

the title for this action, also used for content description if one hasn't been set via setContentDescription.

create

Added in 1.1.0-alpha02
public static SliceAction create(
    @NonNull RemoteCallback action,
    @NonNull IconCompat actionIcon,
    int imageMode,
    @NonNull CharSequence actionTitle
)

Construct a SliceAction representing a tappable icon.

Parameters
@NonNull RemoteCallback action

the remote callback to invoke for this action.

@NonNull IconCompat actionIcon

the icon to display for this action.

int imageMode

the mode this icon should be displayed in.

@NonNull CharSequence actionTitle

the title for this action, also used for content description if one hasn't been set via setContentDescription.

createDeeplink

Added in 1.1.0-alpha02
public static SliceAction createDeeplink(
    @NonNull PendingIntent action,
    @NonNull IconCompat actionIcon,
    int imageMode,
    @NonNull CharSequence actionTitle
)

Construct a SliceAction representing a tappable icon that launches an activity when clicked.

Parameters
@NonNull PendingIntent action

the pending intent to invoke for this action.

@NonNull IconCompat actionIcon

the icon to display for this action.

int imageMode

the mode this icon should be displayed in.

@NonNull CharSequence actionTitle

the title for this action, also used for content description if one hasn't been set via setContentDescription.

createDeeplink

Added in 1.1.0-alpha02
public static SliceAction createDeeplink(
    @NonNull RemoteCallback action,
    @NonNull IconCompat actionIcon,
    int imageMode,
    @NonNull CharSequence actionTitle
)

Construct a SliceAction representing a tappable icon that launches an activity when clicked.

Parameters
@NonNull RemoteCallback action

the remote callback to invoke for this action.

@NonNull IconCompat actionIcon

the icon to display for this action.

int imageMode

the mode this icon should be displayed in.

@NonNull CharSequence actionTitle

the title for this action, also used for content description if one hasn't been set via setContentDescription.

createToggle

Added in 1.1.0-alpha02
public static SliceAction createToggle(
    @NonNull PendingIntent action,
    @NonNull CharSequence actionTitle,
    boolean isChecked
)

Construct a SliceAction representing a default toggle.

Parameters
@NonNull PendingIntent action

the pending intent to invoke for this toggle.

@NonNull CharSequence actionTitle

the title for this toggle, also used for content description if one hasn't been set via setContentDescription.

boolean isChecked

the state of the toggle.

createToggle

Added in 1.1.0-alpha02
public static SliceAction createToggle(
    @NonNull RemoteCallback action,
    @NonNull CharSequence actionTitle,
    boolean isChecked
)

Construct a SliceAction representing a default toggle.

Parameters
@NonNull RemoteCallback action

the remote callback to invoke for this toggle.

@NonNull CharSequence actionTitle

the title for this toggle, also used for content description if one hasn't been set via setContentDescription.

boolean isChecked

the state of the toggle.

createToggle

Added in 1.1.0-alpha02
public static SliceAction createToggle(
    @NonNull PendingIntent action,
    @NonNull IconCompat actionIcon,
    @NonNull CharSequence actionTitle,
    boolean isChecked
)

Construct a SliceAction representing a custom toggle icon.

Parameters
@NonNull PendingIntent action

the pending intent to invoke for this toggle.

@NonNull IconCompat actionIcon

the icon to display for this toggle, should have a checked and unchecked state.

@NonNull CharSequence actionTitle

the title for this toggle, also used for content description if one hasn't been set via setContentDescription.

boolean isChecked

the state of the toggle.

createToggle

Added in 1.1.0-alpha02
public static SliceAction createToggle(
    @NonNull RemoteCallback action,
    @NonNull IconCompat actionIcon,
    @NonNull CharSequence actionTitle,
    boolean isChecked
)

Construct a SliceAction representing a custom toggle icon.

Parameters
@NonNull RemoteCallback action

the remote callback to invoke for this toggle.

@NonNull IconCompat actionIcon

the icon to display for this toggle, should have a checked and unchecked state.

@NonNull CharSequence actionTitle

the title for this toggle, also used for content description if one hasn't been set via setContentDescription.

boolean isChecked

the state of the toggle.

getAction

Added in 1.1.0-alpha02
public @NonNull PendingIntent getAction()
Returns
@NonNull PendingIntent

the PendingIntent associated with this action.

getContentDescription

Added in 1.1.0-alpha02
public @Nullable CharSequence getContentDescription()
Returns
@Nullable CharSequence

the content description to use for this action.

getIcon

Added in 1.1.0-alpha02
public @Nullable IconCompat getIcon()
Returns
@Nullable IconCompat

the Icon to display for this action. This can be null when the action represented is a default toggle.

getImageMode

Added in 1.1.0-alpha02
public int getImageMode()
Returns
int

the image mode to use for this action.

getPriority

Added in 1.1.0-alpha02
public int getPriority()
Returns
int

the priority associated with this action, -1 if unset.

getTitle

Added in 1.1.0-alpha02
public @NonNull CharSequence getTitle()
Returns
@NonNull CharSequence

the title for this action.

isActivity

Added in 1.1.0-alpha02
public boolean isActivity()
Returns
boolean

whether this activity launches an activity or not.

isChecked

Added in 1.1.0-alpha02
public boolean isChecked()
Returns
boolean

whether the state of this action is checked or not; only used for toggle actions.

isDefaultToggle

Added in 1.1.0-alpha02
public boolean isDefaultToggle()
Returns
boolean

whether this action is a toggle using the standard switch control.

isToggle

Added in 1.1.0-alpha02
public boolean isToggle()
Returns
boolean

whether this action represents a toggle (i.e. has a checked and unchecked state).

setChecked

Added in 1.1.0-alpha02
public @NonNull SliceAction setChecked(boolean isChecked)
Parameters
boolean isChecked

whether the state of this action is checked or not; only used for toggle actions.

setContentDescription

Added in 1.1.0-alpha02
public @NonNull SliceAction setContentDescription(@NonNull CharSequence description)
Parameters
@NonNull CharSequence description

the content description for this action.

setPriority

Added in 1.1.0-alpha02
public @NonNull SliceAction setPriority(@IntRange(from = 0) int priority)

Sets the priority of this action, with the lowest priority having the highest ranking.