Constants.java revision 576f8a5b72b550c5d610ccf9014e19db4a9cb8c9
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;
18
19public 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
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            private ExtraValue() {
119                // This utility class is not publicly instantiable.
120            }
121        }
122
123        private Subtype() {
124            // This utility class is not publicly instantiable.
125        }
126    }
127
128    public static final class TextUtils {
129        /**
130         * Capitalization mode for {@link android.text.TextUtils#getCapsMode}: don't capitalize
131         * characters.  This value may be used with
132         * {@link android.text.TextUtils#CAP_MODE_CHARACTERS},
133         * {@link android.text.TextUtils#CAP_MODE_WORDS}, and
134         * {@link android.text.TextUtils#CAP_MODE_SENTENCES}.
135         */
136        // TODO: Straighten this out. It's bizarre to have to use android.text.TextUtils.CAP_MODE_*
137        // except for OFF that is in Constants.TextUtils.
138        public static final int CAP_MODE_OFF = 0;
139
140        private TextUtils() {
141            // This utility class is not publicly instantiable.
142        }
143    }
144
145    public static final int NOT_A_CODE = -1;
146    public static final int NOT_A_CURSOR_POSITION = -1;
147    public static final int NOT_A_COORDINATE = -1;
148    public static final int SUGGESTION_STRIP_COORDINATE = -2;
149    public static final int SPELL_CHECKER_COORDINATE = -3;
150    public static final int EXTERNAL_KEYBOARD_COORDINATE = -4;
151
152    // A hint on how many characters to cache from the TextView. A good value of this is given by
153    // how many characters we need to be able to almost always find the caps mode.
154    public static final int EDITOR_CONTENTS_CACHE_SIZE = 1024;
155
156    // Must be equal to MAX_WORD_LENGTH in native/jni/src/defines.h
157    public static final int DICTIONARY_MAX_WORD_LENGTH = 48;
158
159    // Key events coming any faster than this are long-presses.
160    public static final int LONG_PRESS_MILLISECONDS = 200;
161    // TODO: Set this value appropriately.
162    public static final int GET_SUGGESTED_WORDS_TIMEOUT = 200;
163    // How many continuous deletes at which to start deleting at a higher speed.
164    public static final int DELETE_ACCELERATE_AT = 20;
165
166    public static boolean isValidCoordinate(final int coordinate) {
167        // Detect {@link NOT_A_COORDINATE}, {@link SUGGESTION_STRIP_COORDINATE},
168        // and {@link SPELL_CHECKER_COORDINATE}.
169        return coordinate >= 0;
170    }
171
172    /**
173     * Custom request code used in
174     * {@link com.android.inputmethod.keyboard.KeyboardActionListener#onCustomRequest(int)}.
175     */
176    // The code to show input method picker.
177    public static final int CUSTOM_CODE_SHOW_INPUT_METHOD_PICKER = 1;
178
179    /**
180     * Some common keys code. Must be positive.
181     */
182    public static final int CODE_ENTER = '\n';
183    public static final int CODE_TAB = '\t';
184    public static final int CODE_SPACE = ' ';
185    public static final int CODE_PERIOD = '.';
186    public static final int CODE_COMMA = ',';
187    public static final int CODE_ARMENIAN_PERIOD = 0x0589;
188    public static final int CODE_DASH = '-';
189    public static final int CODE_SINGLE_QUOTE = '\'';
190    public static final int CODE_DOUBLE_QUOTE = '"';
191    public static final int CODE_QUESTION_MARK = '?';
192    public static final int CODE_EXCLAMATION_MARK = '!';
193    public static final int CODE_SLASH = '/';
194    public static final int CODE_COMMERCIAL_AT = '@';
195    public static final int CODE_PLUS = '+';
196    public static final int CODE_PERCENT = '%';
197    public static final int CODE_CLOSING_PARENTHESIS = ')';
198    public static final int CODE_CLOSING_SQUARE_BRACKET = ']';
199    public static final int CODE_CLOSING_CURLY_BRACKET = '}';
200    public static final int CODE_CLOSING_ANGLE_BRACKET = '>';
201
202    /**
203     * Special keys code. Must be negative.
204     * These should be aligned with {@link KeyboardCodesSet#ID_TO_NAME},
205     * {@link KeyboardCodesSet#DEFAULT}, and {@link KeyboardCodesSet#RTL}.
206     */
207    public static final int CODE_SHIFT = -1;
208    public static final int CODE_CAPSLOCK = -2;
209    public static final int CODE_SWITCH_ALPHA_SYMBOL = -3;
210    public static final int CODE_OUTPUT_TEXT = -4;
211    public static final int CODE_DELETE = -5;
212    public static final int CODE_SETTINGS = -6;
213    public static final int CODE_SHORTCUT = -7;
214    public static final int CODE_ACTION_NEXT = -8;
215    public static final int CODE_ACTION_PREVIOUS = -9;
216    public static final int CODE_LANGUAGE_SWITCH = -10;
217    public static final int CODE_EMOJI = -11;
218    public static final int CODE_SHIFT_ENTER = -12;
219    public static final int CODE_SYMBOL_SHIFT = -13;
220    public static final int CODE_ALPHA_FROM_EMOJI = -14;
221    // Code value representing the code is not specified.
222    public static final int CODE_UNSPECIFIED = -15;
223
224    public static boolean isLetterCode(final int code) {
225        return code >= CODE_SPACE;
226    }
227
228    public static String printableCode(final int code) {
229        switch (code) {
230        case CODE_SHIFT: return "shift";
231        case CODE_CAPSLOCK: return "capslock";
232        case CODE_SWITCH_ALPHA_SYMBOL: return "symbol";
233        case CODE_OUTPUT_TEXT: return "text";
234        case CODE_DELETE: return "delete";
235        case CODE_SETTINGS: return "settings";
236        case CODE_SHORTCUT: return "shortcut";
237        case CODE_ACTION_NEXT: return "actionNext";
238        case CODE_ACTION_PREVIOUS: return "actionPrevious";
239        case CODE_LANGUAGE_SWITCH: return "languageSwitch";
240        case CODE_EMOJI: return "emoji";
241        case CODE_SHIFT_ENTER: return "shiftEnter";
242        case CODE_UNSPECIFIED: return "unspec";
243        case CODE_TAB: return "tab";
244        case CODE_ENTER: return "enter";
245        case CODE_ALPHA_FROM_EMOJI: return "alpha";
246        default:
247            if (code < CODE_SPACE) return String.format("'\\u%02x'", code);
248            if (code < 0x100) return String.format("'%c'", code);
249            return String.format("'\\u%04x'", code);
250        }
251    }
252
253    public static final int MAX_INT_BIT_COUNT = 32;
254
255    /**
256     * Screen metrics (a.k.a. Device form factor) constants of
257     * {@link R.integer#config_screen_metrics}.
258     */
259    public static final int SCREEN_METRICS_SMALL_PHONE = 0;
260    public static final int SCREEN_METRICS_LARGE_PHONE = 1;
261    public static final int SCREEN_METRICS_LARGE_TABLET = 2;
262    public static final int SCREEN_METRICS_SMALL_TABLET = 3;
263
264    /**
265     * Default capacity of gesture points container.
266     * This constant is used by {@link BatchInputArbiter} and etc. to preallocate regions that
267     * contain gesture event points.
268     */
269    public static final int DEFAULT_GESTURE_POINTS_CAPACITY = 128;
270
271    private Constants() {
272        // This utility class is not publicly instantiable.
273    }
274}
275