Merge "Move some prefix strings to relevant classes"

main
Tadashi G. Takaoka 2014-01-31 08:11:56 +00:00 committed by Android (Google) Code Review
commit 7914a97b73
6 changed files with 15 additions and 12 deletions

View File

@ -52,8 +52,6 @@ public final class KeySpecParser {
private static final char COMMA = ','; private static final char COMMA = ',';
private static final char BACKSLASH = '\\'; private static final char BACKSLASH = '\\';
private static final char VERTICAL_BAR = '|'; 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 PREFIX_HEX = "0x";
private static final String ADDITIONAL_MORE_KEY_MARKER = "%"; private static final String ADDITIONAL_MORE_KEY_MARKER = "%";
@ -115,13 +113,13 @@ public final class KeySpecParser {
} }
private static boolean hasIcon(final String moreKeySpec) { 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) { private static boolean hasCode(final String moreKeySpec) {
final int end = indexOfLabelEnd(moreKeySpec, 0); final int end = indexOfLabelEnd(moreKeySpec, 0);
if (end > 0 && end + 1 < moreKeySpec.length() && moreKeySpec.startsWith( if (end > 0 && end + 1 < moreKeySpec.length() && moreKeySpec.startsWith(
PREFIX_CODE, end + 1)) { KeyboardCodesSet.PREFIX_CODE, end + 1)) {
return true; return true;
} }
return false; return false;
@ -243,8 +241,8 @@ public final class KeySpecParser {
public static int parseCode(final String text, final KeyboardCodesSet codesSet, public static int parseCode(final String text, final KeyboardCodesSet codesSet,
final int defCode) { final int defCode) {
if (text == null) return defCode; if (text == null) return defCode;
if (text.startsWith(PREFIX_CODE)) { if (text.startsWith(KeyboardCodesSet.PREFIX_CODE)) {
return codesSet.getCode(text.substring(PREFIX_CODE.length())); return codesSet.getCode(text.substring(KeyboardCodesSet.PREFIX_CODE.length()));
} else if (text.startsWith(PREFIX_HEX)) { } else if (text.startsWith(PREFIX_HEX)) {
return Integer.parseInt(text.substring(PREFIX_HEX.length()), 16); return Integer.parseInt(text.substring(PREFIX_HEX.length()), 16);
} else { } else {
@ -254,9 +252,11 @@ public final class KeySpecParser {
public static int getIconId(final String moreKeySpec) { public static int getIconId(final String moreKeySpec) {
if (moreKeySpec != null && hasIcon(moreKeySpec)) { if (moreKeySpec != null && hasIcon(moreKeySpec)) {
final int end = moreKeySpec.indexOf(VERTICAL_BAR, PREFIX_ICON.length()); final int end = moreKeySpec.indexOf(
final String name = (end < 0) ? moreKeySpec.substring(PREFIX_ICON.length()) VERTICAL_BAR, KeyboardIconsSet.PREFIX_ICON.length());
: moreKeySpec.substring(PREFIX_ICON.length(), end); final String name = (end < 0)
? moreKeySpec.substring(KeyboardIconsSet.PREFIX_ICON.length())
: moreKeySpec.substring(KeyboardIconsSet.PREFIX_ICON.length(), end);
return KeyboardIconsSet.getIconId(name); return KeyboardIconsSet.getIconId(name);
} }
return KeyboardIconsSet.ICON_UNDEFINED; return KeyboardIconsSet.ICON_UNDEFINED;

View File

@ -22,6 +22,8 @@ import com.android.inputmethod.latin.utils.CollectionUtils;
import java.util.HashMap; import java.util.HashMap;
public final class KeyboardCodesSet { public final class KeyboardCodesSet {
public static final String PREFIX_CODE = "!code/";
private static final HashMap<String, int[]> sLanguageToCodesMap = CollectionUtils.newHashMap(); private static final HashMap<String, int[]> sLanguageToCodesMap = CollectionUtils.newHashMap();
private static final HashMap<String, Integer> sNameToIdMap = CollectionUtils.newHashMap(); private static final HashMap<String, Integer> sNameToIdMap = CollectionUtils.newHashMap();

View File

@ -30,6 +30,7 @@ import java.util.HashMap;
public final class KeyboardIconsSet { public final class KeyboardIconsSet {
private static final String TAG = KeyboardIconsSet.class.getSimpleName(); private static final String TAG = KeyboardIconsSet.class.getSimpleName();
public static final String PREFIX_ICON = "!icon/";
public static final int ICON_UNDEFINED = 0; public static final int ICON_UNDEFINED = 0;
private static final int ATTR_UNDEFINED = 0; private static final int ATTR_UNDEFINED = 0;

View File

@ -46,7 +46,7 @@ import java.util.HashMap;
* KeyboardTextsSet.java * KeyboardTextsSet.java
*/ */
public final class KeyboardTextsSet { 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 char BACKSLASH = '\\';
private static final int MAX_STRING_REFERENCE_INDIRECTION = 10; private static final int MAX_STRING_REFERENCE_INDIRECTION = 10;

View File

@ -74,7 +74,7 @@ public final class MoreKeySpec {
@Override @Override
public String toString() { public String toString() {
final String label = (mIconId == KeyboardIconsSet.ICON_UNDEFINED ? mLabel 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 final String output = (mCode == Constants.CODE_OUTPUT_TEXT ? mOutputText
: Constants.printableCode(mCode)); : Constants.printableCode(mCode));
if (StringUtils.codePointCount(label) == 1 && label.codePointAt(0) == mCode) { if (StringUtils.codePointCount(label) == 1 && label.codePointAt(0) == mCode) {

View File

@ -46,7 +46,7 @@ import java.util.HashMap;
* KeyboardTextsSet.java * KeyboardTextsSet.java
*/ */
public final class KeyboardTextsSet { 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 char BACKSLASH = '\\';
private static final int MAX_STRING_REFERENCE_INDIRECTION = 10; private static final int MAX_STRING_REFERENCE_INDIRECTION = 10;