Search code examples
androidkeyboardprimary-keyenter

Handling Enter and search key on the keyboard


Hi I want to if anyone has Idea about google keyboard when you enter url in search it show search icon and when you type in SMS or comment on there places like fb or EditText it show Backspace photo for referenceThis one show search button. So below codes are working I want add to Enter button together with those this keys, beacuse when I enter with this keyboard in url I cannot press enter to show results it work in whatsapp and other app but not in brower.

this one show backspace

 public void onKey(int primaryCode, int[] keyCodes) {
    this.previousWord = "";
    if (isWordSeparator(primaryCode) && this.mComposing.length() > 0) {
        this.previousWord = this.mComposing.toString();
        commitTyped(getCurrentInputConnection());
    }
    playClick(primaryCode);
    Keyboard current;
    if (primaryCode == -5) {
        handleBackspace();
    } else if (primaryCode == -1) {
        handleShift();
    } else if (primaryCode == -4) {
        handleClose();
    }else if (primaryCode == -2) {
        if (this.kv.getKeyboard() == this.symbols) {
            current = this.keyboard;
        } else {
            current = this.symbols;
        }
        this.kv.setKeyboard(current);
        if (current == this.symbols) {
            current.setShifted(false);
        }
    } else if (primaryCode == -6) {
        if (this.kv.getKeyboard() == this.eng_keyboard) {
            current = this.keyboard;
        } else {
            current = this.eng_keyboard;
        }
        this.kv.setKeyboard(current);
    }else if (primaryCode == -10) {
        if (this.kv.getKeyboard() == this.keyboard) {
            current = this.eng_keyboard;
        } else {
            current = this.keyboard;
        }
        this.kv.setKeyboard(current);
    }else {
        handleCharacter(primaryCode, keyCodes);
    }
}

those keys working I want to add enter/search key to it when typing in url area

public void swipeDown() {
    handleClose();
}

public void swipeLeft() {
    pickSuggestionManually(1);
}

public void swipeRight() {
    handleBackspace();
}

public void swipeUp() {
}

private void handleClose() {
    requestHideSelf(0);
    this.mComposing = new StringBuilder();
    setSuggestions(null, false, false);
    updateCandidates();
    this.kv.closing();
}

private void handleCharacter(int primaryCode, int[] keyCodes) {
    if (isInputViewShown() && isInputViewShown() && this.kv.isShifted()) {
        primaryCode = Character.toUpperCase(primaryCode);
    }
    if (isAlphabet(primaryCode) && this.mPredictionOn) {
        this.mComposing.append((char) primaryCode);
        getCurrentInputConnection().setComposingText(this.mComposing, 1);
        updateShiftKeyState(getCurrentInputEditorInfo());
        updateCandidates();
        return;
    }
    getCurrentInputConnection().commitText(String.valueOf((char) primaryCode), 1);
}

private void handleShift() {
    if (this.kv != null && this.eng_keyboard == this.kv.getKeyboard()) {
        checkToggleCapsLock();
        KeyboardView keyboardView = this.kv;
        boolean z = this.mCapsLock || !this.kv.isShifted();
        keyboardView.setShifted(z);
    }
}

private void checkToggleCapsLock() {
    long now = System.currentTimeMillis();
    if (this.mLastShiftTime + 800 > now) {
        this.mCapsLock = !this.mCapsLock;
        this.mLastShiftTime = 0;
        return;
    }
    this.mLastShiftTime = now;
}

Solution

  • I had to create two diffrent keyboard xml one with enter button and another with backspace. I have to type in edittext keyboard with backspace button apear and when type in search bar then keyboard with enter button apear.