Move some prefix strings to relevant classes

Change-Id: I7321ac7820d4eded5f16f2440ffb4f525315b3f4
main
Tadashi G. Takaoka 2014-01-31 16:27:49 +09:00
parent 0bae2ab460
commit 3b4eb03fa1
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 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;

View File

@ -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<String, int[]> sLanguageToCodesMap = 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 {
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;

View File

@ -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;

View File

@ -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) {

View File

@ -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;