Loading java/src/com/android/inputmethod/latin/LatinIME.java +6 −1 Original line number Diff line number Diff line Loading @@ -1729,9 +1729,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } public void showSuggestions(SuggestedWords suggestedWords, CharSequence typedWord) { final boolean shouldBlockAutoCorrectionBySafetyNet = Utils.shouldBlockAutoCorrectionBySafetyNet(suggestedWords, mSuggest); if (shouldBlockAutoCorrectionBySafetyNet) { suggestedWords.setShouldBlockAutoCorrection(); } setSuggestions(suggestedWords); if (suggestedWords.size() > 0) { if (Utils.shouldBlockedBySafetyNetForAutoCorrection(suggestedWords, mSuggest)) { if (shouldBlockAutoCorrectionBySafetyNet) { mBestWord = typedWord; } else if (suggestedWords.hasAutoCorrectionWord()) { mBestWord = suggestedWords.getWord(1); Loading java/src/com/android/inputmethod/latin/SuggestedWords.java +16 −5 Original line number Diff line number Diff line Loading @@ -29,12 +29,13 @@ public class SuggestedWords { public final List<CharSequence> mWords; public final boolean mTypedWordValid; public final boolean mHasMinimalSuggestion; public final boolean mHasAutoCorrectionCandidate; public final boolean mIsPunctuationSuggestions; private final List<SuggestedWordInfo> mSuggestedWordInfoList; private boolean mShouldBlockAutoCorrection; private SuggestedWords(List<CharSequence> words, boolean typedWordValid, boolean hasMinimalSuggestion, boolean isPunctuationSuggestions, boolean hasAutoCorrectionCandidate, boolean isPunctuationSuggestions, List<SuggestedWordInfo> suggestedWordInfoList) { if (words != null) { mWords = words; Loading @@ -42,9 +43,10 @@ public class SuggestedWords { mWords = Collections.emptyList(); } mTypedWordValid = typedWordValid; mHasMinimalSuggestion = hasMinimalSuggestion; mHasAutoCorrectionCandidate = hasAutoCorrectionCandidate; mIsPunctuationSuggestions = isPunctuationSuggestions; mSuggestedWordInfoList = suggestedWordInfoList; mShouldBlockAutoCorrection = false; } public int size() { Loading @@ -60,17 +62,25 @@ public class SuggestedWords { } public boolean hasAutoCorrectionWord() { return mHasMinimalSuggestion && size() > 1 && !mTypedWordValid; return mHasAutoCorrectionCandidate && size() > 1 && !mTypedWordValid; } public boolean hasWordAboveAutoCorrectionScoreThreshold() { return mHasMinimalSuggestion && ((size() > 1 && !mTypedWordValid) || mTypedWordValid); return mHasAutoCorrectionCandidate && ((size() > 1 && !mTypedWordValid) || mTypedWordValid); } public boolean isPunctuationSuggestions() { return mIsPunctuationSuggestions; } public void setShouldBlockAutoCorrection() { mShouldBlockAutoCorrection = true; } public boolean shouldBlockAutoCorrection() { return mShouldBlockAutoCorrection; } public static class Builder { private List<CharSequence> mWords = new ArrayList<CharSequence>(); private boolean mTypedWordValid; Loading Loading @@ -176,6 +186,7 @@ public class SuggestedWords { return mWords.get(pos); } @Override public String toString() { // Pretty-print method to help debug final StringBuilder sb = new StringBuilder("StringBuilder: mTypedWordValid = " Loading java/src/com/android/inputmethod/latin/SuggestionsView.java +6 −0 Original line number Diff line number Diff line Loading @@ -303,6 +303,12 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, } else { color = mColorTypedWord; } if (LatinImeLogger.sDBG) { if (index == mCenterSuggestionIndex && suggestions.mHasAutoCorrectionCandidate && suggestions.shouldBlockAutoCorrection()) { return 0xFFFF0000; } } final SuggestedWordInfo info = (pos < suggestions.size()) ? suggestions.getInfo(pos) : null; Loading java/src/com/android/inputmethod/latin/Utils.java +9 −5 Original line number Diff line number Diff line Loading @@ -167,7 +167,9 @@ public class Utils { throw new RuntimeException("Can not find input method id for " + packageName); } public static boolean shouldBlockedBySafetyNetForAutoCorrection(SuggestedWords suggestions, // TODO: Resolve the inconsistencies between the native auto correction algorithms and // this safety net public static boolean shouldBlockAutoCorrectionBySafetyNet(SuggestedWords suggestions, Suggest suggest) { // Safety net for auto correction. // Actually if we hit this safety net, it's actually a bug. Loading @@ -181,7 +183,8 @@ public class Utils { if (typedWord.length() < MINIMUM_SAFETY_NET_CHAR_LENGTH) return false; final CharSequence suggestionWord = suggestions.getWord(1); final int typedWordLength = typedWord.length(); final int maxEditDistanceOfNativeDictionary = typedWordLength < 5 ? 2 : typedWordLength / 2; final int maxEditDistanceOfNativeDictionary = (typedWordLength < 5 ? 2 : typedWordLength / 2) + 1; final int distance = Utils.editDistance(typedWord, suggestionWord); if (DBG) { Log.d(TAG, "Autocorrected edit distance = " + distance Loading @@ -189,8 +192,8 @@ public class Utils { } if (distance > maxEditDistanceOfNativeDictionary) { if (DBG) { Log.d(TAG, "Safety net: before = " + typedWord + ", after = " + suggestionWord); Log.w(TAG, "(Error) The edit distance of this correction exceeds limit. " Log.e(TAG, "Safety net: before = " + typedWord + ", after = " + suggestionWord); Log.e(TAG, "(Error) The edit distance of this correction exceeds limit. " + "Turning off auto-correction."); } return true; Loading Loading @@ -792,6 +795,7 @@ public class Utils { } public static boolean willAutoCorrect(SuggestedWords suggestions) { return !suggestions.mTypedWordValid && suggestions.mHasMinimalSuggestion; return !suggestions.mTypedWordValid && suggestions.mHasAutoCorrectionCandidate && !suggestions.shouldBlockAutoCorrection(); } } Loading
java/src/com/android/inputmethod/latin/LatinIME.java +6 −1 Original line number Diff line number Diff line Loading @@ -1729,9 +1729,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar } public void showSuggestions(SuggestedWords suggestedWords, CharSequence typedWord) { final boolean shouldBlockAutoCorrectionBySafetyNet = Utils.shouldBlockAutoCorrectionBySafetyNet(suggestedWords, mSuggest); if (shouldBlockAutoCorrectionBySafetyNet) { suggestedWords.setShouldBlockAutoCorrection(); } setSuggestions(suggestedWords); if (suggestedWords.size() > 0) { if (Utils.shouldBlockedBySafetyNetForAutoCorrection(suggestedWords, mSuggest)) { if (shouldBlockAutoCorrectionBySafetyNet) { mBestWord = typedWord; } else if (suggestedWords.hasAutoCorrectionWord()) { mBestWord = suggestedWords.getWord(1); Loading
java/src/com/android/inputmethod/latin/SuggestedWords.java +16 −5 Original line number Diff line number Diff line Loading @@ -29,12 +29,13 @@ public class SuggestedWords { public final List<CharSequence> mWords; public final boolean mTypedWordValid; public final boolean mHasMinimalSuggestion; public final boolean mHasAutoCorrectionCandidate; public final boolean mIsPunctuationSuggestions; private final List<SuggestedWordInfo> mSuggestedWordInfoList; private boolean mShouldBlockAutoCorrection; private SuggestedWords(List<CharSequence> words, boolean typedWordValid, boolean hasMinimalSuggestion, boolean isPunctuationSuggestions, boolean hasAutoCorrectionCandidate, boolean isPunctuationSuggestions, List<SuggestedWordInfo> suggestedWordInfoList) { if (words != null) { mWords = words; Loading @@ -42,9 +43,10 @@ public class SuggestedWords { mWords = Collections.emptyList(); } mTypedWordValid = typedWordValid; mHasMinimalSuggestion = hasMinimalSuggestion; mHasAutoCorrectionCandidate = hasAutoCorrectionCandidate; mIsPunctuationSuggestions = isPunctuationSuggestions; mSuggestedWordInfoList = suggestedWordInfoList; mShouldBlockAutoCorrection = false; } public int size() { Loading @@ -60,17 +62,25 @@ public class SuggestedWords { } public boolean hasAutoCorrectionWord() { return mHasMinimalSuggestion && size() > 1 && !mTypedWordValid; return mHasAutoCorrectionCandidate && size() > 1 && !mTypedWordValid; } public boolean hasWordAboveAutoCorrectionScoreThreshold() { return mHasMinimalSuggestion && ((size() > 1 && !mTypedWordValid) || mTypedWordValid); return mHasAutoCorrectionCandidate && ((size() > 1 && !mTypedWordValid) || mTypedWordValid); } public boolean isPunctuationSuggestions() { return mIsPunctuationSuggestions; } public void setShouldBlockAutoCorrection() { mShouldBlockAutoCorrection = true; } public boolean shouldBlockAutoCorrection() { return mShouldBlockAutoCorrection; } public static class Builder { private List<CharSequence> mWords = new ArrayList<CharSequence>(); private boolean mTypedWordValid; Loading Loading @@ -176,6 +186,7 @@ public class SuggestedWords { return mWords.get(pos); } @Override public String toString() { // Pretty-print method to help debug final StringBuilder sb = new StringBuilder("StringBuilder: mTypedWordValid = " Loading
java/src/com/android/inputmethod/latin/SuggestionsView.java +6 −0 Original line number Diff line number Diff line Loading @@ -303,6 +303,12 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, } else { color = mColorTypedWord; } if (LatinImeLogger.sDBG) { if (index == mCenterSuggestionIndex && suggestions.mHasAutoCorrectionCandidate && suggestions.shouldBlockAutoCorrection()) { return 0xFFFF0000; } } final SuggestedWordInfo info = (pos < suggestions.size()) ? suggestions.getInfo(pos) : null; Loading
java/src/com/android/inputmethod/latin/Utils.java +9 −5 Original line number Diff line number Diff line Loading @@ -167,7 +167,9 @@ public class Utils { throw new RuntimeException("Can not find input method id for " + packageName); } public static boolean shouldBlockedBySafetyNetForAutoCorrection(SuggestedWords suggestions, // TODO: Resolve the inconsistencies between the native auto correction algorithms and // this safety net public static boolean shouldBlockAutoCorrectionBySafetyNet(SuggestedWords suggestions, Suggest suggest) { // Safety net for auto correction. // Actually if we hit this safety net, it's actually a bug. Loading @@ -181,7 +183,8 @@ public class Utils { if (typedWord.length() < MINIMUM_SAFETY_NET_CHAR_LENGTH) return false; final CharSequence suggestionWord = suggestions.getWord(1); final int typedWordLength = typedWord.length(); final int maxEditDistanceOfNativeDictionary = typedWordLength < 5 ? 2 : typedWordLength / 2; final int maxEditDistanceOfNativeDictionary = (typedWordLength < 5 ? 2 : typedWordLength / 2) + 1; final int distance = Utils.editDistance(typedWord, suggestionWord); if (DBG) { Log.d(TAG, "Autocorrected edit distance = " + distance Loading @@ -189,8 +192,8 @@ public class Utils { } if (distance > maxEditDistanceOfNativeDictionary) { if (DBG) { Log.d(TAG, "Safety net: before = " + typedWord + ", after = " + suggestionWord); Log.w(TAG, "(Error) The edit distance of this correction exceeds limit. " Log.e(TAG, "Safety net: before = " + typedWord + ", after = " + suggestionWord); Log.e(TAG, "(Error) The edit distance of this correction exceeds limit. " + "Turning off auto-correction."); } return true; Loading Loading @@ -792,6 +795,7 @@ public class Utils { } public static boolean willAutoCorrect(SuggestedWords suggestions) { return !suggestions.mTypedWordValid && suggestions.mHasMinimalSuggestion; return !suggestions.mTypedWordValid && suggestions.mHasAutoCorrectionCandidate && !suggestions.shouldBlockAutoCorrection(); } }