1/*
2 * Copyright (C) 2008 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 android.text;
18
19/**
20 * Bit definitions for an integer defining the basic content type of text
21 * held in an {@link Editable} object. Supported classes may be combined
22 * with variations and flags to indicate desired behaviors.
23 *
24 * <h3>Examples</h3>
25 *
26 * <dl>
27 * <dt>A password field with the password visible to the user:
28 * <dd>inputType = TYPE_CLASS_TEXT |
29 *     TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
30 *
31 * <dt>A multi-line postal address with automatic capitalization:
32 * <dd>inputType = TYPE_CLASS_TEXT |
33 *     TYPE_TEXT_VARIATION_POSTAL_ADDRESS |
34 *     TYPE_TEXT_FLAG_MULTI_LINE
35 *
36 * <dt>A time field:
37 * <dd>inputType = TYPE_CLASS_DATETIME |
38 *     TYPE_DATETIME_VARIATION_TIME
39 * </dl>
40 */
41public interface InputType {
42    /**
43     * Mask of bits that determine the overall class
44     * of text being given.  Currently supported classes are:
45     * {@link #TYPE_CLASS_TEXT}, {@link #TYPE_CLASS_NUMBER},
46     * {@link #TYPE_CLASS_PHONE}, {@link #TYPE_CLASS_DATETIME}.
47     * <p>IME authors: If the class is not one you
48     * understand, assume {@link #TYPE_CLASS_TEXT} with NO variation
49     * or flags.<p>
50     */
51    public static final int TYPE_MASK_CLASS = 0x0000000f;
52
53    /**
54     * Mask of bits that determine the variation of
55     * the base content class.
56     */
57    public static final int TYPE_MASK_VARIATION = 0x00000ff0;
58
59    /**
60     * Mask of bits that provide addition bit flags
61     * of options.
62     */
63    public static final int TYPE_MASK_FLAGS = 0x00fff000;
64
65    /**
66     * Special content type for when no explicit type has been specified.
67     * This should be interpreted to mean that the target input connection
68     * is not rich, it can not process and show things like candidate text nor
69     * retrieve the current text, so the input method will need to run in a
70     * limited "generate key events" mode, if it supports it. Note that some
71     * input methods may not support it, for example a voice-based input
72     * method will likely not be able to generate key events even if this
73     * flag is set.
74     */
75    public static final int TYPE_NULL = 0x00000000;
76
77    // ----------------------------------------------------------------------
78    // ----------------------------------------------------------------------
79    // ----------------------------------------------------------------------
80
81    /**
82     * Class for normal text.  This class supports the following flags (only
83     * one of which should be set):
84     * {@link #TYPE_TEXT_FLAG_CAP_CHARACTERS},
85     * {@link #TYPE_TEXT_FLAG_CAP_WORDS}, and.
86     * {@link #TYPE_TEXT_FLAG_CAP_SENTENCES}.  It also supports the
87     * following variations:
88     * {@link #TYPE_TEXT_VARIATION_NORMAL}, and
89     * {@link #TYPE_TEXT_VARIATION_URI}.  If you do not recognize the
90     * variation, normal should be assumed.
91     */
92    public static final int TYPE_CLASS_TEXT = 0x00000001;
93
94    /**
95     * Flag for {@link #TYPE_CLASS_TEXT}: capitalize all characters.  Overrides
96     * {@link #TYPE_TEXT_FLAG_CAP_WORDS} and
97     * {@link #TYPE_TEXT_FLAG_CAP_SENTENCES}.  This value is explicitly defined
98     * to be the same as {@link TextUtils#CAP_MODE_CHARACTERS}. Of course,
99     * this only affects languages where there are upper-case and lower-case letters.
100     */
101    public static final int TYPE_TEXT_FLAG_CAP_CHARACTERS = 0x00001000;
102
103    /**
104     * Flag for {@link #TYPE_CLASS_TEXT}: capitalize the first character of
105     * every word.  Overrides {@link #TYPE_TEXT_FLAG_CAP_SENTENCES}.  This
106     * value is explicitly defined
107     * to be the same as {@link TextUtils#CAP_MODE_WORDS}. Of course,
108     * this only affects languages where there are upper-case and lower-case letters.
109     */
110    public static final int TYPE_TEXT_FLAG_CAP_WORDS = 0x00002000;
111
112    /**
113     * Flag for {@link #TYPE_CLASS_TEXT}: capitalize the first character of
114     * each sentence.  This value is explicitly defined
115     * to be the same as {@link TextUtils#CAP_MODE_SENTENCES}. For example
116     * in English it means to capitalize after a period and a space (note that other
117     * languages may have different characters for period, or not use spaces,
118     * or use different grammatical rules). Of course,
119     * this only affects languages where there are upper-case and lower-case letters.
120     */
121    public static final int TYPE_TEXT_FLAG_CAP_SENTENCES = 0x00004000;
122
123    /**
124     * Flag for {@link #TYPE_CLASS_TEXT}: the user is entering free-form
125     * text that should have auto-correction applied to it. Without this flag,
126     * the IME will not try to correct typos. You should always set this flag
127     * unless you really expect users to type non-words in this field, for
128     * example to choose a name for a character in a game.
129     * Contrast this with {@link #TYPE_TEXT_FLAG_AUTO_COMPLETE} and
130     * {@link #TYPE_TEXT_FLAG_NO_SUGGESTIONS}:
131     * {@code TYPE_TEXT_FLAG_AUTO_CORRECT} means that the IME will try to
132     * auto-correct typos as the user is typing, but does not define whether
133     * the IME offers an interface to show suggestions.
134     */
135    public static final int TYPE_TEXT_FLAG_AUTO_CORRECT = 0x00008000;
136
137    /**
138     * Flag for {@link #TYPE_CLASS_TEXT}: the text editor (which means
139     * the application) is performing auto-completion of the text being entered
140     * based on its own semantics, which it will present to the user as they type.
141     * This generally means that the input method should not be showing
142     * candidates itself, but can expect the editor to supply its own
143     * completions/candidates from
144     * {@link android.view.inputmethod.InputMethodSession#displayCompletions
145     * InputMethodSession.displayCompletions()} as a result of the editor calling
146     * {@link android.view.inputmethod.InputMethodManager#displayCompletions
147     * InputMethodManager.displayCompletions()}.
148     * Note the contrast with {@link #TYPE_TEXT_FLAG_AUTO_CORRECT} and
149     * {@link #TYPE_TEXT_FLAG_NO_SUGGESTIONS}:
150     * {@code TYPE_TEXT_FLAG_AUTO_COMPLETE} means the editor should show an
151     * interface for displaying suggestions, but instead of supplying its own
152     * it will rely on the Editor to pass completions/corrections.
153     */
154    public static final int TYPE_TEXT_FLAG_AUTO_COMPLETE = 0x00010000;
155
156    /**
157     * Flag for {@link #TYPE_CLASS_TEXT}: multiple lines of text can be
158     * entered into the field.  If this flag is not set, the text field
159     * will be constrained to a single line. The IME may also choose not to
160     * display an enter key when this flag is not set, as there should be no
161     * need to create new lines.
162     */
163    public static final int TYPE_TEXT_FLAG_MULTI_LINE = 0x00020000;
164
165    /**
166     * Flag for {@link #TYPE_CLASS_TEXT}: the regular text view associated
167     * with this should not be multi-line, but when a fullscreen input method
168     * is providing text it should use multiple lines if it can.
169     */
170    public static final int TYPE_TEXT_FLAG_IME_MULTI_LINE = 0x00040000;
171
172    /**
173     * Flag for {@link #TYPE_CLASS_TEXT}: the input method does not need to
174     * display any dictionary-based candidates. This is useful for text views that
175     * do not contain words from the language and do not benefit from any
176     * dictionary-based completions or corrections. It overrides the
177     * {@link #TYPE_TEXT_FLAG_AUTO_CORRECT} value when set.
178     * Please avoid using this unless you are certain this is what you want.
179     * Many input methods need suggestions to work well, for example the ones
180     * based on gesture typing. Consider clearing
181     * {@link #TYPE_TEXT_FLAG_AUTO_CORRECT} instead if you just do not
182     * want the IME to correct typos.
183     * Note the contrast with {@link #TYPE_TEXT_FLAG_AUTO_CORRECT} and
184     * {@link #TYPE_TEXT_FLAG_AUTO_COMPLETE}:
185     * {@code TYPE_TEXT_FLAG_NO_SUGGESTIONS} means the IME does not need to
186     * show an interface to display suggestions. Most IMEs will also take this to
187     * mean they do not need to try to auto-correct what the user is typing.
188     */
189    public static final int TYPE_TEXT_FLAG_NO_SUGGESTIONS = 0x00080000;
190
191    // ----------------------------------------------------------------------
192
193    /**
194     * Default variation of {@link #TYPE_CLASS_TEXT}: plain old normal text.
195     */
196    public static final int TYPE_TEXT_VARIATION_NORMAL = 0x00000000;
197
198    /**
199     * Variation of {@link #TYPE_CLASS_TEXT}: entering a URI.
200     */
201    public static final int TYPE_TEXT_VARIATION_URI = 0x00000010;
202
203    /**
204     * Variation of {@link #TYPE_CLASS_TEXT}: entering an e-mail address.
205     */
206    public static final int TYPE_TEXT_VARIATION_EMAIL_ADDRESS = 0x00000020;
207
208    /**
209     * Variation of {@link #TYPE_CLASS_TEXT}: entering the subject line of
210     * an e-mail.
211     */
212    public static final int TYPE_TEXT_VARIATION_EMAIL_SUBJECT = 0x00000030;
213
214    /**
215     * Variation of {@link #TYPE_CLASS_TEXT}: entering a short, possibly informal
216     * message such as an instant message or a text message.
217     */
218    public static final int TYPE_TEXT_VARIATION_SHORT_MESSAGE = 0x00000040;
219
220    /**
221     * Variation of {@link #TYPE_CLASS_TEXT}: entering the content of a long, possibly
222     * formal message such as the body of an e-mail.
223     */
224    public static final int TYPE_TEXT_VARIATION_LONG_MESSAGE = 0x00000050;
225
226    /**
227     * Variation of {@link #TYPE_CLASS_TEXT}: entering the name of a person.
228     */
229    public static final int TYPE_TEXT_VARIATION_PERSON_NAME = 0x00000060;
230
231    /**
232     * Variation of {@link #TYPE_CLASS_TEXT}: entering a postal mailing address.
233     */
234    public static final int TYPE_TEXT_VARIATION_POSTAL_ADDRESS = 0x00000070;
235
236    /**
237     * Variation of {@link #TYPE_CLASS_TEXT}: entering a password.
238     */
239    public static final int TYPE_TEXT_VARIATION_PASSWORD = 0x00000080;
240
241    /**
242     * Variation of {@link #TYPE_CLASS_TEXT}: entering a password, which should
243     * be visible to the user.
244     */
245    public static final int TYPE_TEXT_VARIATION_VISIBLE_PASSWORD = 0x00000090;
246
247    /**
248     * Variation of {@link #TYPE_CLASS_TEXT}: entering text inside of a web form.
249     */
250    public static final int TYPE_TEXT_VARIATION_WEB_EDIT_TEXT = 0x000000a0;
251
252    /**
253     * Variation of {@link #TYPE_CLASS_TEXT}: entering text to filter contents
254     * of a list etc.
255     */
256    public static final int TYPE_TEXT_VARIATION_FILTER = 0x000000b0;
257
258    /**
259     * Variation of {@link #TYPE_CLASS_TEXT}: entering text for phonetic
260     * pronunciation, such as a phonetic name field in contacts. This is mostly
261     * useful for languages where one spelling may have several phonetic
262     * readings, like Japanese.
263     */
264    public static final int TYPE_TEXT_VARIATION_PHONETIC = 0x000000c0;
265
266    /**
267     * Variation of {@link #TYPE_CLASS_TEXT}: entering e-mail address inside
268     * of a web form.  This was added in
269     * {@link android.os.Build.VERSION_CODES#HONEYCOMB}.  An IME must target
270     * this API version or later to see this input type; if it doesn't, a request
271     * for this type will be seen as {@link #TYPE_TEXT_VARIATION_EMAIL_ADDRESS}
272     * when passed through {@link android.view.inputmethod.EditorInfo#makeCompatible(int)
273     * EditorInfo.makeCompatible(int)}.
274     */
275    public static final int TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS = 0x000000d0;
276
277    /**
278     * Variation of {@link #TYPE_CLASS_TEXT}: entering password inside
279     * of a web form.  This was added in
280     * {@link android.os.Build.VERSION_CODES#HONEYCOMB}.  An IME must target
281     * this API version or later to see this input type; if it doesn't, a request
282     * for this type will be seen as {@link #TYPE_TEXT_VARIATION_PASSWORD}
283     * when passed through {@link android.view.inputmethod.EditorInfo#makeCompatible(int)
284     * EditorInfo.makeCompatible(int)}.
285     */
286    public static final int TYPE_TEXT_VARIATION_WEB_PASSWORD = 0x000000e0;
287
288    // ----------------------------------------------------------------------
289    // ----------------------------------------------------------------------
290    // ----------------------------------------------------------------------
291
292    /**
293     * Class for numeric text.  This class supports the following flags:
294     * {@link #TYPE_NUMBER_FLAG_SIGNED} and
295     * {@link #TYPE_NUMBER_FLAG_DECIMAL}.  It also supports the following
296     * variations: {@link #TYPE_NUMBER_VARIATION_NORMAL} and
297     * {@link #TYPE_NUMBER_VARIATION_PASSWORD}.
298     * <p>IME authors: If you do not recognize
299     * the variation, normal should be assumed.</p>
300     */
301    public static final int TYPE_CLASS_NUMBER = 0x00000002;
302
303    /**
304     * Flag of {@link #TYPE_CLASS_NUMBER}: the number is signed, allowing
305     * a positive or negative sign at the start.
306     */
307    public static final int TYPE_NUMBER_FLAG_SIGNED = 0x00001000;
308
309    /**
310     * Flag of {@link #TYPE_CLASS_NUMBER}: the number is decimal, allowing
311     * a decimal point to provide fractional values.
312     */
313    public static final int TYPE_NUMBER_FLAG_DECIMAL = 0x00002000;
314
315    // ----------------------------------------------------------------------
316
317    /**
318     * Default variation of {@link #TYPE_CLASS_NUMBER}: plain normal
319     * numeric text.  This was added in
320     * {@link android.os.Build.VERSION_CODES#HONEYCOMB}.  An IME must target
321     * this API version or later to see this input type; if it doesn't, a request
322     * for this type will be dropped when passed through
323     * {@link android.view.inputmethod.EditorInfo#makeCompatible(int)
324     * EditorInfo.makeCompatible(int)}.
325     */
326    public static final int TYPE_NUMBER_VARIATION_NORMAL = 0x00000000;
327
328    /**
329     * Variation of {@link #TYPE_CLASS_NUMBER}: entering a numeric password.
330     * This was added in {@link android.os.Build.VERSION_CODES#HONEYCOMB}.  An
331     * IME must target this API version or later to see this input type; if it
332     * doesn't, a request for this type will be dropped when passed
333     * through {@link android.view.inputmethod.EditorInfo#makeCompatible(int)
334     * EditorInfo.makeCompatible(int)}.
335     */
336    public static final int TYPE_NUMBER_VARIATION_PASSWORD = 0x00000010;
337
338    // ----------------------------------------------------------------------
339    // ----------------------------------------------------------------------
340    // ----------------------------------------------------------------------
341
342    /**
343     * Class for a phone number.  This class currently supports no variations
344     * or flags.
345     */
346    public static final int TYPE_CLASS_PHONE = 0x00000003;
347
348    // ----------------------------------------------------------------------
349    // ----------------------------------------------------------------------
350    // ----------------------------------------------------------------------
351
352    /**
353     * Class for dates and times.  It supports the
354     * following variations:
355     * {@link #TYPE_DATETIME_VARIATION_NORMAL}
356     * {@link #TYPE_DATETIME_VARIATION_DATE}, and
357     * {@link #TYPE_DATETIME_VARIATION_TIME}.
358     */
359    public static final int TYPE_CLASS_DATETIME = 0x00000004;
360
361    /**
362     * Default variation of {@link #TYPE_CLASS_DATETIME}: allows entering
363     * both a date and time.
364     */
365    public static final int TYPE_DATETIME_VARIATION_NORMAL = 0x00000000;
366
367    /**
368     * Default variation of {@link #TYPE_CLASS_DATETIME}: allows entering
369     * only a date.
370     */
371    public static final int TYPE_DATETIME_VARIATION_DATE = 0x00000010;
372
373    /**
374     * Default variation of {@link #TYPE_CLASS_DATETIME}: allows entering
375     * only a time.
376     */
377    public static final int TYPE_DATETIME_VARIATION_TIME = 0x00000020;
378}
379