1 /*
2  * Copyright (C) 2020 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.internal.accessibility.common;
18 
19 import static com.android.internal.accessibility.AccessibilityShortcutController.ACCESSIBILITY_HEARING_AIDS_COMPONENT_NAME;
20 import static com.android.internal.accessibility.AccessibilityShortcutController.ACCESSIBILITY_HEARING_AIDS_TILE_COMPONENT_NAME;
21 import static com.android.internal.accessibility.AccessibilityShortcutController.COLOR_INVERSION_COMPONENT_NAME;
22 import static com.android.internal.accessibility.AccessibilityShortcutController.COLOR_INVERSION_TILE_COMPONENT_NAME;
23 import static com.android.internal.accessibility.AccessibilityShortcutController.DALTONIZER_COMPONENT_NAME;
24 import static com.android.internal.accessibility.AccessibilityShortcutController.DALTONIZER_TILE_COMPONENT_NAME;
25 import static com.android.internal.accessibility.AccessibilityShortcutController.FONT_SIZE_COMPONENT_NAME;
26 import static com.android.internal.accessibility.AccessibilityShortcutController.FONT_SIZE_TILE_COMPONENT_NAME;
27 import static com.android.internal.accessibility.AccessibilityShortcutController.ONE_HANDED_COMPONENT_NAME;
28 import static com.android.internal.accessibility.AccessibilityShortcutController.ONE_HANDED_TILE_COMPONENT_NAME;
29 import static com.android.internal.accessibility.AccessibilityShortcutController.REDUCE_BRIGHT_COLORS_COMPONENT_NAME;
30 import static com.android.internal.accessibility.AccessibilityShortcutController.REDUCE_BRIGHT_COLORS_TILE_SERVICE_COMPONENT_NAME;
31 
32 import android.annotation.IntDef;
33 import android.content.ComponentName;
34 
35 import java.lang.annotation.Retention;
36 import java.lang.annotation.RetentionPolicy;
37 import java.util.Map;
38 
39 /**
40  * Collection of common constants for accessibility shortcut.
41  */
42 public final class ShortcutConstants {
ShortcutConstants()43     private ShortcutConstants() {}
44 
45     /**
46      * Package name of the accessibility chooser and used for {@link android.content.Intent}.
47      */
48     public static final String CHOOSER_PACKAGE_NAME = "android";
49 
50     public static final char SERVICES_SEPARATOR = ':';
51 
52     /**
53      * Annotation for different user shortcut type UI type.
54      *
55      * {@code DEFAULT} for displaying default value.
56      * {@code SOFTWARE} for displaying specifying the accessibility services or features which
57      * choose accessibility button in the navigation bar as preferred shortcut.
58      * {@code HARDWARE} for displaying specifying the accessibility services or features which
59      * choose accessibility shortcut as preferred shortcut.
60      * {@code TRIPLETAP} for displaying specifying magnification to be toggled via quickly
61      * tapping screen 3 times as preferred shortcut.
62      * {@code TWOFINGER_DOUBLETAP} for displaying specifying magnification to be toggled via
63      * quickly tapping screen 2 times with two fingers as preferred shortcut.
64      * {@code QUICK_SETTINGS} for displaying specifying the accessibility services or features which
65      * choose Quick Settings as preferred shortcut.
66      */
67     @Retention(RetentionPolicy.SOURCE)
68     @IntDef({
69             UserShortcutType.DEFAULT,
70             UserShortcutType.SOFTWARE,
71             UserShortcutType.HARDWARE,
72             UserShortcutType.TRIPLETAP,
73             UserShortcutType.TWOFINGER_DOUBLETAP,
74             UserShortcutType.QUICK_SETTINGS,
75     })
76     public @interface UserShortcutType {
77         int DEFAULT = 0;
78         // LINT.IfChange(shortcut_type_intdef)
79         int SOFTWARE = 1 << 0;
80         int HARDWARE = 1 << 1;
81         int TRIPLETAP = 1 << 2;
82         int TWOFINGER_DOUBLETAP = 1 << 3;
83         int QUICK_SETTINGS = 1 << 4;
84         // LINT.ThenChange(:shortcut_type_array)
85     }
86 
87     /**
88      * A list of possible {@link UserShortcutType}. Should stay in sync with the
89      * non-default IntDef types.
90      */
91     public static final int[] USER_SHORTCUT_TYPES = {
92             // LINT.IfChange(shortcut_type_array)
93             UserShortcutType.SOFTWARE,
94             UserShortcutType.HARDWARE,
95             UserShortcutType.TRIPLETAP,
96             UserShortcutType.TWOFINGER_DOUBLETAP,
97             UserShortcutType.QUICK_SETTINGS,
98             // LINT.ThenChange(:shortcut_type_intdef)
99     };
100 
101 
102     /**
103      * Annotation for the different accessibility fragment type.
104      *
105      * {@code VOLUME_SHORTCUT_TOGGLE} for displaying appearance with switch bar and only one
106      * shortcut option that is volume key shortcut.
107      * {@code INVISIBLE_TOGGLE} for displaying appearance without switch bar.
108      * {@code TOGGLE} for displaying appearance with switch bar.
109      * {@code LAUNCH_ACTIVITY} for displaying appearance with pop-up action that is for launch
110      * activity.
111      */
112     @Retention(RetentionPolicy.SOURCE)
113     @IntDef({
114             AccessibilityFragmentType.VOLUME_SHORTCUT_TOGGLE,
115             AccessibilityFragmentType.INVISIBLE_TOGGLE,
116             AccessibilityFragmentType.TOGGLE,
117             AccessibilityFragmentType.LAUNCH_ACTIVITY,
118     })
119     public @interface AccessibilityFragmentType {
120         int VOLUME_SHORTCUT_TOGGLE = 0;
121         int INVISIBLE_TOGGLE = 1;
122         int TOGGLE = 2;
123         int LAUNCH_ACTIVITY = 3;
124     }
125 
126     /**
127      * Annotation for different shortcut menu mode.
128      *
129      * {@code LAUNCH} for clicking list item to trigger the service callback.
130      * {@code EDIT} for clicking list item and save button to disable the service.
131      */
132     @Retention(RetentionPolicy.SOURCE)
133     @IntDef({
134             ShortcutMenuMode.LAUNCH,
135             ShortcutMenuMode.EDIT,
136     })
137     public @interface ShortcutMenuMode {
138         int LAUNCH = 0;
139         int EDIT = 1;
140     }
141 
142     /**
143      * Annotation for different FAB shortcut type's menu size
144      */
145     @Retention(RetentionPolicy.SOURCE)
146     @IntDef({
147             FloatingMenuSize.UNKNOWN,
148             FloatingMenuSize.SMALL,
149             FloatingMenuSize.LARGE,
150     })
151     public @interface FloatingMenuSize {
152         int UNKNOWN = -1;
153         int SMALL = 0;
154         int LARGE = 1;
155     }
156 
157     /**
158      * A map of a11y feature to its qs tile component
159      */
160     public static final Map<ComponentName, ComponentName> A11Y_FEATURE_TO_FRAMEWORK_TILE = Map.of(
161             COLOR_INVERSION_COMPONENT_NAME, COLOR_INVERSION_TILE_COMPONENT_NAME,
162             DALTONIZER_COMPONENT_NAME, DALTONIZER_TILE_COMPONENT_NAME,
163             ONE_HANDED_COMPONENT_NAME, ONE_HANDED_TILE_COMPONENT_NAME,
164             REDUCE_BRIGHT_COLORS_COMPONENT_NAME, REDUCE_BRIGHT_COLORS_TILE_SERVICE_COMPONENT_NAME,
165             FONT_SIZE_COMPONENT_NAME, FONT_SIZE_TILE_COMPONENT_NAME,
166             ACCESSIBILITY_HEARING_AIDS_COMPONENT_NAME,
167             ACCESSIBILITY_HEARING_AIDS_TILE_COMPONENT_NAME
168     );
169 }
170