blob: f671e22b492257b4ee1f6f131e1d40021687cc9f [file] [log] [blame]
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -07001/*
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -08002 * Copyright (C) 2007 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 *
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070010 * Unless required by applicable law or agreed to in writing, software
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -080011 * 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.
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070015 */
16
17package android.view.inputmethod;
18
19import android.os.Bundle;
Yohei Yukawa612cce92016-02-11 17:47:33 -080020import android.os.Handler;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070021import android.view.KeyEvent;
22
23/**
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -080024 * <p>Wrapper class for proxying calls to another InputConnection. Subclass and have fun!
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070025 */
26public class InputConnectionWrapper implements InputConnection {
Dianne Hackborn51bf0772009-03-24 19:11:41 -070027 private InputConnection mTarget;
28 final boolean mMutable;
Yohei Yukawa19a80a12016-03-14 22:57:37 -070029 @InputConnectionInspector.MissingMethodFlags
30 private int mMissingMethodFlags;
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -080031
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 Yukawaabc4b8f2016-02-29 13:35:59 -080042 public InputConnectionWrapper(InputConnection target, boolean mutable) {
Dianne Hackborn51bf0772009-03-24 19:11:41 -070043 mMutable = mutable;
44 mTarget = target;
Yohei Yukawa19a80a12016-03-14 22:57:37 -070045 mMissingMethodFlags = InputConnectionInspector.getMissingMethodFlags(target);
Dianne Hackborn51bf0772009-03-24 19:11:41 -070046 }
47
48 /**
49 * Change the target of the input connection.
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -080050 *
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 Hackborn51bf0772009-03-24 19:11:41 -070056 */
Yohei Yukawaabc4b8f2016-02-29 13:35:59 -080057 public void setTarget(InputConnection target) {
Dianne Hackborn51bf0772009-03-24 19:11:41 -070058 if (mTarget != null && !mMutable) {
59 throw new SecurityException("not mutable");
60 }
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070061 mTarget = target;
Yohei Yukawa19a80a12016-03-14 22:57:37 -070062 mMissingMethodFlags = InputConnectionInspector.getMissingMethodFlags(target);
63 }
64
65 /**
66 * @hide
67 */
68 @InputConnectionInspector.MissingMethodFlags
69 public int getMissingMethodFlags() {
70 return mMissingMethodFlags;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070071 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -080072
73 /**
74 * {@inheritDoc}
75 * @throws NullPointerException if the target is {@code null}.
76 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -080077 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070078 public CharSequence getTextBeforeCursor(int n, int flags) {
79 return mTarget.getTextBeforeCursor(n, flags);
80 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -080081
82 /**
83 * {@inheritDoc}
84 * @throws NullPointerException if the target is {@code null}.
85 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -080086 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070087 public CharSequence getTextAfterCursor(int n, int flags) {
88 return mTarget.getTextAfterCursor(n, flags);
89 }
90
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -080091 /**
92 * {@inheritDoc}
93 * @throws NullPointerException if the target is {@code null}.
94 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -080095 @Override
Amith Yamasania90b7f02010-08-25 18:27:20 -070096 public CharSequence getSelectedText(int flags) {
97 return mTarget.getSelectedText(flags);
98 }
99
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800100 /**
101 * {@inheritDoc}
102 * @throws NullPointerException if the target is {@code null}.
103 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800104 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700105 public int getCursorCapsMode(int reqModes) {
106 return mTarget.getCursorCapsMode(reqModes);
107 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800108
109 /**
110 * {@inheritDoc}
111 * @throws NullPointerException if the target is {@code null}.
112 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800113 @Override
satoke3797a12011-03-22 06:34:48 +0900114 public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700115 return mTarget.getExtractedText(request, flags);
116 }
117
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800118 /**
119 * {@inheritDoc}
120 * @throws NullPointerException if the target is {@code null}.
121 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800122 @Override
Yohei Yukawac89e22a2016-01-13 22:48:14 -0800123 public boolean deleteSurroundingTextInCodePoints(int beforeLength, int afterLength) {
124 return mTarget.deleteSurroundingTextInCodePoints(beforeLength, afterLength);
125 }
126
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800127 /**
128 * {@inheritDoc}
129 * @throws NullPointerException if the target is {@code null}.
130 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800131 @Override
Fabrice Di Meglio0c95dd32012-01-23 15:06:42 -0800132 public boolean deleteSurroundingText(int beforeLength, int afterLength) {
133 return mTarget.deleteSurroundingText(beforeLength, afterLength);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700134 }
135
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800136 /**
137 * {@inheritDoc}
138 * @throws NullPointerException if the target is {@code null}.
139 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800140 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700141 public boolean setComposingText(CharSequence text, int newCursorPosition) {
142 return mTarget.setComposingText(text, newCursorPosition);
143 }
144
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800145 /**
146 * {@inheritDoc}
147 * @throws NullPointerException if the target is {@code null}.
148 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800149 @Override
Amith Yamasania90b7f02010-08-25 18:27:20 -0700150 public boolean setComposingRegion(int start, int end) {
151 return mTarget.setComposingRegion(start, end);
152 }
153
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800154 /**
155 * {@inheritDoc}
156 * @throws NullPointerException if the target is {@code null}.
157 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800158 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700159 public boolean finishComposingText() {
160 return mTarget.finishComposingText();
161 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800162
163 /**
164 * {@inheritDoc}
165 * @throws NullPointerException if the target is {@code null}.
166 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800167 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700168 public boolean commitText(CharSequence text, int newCursorPosition) {
169 return mTarget.commitText(text, newCursorPosition);
170 }
171
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800172 /**
173 * {@inheritDoc}
174 * @throws NullPointerException if the target is {@code null}.
175 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800176 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700177 public boolean commitCompletion(CompletionInfo text) {
178 return mTarget.commitCompletion(text);
179 }
180
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800181 /**
182 * {@inheritDoc}
183 * @throws NullPointerException if the target is {@code null}.
184 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800185 @Override
Gilles Debunnecf9cf2f2010-12-08 17:43:58 -0800186 public boolean commitCorrection(CorrectionInfo correctionInfo) {
187 return mTarget.commitCorrection(correctionInfo);
188 }
189
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800190 /**
191 * {@inheritDoc}
192 * @throws NullPointerException if the target is {@code null}.
193 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800194 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700195 public boolean setSelection(int start, int end) {
196 return mTarget.setSelection(start, end);
197 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800198
199 /**
200 * {@inheritDoc}
201 * @throws NullPointerException if the target is {@code null}.
202 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800203 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700204 public boolean performEditorAction(int editorAction) {
205 return mTarget.performEditorAction(editorAction);
206 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800207
208 /**
209 * {@inheritDoc}
210 * @throws NullPointerException if the target is {@code null}.
211 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800212 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700213 public boolean performContextMenuAction(int id) {
214 return mTarget.performContextMenuAction(id);
215 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800216
217 /**
218 * {@inheritDoc}
219 * @throws NullPointerException if the target is {@code null}.
220 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800221 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700222 public boolean beginBatchEdit() {
223 return mTarget.beginBatchEdit();
224 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800225
226 /**
227 * {@inheritDoc}
228 * @throws NullPointerException if the target is {@code null}.
229 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800230 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700231 public boolean endBatchEdit() {
232 return mTarget.endBatchEdit();
233 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800234
235 /**
236 * {@inheritDoc}
237 * @throws NullPointerException if the target is {@code null}.
238 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800239 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700240 public boolean sendKeyEvent(KeyEvent event) {
241 return mTarget.sendKeyEvent(event);
242 }
243
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800244 /**
245 * {@inheritDoc}
246 * @throws NullPointerException if the target is {@code null}.
247 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800248 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700249 public boolean clearMetaKeyStates(int states) {
250 return mTarget.clearMetaKeyStates(states);
251 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800252
253 /**
254 * {@inheritDoc}
255 * @throws NullPointerException if the target is {@code null}.
256 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800257 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700258 public boolean reportFullscreenMode(boolean enabled) {
259 return mTarget.reportFullscreenMode(enabled);
260 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800261
262 /**
263 * {@inheritDoc}
264 * @throws NullPointerException if the target is {@code null}.
265 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800266 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700267 public boolean performPrivateCommand(String action, Bundle data) {
268 return mTarget.performPrivateCommand(action, data);
269 }
Yohei Yukawa0023d0e2014-07-11 04:13:03 +0900270
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800271 /**
272 * {@inheritDoc}
273 * @throws NullPointerException if the target is {@code null}.
274 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800275 @Override
Yohei Yukawad8636ea2014-09-02 22:03:30 -0700276 public boolean requestCursorUpdates(int cursorUpdateMode) {
277 return mTarget.requestCursorUpdates(cursorUpdateMode);
Yohei Yukawa0023d0e2014-07-11 04:13:03 +0900278 }
Yohei Yukawa612cce92016-02-11 17:47:33 -0800279
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800280 /**
281 * {@inheritDoc}
282 * @throws NullPointerException if the target is {@code null}.
283 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800284 @Override
Yohei Yukawa612cce92016-02-11 17:47:33 -0800285 public Handler getHandler() {
286 return mTarget.getHandler();
287 }
Yohei Yukawa9f9afe522016-03-30 12:03:51 -0700288
289 /**
290 * {@inheritDoc}
291 * @throws NullPointerException if the target is {@code null}.
292 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800293 @Override
Yohei Yukawa9f9afe522016-03-30 12:03:51 -0700294 public void closeConnection() {
295 mTarget.closeConnection();
296 }
Yohei Yukawa152944f2016-06-10 19:04:34 -0700297
298 /**
299 * {@inheritDoc}
300 * @throws NullPointerException if the target is {@code null}.
301 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800302 @Override
Yohei Yukawa45700fa2016-06-23 17:12:59 -0700303 public boolean commitContent(InputContentInfo inputContentInfo, int flags, Bundle opts) {
304 return mTarget.commitContent(inputContentInfo, flags, opts);
Yohei Yukawa152944f2016-06-10 19:04:34 -0700305 }
Yohei Yukawad8636ea2014-09-02 22:03:30 -0700306}