Simplify key event handling
This commit is contained in:
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user