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