Search in sources :

Example 31 with InputConnection

use of android.view.inputmethod.InputConnection in project double-espresso by JakeWharton.

the class ViewMatchers method hasImeAction.

/**
   * Returns a matcher that matches views that support input methods (e.g. EditText) and have the
   * specified IME action set in its {@link EditorInfo}.
   *
   * @param imeActionMatcher a matcher for the IME action
   */
public static Matcher<View> hasImeAction(final Matcher<Integer> imeActionMatcher) {
    return new TypeSafeMatcher<View>() {

        @Override
        public void describeTo(Description description) {
            description.appendText("has ime action: ");
            imeActionMatcher.describeTo(description);
        }

        @Override
        public boolean matchesSafely(View view) {
            EditorInfo editorInfo = new EditorInfo();
            InputConnection inputConnection = view.onCreateInputConnection(editorInfo);
            if (inputConnection == null) {
                return false;
            }
            int actionId = editorInfo.actionId != 0 ? editorInfo.actionId : editorInfo.imeOptions & EditorInfo.IME_MASK_ACTION;
            return imeActionMatcher.matches(actionId);
        }
    };
}
Also used : InputConnection(android.view.inputmethod.InputConnection) TypeSafeMatcher(org.hamcrest.TypeSafeMatcher) Description(org.hamcrest.Description) StringDescription(org.hamcrest.StringDescription) EditorInfo(android.view.inputmethod.EditorInfo) TextView(android.widget.TextView) View(android.view.View)

Example 32 with InputConnection

use of android.view.inputmethod.InputConnection in project double-espresso by JakeWharton.

the class HumanReadables method describe.

/**
   * Transforms an arbitrary view into a string with (hopefully) enough debug info.
   *
   * @param v nullable view
   * @return a string for human consumption.
   */
public static String describe(View v) {
    if (null == v) {
        return "null";
    }
    ToStringHelper helper = Objects.toStringHelper(v).add("id", v.getId());
    if (v.getId() != -1 && v.getResources() != null) {
        try {
            helper.add("res-name", v.getResources().getResourceEntryName(v.getId()));
        } catch (Resources.NotFoundException ignore) {
        // Do nothing.
        }
    }
    if (null != v.getContentDescription()) {
        helper.add("desc", v.getContentDescription());
    }
    switch(v.getVisibility()) {
        case View.GONE:
            helper.add("visibility", "GONE");
            break;
        case View.INVISIBLE:
            helper.add("visibility", "INVISIBLE");
            break;
        case View.VISIBLE:
            helper.add("visibility", "VISIBLE");
            break;
        default:
            helper.add("visibility", v.getVisibility());
    }
    helper.add("width", v.getWidth()).add("height", v.getHeight()).add("has-focus", v.hasFocus()).add("has-focusable", v.hasFocusable()).add("has-window-focus", v.hasWindowFocus()).add("is-clickable", v.isClickable()).add("is-enabled", v.isEnabled()).add("is-focused", v.isFocused()).add("is-focusable", v.isFocusable()).add("is-layout-requested", v.isLayoutRequested()).add("is-selected", v.isSelected());
    if (null != v.getRootView()) {
        // pretty much only true in unit-tests.
        helper.add("root-is-layout-requested", v.getRootView().isLayoutRequested());
    }
    EditorInfo ei = new EditorInfo();
    InputConnection ic = v.onCreateInputConnection(ei);
    boolean hasInputConnection = ic != null;
    helper.add("has-input-connection", hasInputConnection);
    if (hasInputConnection) {
        StringBuilder sb = new StringBuilder();
        sb.append("[");
        Printer p = new StringBuilderPrinter(sb);
        ei.dump(p, "");
        sb.append("]");
        helper.add("editor-info", sb.toString().replace("\n", " "));
    }
    if (Build.VERSION.SDK_INT > 10) {
        helper.add("x", v.getX()).add("y", v.getY());
    }
    if (v instanceof TextView) {
        innerDescribe((TextView) v, helper);
    }
    if (v instanceof Checkable) {
        innerDescribe((Checkable) v, helper);
    }
    if (v instanceof ViewGroup) {
        innerDescribe((ViewGroup) v, helper);
    }
    return helper.toString();
}
Also used : InputConnection(android.view.inputmethod.InputConnection) EditorInfo(android.view.inputmethod.EditorInfo) ViewGroup(android.view.ViewGroup) StringBuilderPrinter(android.util.StringBuilderPrinter) TextView(android.widget.TextView) Resources(android.content.res.Resources) Checkable(android.widget.Checkable) Printer(android.util.Printer) StringBuilderPrinter(android.util.StringBuilderPrinter) ToStringHelper(com.google.common.base.Objects.ToStringHelper)

Example 33 with InputConnection

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

the class InputMethodService method sendDownUpKeyEvents.

/**
     * Send the given key event code (as defined by {@link KeyEvent}) to the
     * current input connection is a key down + key up event pair.  The sent
     * events have {@link KeyEvent#FLAG_SOFT_KEYBOARD KeyEvent.FLAG_SOFT_KEYBOARD}
     * set, so that the recipient can identify them as coming from a software
     * input method, and
     * {@link KeyEvent#FLAG_KEEP_TOUCH_MODE KeyEvent.FLAG_KEEP_TOUCH_MODE}, so
     * that they don't impact the current touch mode of the UI.
     *
     * <p>Note that it's discouraged to send such key events in normal operation;
     * this is mainly for use with {@link android.text.InputType#TYPE_NULL} type
     * text fields, or for non-rich input methods. A reasonably capable software
     * input method should use the
     * {@link android.view.inputmethod.InputConnection#commitText} family of methods
     * to send text to an application, rather than sending key events.</p>
     *
     * @param keyEventCode The raw key code to send, as defined by
     * {@link KeyEvent}.
     */
public void sendDownUpKeyEvents(int keyEventCode) {
    InputConnection ic = getCurrentInputConnection();
    if (ic == null)
        return;
    long eventTime = SystemClock.uptimeMillis();
    ic.sendKeyEvent(new KeyEvent(eventTime, eventTime, KeyEvent.ACTION_DOWN, keyEventCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE));
    ic.sendKeyEvent(new KeyEvent(eventTime, SystemClock.uptimeMillis(), KeyEvent.ACTION_UP, keyEventCode, 0, 0, KeyCharacterMap.VIRTUAL_KEYBOARD, 0, KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE));
}
Also used : InputConnection(android.view.inputmethod.InputConnection) KeyEvent(android.view.KeyEvent)

Example 34 with InputConnection

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

the class IInputMethodWrapper method bindInput.

@Override
public void bindInput(InputBinding binding) {
    // This IInputContext is guaranteed to implement all the methods.
    final int missingMethodFlags = 0;
    InputConnection ic = new InputConnectionWrapper(mTarget, IInputContext.Stub.asInterface(binding.getConnectionToken()), missingMethodFlags);
    InputBinding nu = new InputBinding(ic, binding);
    mCaller.executeOrSendMessage(mCaller.obtainMessageO(DO_SET_INPUT_CONTEXT, nu));
}
Also used : InputConnection(android.view.inputmethod.InputConnection) InputConnectionWrapper(com.android.internal.view.InputConnectionWrapper) InputBinding(android.view.inputmethod.InputBinding)

Example 35 with InputConnection

use of android.view.inputmethod.InputConnection in project kdeconnect-android by KDE.

the class RemoteKeyboardPlugin method handleVisibleKey.

private boolean handleVisibleKey(String key, boolean shift, boolean ctrl, boolean alt) {
    if (key.isEmpty())
        return false;
    InputConnection inputConn = RemoteKeyboardService.instance.getCurrentInputConnection();
    if (inputConn == null)
        return false;
    // ctrl+c/v/x
    if (key.equalsIgnoreCase("c") && ctrl) {
        return inputConn.performContextMenuAction(android.R.id.copy);
    } else if (key.equalsIgnoreCase("v") && ctrl)
        return inputConn.performContextMenuAction(android.R.id.paste);
    else if (key.equalsIgnoreCase("x") && ctrl)
        return inputConn.performContextMenuAction(android.R.id.cut);
    else if (key.equalsIgnoreCase("a") && ctrl)
        return inputConn.performContextMenuAction(android.R.id.selectAll);
    //        Log.d("RemoteKeyboardPlugin", "Committing visible key '" + key + "'");
    inputConn.commitText(key, key.length());
    return true;
}
Also used : InputConnection(android.view.inputmethod.InputConnection)

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