use of com.android.inputmethod.annotations.UsedForTesting in project android_packages_inputmethods_LatinIME by CyanogenMod.
the class SuggestionSpanUtils method getTextWithSuggestionSpan.
@UsedForTesting
public static CharSequence getTextWithSuggestionSpan(final Context context, final String pickedWord, final SuggestedWords suggestedWords, final Locale locale) {
if (TextUtils.isEmpty(pickedWord) || suggestedWords.isEmpty() || suggestedWords.isPrediction() || suggestedWords.isPunctuationSuggestions()) {
return pickedWord;
}
final ArrayList<String> suggestionsList = new ArrayList<>();
for (int i = 0; i < suggestedWords.size(); ++i) {
if (suggestionsList.size() >= SuggestionSpan.SUGGESTIONS_MAX_SIZE) {
break;
}
final SuggestedWordInfo info = suggestedWords.getInfo(i);
if (info.isKindOf(SuggestedWordInfo.KIND_PREDICTION)) {
continue;
}
final String word = suggestedWords.getWord(i);
if (!TextUtils.equals(pickedWord, word)) {
suggestionsList.add(word.toString());
}
}
final SuggestionSpan suggestionSpan = new SuggestionSpan(context, locale, suggestionsList.toArray(new String[suggestionsList.size()]), 0, /* flags */
null);
final Spannable spannable = new SpannableString(pickedWord);
spannable.setSpan(suggestionSpan, 0, pickedWord.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannable;
}
Aggregations