Simplify key event handling

This commit is contained in:
2024-11-08 21:53:55 +01:00
parent b4a0e12257
commit 8850c99b93
@@ -20,7 +20,6 @@ package eur.cfpifpsi.titanboard;
import android.annotation.SuppressLint;
import android.inputmethodservice.InputMethodService;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Vibrator;
@@ -86,41 +85,41 @@ public class InputMethod extends InputMethodService {
mMetaKeyManager.updateMetaStateDown(keyCode);
mInputView.updateStateText();
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
if (isInputViewShown()) {
requestHideSelf(0);
return true;
}
return false;
case KeyEvent.KEYCODE_DEL:
case KeyEvent.KEYCODE_ENTER:
mMetaKeyManager.adjustMetaStateAfterKeypress();
mInputView.updateStateText();
return false;
default:
ArrayList<String> symbols = mKeymapManager.getSymbols(keyCode, mMetaKeyManager);
InputConnection conn = getCurrentInputConnection();
if (symbols == null || conn == null) {
return false;
}
if (event.getRepeatCount() == 0 && !symbols.isEmpty()) {
conn.commitText(symbols.get(0), 1);
mMetaKeyManager.adjustMetaStateAfterKeypress();
mInputView.updateStateText();
mHandler.removeCallbacksAndMessages(null);
// If there's no symbols to cycle, why cycle at all?
if (symbols.size() > 1) {
mSymbolCycler.prepare(symbols);
mHandler.postDelayed(mSymbolCycler, mPreferenceHolder.getCycleSpeed());
}
}
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (isInputViewShown()) {
requestHideSelf(0);
return true;
}
return false;
}
if (keyCode == KeyEvent.KEYCODE_DEL || keyCode == KeyEvent.KEYCODE_ENTER) {
mMetaKeyManager.adjustMetaStateAfterKeypress();
mInputView.updateStateText();
return false;
}
ArrayList<String> symbols = mKeymapManager.getSymbols(keyCode, mMetaKeyManager);
InputConnection conn = getCurrentInputConnection();
if (symbols == null || conn == null) {
return false;
}
if (event.getRepeatCount() == 0 && !symbols.isEmpty()) {
conn.commitText(symbols.get(0), 1);
mMetaKeyManager.adjustMetaStateAfterKeypress();
mInputView.updateStateText();
mHandler.removeCallbacksAndMessages(null);
// If there's no symbols to cycle, why cycle at all?
if (symbols.size() > 1) {
mSymbolCycler.prepare(symbols);
mHandler.postDelayed(mSymbolCycler, mPreferenceHolder.getCycleSpeed());
}
}
return true;
}
public boolean onKeyUp(int keyCode, KeyEvent event) {