diff options
author | 2014-10-06 15:03:19 +0000 | |
---|---|---|
committer | 2014-10-06 15:03:20 +0000 | |
commit | db6c32778e80acc156a118f13ff2788a9277da30 (patch) | |
tree | 4ace4f1d9ab46e91449beb0ef975970966077dbb /java | |
parent | 96d97ee23cc325f7045eb3cf3097d614cf35a5ff (diff) | |
parent | 03c1e7955abf089f3bf5027d506336c07d970180 (diff) | |
download | latinime-db6c32778e80acc156a118f13ff2788a9277da30.tar.gz latinime-db6c32778e80acc156a118f13ff2788a9277da30.tar.xz latinime-db6c32778e80acc156a118f13ff2788a9277da30.zip |
Merge "Add a utility method to SuggestionSpanUtils"
Diffstat (limited to 'java')
-rw-r--r-- | java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java index 27db9b8e8..d3e24e342 100644 --- a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java +++ b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java @@ -28,9 +28,13 @@ import com.android.inputmethod.latin.SuggestedWords; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestionSpanPickedNotificationReceiver; import com.android.inputmethod.latin.define.DebugFlags; +import com.android.inputmethod.latin.utils.LocaleUtils; import java.lang.reflect.Field; import java.util.ArrayList; +import java.util.Locale; + +import javax.annotation.Nullable; public final class SuggestionSpanUtils { // Note that SuggestionSpan.FLAG_AUTO_CORRECTION has been introduced @@ -98,4 +102,28 @@ public final class SuggestionSpanUtils { spannable.setSpan(suggestionSpan, 0, pickedWord.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannable; } + + /** + * Returns first {@link Locale} found in the given array of {@link SuggestionSpan}. + * @param suggestionSpans the array of {@link SuggestionSpan} to be examined. + * @return the first {@link Locale} found in {@code suggestionSpans}. {@code null} when not + * found. + */ + @UsedForTesting + @Nullable + public static Locale findFirstLocaleFromSuggestionSpans( + final SuggestionSpan[] suggestionSpans) { + for (final SuggestionSpan suggestionSpan : suggestionSpans) { + final String localeString = suggestionSpan.getLocale(); + if (TextUtils.isEmpty(localeString)) { + continue; + } + final Locale locale = LocaleUtils.constructLocaleFromString(localeString); + if (locale == null) { + continue; + } + return locale; + } + return null; + } } |