blob: cbe6856bba410be8f96cbdbf3473f8642563dcf7 [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
Yohei Yukawae77386e2018-01-23 10:39:32 -080019import android.annotation.NonNull;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070020import android.os.Bundle;
Yohei Yukawa612cce92016-02-11 17:47:33 -080021import android.os.Handler;
Yohei Yukawae77386e2018-01-23 10:39:32 -080022import android.os.LocaleList;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070023import android.view.KeyEvent;
24
25/**
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -080026 * <p>Wrapper class for proxying calls to another InputConnection. Subclass and have fun!
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070027 */
28public class InputConnectionWrapper implements InputConnection {
Dianne Hackborn51bf0772009-03-24 19:11:41 -070029 private InputConnection mTarget;
30 final boolean mMutable;
Yohei Yukawa19a80a12016-03-14 22:57:37 -070031 @InputConnectionInspector.MissingMethodFlags
32 private int mMissingMethodFlags;
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -080033
34 /**
35 * Initializes a wrapper.
36 *
37 * <p><b>Caveat:</b> Although the system can accept {@code (InputConnection) null} in some
38 * places, you cannot emulate such a behavior by non-null {@link InputConnectionWrapper} that
39 * has {@code null} in {@code target}.</p>
40 * @param target the {@link InputConnection} to be proxied.
41 * @param mutable set {@code true} to protect this object from being reconfigured to target
42 * another {@link InputConnection}. Note that this is ignored while the target is {@code null}.
43 */
Yohei Yukawaabc4b8f2016-02-29 13:35:59 -080044 public InputConnectionWrapper(InputConnection target, boolean mutable) {
Dianne Hackborn51bf0772009-03-24 19:11:41 -070045 mMutable = mutable;
46 mTarget = target;
Yohei Yukawa19a80a12016-03-14 22:57:37 -070047 mMissingMethodFlags = InputConnectionInspector.getMissingMethodFlags(target);
Dianne Hackborn51bf0772009-03-24 19:11:41 -070048 }
49
50 /**
51 * Change the target of the input connection.
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -080052 *
53 * <p><b>Caveat:</b> Although the system can accept {@code (InputConnection) null} in some
54 * places, you cannot emulate such a behavior by non-null {@link InputConnectionWrapper} that
55 * has {@code null} in {@code target}.</p>
56 * @param target the {@link InputConnection} to be proxied.
57 * @throws SecurityException when this wrapper has non-null target and is immutable.
Dianne Hackborn51bf0772009-03-24 19:11:41 -070058 */
Yohei Yukawaabc4b8f2016-02-29 13:35:59 -080059 public void setTarget(InputConnection target) {
Dianne Hackborn51bf0772009-03-24 19:11:41 -070060 if (mTarget != null && !mMutable) {
61 throw new SecurityException("not mutable");
62 }
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070063 mTarget = target;
Yohei Yukawa19a80a12016-03-14 22:57:37 -070064 mMissingMethodFlags = InputConnectionInspector.getMissingMethodFlags(target);
65 }
66
67 /**
68 * @hide
69 */
70 @InputConnectionInspector.MissingMethodFlags
71 public int getMissingMethodFlags() {
72 return mMissingMethodFlags;
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070073 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -080074
75 /**
76 * {@inheritDoc}
77 * @throws NullPointerException if the target is {@code null}.
78 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -080079 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070080 public CharSequence getTextBeforeCursor(int n, int flags) {
81 return mTarget.getTextBeforeCursor(n, flags);
82 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -080083
84 /**
85 * {@inheritDoc}
86 * @throws NullPointerException if the target is {@code null}.
87 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -080088 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -070089 public CharSequence getTextAfterCursor(int n, int flags) {
90 return mTarget.getTextAfterCursor(n, flags);
91 }
92
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -080093 /**
94 * {@inheritDoc}
95 * @throws NullPointerException if the target is {@code null}.
96 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -080097 @Override
Amith Yamasania90b7f02010-08-25 18:27:20 -070098 public CharSequence getSelectedText(int flags) {
99 return mTarget.getSelectedText(flags);
100 }
101
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800102 /**
103 * {@inheritDoc}
104 * @throws NullPointerException if the target is {@code null}.
105 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800106 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700107 public int getCursorCapsMode(int reqModes) {
108 return mTarget.getCursorCapsMode(reqModes);
109 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800110
111 /**
112 * {@inheritDoc}
113 * @throws NullPointerException if the target is {@code null}.
114 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800115 @Override
satoke3797a12011-03-22 06:34:48 +0900116 public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700117 return mTarget.getExtractedText(request, flags);
118 }
119
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800120 /**
121 * {@inheritDoc}
122 * @throws NullPointerException if the target is {@code null}.
123 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800124 @Override
Yohei Yukawac89e22a2016-01-13 22:48:14 -0800125 public boolean deleteSurroundingTextInCodePoints(int beforeLength, int afterLength) {
126 return mTarget.deleteSurroundingTextInCodePoints(beforeLength, afterLength);
127 }
128
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800129 /**
130 * {@inheritDoc}
131 * @throws NullPointerException if the target is {@code null}.
132 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800133 @Override
Fabrice Di Meglio0c95dd32012-01-23 15:06:42 -0800134 public boolean deleteSurroundingText(int beforeLength, int afterLength) {
135 return mTarget.deleteSurroundingText(beforeLength, afterLength);
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700136 }
137
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800138 /**
139 * {@inheritDoc}
140 * @throws NullPointerException if the target is {@code null}.
141 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800142 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700143 public boolean setComposingText(CharSequence text, int newCursorPosition) {
144 return mTarget.setComposingText(text, newCursorPosition);
145 }
146
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800147 /**
148 * {@inheritDoc}
149 * @throws NullPointerException if the target is {@code null}.
150 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800151 @Override
Amith Yamasania90b7f02010-08-25 18:27:20 -0700152 public boolean setComposingRegion(int start, int end) {
153 return mTarget.setComposingRegion(start, end);
154 }
155
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800156 /**
157 * {@inheritDoc}
158 * @throws NullPointerException if the target is {@code null}.
159 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800160 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700161 public boolean finishComposingText() {
162 return mTarget.finishComposingText();
163 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800164
165 /**
166 * {@inheritDoc}
167 * @throws NullPointerException if the target is {@code null}.
168 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800169 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700170 public boolean commitText(CharSequence text, int newCursorPosition) {
171 return mTarget.commitText(text, newCursorPosition);
172 }
173
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800174 /**
175 * {@inheritDoc}
176 * @throws NullPointerException if the target is {@code null}.
177 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800178 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700179 public boolean commitCompletion(CompletionInfo text) {
180 return mTarget.commitCompletion(text);
181 }
182
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800183 /**
184 * {@inheritDoc}
185 * @throws NullPointerException if the target is {@code null}.
186 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800187 @Override
Gilles Debunnecf9cf2f2010-12-08 17:43:58 -0800188 public boolean commitCorrection(CorrectionInfo correctionInfo) {
189 return mTarget.commitCorrection(correctionInfo);
190 }
191
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800192 /**
193 * {@inheritDoc}
194 * @throws NullPointerException if the target is {@code null}.
195 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800196 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700197 public boolean setSelection(int start, int end) {
198 return mTarget.setSelection(start, end);
199 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800200
201 /**
202 * {@inheritDoc}
203 * @throws NullPointerException if the target is {@code null}.
204 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800205 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700206 public boolean performEditorAction(int editorAction) {
207 return mTarget.performEditorAction(editorAction);
208 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800209
210 /**
211 * {@inheritDoc}
212 * @throws NullPointerException if the target is {@code null}.
213 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800214 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700215 public boolean performContextMenuAction(int id) {
216 return mTarget.performContextMenuAction(id);
217 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800218
219 /**
220 * {@inheritDoc}
221 * @throws NullPointerException if the target is {@code null}.
222 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800223 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700224 public boolean beginBatchEdit() {
225 return mTarget.beginBatchEdit();
226 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800227
228 /**
229 * {@inheritDoc}
230 * @throws NullPointerException if the target is {@code null}.
231 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800232 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700233 public boolean endBatchEdit() {
234 return mTarget.endBatchEdit();
235 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800236
237 /**
238 * {@inheritDoc}
239 * @throws NullPointerException if the target is {@code null}.
240 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800241 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700242 public boolean sendKeyEvent(KeyEvent event) {
243 return mTarget.sendKeyEvent(event);
244 }
245
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800246 /**
247 * {@inheritDoc}
248 * @throws NullPointerException if the target is {@code null}.
249 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800250 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700251 public boolean clearMetaKeyStates(int states) {
252 return mTarget.clearMetaKeyStates(states);
253 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800254
255 /**
256 * {@inheritDoc}
257 * @throws NullPointerException if the target is {@code null}.
258 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800259 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700260 public boolean reportFullscreenMode(boolean enabled) {
261 return mTarget.reportFullscreenMode(enabled);
262 }
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800263
264 /**
265 * {@inheritDoc}
266 * @throws NullPointerException if the target is {@code null}.
267 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800268 @Override
The Android Open Source Projectb2a3dd82009-03-09 11:52:12 -0700269 public boolean performPrivateCommand(String action, Bundle data) {
270 return mTarget.performPrivateCommand(action, data);
271 }
Yohei Yukawa0023d0e2014-07-11 04:13:03 +0900272
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800273 /**
274 * {@inheritDoc}
275 * @throws NullPointerException if the target is {@code null}.
276 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800277 @Override
Yohei Yukawad8636ea2014-09-02 22:03:30 -0700278 public boolean requestCursorUpdates(int cursorUpdateMode) {
279 return mTarget.requestCursorUpdates(cursorUpdateMode);
Yohei Yukawa0023d0e2014-07-11 04:13:03 +0900280 }
Yohei Yukawa612cce92016-02-11 17:47:33 -0800281
Yohei Yukawa1d1c21c2016-02-29 15:02:41 -0800282 /**
283 * {@inheritDoc}
284 * @throws NullPointerException if the target is {@code null}.
285 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800286 @Override
Yohei Yukawa612cce92016-02-11 17:47:33 -0800287 public Handler getHandler() {
288 return mTarget.getHandler();
289 }
Yohei Yukawa9f9afe522016-03-30 12:03:51 -0700290
291 /**
292 * {@inheritDoc}
293 * @throws NullPointerException if the target is {@code null}.
294 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800295 @Override
Yohei Yukawa9f9afe522016-03-30 12:03:51 -0700296 public void closeConnection() {
297 mTarget.closeConnection();
298 }
Yohei Yukawa152944f2016-06-10 19:04:34 -0700299
300 /**
301 * {@inheritDoc}
302 * @throws NullPointerException if the target is {@code null}.
303 */
Yohei Yukawa7a8c9aa2018-01-15 19:43:38 -0800304 @Override
Yohei Yukawa45700fa2016-06-23 17:12:59 -0700305 public boolean commitContent(InputContentInfo inputContentInfo, int flags, Bundle opts) {
306 return mTarget.commitContent(inputContentInfo, flags, opts);
Yohei Yukawa152944f2016-06-10 19:04:34 -0700307 }
Yohei Yukawae77386e2018-01-23 10:39:32 -0800308
309 /**
310 * {@inheritDoc}
311 * @throws NullPointerException if the target is {@code null}.
312 */
313 @Override
314 public void reportLanguageHint(@NonNull LocaleList languageHint) {
315 mTarget.reportLanguageHint(languageHint);
316 }
Yohei Yukawad8636ea2014-09-02 22:03:30 -0700317}