• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.systemui.accessibility.accessibilitymenu.model;
17 
18 import android.util.Log;
19 
20 import com.android.systemui.accessibility.accessibilitymenu.R;
21 
22 import java.util.Map;
23 
24 /**
25  * Provides a data structure for a11y menu shortcuts.
26  */
27 public class A11yMenuShortcut {
28 
29     public enum ShortcutId {
30         UNSPECIFIED_ID_VALUE,
31         ID_ASSISTANT_VALUE,
32         ID_A11YSETTING_VALUE,
33         ID_POWER_VALUE,
34         ID_VOLUME_DOWN_VALUE,
35         ID_VOLUME_UP_VALUE,
36         ID_RECENT_VALUE,
37         ID_BRIGHTNESS_DOWN_VALUE,
38         ID_BRIGHTNESS_UP_VALUE,
39         ID_LOCKSCREEN_VALUE,
40         ID_QUICKSETTING_VALUE,
41         ID_NOTIFICATION_VALUE,
42         ID_SCREENSHOT_VALUE
43     }
44 
45     private static final String TAG = "A11yMenuShortcut";
46 
47     // Index of resource ID in the array, shortcutResource.
48     private static final int IMG_SRC_INDEX = 0;
49     private static final int IMG_COLOR_INDEX = 1;
50     private static final int CONTENT_DESCRIPTION_INDEX = 2;
51     private static final int LABEL_TEXT_INDEX = 3;
52 
53     /** Map stores all shortcut resource IDs that is in matching order of defined shortcut. */
54     private static final Map<ShortcutId, int[]> sShortcutResource = Map.ofEntries(
55             Map.entry(ShortcutId.ID_ASSISTANT_VALUE, new int[] {
56                     R.drawable.ic_logo_a11y_assistant,
57                     R.color.assistant_color,
58                     R.string.assistant_utterance,
59                     R.string.assistant_label,
60             }),
61             Map.entry(ShortcutId.ID_A11YSETTING_VALUE, new int[] {
62                     R.drawable.ic_logo_a11y_settings,
63                     R.color.a11y_settings_color,
64                     R.string.a11y_settings_label,
65                     R.string.a11y_settings_label,
66             }),
67             Map.entry(ShortcutId.ID_POWER_VALUE, new int[] {
68                     R.drawable.ic_logo_a11y_power,
69                     R.color.power_color,
70                     R.string.power_utterance,
71                     R.string.power_label,
72             }),
73             Map.entry(ShortcutId.ID_RECENT_VALUE, new int[] {
74                     R.drawable.ic_logo_a11y_recent_apps,
75                     R.color.recent_apps_color,
76                     R.string.recent_apps_label,
77                     R.string.recent_apps_label,
78             }),
79             Map.entry(ShortcutId.ID_LOCKSCREEN_VALUE, new int[] {
80                     R.drawable.ic_logo_a11y_lock,
81                     R.color.lockscreen_color,
82                     R.string.lockscreen_label,
83                     R.string.lockscreen_label,
84             }),
85             Map.entry(ShortcutId.ID_QUICKSETTING_VALUE, new int[] {
86                     R.drawable.ic_logo_a11y_quick_settings,
87                     R.color.quick_settings_color,
88                     R.string.quick_settings_label,
89                     R.string.quick_settings_label,
90             }),
91             Map.entry(ShortcutId.ID_NOTIFICATION_VALUE, new int[] {
92                     R.drawable.ic_logo_a11y_notifications,
93                     R.color.notifications_color,
94                     R.string.notifications_label,
95                     R.string.notifications_label,
96             }),
97             Map.entry(ShortcutId.ID_SCREENSHOT_VALUE, new int[] {
98                     R.drawable.ic_logo_a11y_screenshot,
99                     R.color.screenshot_color,
100                     R.string.screenshot_utterance,
101                     R.string.screenshot_label,
102             }),
103             Map.entry(ShortcutId.ID_BRIGHTNESS_UP_VALUE, new int[] {
104                     R.drawable.ic_logo_a11y_brightness_up,
105                     R.color.brightness_color,
106                     R.string.brightness_up_label,
107                     R.string.brightness_up_label,
108             }),
109             Map.entry(ShortcutId.ID_BRIGHTNESS_DOWN_VALUE, new int[] {
110                     R.drawable.ic_logo_a11y_brightness_down,
111                     R.color.brightness_color,
112                     R.string.brightness_down_label,
113                     R.string.brightness_down_label,
114             }),
115             Map.entry(ShortcutId.ID_VOLUME_UP_VALUE, new int[] {
116                     R.drawable.ic_logo_a11y_volume_up,
117                     R.color.volume_color,
118                     R.string.volume_up_label,
119                     R.string.volume_up_label,
120             }),
121             Map.entry(ShortcutId.ID_VOLUME_DOWN_VALUE, new int[] {
122                     R.drawable.ic_logo_a11y_volume_down,
123                     R.color.volume_color,
124                     R.string.volume_down_label,
125                     R.string.volume_down_label,
126             })
127     );
128 
129     /** Shortcut id used to identify. */
130     private int mShortcutId = ShortcutId.UNSPECIFIED_ID_VALUE.ordinal();
131 
132     // Resource IDs of shortcut button and label.
133     public int imageSrc;
134     public int imageColor;
135     public int imgContentDescription;
136     public int labelText;
137 
A11yMenuShortcut(int id)138     public A11yMenuShortcut(int id) {
139         setId(id);
140     }
141 
142     /**
143      * Sets Id to shortcut, checks the value first and updates shortcut resources. It will set id to
144      * default value {@link ShortcutId.UNSPECIFIED_ID_VALUE} if invalid.
145      *
146      * @param id id set to shortcut
147      */
setId(int id)148     public void setId(int id) {
149         mShortcutId = id;
150 
151         if (id < ShortcutId.UNSPECIFIED_ID_VALUE.ordinal()
152                 || id > ShortcutId.values().length) {
153             mShortcutId = ShortcutId.UNSPECIFIED_ID_VALUE.ordinal();
154             Log.w(
155                     TAG, String.format(
156                             "setId to default UNSPECIFIED_ID as id is invalid. "
157                                     + "Max value is %d while id is %d",
158                             ShortcutId.values().length, id
159                     ));
160         }
161         int[] resources = sShortcutResource.getOrDefault(ShortcutId.values()[id], new int[] {
162                 R.drawable.ic_add_32dp,
163                 android.R.color.darker_gray,
164                 R.string.empty_content,
165                 R.string.empty_content,
166         });
167         imageSrc = resources[IMG_SRC_INDEX];
168         imageColor = resources[IMG_COLOR_INDEX];
169         imgContentDescription = resources[CONTENT_DESCRIPTION_INDEX];
170         labelText = resources[LABEL_TEXT_INDEX];
171     }
172 
getId()173     public int getId() {
174         return mShortcutId;
175     }
176 
177     @Override
equals(Object o)178     public boolean equals(Object o) {
179         if (this == o) {
180             return true;
181         }
182         if (!(o instanceof A11yMenuShortcut)) {
183             return false;
184         }
185 
186         A11yMenuShortcut targetObject = (A11yMenuShortcut) o;
187 
188         return mShortcutId == targetObject.mShortcutId;
189     }
190 
191     @Override
hashCode()192     public int hashCode() {
193         return mShortcutId;
194     }
195 }
196