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