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 *
26 * This contains information about a portion of the currently edited text,
27 * that the IME should display into its own interface while in extracted mode.
28 */
29public class ExtractedText implements Parcelable {
30    /**
31     * The text that has been extracted.
32     */
33    public CharSequence text;
34
35    /**
36     * The offset in the overall text at which the extracted text starts.
37     */
38    public int startOffset;
39
40    /**
41     * If the content is a report of a partial text change, this is the
42     * offset where the change starts and it runs until
43     * {@link #partialEndOffset}.  If the content is the full text, this
44     * field is -1.
45     */
46    public int partialStartOffset;
47
48    /**
49     * If the content is a report of a partial text change, this is the offset
50     * where the change ends.  Note that the actual text may be larger or
51     * smaller than the difference between this and {@link #partialStartOffset},
52     * meaning a reduction or increase, respectively, in the total text.
53     */
54    public int partialEndOffset;
55
56    /**
57     * The offset where the selection currently starts within the extracted
58     * text.  The real selection start position is at
59     * <var>startOffset</var>+<var>selectionStart</var>.
60     */
61    public int selectionStart;
62
63    /**
64     * The offset where the selection currently ends within the extracted
65     * text.  The real selection end position is at
66     * <var>startOffset</var>+<var>selectionEnd</var>.
67     */
68    public int selectionEnd;
69
70    /**
71     * Bit for {@link #flags}: set if the text being edited can only be on
72     * a single line.
73     */
74    public static final int FLAG_SINGLE_LINE = 0x0001;
75
76    /**
77     * Bit for {@link #flags}: set if the editor is currently in selection mode.
78     *
79     * This happens when a hardware keyboard with latched keys is attached and
80     * the shift key is currently latched.
81     */
82    public static final int FLAG_SELECTING = 0x0002;
83
84    /**
85     * Additional bit flags of information about the edited text.
86     */
87    public int flags;
88
89    /**
90     * Used to package this object into a {@link Parcel}.
91     *
92     * @param dest The {@link Parcel} to be written.
93     * @param flags The flags used for parceling.
94     */
95    public void writeToParcel(Parcel dest, int flags) {
96        TextUtils.writeToParcel(text, dest, flags);
97        dest.writeInt(startOffset);
98        dest.writeInt(partialStartOffset);
99        dest.writeInt(partialEndOffset);
100        dest.writeInt(selectionStart);
101        dest.writeInt(selectionEnd);
102        dest.writeInt(this.flags);
103    }
104
105    /**
106     * Used to make this class parcelable.
107     */
108    public static final Parcelable.Creator<ExtractedText> CREATOR
109            = new Parcelable.Creator<ExtractedText>() {
110        public ExtractedText createFromParcel(Parcel source) {
111            ExtractedText res = new ExtractedText();
112            res.text = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
113            res.startOffset = source.readInt();
114            res.partialStartOffset = source.readInt();
115            res.partialEndOffset = source.readInt();
116            res.selectionStart = source.readInt();
117            res.selectionEnd = source.readInt();
118            res.flags = source.readInt();
119            return res;
120        }
121
122        public ExtractedText[] newArray(int size) {
123            return new ExtractedText[size];
124        }
125    };
126
127    public int describeContents() {
128        return 0;
129    }
130}
131