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