Android 自定义键盘 - 如何获取浏览器的 InputType?

Android Custom Keyboard - How to get browsers InputType?

我正在尝试为每种输入类型(如简单文本、数字、电子邮件、URL 地址、 ETC)。我不明白的是如何获得浏览器 URL TextEditor InputType,这样我就可以制作一个带有 'Access' 按钮的键盘。

@Override public void onStartInput(EditorInfo attribute, boolean restarting) {
    super.onStartInput(attribute, restarting);

    switch (attribute.inputType & InputType.TYPE_MASK_CLASS) {
        case InputType.TYPE_CLASS_NUMBER:
        case InputType.TYPE_CLASS_DATETIME:
        case InputType.TYPE_CLASS_PHONE:
            mCurKeyboard = symKeyboard_1;
            break;
        case InputType.TYPE_TEXT_VARIATION_URI:
        case InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT:
        case InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS:
        case InputType.TYPE_TEXT_VARIATION_EMAIL_SUBJECT:
        case InputType.TYPE_TEXT_VARIATION_POSTAL_ADDRESS:
        case InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS:
            mCurKeyboard = webKeyboard;
            Log.d("debug", "web keyboard");
            break;
        case InputType.TYPE_CLASS_TEXT:
            mCurKeyboard = myKeyboard;
            Log.d("debug", "text");
            break;
        default:
            mCurKeyboard = myKeyboard;
            Log.d("debug", "default");
            break;
    }
}

但我仍然得到 InputType.TYPE_CLASS_TEXT 作为 InputType。

我想我已经尝试了几乎所有 InputType,但是 none 可以确定我何时在 URLs 文本框中输入。我需要一个解决方案来找到 URL TextEditor.

的输入类型

顺便说一句:如何通过传递给 getCurrentInputConnection().sendKeyEvent()KeyEvent 对浏览器执行 AccessGo 操作?

稍后编辑。解法:

@Override public void onStartInput(EditorInfo attribute, boolean restarting) {
    super.onStartInput(attribute, restarting);

    switch (attribute.inputType & InputType.TYPE_MASK_CLASS) {
        case InputType.TYPE_CLASS_NUMBER:
        case InputType.TYPE_CLASS_DATETIME:
        case InputType.TYPE_CLASS_PHONE:
            currentKeyboard = numericKeyboard;
            break;
        case InputType.TYPE_CLASS_TEXT:
            int webInputType = attribute.inputType & InputType.TYPE_MASK_VARIATION;

            if (webInputType == InputType.TYPE_TEXT_VARIATION_URI ||
                    webInputType == InputType.TYPE_TEXT_VARIATION_WEB_EDIT_TEXT ||
                    webInputType == InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS
                    || webInputType == InputType.TYPE_TEXT_VARIATION_WEB_EMAIL_ADDRESS) {
                currentKeyboard = webKeyboard;
            }else{
                currentKeyboard = latinKeyboard;
            }
            break;
        default:
            currentKeyboard = latinKeyboard;
            break;
    }
}

@ray20 说的是处理"Access"、"GO" 动作的答案,这是针对其他编辑器动作的:

private void handleAction(){
    EditorInfo curEditor = getCurrentInputEditorInfo();
    switch (curEditor.imeOptions & EditorInfo.IME_MASK_ACTION){
        case EditorInfo.IME_ACTION_DONE:
            getCurrentInputConnection().performEditorAction(EditorInfo.IME_ACTION_DONE);
            break;
        case EditorInfo.IME_ACTION_GO:
            getCurrentInputConnection().performEditorAction(EditorInfo.IME_ACTION_GO);
            break;
        case EditorInfo.IME_ACTION_NEXT:
            getCurrentInputConnection().performEditorAction(EditorInfo.IME_ACTION_NEXT);
            break;
        case EditorInfo.IME_ACTION_SEARCH:
            getCurrentInputConnection().performEditorAction(EditorInfo.IME_ACTION_SEARCH);
            break;
        case EditorInfo.IME_ACTION_SEND:
            getCurrentInputConnection().performEditorAction(EditorInfo.IME_ACTION_SEND);
            break;
        default:
            handleClose(); //method that hides the keyboard with no action performed
            break;
    }
}

只需执行 GO 操作

getCurrentInputConnection().performEditorAction(EditorInfo.IME_ACTION_GO);