• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package android.view.inputmethod;
2 
3 import android.os.Bundle;
4 import android.os.Parcel;
5 import android.os.Parcelable;
6 import android.text.InputType;
7 import android.text.TextUtils;
8 import android.util.Printer;
9 
10 /**
11  * An EditorInfo describes several attributes of a text editing object
12  * that an input method is communicating with (typically an EditText), most
13  * importantly the type of text content it contains.
14  */
15 public class EditorInfo implements InputType, Parcelable {
16     /**
17      * The content type of the text box, whose bits are defined by
18      * {@link InputType}.
19      *
20      * @see InputType
21      * @see #TYPE_MASK_CLASS
22      * @see #TYPE_MASK_VARIATION
23      * @see #TYPE_MASK_FLAGS
24      */
25     public int inputType = TYPE_NULL;
26 
27     /**
28      * Set of bits in {@link #imeOptions} that provide alternative actions
29      * associated with the "enter" key.  This both helps the IME provide
30      * better feedback about what the enter key will do, and also allows it
31      * to provide alternative mechanisms for providing that command.
32      */
33     public static final int IME_MASK_ACTION = 0x000000ff;
34 
35     /**
36      * Bits of {@link #IME_MASK_ACTION}: no specific action has been
37      * associated with this editor, let the editor come up with its own if
38      * it can.
39      */
40     public static final int IME_ACTION_UNSPECIFIED = 0x00000000;
41 
42     /**
43      * Bits of {@link #IME_MASK_ACTION}: there is no available action.
44      */
45     public static final int IME_ACTION_NONE = 0x00000001;
46 
47     /**
48      * Bits of {@link #IME_MASK_ACTION}: the action key performs a "go"
49      * operation to take the user to the target of the text they typed.
50      * Typically used, for example, when entering a URL.
51      */
52     public static final int IME_ACTION_GO = 0x00000002;
53 
54     /**
55      * Bits of {@link #IME_MASK_ACTION}: the action key performs a "search"
56      * operation, taking the user to the results of searching for the text
57      * the have typed (in whatever context is appropriate).
58      */
59     public static final int IME_ACTION_SEARCH = 0x00000003;
60 
61     /**
62      * Bits of {@link #IME_MASK_ACTION}: the action key performs a "send"
63      * operation, delivering the text to its target.  This is typically used
64      * when composing a message.
65      */
66     public static final int IME_ACTION_SEND = 0x00000004;
67 
68     /**
69      * Bits of {@link #IME_MASK_ACTION}: the action key performs a "next"
70      * operation, taking the user to the next field that will accept text.
71      */
72     public static final int IME_ACTION_NEXT = 0x00000005;
73 
74     /**
75      * Bits of {@link #IME_MASK_ACTION}: the action key performs a "done"
76      * operation, typically meaning the IME will be closed.
77      */
78     public static final int IME_ACTION_DONE = 0x00000006;
79 
80     /**
81      * Flag of {@link #imeOptions}: used to specify that the IME does not need
82      * to show its extracted text UI.  For input methods that may be fullscreen,
83      * often when in landscape mode, this allows them to be smaller and let part
84      * of the application be shown behind.  Though there will likely be limited
85      * access to the application available from the user, it can make the
86      * experience of a (mostly) fullscreen IME less jarring.  Note that when
87      * this flag is specified the IME may <em>not</em> be set up to be able
88      * to display text, so it should only be used in situations where this is
89      * not needed.
90      */
91     public static final int IME_FLAG_NO_EXTRACT_UI = 0x10000000;
92 
93     /**
94      * Flag of {@link #imeOptions}: used in conjunction with
95      * {@link #IME_MASK_ACTION}, this indicates that the action should not
96      * be available as an accessory button when the input method is full-screen.
97      * Note that by setting this flag, there can be cases where the action
98      * is simply never available to the user.  Setting this generally means
99      * that you think showing text being edited is more important than the
100      * action you have supplied.
101      */
102     public static final int IME_FLAG_NO_ACCESSORY_ACTION = 0x20000000;
103 
104     /**
105      * Flag of {@link #imeOptions}: used in conjunction with
106      * {@link #IME_MASK_ACTION}, this indicates that the action should not
107      * be available in-line as a replacement for "enter" key.  Typically this is
108      * because the action has such a significant impact or is not recoverable
109      * enough that accidentally hitting it should be avoided, such as sending
110      * a message.  Note that {@link android.widget.TextView} will automatically set this
111      * flag for you on multi-line text views.
112      */
113     public static final int IME_FLAG_NO_ENTER_ACTION = 0x40000000;
114 
115     /**
116      * Generic unspecified type for {@link #imeOptions}.
117      */
118     public static final int IME_NULL = 0x00000000;
119 
120     /**
121      * Extended type information for the editor, to help the IME better
122      * integrate with it.
123      */
124     public int imeOptions = IME_NULL;
125 
126     /**
127      * A string supplying additional information options that are
128      * private to a particular IME implementation.  The string must be
129      * scoped to a package owned by the implementation, to ensure there are
130      * no conflicts between implementations, but other than that you can put
131      * whatever you want in it to communicate with the IME.  For example,
132      * you could have a string that supplies an argument like
133      * <code>"com.example.myapp.SpecialMode=3"</code>.  This field is can be
134      * filled in from the {@link android.R.attr#privateImeOptions}
135      * attribute of a TextView.
136      */
137     public String privateImeOptions = null;
138 
139     /**
140      * In some cases an IME may be able to display an arbitrary label for
141      * a command the user can perform, which you can specify here.  You can
142      * not count on this being used.
143      */
144     public CharSequence actionLabel = null;
145 
146     /**
147      * If {@link #actionLabel} has been given, this is the id for that command
148      * when the user presses its button that is delivered back with
149      * {@link InputConnection#performEditorAction(int)
150      * InputConnection.performEditorAction()}.
151      */
152     public int actionId = 0;
153 
154     /**
155      * The text offset of the start of the selection at the time editing
156      * began; -1 if not known.
157      */
158     public int initialSelStart = -1;
159 
160     /**
161      * The text offset of the end of the selection at the time editing
162      * began; -1 if not known.
163      */
164     public int initialSelEnd = -1;
165 
166     /**
167      * The capitalization mode of the first character being edited in the
168      * text.  Values may be any combination of
169      * {@link TextUtils#CAP_MODE_CHARACTERS TextUtils.CAP_MODE_CHARACTERS},
170      * {@link TextUtils#CAP_MODE_WORDS TextUtils.CAP_MODE_WORDS}, and
171      * {@link TextUtils#CAP_MODE_SENTENCES TextUtils.CAP_MODE_SENTENCES}, though
172      * you should generally just take a non-zero value to mean start out in
173      * caps mode.
174      */
175     public int initialCapsMode = 0;
176 
177     /**
178      * The "hint" text of the text view, typically shown in-line when the
179      * text is empty to tell the user what to enter.
180      */
181     public CharSequence hintText;
182 
183     /**
184      * A label to show to the user describing the text they are writing.
185      */
186     public CharSequence label;
187 
188     /**
189      * Name of the package that owns this editor.
190      */
191     public String packageName;
192 
193     /**
194      * Identifier for the editor's field.  This is optional, and may be
195      * 0.  By default it is filled in with the result of
196      * {@link android.view.View#getId() View.getId()} on the View that
197      * is being edited.
198      */
199     public int fieldId;
200 
201     /**
202      * Additional name for the editor's field.  This can supply additional
203      * name information for the field.  By default it is null.  The actual
204      * contents have no meaning.
205      */
206     public String fieldName;
207 
208     /**
209      * Any extra data to supply to the input method.  This is for extended
210      * communication with specific input methods; the name fields in the
211      * bundle should be scoped (such as "com.mydomain.im.SOME_FIELD") so
212      * that they don't conflict with others.  This field is can be
213      * filled in from the {@link android.R.attr#editorExtras}
214      * attribute of a TextView.
215      */
216     public Bundle extras;
217 
218     /**
219      * Write debug output of this object.
220      */
dump(Printer pw, String prefix)221     public void dump(Printer pw, String prefix) {
222         pw.println(prefix + "inputType=0x" + Integer.toHexString(inputType)
223                 + " imeOptions=0x" + Integer.toHexString(imeOptions)
224                 + " privateImeOptions=" + privateImeOptions);
225         pw.println(prefix + "actionLabel=" + actionLabel
226                 + " actionId=" + actionId);
227         pw.println(prefix + "initialSelStart=" + initialSelStart
228                 + " initialSelEnd=" + initialSelEnd
229                 + " initialCapsMode=0x"
230                 + Integer.toHexString(initialCapsMode));
231         pw.println(prefix + "hintText=" + hintText
232                 + " label=" + label);
233         pw.println(prefix + "packageName=" + packageName
234                 + " fieldId=" + fieldId
235                 + " fieldName=" + fieldName);
236         pw.println(prefix + "extras=" + extras);
237     }
238 
239     /**
240      * Used to package this object into a {@link Parcel}.
241      *
242      * @param dest The {@link Parcel} to be written.
243      * @param flags The flags used for parceling.
244      */
writeToParcel(Parcel dest, int flags)245     public void writeToParcel(Parcel dest, int flags) {
246         dest.writeInt(inputType);
247         dest.writeInt(imeOptions);
248         dest.writeString(privateImeOptions);
249         TextUtils.writeToParcel(actionLabel, dest, flags);
250         dest.writeInt(actionId);
251         dest.writeInt(initialSelStart);
252         dest.writeInt(initialSelEnd);
253         dest.writeInt(initialCapsMode);
254         TextUtils.writeToParcel(hintText, dest, flags);
255         TextUtils.writeToParcel(label, dest, flags);
256         dest.writeString(packageName);
257         dest.writeInt(fieldId);
258         dest.writeString(fieldName);
259         dest.writeBundle(extras);
260     }
261 
262     /**
263      * Used to make this class parcelable.
264      */
265     public static final Parcelable.Creator<EditorInfo> CREATOR = new Parcelable.Creator<EditorInfo>() {
266         public EditorInfo createFromParcel(Parcel source) {
267             EditorInfo res = new EditorInfo();
268             res.inputType = source.readInt();
269             res.imeOptions = source.readInt();
270             res.privateImeOptions = source.readString();
271             res.actionLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
272             res.actionId = source.readInt();
273             res.initialSelStart = source.readInt();
274             res.initialSelEnd = source.readInt();
275             res.initialCapsMode = source.readInt();
276             res.hintText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
277             res.label = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
278             res.packageName = source.readString();
279             res.fieldId = source.readInt();
280             res.fieldName = source.readString();
281             res.extras = source.readBundle();
282             return res;
283         }
284 
285         public EditorInfo[] newArray(int size) {
286             return new EditorInfo[size];
287         }
288     };
289 
describeContents()290     public int describeContents() {
291         return 0;
292     }
293 
294 }
295