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