2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.view.inputmethod;
19 import android.os.Bundle;
20 import android.os.Parcel;
21 import android.os.Parcelable;
22 import android.text.InputType;
23 import android.text.TextUtils;
24 import android.util.Printer;
27 * An EditorInfo describes several attributes of a text editing object
28 * that an input method is communicating with (typically an EditText), most
29 * importantly the type of text content it contains.
31 public class EditorInfo implements InputType, Parcelable {
33 * The content type of the text box, whose bits are defined by
37 * @see #TYPE_MASK_CLASS
38 * @see #TYPE_MASK_VARIATION
39 * @see #TYPE_MASK_FLAGS
41 public int inputType = TYPE_NULL;
44 * Set of bits in {@link #imeOptions} that provide alternative actions
45 * associated with the "enter" key. This both helps the IME provide
46 * better feedback about what the enter key will do, and also allows it
47 * to provide alternative mechanisms for providing that command.
49 public static final int IME_MASK_ACTION = 0x000000ff;
52 * Bits of {@link #IME_MASK_ACTION}: no specific action has been
53 * associated with this editor, let the editor come up with its own if
56 public static final int IME_ACTION_UNSPECIFIED = 0x00000000;
59 * Bits of {@link #IME_MASK_ACTION}: there is no available action.
61 public static final int IME_ACTION_NONE = 0x00000001;
64 * Bits of {@link #IME_MASK_ACTION}: the action key performs a "go"
65 * operation to take the user to the target of the text they typed.
66 * Typically used, for example, when entering a URL.
68 public static final int IME_ACTION_GO = 0x00000002;
71 * Bits of {@link #IME_MASK_ACTION}: the action key performs a "search"
72 * operation, taking the user to the results of searching for the text
73 * the have typed (in whatever context is appropriate).
75 public static final int IME_ACTION_SEARCH = 0x00000003;
78 * Bits of {@link #IME_MASK_ACTION}: the action key performs a "send"
79 * operation, delivering the text to its target. This is typically used
80 * when composing a message.
82 public static final int IME_ACTION_SEND = 0x00000004;
85 * Bits of {@link #IME_MASK_ACTION}: the action key performs a "next"
86 * operation, taking the user to the next field that will accept text.
88 public static final int IME_ACTION_NEXT = 0x00000005;
91 * Bits of {@link #IME_MASK_ACTION}: the action key performs a "done"
92 * operation, typically meaning the IME will be closed.
94 public static final int IME_ACTION_DONE = 0x00000006;
97 * Flag of {@link #imeOptions}: used to specify that the IME does not need
98 * to show its extracted text UI. For input methods that may be fullscreen,
99 * often when in landscape mode, this allows them to be smaller and let part
100 * of the application be shown behind. Though there will likely be limited
101 * access to the application available from the user, it can make the
102 * experience of a (mostly) fullscreen IME less jarring. Note that when
103 * this flag is specified the IME may <em>not</em> be set up to be able
104 * to display text, so it should only be used in situations where this is
107 public static final int IME_FLAG_NO_EXTRACT_UI = 0x10000000;
110 * Flag of {@link #imeOptions}: used in conjunction with
111 * {@link #IME_MASK_ACTION}, this indicates that the action should not
112 * be available as an accessory button when the input method is full-screen.
113 * Note that by setting this flag, there can be cases where the action
114 * is simply never available to the user. Setting this generally means
115 * that you think showing text being edited is more important than the
116 * action you have supplied.
118 public static final int IME_FLAG_NO_ACCESSORY_ACTION = 0x20000000;
121 * Flag of {@link #imeOptions}: used in conjunction with
122 * {@link #IME_MASK_ACTION}, this indicates that the action should not
123 * be available in-line as a replacement for "enter" key. Typically this is
124 * because the action has such a significant impact or is not recoverable
125 * enough that accidentally hitting it should be avoided, such as sending
126 * a message. Note that {@link android.widget.TextView} will automatically set this
127 * flag for you on multi-line text views.
129 public static final int IME_FLAG_NO_ENTER_ACTION = 0x40000000;
132 * Flag of {@link #imeOptions}: used to request that the IME never go
133 * into fullscreen mode. Applications need to be aware that the flag is not
134 * a guarantee, and not all IMEs will respect it.
137 public static final int IME_FLAG_NO_FULLSCREEN = 0x80000000;
140 * Generic unspecified type for {@link #imeOptions}.
142 public static final int IME_NULL = 0x00000000;
145 * Extended type information for the editor, to help the IME better
148 public int imeOptions = IME_NULL;
151 * A string supplying additional information options that are
152 * private to a particular IME implementation. The string must be
153 * scoped to a package owned by the implementation, to ensure there are
154 * no conflicts between implementations, but other than that you can put
155 * whatever you want in it to communicate with the IME. For example,
156 * you could have a string that supplies an argument like
157 * <code>"com.example.myapp.SpecialMode=3"</code>. This field is can be
158 * filled in from the {@link android.R.attr#privateImeOptions}
159 * attribute of a TextView.
161 public String privateImeOptions = null;
164 * In some cases an IME may be able to display an arbitrary label for
165 * a command the user can perform, which you can specify here. You can
166 * not count on this being used.
168 public CharSequence actionLabel = null;
171 * If {@link #actionLabel} has been given, this is the id for that command
172 * when the user presses its button that is delivered back with
173 * {@link InputConnection#performEditorAction(int)
174 * InputConnection.performEditorAction()}.
176 public int actionId = 0;
179 * The text offset of the start of the selection at the time editing
180 * began; -1 if not known.
182 public int initialSelStart = -1;
185 * The text offset of the end of the selection at the time editing
186 * began; -1 if not known.
188 public int initialSelEnd = -1;
191 * The capitalization mode of the first character being edited in the
192 * text. Values may be any combination of
193 * {@link TextUtils#CAP_MODE_CHARACTERS TextUtils.CAP_MODE_CHARACTERS},
194 * {@link TextUtils#CAP_MODE_WORDS TextUtils.CAP_MODE_WORDS}, and
195 * {@link TextUtils#CAP_MODE_SENTENCES TextUtils.CAP_MODE_SENTENCES}, though
196 * you should generally just take a non-zero value to mean start out in
199 public int initialCapsMode = 0;
202 * The "hint" text of the text view, typically shown in-line when the
203 * text is empty to tell the user what to enter.
205 public CharSequence hintText;
208 * A label to show to the user describing the text they are writing.
210 public CharSequence label;
213 * Name of the package that owns this editor.
215 public String packageName;
218 * Identifier for the editor's field. This is optional, and may be
219 * 0. By default it is filled in with the result of
220 * {@link android.view.View#getId() View.getId()} on the View that
226 * Additional name for the editor's field. This can supply additional
227 * name information for the field. By default it is null. The actual
228 * contents have no meaning.
230 public String fieldName;
233 * Any extra data to supply to the input method. This is for extended
234 * communication with specific input methods; the name fields in the
235 * bundle should be scoped (such as "com.mydomain.im.SOME_FIELD") so
236 * that they don't conflict with others. This field is can be
237 * filled in from the {@link android.R.attr#editorExtras}
238 * attribute of a TextView.
240 public Bundle extras;
243 * Write debug output of this object.
245 public void dump(Printer pw, String prefix) {
246 pw.println(prefix + "inputType=0x" + Integer.toHexString(inputType)
247 + " imeOptions=0x" + Integer.toHexString(imeOptions)
248 + " privateImeOptions=" + privateImeOptions);
249 pw.println(prefix + "actionLabel=" + actionLabel
250 + " actionId=" + actionId);
251 pw.println(prefix + "initialSelStart=" + initialSelStart
252 + " initialSelEnd=" + initialSelEnd
253 + " initialCapsMode=0x"
254 + Integer.toHexString(initialCapsMode));
255 pw.println(prefix + "hintText=" + hintText
256 + " label=" + label);
257 pw.println(prefix + "packageName=" + packageName
258 + " fieldId=" + fieldId
259 + " fieldName=" + fieldName);
260 pw.println(prefix + "extras=" + extras);
264 * Used to package this object into a {@link Parcel}.
266 * @param dest The {@link Parcel} to be written.
267 * @param flags The flags used for parceling.
269 public void writeToParcel(Parcel dest, int flags) {
270 dest.writeInt(inputType);
271 dest.writeInt(imeOptions);
272 dest.writeString(privateImeOptions);
273 TextUtils.writeToParcel(actionLabel, dest, flags);
274 dest.writeInt(actionId);
275 dest.writeInt(initialSelStart);
276 dest.writeInt(initialSelEnd);
277 dest.writeInt(initialCapsMode);
278 TextUtils.writeToParcel(hintText, dest, flags);
279 TextUtils.writeToParcel(label, dest, flags);
280 dest.writeString(packageName);
281 dest.writeInt(fieldId);
282 dest.writeString(fieldName);
283 dest.writeBundle(extras);
287 * Used to make this class parcelable.
289 public static final Parcelable.Creator<EditorInfo> CREATOR = new Parcelable.Creator<EditorInfo>() {
290 public EditorInfo createFromParcel(Parcel source) {
291 EditorInfo res = new EditorInfo();
292 res.inputType = source.readInt();
293 res.imeOptions = source.readInt();
294 res.privateImeOptions = source.readString();
295 res.actionLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
296 res.actionId = source.readInt();
297 res.initialSelStart = source.readInt();
298 res.initialSelEnd = source.readInt();
299 res.initialCapsMode = source.readInt();
300 res.hintText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
301 res.label = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
302 res.packageName = source.readString();
303 res.fieldId = source.readInt();
304 res.fieldName = source.readString();
305 res.extras = source.readBundle();
309 public EditorInfo[] newArray(int size) {
310 return new EditorInfo[size];
314 public int describeContents() {