From 064e21bb1d634fb986598804302ac77172e51367 Mon Sep 17 00:00:00 2001 From: satok Date: Wed, 15 Jun 2011 14:40:34 +0900 Subject: [PATCH] Remove the original text from SuggestionSpan Change-Id: If70d32cad980b46ba77f399606d7ab3957c5d096 --- .../compat/SuggestionSpanUtils.java | 24 ++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java index 5b02de36e..5d89669b7 100644 --- a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java +++ b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java @@ -23,8 +23,10 @@ import android.content.Context; import android.text.Spannable; import android.text.SpannableString; import android.text.Spanned; +import android.text.TextUtils; import java.lang.reflect.Constructor; +import java.util.ArrayList; import java.util.Locale; public class SuggestionSpanUtils { @@ -33,6 +35,7 @@ public class SuggestionSpanUtils { public static final String SUGGESTION_SPAN_PICKED_AFTER = "after"; public static final String SUGGESTION_SPAN_PICKED_BEFORE = "before"; public static final String SUGGESTION_SPAN_PICKED_HASHCODE = "hashcode"; + public static final int SUGGESTION_MAX_SIZE = 5; private static final Class CLASS_SuggestionSpan = CompatUtils .getClass("android.text.style.SuggestionSpan"); @@ -48,8 +51,8 @@ public class SuggestionSpanUtils { public static CharSequence getTextWithSuggestionSpan(Context context, CharSequence suggestion, SuggestedWords suggestedWords) { - if (CONSTRUCTOR_SuggestionSpan == null || suggestedWords == null - || suggestedWords.size() == 0) { + if (TextUtils.isEmpty(suggestion) || CONSTRUCTOR_SuggestionSpan == null + || suggestedWords == null || suggestedWords.size() == 0) { return suggestion; } @@ -59,14 +62,19 @@ public class SuggestionSpanUtils { } else { spannable = new SpannableString(suggestion); } - // TODO: Use SUGGESTIONS_MAX_SIZE instead of 5. - final int N = Math.min(5, suggestedWords.size()); - final String[] suggestionsArray = new String[N]; - for (int i = 0; i < N; ++i) { - suggestionsArray[i] = suggestedWords.getWord(i).toString(); + final ArrayList suggestionsList = new ArrayList(); + for (int i = 0; i < suggestedWords.size(); ++i) { + if (suggestionsList.size() >= SUGGESTION_MAX_SIZE) { + break; + } + final CharSequence word = suggestedWords.getWord(i); + if (!TextUtils.equals(suggestion, word)) { + suggestionsList.add(word.toString()); + } } + final Object[] args = - { context, null, suggestionsArray, 0, + { context, null, suggestionsList.toArray(new String[suggestionsList.size()]), 0, (Class) SuggestionSpanPickedNotificationReceiver.class }; final Object ss = CompatUtils.newInstance(CONSTRUCTOR_SuggestionSpan, args); if (ss == null) {