public interface

SliceAction

 androidx.slice.core.SliceAction

Subclasses:

SliceActionImpl, SliceAction

Gradle dependencies

compile group: 'androidx.slice', name: 'slice-core', version: '1.1.0-alpha02'

  • groupId: androidx.slice
  • artifactId: slice-core
  • version: 1.1.0-alpha02

Artifact androidx.slice:slice-core:1.1.0-alpha02 it located at Google repository (https://maven.google.com/)

Androidx artifact mapping:

androidx.slice:slice-core com.android.support:slices-core

Overview

Interface for a slice action, supports tappable icons, custom toggle icons, and default toggles.

Summary

Methods
public PendingIntentgetAction()

public java.lang.CharSequencegetContentDescription()

public IconCompatgetIcon()

public intgetImageMode()

public intgetPriority()

public java.lang.CharSequencegetTitle()

public booleanisActivity()

public booleanisChecked()

public booleanisDefaultToggle()

public booleanisToggle()

public SliceActionsetChecked(boolean isChecked)

public SliceActionsetContentDescription(java.lang.CharSequence description)

public SliceActionsetPriority(int priority)

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

Methods

public SliceAction setContentDescription(java.lang.CharSequence description)

Parameters:

description: the content description for this action.

public SliceAction setChecked(boolean isChecked)

Parameters:

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

public SliceAction setPriority(int priority)

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

public PendingIntent getAction()

Returns:

the PendingIntent associated with this action.

public IconCompat getIcon()

Returns:

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

public java.lang.CharSequence getTitle()

Returns:

the title for this action.

public java.lang.CharSequence getContentDescription()

Returns:

the content description to use for this action.

public int getPriority()

Returns:

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

public boolean isToggle()

Returns:

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

public boolean isChecked()

Returns:

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

public boolean isActivity()

Returns:

whether this activity launches an activity or not.

public int getImageMode()

Returns:

the image mode to use for this action.

public boolean isDefaultToggle()

Returns:

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

Source

/*
 * Copyright 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.slice.core;

import android.app.PendingIntent;

import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.core.graphics.drawable.IconCompat;

/**
 * Interface for a slice action, supports tappable icons, custom toggle icons, and default toggles.
 */
@RequiresApi(19)
public interface SliceAction {

    /**
     * @param description the content description for this action.
     */
    @Nullable
    SliceAction setContentDescription(@NonNull CharSequence description);

    /**
     * @param isChecked whether the state of this action is checked or not; only used for toggle
     *                  actions.
     */
    SliceAction setChecked(boolean isChecked);

    /**
     * Sets the priority of this action, with the lowest priority having the highest ranking.
     */
    SliceAction setPriority(@IntRange(from = 0) int priority);

    /**
     * @return the {@link PendingIntent} associated with this action.
     */
    @NonNull
    PendingIntent getAction();

    /**
     * @return the {@link IconCompat} to display for this action. This can be null when the action
     * represented is a default toggle.
     */
    @Nullable
    IconCompat getIcon();

    /**
     * @return the title for this action.
     */
    @NonNull
    CharSequence getTitle();

    /**
     * @return the content description to use for this action.
     */
    @Nullable
    CharSequence getContentDescription();

    /**
     * @return the priority associated with this action, -1 if unset.
     */
    int getPriority();

    /**
     * @return whether this action represents a toggle (i.e. has a checked and unchecked state).
     */
    boolean isToggle();

    /**
     * @return whether the state of this action is checked or not; only used for toggle actions.
     */
    boolean isChecked();

    /**
     * @return whether this activity launches an activity or not.
     */
    boolean isActivity();

    /**
     * @return the image mode to use for this action.
     */
    @SliceHints.ImageMode int getImageMode();

    /**
     * @return whether this action is a toggle using the standard switch control.
     */
    boolean isDefaultToggle();
}