1/* 2 * Copyright (C) 2012 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 17package com.android.inputmethod.latin.common; 18 19import com.android.inputmethod.annotations.UsedForTesting; 20 21import javax.annotation.Nonnull; 22 23public final class Constants { 24 25 public static final class Color { 26 /** 27 * The alpha value for fully opaque. 28 */ 29 public final static int ALPHA_OPAQUE = 255; 30 } 31 32 public static final class ImeOption { 33 /** 34 * The private IME option used to indicate that no microphone should be shown for a given 35 * text field. For instance, this is specified by the search dialog when the dialog is 36 * already showing a voice search button. 37 * 38 * @deprecated Use {@link ImeOption#NO_MICROPHONE} with package name prefixed. 39 */ 40 @SuppressWarnings("dep-ann") 41 public static final String NO_MICROPHONE_COMPAT = "nm"; 42 43 /** 44 * The private IME option used to indicate that no microphone should be shown for a given 45 * text field. For instance, this is specified by the search dialog when the dialog is 46 * already showing a voice search button. 47 */ 48 public static final String NO_MICROPHONE = "noMicrophoneKey"; 49 50 /** 51 * The private IME option used to indicate that no settings key should be shown for a given 52 * text field. 53 */ 54 public static final String NO_SETTINGS_KEY = "noSettingsKey"; 55 56 /** 57 * The private IME option used to indicate that the given text field needs ASCII code points 58 * input. 59 * 60 * @deprecated Use EditorInfo#IME_FLAG_FORCE_ASCII. 61 */ 62 @SuppressWarnings("dep-ann") 63 public static final String FORCE_ASCII = "forceAscii"; 64 65 /** 66 * The private IME option used to suppress the floating gesture preview for a given text 67 * field. This overrides the corresponding keyboard settings preference. 68 * {@link com.android.inputmethod.latin.settings.SettingsValues#mGestureFloatingPreviewTextEnabled} 69 */ 70 public static final String NO_FLOATING_GESTURE_PREVIEW = "noGestureFloatingPreview"; 71 72 private ImeOption() { 73 // This utility class is not publicly instantiable. 74 } 75 } 76 77 public static final class Subtype { 78 /** 79 * The subtype mode used to indicate that the subtype is a keyboard. 80 */ 81 public static final String KEYBOARD_MODE = "keyboard"; 82 83 public static final class ExtraValue { 84 /** 85 * The subtype extra value used to indicate that this subtype is capable of 86 * entering ASCII characters. 87 */ 88 public static final String ASCII_CAPABLE = "AsciiCapable"; 89 90 /** 91 * The subtype extra value used to indicate that this subtype is enabled 92 * when the default subtype is not marked as ascii capable. 93 */ 94 public static final String ENABLED_WHEN_DEFAULT_IS_NOT_ASCII_CAPABLE = 95 "EnabledWhenDefaultIsNotAsciiCapable"; 96 97 /** 98 * The subtype extra value used to indicate that this subtype is capable of 99 * entering emoji characters. 100 */ 101 public static final String EMOJI_CAPABLE = "EmojiCapable"; 102 103 /** 104 * The subtype extra value used to indicate that this subtype requires a network 105 * connection to work. 106 */ 107 public static final String REQ_NETWORK_CONNECTIVITY = "requireNetworkConnectivity"; 108 109 /** 110 * The subtype extra value used to indicate that the display name of this subtype 111 * contains a "%s" for printf-like replacement and it should be replaced by 112 * this extra value. 113 * This extra value is supported on JellyBean and later. 114 */ 115 public static final String UNTRANSLATABLE_STRING_IN_SUBTYPE_NAME = 116 "UntranslatableReplacementStringInSubtypeName"; 117 118 /** 119 * The subtype extra value used to indicate this subtype keyboard layout set name. 120 * This extra value is private to LatinIME. 121 */ 122 public static final String KEYBOARD_LAYOUT_SET = "KeyboardLayoutSet"; 123 124 /** 125 * The subtype extra value used to indicate that this subtype is an additional subtype 126 * that the user defined. This extra value is private to LatinIME. 127 */ 128 public static final String IS_ADDITIONAL_SUBTYPE = "isAdditionalSubtype"; 129 130 /** 131 * The subtype extra value used to specify the combining rules. 132 */ 133 public static final String COMBINING_RULES = "CombiningRules"; 134 135 private ExtraValue() { 136 // This utility class is not publicly instantiable. 137 } 138 } 139 140 private Subtype() { 141 // This utility class is not publicly instantiable. 142 } 143 } 144 145 public static final class TextUtils { 146 /** 147 * Capitalization mode for {@link android.text.TextUtils#getCapsMode}: don't capitalize 148 * characters. This value may be used with 149 * {@link android.text.TextUtils#CAP_MODE_CHARACTERS}, 150 * {@link android.text.TextUtils#CAP_MODE_WORDS}, and 151 * {@link android.text.TextUtils#CAP_MODE_SENTENCES}. 152 */ 153 // TODO: Straighten this out. It's bizarre to have to use android.text.TextUtils.CAP_MODE_* 154 // except for OFF that is in Constants.TextUtils. 155 public static final int CAP_MODE_OFF = 0; 156 157 private TextUtils() { 158 // This utility class is not publicly instantiable. 159 } 160 } 161 162 public static final int NOT_A_CODE = -1; 163 public static final int NOT_A_CURSOR_POSITION = -1; 164 // TODO: replace the following constants with state in InputTransaction? 165 public static final int NOT_A_COORDINATE = -1; 166 public static final int SUGGESTION_STRIP_COORDINATE = -2; 167 public static final int EXTERNAL_KEYBOARD_COORDINATE = -4; 168 169 // A hint on how many characters to cache from the TextView. A good value of this is given by 170 // how many characters we need to be able to almost always find the caps mode. 171 public static final int EDITOR_CONTENTS_CACHE_SIZE = 1024; 172 // How many characters we accept for the recapitalization functionality. This needs to be 173 // large enough for all reasonable purposes, but avoid purposeful attacks. 100k sounds about 174 // right for this. 175 public static final int MAX_CHARACTERS_FOR_RECAPITALIZATION = 1024 * 100; 176 177 // Key events coming any faster than this are long-presses. 178 public static final int LONG_PRESS_MILLISECONDS = 200; 179 // TODO: Set this value appropriately. 180 public static final int GET_SUGGESTED_WORDS_TIMEOUT = 200; 181 // How many continuous deletes at which to start deleting at a higher speed. 182 public static final int DELETE_ACCELERATE_AT = 20; 183 184 public static final String WORD_SEPARATOR = " "; 185 186 public static boolean isValidCoordinate(final int coordinate) { 187 // Detect {@link NOT_A_COORDINATE}, {@link SUGGESTION_STRIP_COORDINATE}, 188 // and {@link SPELL_CHECKER_COORDINATE}. 189 return coordinate >= 0; 190 } 191 192 /** 193 * Custom request code used in 194 * {@link com.android.inputmethod.keyboard.KeyboardActionListener#onCustomRequest(int)}. 195 */ 196 // The code to show input method picker. 197 public static final int CUSTOM_CODE_SHOW_INPUT_METHOD_PICKER = 1; 198 199 /** 200 * Some common keys code. Must be positive. 201 */ 202 public static final int CODE_ENTER = '\n'; 203 public static final int CODE_TAB = '\t'; 204 public static final int CODE_SPACE = ' '; 205 public static final int CODE_PERIOD = '.'; 206 public static final int CODE_COMMA = ','; 207 public static final int CODE_DASH = '-'; 208 public static final int CODE_SINGLE_QUOTE = '\''; 209 public static final int CODE_DOUBLE_QUOTE = '"'; 210 public static final int CODE_SLASH = '/'; 211 public static final int CODE_BACKSLASH = '\\'; 212 public static final int CODE_VERTICAL_BAR = '|'; 213 public static final int CODE_COMMERCIAL_AT = '@'; 214 public static final int CODE_PLUS = '+'; 215 public static final int CODE_PERCENT = '%'; 216 public static final int CODE_CLOSING_PARENTHESIS = ')'; 217 public static final int CODE_CLOSING_SQUARE_BRACKET = ']'; 218 public static final int CODE_CLOSING_CURLY_BRACKET = '}'; 219 public static final int CODE_CLOSING_ANGLE_BRACKET = '>'; 220 public static final int CODE_INVERTED_QUESTION_MARK = 0xBF; // ¿ 221 public static final int CODE_INVERTED_EXCLAMATION_MARK = 0xA1; // ¡ 222 public static final int CODE_GRAVE_ACCENT = '`'; 223 public static final int CODE_CIRCUMFLEX_ACCENT = '^'; 224 public static final int CODE_TILDE = '~'; 225 226 public static final String REGEXP_PERIOD = "\\."; 227 public static final String STRING_SPACE = " "; 228 229 /** 230 * Special keys code. Must be negative. 231 * These should be aligned with constants in 232 * {@link com.android.inputmethod.keyboard.internal.KeyboardCodesSet}. 233 */ 234 public static final int CODE_SHIFT = -1; 235 public static final int CODE_CAPSLOCK = -2; 236 public static final int CODE_SWITCH_ALPHA_SYMBOL = -3; 237 public static final int CODE_OUTPUT_TEXT = -4; 238 public static final int CODE_DELETE = -5; 239 public static final int CODE_SETTINGS = -6; 240 public static final int CODE_SHORTCUT = -7; 241 public static final int CODE_ACTION_NEXT = -8; 242 public static final int CODE_ACTION_PREVIOUS = -9; 243 public static final int CODE_LANGUAGE_SWITCH = -10; 244 public static final int CODE_EMOJI = -11; 245 public static final int CODE_SHIFT_ENTER = -12; 246 public static final int CODE_SYMBOL_SHIFT = -13; 247 public static final int CODE_ALPHA_FROM_EMOJI = -14; 248 // Code value representing the code is not specified. 249 public static final int CODE_UNSPECIFIED = -15; 250 251 public static boolean isLetterCode(final int code) { 252 return code >= CODE_SPACE; 253 } 254 255 @Nonnull 256 public static String printableCode(final int code) { 257 switch (code) { 258 case CODE_SHIFT: return "shift"; 259 case CODE_CAPSLOCK: return "capslock"; 260 case CODE_SWITCH_ALPHA_SYMBOL: return "symbol"; 261 case CODE_OUTPUT_TEXT: return "text"; 262 case CODE_DELETE: return "delete"; 263 case CODE_SETTINGS: return "settings"; 264 case CODE_SHORTCUT: return "shortcut"; 265 case CODE_ACTION_NEXT: return "actionNext"; 266 case CODE_ACTION_PREVIOUS: return "actionPrevious"; 267 case CODE_LANGUAGE_SWITCH: return "languageSwitch"; 268 case CODE_EMOJI: return "emoji"; 269 case CODE_SHIFT_ENTER: return "shiftEnter"; 270 case CODE_ALPHA_FROM_EMOJI: return "alpha"; 271 case CODE_UNSPECIFIED: return "unspec"; 272 case CODE_TAB: return "tab"; 273 case CODE_ENTER: return "enter"; 274 case CODE_SPACE: return "space"; 275 default: 276 if (code < CODE_SPACE) return String.format("\\u%02X", code); 277 if (code < 0x100) return String.format("%c", code); 278 if (code < 0x10000) return String.format("\\u%04X", code); 279 return String.format("\\U%05X", code); 280 } 281 } 282 283 @Nonnull 284 public static String printableCodes(@Nonnull final int[] codes) { 285 final StringBuilder sb = new StringBuilder(); 286 boolean addDelimiter = false; 287 for (final int code : codes) { 288 if (code == NOT_A_CODE) break; 289 if (addDelimiter) sb.append(", "); 290 sb.append(printableCode(code)); 291 addDelimiter = true; 292 } 293 return "[" + sb + "]"; 294 } 295 296 /** 297 * Screen metrics (a.k.a. Device form factor) constants of 298 * {@link com.android.inputmethod.latin.R.integer#config_screen_metrics}. 299 */ 300 public static final int SCREEN_METRICS_SMALL_PHONE = 0; 301 public static final int SCREEN_METRICS_LARGE_PHONE = 1; 302 public static final int SCREEN_METRICS_LARGE_TABLET = 2; 303 public static final int SCREEN_METRICS_SMALL_TABLET = 3; 304 305 @UsedForTesting 306 public static boolean isPhone(final int screenMetrics) { 307 return screenMetrics == SCREEN_METRICS_SMALL_PHONE 308 || screenMetrics == SCREEN_METRICS_LARGE_PHONE; 309 } 310 311 @UsedForTesting 312 public static boolean isTablet(final int screenMetrics) { 313 return screenMetrics == SCREEN_METRICS_SMALL_TABLET 314 || screenMetrics == SCREEN_METRICS_LARGE_TABLET; 315 } 316 317 /** 318 * Default capacity of gesture points container. 319 * This constant is used by {@link com.android.inputmethod.keyboard.internal.BatchInputArbiter} 320 * and etc. to preallocate regions that contain gesture event points. 321 */ 322 public static final int DEFAULT_GESTURE_POINTS_CAPACITY = 128; 323 324 public static final int MAX_IME_DECODER_RESULTS = 20; 325 public static final int DECODER_SCORE_SCALAR = 1000000; 326 public static final int DECODER_MAX_SCORE = 1000000000; 327 328 public static final int EVENT_BACKSPACE = 1; 329 public static final int EVENT_REJECTION = 2; 330 public static final int EVENT_REVERT = 3; 331 332 private Constants() { 333 // This utility class is not publicly instantiable. 334 } 335} 336