Search in sources :

Example 11 with UsedForTesting

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;
}
Also used : SpannableString(android.text.SpannableString) SuggestedWordInfo(com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) SuggestionSpan(android.text.style.SuggestionSpan) Spannable(android.text.Spannable) UsedForTesting(com.android.inputmethod.annotations.UsedForTesting)

Aggregations

UsedForTesting (com.android.inputmethod.annotations.UsedForTesting)11 ArrayList (java.util.ArrayList)3 Spannable (android.text.Spannable)2 SpannableString (android.text.SpannableString)2 SuggestionSpan (android.text.style.SuggestionSpan)2 SettingsValues (com.android.inputmethod.latin.settings.SettingsValues)2 Locale (java.util.Locale)2 SharedPreferences (android.content.SharedPreferences)1 Paint (android.graphics.Paint)1 Spanned (android.text.Spanned)1 TextPaint (android.text.TextPaint)1 EditorInfo (android.view.inputmethod.EditorInfo)1 SuggestedWordInfo (com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo)1 UserHistoryDictionary (com.android.inputmethod.latin.personalization.UserHistoryDictionary)1 File (java.io.File)1 HttpURLConnection (java.net.HttpURLConnection)1 HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 Matcher (java.util.regex.Matcher)1