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
main
satok 2012-03-26 17:43:38 +09:00
parent a77bbc64f0
commit 356776a9b7
2 changed files with 25 additions and 11 deletions

View File

@ -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) {

View File

@ -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;
}