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