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