ExtractedText.java revision b2a3dd88a53cc8c6d19f6dc8ec4f3d6c4abd9b54
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     * Bit for {@link #flags}: set if the editor is currently in selection mode.
59     */
60    public static final int FLAG_SELECTING = 0x0002;
61
62    /**
63     * Additional bit flags of information about the edited text.
64     */
65    public int flags;
66
67    /**
68     * Used to package this object into a {@link Parcel}.
69     *
70     * @param dest The {@link Parcel} to be written.
71     * @param flags The flags used for parceling.
72     */
73    public void writeToParcel(Parcel dest, int flags) {
74        TextUtils.writeToParcel(text, dest, flags);
75        dest.writeInt(startOffset);
76        dest.writeInt(partialStartOffset);
77        dest.writeInt(partialEndOffset);
78        dest.writeInt(selectionStart);
79        dest.writeInt(selectionEnd);
80        dest.writeInt(this.flags);
81    }
82
83    /**
84     * Used to make this class parcelable.
85     */
86    public static final Parcelable.Creator<ExtractedText> CREATOR = new Parcelable.Creator<ExtractedText>() {
87        public ExtractedText createFromParcel(Parcel source) {
88            ExtractedText res = new ExtractedText();
89            res.text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
90            res.startOffset = source.readInt();
91            res.partialStartOffset = source.readInt();
92            res.partialEndOffset = source.readInt();
93            res.selectionStart = source.readInt();
94            res.selectionEnd = source.readInt();
95            res.flags = source.readInt();
96            return res;
97        }
98
99        public ExtractedText[] newArray(int size) {
100            return new ExtractedText[size];
101        }
102    };
103
104    public int describeContents() {
105        return 0;
106    }
107}
108