aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--common/src/com/android/inputmethod/latin/common/InputPointers.java (renamed from java/src/com/android/inputmethod/latin/InputPointers.java)38
-rw-r--r--common/src/com/android/inputmethod/latin/common/ResizableIntArray.java (renamed from java/src/com/android/inputmethod/latin/utils/ResizableIntArray.java)2
-rw-r--r--common/src/com/android/inputmethod/latin/common/StringUtils.java (renamed from java/src/com/android/inputmethod/latin/utils/StringUtils.java)304
-rw-r--r--java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java2
-rw-r--r--java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java43
-rw-r--r--java/src/com/android/inputmethod/event/Event.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/Key.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/MainKeyboardView.java17
-rw-r--r--java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/PointerTracker.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/BatchInputArbiter.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/CodesArrayParser.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/DrawingHandler.java12
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/GestureStrokeDrawingPoints.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/GestureStrokeRecognitionPoints.java4
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/GestureTrailDrawingPoints.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java7
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java2
-rw-r--r--java/src/com/android/inputmethod/keyboard/internal/MoreKeySpec.java2
-rw-r--r--java/src/com/android/inputmethod/latin/BinaryDictionary.java3
-rw-r--r--java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java2
-rw-r--r--java/src/com/android/inputmethod/latin/InputAttributes.java2
-rw-r--r--java/src/com/android/inputmethod/latin/LastComposedWord.java1
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java1
-rw-r--r--java/src/com/android/inputmethod/latin/NgramContext.java2
-rw-r--r--java/src/com/android/inputmethod/latin/PunctuationSuggestions.java2
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputConnection.java2
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java2
-rw-r--r--java/src/com/android/inputmethod/latin/SuggestedWords.java2
-rw-r--r--java/src/com/android/inputmethod/latin/WordComposer.java3
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java4
-rw-r--r--java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java2
-rw-r--r--java/src/com/android/inputmethod/latin/makedict/WordProperty.java2
-rw-r--r--java/src/com/android/inputmethod/latin/settings/AppearanceSettingsFragment.java8
-rw-r--r--java/src/com/android/inputmethod/latin/settings/Settings.java6
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SettingsValues.java8
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java2
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerSession.java7
-rw-r--r--java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java2
-rw-r--r--java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java6
-rw-r--r--java/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtils.java1
-rw-r--r--java/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtils.java1
-rw-r--r--java/src/com/android/inputmethod/latin/utils/CapsModeUtils.java1
-rw-r--r--java/src/com/android/inputmethod/latin/utils/DistracterFilterCheckingExactMatchesAndSuggestions.java1
-rw-r--r--java/src/com/android/inputmethod/latin/utils/RecapitalizeStatus.java2
-rw-r--r--java/src/com/android/inputmethod/latin/utils/SpannableStringUtils.java55
-rw-r--r--java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java27
-rw-r--r--java/src/com/android/inputmethod/latin/utils/WordInputEventForPersonalization.java1
50 files changed, 345 insertions, 266 deletions
diff --git a/java/src/com/android/inputmethod/latin/InputPointers.java b/common/src/com/android/inputmethod/latin/common/InputPointers.java
index d57a881c0..40131aca4 100644
--- a/java/src/com/android/inputmethod/latin/InputPointers.java
+++ b/common/src/com/android/inputmethod/latin/common/InputPointers.java
@@ -14,18 +14,12 @@
* limitations under the License.
*/
-package com.android.inputmethod.latin;
-
-import android.util.Log;
-import android.util.SparseIntArray;
+package com.android.inputmethod.latin.common;
import com.android.inputmethod.annotations.UsedForTesting;
-import com.android.inputmethod.latin.define.DebugFlags;
-import com.android.inputmethod.latin.utils.ResizableIntArray;
// TODO: This class is not thread-safe.
public final class InputPointers {
- private static final String TAG = InputPointers.class.getSimpleName();
private static final boolean DEBUG_TIME = false;
private final int mDefaultCapacity;
@@ -61,14 +55,14 @@ public final class InputPointers {
mXCoordinates.addAt(index, x);
mYCoordinates.addAt(index, y);
mPointerIds.addAt(index, pointerId);
- if (DebugFlags.DEBUG_ENABLED || DEBUG_TIME) {
+ if (DEBUG_TIME) {
fillWithLastTimeUntil(index);
}
mTimes.addAt(index, time);
}
@UsedForTesting
- void addPointer(int x, int y, int pointerId, int time) {
+ public void addPointer(int x, int y, int pointerId, int time) {
mXCoordinates.add(x);
mYCoordinates.add(y);
mPointerIds.add(pointerId);
@@ -152,11 +146,6 @@ public final class InputPointers {
* the sequence.
*/
public int[] getTimes() {
- if (DebugFlags.DEBUG_ENABLED || DEBUG_TIME) {
- if (!isValidTimeStamps()) {
- throw new RuntimeException("Time stamps are invalid.");
- }
- }
return mTimes.getPrimitiveArray();
}
@@ -165,25 +154,4 @@ public final class InputPointers {
return "size=" + getPointerSize() + " id=" + mPointerIds + " time=" + mTimes
+ " x=" + mXCoordinates + " y=" + mYCoordinates;
}
-
- private boolean isValidTimeStamps() {
- final int[] times = mTimes.getPrimitiveArray();
- final int[] pointerIds = mPointerIds.getPrimitiveArray();
- final SparseIntArray lastTimeOfPointers = new SparseIntArray();
- final int size = getPointerSize();
- for (int i = 0; i < size; ++i) {
- final int pointerId = pointerIds[i];
- final int time = times[i];
- final int lastTime = lastTimeOfPointers.get(pointerId, time);
- if (time < lastTime) {
- // dump
- for (int j = 0; j < size; ++j) {
- Log.d(TAG, "--- (" + j + ") " + times[j]);
- }
- return false;
- }
- lastTimeOfPointers.put(pointerId, time);
- }
- return true;
- }
}
diff --git a/java/src/com/android/inputmethod/latin/utils/ResizableIntArray.java b/common/src/com/android/inputmethod/latin/common/ResizableIntArray.java
index 64c9e2cff..ea23d8a33 100644
--- a/java/src/com/android/inputmethod/latin/utils/ResizableIntArray.java
+++ b/common/src/com/android/inputmethod/latin/common/ResizableIntArray.java
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-package com.android.inputmethod.latin.utils;
+package com.android.inputmethod.latin.common;
import java.util.Arrays;
diff --git a/java/src/com/android/inputmethod/latin/utils/StringUtils.java b/common/src/com/android/inputmethod/latin/common/StringUtils.java
index f96ed0468..be7260308 100644
--- a/java/src/com/android/inputmethod/latin/utils/StringUtils.java
+++ b/common/src/com/android/inputmethod/latin/common/StringUtils.java
@@ -14,25 +14,23 @@
* limitations under the License.
*/
-package com.android.inputmethod.latin.utils;
-
-import android.text.Spanned;
-import android.text.TextUtils;
+package com.android.inputmethod.latin.common;
import com.android.inputmethod.annotations.UsedForTesting;
-import com.android.inputmethod.latin.common.Constants;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Locale;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
public final class StringUtils {
public static final int CAPITALIZE_NONE = 0; // No caps, or mixed case
public static final int CAPITALIZE_FIRST = 1; // First only
public static final int CAPITALIZE_ALL = 2; // All caps
+ @Nonnull
private static final String EMPTY_STRING = "";
private static final char CHAR_LINE_FEED = 0X000A;
@@ -47,12 +45,77 @@ public final class StringUtils {
// This utility class is not publicly instantiable.
}
- public static int codePointCount(final CharSequence text) {
- if (TextUtils.isEmpty(text)) return 0;
+ // Taken from android.text.TextUtils. We are extensively using this method in many places,
+ // some of which don't have the android libraries available.
+ /**
+ * Returns true if the string is null or 0-length.
+ * @param str the string to be examined
+ * @return true if str is null or zero length
+ */
+ public static boolean isEmpty(@Nullable final CharSequence str) {
+ return (str == null || str.length() == 0);
+ }
+
+ // Taken from android.text.TextUtils to cut the dependency to the Android framework.
+ /**
+ * Returns a string containing the tokens joined by delimiters.
+ * @param delimiter the delimiter
+ * @param tokens an array objects to be joined. Strings will be formed from
+ * the objects by calling object.toString().
+ */
+ @Nonnull
+ public static String join(@Nonnull final CharSequence delimiter,
+ @Nonnull final Iterable<?> tokens) {
+ final StringBuilder sb = new StringBuilder();
+ boolean firstTime = true;
+ for (final Object token: tokens) {
+ if (firstTime) {
+ firstTime = false;
+ } else {
+ sb.append(delimiter);
+ }
+ sb.append(token);
+ }
+ return sb.toString();
+ }
+
+ // Taken from android.text.TextUtils to cut the dependency to the Android framework.
+ /**
+ * Returns true if a and b are equal, including if they are both null.
+ * <p><i>Note: In platform versions 1.1 and earlier, this method only worked well if
+ * both the arguments were instances of String.</i></p>
+ * @param a first CharSequence to check
+ * @param b second CharSequence to check
+ * @return true if a and b are equal
+ */
+ public static boolean equals(@Nullable final CharSequence a, @Nullable final CharSequence b) {
+ if (a == b) {
+ return true;
+ }
+ final int length;
+ if (a != null && b != null && (length = a.length()) == b.length()) {
+ if (a instanceof String && b instanceof String) {
+ return a.equals(b);
+ }
+ for (int i = 0; i < length; i++) {
+ if (a.charAt(i) != b.charAt(i)) {
+ return false;
+ }
+ }
+ return true;
+ }
+ return false;
+ }
+
+ public static int codePointCount(@Nullable final CharSequence text) {
+ if (isEmpty(text)) {
+ return 0;
+ }
return Character.codePointCount(text, 0, text.length());
}
- public static String newSingleCodePointString(int codePoint) {
+ @Nonnull
+ public static String newSingleCodePointString(final int codePoint) {
if (Character.charCount(codePoint) == 1) {
// Optimization: avoid creating a temporary array for characters that are
// represented by a single char value
@@ -62,9 +125,12 @@ public final class StringUtils {
return new String(Character.toChars(codePoint));
}
- public static boolean containsInArray(final String text, final String[] array) {
+ public static boolean containsInArray(@Nonnull final String text,
+ @Nonnull final String[] array) {
for (final String element : array) {
- if (text.equals(element)) return true;
+ if (text.equals(element)) {
+ return true;
+ }
}
return false;
}
@@ -74,19 +140,21 @@ public final class StringUtils {
* Unlike CSV, Comma-Splittable Text has no escaping mechanism, so that the text can't contain
* a comma character in it.
*/
+ @Nonnull
private static final String SEPARATOR_FOR_COMMA_SPLITTABLE_TEXT = ",";
- public static boolean containsInCommaSplittableText(final String text,
- final String extraValues) {
- if (TextUtils.isEmpty(extraValues)) {
+ public static boolean containsInCommaSplittableText(@Nonnull final String text,
+ @Nullable final String extraValues) {
+ if (isEmpty(extraValues)) {
return false;
}
return containsInArray(text, extraValues.split(SEPARATOR_FOR_COMMA_SPLITTABLE_TEXT));
}
- public static String removeFromCommaSplittableTextIfExists(final String text,
- final String extraValues) {
- if (TextUtils.isEmpty(extraValues)) {
+ @Nonnull
+ public static String removeFromCommaSplittableTextIfExists(@Nonnull final String text,
+ @Nullable final String extraValues) {
+ if (isEmpty(extraValues)) {
return EMPTY_STRING;
}
final String[] elements = extraValues.split(SEPARATOR_FOR_COMMA_SPLITTABLE_TEXT);
@@ -99,7 +167,7 @@ public final class StringUtils {
result.add(element);
}
}
- return TextUtils.join(SEPARATOR_FOR_COMMA_SPLITTABLE_TEXT, result);
+ return join(SEPARATOR_FOR_COMMA_SPLITTABLE_TEXT, result);
}
/**
@@ -108,8 +176,10 @@ public final class StringUtils {
* This method will always keep the first occurrence of all strings at their position
* in the array, removing the subsequent ones.
*/
- public static void removeDupes(final ArrayList<String> suggestions) {
- if (suggestions.size() < 2) return;
+ public static void removeDupes(@Nonnull final ArrayList<String> suggestions) {
+ if (suggestions.size() < 2) {
+ return;
+ }
int i = 1;
// Don't cache suggestions.size(), since we may be removing items
while (i < suggestions.size()) {
@@ -117,7 +187,7 @@ public final class StringUtils {
// Compare each suggestion with each previous suggestion
for (int j = 0; j < i; j++) {
final String previous = suggestions.get(j);
- if (TextUtils.equals(cur, previous)) {
+ if (equals(cur, previous)) {
suggestions.remove(i);
i--;
break;
@@ -127,7 +197,9 @@ public final class StringUtils {
}
}
- public static String capitalizeFirstCodePoint(final String s, final Locale locale) {
+ @Nonnull
+ public static String capitalizeFirstCodePoint(@Nonnull final String s,
+ @Nonnull final Locale locale) {
if (s.length() <= 1) {
return s.toUpperCase(locale);
}
@@ -137,7 +209,9 @@ public final class StringUtils {
return s.substring(0, cutoff).toUpperCase(locale) + s.substring(cutoff);
}
- public static String capitalizeFirstAndDowncaseRest(final String s, final Locale locale) {
+ @Nonnull
+ public static String capitalizeFirstAndDowncaseRest(@Nonnull final String s,
+ @Nonnull final Locale locale) {
if (s.length() <= 1) {
return s.toUpperCase(locale);
}
@@ -153,12 +227,14 @@ public final class StringUtils {
return s.substring(0, cutoff).toUpperCase(locale) + s.substring(cutoff).toLowerCase(locale);
}
- private static final int[] EMPTY_CODEPOINTS = {};
-
- public static int[] toCodePointArray(final CharSequence charSequence) {
+ @Nonnull
+ public static int[] toCodePointArray(@Nonnull final CharSequence charSequence) {
return toCodePointArray(charSequence, 0, charSequence.length());
}
+ @Nonnull
+ private static final int[] EMPTY_CODEPOINTS = {};
+
/**
* Converts a range of a string to an array of code points.
* @param charSequence the source string.
@@ -166,7 +242,8 @@ public final class StringUtils {
* @param endIndex the end index inside the string in java chars, exclusive.
* @return a new array of code points. At most endIndex - startIndex, but possibly less.
*/
- public static int[] toCodePointArray(final CharSequence charSequence,
+ @Nonnull
+ public static int[] toCodePointArray(@Nonnull final CharSequence charSequence,
final int startIndex, final int endIndex) {
final int length = charSequence.length();
if (length <= 0) {
@@ -197,8 +274,8 @@ public final class StringUtils {
* @param downCase if this is true, code points will be downcased before being copied.
* @return the number of copied code points.
*/
- public static int copyCodePointsAndReturnCodePointCount(final int[] destination,
- final CharSequence charSequence, final int startIndex, final int endIndex,
+ public static int copyCodePointsAndReturnCodePointCount(@Nonnull final int[] destination,
+ @Nonnull final CharSequence charSequence, final int startIndex, final int endIndex,
final boolean downCase) {
int destIndex = 0;
for (int index = startIndex; index < endIndex;
@@ -212,7 +289,8 @@ public final class StringUtils {
return destIndex;
}
- public static int[] toSortedCodePointArray(final String string) {
+ @Nonnull
+ public static int[] toSortedCodePointArray(@Nonnull final String string) {
final int[] codePoints = toCodePointArray(string);
Arrays.sort(codePoints);
return codePoints;
@@ -225,7 +303,9 @@ public final class StringUtils {
* shorter than the array length.
* @return a string constructed from the code point array.
*/
- public static String getStringFromNullTerminatedCodePointArray(final int[] codePoints) {
+ @Nonnull
+ public static String getStringFromNullTerminatedCodePointArray(
+ @Nonnull final int[] codePoints) {
int stringLength = codePoints.length;
for (int i = 0; i < codePoints.length; i++) {
if (codePoints[i] == 0) {
@@ -237,7 +317,7 @@ public final class StringUtils {
}
// This method assumes the text is not null. For the empty string, it returns CAPITALIZE_NONE.
- public static int getCapitalizationType(final String text) {
+ public static int getCapitalizationType(@Nonnull final String text) {
// If the first char is not uppercase, then the word is either all lower case or
// camel case, and in either case we return CAPITALIZE_NONE.
final int len = text.length();
@@ -273,7 +353,7 @@ public final class StringUtils {
return (letterCount == capsCount ? CAPITALIZE_ALL : CAPITALIZE_NONE);
}
- public static boolean isIdenticalAfterUpcase(final String text) {
+ public static boolean isIdenticalAfterUpcase(@Nonnull final String text) {
final int length = text.length();
int i = 0;
while (i < length) {
@@ -286,7 +366,7 @@ public final class StringUtils {
return true;
}
- public static boolean isIdenticalAfterDowncase(final String text) {
+ public static boolean isIdenticalAfterDowncase(@Nonnull final String text) {
final int length = text.length();
int i = 0;
while (i < length) {
@@ -299,8 +379,8 @@ public final class StringUtils {
return true;
}
- public static boolean isIdenticalAfterCapitalizeEachWord(final String text,
- final int[] sortedSeparators) {
+ public static boolean isIdenticalAfterCapitalizeEachWord(@Nonnull final String text,
+ @Nonnull final int[] sortedSeparators) {
boolean needsCapsNext = true;
final int len = text.length();
for (int i = 0; i < len; i = text.offsetByCodePoints(i, 1)) {
@@ -319,8 +399,9 @@ public final class StringUtils {
// TODO: like capitalizeFirst*, this does not work perfectly for Dutch because of the IJ digraph
// which should be capitalized together in *some* cases.
- public static String capitalizeEachWord(final String text, final int[] sortedSeparators,
- final Locale locale) {
+ @Nonnull
+ public static String capitalizeEachWord(@Nonnull final String text,
+ @Nonnull final int[] sortedSeparators, @Nonnull final Locale locale) {
final StringBuilder builder = new StringBuilder();
boolean needsCapsNext = true;
final int len = text.length();
@@ -354,9 +435,11 @@ public final class StringUtils {
* TODO: This will return that "abc./def" and ".abc/def" look like URLs to keep down the
* code complexity, but ideally it should not. It's acceptable for now.
*/
- public static boolean lastPartLooksLikeURL(final CharSequence text) {
+ public static boolean lastPartLooksLikeURL(@Nonnull final CharSequence text) {
int i = text.length();
- if (0 == i) return false;
+ if (0 == i) {
+ return false;
+ }
int wCount = 0;
int slashCount = 0;
boolean hasSlash = false;
@@ -393,11 +476,17 @@ public final class StringUtils {
}
// End of the text run.
// If it starts with www and includes a period, then it looks like a URL.
- if (wCount >= 3 && hasPeriod) return true;
+ if (wCount >= 3 && hasPeriod) {
+ return true;
+ }
// If it starts with a slash, and the code point before is whitespace, it looks like an URL.
- if (1 == slashCount && (0 == i || Character.isWhitespace(codePoint))) return true;
+ if (1 == slashCount && (0 == i || Character.isWhitespace(codePoint))) {
+ return true;
+ }
// If it has both a period and a slash, it looks like an URL.
- if (hasPeriod && hasSlash) return true;
+ if (hasPeriod && hasSlash) {
+ return true;
+ }
// Otherwise, it doesn't look like an URL.
return false;
}
@@ -418,18 +507,24 @@ public final class StringUtils {
* @param text the text to examine.
* @return whether we're inside a double quote.
*/
- public static boolean isInsideDoubleQuoteOrAfterDigit(final CharSequence text) {
+ public static boolean isInsideDoubleQuoteOrAfterDigit(@Nonnull final CharSequence text) {
int i = text.length();
- if (0 == i) return false;
+ if (0 == i) {
+ return false;
+ }
int codePoint = Character.codePointBefore(text, i);
- if (Character.isDigit(codePoint)) return true;
+ if (Character.isDigit(codePoint)) {
+ return true;
+ }
int prevCodePoint = 0;
while (i > 0) {
codePoint = Character.codePointBefore(text, i);
if (Constants.CODE_DOUBLE_QUOTE == codePoint) {
// If we see a double quote followed by whitespace, then that
// was a closing quote.
- if (Character.isWhitespace(prevCodePoint)) return false;
+ if (Character.isWhitespace(prevCodePoint)) {
+ return false;
+ }
}
if (Character.isWhitespace(codePoint) && Constants.CODE_DOUBLE_QUOTE == prevCodePoint) {
// If we see a double quote preceded by whitespace, then that
@@ -444,7 +539,7 @@ public final class StringUtils {
return Constants.CODE_DOUBLE_QUOTE == codePoint;
}
- public static boolean isEmptyStringOrWhiteSpaces(final String s) {
+ public static boolean isEmptyStringOrWhiteSpaces(@Nonnull final String s) {
final int N = codePointCount(s);
for (int i = 0; i < N; ++i) {
if (!Character.isWhitespace(s.codePointAt(i))) {
@@ -455,12 +550,13 @@ public final class StringUtils {
}
@UsedForTesting
- public static String byteArrayToHexString(final byte[] bytes) {
+ @Nonnull
+ public static String byteArrayToHexString(@Nullable final byte[] bytes) {
if (bytes == null || bytes.length == 0) {
return EMPTY_STRING;
}
final StringBuilder sb = new StringBuilder();
- for (byte b : bytes) {
+ for (final byte b : bytes) {
sb.append(String.format("%02x", b & 0xff));
}
return sb.toString();
@@ -470,8 +566,9 @@ public final class StringUtils {
* Convert hex string to byte array. The string length must be an even number.
*/
@UsedForTesting
- public static byte[] hexStringToByteArray(final String hexString) {
- if (TextUtils.isEmpty(hexString)) {
+ @Nullable
+ public static byte[] hexStringToByteArray(@Nullable final String hexString) {
+ if (isEmpty(hexString)) {
return null;
}
final int N = hexString.length();
@@ -487,15 +584,20 @@ public final class StringUtils {
return bytes;
}
- public static String toUpperCaseOfStringForLocale(final String text,
- final boolean needsToUpperCase, final Locale locale) {
- if (text == null || !needsToUpperCase) return text;
+ @Nullable
+ public static String toUpperCaseOfStringForLocale(@Nullable final String text,
+ final boolean needsToUpperCase, @Nonnull 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;
+ @Nonnull final Locale locale) {
+ if (!Constants.isLetterCode(code) || !needsToUpperCase) {
+ return code;
+ }
final String text = newSingleCodePointString(code);
final String casedText = toUpperCaseOfStringForLocale(
text, needsToUpperCase, locale);
@@ -503,7 +605,7 @@ public final class StringUtils {
? casedText.codePointAt(0) : Constants.CODE_UNSPECIFIED;
}
- public static int getTrailingSingleQuotesCount(final CharSequence charSequence) {
+ public static int getTrailingSingleQuotesCount(@Nonnull final CharSequence charSequence) {
final int lastIndex = charSequence.length() - 1;
int i = lastIndex;
while (i >= 0 && charSequence.charAt(i) == Constants.CODE_SINGLE_QUOTE) {
@@ -512,72 +614,36 @@ public final class StringUtils {
return lastIndex - i;
}
- /**
- * Splits the given {@code charSequence} with at occurrences of the given {@code regex}.
- * <p>
- * This is equivalent to
- * {@code charSequence.toString().split(regex, preserveTrailingEmptySegments ? -1 : 0)}
- * except that the spans are preserved in the result array.
- * </p>
- * @param charSequence the character sequence to be split.
- * @param regex the regex pattern to be used as the separator.
- * @param preserveTrailingEmptySegments {@code true} to preserve the trailing empty
- * segments. Otherwise, trailing empty segments will be removed before being returned.
- * @return the array which contains the result. All the spans in the <code>charSequence</code>
- * is preserved.
- */
- @UsedForTesting
- public static CharSequence[] split(final CharSequence charSequence, final String regex,
- final boolean preserveTrailingEmptySegments) {
- // A short-cut for non-spanned strings.
- if (!(charSequence instanceof Spanned)) {
- // -1 means that trailing empty segments will be preserved.
- return charSequence.toString().split(regex, preserveTrailingEmptySegments ? -1 : 0);
- }
-
- // Hereafter, emulate String.split for CharSequence.
- final ArrayList<CharSequence> sequences = new ArrayList<>();
- final Matcher matcher = Pattern.compile(regex).matcher(charSequence);
- int nextStart = 0;
- boolean matched = false;
- while (matcher.find()) {
- sequences.add(charSequence.subSequence(nextStart, matcher.start()));
- nextStart = matcher.end();
- matched = true;
- }
- if (!matched) {
- // never matched. preserveTrailingEmptySegments is ignored in this case.
- return new CharSequence[] { charSequence };
- }
- sequences.add(charSequence.subSequence(nextStart, charSequence.length()));
- if (!preserveTrailingEmptySegments) {
- for (int i = sequences.size() - 1; i >= 0; --i) {
- if (!TextUtils.isEmpty(sequences.get(i))) {
- break;
- }
- sequences.remove(i);
- }
- }
- return sequences.toArray(new CharSequence[sequences.size()]);
- }
-
@UsedForTesting
public static class Stringizer<E> {
- public String stringize(final E element) {
- return element != null ? element.toString() : "null";
+ @Nonnull
+ private static final String[] EMPTY_STRING_ARRAY = new String[0];
+
+ @UsedForTesting
+ @Nonnull
+ public String stringize(@Nullable final E element) {
+ if (element == null) {
+ return "null";
+ }
+ return element.toString();
}
@UsedForTesting
- public final String join(final E[] array) {
+ @Nonnull
+ public final String join(@Nullable final E[] array) {
return joinStringArray(toStringArray(array), null /* delimiter */);
}
@UsedForTesting
- public final String join(final E[] array, final String delimiter) {
+ public final String join(@Nullable final E[] array, @Nullable final String delimiter) {
return joinStringArray(toStringArray(array), delimiter);
}
- protected String[] toStringArray(final E[] array) {
+ @Nonnull
+ protected String[] toStringArray(@Nullable final E[] array) {
+ if (array == null) {
+ return EMPTY_STRING_ARRAY;
+ }
final String[] stringArray = new String[array.length];
for (int index = 0; index < array.length; index++) {
stringArray[index] = stringize(array[index]);
@@ -585,10 +651,9 @@ public final class StringUtils {
return stringArray;
}
- protected String joinStringArray(final String[] stringArray, final String delimiter) {
- if (stringArray == null) {
- return "null";
- }
+ @Nonnull
+ protected String joinStringArray(@Nonnull final String[] stringArray,
+ @Nullable final String delimiter) {
if (delimiter == null) {
return Arrays.toString(stringArray);
}
@@ -606,9 +671,8 @@ public final class StringUtils {
* @param text the text to be examined.
* @return {@code true} if the last composed word contains line-breaking separator.
*/
- @UsedForTesting
- public static boolean hasLineBreakCharacter(final String text) {
- if (TextUtils.isEmpty(text)) {
+ public static boolean hasLineBreakCharacter(@Nullable final String text) {
+ if (isEmpty(text)) {
return false;
}
for (int i = text.length() - 1; i >= 0; --i) {
diff --git a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
index 9f7caa47e..bbda9f8e2 100644
--- a/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
+++ b/java/src/com/android/inputmethod/accessibility/KeyCodeDescriptionMapper.java
@@ -28,7 +28,7 @@ import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.common.Constants;
-import com.android.inputmethod.latin.utils.StringUtils;
+import com.android.inputmethod.latin.common.StringUtils;
import java.util.Locale;
diff --git a/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java b/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java
index 1fb597ba6..b78c357ab 100644
--- a/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java
+++ b/java/src/com/android/inputmethod/compat/UserDictionaryCompatUtils.java
@@ -16,42 +16,33 @@
package com.android.inputmethod.compat;
+import android.annotation.TargetApi;
import android.content.Context;
-import android.provider.UserDictionary.Words;
+import android.os.Build;
+import android.provider.UserDictionary;
-import java.lang.reflect.Method;
import java.util.Locale;
public final class UserDictionaryCompatUtils {
- // UserDictionary.Words#addWord(Context, String, int, String, Locale) was introduced
- // in API level 16 (Build.VERSION_CODES.JELLY_BEAN).
- private static final Method METHOD_addWord = CompatUtils.getMethod(Words.class, "addWord",
- Context.class, String.class, int.class, String.class, Locale.class);
-
@SuppressWarnings("deprecation")
public static void addWord(final Context context, final String word,
final int freq, final String shortcut, final Locale locale) {
- if (hasNewerAddWord()) {
- CompatUtils.invoke(Words.class, null, METHOD_addWord, context, word, freq, shortcut,
- locale);
- } else {
- // Fall back to the pre-JellyBean method.
- final int localeType;
- if (null == locale) {
- localeType = Words.LOCALE_TYPE_ALL;
- } else {
- final Locale currentLocale = context.getResources().getConfiguration().locale;
- if (locale.equals(currentLocale)) {
- localeType = Words.LOCALE_TYPE_CURRENT;
- } else {
- localeType = Words.LOCALE_TYPE_ALL;
- }
- }
- Words.addWord(context, word, freq, localeType);
+ if (BuildCompatUtils.EFFECTIVE_SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
+ addWordWithShortcut(context, word, freq, shortcut, locale);
+ return;
}
+ // Fall back to the pre-JellyBean method.
+ final Locale currentLocale = context.getResources().getConfiguration().locale;
+ final int localeType = currentLocale.equals(locale)
+ ? UserDictionary.Words.LOCALE_TYPE_CURRENT : UserDictionary.Words.LOCALE_TYPE_ALL;
+ UserDictionary.Words.addWord(context, word, freq, localeType);
}
- public static final boolean hasNewerAddWord() {
- return null != METHOD_addWord;
+ // {@link UserDictionary.Words#addWord(Context,String,int,String,Locale)} was introduced
+ // in API level 16 (Build.VERSION_CODES.JELLY_BEAN).
+ @TargetApi(Build.VERSION_CODES.JELLY_BEAN)
+ private static void addWordWithShortcut(final Context context, final String word,
+ final int freq, final String shortcut, final Locale locale) {
+ UserDictionary.Words.addWord(context, word, freq, shortcut, locale);
}
}
diff --git a/java/src/com/android/inputmethod/event/Event.java b/java/src/com/android/inputmethod/event/Event.java
index 92bcda455..a1226dc93 100644
--- a/java/src/com/android/inputmethod/event/Event.java
+++ b/java/src/com/android/inputmethod/event/Event.java
@@ -19,7 +19,7 @@ package com.android.inputmethod.event;
import com.android.inputmethod.annotations.ExternallyReferenced;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.common.Constants;
-import com.android.inputmethod.latin.utils.StringUtils;
+import com.android.inputmethod.latin.common.StringUtils;
import javax.annotation.Nonnull;
diff --git a/java/src/com/android/inputmethod/keyboard/Key.java b/java/src/com/android/inputmethod/keyboard/Key.java
index 04a0f1e13..6b2094b9e 100644
--- a/java/src/com/android/inputmethod/keyboard/Key.java
+++ b/java/src/com/android/inputmethod/keyboard/Key.java
@@ -38,7 +38,7 @@ import com.android.inputmethod.keyboard.internal.KeyboardRow;
import com.android.inputmethod.keyboard.internal.MoreKeySpec;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.common.Constants;
-import com.android.inputmethod.latin.utils.StringUtils;
+import com.android.inputmethod.latin.common.StringUtils;
import java.util.Arrays;
import java.util.Locale;
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java b/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java
index ac66f7c6a..cdd632bc8 100644
--- a/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java
+++ b/java/src/com/android/inputmethod/keyboard/KeyboardActionListener.java
@@ -16,8 +16,8 @@
package com.android.inputmethod.keyboard;
-import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.InputPointers;
public interface KeyboardActionListener {
/**
diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
index e66523be0..6dbd94740 100644
--- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
+++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java
@@ -56,9 +56,9 @@ import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodSubtype;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.settings.DebugSettings;
import com.android.inputmethod.latin.utils.CoordinateUtils;
-import com.android.inputmethod.latin.utils.StringUtils;
import com.android.inputmethod.latin.utils.TypefaceUtils;
import java.util.Locale;
@@ -451,13 +451,6 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
windowContentView.addView(mDrawingPreviewPlacerView);
}
- // Implements {@link DrawingHandler.Callbacks} method.
- @Override
- public void dismissAllKeyPreviews() {
- mKeyPreviewChoreographer.dismissAllKeyPreviews();
- PointerTracker.setReleasedKeyGraphicsToAllKeys();
- }
-
@Override
public void showKeyPreview(final Key key) {
// If the key is invalid or has no key preview, we must not show key preview.
@@ -673,6 +666,12 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
@Override
public void onShowMoreKeysPanel(final MoreKeysPanel panel) {
locatePreviewPlacerView();
+ // Dismiss another {@link MoreKeysPanel} that may be being showed.
+ onDismissMoreKeysPanel();
+ // Dismiss all key previews that may be being showed.
+ PointerTracker.setReleasedKeyGraphicsToAllKeys();
+ // Dismiss sliding key input preview that may be being showed.
+ dismissSlidingKeyInputPreview();
panel.showInParent(mDrawingPreviewPlacerView);
mMoreKeysPanel = panel;
}
@@ -740,7 +739,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
public void cancelAllOngoingEvents() {
mKeyTimerHandler.cancelAllMessages();
mDrawingHandler.cancelAllMessages();
- dismissAllKeyPreviews();
+ PointerTracker.setReleasedKeyGraphicsToAllKeys();
dismissGestureFloatingPreviewText();
dismissSlidingKeyInputPreview();
PointerTracker.dismissAllMoreKeysPanels();
diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java
index abcfff8a6..f0de86ff9 100644
--- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java
+++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboard.java
@@ -24,7 +24,7 @@ import com.android.inputmethod.keyboard.internal.KeyboardBuilder;
import com.android.inputmethod.keyboard.internal.KeyboardParams;
import com.android.inputmethod.keyboard.internal.MoreKeySpec;
import com.android.inputmethod.latin.R;
-import com.android.inputmethod.latin.utils.StringUtils;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.utils.TypefaceUtils;
public final class MoreKeysKeyboard extends Keyboard {
diff --git a/java/src/com/android/inputmethod/keyboard/PointerTracker.java b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
index fe6270fb5..5a540ff17 100644
--- a/java/src/com/android/inputmethod/keyboard/PointerTracker.java
+++ b/java/src/com/android/inputmethod/keyboard/PointerTracker.java
@@ -31,9 +31,9 @@ import com.android.inputmethod.keyboard.internal.GestureStrokeDrawingPoints;
import com.android.inputmethod.keyboard.internal.GestureStrokeRecognitionParams;
import com.android.inputmethod.keyboard.internal.PointerTrackerQueue;
import com.android.inputmethod.keyboard.internal.TypingTimeRecorder;
-import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.InputPointers;
import com.android.inputmethod.latin.define.DebugFlags;
import com.android.inputmethod.latin.settings.Settings;
import com.android.inputmethod.latin.utils.CoordinateUtils;
diff --git a/java/src/com/android/inputmethod/keyboard/internal/BatchInputArbiter.java b/java/src/com/android/inputmethod/keyboard/internal/BatchInputArbiter.java
index efb365e42..77d0e7a90 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/BatchInputArbiter.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/BatchInputArbiter.java
@@ -16,8 +16,8 @@
package com.android.inputmethod.keyboard.internal;
-import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.InputPointers;
/**
* This class arbitrates batch input.
diff --git a/java/src/com/android/inputmethod/keyboard/internal/CodesArrayParser.java b/java/src/com/android/inputmethod/keyboard/internal/CodesArrayParser.java
index 5797b7efd..2e2ed52dd 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/CodesArrayParser.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/CodesArrayParser.java
@@ -17,7 +17,7 @@
package com.android.inputmethod.keyboard.internal;
import com.android.inputmethod.latin.common.Constants;
-import com.android.inputmethod.latin.utils.StringUtils;
+import com.android.inputmethod.latin.common.StringUtils;
import android.text.TextUtils;
diff --git a/java/src/com/android/inputmethod/keyboard/internal/DrawingHandler.java b/java/src/com/android/inputmethod/keyboard/internal/DrawingHandler.java
index 1a55359f5..6513485de 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/DrawingHandler.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/DrawingHandler.java
@@ -29,7 +29,6 @@ import javax.annotation.Nonnull;
public class DrawingHandler extends LeakGuardHandlerWrapper<Callbacks> {
public interface Callbacks {
public void dismissKeyPreviewWithoutDelay(Key key);
- public void dismissAllKeyPreviews();
public void showGestureFloatingPreviewText(SuggestedWords suggestedWords);
}
@@ -60,20 +59,11 @@ public class DrawingHandler extends LeakGuardHandlerWrapper<Callbacks> {
sendMessageDelayed(obtainMessage(MSG_DISMISS_KEY_PREVIEW, key), delay);
}
- private void cancelAllDismissKeyPreviews() {
- removeMessages(MSG_DISMISS_KEY_PREVIEW);
- final Callbacks callbacks = getOwnerInstance();
- if (callbacks == null) {
- return;
- }
- callbacks.dismissAllKeyPreviews();
- }
-
public void dismissGestureFloatingPreviewText(final long delay) {
sendMessageDelayed(obtainMessage(MSG_DISMISS_GESTURE_FLOATING_PREVIEW_TEXT), delay);
}
public void cancelAllMessages() {
- cancelAllDismissKeyPreviews();
+ removeMessages(MSG_DISMISS_KEY_PREVIEW);
}
}
diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeDrawingPoints.java b/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeDrawingPoints.java
index 7d09e9d2f..07ef00924 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeDrawingPoints.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeDrawingPoints.java
@@ -16,7 +16,7 @@
package com.android.inputmethod.keyboard.internal;
-import com.android.inputmethod.latin.utils.ResizableIntArray;
+import com.android.inputmethod.latin.common.ResizableIntArray;
/**
* This class holds drawing points to represent a gesture stroke on the screen.
diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeRecognitionPoints.java b/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeRecognitionPoints.java
index 99ec18f4d..3e901114a 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeRecognitionPoints.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/GestureStrokeRecognitionPoints.java
@@ -18,9 +18,9 @@ package com.android.inputmethod.keyboard.internal;
import android.util.Log;
-import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.common.Constants;
-import com.android.inputmethod.latin.utils.ResizableIntArray;
+import com.android.inputmethod.latin.common.InputPointers;
+import com.android.inputmethod.latin.common.ResizableIntArray;
/**
* This class holds event points to recognize a gesture stroke.
diff --git a/java/src/com/android/inputmethod/keyboard/internal/GestureTrailDrawingPoints.java b/java/src/com/android/inputmethod/keyboard/internal/GestureTrailDrawingPoints.java
index 67683e247..4d998e443 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/GestureTrailDrawingPoints.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/GestureTrailDrawingPoints.java
@@ -24,7 +24,7 @@ import android.graphics.Rect;
import android.os.SystemClock;
import com.android.inputmethod.latin.common.Constants;
-import com.android.inputmethod.latin.utils.ResizableIntArray;
+import com.android.inputmethod.latin.common.ResizableIntArray;
/**
* This class holds drawing points to represent a gesture trail. The gesture trail may contain
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java b/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java
index ddb193ead..d3764877c 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyPreviewChoreographer.java
@@ -28,7 +28,6 @@ import com.android.inputmethod.latin.utils.ViewLayoutUtils;
import java.util.ArrayDeque;
import java.util.HashMap;
-import java.util.HashSet;
/**
* This class controls pop up key previews. This class decides:
@@ -69,12 +68,6 @@ public final class KeyPreviewChoreographer {
return mShowingKeyPreviewViews.containsKey(key);
}
- public void dismissAllKeyPreviews() {
- for (final Key key : new HashSet<>(mShowingKeyPreviewViews.keySet())) {
- dismissKeyPreview(key, false /* withAnimation */);
- }
- }
-
public void dismissKeyPreview(final Key key, final boolean withAnimation) {
if (key == null) {
return;
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java
index d33e53a61..63aab968b 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeySpecParser.java
@@ -20,7 +20,7 @@ import static com.android.inputmethod.latin.common.Constants.CODE_OUTPUT_TEXT;
import static com.android.inputmethod.latin.common.Constants.CODE_UNSPECIFIED;
import com.android.inputmethod.latin.common.Constants;
-import com.android.inputmethod.latin.utils.StringUtils;
+import com.android.inputmethod.latin.common.StringUtils;
/**
* The string parser of the key specification.
diff --git a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
index 6c75fb6c1..c739bf3e0 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/KeyboardBuilder.java
@@ -34,8 +34,8 @@ import com.android.inputmethod.keyboard.KeyboardId;
import com.android.inputmethod.keyboard.KeyboardTheme;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.utils.ResourceUtils;
-import com.android.inputmethod.latin.utils.StringUtils;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
import com.android.inputmethod.latin.utils.XmlParseUtils;
import com.android.inputmethod.latin.utils.XmlParseUtils.ParseException;
diff --git a/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpec.java b/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpec.java
index 4392dbcbd..a0bb406aa 100644
--- a/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpec.java
+++ b/java/src/com/android/inputmethod/keyboard/internal/MoreKeySpec.java
@@ -22,9 +22,9 @@ import android.util.SparseIntArray;
import com.android.inputmethod.compat.CharacterCompat;
import com.android.inputmethod.keyboard.Key;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.define.DebugFlags;
import com.android.inputmethod.latin.utils.CollectionUtils;
-import com.android.inputmethod.latin.utils.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
index 76459f817..8e9b5c6f6 100644
--- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java
@@ -24,6 +24,8 @@ import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.InputPointers;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.makedict.DictionaryHeader;
import com.android.inputmethod.latin.makedict.FormatSpec;
import com.android.inputmethod.latin.makedict.FormatSpec.DictionaryOptions;
@@ -33,7 +35,6 @@ import com.android.inputmethod.latin.settings.SettingsValuesForSuggestion;
import com.android.inputmethod.latin.utils.BinaryDictionaryUtils;
import com.android.inputmethod.latin.utils.FileUtils;
import com.android.inputmethod.latin.utils.JniUtils;
-import com.android.inputmethod.latin.utils.StringUtils;
import com.android.inputmethod.latin.utils.WordInputEventForPersonalization;
import java.io.File;
diff --git a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java
index 08e1983d4..59763c0fc 100644
--- a/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java
+++ b/java/src/com/android/inputmethod/latin/ContactsBinaryDictionary.java
@@ -30,9 +30,9 @@ import android.util.Log;
import com.android.inputmethod.annotations.ExternallyReferenced;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.personalization.AccountUtils;
import com.android.inputmethod.latin.utils.ExecutorUtils;
-import com.android.inputmethod.latin.utils.StringUtils;
import java.io.File;
import java.util.ArrayList;
diff --git a/java/src/com/android/inputmethod/latin/InputAttributes.java b/java/src/com/android/inputmethod/latin/InputAttributes.java
index 002222080..37effeead 100644
--- a/java/src/com/android/inputmethod/latin/InputAttributes.java
+++ b/java/src/com/android/inputmethod/latin/InputAttributes.java
@@ -24,8 +24,8 @@ import android.text.InputType;
import android.util.Log;
import android.view.inputmethod.EditorInfo;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.utils.InputTypeUtils;
-import com.android.inputmethod.latin.utils.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/java/src/com/android/inputmethod/latin/LastComposedWord.java b/java/src/com/android/inputmethod/latin/LastComposedWord.java
index c4c389411..9fcdb2229 100644
--- a/java/src/com/android/inputmethod/latin/LastComposedWord.java
+++ b/java/src/com/android/inputmethod/latin/LastComposedWord.java
@@ -20,6 +20,7 @@ import android.text.TextUtils;
import com.android.inputmethod.event.Event;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.InputPointers;
import java.util.ArrayList;
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index ff82087ae..5fa28d571 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -77,6 +77,7 @@ import com.android.inputmethod.keyboard.TextDecoratorUi;
import com.android.inputmethod.latin.Suggest.OnGetSuggestedWordsCallback;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.InputPointers;
import com.android.inputmethod.latin.define.DebugFlags;
import com.android.inputmethod.latin.define.ProductionFlags;
import com.android.inputmethod.latin.inputlogic.InputLogic;
diff --git a/java/src/com/android/inputmethod/latin/NgramContext.java b/java/src/com/android/inputmethod/latin/NgramContext.java
index 0ccea4732..82a13274d 100644
--- a/java/src/com/android/inputmethod/latin/NgramContext.java
+++ b/java/src/com/android/inputmethod/latin/NgramContext.java
@@ -20,7 +20,7 @@ import android.text.TextUtils;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.common.Constants;
-import com.android.inputmethod.latin.utils.StringUtils;
+import com.android.inputmethod.latin.common.StringUtils;
import java.util.Arrays;
diff --git a/java/src/com/android/inputmethod/latin/PunctuationSuggestions.java b/java/src/com/android/inputmethod/latin/PunctuationSuggestions.java
index 93598d2fb..a65304cd0 100644
--- a/java/src/com/android/inputmethod/latin/PunctuationSuggestions.java
+++ b/java/src/com/android/inputmethod/latin/PunctuationSuggestions.java
@@ -18,7 +18,7 @@ package com.android.inputmethod.latin;
import com.android.inputmethod.keyboard.internal.KeySpecParser;
import com.android.inputmethod.latin.common.Constants;
-import com.android.inputmethod.latin.utils.StringUtils;
+import com.android.inputmethod.latin.common.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java
index 0763ef807..834f747d9 100644
--- a/java/src/com/android/inputmethod/latin/RichInputConnection.java
+++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java
@@ -35,6 +35,7 @@ import android.view.inputmethod.InputMethodManager;
import com.android.inputmethod.compat.InputConnectionCompatUtils;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.inputlogic.PrivateCommandPerformer;
import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
import com.android.inputmethod.latin.utils.CapsModeUtils;
@@ -42,7 +43,6 @@ import com.android.inputmethod.latin.utils.DebugLogUtils;
import com.android.inputmethod.latin.utils.NgramContextUtils;
import com.android.inputmethod.latin.utils.ScriptUtils;
import com.android.inputmethod.latin.utils.SpannableStringUtils;
-import com.android.inputmethod.latin.utils.StringUtils;
import com.android.inputmethod.latin.utils.TextRange;
import javax.annotation.Nonnull;
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index 1f78a84c8..430f765ea 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -21,11 +21,11 @@ import android.text.TextUtils;
import com.android.inputmethod.keyboard.ProximityInfo;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.define.DebugFlags;
import com.android.inputmethod.latin.settings.SettingsValuesForSuggestion;
import com.android.inputmethod.latin.utils.AutoCorrectionUtils;
import com.android.inputmethod.latin.utils.BinaryDictionaryUtils;
-import com.android.inputmethod.latin.utils.StringUtils;
import com.android.inputmethod.latin.utils.SuggestionResults;
import java.util.ArrayList;
diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java
index a6428896e..b84de6919 100644
--- a/java/src/com/android/inputmethod/latin/SuggestedWords.java
+++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java
@@ -21,8 +21,8 @@ import android.view.inputmethod.CompletionInfo;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.define.DebugFlags;
-import com.android.inputmethod.latin.utils.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/java/src/com/android/inputmethod/latin/WordComposer.java b/java/src/com/android/inputmethod/latin/WordComposer.java
index 8830521c7..0b77f2ce3 100644
--- a/java/src/com/android/inputmethod/latin/WordComposer.java
+++ b/java/src/com/android/inputmethod/latin/WordComposer.java
@@ -20,9 +20,10 @@ import com.android.inputmethod.event.CombinerChain;
import com.android.inputmethod.event.Event;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.InputPointers;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.define.DebugFlags;
import com.android.inputmethod.latin.utils.CoordinateUtils;
-import com.android.inputmethod.latin.utils.StringUtils;
import java.util.ArrayList;
import java.util.Collections;
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
index a67f46108..bafea178e 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java
@@ -41,7 +41,6 @@ import com.android.inputmethod.keyboard.TextDecorator;
import com.android.inputmethod.keyboard.TextDecoratorUiOperator;
import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.DictionaryFacilitator;
-import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.LastComposedWord;
import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.NgramContext;
@@ -52,6 +51,8 @@ import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.WordComposer;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.InputPointers;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.define.DebugFlags;
import com.android.inputmethod.latin.settings.SettingsValues;
import com.android.inputmethod.latin.settings.SettingsValuesForSuggestion;
@@ -61,7 +62,6 @@ import com.android.inputmethod.latin.utils.AsyncResultHolder;
import com.android.inputmethod.latin.utils.InputTypeUtils;
import com.android.inputmethod.latin.utils.RecapitalizeStatus;
import com.android.inputmethod.latin.utils.StatsUtils;
-import com.android.inputmethod.latin.utils.StringUtils;
import com.android.inputmethod.latin.utils.TextRange;
import java.util.ArrayList;
diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java
index 5f391dd9b..ddc4ad99c 100644
--- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java
+++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogicHandler.java
@@ -21,10 +21,10 @@ import android.os.HandlerThread;
import android.os.Message;
import com.android.inputmethod.compat.LooperCompatUtils;
-import com.android.inputmethod.latin.InputPointers;
import com.android.inputmethod.latin.LatinIME;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.Suggest.OnGetSuggestedWordsCallback;
+import com.android.inputmethod.latin.common.InputPointers;
/**
* A helper to manage deferred tasks for the input logic.
diff --git a/java/src/com/android/inputmethod/latin/makedict/WordProperty.java b/java/src/com/android/inputmethod/latin/makedict/WordProperty.java
index e7808e46e..388d57816 100644
--- a/java/src/com/android/inputmethod/latin/makedict/WordProperty.java
+++ b/java/src/com/android/inputmethod/latin/makedict/WordProperty.java
@@ -21,8 +21,8 @@ import com.android.inputmethod.latin.BinaryDictionary;
import com.android.inputmethod.latin.Dictionary;
import com.android.inputmethod.latin.NgramContext;
import com.android.inputmethod.latin.NgramContext.WordInfo;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.utils.CombinedFormatUtils;
-import com.android.inputmethod.latin.utils.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/java/src/com/android/inputmethod/latin/settings/AppearanceSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/AppearanceSettingsFragment.java
index a9884ba13..554edc85c 100644
--- a/java/src/com/android/inputmethod/latin/settings/AppearanceSettingsFragment.java
+++ b/java/src/com/android/inputmethod/latin/settings/AppearanceSettingsFragment.java
@@ -19,9 +19,9 @@ package com.android.inputmethod.latin.settings;
import android.os.Bundle;
import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.define.ProductionFlags;
-
/**
* "Appearance" settings sub screen.
*/
@@ -30,8 +30,8 @@ public final class AppearanceSettingsFragment extends SubScreenFragment {
public void onCreate(final Bundle icicle) {
super.onCreate(icicle);
addPreferencesFromResource(R.xml.prefs_screen_appearance);
- if (!ProductionFlags.IS_SPLIT_KEYBOARD_SUPPORTED
- || !Settings.getInstance().getCurrent().isTablet()) {
+ if (!ProductionFlags.IS_SPLIT_KEYBOARD_SUPPORTED ||
+ Constants.isPhone(Settings.readScreenMetrics(getResources()))) {
removePreference(Settings.PREF_ENABLE_SPLIT_KEYBOARD);
}
}
@@ -43,4 +43,4 @@ public final class AppearanceSettingsFragment extends SubScreenFragment {
findPreference(Settings.PREF_CUSTOM_INPUT_STYLES));
ThemeSettingsFragment.updateKeyboardThemeSummary(findPreference(Settings.SCREEN_THEME));
}
-} \ No newline at end of file
+}
diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java
index 2ac6e8576..19db60655 100644
--- a/java/src/com/android/inputmethod/latin/settings/Settings.java
+++ b/java/src/com/android/inputmethod/latin/settings/Settings.java
@@ -29,11 +29,11 @@ import com.android.inputmethod.compat.BuildCompatUtils;
import com.android.inputmethod.latin.AudioAndHapticFeedbackManager;
import com.android.inputmethod.latin.InputAttributes;
import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.utils.AdditionalSubtypeUtils;
import com.android.inputmethod.latin.utils.ResourceUtils;
import com.android.inputmethod.latin.utils.RunInLocale;
import com.android.inputmethod.latin.utils.StatsUtils;
-import com.android.inputmethod.latin.utils.StringUtils;
import java.util.Collections;
import java.util.Locale;
@@ -213,6 +213,10 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
return mSettingsValues.mBlockPotentiallyOffensive;
}
+ public static int readScreenMetrics(final Resources res) {
+ return res.getInteger(R.integer.config_screen_metrics);
+ }
+
// Accessed from the settings interface, hence public
public static boolean readKeypressSoundEnabled(final SharedPreferences prefs,
final Resources res) {
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
index e488cb10c..bdb4e64e0 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
@@ -29,7 +29,6 @@ import com.android.inputmethod.latin.InputAttributes;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodManager;
import com.android.inputmethod.latin.SubtypeSwitcher;
-import com.android.inputmethod.latin.common.Constants;
import com.android.inputmethod.latin.utils.AsyncResultHolder;
import com.android.inputmethod.latin.utils.ResourceUtils;
import com.android.inputmethod.latin.utils.TargetPackageInfoGetterTask;
@@ -158,7 +157,7 @@ public class SettingsValues {
mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration());
mEnableMetricsLogging = prefs.getBoolean(Settings.PREF_ENABLE_METRICS_LOGGING, true);
mIsSplitKeyboardEnabled = prefs.getBoolean(Settings.PREF_ENABLE_SPLIT_KEYBOARD, false);
- mScreenMetrics = res.getInteger(R.integer.config_screen_metrics);
+ mScreenMetrics = Settings.readScreenMetrics(res);
mShouldShowLxxSuggestionUi = Settings.SHOULD_SHOW_LXX_SUGGESTION_UI
&& prefs.getBoolean(DebugSettings.PREF_SHOULD_SHOW_LXX_SUGGESTION_UI, true);
@@ -224,11 +223,6 @@ public class SettingsValues {
return mEnableMetricsLogging;
}
- public boolean isTablet() {
- return mScreenMetrics == Constants.SCREEN_METRICS_SMALL_TABLET
- || mScreenMetrics == Constants.SCREEN_METRICS_LARGE_TABLET;
- }
-
public boolean isApplicationSpecifiedCompletionsOn() {
return mInputAttributes.mApplicationSpecifiedCompletionOn;
}
diff --git a/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java b/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java
index 46aef89c4..70d97a5ba 100644
--- a/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java
+++ b/java/src/com/android/inputmethod/latin/settings/SpacingAndPunctuations.java
@@ -23,7 +23,7 @@ import com.android.inputmethod.keyboard.internal.MoreKeySpec;
import com.android.inputmethod.latin.PunctuationSuggestions;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.common.Constants;
-import com.android.inputmethod.latin.utils.StringUtils;
+import com.android.inputmethod.latin.common.StringUtils;
import java.util.Arrays;
import java.util.Locale;
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerSession.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerSession.java
index ac395bf02..2c690aea7 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerSession.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerSession.java
@@ -28,7 +28,7 @@ import android.view.textservice.TextInfo;
import com.android.inputmethod.compat.TextInfoCompatUtils;
import com.android.inputmethod.latin.NgramContext;
-import com.android.inputmethod.latin.utils.StringUtils;
+import com.android.inputmethod.latin.utils.SpannableStringUtils;
import java.util.ArrayList;
import java.util.Locale;
@@ -71,9 +71,10 @@ public final class AndroidSpellCheckerSession extends AndroidWordLevelSpellCheck
if (!subText.toString().contains(AndroidSpellCheckerService.SINGLE_QUOTE)) {
continue;
}
- final CharSequence[] splitTexts = StringUtils.split(subText,
+ // Split preserving spans.
+ final CharSequence[] splitTexts = SpannableStringUtils.split(subText,
AndroidSpellCheckerService.SINGLE_QUOTE,
- true /* preserveTrailingEmptySegments */ );
+ true /* preserveTrailingEmptySegments */);
if (splitTexts == null || splitTexts.length <= 1) {
continue;
}
diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java
index 514bfca85..3ad8fb910 100644
--- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java
+++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidWordLevelSpellCheckerSession.java
@@ -34,11 +34,11 @@ import com.android.inputmethod.latin.NgramContext;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.WordComposer;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.utils.BinaryDictionaryUtils;
import com.android.inputmethod.latin.utils.CoordinateUtils;
import com.android.inputmethod.latin.utils.LocaleUtils;
import com.android.inputmethod.latin.utils.ScriptUtils;
-import com.android.inputmethod.latin.utils.StringUtils;
import com.android.inputmethod.latin.utils.SuggestionResults;
import java.util.ArrayList;
diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
index b18fcc744..b71bd1f50 100644
--- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
+++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionStripView.java
@@ -344,12 +344,6 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
if (mSuggestedWords.size() <= mStartIndexOfMoreSuggestions) {
return false;
}
- // Dismiss another {@link MoreKeysPanel} that may be being showed, for example
- // {@link MoreKeysKeyboardView}.
- mMainKeyboardView.onDismissMoreKeysPanel();
- // Dismiss all key previews and sliding key input preview that may be being showed.
- mMainKeyboardView.dismissAllKeyPreviews();
- mMainKeyboardView.dismissSlidingKeyInputPreview();
final int stripWidth = getWidth();
final View container = mMoreSuggestionsContainer;
final int maxWidth = stripWidth - container.getPaddingLeft() - container.getPaddingRight();
diff --git a/java/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtils.java b/java/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtils.java
index 02ace6a1e..2aac7c57a 100644
--- a/java/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtils.java
@@ -31,6 +31,7 @@ import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
import com.android.inputmethod.latin.R;
+import com.android.inputmethod.latin.common.StringUtils;
import java.util.ArrayList;
import java.util.Arrays;
diff --git a/java/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtils.java b/java/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtils.java
index ce25fe6a4..23ffde2a2 100644
--- a/java/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/BinaryDictionaryUtils.java
@@ -18,6 +18,7 @@ package com.android.inputmethod.latin.utils;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.BinaryDictionary;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.makedict.DictionaryHeader;
import com.android.inputmethod.latin.makedict.UnsupportedFormatException;
import com.android.inputmethod.latin.personalization.PersonalizationHelper;
diff --git a/java/src/com/android/inputmethod/latin/utils/CapsModeUtils.java b/java/src/com/android/inputmethod/latin/utils/CapsModeUtils.java
index b087e9ee8..0db63fd9f 100644
--- a/java/src/com/android/inputmethod/latin/utils/CapsModeUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/CapsModeUtils.java
@@ -21,6 +21,7 @@ import android.text.TextUtils;
import com.android.inputmethod.latin.WordComposer;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
import java.util.Locale;
diff --git a/java/src/com/android/inputmethod/latin/utils/DistracterFilterCheckingExactMatchesAndSuggestions.java b/java/src/com/android/inputmethod/latin/utils/DistracterFilterCheckingExactMatchesAndSuggestions.java
index 8f0f9bb44..56c8249bd 100644
--- a/java/src/com/android/inputmethod/latin/utils/DistracterFilterCheckingExactMatchesAndSuggestions.java
+++ b/java/src/com/android/inputmethod/latin/utils/DistracterFilterCheckingExactMatchesAndSuggestions.java
@@ -40,6 +40,7 @@ import com.android.inputmethod.latin.NgramContext;
import com.android.inputmethod.latin.RichInputMethodSubtype;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.WordComposer;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.settings.SettingsValuesForSuggestion;
/**
diff --git a/java/src/com/android/inputmethod/latin/utils/RecapitalizeStatus.java b/java/src/com/android/inputmethod/latin/utils/RecapitalizeStatus.java
index e3cac97f0..21daddce7 100644
--- a/java/src/com/android/inputmethod/latin/utils/RecapitalizeStatus.java
+++ b/java/src/com/android/inputmethod/latin/utils/RecapitalizeStatus.java
@@ -16,6 +16,8 @@
package com.android.inputmethod.latin.utils;
+import com.android.inputmethod.latin.common.StringUtils;
+
import java.util.Locale;
/**
diff --git a/java/src/com/android/inputmethod/latin/utils/SpannableStringUtils.java b/java/src/com/android/inputmethod/latin/utils/SpannableStringUtils.java
index cea1d1d58..c41817fe6 100644
--- a/java/src/com/android/inputmethod/latin/utils/SpannableStringUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/SpannableStringUtils.java
@@ -24,6 +24,12 @@ import android.text.TextUtils;
import android.text.style.SuggestionSpan;
import android.text.style.URLSpan;
+import com.android.inputmethod.annotations.UsedForTesting;
+
+import java.util.ArrayList;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
public final class SpannableStringUtils {
/**
* Copies the spans from the region <code>start...end</code> in
@@ -125,4 +131,53 @@ public final class SpannableStringUtils {
final URLSpan[] spans = spanned.getSpans(startIndex - 1, endIndex + 1, URLSpan.class);
return null != spans && spans.length > 0;
}
+
+ /**
+ * Splits the given {@code charSequence} with at occurrences of the given {@code regex}.
+ * <p>
+ * This is equivalent to
+ * {@code charSequence.toString().split(regex, preserveTrailingEmptySegments ? -1 : 0)}
+ * except that the spans are preserved in the result array.
+ * </p>
+ * @param charSequence the character sequence to be split.
+ * @param regex the regex pattern to be used as the separator.
+ * @param preserveTrailingEmptySegments {@code true} to preserve the trailing empty
+ * segments. Otherwise, trailing empty segments will be removed before being returned.
+ * @return the array which contains the result. All the spans in the <code>charSequence</code>
+ * is preserved.
+ */
+ @UsedForTesting
+ public static CharSequence[] split(final CharSequence charSequence, final String regex,
+ final boolean preserveTrailingEmptySegments) {
+ // A short-cut for non-spanned strings.
+ if (!(charSequence instanceof Spanned)) {
+ // -1 means that trailing empty segments will be preserved.
+ return charSequence.toString().split(regex, preserveTrailingEmptySegments ? -1 : 0);
+ }
+
+ // Hereafter, emulate String.split for CharSequence.
+ final ArrayList<CharSequence> sequences = new ArrayList<>();
+ final Matcher matcher = Pattern.compile(regex).matcher(charSequence);
+ int nextStart = 0;
+ boolean matched = false;
+ while (matcher.find()) {
+ sequences.add(charSequence.subSequence(nextStart, matcher.start()));
+ nextStart = matcher.end();
+ matched = true;
+ }
+ if (!matched) {
+ // never matched. preserveTrailingEmptySegments is ignored in this case.
+ return new CharSequence[] { charSequence };
+ }
+ sequences.add(charSequence.subSequence(nextStart, charSequence.length()));
+ if (!preserveTrailingEmptySegments) {
+ for (int i = sequences.size() - 1; i >= 0; --i) {
+ if (!TextUtils.isEmpty(sequences.get(i))) {
+ break;
+ }
+ sequences.remove(i);
+ }
+ }
+ return sequences.toArray(new CharSequence[sequences.size()]);
+ }
}
diff --git a/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java b/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java
index eb85c1baf..55c1dc9e5 100644
--- a/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/SubtypeLocaleUtils.java
@@ -28,10 +28,10 @@ import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.RichInputMethodSubtype;
+import com.android.inputmethod.latin.common.StringUtils;
import java.util.Arrays;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Locale;
/**
@@ -59,7 +59,8 @@ public final class SubtypeLocaleUtils {
// Keyboard layout to subtype name resource id map.
private static final HashMap<String, Integer> sKeyboardLayoutToNameIdsMap = new HashMap<>();
// Exceptional locale whose name should be displayed in Locale.ROOT.
- static final HashSet<String> sExceptionalLocaleDisplayedInRootLocale = new HashSet<>();
+ private static final HashMap<String, Integer> sExceptionalLocaleDisplayedInRootLocale =
+ new HashMap<>();
// Exceptional locale to subtype name resource id map.
private static final HashMap<String, Integer> sExceptionalLocaleToNameIdsMap = new HashMap<>();
// Exceptional locale to subtype name with layout resource id map.
@@ -73,6 +74,8 @@ public final class SubtypeLocaleUtils {
"string/subtype_with_layout_";
private static final String SUBTYPE_NAME_RESOURCE_NO_LANGUAGE_PREFIX =
"string/subtype_no_language_";
+ private static final String SUBTYPE_NAME_RESOURCE_IN_ROOT_LOCALE_PREFIX =
+ "string/subtype_in_root_locale_";
// Keyboard layout set name for the subtypes that don't have a keyboardLayoutSet extra value.
// This is for compatibility to keep the same subtype ids as pre-JellyBean.
private static final HashMap<String, String> sLocaleAndExtraValueToKeyboardLayoutSetMap =
@@ -117,7 +120,10 @@ public final class SubtypeLocaleUtils {
final String[] exceptionalLocaleInRootLocale = res.getStringArray(
R.array.subtype_locale_displayed_in_root_locale);
for (int i = 0; i < exceptionalLocaleInRootLocale.length; i++) {
- sExceptionalLocaleDisplayedInRootLocale.add(exceptionalLocaleInRootLocale[i]);
+ final String localeString = exceptionalLocaleInRootLocale[i];
+ final String resourceName = SUBTYPE_NAME_RESOURCE_IN_ROOT_LOCALE_PREFIX + localeString;
+ final int resId = res.getIdentifier(resourceName, null, RESOURCE_PACKAGE_NAME);
+ sExceptionalLocaleDisplayedInRootLocale.put(localeString, resId);
}
final String[] exceptionalLocales = res.getStringArray(
@@ -171,7 +177,7 @@ public final class SubtypeLocaleUtils {
if (NO_LANGUAGE.equals(localeString)) {
return sResources.getConfiguration().locale;
}
- if (sExceptionalLocaleDisplayedInRootLocale.contains(localeString)) {
+ if (sExceptionalLocaleDisplayedInRootLocale.containsKey(localeString)) {
return Locale.ROOT;
}
return LocaleUtils.constructLocaleFromString(localeString);
@@ -190,7 +196,7 @@ public final class SubtypeLocaleUtils {
public static String getSubtypeLanguageDisplayName(final String localeString) {
final Locale displayLocale = getDisplayLocaleOfSubtypeLocale(localeString);
final String languageString;
- if (sExceptionalLocaleDisplayedInRootLocale.contains(localeString)) {
+ if (sExceptionalLocaleDisplayedInRootLocale.containsKey(localeString)) {
languageString = localeString;
} else {
final Locale locale = LocaleUtils.constructLocaleFromString(localeString);
@@ -205,7 +211,16 @@ public final class SubtypeLocaleUtils {
// No language subtype should be displayed in system locale.
return sResources.getString(R.string.subtype_no_language);
}
- final Integer exceptionalNameResId = sExceptionalLocaleToNameIdsMap.get(localeString);
+ final Integer exceptionalNameResId;
+ if (displayLocale.equals(Locale.ROOT)
+ && sExceptionalLocaleDisplayedInRootLocale.containsKey(localeString)) {
+ exceptionalNameResId = sExceptionalLocaleDisplayedInRootLocale.get(localeString);
+ } else if (sExceptionalLocaleToNameIdsMap.containsKey(localeString)) {
+ exceptionalNameResId = sExceptionalLocaleToNameIdsMap.get(localeString);
+ } else {
+ exceptionalNameResId = null;
+ }
+
final String displayName;
if (exceptionalNameResId != null) {
final RunInLocale<String> getExceptionalName = new RunInLocale<String>() {
diff --git a/java/src/com/android/inputmethod/latin/utils/WordInputEventForPersonalization.java b/java/src/com/android/inputmethod/latin/utils/WordInputEventForPersonalization.java
index d3fa0c748..86a5b19ec 100644
--- a/java/src/com/android/inputmethod/latin/utils/WordInputEventForPersonalization.java
+++ b/java/src/com/android/inputmethod/latin/utils/WordInputEventForPersonalization.java
@@ -21,6 +21,7 @@ import android.util.Log;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.latin.NgramContext;
import com.android.inputmethod.latin.common.Constants;
+import com.android.inputmethod.latin.common.StringUtils;
import com.android.inputmethod.latin.settings.SpacingAndPunctuations;
import com.android.inputmethod.latin.utils.DistracterFilter.HandlingType;