aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
diff options
context:
space:
mode:
authorsatok <satok@google.com>2012-03-26 17:43:38 +0900
committersatok <satok@google.com>2012-03-27 17:11:48 +0900
commit356776a9b7150d2485b340ac7f9daaef090c1f69 (patch)
treea6261ab6bbe4a10d57fd2550c696084822c7dd47 /java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
parenta77bbc64f0f7f2df25674a8e284a78a235396f4f (diff)
downloadlatinime-356776a9b7150d2485b340ac7f9daaef090c1f69.tar.gz
latinime-356776a9b7150d2485b340ac7f9daaef090c1f69.tar.xz
latinime-356776a9b7150d2485b340ac7f9daaef090c1f69.zip
Put a misspelled flag if the word is not valid by the same logic of Android spell checker.
Bug: 6222722 Currently, the flags of the suggestion span from the Latin IME is different from the flags from Android spell checker. Change-Id: I2f7a54ae0d63235a0b94e039109ab8b2f1311055
Diffstat (limited to 'java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java')
-rw-r--r--java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java32
1 files changed, 25 insertions, 7 deletions
diff --git a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
index e82d91411..a9e48404a 100644
--- a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
+++ b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java
@@ -48,21 +48,30 @@ 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_FLAG_EASY_CORRECT =
+ 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
= 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
- .getFieldValue(null, null, FIELD_FLAG_AUTO_CORRECTION);;
+ .getFieldValue(null, null, FIELD_FLAG_AUTO_CORRECTION);
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 {
SUGGESTION_SPAN_IS_SUPPORTED =
CLASS_SuggestionSpan != null && CONSTRUCTOR_SuggestionSpan != null;
if (LatinImeLogger.sDBG) {
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.");
}
}
@@ -71,7 +80,8 @@ public class SuggestionSpanUtils {
public static CharSequence getTextWithAutoCorrectionIndicatorUnderline(
Context context, CharSequence text) {
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;
}
final Spannable spannable = text instanceof Spannable
@@ -104,6 +114,7 @@ public class SuggestionSpanUtils {
spannable = new SpannableString(pickedWord);
}
final ArrayList<String> suggestionsList = new ArrayList<String>();
+ boolean sameAsTyped = false;
for (int i = 0; i < suggestedWords.size(); ++i) {
if (suggestionsList.size() >= OBJ_SUGGESTIONS_MAX_SIZE) {
break;
@@ -111,11 +122,18 @@ public class SuggestionSpanUtils {
final CharSequence word = suggestedWords.getWord(i);
if (!TextUtils.equals(pickedWord, word)) {
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 =
- { context, null, suggestionsList.toArray(new String[suggestionsList.size()]), 0,
+ { context, null, suggestionsList.toArray(new String[suggestionsList.size()]), flag,
(Class<?>) SuggestionSpanPickedNotificationReceiver.class };
final Object ss = CompatUtils.newInstance(CONSTRUCTOR_SuggestionSpan, args);
if (ss == null) {