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
17package android.view.inputmethod;
18
19import android.os.Bundle;
20import android.view.KeyEvent;
21
22/**
23 * <p>Wrapper class for proxying calls to another InputConnection.  Subclass
24 * and have fun!
25 */
26public class InputConnectionWrapper implements InputConnection {
27    private InputConnection mTarget;
28    final boolean mMutable;
29
30    public InputConnectionWrapper(InputConnection target, boolean mutable) {
31        mMutable = mutable;
32        mTarget = target;
33    }
34
35    /**
36     * Change the target of the input connection.
37     */
38    public void setTarget(InputConnection target) {
39        if (mTarget != null && !mMutable) {
40            throw new SecurityException("not mutable");
41        }
42        mTarget = target;
43    }
44
45    public CharSequence getTextBeforeCursor(int n, int flags) {
46        return mTarget.getTextBeforeCursor(n, flags);
47    }
48
49    public CharSequence getTextAfterCursor(int n, int flags) {
50        return mTarget.getTextAfterCursor(n, flags);
51    }
52
53    public CharSequence getSelectedText(int flags) {
54        return mTarget.getSelectedText(flags);
55    }
56
57    public int getCursorCapsMode(int reqModes) {
58        return mTarget.getCursorCapsMode(reqModes);
59    }
60
61    public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) {
62        return mTarget.getExtractedText(request, flags);
63    }
64
65    public boolean deleteSurroundingText(int beforeLength, int afterLength) {
66        return mTarget.deleteSurroundingText(beforeLength, afterLength);
67    }
68
69    public boolean setComposingText(CharSequence text, int newCursorPosition) {
70        return mTarget.setComposingText(text, newCursorPosition);
71    }
72
73    public boolean setComposingRegion(int start, int end) {
74        return mTarget.setComposingRegion(start, end);
75    }
76
77    public boolean finishComposingText() {
78        return mTarget.finishComposingText();
79    }
80
81    public boolean commitText(CharSequence text, int newCursorPosition) {
82        return mTarget.commitText(text, newCursorPosition);
83    }
84
85    public boolean commitCompletion(CompletionInfo text) {
86        return mTarget.commitCompletion(text);
87    }
88
89    public boolean commitCorrection(CorrectionInfo correctionInfo) {
90        return mTarget.commitCorrection(correctionInfo);
91    }
92
93    public boolean setSelection(int start, int end) {
94        return mTarget.setSelection(start, end);
95    }
96
97    public boolean performEditorAction(int editorAction) {
98        return mTarget.performEditorAction(editorAction);
99    }
100
101    public boolean performContextMenuAction(int id) {
102        return mTarget.performContextMenuAction(id);
103    }
104
105    public boolean beginBatchEdit() {
106        return mTarget.beginBatchEdit();
107    }
108
109    public boolean endBatchEdit() {
110        return mTarget.endBatchEdit();
111    }
112
113    public boolean sendKeyEvent(KeyEvent event) {
114        return mTarget.sendKeyEvent(event);
115    }
116
117    public boolean clearMetaKeyStates(int states) {
118        return mTarget.clearMetaKeyStates(states);
119    }
120
121    public boolean reportFullscreenMode(boolean enabled) {
122        return mTarget.reportFullscreenMode(enabled);
123    }
124
125    public boolean performPrivateCommand(String action, Bundle data) {
126        return mTarget.performPrivateCommand(action, data);
127    }
128}
129