Merge "Stop a flag from escaping."

main
Jean Chalard 2011-12-08 23:14:15 -08:00 committed by Android (Google) Code Review
commit 284c8a0449
4 changed files with 26 additions and 33 deletions

View File

@ -1791,8 +1791,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
prevWord = EditingUtils.getPreviousWord(ic, mSettingsValues.mWordSeparators); prevWord = EditingUtils.getPreviousWord(ic, mSettingsValues.mWordSeparators);
} }
// getSuggestedWordBuilder handles gracefully a null value of prevWord // getSuggestedWordBuilder handles gracefully a null value of prevWord
final SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder( final SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(wordComposer,
wordComposer, prevWord, mKeyboardSwitcher.getLatinKeyboard().getProximityInfo()); prevWord, mKeyboardSwitcher.getLatinKeyboard().getProximityInfo(), mCorrectionMode);
boolean autoCorrectionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasAutoCorrection(); boolean autoCorrectionAvailable = !mInputTypeNoAutoCorrect && mSuggest.hasAutoCorrection();
final CharSequence typedWord = wordComposer.getTypedWord(); final CharSequence typedWord = wordComposer.getTypedWord();
@ -2035,7 +2035,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
final CharSequence prevWord = EditingUtils.getThisWord(getCurrentInputConnection(), final CharSequence prevWord = EditingUtils.getThisWord(getCurrentInputConnection(),
mSettingsValues.mWordSeparators); mSettingsValues.mWordSeparators);
SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(sEmptyWordComposer, SuggestedWords.Builder builder = mSuggest.getSuggestedWordBuilder(sEmptyWordComposer,
prevWord, mKeyboardSwitcher.getLatinKeyboard().getProximityInfo()); prevWord, mKeyboardSwitcher.getLatinKeyboard().getProximityInfo(), mCorrectionMode);
if (builder.size() > 0) { if (builder.size() > 0) {
// Explicitly supply an empty typed word (the no-second-arg version of // Explicitly supply an empty typed word (the no-second-arg version of
@ -2399,9 +2399,6 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
mCorrectionMode = shouldAutoCorrect ? Suggest.CORRECTION_FULL : Suggest.CORRECTION_NONE; mCorrectionMode = shouldAutoCorrect ? Suggest.CORRECTION_FULL : Suggest.CORRECTION_NONE;
mCorrectionMode = (mSettingsValues.mBigramSuggestionEnabled && shouldAutoCorrect) mCorrectionMode = (mSettingsValues.mBigramSuggestionEnabled && shouldAutoCorrect)
? Suggest.CORRECTION_FULL_BIGRAM : mCorrectionMode; ? Suggest.CORRECTION_FULL_BIGRAM : mCorrectionMode;
if (mSuggest != null) {
mSuggest.setCorrectionMode(mCorrectionMode);
}
} }
private void updateSuggestionVisibility(final SharedPreferences prefs, final Resources res) { private void updateSuggestionVisibility(final SharedPreferences prefs, final Resources res) {

View File

@ -43,9 +43,8 @@ public class Suggest implements Dictionary.WordCallback {
public static final int APPROX_MAX_WORD_LENGTH = 32; public static final int APPROX_MAX_WORD_LENGTH = 32;
public static final int CORRECTION_NONE = 0; public static final int CORRECTION_NONE = 0;
public static final int CORRECTION_BASIC = 1; public static final int CORRECTION_FULL = 1;
public static final int CORRECTION_FULL = 2; public static final int CORRECTION_FULL_BIGRAM = 2;
public static final int CORRECTION_FULL_BIGRAM = 3;
/** /**
* Words that appear in both bigram and unigram data gets multiplier ranging from * Words that appear in both bigram and unigram data gets multiplier ranging from
@ -109,8 +108,6 @@ public class Suggest implements Dictionary.WordCallback {
private boolean mIsAllUpperCase; private boolean mIsAllUpperCase;
private int mTrailingSingleQuotesCount; private int mTrailingSingleQuotesCount;
private int mCorrectionMode = CORRECTION_BASIC;
public Suggest(final Context context, final int dictionaryResId, final Locale locale) { public Suggest(final Context context, final int dictionaryResId, final Locale locale) {
initAsynchronously(context, dictionaryResId, locale); initAsynchronously(context, dictionaryResId, locale);
} }
@ -171,10 +168,6 @@ public class Suggest implements Dictionary.WordCallback {
}.start(); }.start();
} }
public void setCorrectionMode(int mode) {
mCorrectionMode = mode;
}
// The main dictionary could have been loaded asynchronously. Don't cache the return value // The main dictionary could have been loaded asynchronously. Don't cache the return value
// of this method. // of this method.
public boolean hasMainDictionary() { public boolean hasMainDictionary() {
@ -253,9 +246,10 @@ public class Suggest implements Dictionary.WordCallback {
* @return suggested words object. * @return suggested words object.
*/ */
public SuggestedWords getSuggestions(final WordComposer wordComposer, public SuggestedWords getSuggestions(final WordComposer wordComposer,
final CharSequence prevWordForBigram, final ProximityInfo proximityInfo) { final CharSequence prevWordForBigram, final ProximityInfo proximityInfo,
final int correctionMode) {
return getSuggestedWordBuilder(wordComposer, prevWordForBigram, return getSuggestedWordBuilder(wordComposer, prevWordForBigram,
proximityInfo).build(); proximityInfo, correctionMode).build();
} }
private CharSequence capitalizeWord(boolean all, boolean first, CharSequence word) { private CharSequence capitalizeWord(boolean all, boolean first, CharSequence word) {
@ -288,7 +282,7 @@ public class Suggest implements Dictionary.WordCallback {
// TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder // TODO: cleanup dictionaries looking up and suggestions building with SuggestedWords.Builder
public SuggestedWords.Builder getSuggestedWordBuilder( public SuggestedWords.Builder getSuggestedWordBuilder(
final WordComposer wordComposer, CharSequence prevWordForBigram, final WordComposer wordComposer, CharSequence prevWordForBigram,
final ProximityInfo proximityInfo) { final ProximityInfo proximityInfo, final int correctionMode) {
LatinImeLogger.onStartSuggestion(prevWordForBigram); LatinImeLogger.onStartSuggestion(prevWordForBigram);
mAutoCorrection.init(); mAutoCorrection.init();
mIsFirstCharCapitalized = wordComposer.isFirstCharCapitalized(); mIsFirstCharCapitalized = wordComposer.isFirstCharCapitalized();
@ -308,8 +302,7 @@ public class Suggest implements Dictionary.WordCallback {
} }
mConsideredWord = consideredWord; mConsideredWord = consideredWord;
if (wordComposer.size() <= 1 && (mCorrectionMode == CORRECTION_FULL_BIGRAM if (wordComposer.size() <= 1 && (correctionMode == CORRECTION_FULL_BIGRAM)) {
|| mCorrectionMode == CORRECTION_BASIC)) {
// At first character typed, search only the bigrams // At first character typed, search only the bigrams
Arrays.fill(mBigramScores, 0); Arrays.fill(mBigramScores, 0);
collectGarbage(mBigramSuggestions, PREF_MAX_BIGRAMS); collectGarbage(mBigramSuggestions, PREF_MAX_BIGRAMS);
@ -373,7 +366,7 @@ public class Suggest implements Dictionary.WordCallback {
mWhiteListDictionary.getWhitelistedWord(consideredWordString)); mWhiteListDictionary.getWhitelistedWord(consideredWordString));
mAutoCorrection.updateAutoCorrectionStatus(mUnigramDictionaries, wordComposer, mAutoCorrection.updateAutoCorrectionStatus(mUnigramDictionaries, wordComposer,
mSuggestions, mScores, consideredWord, mAutoCorrectionThreshold, mCorrectionMode, mSuggestions, mScores, consideredWord, mAutoCorrectionThreshold, correctionMode,
whitelistedWord); whitelistedWord);
if (whitelistedWord != null) { if (whitelistedWord != null) {

View File

@ -28,6 +28,7 @@ import java.util.Locale;
public class SuggestHelper { public class SuggestHelper {
protected final Suggest mSuggest; protected final Suggest mSuggest;
protected int mCorrectionMode;
protected final LatinKeyboard mKeyboard; protected final LatinKeyboard mKeyboard;
private final KeyDetector mKeyDetector; private final KeyDetector mKeyDetector;
@ -50,14 +51,14 @@ public class SuggestHelper {
} }
private void init() { private void init() {
mSuggest.setCorrectionMode(Suggest.CORRECTION_FULL); setCorrectionMode(Suggest.CORRECTION_FULL);
mKeyDetector.setKeyboard(mKeyboard, 0, 0); mKeyDetector.setKeyboard(mKeyboard, 0, 0);
mKeyDetector.setProximityCorrectionEnabled(true); mKeyDetector.setProximityCorrectionEnabled(true);
mKeyDetector.setProximityThreshold(mKeyboard.mMostCommonKeyWidth); mKeyDetector.setProximityThreshold(mKeyboard.mMostCommonKeyWidth);
} }
public void setCorrectionMode(int correctionMode) { public void setCorrectionMode(int correctionMode) {
mSuggest.setCorrectionMode(correctionMode); mCorrectionMode = correctionMode;
} }
public boolean hasMainDictionary() { public boolean hasMainDictionary() {
@ -78,13 +79,13 @@ public class SuggestHelper {
// TODO: This may be slow, but is OK for test so far. // TODO: This may be slow, but is OK for test so far.
public SuggestedWords getSuggestions(CharSequence typed) { public SuggestedWords getSuggestions(CharSequence typed) {
return mSuggest.getSuggestions(createWordComposer(typed), null, return mSuggest.getSuggestions(createWordComposer(typed), null,
mKeyboard.getProximityInfo()); mKeyboard.getProximityInfo(), mCorrectionMode);
} }
public CharSequence getFirstSuggestion(CharSequence typed) { public CharSequence getFirstSuggestion(CharSequence typed) {
WordComposer word = createWordComposer(typed); WordComposer word = createWordComposer(typed);
SuggestedWords suggestions = mSuggest.getSuggestions(word, null, SuggestedWords suggestions = mSuggest.getSuggestions(word, null,
mKeyboard.getProximityInfo()); mKeyboard.getProximityInfo(), mCorrectionMode);
// Note that suggestions.getWord(0) is the word user typed. // Note that suggestions.getWord(0) is the word user typed.
return suggestions.size() > 1 ? suggestions.getWord(1) : null; return suggestions.size() > 1 ? suggestions.getWord(1) : null;
} }
@ -92,7 +93,7 @@ public class SuggestHelper {
public CharSequence getAutoCorrection(CharSequence typed) { public CharSequence getAutoCorrection(CharSequence typed) {
WordComposer word = createWordComposer(typed); WordComposer word = createWordComposer(typed);
SuggestedWords suggestions = mSuggest.getSuggestions(word, null, SuggestedWords suggestions = mSuggest.getSuggestions(word, null,
mKeyboard.getProximityInfo()); mKeyboard.getProximityInfo(), mCorrectionMode);
// Note that suggestions.getWord(0) is the word user typed. // Note that suggestions.getWord(0) is the word user typed.
return (suggestions.size() > 1 && mSuggest.hasAutoCorrection()) return (suggestions.size() > 1 && mSuggest.hasAutoCorrection())
? suggestions.getWord(1) : null; ? suggestions.getWord(1) : null;
@ -101,7 +102,7 @@ public class SuggestHelper {
public int getSuggestIndex(CharSequence typed, CharSequence expected) { public int getSuggestIndex(CharSequence typed, CharSequence expected) {
WordComposer word = createWordComposer(typed); WordComposer word = createWordComposer(typed);
SuggestedWords suggestions = mSuggest.getSuggestions(word, null, SuggestedWords suggestions = mSuggest.getSuggestions(word, null,
mKeyboard.getProximityInfo()); mKeyboard.getProximityInfo(), mCorrectionMode);
// Note that suggestions.getWord(0) is the word user typed. // Note that suggestions.getWord(0) is the word user typed.
for (int i = 1; i < suggestions.size(); i++) { for (int i = 1; i < suggestions.size(); i++) {
if (TextUtils.equals(suggestions.getWord(i), expected)) if (TextUtils.equals(suggestions.getWord(i), expected))
@ -113,7 +114,8 @@ public class SuggestHelper {
private void getBigramSuggestions(CharSequence previous, CharSequence typed) { private void getBigramSuggestions(CharSequence previous, CharSequence typed) {
if (!TextUtils.isEmpty(previous) && (typed.length() > 1)) { if (!TextUtils.isEmpty(previous) && (typed.length() > 1)) {
WordComposer firstChar = createWordComposer(Character.toString(typed.charAt(0))); WordComposer firstChar = createWordComposer(Character.toString(typed.charAt(0)));
mSuggest.getSuggestions(firstChar, previous, mKeyboard.getProximityInfo()); mSuggest.getSuggestions(firstChar, previous, mKeyboard.getProximityInfo(),
mCorrectionMode);
} }
} }
@ -121,7 +123,7 @@ public class SuggestHelper {
WordComposer word = createWordComposer(typed); WordComposer word = createWordComposer(typed);
getBigramSuggestions(previous, typed); getBigramSuggestions(previous, typed);
SuggestedWords suggestions = mSuggest.getSuggestions(word, previous, SuggestedWords suggestions = mSuggest.getSuggestions(word, previous,
mKeyboard.getProximityInfo()); mKeyboard.getProximityInfo(), mCorrectionMode);
return suggestions.size() > 1 ? suggestions.getWord(1) : null; return suggestions.size() > 1 ? suggestions.getWord(1) : null;
} }
@ -129,7 +131,7 @@ public class SuggestHelper {
WordComposer word = createWordComposer(typed); WordComposer word = createWordComposer(typed);
getBigramSuggestions(previous, typed); getBigramSuggestions(previous, typed);
SuggestedWords suggestions = mSuggest.getSuggestions(word, previous, SuggestedWords suggestions = mSuggest.getSuggestions(word, previous,
mKeyboard.getProximityInfo()); mKeyboard.getProximityInfo(), mCorrectionMode);
return (suggestions.size() > 1 && mSuggest.hasAutoCorrection()) return (suggestions.size() > 1 && mSuggest.hasAutoCorrection())
? suggestions.getWord(1) : null; ? suggestions.getWord(1) : null;
} }
@ -139,7 +141,7 @@ public class SuggestHelper {
WordComposer word = createWordComposer(typed); WordComposer word = createWordComposer(typed);
getBigramSuggestions(previous, typed); getBigramSuggestions(previous, typed);
SuggestedWords suggestions = mSuggest.getSuggestions(word, previous, SuggestedWords suggestions = mSuggest.getSuggestions(word, previous,
mKeyboard.getProximityInfo()); mKeyboard.getProximityInfo(), mCorrectionMode);
for (int i = 1; i < suggestions.size(); i++) { for (int i = 1; i < suggestions.size(); i++) {
if (TextUtils.equals(suggestions.getWord(i), expected)) if (TextUtils.equals(suggestions.getWord(i), expected))
return i; return i;

View File

@ -38,7 +38,7 @@ public class UserBigramSuggestHelper extends SuggestHelper {
Suggest.DIC_USER); Suggest.DIC_USER);
mUserBigram.setDatabaseMax(userBigramMax); mUserBigram.setDatabaseMax(userBigramMax);
mUserBigram.setDatabaseDelete(userBigramDelete); mUserBigram.setDatabaseDelete(userBigramDelete);
mSuggest.setCorrectionMode(Suggest.CORRECTION_FULL_BIGRAM); setCorrectionMode(Suggest.CORRECTION_FULL_BIGRAM);
mSuggest.setUserBigramDictionary(mUserBigram); mSuggest.setUserBigramDictionary(mUserBigram);
} }
@ -59,7 +59,8 @@ public class UserBigramSuggestHelper extends SuggestHelper {
flushUserBigrams(); flushUserBigrams();
if (!TextUtils.isEmpty(previous) && !TextUtils.isEmpty(Character.toString(typed))) { if (!TextUtils.isEmpty(previous) && !TextUtils.isEmpty(Character.toString(typed))) {
WordComposer firstChar = createWordComposer(Character.toString(typed)); WordComposer firstChar = createWordComposer(Character.toString(typed));
mSuggest.getSuggestions(firstChar, previous, mKeyboard.getProximityInfo()); mSuggest.getSuggestions(firstChar, previous, mKeyboard.getProximityInfo(),
mCorrectionMode);
boolean reloading = mUserBigram.reloadDictionaryIfRequired(); boolean reloading = mUserBigram.reloadDictionaryIfRequired();
if (reloading) mUserBigram.waitForDictionaryLoading(); if (reloading) mUserBigram.waitForDictionaryLoading();
mUserBigram.getBigrams(firstChar, previous, mSuggest); mUserBigram.getBigrams(firstChar, previous, mSuggest);