Move some methods to StringUtils
Change-Id: I29d87fdd65ec879d1c0bdf7e7792a677687c1693main
parent
776d46a771
commit
639bf62e4f
|
@ -331,16 +331,16 @@ public class Key implements Comparable<Key> {
|
||||||
// code point nor as a surrogate pair.
|
// code point nor as a surrogate pair.
|
||||||
mLabel = new StringBuilder().appendCodePoint(code).toString();
|
mLabel = new StringBuilder().appendCodePoint(code).toString();
|
||||||
} else {
|
} else {
|
||||||
mLabel = KeySpecParser.toUpperCaseOfStringForLocale(style.getString(keyAttr,
|
mLabel = StringUtils.toUpperCaseOfStringForLocale(style.getString(keyAttr,
|
||||||
R.styleable.Keyboard_Key_keyLabel), needsToUpperCase, locale);
|
R.styleable.Keyboard_Key_keyLabel), needsToUpperCase, locale);
|
||||||
}
|
}
|
||||||
if ((mLabelFlags & LABEL_FLAGS_DISABLE_HINT_LABEL) != 0) {
|
if ((mLabelFlags & LABEL_FLAGS_DISABLE_HINT_LABEL) != 0) {
|
||||||
mHintLabel = null;
|
mHintLabel = null;
|
||||||
} else {
|
} else {
|
||||||
mHintLabel = KeySpecParser.toUpperCaseOfStringForLocale(style.getString(keyAttr,
|
mHintLabel = StringUtils.toUpperCaseOfStringForLocale(style.getString(keyAttr,
|
||||||
R.styleable.Keyboard_Key_keyHintLabel), needsToUpperCase, locale);
|
R.styleable.Keyboard_Key_keyHintLabel), needsToUpperCase, locale);
|
||||||
}
|
}
|
||||||
String outputText = KeySpecParser.toUpperCaseOfStringForLocale(style.getString(keyAttr,
|
String outputText = StringUtils.toUpperCaseOfStringForLocale(style.getString(keyAttr,
|
||||||
R.styleable.Keyboard_Key_keyOutputText), needsToUpperCase, locale);
|
R.styleable.Keyboard_Key_keyOutputText), needsToUpperCase, locale);
|
||||||
// Choose the first letter of the label as primary code if not specified.
|
// Choose the first letter of the label as primary code if not specified.
|
||||||
if (code == CODE_UNSPECIFIED && TextUtils.isEmpty(outputText)
|
if (code == CODE_UNSPECIFIED && TextUtils.isEmpty(outputText)
|
||||||
|
@ -367,9 +367,9 @@ public class Key implements Comparable<Key> {
|
||||||
mCode = CODE_OUTPUT_TEXT;
|
mCode = CODE_OUTPUT_TEXT;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
mCode = KeySpecParser.toUpperCaseOfCodeForLocale(code, needsToUpperCase, locale);
|
mCode = StringUtils.toUpperCaseOfCodeForLocale(code, needsToUpperCase, locale);
|
||||||
}
|
}
|
||||||
final int altCode = KeySpecParser.toUpperCaseOfCodeForLocale(
|
final int altCode = StringUtils.toUpperCaseOfCodeForLocale(
|
||||||
KeySpecParser.parseCode(style.getString(keyAttr,
|
KeySpecParser.parseCode(style.getString(keyAttr,
|
||||||
R.styleable.Keyboard_Key_altCode), params.mCodesSet, CODE_UNSPECIFIED),
|
R.styleable.Keyboard_Key_altCode), params.mCodesSet, CODE_UNSPECIFIED),
|
||||||
needsToUpperCase, locale);
|
needsToUpperCase, locale);
|
||||||
|
|
|
@ -21,14 +21,12 @@ import static com.android.inputmethod.latin.Constants.CODE_UNSPECIFIED;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.android.inputmethod.latin.Constants;
|
|
||||||
import com.android.inputmethod.latin.LatinImeLogger;
|
import com.android.inputmethod.latin.LatinImeLogger;
|
||||||
import com.android.inputmethod.latin.utils.CollectionUtils;
|
import com.android.inputmethod.latin.utils.CollectionUtils;
|
||||||
import com.android.inputmethod.latin.utils.StringUtils;
|
import com.android.inputmethod.latin.utils.StringUtils;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Locale;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The string parser of more keys specification.
|
* The string parser of more keys specification.
|
||||||
|
@ -482,20 +480,4 @@ public final class KeySpecParser {
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int toUpperCaseOfCodeForLocale(final int code, final boolean needsToUpperCase,
|
|
||||||
final Locale locale) {
|
|
||||||
if (!Constants.isLetterCode(code) || !needsToUpperCase) return code;
|
|
||||||
final String text = StringUtils.newSingleCodePointString(code);
|
|
||||||
final String casedText = KeySpecParser.toUpperCaseOfStringForLocale(
|
|
||||||
text, needsToUpperCase, locale);
|
|
||||||
return StringUtils.codePointCount(casedText) == 1
|
|
||||||
? casedText.codePointAt(0) : CODE_UNSPECIFIED;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String toUpperCaseOfStringForLocale(final String text,
|
|
||||||
final boolean needsToUpperCase, final Locale locale) {
|
|
||||||
if (text == null || !needsToUpperCase) return text;
|
|
||||||
return text.toUpperCase(locale);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,9 +31,9 @@ public final class MoreKeySpec {
|
||||||
|
|
||||||
public MoreKeySpec(final String moreKeySpec, boolean needsToUpperCase, final Locale locale,
|
public MoreKeySpec(final String moreKeySpec, boolean needsToUpperCase, final Locale locale,
|
||||||
final KeyboardCodesSet codesSet) {
|
final KeyboardCodesSet codesSet) {
|
||||||
mLabel = KeySpecParser.toUpperCaseOfStringForLocale(
|
mLabel = StringUtils.toUpperCaseOfStringForLocale(
|
||||||
KeySpecParser.getLabel(moreKeySpec), needsToUpperCase, locale);
|
KeySpecParser.getLabel(moreKeySpec), needsToUpperCase, locale);
|
||||||
final int code = KeySpecParser.toUpperCaseOfCodeForLocale(
|
final int code = StringUtils.toUpperCaseOfCodeForLocale(
|
||||||
KeySpecParser.getCode(moreKeySpec, codesSet), needsToUpperCase, locale);
|
KeySpecParser.getCode(moreKeySpec, codesSet), needsToUpperCase, locale);
|
||||||
if (code == Constants.CODE_UNSPECIFIED) {
|
if (code == Constants.CODE_UNSPECIFIED) {
|
||||||
// Some letter, for example German Eszett (U+00DF: "ß"), has multiple characters
|
// Some letter, for example German Eszett (U+00DF: "ß"), has multiple characters
|
||||||
|
@ -42,7 +42,7 @@ public final class MoreKeySpec {
|
||||||
mOutputText = mLabel;
|
mOutputText = mLabel;
|
||||||
} else {
|
} else {
|
||||||
mCode = code;
|
mCode = code;
|
||||||
mOutputText = KeySpecParser.toUpperCaseOfStringForLocale(
|
mOutputText = StringUtils.toUpperCaseOfStringForLocale(
|
||||||
KeySpecParser.getOutputText(moreKeySpec), needsToUpperCase, locale);
|
KeySpecParser.getOutputText(moreKeySpec), needsToUpperCase, locale);
|
||||||
}
|
}
|
||||||
mIconId = KeySpecParser.getIconId(moreKeySpec);
|
mIconId = KeySpecParser.getIconId(moreKeySpec);
|
||||||
|
|
|
@ -16,6 +16,8 @@
|
||||||
|
|
||||||
package com.android.inputmethod.latin.utils;
|
package com.android.inputmethod.latin.utils;
|
||||||
|
|
||||||
|
import static com.android.inputmethod.latin.Constants.CODE_UNSPECIFIED;
|
||||||
|
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import com.android.inputmethod.annotations.UsedForTesting;
|
import com.android.inputmethod.annotations.UsedForTesting;
|
||||||
|
@ -471,4 +473,20 @@ public final class StringUtils {
|
||||||
}
|
}
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String toUpperCaseOfStringForLocale(final String text,
|
||||||
|
final boolean needsToUpperCase, final Locale locale) {
|
||||||
|
if (text == null || !needsToUpperCase) return text;
|
||||||
|
return text.toUpperCase(locale);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int toUpperCaseOfCodeForLocale(final int code, final boolean needsToUpperCase,
|
||||||
|
final Locale locale) {
|
||||||
|
if (!Constants.isLetterCode(code) || !needsToUpperCase) return code;
|
||||||
|
final String text = newSingleCodePointString(code);
|
||||||
|
final String casedText = toUpperCaseOfStringForLocale(
|
||||||
|
text, needsToUpperCase, locale);
|
||||||
|
return codePointCount(casedText) == 1
|
||||||
|
? casedText.codePointAt(0) : CODE_UNSPECIFIED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue