• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 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 package com.android.launcher3.popup;
17 
18 import com.android.launcher3.ItemInfo;
19 import com.android.launcher3.Launcher;
20 import com.android.launcher3.R;
21 import com.android.launcher3.util.MainThreadInitializedObject;
22 import com.android.launcher3.util.ResourceBasedOverride;
23 
24 import java.util.ArrayList;
25 import java.util.List;
26 
27 import androidx.annotation.NonNull;
28 
29 public class SystemShortcutFactory implements ResourceBasedOverride {
30 
31     public static final MainThreadInitializedObject<SystemShortcutFactory> INSTANCE =
32             new MainThreadInitializedObject<>(c -> Overrides.getObject(
33                     SystemShortcutFactory.class, c, R.string.system_shortcut_factory_class));
34 
35     /** Note that these are in order of priority. */
36     private final SystemShortcut[] mAllShortcuts;
37 
38     @SuppressWarnings("unused")
SystemShortcutFactory()39     public SystemShortcutFactory() {
40         this(new SystemShortcut.AppInfo(),
41                 new SystemShortcut.Widgets(), new SystemShortcut.Install());
42     }
43 
SystemShortcutFactory(SystemShortcut... shortcuts)44     protected SystemShortcutFactory(SystemShortcut... shortcuts) {
45         mAllShortcuts = shortcuts;
46     }
47 
getEnabledShortcuts(Launcher launcher, ItemInfo info)48     public @NonNull List<SystemShortcut> getEnabledShortcuts(Launcher launcher, ItemInfo info) {
49         List<SystemShortcut> systemShortcuts = new ArrayList<>();
50         for (SystemShortcut systemShortcut : mAllShortcuts) {
51             if (systemShortcut.getOnClickListener(launcher, info) != null) {
52                 systemShortcuts.add(systemShortcut);
53             }
54         }
55         return systemShortcuts;
56     }
57 }
58