1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.slice.core; 18 19 import android.app.PendingIntent; 20 21 import androidx.annotation.IntRange; 22 import androidx.annotation.NonNull; 23 import androidx.annotation.Nullable; 24 import androidx.core.graphics.drawable.IconCompat; 25 26 /** 27 * Interface for a slice action, supports tappable icons, custom toggle icons, and default toggles. 28 */ 29 public interface SliceAction { 30 31 /** 32 * @param description the content description for this action. 33 */ 34 @Nullable setContentDescription(@onNull CharSequence description)35 SliceAction setContentDescription(@NonNull CharSequence description); 36 37 /** 38 * @param isChecked whether the state of this action is checked or not; only used for toggle 39 * actions. 40 */ setChecked(boolean isChecked)41 SliceAction setChecked(boolean isChecked); 42 43 /** 44 * Sets the priority of this action, with the lowest priority having the highest ranking. 45 */ setPriority(@ntRangefrom = 0) int priority)46 SliceAction setPriority(@IntRange(from = 0) int priority); 47 48 /** 49 * @return the {@link PendingIntent} associated with this action. 50 */ 51 @NonNull getAction()52 PendingIntent getAction(); 53 54 /** 55 * @return the {@link IconCompat} to display for this action. This can be null when the action 56 * represented is a default toggle. 57 */ 58 @Nullable getIcon()59 IconCompat getIcon(); 60 61 /** 62 * @return the title for this action. 63 */ 64 @NonNull getTitle()65 CharSequence getTitle(); 66 67 /** 68 * @return the content description to use for this action. 69 */ 70 @Nullable getContentDescription()71 CharSequence getContentDescription(); 72 73 /** 74 * @return the priority associated with this action, -1 if unset. 75 */ getPriority()76 int getPriority(); 77 78 /** 79 * @return whether this action represents a toggle (i.e. has a checked and unchecked state). 80 */ isToggle()81 boolean isToggle(); 82 83 /** 84 * @return whether the state of this action is checked or not; only used for toggle actions. 85 */ isChecked()86 boolean isChecked(); 87 88 /** 89 * @return the image mode to use for this action. 90 */ getImageMode()91 @SliceHints.ImageMode int getImageMode(); 92 93 /** 94 * @return whether this action is a toggle using the standard switch control. 95 */ isDefaultToggle()96 boolean isDefaultToggle(); 97 } 98