Search in sources :

Example 81 with InputConnection

use of android.view.inputmethod.InputConnection in project android_frameworks_base by crdroidandroid.

the class TextView method onCreateInputConnection.

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    if (onCheckIsTextEditor() && isEnabled()) {
        mEditor.createInputMethodStateIfNeeded();
        outAttrs.inputType = getInputType();
        if (mEditor.mInputContentType != null) {
            outAttrs.imeOptions = mEditor.mInputContentType.imeOptions;
            outAttrs.privateImeOptions = mEditor.mInputContentType.privateImeOptions;
            outAttrs.actionLabel = mEditor.mInputContentType.imeActionLabel;
            outAttrs.actionId = mEditor.mInputContentType.imeActionId;
            outAttrs.extras = mEditor.mInputContentType.extras;
            outAttrs.hintLocales = mEditor.mInputContentType.imeHintLocales;
        } else {
            outAttrs.imeOptions = EditorInfo.IME_NULL;
            outAttrs.hintLocales = null;
        }
        if (focusSearch(FOCUS_DOWN) != null) {
            outAttrs.imeOptions |= EditorInfo.IME_FLAG_NAVIGATE_NEXT;
        }
        if (focusSearch(FOCUS_UP) != null) {
            outAttrs.imeOptions |= EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS;
        }
        if ((outAttrs.imeOptions & EditorInfo.IME_MASK_ACTION) == EditorInfo.IME_ACTION_UNSPECIFIED) {
            if ((outAttrs.imeOptions & EditorInfo.IME_FLAG_NAVIGATE_NEXT) != 0) {
                // An action has not been set, but the enter key will move to
                // the next focus, so set the action to that.
                outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
            } else {
                // An action has not been set, and there is no focus to move
                // to, so let's just supply a "done" action.
                outAttrs.imeOptions |= EditorInfo.IME_ACTION_DONE;
            }
            if (!shouldAdvanceFocusOnEnter()) {
                outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_ENTER_ACTION;
            }
        }
        if (isMultilineInputType(outAttrs.inputType)) {
            // Multi-line text editors should always show an enter key.
            outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_ENTER_ACTION;
        }
        outAttrs.hintText = mHint;
        if (mText instanceof Editable) {
            InputConnection ic = new EditableInputConnection(this);
            outAttrs.initialSelStart = getSelectionStart();
            outAttrs.initialSelEnd = getSelectionEnd();
            outAttrs.initialCapsMode = ic.getCursorCapsMode(getInputType());
            return ic;
        }
    }
    return null;
}
Also used : BaseInputConnection(android.view.inputmethod.BaseInputConnection) EditableInputConnection(com.android.internal.widget.EditableInputConnection) InputConnection(android.view.inputmethod.InputConnection) EditableInputConnection(com.android.internal.widget.EditableInputConnection) Editable(android.text.Editable)

Aggregations

InputConnection (android.view.inputmethod.InputConnection)81 EditorInfo (android.view.inputmethod.EditorInfo)20 InputBinding (android.view.inputmethod.InputBinding)14 InputConnectionWrapper (com.android.internal.view.InputConnectionWrapper)14 KeyEvent (android.view.KeyEvent)9 ViewGroup (android.view.ViewGroup)9 ExtractedTextRequest (android.view.inputmethod.ExtractedTextRequest)9 Editable (android.text.Editable)8 View (android.view.View)8 BaseInputConnection (android.view.inputmethod.BaseInputConnection)8 IBinder (android.os.IBinder)7 InputMethod (android.view.inputmethod.InputMethod)7 LinearLayout (android.widget.LinearLayout)7 TextView (android.widget.TextView)7 IInputContext (com.android.internal.view.IInputContext)7 IInputMethod (com.android.internal.view.IInputMethod)7 EditableInputConnection (com.android.internal.widget.EditableInputConnection)7 FileDescriptor (java.io.FileDescriptor)7 PrintWriter (java.io.PrintWriter)7 Spannable (android.text.Spannable)6