Kenny Root | 15a4d2f | 2010-03-11 18:20:12 -0800 | [diff] [blame] | 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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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. |
Jean Chalard | e811de2 | 2013-05-24 08:06:28 +0900 | [diff] [blame] | 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. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | */ |
| 29 | public class ExtractedText implements Parcelable { |
| 30 | /** |
| 31 | * The text that has been extracted. |
Clara Bayarri | e0f35ee | 2018-01-04 15:30:08 +0000 | [diff] [blame] | 32 | * |
| 33 | * @see android.widget.TextView#getText() |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
Jean Chalard | e811de2 | 2013-05-24 08:06:28 +0900 | [diff] [blame] | 41 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
Jean Chalard | e811de2 | 2013-05-24 08:06:28 +0900 | [diff] [blame] | 49 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 |
Gilles Debunne | c62589c | 2012-04-12 14:50:23 -0700 | [diff] [blame] | 53 | * smaller than the difference between this and {@link #partialStartOffset}, |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | * meaning a reduction or increase, respectively, in the total text. |
| 55 | */ |
| 56 | public int partialEndOffset; |
Jean Chalard | e811de2 | 2013-05-24 08:06:28 +0900 | [diff] [blame] | 57 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
Jean Chalard | e811de2 | 2013-05-24 08:06:28 +0900 | [diff] [blame] | 64 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
Jean Chalard | e811de2 | 2013-05-24 08:06:28 +0900 | [diff] [blame] | 71 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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; |
Jean Chalard | e811de2 | 2013-05-24 08:06:28 +0900 | [diff] [blame] | 77 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | /** |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 79 | * Bit for {@link #flags}: set if the editor is currently in selection mode. |
Jean Chalard | e811de2 | 2013-05-24 08:06:28 +0900 | [diff] [blame] | 80 | * |
| 81 | * This happens when a hardware keyboard with latched keys is attached and |
| 82 | * the shift key is currently latched. |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 83 | */ |
| 84 | public static final int FLAG_SELECTING = 0x0002; |
Jean Chalard | e811de2 | 2013-05-24 08:06:28 +0900 | [diff] [blame] | 85 | |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 86 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | * Additional bit flags of information about the edited text. |
| 88 | */ |
| 89 | public int flags; |
Jean Chalard | e811de2 | 2013-05-24 08:06:28 +0900 | [diff] [blame] | 90 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | /** |
Clara Bayarri | d8c5e7f | 2017-07-24 15:29:58 +0100 | [diff] [blame] | 92 | * The hint that has been extracted. |
Clara Bayarri | e0f35ee | 2018-01-04 15:30:08 +0000 | [diff] [blame] | 93 | * |
| 94 | * @see android.widget.TextView#getHint() |
Clara Bayarri | d8c5e7f | 2017-07-24 15:29:58 +0100 | [diff] [blame] | 95 | */ |
| 96 | public CharSequence hint; |
| 97 | |
| 98 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 99 | * Used to package this object into a {@link Parcel}. |
Jean Chalard | e811de2 | 2013-05-24 08:06:28 +0900 | [diff] [blame] | 100 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | * @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 Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 111 | dest.writeInt(this.flags); |
Clara Bayarri | d8c5e7f | 2017-07-24 15:29:58 +0100 | [diff] [blame] | 112 | TextUtils.writeToParcel(hint, dest, flags); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | /** |
| 116 | * Used to make this class parcelable. |
| 117 | */ |
Jean Chalard | e811de2 | 2013-05-24 08:06:28 +0900 | [diff] [blame] | 118 | public static final Parcelable.Creator<ExtractedText> CREATOR |
| 119 | = new Parcelable.Creator<ExtractedText>() { |
Clara Bayarri | d8c5e7f | 2017-07-24 15:29:58 +0100 | [diff] [blame] | 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 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | |
| 133 | public ExtractedText[] newArray(int size) { |
| 134 | return new ExtractedText[size]; |
| 135 | } |
| 136 | }; |
| 137 | |
| 138 | public int describeContents() { |
| 139 | return 0; |
| 140 | } |
| 141 | } |