aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java32
-rw-r--r--java/src/com/android/inputmethod/latin/Utils.java4
2 files changed, 25 insertions, 11 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) {
diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java
index be64c2fd8..0485c881b 100644
--- a/java/src/com/android/inputmethod/latin/Utils.java
+++ b/java/src/com/android/inputmethod/latin/Utils.java
@@ -31,9 +31,7 @@ import android.os.Process;
import android.text.TextUtils;
import android.text.format.DateUtils;
import android.util.Log;
-import android.view.MotionEvent;
-import com.android.inputmethod.keyboard.Keyboard;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import java.io.BufferedReader;
@@ -112,7 +110,6 @@ public class Utils {
/* package */ static final int BUFSIZE = 20;
private InputMethodService mContext;
private boolean mEnabled = false;
- private boolean mUsabilityStudy = false;
private int mEnd = 0;
/* package */ int mLength = 0;
private char[] mCharBuf = new char[BUFSIZE];
@@ -129,7 +126,6 @@ public class Utils {
boolean usabilityStudy) {
sRingCharBuffer.mContext = context;
sRingCharBuffer.mEnabled = enabled || usabilityStudy;
- sRingCharBuffer.mUsabilityStudy = usabilityStudy;
UsabilityStudyLogUtils.getInstance().init(context);
return sRingCharBuffer;
}