Android Custom Keyboard - How to get browsers InputType?

I am trying to create a custom Android keyboard (min API 16) with a keyboard for each type of input (e.g. plain text, numeric, email, url, etc.). I don't understand how to get the Browser's TextEditor InputType URL so that I can create a keyboard with an Access button.

@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;
    }
}

      

But I am still getting as InputType InputType.TYPE_CLASS_TEXT

.

I think I have tried almost everything InputType

, but no one is trying to detect when I type in the URL textbox. I need a solution to find a TextEditor url input type.

BTW: How do I perform an action Access

or Go

in the browser via KeyEvent

passed to getCurrentInputConnection().sendKeyEvent()

?

Later Edit. Decision:

@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 said the answer for handling the "Access" action is "GO", this is for other editor actions:

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;
    }
}

      

+3


source to share


1 answer


To perform a GO action simply



getCurrentInputConnection().performEditorAction(EditorInfo.IME_ACTION_GO);

0


source







All Articles