/** * Update the key name mapped to the given action in the displayed key bindings list. * * @param action */ private void updateList(int action) { int key; String keyName; key = keyBindings.getKeyForAction(action); try { keyName = (key != 0) ? screenKeyBinder.getKeyName(key) : ""; } catch (IllegalArgumentException e) { // may happen on version change or device firmware update keyBindings.release(key); keyName = ""; } set(action, KeyBindings.actionNames[action] + ": " + keyName, null); }
public void keyPressed(int key) { int actionOld; String keyName; if (key == 0 || key == keyBindings.getKeyForAction(actionToBind)) { display.setCurrent(this); } else if (keyBindings.isBound(key)) { selectedKey = key; actionOld = keyBindings.getActionForKey(key); keyName = screenKeyBinder.getKeyName(key); msgKeyConflict.delete(0, msgKeyConflict.length()); msgKeyConflict.append("Key ").append(keyName); msgKeyConflict.append(" is already in use for '"); msgKeyConflict.append(KeyBindings.actionNames[actionOld]).append("'."); msgKeyConflict.append("\nDo you want to unset it from '"); msgKeyConflict.append(KeyBindings.actionNames[actionOld]); msgKeyConflict.append("' and use it for '"); msgKeyConflict.append(KeyBindings.actionNames[actionToBind]).append("' ?"); alertKeyConflict.setString(msgKeyConflict.toString()); display.setCurrent(alertKeyConflict); } else { // key is valid and free keyBindings.bindKeyToAction(actionToBind, key); updateList(actionToBind); display.setCurrent(this); } }