• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 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 package com.android.launcher3.util;
17 
18 import static com.android.launcher3.BuildConfig.WIDGETS_ENABLED;
19 
20 import com.android.launcher3.LauncherSettings;
21 import com.android.launcher3.Utilities;
22 import com.android.launcher3.model.data.ItemInfo;
23 import com.android.launcher3.model.data.WorkspaceItemInfo;
24 import com.android.launcher3.shortcuts.ShortcutKey;
25 
26 public class ShortcutUtil {
27     /**
28      * Returns true when we should show shortcut menu for the item.
29      */
supportsShortcuts(ItemInfo info)30     public static boolean supportsShortcuts(ItemInfo info) {
31         return isActive(info) && (isApp(info) || isPinnedShortcut(info));
32     }
33 
34     /**
35      * Returns true when we should show depp shortcuts in shortcut menu for the item.
36      */
supportsDeepShortcuts(ItemInfo info)37     public static boolean supportsDeepShortcuts(ItemInfo info) {
38         return isActive(info) && isApp(info) && !!WIDGETS_ENABLED;
39     }
40 
41     /**
42      * Returns the shortcut id if the item is a pinned shortcut.
43      */
getShortcutIdIfPinnedShortcut(ItemInfo info)44     public static String getShortcutIdIfPinnedShortcut(ItemInfo info) {
45         return isActive(info) && isPinnedShortcut(info)
46                 ? ShortcutKey.fromItemInfo(info).getId() : null;
47     }
48 
49     /**
50      * Returns the person keys associated with the item. (Has no function right now.)
51      */
getPersonKeysIfPinnedShortcut(ItemInfo info)52     public static String[] getPersonKeysIfPinnedShortcut(ItemInfo info) {
53         return isActive(info) && isPinnedShortcut(info)
54                 ? ((WorkspaceItemInfo) info).getPersonKeys() : Utilities.EMPTY_STRING_ARRAY;
55     }
56 
isActive(ItemInfo info)57     private static boolean isActive(ItemInfo info) {
58         boolean isLoading = info instanceof WorkspaceItemInfo
59                 && ((WorkspaceItemInfo) info).hasPromiseIconUi();
60         return !isLoading && !info.isDisabled();
61     }
62 
isApp(ItemInfo info)63     private static boolean isApp(ItemInfo info) {
64         return info.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION;
65     }
66 
isPinnedShortcut(ItemInfo info)67     private static boolean isPinnedShortcut(ItemInfo info) {
68         return info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT
69                 && info.container != ItemInfo.NO_ID
70                 && info instanceof WorkspaceItemInfo;
71     }
72 }
73