Refactor of SuggestionSpanUtils

Change-Id: Id266062831e8c28a346e129168b883ee3d5622bf
diff --git a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
index 5d89669..4929dd9 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.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 @@
             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 @@
                 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 @@
                         (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;
     }
 }