aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
diff options
context:
space:
mode:
authorsatok <satok@google.com>2011-06-17 18:25:36 +0900
committersatok <satok@google.com>2011-06-17 18:25:36 +0900
commit23726dbdca0478297a4eed5dcce70b1bace34293 (patch)
treefbbc49e7584c4b68dca4f2bd1c4f7ca1a2bb3646 /java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
parent064e21bb1d634fb986598804302ac77172e51367 (diff)
downloadlatinime-23726dbdca0478297a4eed5dcce70b1bace34293.tar.gz
latinime-23726dbdca0478297a4eed5dcce70b1bace34293.tar.xz
latinime-23726dbdca0478297a4eed5dcce70b1bace34293.zip
Refactor of SuggestionSpanUtils
Change-Id: Id266062831e8c28a346e129168b883ee3d5622bf
Diffstat (limited to 'java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java')
-rw-r--r--java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java21
1 files changed, 11 insertions, 10 deletions
diff --git a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
index 5d89669b7..4929dd948 100644
--- a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
+++ b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
@@ -30,12 +30,14 @@ import java.util.ArrayList;
import java.util.Locale;
public class SuggestionSpanUtils {
+ // TODO: Use reflection to get field values
public static final String ACTION_SUGGESTION_PICKED =
"android.text.style.SUGGESTION_PICKED";
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;
+ public static final boolean SUGGESTION_SPAN_IS_SUPPORTED;
private static final Class<?> CLASS_SuggestionSpan = CompatUtils
.getClass("android.text.style.SuggestionSpan");
@@ -43,24 +45,23 @@ public class SuggestionSpanUtils {
Context.class, Locale.class, String[].class, int.class, Class.class };
private static final Constructor<?> CONSTRUCTOR_SuggestionSpan = CompatUtils
.getConstructor(CLASS_SuggestionSpan, INPUT_TYPE_SuggestionSpan);
- public static final boolean SUGGESTION_SPAN_IS_SUPPORTED;
static {
SUGGESTION_SPAN_IS_SUPPORTED =
CLASS_SuggestionSpan != null && CONSTRUCTOR_SuggestionSpan != null;
}
public static CharSequence getTextWithSuggestionSpan(Context context,
- CharSequence suggestion, SuggestedWords suggestedWords) {
- if (TextUtils.isEmpty(suggestion) || CONSTRUCTOR_SuggestionSpan == null
+ CharSequence pickedWord, SuggestedWords suggestedWords) {
+ if (TextUtils.isEmpty(pickedWord) || CONSTRUCTOR_SuggestionSpan == null
|| suggestedWords == null || suggestedWords.size() == 0) {
- return suggestion;
+ return pickedWord;
}
final Spannable spannable;
- if (suggestion instanceof Spannable) {
- spannable = (Spannable) suggestion;
+ if (pickedWord instanceof Spannable) {
+ spannable = (Spannable) pickedWord;
} else {
- spannable = new SpannableString(suggestion);
+ spannable = new SpannableString(pickedWord);
}
final ArrayList<String> suggestionsList = new ArrayList<String>();
for (int i = 0; i < suggestedWords.size(); ++i) {
@@ -68,7 +69,7 @@ public class SuggestionSpanUtils {
break;
}
final CharSequence word = suggestedWords.getWord(i);
- if (!TextUtils.equals(suggestion, word)) {
+ if (!TextUtils.equals(pickedWord, word)) {
suggestionsList.add(word.toString());
}
}
@@ -78,9 +79,9 @@ public class SuggestionSpanUtils {
(Class<?>) SuggestionSpanPickedNotificationReceiver.class };
final Object ss = CompatUtils.newInstance(CONSTRUCTOR_SuggestionSpan, args);
if (ss == null) {
- return suggestion;
+ return pickedWord;
}
- spannable.setSpan(ss, 0, suggestion.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
+ spannable.setSpan(ss, 0, pickedWord.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannable;
}
}