Don't apply autotext to the wrong input language.

Since autotext is tied to the display language, if the input lang
is different from the display lang, don't apply autotext.

Bug: 2417495
main
Amith Yamasani 2010-02-18 11:09:43 -08:00
parent db84e0318c
commit fac5dcb5fe
2 changed files with 31 additions and 21 deletions

View File

@ -318,12 +318,14 @@ public class LatinIME extends InputMethodService
Resources orig = getResources(); Resources orig = getResources();
Configuration conf = orig.getConfiguration(); Configuration conf = orig.getConfiguration();
Locale saveLocale = conf.locale; Locale saveLocale = conf.locale;
boolean different = !conf.locale.getCountry().equalsIgnoreCase(locale.substring(0, 2));
conf.locale = new Locale(locale); conf.locale = new Locale(locale);
orig.updateConfiguration(conf, orig.getDisplayMetrics()); orig.updateConfiguration(conf, orig.getDisplayMetrics());
if (mSuggest != null) { if (mSuggest != null) {
mSuggest.close(); mSuggest.close();
} }
mSuggest = new Suggest(this, R.raw.main); mSuggest = new Suggest(this, R.raw.main);
mSuggest.setAutoTextEnabled(!different);
if (mUserDictionary != null) mUserDictionary.close(); if (mUserDictionary != null) mUserDictionary.close();
mUserDictionary = new UserDictionary(this); mUserDictionary = new UserDictionary(this);
if (mContactsDictionary == null) { if (mContactsDictionary == null) {

View File

@ -51,6 +51,8 @@ public class Suggest implements Dictionary.WordCallback {
private int mPrefMaxSuggestions = 12; private int mPrefMaxSuggestions = 12;
private boolean mAutoTextEnabled;
private int[] mPriorities = new int[mPrefMaxSuggestions]; private int[] mPriorities = new int[mPrefMaxSuggestions];
// Handle predictive correction for only the first 1280 characters for performance reasons // Handle predictive correction for only the first 1280 characters for performance reasons
// If we support scripts that need latin characters beyond that, we should probably use some // If we support scripts that need latin characters beyond that, we should probably use some
@ -76,6 +78,10 @@ public class Suggest implements Dictionary.WordCallback {
} }
} }
public void setAutoTextEnabled(boolean enabled) {
mAutoTextEnabled = enabled;
}
public int getCorrectionMode() { public int getCorrectionMode() {
return mCorrectionMode; return mCorrectionMode;
} }
@ -207,29 +213,31 @@ public class Suggest implements Dictionary.WordCallback {
mHaveCorrection = false; mHaveCorrection = false;
} }
} }
int i = 0; if (mAutoTextEnabled) {
int max = 6; int i = 0;
// Don't autotext the suggestions from the dictionaries int max = 6;
if (mCorrectionMode == CORRECTION_BASIC) max = 1; // Don't autotext the suggestions from the dictionaries
while (i < mSuggestions.size() && i < max) { if (mCorrectionMode == CORRECTION_BASIC) max = 1;
String suggestedWord = mSuggestions.get(i).toString().toLowerCase(); while (i < mSuggestions.size() && i < max) {
CharSequence autoText = String suggestedWord = mSuggestions.get(i).toString().toLowerCase();
AutoText.get(suggestedWord, 0, suggestedWord.length(), view); CharSequence autoText =
// Is there an AutoText correction? AutoText.get(suggestedWord, 0, suggestedWord.length(), view);
boolean canAdd = autoText != null; // Is there an AutoText correction?
// Is that correction already the current prediction (or original word)? boolean canAdd = autoText != null;
canAdd &= !TextUtils.equals(autoText, mSuggestions.get(i)); // Is that correction already the current prediction (or original word)?
// Is that correction already the next predicted word? canAdd &= !TextUtils.equals(autoText, mSuggestions.get(i));
if (canAdd && i + 1 < mSuggestions.size() && mCorrectionMode != CORRECTION_BASIC) { // Is that correction already the next predicted word?
canAdd &= !TextUtils.equals(autoText, mSuggestions.get(i + 1)); if (canAdd && i + 1 < mSuggestions.size() && mCorrectionMode != CORRECTION_BASIC) {
} canAdd &= !TextUtils.equals(autoText, mSuggestions.get(i + 1));
if (canAdd) { }
mHaveCorrection = true; if (canAdd) {
mSuggestions.add(i + 1, autoText); mHaveCorrection = true;
mSuggestions.add(i + 1, autoText);
i++;
}
i++; i++;
} }
i++;
} }
removeDupes(); removeDupes();