Loading java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java +25 −7 Original line number Original line Diff line number Diff line Loading @@ -48,21 +48,30 @@ public class SuggestionSpanUtils { Context.class, Locale.class, String[].class, int.class, Class.class }; Context.class, Locale.class, String[].class, int.class, Class.class }; private static final Constructor<?> CONSTRUCTOR_SuggestionSpan = CompatUtils private static final Constructor<?> CONSTRUCTOR_SuggestionSpan = CompatUtils .getConstructor(CLASS_SuggestionSpan, INPUT_TYPE_SuggestionSpan); .getConstructor(CLASS_SuggestionSpan, INPUT_TYPE_SuggestionSpan); public static final Field FIELD_FLAG_AUTO_CORRECTION public static final Field FIELD_FLAG_EASY_CORRECT = = CompatUtils.getField(CLASS_SuggestionSpan, "FLAG_AUTO_CORRECTION"); CompatUtils.getField(CLASS_SuggestionSpan, "FLAG_EASY_CORRECT"); public static final Field FIELD_FLAG_MISSPELLED = CompatUtils.getField(CLASS_SuggestionSpan, "FLAG_MISSPELLED"); public static final Field FIELD_FLAG_AUTO_CORRECTION = CompatUtils.getField(CLASS_SuggestionSpan, "FLAG_AUTO_CORRECTION"); public static final Field FIELD_SUGGESTIONS_MAX_SIZE public static final Field FIELD_SUGGESTIONS_MAX_SIZE = CompatUtils.getField(CLASS_SuggestionSpan, "SUGGESTIONS_MAX_SIZE"); = CompatUtils.getField(CLASS_SuggestionSpan, "SUGGESTIONS_MAX_SIZE"); public static final Integer OBJ_FLAG_EASY_CORRECT = (Integer) CompatUtils .getFieldValue(null, null, FIELD_FLAG_EASY_CORRECT); public static final Integer OBJ_FLAG_MISSPELLED = (Integer) CompatUtils .getFieldValue(null, null, FIELD_FLAG_MISSPELLED); public static final Integer OBJ_FLAG_AUTO_CORRECTION = (Integer) CompatUtils public static final Integer OBJ_FLAG_AUTO_CORRECTION = (Integer) CompatUtils .getFieldValue(null, null, FIELD_FLAG_AUTO_CORRECTION);; .getFieldValue(null, null, FIELD_FLAG_AUTO_CORRECTION); public static final Integer OBJ_SUGGESTIONS_MAX_SIZE = (Integer) CompatUtils public static final Integer OBJ_SUGGESTIONS_MAX_SIZE = (Integer) CompatUtils .getFieldValue(null, null, FIELD_SUGGESTIONS_MAX_SIZE);; .getFieldValue(null, null, FIELD_SUGGESTIONS_MAX_SIZE); static { static { SUGGESTION_SPAN_IS_SUPPORTED = SUGGESTION_SPAN_IS_SUPPORTED = CLASS_SuggestionSpan != null && CONSTRUCTOR_SuggestionSpan != null; CLASS_SuggestionSpan != null && CONSTRUCTOR_SuggestionSpan != null; if (LatinImeLogger.sDBG) { if (LatinImeLogger.sDBG) { if (SUGGESTION_SPAN_IS_SUPPORTED if (SUGGESTION_SPAN_IS_SUPPORTED && (OBJ_FLAG_AUTO_CORRECTION == null || OBJ_SUGGESTIONS_MAX_SIZE == null)) { && (OBJ_FLAG_AUTO_CORRECTION == null || OBJ_SUGGESTIONS_MAX_SIZE == null || OBJ_FLAG_MISSPELLED == null || OBJ_FLAG_EASY_CORRECT == null)) { throw new RuntimeException("Field is accidentially null."); throw new RuntimeException("Field is accidentially null."); } } } } Loading @@ -71,7 +80,8 @@ public class SuggestionSpanUtils { public static CharSequence getTextWithAutoCorrectionIndicatorUnderline( public static CharSequence getTextWithAutoCorrectionIndicatorUnderline( Context context, CharSequence text) { Context context, CharSequence text) { if (TextUtils.isEmpty(text) || CONSTRUCTOR_SuggestionSpan == null if (TextUtils.isEmpty(text) || CONSTRUCTOR_SuggestionSpan == null || OBJ_FLAG_AUTO_CORRECTION == null || OBJ_SUGGESTIONS_MAX_SIZE == null) { || OBJ_FLAG_AUTO_CORRECTION == null || OBJ_SUGGESTIONS_MAX_SIZE == null || OBJ_FLAG_MISSPELLED == null || OBJ_FLAG_EASY_CORRECT == null) { return text; return text; } } final Spannable spannable = text instanceof Spannable final Spannable spannable = text instanceof Spannable Loading Loading @@ -104,6 +114,7 @@ public class SuggestionSpanUtils { spannable = new SpannableString(pickedWord); spannable = new SpannableString(pickedWord); } } final ArrayList<String> suggestionsList = new ArrayList<String>(); final ArrayList<String> suggestionsList = new ArrayList<String>(); boolean sameAsTyped = false; for (int i = 0; i < suggestedWords.size(); ++i) { for (int i = 0; i < suggestedWords.size(); ++i) { if (suggestionsList.size() >= OBJ_SUGGESTIONS_MAX_SIZE) { if (suggestionsList.size() >= OBJ_SUGGESTIONS_MAX_SIZE) { break; break; Loading @@ -111,11 +122,18 @@ public class SuggestionSpanUtils { final CharSequence word = suggestedWords.getWord(i); final CharSequence word = suggestedWords.getWord(i); if (!TextUtils.equals(pickedWord, word)) { if (!TextUtils.equals(pickedWord, word)) { suggestionsList.add(word.toString()); suggestionsList.add(word.toString()); } else if (i == 0) { sameAsTyped = true; } } } } // TODO: Share the implementation for checking typed word validity between the IME // and the spell checker. final int flag = (sameAsTyped && !suggestedWords.mTypedWordValid) ? ((int)OBJ_FLAG_EASY_CORRECT | (int)OBJ_FLAG_MISSPELLED) : 0; final Object[] args = final Object[] args = { context, null, suggestionsList.toArray(new String[suggestionsList.size()]), 0, { context, null, suggestionsList.toArray(new String[suggestionsList.size()]), flag, (Class<?>) SuggestionSpanPickedNotificationReceiver.class }; (Class<?>) SuggestionSpanPickedNotificationReceiver.class }; final Object ss = CompatUtils.newInstance(CONSTRUCTOR_SuggestionSpan, args); final Object ss = CompatUtils.newInstance(CONSTRUCTOR_SuggestionSpan, args); if (ss == null) { if (ss == null) { Loading java/src/com/android/inputmethod/latin/Utils.java +0 −4 Original line number Original line Diff line number Diff line Loading @@ -31,9 +31,7 @@ import android.os.Process; import android.text.TextUtils; import android.text.TextUtils; import android.text.format.DateUtils; import android.text.format.DateUtils; import android.util.Log; import android.util.Log; import android.view.MotionEvent; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import java.io.BufferedReader; import java.io.BufferedReader; Loading Loading @@ -112,7 +110,6 @@ public class Utils { /* package */ static final int BUFSIZE = 20; /* package */ static final int BUFSIZE = 20; private InputMethodService mContext; private InputMethodService mContext; private boolean mEnabled = false; private boolean mEnabled = false; private boolean mUsabilityStudy = false; private int mEnd = 0; private int mEnd = 0; /* package */ int mLength = 0; /* package */ int mLength = 0; private char[] mCharBuf = new char[BUFSIZE]; private char[] mCharBuf = new char[BUFSIZE]; Loading @@ -129,7 +126,6 @@ public class Utils { boolean usabilityStudy) { boolean usabilityStudy) { sRingCharBuffer.mContext = context; sRingCharBuffer.mContext = context; sRingCharBuffer.mEnabled = enabled || usabilityStudy; sRingCharBuffer.mEnabled = enabled || usabilityStudy; sRingCharBuffer.mUsabilityStudy = usabilityStudy; UsabilityStudyLogUtils.getInstance().init(context); UsabilityStudyLogUtils.getInstance().init(context); return sRingCharBuffer; return sRingCharBuffer; } } Loading Loading
java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java +25 −7 Original line number Original line Diff line number Diff line Loading @@ -48,21 +48,30 @@ public class SuggestionSpanUtils { Context.class, Locale.class, String[].class, int.class, Class.class }; Context.class, Locale.class, String[].class, int.class, Class.class }; private static final Constructor<?> CONSTRUCTOR_SuggestionSpan = CompatUtils private static final Constructor<?> CONSTRUCTOR_SuggestionSpan = CompatUtils .getConstructor(CLASS_SuggestionSpan, INPUT_TYPE_SuggestionSpan); .getConstructor(CLASS_SuggestionSpan, INPUT_TYPE_SuggestionSpan); public static final Field FIELD_FLAG_AUTO_CORRECTION public static final Field FIELD_FLAG_EASY_CORRECT = = CompatUtils.getField(CLASS_SuggestionSpan, "FLAG_AUTO_CORRECTION"); CompatUtils.getField(CLASS_SuggestionSpan, "FLAG_EASY_CORRECT"); public static final Field FIELD_FLAG_MISSPELLED = CompatUtils.getField(CLASS_SuggestionSpan, "FLAG_MISSPELLED"); public static final Field FIELD_FLAG_AUTO_CORRECTION = CompatUtils.getField(CLASS_SuggestionSpan, "FLAG_AUTO_CORRECTION"); public static final Field FIELD_SUGGESTIONS_MAX_SIZE public static final Field FIELD_SUGGESTIONS_MAX_SIZE = CompatUtils.getField(CLASS_SuggestionSpan, "SUGGESTIONS_MAX_SIZE"); = CompatUtils.getField(CLASS_SuggestionSpan, "SUGGESTIONS_MAX_SIZE"); public static final Integer OBJ_FLAG_EASY_CORRECT = (Integer) CompatUtils .getFieldValue(null, null, FIELD_FLAG_EASY_CORRECT); public static final Integer OBJ_FLAG_MISSPELLED = (Integer) CompatUtils .getFieldValue(null, null, FIELD_FLAG_MISSPELLED); public static final Integer OBJ_FLAG_AUTO_CORRECTION = (Integer) CompatUtils public static final Integer OBJ_FLAG_AUTO_CORRECTION = (Integer) CompatUtils .getFieldValue(null, null, FIELD_FLAG_AUTO_CORRECTION);; .getFieldValue(null, null, FIELD_FLAG_AUTO_CORRECTION); public static final Integer OBJ_SUGGESTIONS_MAX_SIZE = (Integer) CompatUtils public static final Integer OBJ_SUGGESTIONS_MAX_SIZE = (Integer) CompatUtils .getFieldValue(null, null, FIELD_SUGGESTIONS_MAX_SIZE);; .getFieldValue(null, null, FIELD_SUGGESTIONS_MAX_SIZE); static { static { SUGGESTION_SPAN_IS_SUPPORTED = SUGGESTION_SPAN_IS_SUPPORTED = CLASS_SuggestionSpan != null && CONSTRUCTOR_SuggestionSpan != null; CLASS_SuggestionSpan != null && CONSTRUCTOR_SuggestionSpan != null; if (LatinImeLogger.sDBG) { if (LatinImeLogger.sDBG) { if (SUGGESTION_SPAN_IS_SUPPORTED if (SUGGESTION_SPAN_IS_SUPPORTED && (OBJ_FLAG_AUTO_CORRECTION == null || OBJ_SUGGESTIONS_MAX_SIZE == null)) { && (OBJ_FLAG_AUTO_CORRECTION == null || OBJ_SUGGESTIONS_MAX_SIZE == null || OBJ_FLAG_MISSPELLED == null || OBJ_FLAG_EASY_CORRECT == null)) { throw new RuntimeException("Field is accidentially null."); throw new RuntimeException("Field is accidentially null."); } } } } Loading @@ -71,7 +80,8 @@ public class SuggestionSpanUtils { public static CharSequence getTextWithAutoCorrectionIndicatorUnderline( public static CharSequence getTextWithAutoCorrectionIndicatorUnderline( Context context, CharSequence text) { Context context, CharSequence text) { if (TextUtils.isEmpty(text) || CONSTRUCTOR_SuggestionSpan == null if (TextUtils.isEmpty(text) || CONSTRUCTOR_SuggestionSpan == null || OBJ_FLAG_AUTO_CORRECTION == null || OBJ_SUGGESTIONS_MAX_SIZE == null) { || OBJ_FLAG_AUTO_CORRECTION == null || OBJ_SUGGESTIONS_MAX_SIZE == null || OBJ_FLAG_MISSPELLED == null || OBJ_FLAG_EASY_CORRECT == null) { return text; return text; } } final Spannable spannable = text instanceof Spannable final Spannable spannable = text instanceof Spannable Loading Loading @@ -104,6 +114,7 @@ public class SuggestionSpanUtils { spannable = new SpannableString(pickedWord); spannable = new SpannableString(pickedWord); } } final ArrayList<String> suggestionsList = new ArrayList<String>(); final ArrayList<String> suggestionsList = new ArrayList<String>(); boolean sameAsTyped = false; for (int i = 0; i < suggestedWords.size(); ++i) { for (int i = 0; i < suggestedWords.size(); ++i) { if (suggestionsList.size() >= OBJ_SUGGESTIONS_MAX_SIZE) { if (suggestionsList.size() >= OBJ_SUGGESTIONS_MAX_SIZE) { break; break; Loading @@ -111,11 +122,18 @@ public class SuggestionSpanUtils { final CharSequence word = suggestedWords.getWord(i); final CharSequence word = suggestedWords.getWord(i); if (!TextUtils.equals(pickedWord, word)) { if (!TextUtils.equals(pickedWord, word)) { suggestionsList.add(word.toString()); suggestionsList.add(word.toString()); } else if (i == 0) { sameAsTyped = true; } } } } // TODO: Share the implementation for checking typed word validity between the IME // and the spell checker. final int flag = (sameAsTyped && !suggestedWords.mTypedWordValid) ? ((int)OBJ_FLAG_EASY_CORRECT | (int)OBJ_FLAG_MISSPELLED) : 0; final Object[] args = final Object[] args = { context, null, suggestionsList.toArray(new String[suggestionsList.size()]), 0, { context, null, suggestionsList.toArray(new String[suggestionsList.size()]), flag, (Class<?>) SuggestionSpanPickedNotificationReceiver.class }; (Class<?>) SuggestionSpanPickedNotificationReceiver.class }; final Object ss = CompatUtils.newInstance(CONSTRUCTOR_SuggestionSpan, args); final Object ss = CompatUtils.newInstance(CONSTRUCTOR_SuggestionSpan, args); if (ss == null) { if (ss == null) { Loading
java/src/com/android/inputmethod/latin/Utils.java +0 −4 Original line number Original line Diff line number Diff line Loading @@ -31,9 +31,7 @@ import android.os.Process; import android.text.TextUtils; import android.text.TextUtils; import android.text.format.DateUtils; import android.text.format.DateUtils; import android.util.Log; import android.util.Log; import android.view.MotionEvent; import com.android.inputmethod.keyboard.Keyboard; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo; import java.io.BufferedReader; import java.io.BufferedReader; Loading Loading @@ -112,7 +110,6 @@ public class Utils { /* package */ static final int BUFSIZE = 20; /* package */ static final int BUFSIZE = 20; private InputMethodService mContext; private InputMethodService mContext; private boolean mEnabled = false; private boolean mEnabled = false; private boolean mUsabilityStudy = false; private int mEnd = 0; private int mEnd = 0; /* package */ int mLength = 0; /* package */ int mLength = 0; private char[] mCharBuf = new char[BUFSIZE]; private char[] mCharBuf = new char[BUFSIZE]; Loading @@ -129,7 +126,6 @@ public class Utils { boolean usabilityStudy) { boolean usabilityStudy) { sRingCharBuffer.mContext = context; sRingCharBuffer.mContext = context; sRingCharBuffer.mEnabled = enabled || usabilityStudy; sRingCharBuffer.mEnabled = enabled || usabilityStudy; sRingCharBuffer.mUsabilityStudy = usabilityStudy; UsabilityStudyLogUtils.getInstance().init(context); UsabilityStudyLogUtils.getInstance().init(context); return sRingCharBuffer; return sRingCharBuffer; } } Loading