aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
diff options
context:
space:
mode:
authorsatok <satok@google.com>2011-10-28 19:02:59 +0900
committersatok <satok@google.com>2011-10-28 19:03:49 +0900
commit68ef7b77ede812051668465b1d65119735cf643d (patch)
tree2188f25d1f69a5d6cbd650b0133efc2aa4002a48 /java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
parent07a445572f7fa21c0e24f5cdb0f0b88ff2adc672 (diff)
downloadlatinime-68ef7b77ede812051668465b1d65119735cf643d.tar.gz
latinime-68ef7b77ede812051668465b1d65119735cf643d.tar.xz
latinime-68ef7b77ede812051668465b1d65119735cf643d.zip
Use reflection to get field values of SuggestionSpan
Bug: 5440299 Change-Id: I5e40edf6f790c078c4a05d0d347a89d63f7c042a
Diffstat (limited to 'java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java')
-rw-r--r--java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java30
1 files changed, 23 insertions, 7 deletions
diff --git a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
index 2766cc3f1..164d2b748 100644
--- a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
+++ b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
@@ -16,6 +16,7 @@
package com.android.inputmethod.compat;
+import com.android.inputmethod.latin.LatinImeLogger;
import com.android.inputmethod.latin.SuggestedWords;
import com.android.inputmethod.latin.SuggestionSpanPickedNotificationReceiver;
@@ -27,6 +28,7 @@ import android.text.TextUtils;
import android.util.Log;
import java.lang.reflect.Constructor;
+import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Locale;
@@ -38,9 +40,6 @@ 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";
- // TODO: Use the API constant after it gets public.
- public static final int FLAG_AUTO_CORRECTION = 0x0004;
- public static final int SUGGESTION_MAX_SIZE = 5;
public static final boolean SUGGESTION_SPAN_IS_SUPPORTED;
private static final Class<?> CLASS_SuggestionSpan = CompatUtils
@@ -49,20 +48,36 @@ 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 Field FIELD_FLAG_AUTO_CORRECTION
+ = CompatUtils.getField(CLASS_SuggestionSpan, "FLAG_AUTO_CORRECTION");
+ public static final Field FIELD_SUGGESTION_MAX_SIZE
+ = CompatUtils.getField(CLASS_SuggestionSpan, "SUGGESTION_MAX_SIZE");
+ public static final Integer OBJ_FLAG_AUTO_CORRECTION = (Integer) CompatUtils
+ .getFieldValue(null, null, FIELD_FLAG_AUTO_CORRECTION);;
+ public static final Integer OBJ_SUGGESTION_MAX_SIZE = (Integer) CompatUtils
+ .getFieldValue(null, null, FIELD_SUGGESTION_MAX_SIZE);;
+
static {
SUGGESTION_SPAN_IS_SUPPORTED =
CLASS_SuggestionSpan != null && CONSTRUCTOR_SuggestionSpan != null;
+ if (LatinImeLogger.sDBG) {
+ if (SUGGESTION_SPAN_IS_SUPPORTED
+ && (OBJ_FLAG_AUTO_CORRECTION == null || OBJ_SUGGESTION_MAX_SIZE == null)) {
+ Log.e(TAG, "Field is accidentially null.");
+ }
+ }
}
public static CharSequence getTextWithAutoCorrectionIndicatorUnderline(
Context context, CharSequence text) {
- if (TextUtils.isEmpty(text) || CONSTRUCTOR_SuggestionSpan == null) {
+ if (TextUtils.isEmpty(text) || CONSTRUCTOR_SuggestionSpan == null
+ || OBJ_FLAG_AUTO_CORRECTION == null) {
return text;
}
final Spannable spannable = text instanceof Spannable
? (Spannable) text : new SpannableString(text);
final Object[] args =
- { context, null, new String[] {}, FLAG_AUTO_CORRECTION,
+ { context, null, new String[] {}, (int)OBJ_FLAG_AUTO_CORRECTION,
(Class<?>) SuggestionSpanPickedNotificationReceiver.class };
final Object ss = CompatUtils.newInstance(CONSTRUCTOR_SuggestionSpan, args);
if (ss == null) {
@@ -78,7 +93,8 @@ public class SuggestionSpanUtils {
CharSequence pickedWord, SuggestedWords suggestedWords) {
if (TextUtils.isEmpty(pickedWord) || CONSTRUCTOR_SuggestionSpan == null
|| suggestedWords == null || suggestedWords.size() == 0
- || suggestedWords.getInfo(0).isObsoleteSuggestedWord()) {
+ || suggestedWords.getInfo(0).isObsoleteSuggestedWord()
+ || OBJ_SUGGESTION_MAX_SIZE == null) {
return pickedWord;
}
@@ -90,7 +106,7 @@ public class SuggestionSpanUtils {
}
final ArrayList<String> suggestionsList = new ArrayList<String>();
for (int i = 0; i < suggestedWords.size(); ++i) {
- if (suggestionsList.size() >= SUGGESTION_MAX_SIZE) {
+ if (suggestionsList.size() >= OBJ_SUGGESTION_MAX_SIZE) {
break;
}
final CharSequence word = suggestedWords.getWord(i);