EditorInfo.java revision d24b8183b93e781080b2c16c487e60d51c12da31
1package android.view.inputmethod; 2 3import android.os.Bundle; 4import android.os.Parcel; 5import android.os.Parcelable; 6import android.text.InputType; 7import android.text.TextUtils; 8import 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 */ 15public 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 * A string supplying additional information about the content type that 29 * is private to a particular IME implementation. The string must be 30 * scoped to a package owned by the implementation, to ensure there are 31 * no conflicts between implementations, but other than that you can put 32 * whatever you want in it to communicate with the IME. For example, 33 * you could have a string that supplies an argument like 34 * <code>"com.example.myapp.SpecialMode=3"</code>. This field is can be 35 * filled in from the {@link android.R.attr#editorPrivateContentType} 36 * attribute of a TextView. 37 */ 38 public String privateContentType = null; 39 40 /** 41 * The text offset of the start of the selection at the time editing 42 * began; -1 if not known. 43 */ 44 public int initialSelStart = -1; 45 46 /** 47 * The text offset of the end of the selection at the time editing 48 * began; -1 if not known. 49 */ 50 public int initialSelEnd = -1; 51 52 /** 53 * The capitalization mode of the first character being edited in the 54 * text. Values may be any combination of 55 * {@link TextUtils#CAP_MODE_CHARACTERS TextUtils.CAP_MODE_CHARACTERS}, 56 * {@link TextUtils#CAP_MODE_WORDS TextUtils.CAP_MODE_WORDS}, and 57 * {@link TextUtils#CAP_MODE_SENTENCES TextUtils.CAP_MODE_SENTENCES}, though 58 * you should generally just take a non-zero value to mean start out in 59 * caps mode. 60 */ 61 public int initialCapsMode = 0; 62 63 /** 64 * The "hint" text of the text view, typically shown in-line when the 65 * text is empty to tell the user what to enter. 66 */ 67 public CharSequence hintText; 68 69 /** 70 * A label to show to the user describing the text they are writing. 71 */ 72 public CharSequence label; 73 74 /** 75 * Name of the package that owns this editor. 76 */ 77 public String packageName; 78 79 /** 80 * Identifier for the editor's field. This is optional, and may be 81 * 0. By default it is filled in with the result of 82 * {@link android.view.View#getId() View.getId()} on the View that 83 * is being edited. 84 */ 85 public int fieldId; 86 87 /** 88 * Additional name for the editor's field. This can supply additional 89 * name information for the field. By default it is null. The actual 90 * contents have no meaning. 91 */ 92 public String fieldName; 93 94 /** 95 * Any extra data to supply to the input method. This is for extended 96 * communication with specific input methods; the name fields in the 97 * bundle should be scoped (such as "com.mydomain.im.SOME_FIELD") so 98 * that they don't conflict with others. This field is can be 99 * filled in from the {@link android.R.attr#editorExtras} 100 * attribute of a TextView. 101 */ 102 public Bundle extras; 103 104 /** 105 * Write debug output of this object. 106 */ 107 public void dump(Printer pw, String prefix) { 108 pw.println(prefix + "inputType=0x" + Integer.toHexString(inputType) 109 + " privateContentType=" + privateContentType); 110 pw.println(prefix + "initialSelStart=" + initialSelStart 111 + " initialSelEnd=" + initialSelEnd 112 + " initialCapsMode=0x" 113 + Integer.toHexString(initialCapsMode)); 114 pw.println(prefix + "hintText=" + hintText 115 + " label=" + label); 116 pw.println(prefix + "packageName=" + packageName 117 + " fieldId=" + fieldId 118 + " fieldName=" + fieldName); 119 pw.println(prefix + "extras=" + extras); 120 } 121 122 /** 123 * Used to package this object into a {@link Parcel}. 124 * 125 * @param dest The {@link Parcel} to be written. 126 * @param flags The flags used for parceling. 127 */ 128 public void writeToParcel(Parcel dest, int flags) { 129 dest.writeInt(inputType); 130 dest.writeString(privateContentType); 131 dest.writeInt(initialSelStart); 132 dest.writeInt(initialSelEnd); 133 dest.writeInt(initialCapsMode); 134 TextUtils.writeToParcel(hintText, dest, flags); 135 TextUtils.writeToParcel(label, dest, flags); 136 dest.writeString(packageName); 137 dest.writeInt(fieldId); 138 dest.writeString(fieldName); 139 dest.writeBundle(extras); 140 } 141 142 /** 143 * Used to make this class parcelable. 144 */ 145 public static final Parcelable.Creator<EditorInfo> CREATOR = new Parcelable.Creator<EditorInfo>() { 146 public EditorInfo createFromParcel(Parcel source) { 147 EditorInfo res = new EditorInfo(); 148 res.inputType = source.readInt(); 149 res.privateContentType = source.readString(); 150 res.initialSelStart = source.readInt(); 151 res.initialSelEnd = source.readInt(); 152 res.initialCapsMode = source.readInt(); 153 res.hintText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); 154 res.label = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); 155 res.packageName = source.readString(); 156 res.fieldId = source.readInt(); 157 res.fieldName = source.readString(); 158 res.extras = source.readBundle(); 159 return res; 160 } 161 162 public EditorInfo[] newArray(int size) { 163 return new EditorInfo[size]; 164 } 165 }; 166 167 public int describeContents() { 168 return 0; 169 } 170 171} 172