blob: 1eb300eafb661197ed45ee8335a93e72a7d30ebe [file] [log] [blame]
Kenny Root15a4d2f2010-03-11 18:20:12 -08001/*
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
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080017package 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.
Jean Chalarde811de22013-05-24 08:06:28 +090025 *
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.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028 */
29public class ExtractedText implements Parcelable {
30 /**
31 * The text that has been extracted.
Clara Bayarrie0f35ee2018-01-04 15:30:08 +000032 *
33 * @see android.widget.TextView#getText()
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080034 */
35 public CharSequence text;
36
37 /**
38 * The offset in the overall text at which the extracted text starts.
39 */
40 public int startOffset;
Jean Chalarde811de22013-05-24 08:06:28 +090041
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042 /**
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;
Jean Chalarde811de22013-05-24 08:06:28 +090049
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080050 /**
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
Gilles Debunnec62589c2012-04-12 14:50:23 -070053 * smaller than the difference between this and {@link #partialStartOffset},
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080054 * meaning a reduction or increase, respectively, in the total text.
55 */
56 public int partialEndOffset;
Jean Chalarde811de22013-05-24 08:06:28 +090057
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080058 /**
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;
Jean Chalarde811de22013-05-24 08:06:28 +090064
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080065 /**
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;
Jean Chalarde811de22013-05-24 08:06:28 +090071
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080072 /**
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;
Jean Chalarde811de22013-05-24 08:06:28 +090077
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080078 /**
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070079 * Bit for {@link #flags}: set if the editor is currently in selection mode.
Jean Chalarde811de22013-05-24 08:06:28 +090080 *
81 * This happens when a hardware keyboard with latched keys is attached and
82 * the shift key is currently latched.
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070083 */
84 public static final int FLAG_SELECTING = 0x0002;
Jean Chalarde811de22013-05-24 08:06:28 +090085
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070086 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080087 * Additional bit flags of information about the edited text.
88 */
89 public int flags;
Jean Chalarde811de22013-05-24 08:06:28 +090090
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 /**
Clara Bayarrid8c5e7f2017-07-24 15:29:58 +010092 * The hint that has been extracted.
Clara Bayarrie0f35ee2018-01-04 15:30:08 +000093 *
94 * @see android.widget.TextView#getHint()
Clara Bayarrid8c5e7f2017-07-24 15:29:58 +010095 */
96 public CharSequence hint;
97
98 /**
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080099 * Used to package this object into a {@link Parcel}.
Jean Chalarde811de22013-05-24 08:06:28 +0900100 *
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800101 * @param dest The {@link Parcel} to be written.
102 * @param flags The flags used for parceling.
103 */
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);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700111 dest.writeInt(this.flags);
Clara Bayarrid8c5e7f2017-07-24 15:29:58 +0100112 TextUtils.writeToParcel(hint, dest, flags);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800113 }
114
115 /**
116 * Used to make this class parcelable.
117 */
Jean Chalarde811de22013-05-24 08:06:28 +0900118 public static final Parcelable.Creator<ExtractedText> CREATOR
119 = new Parcelable.Creator<ExtractedText>() {
Clara Bayarrid8c5e7f2017-07-24 15:29:58 +0100120 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 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800132
133 public ExtractedText[] newArray(int size) {
134 return new ExtractedText[size];
135 }
136 };
137
138 public int describeContents() {
139 return 0;
140 }
141}