ExtractedText.java revision 9066cfe9886ac131c34d59ed0e2d287b0e3c0087
1package android.view.inputmethod; 2 3import android.os.Parcel; 4import android.os.Parcelable; 5import android.text.TextUtils; 6 7/** 8 * Information about text that has been extracted for use by an input method. 9 */ 10public class ExtractedText implements Parcelable { 11 /** 12 * The text that has been extracted. 13 */ 14 public CharSequence text; 15 16 /** 17 * The offset in the overall text at which the extracted text starts. 18 */ 19 public int startOffset; 20 21 /** 22 * If the content is a report of a partial text change, this is the 23 * offset where the change starts and it runs until 24 * {@link #partialEndOffset}. If the content is the full text, this 25 * field is -1. 26 */ 27 public int partialStartOffset; 28 29 /** 30 * If the content is a report of a partial text change, this is the offset 31 * where the change ends. Note that the actual text may be larger or 32 * smaller than the difference between this and {@link #partialEndOffset}, 33 * meaning a reduction or increase, respectively, in the total text. 34 */ 35 public int partialEndOffset; 36 37 /** 38 * The offset where the selection currently starts within the extracted 39 * text. The real selection start position is at 40 * <var>startOffset</var>+<var>selectionStart</var>. 41 */ 42 public int selectionStart; 43 44 /** 45 * The offset where the selection currently ends within the extracted 46 * text. The real selection end position is at 47 * <var>startOffset</var>+<var>selectionEnd</var>. 48 */ 49 public int selectionEnd; 50 51 /** 52 * Bit for {@link #flags}: set if the text being edited can only be on 53 * a single line. 54 */ 55 public static final int FLAG_SINGLE_LINE = 0x0001; 56 57 /** 58 * Additional bit flags of information about the edited text. 59 */ 60 public int flags; 61 62 /** 63 * Used to package this object into a {@link Parcel}. 64 * 65 * @param dest The {@link Parcel} to be written. 66 * @param flags The flags used for parceling. 67 */ 68 public void writeToParcel(Parcel dest, int flags) { 69 TextUtils.writeToParcel(text, dest, flags); 70 dest.writeInt(startOffset); 71 dest.writeInt(partialStartOffset); 72 dest.writeInt(partialEndOffset); 73 dest.writeInt(selectionStart); 74 dest.writeInt(selectionEnd); 75 dest.writeInt(flags); 76 } 77 78 /** 79 * Used to make this class parcelable. 80 */ 81 public static final Parcelable.Creator<ExtractedText> CREATOR = new Parcelable.Creator<ExtractedText>() { 82 public ExtractedText createFromParcel(Parcel source) { 83 ExtractedText res = new ExtractedText(); 84 res.text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); 85 res.startOffset = source.readInt(); 86 res.partialStartOffset = source.readInt(); 87 res.partialEndOffset = source.readInt(); 88 res.selectionStart = source.readInt(); 89 res.selectionEnd = source.readInt(); 90 res.flags = source.readInt(); 91 return res; 92 } 93 94 public ExtractedText[] newArray(int size) { 95 return new ExtractedText[size]; 96 } 97 }; 98 99 public int describeContents() { 100 return 0; 101 } 102} 103