Code example for SparseBooleanArray

Methods: getput

    private void initShortcutPreferences() { 
        /** Whether the shortcut has been seen already.  The array index is the shortcut. */ 
        SparseBooleanArray shortcutSeen = new SparseBooleanArray();
        KeyCharacterMap keyMap = KeyCharacterMap.load(KeyCharacterMap.BUILT_IN_KEYBOARD);
        // Go through all the key codes and create a preference for the appropriate keys 
        for (int keyCode = KeyEvent.getMaxKeyCode() - 1; keyCode >= 0; keyCode--) {
            // Get the label for the primary char on the key that produces this key code 
            char shortcut = (char) Character.toLowerCase(keyMap.getDisplayLabel(keyCode));
            if (shortcut == 0 || shortcutSeen.get(shortcut, false)) continue;
            // TODO: need a to tell if the current keyboard can produce this key code, for now 
            // only allow the letter or digits 
            if (!Character.isLetterOrDigit(shortcut)) continue;
            shortcutSeen.put(shortcut, true);