am d4a0e746: am 5c73753e: Merge "Fix safety net not to be enabled at aggressive autocompletion mode" into honeycomb

* commit 'd4a0e7461090e9f5e9f3f9427d9b7820cea2ff7c':
  Fix safety net not to be enabled at aggressive autocompletion mode
main
satok 2011-01-26 21:20:18 -08:00 committed by Android Git Automerger
commit 15cb2e57bf
3 changed files with 14 additions and 2 deletions

View File

@ -1580,7 +1580,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void showSuggestions(SuggestedWords suggestedWords, CharSequence typedWord) { private void showSuggestions(SuggestedWords suggestedWords, CharSequence typedWord) {
setSuggestions(suggestedWords); setSuggestions(suggestedWords);
if (suggestedWords.size() > 0) { if (suggestedWords.size() > 0) {
if (Utils.shouldBlockedBySafetyNetForAutoCorrection(suggestedWords)) { if (Utils.shouldBlockedBySafetyNetForAutoCorrection(suggestedWords, mSuggest)) {
mBestWord = typedWord; mBestWord = typedWord;
} else if (suggestedWords.hasAutoCorrectionWord()) { } else if (suggestedWords.hasAutoCorrectionWord()) {
mBestWord = suggestedWords.getWord(1); mBestWord = suggestedWords.getWord(1);

View File

@ -163,6 +163,10 @@ public class Suggest implements Dictionary.WordCallback {
mAutoCorrectionThreshold = threshold; mAutoCorrectionThreshold = threshold;
} }
public boolean isAggressiveAutoCorrectionMode() {
return (mAutoCorrectionThreshold == 0);
}
/** /**
* Number of suggestions to generate from the input key sequence. This has * Number of suggestions to generate from the input key sequence. This has
* to be a number between 1 and 100 (inclusive). * to be a number between 1 and 100 (inclusive).

View File

@ -38,6 +38,7 @@ import java.util.Date;
public class Utils { public class Utils {
private static final String TAG = Utils.class.getSimpleName(); private static final String TAG = Utils.class.getSimpleName();
private static final int MINIMUM_SAFETY_NET_CHAR_LENGTH = 4;
private static boolean DBG = LatinImeLogger.sDBG; private static boolean DBG = LatinImeLogger.sDBG;
/** /**
@ -106,11 +107,18 @@ public class Utils {
throw new RuntimeException("Can not find input method id for " + packageName); throw new RuntimeException("Can not find input method id for " + packageName);
} }
public static boolean shouldBlockedBySafetyNetForAutoCorrection(SuggestedWords suggestions) { public static boolean shouldBlockedBySafetyNetForAutoCorrection(SuggestedWords suggestions,
Suggest suggest) {
// Safety net for auto correction. // Safety net for auto correction.
// Actually if we hit this safety net, it's actually a bug. // Actually if we hit this safety net, it's actually a bug.
if (suggestions.size() <= 1 || suggestions.mTypedWordValid) return false; if (suggestions.size() <= 1 || suggestions.mTypedWordValid) return false;
// If user selected aggressive auto correction mode, there is no need to use the safety
// net.
if (suggest.isAggressiveAutoCorrectionMode()) return false;
CharSequence typedWord = suggestions.getWord(0); CharSequence typedWord = suggestions.getWord(0);
// If the length of typed word is less than MINIMUM_SAFETY_NET_CHAR_LENGTH,
// we should not use net because relatively edit distance can be big.
if (typedWord.length() < MINIMUM_SAFETY_NET_CHAR_LENGTH) return false;
CharSequence candidateWord = suggestions.getWord(1); CharSequence candidateWord = suggestions.getWord(1);
final int typedWordLength = typedWord.length(); final int typedWordLength = typedWord.length();
final int maxEditDistanceOfNativeDictionary = typedWordLength < 5 ? 2 : typedWordLength / 2; final int maxEditDistanceOfNativeDictionary = typedWordLength < 5 ? 2 : typedWordLength / 2;