/** * Handles a key event. * * @param event the key event to handle * @return {@code true} if the event was handled */ public boolean handleKey(KeyEvent event) { if (event.getAction() != KeyEvent.ACTION_DOWN) { return false; } int code = event.getKeyCode(); if (code == KeyEvent.KEYCODE_ENTER) { displaySingleTimeMessage(context.getString(R.string.keyboard_enter)); Action.ENTER.execute(commands); return true; } if (code == KeyEvent.KEYCODE_DEL) { displaySingleTimeMessage(context.getString(R.string.keyboard_del)); Action.BACKSPACE.execute(commands); return true; } if (code == KeyEvent.KEYCODE_SPACE) { appendDisplayedText(" "); commands.keyPress(Code.KEYCODE_SPACE); return true; } int c = event.getUnicodeChar(); return handleChar((char) c); }
/** * Handles a character input. * * @param c the character being typed * @return {@code true} if the event was handled */ public boolean handleChar(char c) { if (isValidCharacter(c)) { String str = String.valueOf(c); appendDisplayedText(str); commands.string(str); return true; } return false; }