Skip to content

Commit

Permalink
reset input if switch input mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dongyuwei committed Feb 19, 2024
1 parent eceb571 commit 7b8ca86
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions app/src/main/java/rkr/tinykeyboard/inputmethod/SoftKeyboard.java
Original file line number Diff line number Diff line change
Expand Up @@ -405,18 +405,23 @@ private IBinder getToken() {


private void handleLanguageSwitch() {
reset();
inputMode = inputMode == InputMode.English ? InputMode.Pinyin : InputMode.English;
updateStatusOfSwitchKey();
}

private void updateStatusOfSwitchKey() {
List<Keyboard.Key> keys = mQwertyKeyboard.getKeys();
Keyboard.Key switchKey = keys.stream()
.filter(key -> key.codes != null && key.codes.length > 0 && key.codes[0] == LatinKeyboard.KEYCODE_LANGUAGE_SWITCH).findFirst().get();
.filter(key -> key.codes != null && key.codes.length > 0 && key.codes[0] == LatinKeyboard.KEYCODE_LANGUAGE_SWITCH)
.findFirst()
.get();

if (inputMode == InputMode.English) {
inputMode = InputMode.Pinyin;
if (inputMode == InputMode.Pinyin) {
switchKey.label = "\uD83C\uDF10中文";
} else {
inputMode = InputMode.English;
switchKey.label = "\uD83C\uDF10En";
}

// Redraw the keyboard with updated labels
mInputView.invalidateAllKeys();
}
Expand Down

0 comments on commit 7b8ca86

Please sign in to comment.