• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 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 
17 package com.android.launcher3.taskbar;
18 
19 import static android.view.Display.DEFAULT_DISPLAY;
20 
21 import android.content.Intent;
22 import android.view.inputmethod.InputMethodManager;
23 
24 import androidx.annotation.IntDef;
25 
26 import com.android.quickstep.OverviewCommandHelper;
27 import com.android.quickstep.SystemUiProxy;
28 import com.android.quickstep.TouchInteractionService;
29 
30 import java.lang.annotation.Retention;
31 import java.lang.annotation.RetentionPolicy;
32 
33 /**
34  * Controller for 3 button mode in the taskbar.
35  * Handles all the functionality of the various buttons, making/routing the right calls into
36  * launcher or sysui/system.
37  *
38  * TODO: Create callbacks to hook into UI layer since state will change for more context buttons/
39  *       assistant invocation.
40  */
41 public class TaskbarNavButtonController {
42     @Retention(RetentionPolicy.SOURCE)
43     @IntDef(value = {
44             BUTTON_BACK,
45             BUTTON_HOME,
46             BUTTON_RECENTS,
47             BUTTON_IME_SWITCH
48     })
49 
50     public @interface TaskbarButton {}
51 
52     static final int BUTTON_BACK = 1;
53     static final int BUTTON_HOME = BUTTON_BACK << 1;
54     static final int BUTTON_RECENTS = BUTTON_HOME << 1;
55     static final int BUTTON_IME_SWITCH = BUTTON_RECENTS << 1;
56 
57     private final TouchInteractionService mService;
58 
TaskbarNavButtonController(TouchInteractionService service)59     public TaskbarNavButtonController(TouchInteractionService service) {
60         mService = service;
61     }
62 
onButtonClick(@askbarButton int buttonType)63     public void onButtonClick(@TaskbarButton int buttonType) {
64         switch (buttonType) {
65             case BUTTON_BACK:
66                 executeBack();
67                 break;
68             case BUTTON_HOME:
69                 navigateHome();
70                 break;
71             case BUTTON_RECENTS:
72                 navigateToOverview();;
73                 break;
74             case BUTTON_IME_SWITCH:
75                 showIMESwitcher();
76                 break;
77         }
78     }
79 
navigateHome()80     private void navigateHome() {
81         mService.startActivity(new Intent(Intent.ACTION_MAIN)
82                 .addCategory(Intent.CATEGORY_HOME)
83                 .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
84     }
85 
navigateToOverview()86     private void navigateToOverview() {
87         mService.getOverviewCommandHelper()
88                 .addCommand(OverviewCommandHelper.TYPE_SHOW);
89     }
90 
executeBack()91     private void executeBack() {
92         SystemUiProxy.INSTANCE.getNoCreate().onBackPressed();
93     }
94 
showIMESwitcher()95     private void showIMESwitcher() {
96         mService.getSystemService(InputMethodManager.class)
97                 .showInputMethodPickerFromSystem(true /* showAuxiliarySubtypes */,
98                         DEFAULT_DISPLAY);
99     }
100 }
101