diff options
| author | Tadashi G. Takaoka <takaoka@google.com> | 2012-04-20 06:24:51 +0900 |
|---|---|---|
| committer | Tadashi G. Takaoka <takaoka@google.com> | 2012-04-20 15:31:42 +0900 |
| commit | cf41aff251ecc94b729307ede05208a104fcd8b0 (patch) | |
| tree | 5181ed357f57f35b7ebef56a709f390496b9d03e /java/src/com/android/inputmethod/keyboard/internal | |
| parent | 050b577bfb9a033cfa049b2d4be2a15609ea7ce2 (diff) | |
Use string attribute for icon name
Change-Id: I336acf33c7e6bc993b9da9b17ec689975fa8127d
Diffstat (limited to 'java/src/com/android/inputmethod/keyboard/internal')
4 files changed, 47 insertions, 49 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java index e24cfa0e7..97e360e0b 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java @@ -76,14 +76,7 @@ public class KeySpecParser { } private static boolean hasIcon(String moreKeySpec) { - if (moreKeySpec.regionMatches(true, 0, PREFIX_ICON, 0, PREFIX_ICON.length())) { - final int end = indexOfLabelEnd(moreKeySpec, 0); - if (end > 0) { - return true; - } - throw new KeySpecParserError("outputText or code not specified: " + moreKeySpec); - } - return false; + return moreKeySpec.regionMatches(true, 0, PREFIX_ICON, 0, PREFIX_ICON.length()); } private static boolean hasCode(String moreKeySpec) { @@ -219,10 +212,11 @@ public class KeySpecParser { } } - static int getIconId(String moreKeySpec) { - if (hasIcon(moreKeySpec)) { + public static int getIconId(String moreKeySpec) { + if (moreKeySpec != null && hasIcon(moreKeySpec)) { final int end = moreKeySpec.indexOf(LABEL_END, PREFIX_ICON.length()); - final String name = moreKeySpec.substring(PREFIX_ICON.length(), end); + final String name = (end < 0) ? moreKeySpec.substring(PREFIX_ICON.length()) + : moreKeySpec.substring(PREFIX_ICON.length(), end); return KeyboardIconsSet.getIconId(name); } return KeyboardIconsSet.ICON_UNDEFINED; diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java index 8e0b21607..922a44158 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyStyles.java @@ -145,9 +145,9 @@ public class KeyStyles { readStringArray(keyAttr, R.styleable.Keyboard_Key_moreKeys); readStringArray(keyAttr, R.styleable.Keyboard_Key_additionalMoreKeys); readFlag(keyAttr, R.styleable.Keyboard_Key_keyLabelFlags); - readInt(keyAttr, R.styleable.Keyboard_Key_keyIcon); - readInt(keyAttr, R.styleable.Keyboard_Key_keyIconDisabled); - readInt(keyAttr, R.styleable.Keyboard_Key_keyIconPreview); + readString(keyAttr, R.styleable.Keyboard_Key_keyIcon); + readString(keyAttr, R.styleable.Keyboard_Key_keyIconDisabled); + readString(keyAttr, R.styleable.Keyboard_Key_keyIconPreview); readInt(keyAttr, R.styleable.Keyboard_Key_maxMoreKeysColumn); readInt(keyAttr, R.styleable.Keyboard_Key_backgroundType); readFlag(keyAttr, R.styleable.Keyboard_Key_keyActionFlags); diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java index 07636249f..a86a9577f 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java @@ -28,48 +28,52 @@ import java.util.HashMap; public class KeyboardIconsSet { private static final String TAG = KeyboardIconsSet.class.getSimpleName(); - // The value should be aligned with the enum value of Key.keyIcon. public static final int ICON_UNDEFINED = 0; - private static final int NUM_ICONS = 16; - - private final Drawable[] mIcons = new Drawable[NUM_ICONS + 1]; + private static final int ATTR_UNDEFINED = 0; private static final HashMap<Integer, Integer> ATTR_ID_TO_ICON_ID = new HashMap<Integer, Integer>(); + // Lower case icon name to icon id map. private static final HashMap<String, Integer> sLowerCaseNameToIdsMap = new HashMap<String, Integer>(); - private static final String[] ICON_NAMES = new String[NUM_ICONS + 1]; - private static final int ATTR_UNDEFINED = 0; - static { - // The key value should be aligned with the enum value of Key.keyIcon. - addIconIdMap(0, "undefined", ATTR_UNDEFINED); - addIconIdMap(1, "shiftKey", R.styleable.Keyboard_iconShiftKey); - addIconIdMap(2, "deleteKey", R.styleable.Keyboard_iconDeleteKey); - addIconIdMap(3, "settingsKey", R.styleable.Keyboard_iconSettingsKey); - addIconIdMap(4, "spaceKey", R.styleable.Keyboard_iconSpaceKey); - addIconIdMap(5, "returnKey", R.styleable.Keyboard_iconReturnKey); - addIconIdMap(6, "searchKey", R.styleable.Keyboard_iconSearchKey); - addIconIdMap(7, "tabKey", R.styleable.Keyboard_iconTabKey); - addIconIdMap(8, "shortcutKey", R.styleable.Keyboard_iconShortcutKey); - addIconIdMap(9, "shortcutForLabel", R.styleable.Keyboard_iconShortcutForLabel); - addIconIdMap(10, "spaceKeyForNumberLayout", - R.styleable.Keyboard_iconSpaceKeyForNumberLayout); - addIconIdMap(11, "shiftKeyShifted", R.styleable.Keyboard_iconShiftKeyShifted); - addIconIdMap(12, "disabledShortcurKey", R.styleable.Keyboard_iconDisabledShortcutKey); - addIconIdMap(13, "previewTabKey", R.styleable.Keyboard_iconPreviewTabKey); - addIconIdMap(14, "languageSwitchKey", R.styleable.Keyboard_iconLanguageSwitchKey); - addIconIdMap(15, "zwnjKey", R.styleable.Keyboard_iconZwnjKey); - addIconIdMap(16, "zwjKey", R.styleable.Keyboard_iconZwjKey); - } + private static final Object[] NAMES_AND_ATTR_IDS = { + "undefined", ATTR_UNDEFINED, + "shift_key", R.styleable.Keyboard_iconShiftKey, + "delete_key", R.styleable.Keyboard_iconDeleteKey, + "settings_key", R.styleable.Keyboard_iconSettingsKey, + "space_key", R.styleable.Keyboard_iconSpaceKey, + "enter_key", R.styleable.Keyboard_iconEnterKey, + "search_key", R.styleable.Keyboard_iconSearchKey, + "tab_key", R.styleable.Keyboard_iconTabKey, + "shortcut_key", R.styleable.Keyboard_iconShortcutKey, + "shortcut_for_label", R.styleable.Keyboard_iconShortcutForLabel, + "space_key_for_number_layout", R.styleable.Keyboard_iconSpaceKeyForNumberLayout, + "shift_key_shifted", R.styleable.Keyboard_iconShiftKeyShifted, + "shortcut_key_disabled", R.styleable.Keyboard_iconShortcutKeyDisabled, + "tab_key_preview", R.styleable.Keyboard_iconTabKeyPreview, + "language_switch_key", R.styleable.Keyboard_iconLanguageSwitchKey, + "zwnj_key", R.styleable.Keyboard_iconZwnjKey, + "zwj_key", R.styleable.Keyboard_iconZwjKey, + }; + + private static int NUM_ICONS = NAMES_AND_ATTR_IDS.length / 2; + private static final String[] ICON_NAMES = new String[NUM_ICONS]; + private final Drawable[] mIcons = new Drawable[NUM_ICONS]; - private static void addIconIdMap(int iconId, String name, int attrId) { - if (attrId != ATTR_UNDEFINED) { - ATTR_ID_TO_ICON_ID.put(attrId, iconId); + static { + int iconId = ICON_UNDEFINED; + for (int i = 0; i < NAMES_AND_ATTR_IDS.length; i += 2) { + final String name = (String)NAMES_AND_ATTR_IDS[i]; + final Integer attrId = (Integer)NAMES_AND_ATTR_IDS[i + 1]; + if (attrId != ATTR_UNDEFINED) { + ATTR_ID_TO_ICON_ID.put(attrId, iconId); + } + sLowerCaseNameToIdsMap.put(name, iconId); + ICON_NAMES[iconId] = name; + iconId++; } - sLowerCaseNameToIdsMap.put(name.toLowerCase(), iconId); - ICON_NAMES[iconId] = name; } public void loadIcons(final TypedArray keyboardAttrs) { @@ -95,7 +99,7 @@ public class KeyboardIconsSet { return isValidIconId(iconId) ? ICON_NAMES[iconId] : "unknown<" + iconId + ">"; } - public static int getIconId(final String name) { + static int getIconId(final String name) { Integer iconId = sLowerCaseNameToIdsMap.get(name); if (iconId == null) { iconId = sLowerCaseNameToIdsMap.get(name.toLowerCase()); diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardLabelsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardLabelsSet.java index bd95848a9..1ba84e505 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardLabelsSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardLabelsSet.java @@ -345,8 +345,8 @@ public final class KeyboardLabelsSet { // U+2663: "♣" BLACK CLUB SUIT /* 108 */ "\u266A,\u2665,\u2660,\u2666,\u2663", /* 109 */ "!fixedColumnOrder!2,!hasLabels!,!label/label_time_am,!label/label_time_pm", - /* 110 */ "!icon/settingsKey|!code/key_settings", - /* 111 */ "!icon/shortcutKey|!code/key_shortcut", + /* 110 */ "!icon/settings_key|!code/key_settings", + /* 111 */ "!icon/shortcut_key|!code/key_shortcut", /* 112 */ "!hasLabels!,!label/label_next_key|!code/key_action_next", /* 113 */ "!hasLabels!,!label/label_previous_key|!code/key_action_previous", // Label for "switch to more symbol" modifier key. Must be short to fit on key! |
