public void commandAction(Command c, Displayable d) { int actionOld; if (c == CMD_RESET) { display.setCurrent(alertReset); } else if (c == CMD.YES && d == alertReset) { keyBindings.resetToDefaults(); updateList(); display.setCurrent(this); } else if (c == CMD.NO && d == alertReset) { display.setCurrent(this); } else if (c == List.SELECT_COMMAND) { // an action to set a key for // has been chosen actionToBind = getSelectedIndex(); screenKeyBinder.configure(actionToBind); display.setCurrent(screenKeyBinder); } else if (c == CMD.YES && d == alertKeyConflict) { actionOld = keyBindings.release(selectedKey); keyBindings.bindKeyToAction(actionToBind, selectedKey); updateList(actionToBind); if (actionOld >= 0) updateList(actionOld); display.setCurrent(this); } else if (c == CMD.NO && d == alertKeyConflict) { display.setCurrent(this); } else if (externalCommandListener != null) { externalCommandListener.commandAction(c, d); } else { Log.bug("Aug 21, 2009.8:06:24 PM"); } }
/** * 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 KeyBindingsScreen(final Display display) { super("Key Bindings", IMPLICIT); this.display = display; keyBindings = KeyBindings.getInstance(); screenKeyBinder = new KeyBinderScreen(this); addCommand(CMD_RESET); setCommandListener(this); for (int i = 0; i < KeyBindings.actionNames.length; i++) append("", null); updateList(); alertKeyConflict = new Alert("Key already in use!"); alertKeyConflict.setType(AlertType.WARNING); alertKeyConflict.setTimeout(Alert.FOREVER); alertKeyConflict.addCommand(CMD.NO); alertKeyConflict.addCommand(CMD.YES); alertKeyConflict.setCommandListener(this); alertReset = new Alert("Please confirm:"); alertReset.setString("Reset to default key bindings?"); alertReset.setType(AlertType.WARNING); alertReset.addCommand(CMD.NO); alertReset.addCommand(CMD.YES); alertReset.setCommandListener(this); }
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); } }