The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007-2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | * use this file except in compliance with the License. You may obtain a copy of |
| 6 | * 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, WITHOUT |
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | * License for the specific language governing permissions and limitations under |
| 14 | * the License. |
| 15 | */ |
| 16 | |
| 17 | package android.view.inputmethod; |
| 18 | |
| 19 | import android.os.Bundle; |
Yohei Yukawa | 612cce9 | 2016-02-11 17:47:33 -0800 | [diff] [blame] | 20 | import android.os.Handler; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 21 | import android.view.KeyEvent; |
| 22 | |
| 23 | /** |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 24 | * <p>Wrapper class for proxying calls to another InputConnection. Subclass and have fun! |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 25 | */ |
| 26 | public class InputConnectionWrapper implements InputConnection { |
Dianne Hackborn | 51bf077 | 2009-03-24 19:11:41 -0700 | [diff] [blame] | 27 | private InputConnection mTarget; |
| 28 | final boolean mMutable; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 29 | @InputConnectionInspector.MissingMethodFlags |
| 30 | private int mMissingMethodFlags; |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 31 | |
| 32 | /** |
| 33 | * Initializes a wrapper. |
| 34 | * |
| 35 | * <p><b>Caveat:</b> Although the system can accept {@code (InputConnection) null} in some |
| 36 | * places, you cannot emulate such a behavior by non-null {@link InputConnectionWrapper} that |
| 37 | * has {@code null} in {@code target}.</p> |
| 38 | * @param target the {@link InputConnection} to be proxied. |
| 39 | * @param mutable set {@code true} to protect this object from being reconfigured to target |
| 40 | * another {@link InputConnection}. Note that this is ignored while the target is {@code null}. |
| 41 | */ |
Yohei Yukawa | abc4b8f | 2016-02-29 13:35:59 -0800 | [diff] [blame] | 42 | public InputConnectionWrapper(InputConnection target, boolean mutable) { |
Dianne Hackborn | 51bf077 | 2009-03-24 19:11:41 -0700 | [diff] [blame] | 43 | mMutable = mutable; |
| 44 | mTarget = target; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 45 | mMissingMethodFlags = InputConnectionInspector.getMissingMethodFlags(target); |
Dianne Hackborn | 51bf077 | 2009-03-24 19:11:41 -0700 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Change the target of the input connection. |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 50 | * |
| 51 | * <p><b>Caveat:</b> Although the system can accept {@code (InputConnection) null} in some |
| 52 | * places, you cannot emulate such a behavior by non-null {@link InputConnectionWrapper} that |
| 53 | * has {@code null} in {@code target}.</p> |
| 54 | * @param target the {@link InputConnection} to be proxied. |
| 55 | * @throws SecurityException when this wrapper has non-null target and is immutable. |
Dianne Hackborn | 51bf077 | 2009-03-24 19:11:41 -0700 | [diff] [blame] | 56 | */ |
Yohei Yukawa | abc4b8f | 2016-02-29 13:35:59 -0800 | [diff] [blame] | 57 | public void setTarget(InputConnection target) { |
Dianne Hackborn | 51bf077 | 2009-03-24 19:11:41 -0700 | [diff] [blame] | 58 | if (mTarget != null && !mMutable) { |
| 59 | throw new SecurityException("not mutable"); |
| 60 | } |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 61 | mTarget = target; |
Yohei Yukawa | 19a80a1 | 2016-03-14 22:57:37 -0700 | [diff] [blame] | 62 | mMissingMethodFlags = InputConnectionInspector.getMissingMethodFlags(target); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @hide |
| 67 | */ |
| 68 | @InputConnectionInspector.MissingMethodFlags |
| 69 | public int getMissingMethodFlags() { |
| 70 | return mMissingMethodFlags; |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 71 | } |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * {@inheritDoc} |
| 75 | * @throws NullPointerException if the target is {@code null}. |
| 76 | */ |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 77 | public CharSequence getTextBeforeCursor(int n, int flags) { |
| 78 | return mTarget.getTextBeforeCursor(n, flags); |
| 79 | } |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 80 | |
| 81 | /** |
| 82 | * {@inheritDoc} |
| 83 | * @throws NullPointerException if the target is {@code null}. |
| 84 | */ |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 85 | public CharSequence getTextAfterCursor(int n, int flags) { |
| 86 | return mTarget.getTextAfterCursor(n, flags); |
| 87 | } |
| 88 | |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 89 | /** |
| 90 | * {@inheritDoc} |
| 91 | * @throws NullPointerException if the target is {@code null}. |
| 92 | */ |
Amith Yamasani | a90b7f0 | 2010-08-25 18:27:20 -0700 | [diff] [blame] | 93 | public CharSequence getSelectedText(int flags) { |
| 94 | return mTarget.getSelectedText(flags); |
| 95 | } |
| 96 | |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 97 | /** |
| 98 | * {@inheritDoc} |
| 99 | * @throws NullPointerException if the target is {@code null}. |
| 100 | */ |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 101 | public int getCursorCapsMode(int reqModes) { |
| 102 | return mTarget.getCursorCapsMode(reqModes); |
| 103 | } |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 104 | |
| 105 | /** |
| 106 | * {@inheritDoc} |
| 107 | * @throws NullPointerException if the target is {@code null}. |
| 108 | */ |
satok | e3797a1 | 2011-03-22 06:34:48 +0900 | [diff] [blame] | 109 | public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) { |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 110 | return mTarget.getExtractedText(request, flags); |
| 111 | } |
| 112 | |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 113 | /** |
| 114 | * {@inheritDoc} |
| 115 | * @throws NullPointerException if the target is {@code null}. |
| 116 | */ |
Yohei Yukawa | c89e22a | 2016-01-13 22:48:14 -0800 | [diff] [blame] | 117 | public boolean deleteSurroundingTextInCodePoints(int beforeLength, int afterLength) { |
| 118 | return mTarget.deleteSurroundingTextInCodePoints(beforeLength, afterLength); |
| 119 | } |
| 120 | |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 121 | /** |
| 122 | * {@inheritDoc} |
| 123 | * @throws NullPointerException if the target is {@code null}. |
| 124 | */ |
Fabrice Di Meglio | 0c95dd3 | 2012-01-23 15:06:42 -0800 | [diff] [blame] | 125 | public boolean deleteSurroundingText(int beforeLength, int afterLength) { |
| 126 | return mTarget.deleteSurroundingText(beforeLength, afterLength); |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 129 | /** |
| 130 | * {@inheritDoc} |
| 131 | * @throws NullPointerException if the target is {@code null}. |
| 132 | */ |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 133 | public boolean setComposingText(CharSequence text, int newCursorPosition) { |
| 134 | return mTarget.setComposingText(text, newCursorPosition); |
| 135 | } |
| 136 | |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 137 | /** |
| 138 | * {@inheritDoc} |
| 139 | * @throws NullPointerException if the target is {@code null}. |
| 140 | */ |
Amith Yamasani | a90b7f0 | 2010-08-25 18:27:20 -0700 | [diff] [blame] | 141 | public boolean setComposingRegion(int start, int end) { |
| 142 | return mTarget.setComposingRegion(start, end); |
| 143 | } |
| 144 | |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 145 | /** |
| 146 | * {@inheritDoc} |
| 147 | * @throws NullPointerException if the target is {@code null}. |
| 148 | */ |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 149 | public boolean finishComposingText() { |
| 150 | return mTarget.finishComposingText(); |
| 151 | } |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 152 | |
| 153 | /** |
| 154 | * {@inheritDoc} |
| 155 | * @throws NullPointerException if the target is {@code null}. |
| 156 | */ |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 157 | public boolean commitText(CharSequence text, int newCursorPosition) { |
| 158 | return mTarget.commitText(text, newCursorPosition); |
| 159 | } |
| 160 | |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 161 | /** |
| 162 | * {@inheritDoc} |
| 163 | * @throws NullPointerException if the target is {@code null}. |
| 164 | */ |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 165 | public boolean commitCompletion(CompletionInfo text) { |
| 166 | return mTarget.commitCompletion(text); |
| 167 | } |
| 168 | |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 169 | /** |
| 170 | * {@inheritDoc} |
| 171 | * @throws NullPointerException if the target is {@code null}. |
| 172 | */ |
Gilles Debunne | cf9cf2f | 2010-12-08 17:43:58 -0800 | [diff] [blame] | 173 | public boolean commitCorrection(CorrectionInfo correctionInfo) { |
| 174 | return mTarget.commitCorrection(correctionInfo); |
| 175 | } |
| 176 | |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 177 | /** |
| 178 | * {@inheritDoc} |
| 179 | * @throws NullPointerException if the target is {@code null}. |
| 180 | */ |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 181 | public boolean setSelection(int start, int end) { |
| 182 | return mTarget.setSelection(start, end); |
| 183 | } |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 184 | |
| 185 | /** |
| 186 | * {@inheritDoc} |
| 187 | * @throws NullPointerException if the target is {@code null}. |
| 188 | */ |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 189 | public boolean performEditorAction(int editorAction) { |
| 190 | return mTarget.performEditorAction(editorAction); |
| 191 | } |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 192 | |
| 193 | /** |
| 194 | * {@inheritDoc} |
| 195 | * @throws NullPointerException if the target is {@code null}. |
| 196 | */ |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 197 | public boolean performContextMenuAction(int id) { |
| 198 | return mTarget.performContextMenuAction(id); |
| 199 | } |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 200 | |
| 201 | /** |
| 202 | * {@inheritDoc} |
| 203 | * @throws NullPointerException if the target is {@code null}. |
| 204 | */ |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 205 | public boolean beginBatchEdit() { |
| 206 | return mTarget.beginBatchEdit(); |
| 207 | } |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 208 | |
| 209 | /** |
| 210 | * {@inheritDoc} |
| 211 | * @throws NullPointerException if the target is {@code null}. |
| 212 | */ |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 213 | public boolean endBatchEdit() { |
| 214 | return mTarget.endBatchEdit(); |
| 215 | } |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 216 | |
| 217 | /** |
| 218 | * {@inheritDoc} |
| 219 | * @throws NullPointerException if the target is {@code null}. |
| 220 | */ |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 221 | public boolean sendKeyEvent(KeyEvent event) { |
| 222 | return mTarget.sendKeyEvent(event); |
| 223 | } |
| 224 | |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 225 | /** |
| 226 | * {@inheritDoc} |
| 227 | * @throws NullPointerException if the target is {@code null}. |
| 228 | */ |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 229 | public boolean clearMetaKeyStates(int states) { |
| 230 | return mTarget.clearMetaKeyStates(states); |
| 231 | } |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 232 | |
| 233 | /** |
| 234 | * {@inheritDoc} |
| 235 | * @throws NullPointerException if the target is {@code null}. |
| 236 | */ |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 237 | public boolean reportFullscreenMode(boolean enabled) { |
| 238 | return mTarget.reportFullscreenMode(enabled); |
| 239 | } |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 240 | |
| 241 | /** |
| 242 | * {@inheritDoc} |
| 243 | * @throws NullPointerException if the target is {@code null}. |
| 244 | */ |
The Android Open Source Project | b2a3dd8 | 2009-03-09 11:52:12 -0700 | [diff] [blame] | 245 | public boolean performPrivateCommand(String action, Bundle data) { |
| 246 | return mTarget.performPrivateCommand(action, data); |
| 247 | } |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 248 | |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 249 | /** |
| 250 | * {@inheritDoc} |
| 251 | * @throws NullPointerException if the target is {@code null}. |
| 252 | */ |
Yohei Yukawa | d8636ea | 2014-09-02 22:03:30 -0700 | [diff] [blame] | 253 | public boolean requestCursorUpdates(int cursorUpdateMode) { |
| 254 | return mTarget.requestCursorUpdates(cursorUpdateMode); |
Yohei Yukawa | 0023d0e | 2014-07-11 04:13:03 +0900 | [diff] [blame] | 255 | } |
Yohei Yukawa | 612cce9 | 2016-02-11 17:47:33 -0800 | [diff] [blame] | 256 | |
Yohei Yukawa | 1d1c21c | 2016-02-29 15:02:41 -0800 | [diff] [blame] | 257 | /** |
| 258 | * {@inheritDoc} |
| 259 | * @throws NullPointerException if the target is {@code null}. |
| 260 | */ |
Yohei Yukawa | 612cce9 | 2016-02-11 17:47:33 -0800 | [diff] [blame] | 261 | public Handler getHandler() { |
| 262 | return mTarget.getHandler(); |
| 263 | } |
Yohei Yukawa | d8636ea | 2014-09-02 22:03:30 -0700 | [diff] [blame] | 264 | } |