From 3b4eb03fa171ab42ad4f38abcfa5184c5362e5ae Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Fri, 31 Jan 2014 16:27:49 +0900 Subject: [PATCH] Move some prefix strings to relevant classes Change-Id: I7321ac7820d4eded5f16f2440ffb4f525315b3f4 --- .../keyboard/internal/KeySpecParser.java | 18 +++++++++--------- .../keyboard/internal/KeyboardCodesSet.java | 2 ++ .../keyboard/internal/KeyboardIconsSet.java | 1 + .../keyboard/internal/KeyboardTextsSet.java | 2 +- .../keyboard/internal/MoreKeySpec.java | 2 +- .../keyboard/internal/KeyboardTextsSet.tmpl | 2 +- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java index 144d55220..07c5cae8a 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java @@ -52,8 +52,6 @@ public final class KeySpecParser { private static final char COMMA = ','; private static final char BACKSLASH = '\\'; private static final char VERTICAL_BAR = '|'; - static final String PREFIX_ICON = "!icon/"; - private static final String PREFIX_CODE = "!code/"; private static final String PREFIX_HEX = "0x"; private static final String ADDITIONAL_MORE_KEY_MARKER = "%"; @@ -115,13 +113,13 @@ public final class KeySpecParser { } private static boolean hasIcon(final String moreKeySpec) { - return moreKeySpec.startsWith(PREFIX_ICON); + return moreKeySpec.startsWith(KeyboardIconsSet.PREFIX_ICON); } private static boolean hasCode(final String moreKeySpec) { final int end = indexOfLabelEnd(moreKeySpec, 0); if (end > 0 && end + 1 < moreKeySpec.length() && moreKeySpec.startsWith( - PREFIX_CODE, end + 1)) { + KeyboardCodesSet.PREFIX_CODE, end + 1)) { return true; } return false; @@ -243,8 +241,8 @@ public final class KeySpecParser { public static int parseCode(final String text, final KeyboardCodesSet codesSet, final int defCode) { if (text == null) return defCode; - if (text.startsWith(PREFIX_CODE)) { - return codesSet.getCode(text.substring(PREFIX_CODE.length())); + if (text.startsWith(KeyboardCodesSet.PREFIX_CODE)) { + return codesSet.getCode(text.substring(KeyboardCodesSet.PREFIX_CODE.length())); } else if (text.startsWith(PREFIX_HEX)) { return Integer.parseInt(text.substring(PREFIX_HEX.length()), 16); } else { @@ -254,9 +252,11 @@ public final class KeySpecParser { public static int getIconId(final String moreKeySpec) { if (moreKeySpec != null && hasIcon(moreKeySpec)) { - final int end = moreKeySpec.indexOf(VERTICAL_BAR, PREFIX_ICON.length()); - final String name = (end < 0) ? moreKeySpec.substring(PREFIX_ICON.length()) - : moreKeySpec.substring(PREFIX_ICON.length(), end); + final int end = moreKeySpec.indexOf( + VERTICAL_BAR, KeyboardIconsSet.PREFIX_ICON.length()); + final String name = (end < 0) + ? moreKeySpec.substring(KeyboardIconsSet.PREFIX_ICON.length()) + : moreKeySpec.substring(KeyboardIconsSet.PREFIX_ICON.length(), end); return KeyboardIconsSet.getIconId(name); } return KeyboardIconsSet.ICON_UNDEFINED; diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java index 78809d53b..aeb4db557 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardCodesSet.java @@ -22,6 +22,8 @@ import com.android.inputmethod.latin.utils.CollectionUtils; import java.util.HashMap; public final class KeyboardCodesSet { + public static final String PREFIX_CODE = "!code/"; + private static final HashMap sLanguageToCodesMap = CollectionUtils.newHashMap(); private static final HashMap sNameToIdMap = CollectionUtils.newHashMap(); diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java index 0ee935f60..da8bf7d69 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardIconsSet.java @@ -30,6 +30,7 @@ import java.util.HashMap; public final class KeyboardIconsSet { private static final String TAG = KeyboardIconsSet.class.getSimpleName(); + public static final String PREFIX_ICON = "!icon/"; public static final int ICON_UNDEFINED = 0; private static final int ATTR_UNDEFINED = 0; diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java index d953a6bb1..96a5b089f 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java +++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.java @@ -46,7 +46,7 @@ import java.util.HashMap; * KeyboardTextsSet.java */ public final class KeyboardTextsSet { - private static final String PREFIX_TEXT = "!text/"; + public static final String PREFIX_TEXT = "!text/"; private static final char BACKSLASH = '\\'; private static final int MAX_STRING_REFERENCE_INDIRECTION = 10; diff --git a/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpec.java b/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpec.java index 889fc9c7e..dd58e1ff4 100644 --- a/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpec.java +++ b/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpec.java @@ -74,7 +74,7 @@ public final class MoreKeySpec { @Override public String toString() { final String label = (mIconId == KeyboardIconsSet.ICON_UNDEFINED ? mLabel - : KeySpecParser.PREFIX_ICON + KeyboardIconsSet.getIconName(mIconId)); + : KeyboardIconsSet.PREFIX_ICON + KeyboardIconsSet.getIconName(mIconId)); final String output = (mCode == Constants.CODE_OUTPUT_TEXT ? mOutputText : Constants.printableCode(mCode)); if (StringUtils.codePointCount(label) == 1 && label.codePointAt(0) == mCode) { diff --git a/tools/make-keyboard-text/res/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.tmpl b/tools/make-keyboard-text/res/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.tmpl index 5898bc50b..92529925d 100644 --- a/tools/make-keyboard-text/res/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.tmpl +++ b/tools/make-keyboard-text/res/com/android/inputmethod/keyboard/internal/KeyboardTextsSet.tmpl @@ -46,7 +46,7 @@ import java.util.HashMap; * KeyboardTextsSet.java */ public final class KeyboardTextsSet { - private static final String PREFIX_TEXT = "!text/"; + public static final String PREFIX_TEXT = "!text/"; private static final char BACKSLASH = '\\'; private static final int MAX_STRING_REFERENCE_INDIRECTION = 10;