FileDocCategorySizeDatePackage
IInputConnectionWrapper.javaAPI DocAndroid 5.1 API20083Thu Mar 12 22:22:10 GMT 2015com.android.internal.view

IInputConnectionWrapper

public class IInputConnectionWrapper extends IInputContext.Stub

Fields Summary
static final String
TAG
private static final int
DO_GET_TEXT_AFTER_CURSOR
private static final int
DO_GET_TEXT_BEFORE_CURSOR
private static final int
DO_GET_SELECTED_TEXT
private static final int
DO_GET_CURSOR_CAPS_MODE
private static final int
DO_GET_EXTRACTED_TEXT
private static final int
DO_COMMIT_TEXT
private static final int
DO_COMMIT_COMPLETION
private static final int
DO_COMMIT_CORRECTION
private static final int
DO_SET_SELECTION
private static final int
DO_PERFORM_EDITOR_ACTION
private static final int
DO_PERFORM_CONTEXT_MENU_ACTION
private static final int
DO_SET_COMPOSING_TEXT
private static final int
DO_SET_COMPOSING_REGION
private static final int
DO_FINISH_COMPOSING_TEXT
private static final int
DO_SEND_KEY_EVENT
private static final int
DO_DELETE_SURROUNDING_TEXT
private static final int
DO_BEGIN_BATCH_EDIT
private static final int
DO_END_BATCH_EDIT
private static final int
DO_REPORT_FULLSCREEN_MODE
private static final int
DO_PERFORM_PRIVATE_COMMAND
private static final int
DO_CLEAR_META_KEY_STATES
private static final int
DO_REQUEST_UPDATE_CURSOR_ANCHOR_INFO
private WeakReference
mInputConnection
private android.os.Looper
mMainLooper
private android.os.Handler
mH
Constructors Summary
public IInputConnectionWrapper(android.os.Looper mainLooper, android.view.inputmethod.InputConnection conn)

        mInputConnection = new WeakReference<InputConnection>(conn);
        mMainLooper = mainLooper;
        mH = new MyHandler(mMainLooper);
    
Methods Summary
public voidbeginBatchEdit()

        dispatchMessage(obtainMessage(DO_BEGIN_BATCH_EDIT));
    
public voidclearMetaKeyStates(int states)

        dispatchMessage(obtainMessageII(DO_CLEAR_META_KEY_STATES, states, 0));
    
public voidcommitCompletion(android.view.inputmethod.CompletionInfo text)

        dispatchMessage(obtainMessageO(DO_COMMIT_COMPLETION, text));
    
public voidcommitCorrection(android.view.inputmethod.CorrectionInfo info)

        dispatchMessage(obtainMessageO(DO_COMMIT_CORRECTION, info));
    
public voidcommitText(java.lang.CharSequence text, int newCursorPosition)

        dispatchMessage(obtainMessageIO(DO_COMMIT_TEXT, newCursorPosition, text));
    
public voiddeleteSurroundingText(int leftLength, int rightLength)

        dispatchMessage(obtainMessageII(DO_DELETE_SURROUNDING_TEXT,
            leftLength, rightLength));
    
voiddispatchMessage(android.os.Message msg)

        // If we are calling this from the main thread, then we can call
        // right through.  Otherwise, we need to send the message to the
        // main thread.
        if (Looper.myLooper() == mMainLooper) {
            executeMessage(msg);
            msg.recycle();
            return;
        }
        
        mH.sendMessage(msg);
    
public voidendBatchEdit()

        dispatchMessage(obtainMessage(DO_END_BATCH_EDIT));
    
voidexecuteMessage(android.os.Message msg)

        switch (msg.what) {
            case DO_GET_TEXT_AFTER_CURSOR: {
                SomeArgs args = (SomeArgs)msg.obj;
                try {
                    InputConnection ic = mInputConnection.get();
                    if (ic == null || !isActive()) {
                        Log.w(TAG, "getTextAfterCursor on inactive InputConnection");
                        args.callback.setTextAfterCursor(null, args.seq);
                        return;
                    }
                    args.callback.setTextAfterCursor(ic.getTextAfterCursor(
                            msg.arg1, msg.arg2), args.seq);
                } catch (RemoteException e) {
                    Log.w(TAG, "Got RemoteException calling setTextAfterCursor", e);
                }
                return;
            }
            case DO_GET_TEXT_BEFORE_CURSOR: {
                SomeArgs args = (SomeArgs)msg.obj;
                try {
                    InputConnection ic = mInputConnection.get();
                    if (ic == null || !isActive()) {
                        Log.w(TAG, "getTextBeforeCursor on inactive InputConnection");
                        args.callback.setTextBeforeCursor(null, args.seq);
                        return;
                    }
                    args.callback.setTextBeforeCursor(ic.getTextBeforeCursor(
                            msg.arg1, msg.arg2), args.seq);
                } catch (RemoteException e) {
                    Log.w(TAG, "Got RemoteException calling setTextBeforeCursor", e);
                }
                return;
            }
            case DO_GET_SELECTED_TEXT: {
                SomeArgs args = (SomeArgs)msg.obj;
                try {
                    InputConnection ic = mInputConnection.get();
                    if (ic == null || !isActive()) {
                        Log.w(TAG, "getSelectedText on inactive InputConnection");
                        args.callback.setSelectedText(null, args.seq);
                        return;
                    }
                    args.callback.setSelectedText(ic.getSelectedText(
                            msg.arg1), args.seq);
                } catch (RemoteException e) {
                    Log.w(TAG, "Got RemoteException calling setSelectedText", e);
                }
                return;
            }
            case DO_GET_CURSOR_CAPS_MODE: {
                SomeArgs args = (SomeArgs)msg.obj;
                try {
                    InputConnection ic = mInputConnection.get();
                    if (ic == null || !isActive()) {
                        Log.w(TAG, "getCursorCapsMode on inactive InputConnection");
                        args.callback.setCursorCapsMode(0, args.seq);
                        return;
                    }
                    args.callback.setCursorCapsMode(ic.getCursorCapsMode(msg.arg1),
                            args.seq);
                } catch (RemoteException e) {
                    Log.w(TAG, "Got RemoteException calling setCursorCapsMode", e);
                }
                return;
            }
            case DO_GET_EXTRACTED_TEXT: {
                SomeArgs args = (SomeArgs)msg.obj;
                try {
                    InputConnection ic = mInputConnection.get();
                    if (ic == null || !isActive()) {
                        Log.w(TAG, "getExtractedText on inactive InputConnection");
                        args.callback.setExtractedText(null, args.seq);
                        return;
                    }
                    args.callback.setExtractedText(ic.getExtractedText(
                            (ExtractedTextRequest)args.arg1, msg.arg1), args.seq);
                } catch (RemoteException e) {
                    Log.w(TAG, "Got RemoteException calling setExtractedText", e);
                }
                return;
            }
            case DO_COMMIT_TEXT: {
                InputConnection ic = mInputConnection.get();
                if (ic == null || !isActive()) {
                    Log.w(TAG, "commitText on inactive InputConnection");
                    return;
                }
                ic.commitText((CharSequence)msg.obj, msg.arg1);
                return;
            }
            case DO_SET_SELECTION: {
                InputConnection ic = mInputConnection.get();
                if (ic == null || !isActive()) {
                    Log.w(TAG, "setSelection on inactive InputConnection");
                    return;
                }
                ic.setSelection(msg.arg1, msg.arg2);
                return;
            }
            case DO_PERFORM_EDITOR_ACTION: {
                InputConnection ic = mInputConnection.get();
                if (ic == null || !isActive()) {
                    Log.w(TAG, "performEditorAction on inactive InputConnection");
                    return;
                }
                ic.performEditorAction(msg.arg1);
                return;
            }
            case DO_PERFORM_CONTEXT_MENU_ACTION: {
                InputConnection ic = mInputConnection.get();
                if (ic == null || !isActive()) {
                    Log.w(TAG, "performContextMenuAction on inactive InputConnection");
                    return;
                }
                ic.performContextMenuAction(msg.arg1);
                return;
            }
            case DO_COMMIT_COMPLETION: {
                InputConnection ic = mInputConnection.get();
                if (ic == null || !isActive()) {
                    Log.w(TAG, "commitCompletion on inactive InputConnection");
                    return;
                }
                ic.commitCompletion((CompletionInfo)msg.obj);
                return;
            }
            case DO_COMMIT_CORRECTION: {
                InputConnection ic = mInputConnection.get();
                if (ic == null || !isActive()) {
                    Log.w(TAG, "commitCorrection on inactive InputConnection");
                    return;
                }
                ic.commitCorrection((CorrectionInfo)msg.obj);
                return;
            }
            case DO_SET_COMPOSING_TEXT: {
                InputConnection ic = mInputConnection.get();
                if (ic == null || !isActive()) {
                    Log.w(TAG, "setComposingText on inactive InputConnection");
                    return;
                }
                ic.setComposingText((CharSequence)msg.obj, msg.arg1);
                return;
            }
            case DO_SET_COMPOSING_REGION: {
                InputConnection ic = mInputConnection.get();
                if (ic == null || !isActive()) {
                    Log.w(TAG, "setComposingRegion on inactive InputConnection");
                    return;
                }
                ic.setComposingRegion(msg.arg1, msg.arg2);
                return;
            }
            case DO_FINISH_COMPOSING_TEXT: {
                InputConnection ic = mInputConnection.get();
                // Note we do NOT check isActive() here, because this is safe
                // for an IME to call at any time, and we need to allow it
                // through to clean up our state after the IME has switched to
                // another client.
                if (ic == null) {
                    Log.w(TAG, "finishComposingText on inactive InputConnection");
                    return;
                }
                ic.finishComposingText();
                return;
            }
            case DO_SEND_KEY_EVENT: {
                InputConnection ic = mInputConnection.get();
                if (ic == null || !isActive()) {
                    Log.w(TAG, "sendKeyEvent on inactive InputConnection");
                    return;
                }
                ic.sendKeyEvent((KeyEvent)msg.obj);
                return;
            }
            case DO_CLEAR_META_KEY_STATES: {
                InputConnection ic = mInputConnection.get();
                if (ic == null || !isActive()) {
                    Log.w(TAG, "clearMetaKeyStates on inactive InputConnection");
                    return;
                }
                ic.clearMetaKeyStates(msg.arg1);
                return;
            }
            case DO_DELETE_SURROUNDING_TEXT: {
                InputConnection ic = mInputConnection.get();
                if (ic == null || !isActive()) {
                    Log.w(TAG, "deleteSurroundingText on inactive InputConnection");
                    return;
                }
                ic.deleteSurroundingText(msg.arg1, msg.arg2);
                return;
            }
            case DO_BEGIN_BATCH_EDIT: {
                InputConnection ic = mInputConnection.get();
                if (ic == null || !isActive()) {
                    Log.w(TAG, "beginBatchEdit on inactive InputConnection");
                    return;
                }
                ic.beginBatchEdit();
                return;
            }
            case DO_END_BATCH_EDIT: {
                InputConnection ic = mInputConnection.get();
                if (ic == null || !isActive()) {
                    Log.w(TAG, "endBatchEdit on inactive InputConnection");
                    return;
                }
                ic.endBatchEdit();
                return;
            }
            case DO_REPORT_FULLSCREEN_MODE: {
                InputConnection ic = mInputConnection.get();
                if (ic == null || !isActive()) {
                    Log.w(TAG, "showStatusIcon on inactive InputConnection");
                    return;
                }
                ic.reportFullscreenMode(msg.arg1 == 1);
                return;
            }
            case DO_PERFORM_PRIVATE_COMMAND: {
                InputConnection ic = mInputConnection.get();
                if (ic == null || !isActive()) {
                    Log.w(TAG, "performPrivateCommand on inactive InputConnection");
                    return;
                }
                SomeArgs args = (SomeArgs)msg.obj;
                ic.performPrivateCommand((String)args.arg1,
                        (Bundle)args.arg2);
                return;
            }
            case DO_REQUEST_UPDATE_CURSOR_ANCHOR_INFO: {
                SomeArgs args = (SomeArgs)msg.obj;
                try {
                    InputConnection ic = mInputConnection.get();
                    if (ic == null || !isActive()) {
                        Log.w(TAG, "requestCursorAnchorInfo on inactive InputConnection");
                        args.callback.setRequestUpdateCursorAnchorInfoResult(false, args.seq);
                        return;
                    }
                    args.callback.setRequestUpdateCursorAnchorInfoResult(
                            ic.requestCursorUpdates(msg.arg1), args.seq);
                } catch (RemoteException e) {
                    Log.w(TAG, "Got RemoteException calling requestCursorAnchorInfo", e);
                }
                return;
            }
        }
        Log.w(TAG, "Unhandled message code: " + msg.what);
    
public voidfinishComposingText()

        dispatchMessage(obtainMessage(DO_FINISH_COMPOSING_TEXT));
    
public voidgetCursorCapsMode(int reqModes, int seq, IInputContextCallback callback)

        dispatchMessage(obtainMessageISC(DO_GET_CURSOR_CAPS_MODE, reqModes, seq, callback));
    
public voidgetExtractedText(android.view.inputmethod.ExtractedTextRequest request, int flags, int seq, IInputContextCallback callback)

        dispatchMessage(obtainMessageIOSC(DO_GET_EXTRACTED_TEXT, flags,
                request, seq, callback));
    
public voidgetSelectedText(int flags, int seq, IInputContextCallback callback)

        dispatchMessage(obtainMessageISC(DO_GET_SELECTED_TEXT, flags, seq, callback));
    
public voidgetTextAfterCursor(int length, int flags, int seq, IInputContextCallback callback)

        dispatchMessage(obtainMessageIISC(DO_GET_TEXT_AFTER_CURSOR, length, flags, seq, callback));
    
public voidgetTextBeforeCursor(int length, int flags, int seq, IInputContextCallback callback)

        dispatchMessage(obtainMessageIISC(DO_GET_TEXT_BEFORE_CURSOR, length, flags, seq, callback));
    
public booleanisActive()

        return true;
    
android.os.MessageobtainMessage(int what)

        return mH.obtainMessage(what);
    
android.os.MessageobtainMessageII(int what, int arg1, int arg2)

        return mH.obtainMessage(what, arg1, arg2);
    
android.os.MessageobtainMessageIISC(int what, int arg1, int arg2, int seq, IInputContextCallback callback)

        SomeArgs args = new SomeArgs();
        args.callback = callback;
        args.seq = seq;
        return mH.obtainMessage(what, arg1, arg2, args);
    
android.os.MessageobtainMessageIO(int what, int arg1, java.lang.Object arg2)

        return mH.obtainMessage(what, arg1, 0, arg2);
    
android.os.MessageobtainMessageIOSC(int what, int arg1, java.lang.Object arg2, int seq, IInputContextCallback callback)

        SomeArgs args = new SomeArgs();
        args.arg1 = arg2;
        args.callback = callback;
        args.seq = seq;
        return mH.obtainMessage(what, arg1, 0, args);
    
android.os.MessageobtainMessageISC(int what, int arg1, int seq, IInputContextCallback callback)

        SomeArgs args = new SomeArgs();
        args.callback = callback;
        args.seq = seq;
        return mH.obtainMessage(what, arg1, 0, args);
    
android.os.MessageobtainMessageO(int what, java.lang.Object arg1)

        return mH.obtainMessage(what, 0, 0, arg1);
    
android.os.MessageobtainMessageOO(int what, java.lang.Object arg1, java.lang.Object arg2)

        SomeArgs args = new SomeArgs();
        args.arg1 = arg1;
        args.arg2 = arg2;
        return mH.obtainMessage(what, 0, 0, args);
    
android.os.MessageobtainMessageOSC(int what, java.lang.Object arg1, int seq, IInputContextCallback callback)

        SomeArgs args = new SomeArgs();
        args.arg1 = arg1;
        args.callback = callback;
        args.seq = seq;
        return mH.obtainMessage(what, 0, 0, args);
    
public voidperformContextMenuAction(int id)

        dispatchMessage(obtainMessageII(DO_PERFORM_CONTEXT_MENU_ACTION, id, 0));
    
public voidperformEditorAction(int id)

        dispatchMessage(obtainMessageII(DO_PERFORM_EDITOR_ACTION, id, 0));
    
public voidperformPrivateCommand(java.lang.String action, android.os.Bundle data)

        dispatchMessage(obtainMessageOO(DO_PERFORM_PRIVATE_COMMAND, action, data));
    
public voidreportFullscreenMode(boolean enabled)

        dispatchMessage(obtainMessageII(DO_REPORT_FULLSCREEN_MODE, enabled ? 1 : 0, 0));
    
public voidrequestUpdateCursorAnchorInfo(int cursorUpdateMode, int seq, IInputContextCallback callback)

        dispatchMessage(obtainMessageISC(DO_REQUEST_UPDATE_CURSOR_ANCHOR_INFO, cursorUpdateMode,
                seq, callback));
    
public voidsendKeyEvent(android.view.KeyEvent event)

        dispatchMessage(obtainMessageO(DO_SEND_KEY_EVENT, event));
    
public voidsetComposingRegion(int start, int end)

        dispatchMessage(obtainMessageII(DO_SET_COMPOSING_REGION, start, end));
    
public voidsetComposingText(java.lang.CharSequence text, int newCursorPosition)

        dispatchMessage(obtainMessageIO(DO_SET_COMPOSING_TEXT, newCursorPosition, text));
    
public voidsetSelection(int start, int end)

        dispatchMessage(obtainMessageII(DO_SET_SELECTION, start, end));