• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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.systemui.keyboard.shortcut.data.repository
18 
19 import android.content.Context
20 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_ACTIVATE_SELECT_TO_SPEAK
21 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_ALL_APPS
22 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_BACK
23 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_CHANGE_SPLITSCREEN_FOCUS_LEFT
24 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_CHANGE_SPLITSCREEN_FOCUS_RIGHT
25 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_HOME
26 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_APPLICATION
27 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_ASSISTANT
28 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS
29 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_LAUNCH_VOICE_ASSISTANT
30 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_LOCK_SCREEN
31 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_MINIMIZE_FREEFORM_WINDOW
32 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_MOVE_TO_NEXT_DISPLAY
33 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_MULTI_WINDOW_NAVIGATION
34 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_OPEN_SHORTCUT_HELPER
35 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS
36 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_RECENT_APPS_SWITCHER
37 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_SNAP_LEFT_FREEFORM_WINDOW
38 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_SNAP_RIGHT_FREEFORM_WINDOW
39 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_LEFT
40 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_RIGHT
41 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_TAKE_SCREENSHOT
42 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_BOUNCE_KEYS
43 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION
44 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MAXIMIZE_FREEFORM_WINDOW
45 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_MOUSE_KEYS
46 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_NOTIFICATION_PANEL
47 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_SLOW_KEYS
48 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_STICKY_KEYS
49 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_TALKBACK
50 import android.hardware.input.KeyGestureEvent.KEY_GESTURE_TYPE_TOGGLE_VOICE_ACCESS
51 import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.Accessibility
52 import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.AppCategories
53 import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.MultiTasking
54 import com.android.systemui.keyboard.shortcut.shared.model.ShortcutCategoryType.System
55 import com.android.systemui.res.R
56 import javax.inject.Inject
57 
58 class InputGestureMaps @Inject constructor(private val context: Context) {
59     val gestureToShortcutCategoryTypeMap =
60         mapOf(
61             // System Category
62             KEY_GESTURE_TYPE_HOME to System,
63             KEY_GESTURE_TYPE_RECENT_APPS to System,
64             KEY_GESTURE_TYPE_BACK to System,
65             KEY_GESTURE_TYPE_TAKE_SCREENSHOT to System,
66             KEY_GESTURE_TYPE_OPEN_SHORTCUT_HELPER to System,
67             KEY_GESTURE_TYPE_TOGGLE_NOTIFICATION_PANEL to System,
68             KEY_GESTURE_TYPE_LOCK_SCREEN to System,
69             KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS to System,
70             KEY_GESTURE_TYPE_LAUNCH_ASSISTANT to System,
71             KEY_GESTURE_TYPE_LAUNCH_VOICE_ASSISTANT to System,
72             KEY_GESTURE_TYPE_ALL_APPS to System,
73 
74             // Multitasking Category
75             KEY_GESTURE_TYPE_RECENT_APPS_SWITCHER to MultiTasking,
76             KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_LEFT to MultiTasking,
77             KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_RIGHT to MultiTasking,
78             KEY_GESTURE_TYPE_MULTI_WINDOW_NAVIGATION to MultiTasking,
79             KEY_GESTURE_TYPE_CHANGE_SPLITSCREEN_FOCUS_LEFT to MultiTasking,
80             KEY_GESTURE_TYPE_CHANGE_SPLITSCREEN_FOCUS_RIGHT to MultiTasking,
81             KEY_GESTURE_TYPE_SNAP_LEFT_FREEFORM_WINDOW to MultiTasking,
82             KEY_GESTURE_TYPE_SNAP_RIGHT_FREEFORM_WINDOW to MultiTasking,
83             KEY_GESTURE_TYPE_MINIMIZE_FREEFORM_WINDOW to MultiTasking,
84             KEY_GESTURE_TYPE_TOGGLE_MAXIMIZE_FREEFORM_WINDOW to MultiTasking,
85             KEY_GESTURE_TYPE_MOVE_TO_NEXT_DISPLAY to MultiTasking,
86 
87             // App Category
88             KEY_GESTURE_TYPE_LAUNCH_APPLICATION to AppCategories,
89 
90             // Accessibility Category
91             KEY_GESTURE_TYPE_TOGGLE_BOUNCE_KEYS to Accessibility,
92             KEY_GESTURE_TYPE_TOGGLE_MOUSE_KEYS to Accessibility,
93             KEY_GESTURE_TYPE_TOGGLE_STICKY_KEYS to Accessibility,
94             KEY_GESTURE_TYPE_TOGGLE_SLOW_KEYS to Accessibility,
95             KEY_GESTURE_TYPE_TOGGLE_VOICE_ACCESS to Accessibility,
96             KEY_GESTURE_TYPE_TOGGLE_TALKBACK to Accessibility,
97             KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION to Accessibility,
98             KEY_GESTURE_TYPE_ACTIVATE_SELECT_TO_SPEAK to Accessibility,
99         )
100 
101     val gestureToInternalKeyboardShortcutGroupLabelResIdMap =
102         mapOf(
103             // System Category
104             KEY_GESTURE_TYPE_HOME to R.string.shortcut_helper_category_system_controls,
105             KEY_GESTURE_TYPE_RECENT_APPS to R.string.shortcut_helper_category_system_controls,
106             KEY_GESTURE_TYPE_BACK to R.string.shortcut_helper_category_system_controls,
107             KEY_GESTURE_TYPE_TAKE_SCREENSHOT to R.string.shortcut_helper_category_system_controls,
108             KEY_GESTURE_TYPE_OPEN_SHORTCUT_HELPER to
109                 R.string.shortcut_helper_category_system_controls,
110             KEY_GESTURE_TYPE_TOGGLE_NOTIFICATION_PANEL to
111                 R.string.shortcut_helper_category_system_controls,
112             KEY_GESTURE_TYPE_LOCK_SCREEN to R.string.shortcut_helper_category_system_controls,
113             KEY_GESTURE_TYPE_ALL_APPS to R.string.shortcut_helper_category_system_controls,
114             KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS to
115                 R.string.shortcut_helper_category_system_apps,
116             KEY_GESTURE_TYPE_LAUNCH_ASSISTANT to R.string.shortcut_helper_category_system_apps,
117             KEY_GESTURE_TYPE_LAUNCH_VOICE_ASSISTANT to
118                 R.string.shortcut_helper_category_system_apps,
119 
120             // Multitasking Category
121             KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_LEFT to
122                 R.string.shortcutHelper_category_split_screen,
123             KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_RIGHT to
124                 R.string.shortcutHelper_category_split_screen,
125             KEY_GESTURE_TYPE_MULTI_WINDOW_NAVIGATION to
126                 R.string.shortcutHelper_category_split_screen,
127             KEY_GESTURE_TYPE_CHANGE_SPLITSCREEN_FOCUS_LEFT to
128                 R.string.shortcutHelper_category_split_screen,
129             KEY_GESTURE_TYPE_CHANGE_SPLITSCREEN_FOCUS_RIGHT to
130                 R.string.shortcutHelper_category_split_screen,
131             KEY_GESTURE_TYPE_SNAP_LEFT_FREEFORM_WINDOW to
132                 R.string.shortcutHelper_category_split_screen,
133             KEY_GESTURE_TYPE_SNAP_RIGHT_FREEFORM_WINDOW to
134                 R.string.shortcutHelper_category_split_screen,
135             KEY_GESTURE_TYPE_MINIMIZE_FREEFORM_WINDOW to
136                 R.string.shortcutHelper_category_split_screen,
137             KEY_GESTURE_TYPE_TOGGLE_MAXIMIZE_FREEFORM_WINDOW to
138                 R.string.shortcutHelper_category_split_screen,
139             KEY_GESTURE_TYPE_MOVE_TO_NEXT_DISPLAY to R.string.shortcutHelper_category_split_screen,
140 
141             // App Category
142             KEY_GESTURE_TYPE_LAUNCH_APPLICATION to R.string.keyboard_shortcut_group_applications,
143 
144             // Accessibility Category
145             KEY_GESTURE_TYPE_TOGGLE_BOUNCE_KEYS to R.string.shortcutHelper_category_accessibility,
146             KEY_GESTURE_TYPE_TOGGLE_MOUSE_KEYS to R.string.shortcutHelper_category_accessibility,
147             KEY_GESTURE_TYPE_TOGGLE_STICKY_KEYS to R.string.shortcutHelper_category_accessibility,
148             KEY_GESTURE_TYPE_TOGGLE_SLOW_KEYS to R.string.shortcutHelper_category_accessibility,
149             KEY_GESTURE_TYPE_TOGGLE_VOICE_ACCESS to R.string.shortcutHelper_category_accessibility,
150             KEY_GESTURE_TYPE_TOGGLE_TALKBACK to R.string.shortcutHelper_category_accessibility,
151             KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION to R.string.shortcutHelper_category_accessibility,
152             KEY_GESTURE_TYPE_ACTIVATE_SELECT_TO_SPEAK to
153                 R.string.shortcutHelper_category_accessibility,
154         )
155 
156     /**
157      * App Category shortcut labels are mapped dynamically based on intent see
158      * [InputGestureDataAdapter.fetchShortcutLabelByAppLaunchData]
159      */
160     val gestureToInternalKeyboardShortcutInfoLabelResIdMap =
161         mapOf(
162             // System Category
163             KEY_GESTURE_TYPE_HOME to R.string.group_system_access_home_screen,
164             KEY_GESTURE_TYPE_RECENT_APPS to R.string.group_system_overview_open_apps,
165             KEY_GESTURE_TYPE_BACK to R.string.group_system_go_back,
166             KEY_GESTURE_TYPE_TAKE_SCREENSHOT to R.string.group_system_full_screenshot,
167             KEY_GESTURE_TYPE_OPEN_SHORTCUT_HELPER to
168                 R.string.group_system_access_system_app_shortcuts,
169             KEY_GESTURE_TYPE_TOGGLE_NOTIFICATION_PANEL to
170                 R.string.group_system_access_notification_shade,
171             KEY_GESTURE_TYPE_LOCK_SCREEN to R.string.group_system_lock_screen,
172             KEY_GESTURE_TYPE_ALL_APPS to R.string.group_system_access_all_apps_search,
173             KEY_GESTURE_TYPE_LAUNCH_SYSTEM_SETTINGS to R.string.group_system_access_system_settings,
174             KEY_GESTURE_TYPE_LAUNCH_ASSISTANT to R.string.group_system_access_google_assistant,
175             KEY_GESTURE_TYPE_LAUNCH_VOICE_ASSISTANT to
176                 R.string.group_system_access_google_assistant,
177 
178             // Multitasking Category
179             KEY_GESTURE_TYPE_RECENT_APPS_SWITCHER to R.string.group_system_cycle_forward,
180             KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_LEFT to R.string.system_multitasking_lhs,
181             KEY_GESTURE_TYPE_SPLIT_SCREEN_NAVIGATION_RIGHT to R.string.system_multitasking_rhs,
182             KEY_GESTURE_TYPE_MULTI_WINDOW_NAVIGATION to R.string.system_multitasking_full_screen,
183             KEY_GESTURE_TYPE_SNAP_LEFT_FREEFORM_WINDOW to
184                 R.string.system_desktop_mode_snap_left_window,
185             KEY_GESTURE_TYPE_SNAP_RIGHT_FREEFORM_WINDOW to
186                 R.string.system_desktop_mode_snap_right_window,
187             KEY_GESTURE_TYPE_MINIMIZE_FREEFORM_WINDOW to
188                 R.string.system_desktop_mode_minimize_window,
189             KEY_GESTURE_TYPE_TOGGLE_MAXIMIZE_FREEFORM_WINDOW to
190                 R.string.system_desktop_mode_toggle_maximize_window,
191             KEY_GESTURE_TYPE_MOVE_TO_NEXT_DISPLAY to
192                 R.string.system_multitasking_move_to_next_display,
193 
194             // Accessibility Category
195             KEY_GESTURE_TYPE_TOGGLE_BOUNCE_KEYS to R.string.group_accessibility_toggle_bounce_keys,
196             KEY_GESTURE_TYPE_TOGGLE_MOUSE_KEYS to R.string.group_accessibility_toggle_mouse_keys,
197             KEY_GESTURE_TYPE_TOGGLE_STICKY_KEYS to R.string.group_accessibility_toggle_sticky_keys,
198             KEY_GESTURE_TYPE_TOGGLE_SLOW_KEYS to R.string.group_accessibility_toggle_slow_keys,
199             KEY_GESTURE_TYPE_TOGGLE_VOICE_ACCESS to
200                 R.string.group_accessibility_toggle_voice_access,
201             KEY_GESTURE_TYPE_TOGGLE_TALKBACK to R.string.group_accessibility_toggle_talkback,
202             KEY_GESTURE_TYPE_TOGGLE_MAGNIFICATION to
203                 R.string.group_accessibility_toggle_magnification,
204             KEY_GESTURE_TYPE_ACTIVATE_SELECT_TO_SPEAK to
205                 R.string.group_accessibility_activate_select_to_speak,
206         )
207 
208     val shortcutLabelToKeyGestureTypeMap: Map<String, Int>
209         get() =
<lambda>null210             gestureToInternalKeyboardShortcutInfoLabelResIdMap.entries.associateBy({
211                 context.getString(it.value)
212             }) {
213                 it.key
214             }
215 }
216