1 /*
2  * Copyright (C) 2021 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;
17 
18 import android.view.KeyEvent;
19 import android.view.View;
20 
21 import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
22 import com.android.launcher3.model.data.ItemInfo;
23 import com.android.launcher3.uioverrides.PredictedAppIcon;
24 import com.android.launcher3.uioverrides.QuickstepLauncher;
25 
26 import java.util.List;
27 
28 public class QuickstepAccessibilityDelegate extends LauncherAccessibilityDelegate {
29 
QuickstepAccessibilityDelegate(QuickstepLauncher launcher)30     public QuickstepAccessibilityDelegate(QuickstepLauncher launcher) {
31         super(launcher);
32         mActions.put(PIN_PREDICTION, new LauncherAction(
33                 PIN_PREDICTION, R.string.pin_prediction, KeyEvent.KEYCODE_P));
34     }
35 
36     @Override
getSupportedActions(View host, ItemInfo item, List<LauncherAction> out)37     protected void getSupportedActions(View host, ItemInfo item, List<LauncherAction> out) {
38         if (host instanceof PredictedAppIcon && !((PredictedAppIcon) host).isPinned()) {
39             out.add(new LauncherAction(PIN_PREDICTION, R.string.pin_prediction,
40                     KeyEvent.KEYCODE_P));
41         }
42         super.getSupportedActions(host, item, out);
43     }
44 
45     @Override
performAction(View host, ItemInfo item, int action, boolean fromKeyboard)46     protected boolean performAction(View host, ItemInfo item, int action, boolean fromKeyboard) {
47         QuickstepLauncher launcher = (QuickstepLauncher) mLauncher;
48         if (action == PIN_PREDICTION) {
49             if (launcher.getHotseatPredictionController() == null) {
50                 return false;
51             }
52             launcher.getHotseatPredictionController().pinPrediction(item);
53             return true;
54         }
55         return super.performAction(host, item, action, fromKeyboard);
56     }
57 }
58