blob: 8e7b0db21946266130dc79902c2dbb247c236e80 [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017package android.view.inputmethod;
18
Yohei Yukawa0f5eade2019-01-18 08:48:07 -080019import static android.Manifest.permission.INTERACT_ACROSS_USERS_FULL;
20
Yohei Yukawad469f212016-01-21 12:38:09 -080021import android.annotation.Nullable;
Yohei Yukawa0f5eade2019-01-18 08:48:07 -080022import android.annotation.RequiresPermission;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080023import android.os.Bundle;
Yohei Yukawa23cbe852016-05-17 16:42:58 -070024import android.os.LocaleList;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080025import android.os.Parcel;
26import android.os.Parcelable;
Yohei Yukawa0f5eade2019-01-18 08:48:07 -080027import android.os.UserHandle;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028import android.text.InputType;
29import android.text.TextUtils;
30import android.util.Printer;
31
Yohei Yukawa152944f2016-06-10 19:04:34 -070032import java.util.Arrays;
33
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034/**
35 * An EditorInfo describes several attributes of a text editing object
36 * that an input method is communicating with (typically an EditText), most
Jean Chalard6fd68e02014-02-20 17:48:46 +090037 * importantly the type of text content it contains and the current cursor position.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038 */
39public class EditorInfo implements InputType, Parcelable {
40 /**
Yohei Yukawad0bbe212016-11-09 19:49:50 -080041 * Masks for {@link inputType}
42 *
43 * <pre>
44 * |-------|-------|-------|-------|
45 * 1111 TYPE_MASK_CLASS
46 * 11111111 TYPE_MASK_VARIATION
47 * 111111111111 TYPE_MASK_FLAGS
48 * |-------|-------|-------|-------|
49 * TYPE_NULL
50 * |-------|-------|-------|-------|
51 * 1 TYPE_CLASS_TEXT
52 * 1 TYPE_TEXT_VARIATION_URI
53 * 1 TYPE_TEXT_VARIATION_EMAIL_ADDRESS
54 * 11 TYPE_TEXT_VARIATION_EMAIL_SUBJECT
55 * 1 TYPE_TEXT_VARIATION_SHORT_MESSAGE
56 * 1 1 TYPE_TEXT_VARIATION_LONG_MESSAGE
57 * 11 TYPE_TEXT_VARIATION_PERSON_NAME
58 * 111 TYPE_TEXT_VARIATION_POSTAL_ADDRESS
59 * 1 TYPE_TEXT_VARIATION_PASSWORD
60 * 1 1 TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
61 * 1 1 TYPE_TEXT_VARIATION_WEB_EDIT_TEXT
62 * 1 11 TYPE_TEXT_VARIATION_FILTER
63 * 11 TYPE_TEXT_VARIATION_PHONETIC
64 * 11 1 TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS
65 * 111 TYPE_TEXT_VARIATION_WEB_PASSWORD
66 * 1 TYPE_TEXT_FLAG_CAP_CHARACTERS
67 * 1 TYPE_TEXT_FLAG_CAP_WORDS
68 * 1 TYPE_TEXT_FLAG_CAP_SENTENCES
69 * 1 TYPE_TEXT_FLAG_AUTO_CORRECT
70 * 1 TYPE_TEXT_FLAG_AUTO_COMPLETE
71 * 1 TYPE_TEXT_FLAG_MULTI_LINE
72 * 1 TYPE_TEXT_FLAG_IME_MULTI_LINE
73 * 1 TYPE_TEXT_FLAG_NO_SUGGESTIONS
74 * |-------|-------|-------|-------|
75 * 1 TYPE_CLASS_NUMBER
76 * 1 TYPE_NUMBER_VARIATION_PASSWORD
77 * 1 TYPE_NUMBER_FLAG_SIGNED
78 * 1 TYPE_NUMBER_FLAG_DECIMAL
79 * |-------|-------|-------|-------|
80 * 11 TYPE_CLASS_PHONE
81 * |-------|-------|-------|-------|
82 * 1 TYPE_CLASS_DATETIME
83 * 1 TYPE_DATETIME_VARIATION_DATE
84 * 1 TYPE_DATETIME_VARIATION_TIME
85 * |-------|-------|-------|-------|</pre>
86 */
87
88 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080089 * The content type of the text box, whose bits are defined by
90 * {@link InputType}.
Jean Chalard6fd68e02014-02-20 17:48:46 +090091 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080092 * @see InputType
93 * @see #TYPE_MASK_CLASS
94 * @see #TYPE_MASK_VARIATION
95 * @see #TYPE_MASK_FLAGS
96 */
97 public int inputType = TYPE_NULL;
98
99 /**
100 * Set of bits in {@link #imeOptions} that provide alternative actions
101 * associated with the "enter" key. This both helps the IME provide
102 * better feedback about what the enter key will do, and also allows it
103 * to provide alternative mechanisms for providing that command.
104 */
105 public static final int IME_MASK_ACTION = 0x000000ff;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900106
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800107 /**
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700108 * Bits of {@link #IME_MASK_ACTION}: no specific action has been
109 * associated with this editor, let the editor come up with its own if
110 * it can.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800111 */
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700112 public static final int IME_ACTION_UNSPECIFIED = 0x00000000;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900113
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700114 /**
115 * Bits of {@link #IME_MASK_ACTION}: there is no available action.
116 */
117 public static final int IME_ACTION_NONE = 0x00000001;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900118
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800119 /**
120 * Bits of {@link #IME_MASK_ACTION}: the action key performs a "go"
121 * operation to take the user to the target of the text they typed.
122 * Typically used, for example, when entering a URL.
123 */
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700124 public static final int IME_ACTION_GO = 0x00000002;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900125
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800126 /**
127 * Bits of {@link #IME_MASK_ACTION}: the action key performs a "search"
128 * operation, taking the user to the results of searching for the text
Jean Chalardc1a11f172013-11-11 17:47:51 +0900129 * they have typed (in whatever context is appropriate).
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800130 */
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700131 public static final int IME_ACTION_SEARCH = 0x00000003;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900132
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800133 /**
134 * Bits of {@link #IME_MASK_ACTION}: the action key performs a "send"
135 * operation, delivering the text to its target. This is typically used
Jean Chalardc1a11f172013-11-11 17:47:51 +0900136 * when composing a message in IM or SMS where sending is immediate.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800137 */
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700138 public static final int IME_ACTION_SEND = 0x00000004;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900139
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800140 /**
141 * Bits of {@link #IME_MASK_ACTION}: the action key performs a "next"
142 * operation, taking the user to the next field that will accept text.
143 */
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700144 public static final int IME_ACTION_NEXT = 0x00000005;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900145
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800146 /**
The Android Open Source Project4df24232009-03-05 14:34:35 -0800147 * Bits of {@link #IME_MASK_ACTION}: the action key performs a "done"
Jean Chalardc1a11f172013-11-11 17:47:51 +0900148 * operation, typically meaning there is nothing more to input and the
149 * IME will be closed.
The Android Open Source Project4df24232009-03-05 14:34:35 -0800150 */
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700151 public static final int IME_ACTION_DONE = 0x00000006;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900152
The Android Open Source Project4df24232009-03-05 14:34:35 -0800153 /**
Jean Chalard6fd68e02014-02-20 17:48:46 +0900154 * Bits of {@link #IME_MASK_ACTION}: like {@link #IME_ACTION_NEXT}, but
Dianne Hackborndea3ef72010-10-28 14:24:22 -0700155 * for moving to the previous field. This will normally not be used to
Jean Chalardc1a11f172013-11-11 17:47:51 +0900156 * specify an action (since it precludes {@link #IME_ACTION_NEXT}), but
Dianne Hackborndea3ef72010-10-28 14:24:22 -0700157 * can be returned to the app if it sets {@link #IME_FLAG_NAVIGATE_PREVIOUS}.
158 */
159 public static final int IME_ACTION_PREVIOUS = 0x00000007;
160
161 /**
Yohei Yukawad91860d2017-04-14 13:46:37 -0700162 * Flag of {@link #imeOptions}: used to request that the IME should not update any personalized
Yohei Yukawa5959af12016-11-10 20:18:30 -0800163 * data such as typing history and personalized language model based on what the user typed on
164 * this text editing object. Typical use cases are:
165 * <ul>
166 * <li>When the application is in a special mode, where user's activities are expected to be
167 * not recorded in the application's history. Some web browsers and chat applications may
168 * have this kind of modes.</li>
169 * <li>When storing typing history does not make much sense. Specifying this flag in typing
170 * games may help to avoid typing history from being filled up with words that the user is
171 * less likely to type in their daily life. Another example is that when the application
172 * already knows that the expected input is not a valid word (e.g. a promotion code that is
173 * not a valid word in any natural language).</li>
174 * </ul>
175 *
176 * <p>Applications need to be aware that the flag is not a guarantee, and some IMEs may not
177 * respect it.</p>
178 */
179 public static final int IME_FLAG_NO_PERSONALIZED_LEARNING = 0x1000000;
180
181 /**
Dianne Hackborndea3ef72010-10-28 14:24:22 -0700182 * Flag of {@link #imeOptions}: used to request that the IME never go
Jean Chalardc1a11f172013-11-11 17:47:51 +0900183 * into fullscreen mode.
184 * By default, IMEs may go into full screen mode when they think
185 * it's appropriate, for example on small screens in landscape
186 * orientation where displaying a software keyboard may occlude
187 * such a large portion of the screen that the remaining part is
188 * too small to meaningfully display the application UI.
189 * If this flag is set, compliant IMEs will never go into full screen mode,
190 * and always leave some space to display the application UI.
191 * Applications need to be aware that the flag is not a guarantee, and
192 * some IMEs may ignore it.
Dianne Hackborndea3ef72010-10-28 14:24:22 -0700193 */
194 public static final int IME_FLAG_NO_FULLSCREEN = 0x2000000;
195
196 /**
197 * Flag of {@link #imeOptions}: like {@link #IME_FLAG_NAVIGATE_NEXT}, but
198 * specifies there is something interesting that a backward navigation
199 * can focus on. If the user selects the IME's facility to backward
200 * navigate, this will show up in the application as an {@link #IME_ACTION_PREVIOUS}
201 * at {@link InputConnection#performEditorAction(int)
202 * InputConnection.performEditorAction(int)}.
203 */
204 public static final int IME_FLAG_NAVIGATE_PREVIOUS = 0x4000000;
205
206 /**
207 * Flag of {@link #imeOptions}: used to specify that there is something
208 * interesting that a forward navigation can focus on. This is like using
209 * {@link #IME_ACTION_NEXT}, except allows the IME to be multiline (with
210 * an enter key) as well as provide forward navigation. Note that some
211 * IMEs may not be able to do this, especially when running on a small
212 * screen where there is little space. In that case it does not need to
213 * present a UI for this option. Like {@link #IME_ACTION_NEXT}, if the
214 * user selects the IME's facility to forward navigate, this will show up
215 * in the application at {@link InputConnection#performEditorAction(int)
216 * InputConnection.performEditorAction(int)}.
217 */
218 public static final int IME_FLAG_NAVIGATE_NEXT = 0x8000000;
219
220 /**
The Android Open Source Project10592532009-03-18 17:39:46 -0700221 * Flag of {@link #imeOptions}: used to specify that the IME does not need
222 * to show its extracted text UI. For input methods that may be fullscreen,
223 * often when in landscape mode, this allows them to be smaller and let part
Jean Chalardc1a11f172013-11-11 17:47:51 +0900224 * of the application be shown behind, through transparent UI parts in the
225 * fullscreen IME. The part of the UI visible to the user may not be responsive
226 * to touch because the IME will receive touch events, which may confuse the
Jean Chalard218ecd42013-11-13 15:20:38 +0900227 * user; use {@link #IME_FLAG_NO_FULLSCREEN} instead for a better experience.
Jean Chalardc1a11f172013-11-11 17:47:51 +0900228 * Using this flag is discouraged and it may become deprecated in the future.
229 * Its meaning is unclear in some situations and it may not work appropriately
230 * on older versions of the platform.
The Android Open Source Project10592532009-03-18 17:39:46 -0700231 */
232 public static final int IME_FLAG_NO_EXTRACT_UI = 0x10000000;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900233
The Android Open Source Project10592532009-03-18 17:39:46 -0700234 /**
Jean Chalardc1a11f172013-11-11 17:47:51 +0900235 * Flag of {@link #imeOptions}: used in conjunction with one of the actions
236 * masked by {@link #IME_MASK_ACTION}, this indicates that the action
237 * should not be available as an accessory button on the right of the extracted
238 * text when the input method is full-screen. Note that by setting this flag,
239 * there can be cases where the action is simply never available to the
240 * user. Setting this generally means that you think that in fullscreen mode,
241 * where there is little space to show the text, it's not worth taking some
242 * screen real estate to display the action and it should be used instead
243 * to show more text.
The Android Open Source Project10592532009-03-18 17:39:46 -0700244 */
245 public static final int IME_FLAG_NO_ACCESSORY_ACTION = 0x20000000;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900246
The Android Open Source Project10592532009-03-18 17:39:46 -0700247 /**
Jean Chalardc1a11f172013-11-11 17:47:51 +0900248 * Flag of {@link #imeOptions}: used in conjunction with one of the actions
249 * masked by {@link #IME_MASK_ACTION}. If this flag is not set, IMEs will
250 * normally replace the "enter" key with the action supplied. This flag
251 * indicates that the action should not be available in-line as a replacement
252 * for the "enter" key. Typically this is because the action has such a
253 * significant impact or is not recoverable enough that accidentally hitting
254 * it should be avoided, such as sending a message. Note that
255 * {@link android.widget.TextView} will automatically set this flag for you
256 * on multi-line text views.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800257 */
258 public static final int IME_FLAG_NO_ENTER_ACTION = 0x40000000;
Leon Scroggins2edd6822010-01-12 11:36:13 -0500259
260 /**
Jean Chalardc1a11f172013-11-11 17:47:51 +0900261 * Flag of {@link #imeOptions}: used to request an IME that is capable of
Ken Wakasac8f41832012-01-12 22:51:55 +0900262 * inputting ASCII characters. The intention of this flag is to ensure that
Jean Chalardc1a11f172013-11-11 17:47:51 +0900263 * the user can type Roman alphabet characters in a {@link android.widget.TextView}.
264 * It is typically used for an account ID or password input. A lot of the time,
265 * IMEs are already able to input ASCII even without being told so (such IMEs
266 * already respect this flag in a sense), but there are cases when this is not
267 * the default. For instance, users of languages using a different script like
268 * Arabic, Greek, Hebrew or Russian typically have a keyboard that can't
269 * input ASCII characters by default. Applications need to be
270 * aware that the flag is not a guarantee, and some IMEs may not respect it.
Ken Wakasac8f41832012-01-12 22:51:55 +0900271 * However, it is strongly recommended for IME authors to respect this flag
Jean Chalardc1a11f172013-11-11 17:47:51 +0900272 * especially when their IME could end up with a state where only languages
273 * using non-ASCII are enabled.
Ken Wakasac8f41832012-01-12 22:51:55 +0900274 */
275 public static final int IME_FLAG_FORCE_ASCII = 0x80000000;
276
277 /**
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700278 * Generic unspecified type for {@link #imeOptions}.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800279 */
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700280 public static final int IME_NULL = 0x00000000;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900281
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800282 /**
Yohei Yukawad0bbe212016-11-09 19:49:50 -0800283 * Masks for {@link imeOptions}
284 *
285 * <pre>
286 * |-------|-------|-------|-------|
287 * 1111 IME_MASK_ACTION
288 * |-------|-------|-------|-------|
289 * IME_ACTION_UNSPECIFIED
290 * 1 IME_ACTION_NONE
291 * 1 IME_ACTION_GO
292 * 11 IME_ACTION_SEARCH
293 * 1 IME_ACTION_SEND
294 * 1 1 IME_ACTION_NEXT
295 * 11 IME_ACTION_DONE
296 * 111 IME_ACTION_PREVIOUS
Yohei Yukawa5959af12016-11-10 20:18:30 -0800297 * 1 IME_FLAG_NO_PERSONALIZED_LEARNING
Yohei Yukawad0bbe212016-11-09 19:49:50 -0800298 * 1 IME_FLAG_NO_FULLSCREEN
299 * 1 IME_FLAG_NAVIGATE_PREVIOUS
300 * 1 IME_FLAG_NAVIGATE_NEXT
301 * 1 IME_FLAG_NO_EXTRACT_UI
302 * 1 IME_FLAG_NO_ACCESSORY_ACTION
303 * 1 IME_FLAG_NO_ENTER_ACTION
304 * 1 IME_FLAG_FORCE_ASCII
305 * |-------|-------|-------|-------|</pre>
306 */
307
308 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800309 * Extended type information for the editor, to help the IME better
310 * integrate with it.
311 */
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700312 public int imeOptions = IME_NULL;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900313
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800314 /**
315 * A string supplying additional information options that are
316 * private to a particular IME implementation. The string must be
317 * scoped to a package owned by the implementation, to ensure there are
318 * no conflicts between implementations, but other than that you can put
319 * whatever you want in it to communicate with the IME. For example,
320 * you could have a string that supplies an argument like
321 * <code>"com.example.myapp.SpecialMode=3"</code>. This field is can be
322 * filled in from the {@link android.R.attr#privateImeOptions}
323 * attribute of a TextView.
324 */
325 public String privateImeOptions = null;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900326
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800327 /**
328 * In some cases an IME may be able to display an arbitrary label for
Jean Chalardc1a11f172013-11-11 17:47:51 +0900329 * a command the user can perform, which you can specify here. This is
330 * typically used as the label for the action to use in-line as a replacement
331 * for the "enter" key (see {@link #actionId}). Remember the key where
332 * this will be displayed is typically very small, and there are significant
333 * localization challenges to make this fit in all supported languages. Also
334 * you can not count absolutely on this being used, as some IMEs may
335 * ignore this.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800336 */
337 public CharSequence actionLabel = null;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900338
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800339 /**
340 * If {@link #actionLabel} has been given, this is the id for that command
341 * when the user presses its button that is delivered back with
342 * {@link InputConnection#performEditorAction(int)
343 * InputConnection.performEditorAction()}.
344 */
345 public int actionId = 0;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900346
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800347 /**
348 * The text offset of the start of the selection at the time editing
Jean Chalard6fd68e02014-02-20 17:48:46 +0900349 * begins; -1 if not known. Keep in mind that, without knowing the cursor
350 * position, many IMEs will not be able to offer their full feature set and
351 * may even behave in unpredictable ways: pass the actual cursor position
352 * here if possible at all.
353 *
354 * <p>Also, this needs to be the cursor position <strong>right now</strong>,
355 * not at some point in the past, even if input is starting in the same text field
356 * as before. When the app is filling this object, input is about to start by
357 * definition, and this value will override any value the app may have passed to
358 * {@link InputMethodManager#updateSelection(android.view.View, int, int, int, int)}
359 * before.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800360 */
361 public int initialSelStart = -1;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900362
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800363 /**
Jean Chalard6fd68e02014-02-20 17:48:46 +0900364 * <p>The text offset of the end of the selection at the time editing
365 * begins; -1 if not known. Keep in mind that, without knowing the cursor
366 * position, many IMEs will not be able to offer their full feature set and
367 * may behave in unpredictable ways: pass the actual cursor position
368 * here if possible at all.</p>
369 *
370 * <p>Also, this needs to be the cursor position <strong>right now</strong>,
371 * not at some point in the past, even if input is starting in the same text field
372 * as before. When the app is filling this object, input is about to start by
373 * definition, and this value will override any value the app may have passed to
374 * {@link InputMethodManager#updateSelection(android.view.View, int, int, int, int)}
375 * before.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800376 */
377 public int initialSelEnd = -1;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900378
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800379 /**
380 * The capitalization mode of the first character being edited in the
381 * text. Values may be any combination of
382 * {@link TextUtils#CAP_MODE_CHARACTERS TextUtils.CAP_MODE_CHARACTERS},
383 * {@link TextUtils#CAP_MODE_WORDS TextUtils.CAP_MODE_WORDS}, and
384 * {@link TextUtils#CAP_MODE_SENTENCES TextUtils.CAP_MODE_SENTENCES}, though
Jean Chalard6fd68e02014-02-20 17:48:46 +0900385 * you should generally just take a non-zero value to mean "start out in
386 * caps mode".
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800387 */
388 public int initialCapsMode = 0;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900389
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800390 /**
391 * The "hint" text of the text view, typically shown in-line when the
392 * text is empty to tell the user what to enter.
393 */
394 public CharSequence hintText;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900395
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800396 /**
397 * A label to show to the user describing the text they are writing.
398 */
399 public CharSequence label;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900400
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800401 /**
402 * Name of the package that owns this editor.
Yohei Yukawa915e2c72015-06-08 17:05:44 -0700403 *
404 * <p><strong>IME authors:</strong> In API level 22
405 * {@link android.os.Build.VERSION_CODES#LOLLIPOP_MR1} and prior, do not trust this package
406 * name. The system had not verified the consistency between the package name here and
407 * application's uid. Consider to use {@link InputBinding#getUid()}, which is trustworthy.
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700408 * Starting from {@link android.os.Build.VERSION_CODES#M}, the system verifies the consistency
409 * between this package name and application uid before {@link EditorInfo} is passed to the
410 * input method.</p>
Yohei Yukawa915e2c72015-06-08 17:05:44 -0700411 *
Dianne Hackborn0e3de6c2015-07-29 15:20:21 -0700412 * <p><strong>Editor authors:</strong> Starting from {@link android.os.Build.VERSION_CODES#M},
413 * the application is no longer
Yohei Yukawa915e2c72015-06-08 17:05:44 -0700414 * able to establish input connections if the package name provided here is inconsistent with
Yohei Yukawad57ba672015-06-08 16:39:46 -0700415 * application's uid.</p>
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800416 */
417 public String packageName;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900418
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800419 /**
420 * Identifier for the editor's field. This is optional, and may be
421 * 0. By default it is filled in with the result of
422 * {@link android.view.View#getId() View.getId()} on the View that
423 * is being edited.
424 */
425 public int fieldId;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900426
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800427 /**
428 * Additional name for the editor's field. This can supply additional
429 * name information for the field. By default it is null. The actual
430 * contents have no meaning.
431 */
432 public String fieldName;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900433
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800434 /**
435 * Any extra data to supply to the input method. This is for extended
436 * communication with specific input methods; the name fields in the
437 * bundle should be scoped (such as "com.mydomain.im.SOME_FIELD") so
Jean Chalardc1a11f172013-11-11 17:47:51 +0900438 * that they don't conflict with others. This field can be
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800439 * filled in from the {@link android.R.attr#editorExtras}
440 * attribute of a TextView.
441 */
442 public Bundle extras;
Jean Chalard6fd68e02014-02-20 17:48:46 +0900443
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800444 /**
Yohei Yukawad469f212016-01-21 12:38:09 -0800445 * List of the languages that the user is supposed to switch to no matter what input method
446 * subtype is currently used. This special "hint" can be used mainly for, but not limited to,
447 * multilingual users who want IMEs to switch language context automatically.
Yohei Yukawa8d6eeb02015-12-03 11:27:32 -0800448 *
Yohei Yukawad469f212016-01-21 12:38:09 -0800449 * <p>{@code null} means that no special language "hint" is needed.</p>
Yohei Yukawa8d6eeb02015-12-03 11:27:32 -0800450 *
Yohei Yukawad469f212016-01-21 12:38:09 -0800451 * <p><strong>Editor authors:</strong> Specify this only when you are confident that the user
452 * will switch to certain languages in this context no matter what input method subtype is
453 * currently selected. Otherwise, keep this {@code null}. Explicit user actions and/or
454 * preferences would be good signals to specify this special "hint", For example, a chat
455 * application may be able to put the last used language at the top of {@link #hintLocales}
456 * based on whom the user is going to talk, by remembering what language is used in the last
457 * conversation. Do not specify {@link android.widget.TextView#getTextLocales()} only because
458 * it is used for text rendering.</p>
459 *
460 * @see android.widget.TextView#setImeHintLocales(LocaleList)
461 * @see android.widget.TextView#getImeHintLocales()
Yohei Yukawa8d6eeb02015-12-03 11:27:32 -0800462 */
Yohei Yukawad469f212016-01-21 12:38:09 -0800463 @Nullable
464 public LocaleList hintLocales = null;
Yohei Yukawa8d6eeb02015-12-03 11:27:32 -0800465
Yohei Yukawa152944f2016-06-10 19:04:34 -0700466
467 /**
468 * List of acceptable MIME types for
Yohei Yukawa45700fa2016-06-23 17:12:59 -0700469 * {@link InputConnection#commitContent(InputContentInfo, int, Bundle)}.
Yohei Yukawa152944f2016-06-10 19:04:34 -0700470 *
471 * <p>{@code null} or an empty array means that
Yohei Yukawa45700fa2016-06-23 17:12:59 -0700472 * {@link InputConnection#commitContent(InputContentInfo, int, Bundle)} is not supported in this
Yohei Yukawa152944f2016-06-10 19:04:34 -0700473 * editor.</p>
474 */
475 @Nullable
476 public String[] contentMimeTypes = null;
477
Yohei Yukawa8d6eeb02015-12-03 11:27:32 -0800478 /**
Yohei Yukawa0f5eade2019-01-18 08:48:07 -0800479 * If not {@code null}, this editor needs to talk to IMEs that run for the specified user, no
480 * matter what user ID the calling process has.
481 *
Yohei Yukawa716897c2019-01-22 00:00:53 -0800482 * <p>Note: This field will be silently ignored when
483 * {@link android.view.inputmethod.InputMethodSystemProperty#MULTI_CLIENT_IME_ENABLED} is
484 * {@code true}.</p>
Yohei Yukawa0f5eade2019-01-18 08:48:07 -0800485 *
486 * <p>Note also that pseudo handles such as {@link UserHandle#ALL} are not supported.</p>
487 *
488 * @hide
489 */
490 @RequiresPermission(INTERACT_ACROSS_USERS_FULL)
491 @Nullable
492 public UserHandle targetInputMethodUser = null;
493
494 /**
Dianne Hackborndea3ef72010-10-28 14:24:22 -0700495 * Ensure that the data in this EditorInfo is compatible with an application
496 * that was developed against the given target API version. This can
497 * impact the following input types:
498 * {@link InputType#TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS},
Ken Wakasa82d731a2010-12-24 23:42:41 +0900499 * {@link InputType#TYPE_TEXT_VARIATION_WEB_PASSWORD},
500 * {@link InputType#TYPE_NUMBER_VARIATION_NORMAL},
501 * {@link InputType#TYPE_NUMBER_VARIATION_PASSWORD}.
Dianne Hackborndea3ef72010-10-28 14:24:22 -0700502 *
503 * <p>This is called by the framework for input method implementations;
504 * you should not generally need to call it yourself.
505 *
506 * @param targetSdkVersion The API version number that the compatible
507 * application was developed against.
508 */
509 public final void makeCompatible(int targetSdkVersion) {
510 if (targetSdkVersion < android.os.Build.VERSION_CODES.HONEYCOMB) {
511 switch (inputType&(TYPE_MASK_CLASS|TYPE_MASK_VARIATION)) {
512 case TYPE_CLASS_TEXT|TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS:
513 inputType = TYPE_CLASS_TEXT|TYPE_TEXT_VARIATION_EMAIL_ADDRESS
Ken Wakasa82d731a2010-12-24 23:42:41 +0900514 | (inputType&TYPE_MASK_FLAGS);
Dianne Hackborndea3ef72010-10-28 14:24:22 -0700515 break;
516 case TYPE_CLASS_TEXT|TYPE_TEXT_VARIATION_WEB_PASSWORD:
517 inputType = TYPE_CLASS_TEXT|TYPE_TEXT_VARIATION_PASSWORD
Ken Wakasa82d731a2010-12-24 23:42:41 +0900518 | (inputType&TYPE_MASK_FLAGS);
519 break;
520 case TYPE_CLASS_NUMBER|TYPE_NUMBER_VARIATION_NORMAL:
521 case TYPE_CLASS_NUMBER|TYPE_NUMBER_VARIATION_PASSWORD:
522 inputType = TYPE_CLASS_NUMBER
523 | (inputType&TYPE_MASK_FLAGS);
Dianne Hackborndea3ef72010-10-28 14:24:22 -0700524 break;
525 }
526 }
527 }
528
529 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800530 * Write debug output of this object.
531 */
532 public void dump(Printer pw, String prefix) {
533 pw.println(prefix + "inputType=0x" + Integer.toHexString(inputType)
534 + " imeOptions=0x" + Integer.toHexString(imeOptions)
535 + " privateImeOptions=" + privateImeOptions);
536 pw.println(prefix + "actionLabel=" + actionLabel
537 + " actionId=" + actionId);
538 pw.println(prefix + "initialSelStart=" + initialSelStart
539 + " initialSelEnd=" + initialSelEnd
540 + " initialCapsMode=0x"
541 + Integer.toHexString(initialCapsMode));
542 pw.println(prefix + "hintText=" + hintText
543 + " label=" + label);
544 pw.println(prefix + "packageName=" + packageName
545 + " fieldId=" + fieldId
546 + " fieldName=" + fieldName);
547 pw.println(prefix + "extras=" + extras);
Yohei Yukawad469f212016-01-21 12:38:09 -0800548 pw.println(prefix + "hintLocales=" + hintLocales);
Yohei Yukawa152944f2016-06-10 19:04:34 -0700549 pw.println(prefix + "contentMimeTypes=" + Arrays.toString(contentMimeTypes));
Yohei Yukawa0f5eade2019-01-18 08:48:07 -0800550 if (targetInputMethodUser != null) {
551 pw.println(prefix + "targetInputMethodUserId=" + targetInputMethodUser.getIdentifier());
552 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800553 }
Jean Chalard6fd68e02014-02-20 17:48:46 +0900554
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800555 /**
556 * Used to package this object into a {@link Parcel}.
Jean Chalard6fd68e02014-02-20 17:48:46 +0900557 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800558 * @param dest The {@link Parcel} to be written.
559 * @param flags The flags used for parceling.
560 */
561 public void writeToParcel(Parcel dest, int flags) {
562 dest.writeInt(inputType);
563 dest.writeInt(imeOptions);
564 dest.writeString(privateImeOptions);
565 TextUtils.writeToParcel(actionLabel, dest, flags);
566 dest.writeInt(actionId);
567 dest.writeInt(initialSelStart);
568 dest.writeInt(initialSelEnd);
569 dest.writeInt(initialCapsMode);
570 TextUtils.writeToParcel(hintText, dest, flags);
571 TextUtils.writeToParcel(label, dest, flags);
572 dest.writeString(packageName);
573 dest.writeInt(fieldId);
574 dest.writeString(fieldName);
575 dest.writeBundle(extras);
Yohei Yukawad469f212016-01-21 12:38:09 -0800576 if (hintLocales != null) {
577 hintLocales.writeToParcel(dest, flags);
578 } else {
579 LocaleList.getEmptyLocaleList().writeToParcel(dest, flags);
580 }
Yohei Yukawa152944f2016-06-10 19:04:34 -0700581 dest.writeStringArray(contentMimeTypes);
Yohei Yukawa0f5eade2019-01-18 08:48:07 -0800582 UserHandle.writeToParcel(targetInputMethodUser, dest);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800583 }
584
585 /**
586 * Used to make this class parcelable.
587 */
Jean Chalard6fd68e02014-02-20 17:48:46 +0900588 public static final Parcelable.Creator<EditorInfo> CREATOR =
589 new Parcelable.Creator<EditorInfo>() {
590 public EditorInfo createFromParcel(Parcel source) {
591 EditorInfo res = new EditorInfo();
592 res.inputType = source.readInt();
593 res.imeOptions = source.readInt();
594 res.privateImeOptions = source.readString();
595 res.actionLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
596 res.actionId = source.readInt();
597 res.initialSelStart = source.readInt();
598 res.initialSelEnd = source.readInt();
599 res.initialCapsMode = source.readInt();
600 res.hintText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
601 res.label = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
602 res.packageName = source.readString();
603 res.fieldId = source.readInt();
604 res.fieldName = source.readString();
605 res.extras = source.readBundle();
Yohei Yukawad469f212016-01-21 12:38:09 -0800606 LocaleList hintLocales = LocaleList.CREATOR.createFromParcel(source);
607 res.hintLocales = hintLocales.isEmpty() ? null : hintLocales;
Yohei Yukawa152944f2016-06-10 19:04:34 -0700608 res.contentMimeTypes = source.readStringArray();
Yohei Yukawa0f5eade2019-01-18 08:48:07 -0800609 res.targetInputMethodUser = UserHandle.readFromParcel(source);
Jean Chalard6fd68e02014-02-20 17:48:46 +0900610 return res;
611 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800612
Jean Chalard6fd68e02014-02-20 17:48:46 +0900613 public EditorInfo[] newArray(int size) {
614 return new EditorInfo[size];
615 }
616 };
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800617
618 public int describeContents() {
619 return 0;
620 }
621
622}