diff options
Diffstat (limited to 'java')
29 files changed, 122 insertions, 24 deletions
diff --git a/java/res/drawable-hdpi/btn_keyboard_key_dark_active_holo.9.png b/java/res/drawable-hdpi/btn_keyboard_key_dark_active_holo.9.png Binary files differindex 8bb66b722..9aa8db60e 100644 --- a/java/res/drawable-hdpi/btn_keyboard_key_dark_active_holo.9.png +++ b/java/res/drawable-hdpi/btn_keyboard_key_dark_active_holo.9.png diff --git a/java/res/drawable-hdpi/btn_keyboard_key_dark_normal_off_holo.9.png b/java/res/drawable-hdpi/btn_keyboard_key_dark_normal_off_holo.9.png Binary files differindex eb9d7406a..a3ba2230d 100644 --- a/java/res/drawable-hdpi/btn_keyboard_key_dark_normal_off_holo.9.png +++ b/java/res/drawable-hdpi/btn_keyboard_key_dark_normal_off_holo.9.png diff --git a/java/res/drawable-hdpi/btn_keyboard_key_dark_normal_on_holo.9.png b/java/res/drawable-hdpi/btn_keyboard_key_dark_normal_on_holo.9.png Binary files differindex 869a33080..9f4587b4a 100644 --- a/java/res/drawable-hdpi/btn_keyboard_key_dark_normal_on_holo.9.png +++ b/java/res/drawable-hdpi/btn_keyboard_key_dark_normal_on_holo.9.png diff --git a/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed_off_holo.9.png b/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed_off_holo.9.png Binary files differindex 72d63da61..655bc01b1 100644 --- a/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed_off_holo.9.png +++ b/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed_off_holo.9.png diff --git a/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed_on_holo.9.png b/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed_on_holo.9.png Binary files differindex fcc5cac89..138e915d9 100644 --- a/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed_on_holo.9.png +++ b/java/res/drawable-hdpi/btn_keyboard_key_dark_pressed_on_holo.9.png diff --git a/java/res/drawable-hdpi/keyboard_background_holo.9.png b/java/res/drawable-hdpi/keyboard_background_holo.9.png Binary files differindex 714db4305..73868751c 100644 --- a/java/res/drawable-hdpi/keyboard_background_holo.9.png +++ b/java/res/drawable-hdpi/keyboard_background_holo.9.png diff --git a/java/res/drawable-hdpi/sym_keyboard_search_holo.png b/java/res/drawable-hdpi/sym_keyboard_search_holo.png Binary files differindex d888214ec..b987a20f1 100644 --- a/java/res/drawable-hdpi/sym_keyboard_search_holo.png +++ b/java/res/drawable-hdpi/sym_keyboard_search_holo.png diff --git a/java/res/drawable-hdpi/sym_keyboard_settings_holo.png b/java/res/drawable-hdpi/sym_keyboard_settings_holo.png Binary files differindex c08b2b7f3..5af09ad8c 100644 --- a/java/res/drawable-hdpi/sym_keyboard_settings_holo.png +++ b/java/res/drawable-hdpi/sym_keyboard_settings_holo.png diff --git a/java/res/drawable-mdpi/btn_keyboard_key_dark_active_holo.9.png b/java/res/drawable-mdpi/btn_keyboard_key_dark_active_holo.9.png Binary files differindex c8d7ee0af..e810c7789 100644 --- a/java/res/drawable-mdpi/btn_keyboard_key_dark_active_holo.9.png +++ b/java/res/drawable-mdpi/btn_keyboard_key_dark_active_holo.9.png diff --git a/java/res/drawable-mdpi/btn_keyboard_key_dark_normal_off_holo.9.png b/java/res/drawable-mdpi/btn_keyboard_key_dark_normal_off_holo.9.png Binary files differindex 80fe863f5..fa24d5987 100644 --- a/java/res/drawable-mdpi/btn_keyboard_key_dark_normal_off_holo.9.png +++ b/java/res/drawable-mdpi/btn_keyboard_key_dark_normal_off_holo.9.png diff --git a/java/res/drawable-mdpi/btn_keyboard_key_dark_normal_on_holo.9.png b/java/res/drawable-mdpi/btn_keyboard_key_dark_normal_on_holo.9.png Binary files differindex 196d6d9bd..f3fc64114 100644 --- a/java/res/drawable-mdpi/btn_keyboard_key_dark_normal_on_holo.9.png +++ b/java/res/drawable-mdpi/btn_keyboard_key_dark_normal_on_holo.9.png diff --git a/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed_off_holo.9.png b/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed_off_holo.9.png Binary files differindex b34b95765..53ea5f894 100644 --- a/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed_off_holo.9.png +++ b/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed_off_holo.9.png diff --git a/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed_on_holo.9.png b/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed_on_holo.9.png Binary files differindex 02f4b3de9..69c84e7ec 100644 --- a/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed_on_holo.9.png +++ b/java/res/drawable-mdpi/btn_keyboard_key_dark_pressed_on_holo.9.png diff --git a/java/res/drawable-mdpi/keyboard_background_holo.9.png b/java/res/drawable-mdpi/keyboard_background_holo.9.png Binary files differindex 2776621b1..fbe97f7a2 100644 --- a/java/res/drawable-mdpi/keyboard_background_holo.9.png +++ b/java/res/drawable-mdpi/keyboard_background_holo.9.png diff --git a/java/res/drawable-mdpi/sym_keyboard_search_holo.png b/java/res/drawable-mdpi/sym_keyboard_search_holo.png Binary files differindex 9eb214a9d..dd3c83a84 100644 --- a/java/res/drawable-mdpi/sym_keyboard_search_holo.png +++ b/java/res/drawable-mdpi/sym_keyboard_search_holo.png diff --git a/java/res/drawable-mdpi/sym_keyboard_settings_holo.png b/java/res/drawable-mdpi/sym_keyboard_settings_holo.png Binary files differindex 7ac90d0f5..36c8c9623 100644 --- a/java/res/drawable-mdpi/sym_keyboard_settings_holo.png +++ b/java/res/drawable-mdpi/sym_keyboard_settings_holo.png diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_dark_active_holo.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_dark_active_holo.9.png Binary files differindex eba91db33..d990c0258 100644 --- a/java/res/drawable-xhdpi/btn_keyboard_key_dark_active_holo.9.png +++ b/java/res/drawable-xhdpi/btn_keyboard_key_dark_active_holo.9.png diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal_off_holo.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal_off_holo.9.png Binary files differindex 0f709eb02..bca39cf17 100644 --- a/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal_off_holo.9.png +++ b/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal_off_holo.9.png diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal_on_holo.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal_on_holo.9.png Binary files differindex 2f4de8ee7..ab8fb2e86 100644 --- a/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal_on_holo.9.png +++ b/java/res/drawable-xhdpi/btn_keyboard_key_dark_normal_on_holo.9.png diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed_off_holo.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed_off_holo.9.png Binary files differindex 836ea6e78..912506368 100644 --- a/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed_off_holo.9.png +++ b/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed_off_holo.9.png diff --git a/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed_on_holo.9.png b/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed_on_holo.9.png Binary files differindex 279db1f92..35ce67fdc 100644 --- a/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed_on_holo.9.png +++ b/java/res/drawable-xhdpi/btn_keyboard_key_dark_pressed_on_holo.9.png diff --git a/java/res/drawable-xhdpi/keyboard_background_holo.9.png b/java/res/drawable-xhdpi/keyboard_background_holo.9.png Binary files differindex a0aa4ba22..f5c9df3e5 100644 --- a/java/res/drawable-xhdpi/keyboard_background_holo.9.png +++ b/java/res/drawable-xhdpi/keyboard_background_holo.9.png diff --git a/java/res/drawable-xhdpi/sym_keyboard_search_holo.png b/java/res/drawable-xhdpi/sym_keyboard_search_holo.png Binary files differindex 0f4caad91..f2fb2a2b5 100644 --- a/java/res/drawable-xhdpi/sym_keyboard_search_holo.png +++ b/java/res/drawable-xhdpi/sym_keyboard_search_holo.png diff --git a/java/res/drawable-xhdpi/sym_keyboard_settings_holo.png b/java/res/drawable-xhdpi/sym_keyboard_settings_holo.png Binary files differindex 16a8aea32..99ee97dbf 100644 --- a/java/res/drawable-xhdpi/sym_keyboard_settings_holo.png +++ b/java/res/drawable-xhdpi/sym_keyboard_settings_holo.png diff --git a/java/res/values-ar/donottranslate-more-keys.xml b/java/res/values-ar/donottranslate-more-keys.xml index 2596be05d..39d38a5d9 100644 --- a/java/res/values-ar/donottranslate-more-keys.xml +++ b/java/res/values-ar/donottranslate-more-keys.xml @@ -30,7 +30,8 @@ \u0650: ARABIC KASRA \u064b: ARABIC FATHATAN \u064d: ARABIC KASRATAN --> - <string name="more_keys_for_punctuation">"\u060c,\u061b,\u061f,!,:,-,/,\',\",\u0651,\u0652,\u064c,\u0640,\u064f,\u064e,\u0650,\u064b,\u064d"</string> + <!-- In order to make Tatweel easily distinguishable from other punctuations, we use consecutive Tatweels only for its displayed label. --> + <string name="more_keys_for_punctuation">"\u060c,\u061b,\u061f,!,:,-,/,\',\",\u0651,\u0640\u0640\u0640|\u0640,\u064f,\u064e,\u0650,\u064b,\u064d"</string> <integer name="mini_keyboard_column_for_punctuation">9</integer> <string name="keyhintlabel_for_punctuation">\u064b</string> <string name="keylabel_for_symbols_1">"١"</string> @@ -73,7 +74,8 @@ <string name="keyhintlabel_for_apostrophe">"؟"</string> <string name="keyhintlabel_for_dash">"\u064b"</string> <string name="more_keys_for_apostrophe">"\u061f,\u061b,!,:,-,/,\',\""</string> - <string name="more_keys_for_dash">"\u0651,\u0652,\u064c,\u0640,\u064f,\u064e,\u0650,\u064b,\u064d"</string> + <!-- In order to make Tatweel easily distinguishable from other punctuations, we use consecutive Tatweels only for its displayed label. --> + <string name="more_keys_for_dash">"\u0651,\u0652,\u064c,\u0640\u0640\u0640|\u0640,\u064f,\u064e,\u0650,\u064b,\u064d"</string> <string name="more_keys_for_bullet">♪</string> <string name="more_keys_for_star">★</string> </resources> diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index c53d13e26..70e37a9f3 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -159,6 +159,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private Settings.Values mSettingsValues; + private View mExtractArea; private View mKeyPreviewBackingView; private View mSuggestionsContainer; private SuggestionsView mSuggestionsView; @@ -228,6 +229,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // Keeps track of most recently inserted text (multi-character key) for reverting private CharSequence mEnteredText; + private final ComposingStateManager mComposingStateManager = + new ComposingStateManager(); + public final UIHandler mHandler = new UIHandler(this); public static class UIHandler extends StaticInnerHandlerWrapper<LatinIME> { @@ -609,6 +613,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public void onConfigurationChanged(Configuration conf) { mSubtypeSwitcher.onConfigurationChanged(conf); + mComposingStateManager.onFinishComposingText(); // If orientation changed while predicting, commit the change if (mDisplayOrientation != conf.orientation) { mDisplayOrientation = conf.orientation; @@ -637,6 +642,8 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public void setInputView(View view) { super.setInputView(view); + mExtractArea = getWindow().getWindow().getDecorView() + .findViewById(android.R.id.extractArea); mKeyPreviewBackingView = view.findViewById(R.id.key_preview_backing); mSuggestionsContainer = view.findViewById(R.id.suggestions_container); mSuggestionsView = (SuggestionsView) view.findViewById(R.id.suggestions_view); @@ -880,6 +887,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (ic != null) { ic.finishComposingText(); } + mComposingStateManager.onFinishComposingText(); mVoiceProxy.setVoiceInputHighlighted(false); } else if (!mHasUncommittedTypedChars) { TextEntryState.reset(); @@ -999,11 +1007,15 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar final KeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView == null || mSuggestionsContainer == null) return; + // In fullscreen mode, the height of the extract area managed by InputMethodService should + // be considered. + // See {@link android.inputmethodservice.InputMethodService#onComputeInsets}. + final int extractHeight = isFullscreenMode() ? mExtractArea.getHeight() : 0; final int backingHeight = (mKeyPreviewBackingView.getVisibility() == View.GONE) ? 0 : mKeyPreviewBackingView.getHeight(); final int suggestionsHeight = (mSuggestionsContainer.getVisibility() == View.GONE) ? 0 : mSuggestionsContainer.getHeight(); - final int extraHeight = backingHeight + suggestionsHeight; + final int extraHeight = extractHeight + backingHeight + suggestionsHeight; int touchY = extraHeight; // Need to set touchable region only if input view is being shown if (mKeyboardSwitcher.isInputViewShown()) { @@ -1044,9 +1056,9 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar super.updateFullscreenMode(); if (mKeyPreviewBackingView == null) return; - // In fullscreen mode, no need to have extra space to show the key preview. + // In extract mode, no need to have extra space to show the key preview. // If not, we should have extra space above the keyboard to show the key preview. - mKeyPreviewBackingView.setVisibility(isFullscreenMode() ? View.GONE : View.VISIBLE); + mKeyPreviewBackingView.setVisibility(isExtractViewShown() ? View.GONE : View.VISIBLE); } @Override @@ -1335,7 +1347,12 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar if (length > 0) { mComposingStringBuilder.delete(length - 1, length); mWordComposer.deleteLast(); - ic.setComposingText(mComposingStringBuilder, 1); + final CharSequence textWithUnderline = + mComposingStateManager.isAutoCorrectionIndicatorOn() + ? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline( + this, mComposingStringBuilder) + : mComposingStringBuilder; + ic.setComposingText(textWithUnderline, 1); if (mComposingStringBuilder.length() == 0) { mHasUncommittedTypedChars = false; } @@ -1426,6 +1443,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar mComposingStringBuilder.setLength(0); mWordComposer.reset(); clearSuggestions(); + mComposingStateManager.onFinishComposingText(); } } final KeyboardSwitcher switcher = mKeyboardSwitcher; @@ -1457,8 +1475,14 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // If it's the first letter, make note of auto-caps state if (mWordComposer.size() == 1) { mWordComposer.setAutoCapitalized(getCurrentAutoCapsState()); + mComposingStateManager.onStartComposingText(); } - ic.setComposingText(mComposingStringBuilder, 1); + final CharSequence textWithUnderline = + mComposingStateManager.isAutoCorrectionIndicatorOn() + ? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline( + this, mComposingStringBuilder) + : mComposingStringBuilder; + ic.setComposingText(textWithUnderline, 1); } mHandler.postUpdateSuggestions(); } else { @@ -1477,6 +1501,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar private void handleSeparator(int primaryCode, int x, int y) { mVoiceProxy.handleSeparator(); + mComposingStateManager.onFinishComposingText(); // Should dismiss the "Touch again to save" message when handling separator if (mSuggestionsView != null && mSuggestionsView.dismissAddToDictionaryHint()) { @@ -1614,12 +1639,19 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar // Put a blue underline to a word in TextView which will be auto-corrected. final InputConnection ic = getCurrentInputConnection(); - if (ic != null && Utils.willAutoCorrect(words)) { - final CharSequence textWithUnderline = - SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline( - this, mComposingStringBuilder); - if (!TextUtils.isEmpty(textWithUnderline)) { - ic.setComposingText(textWithUnderline, 1); + if (ic != null) { + final boolean oldAutoCorrectionIndicator = + mComposingStateManager.isAutoCorrectionIndicatorOn(); + final boolean newAutoCorrectionIndicator = Utils.willAutoCorrect(words); + if (oldAutoCorrectionIndicator != newAutoCorrectionIndicator) { + final CharSequence textWithUnderline = newAutoCorrectionIndicator + ? SuggestionSpanUtils.getTextWithAutoCorrectionIndicatorUnderline( + this, mComposingStringBuilder) + : mComposingStringBuilder; + if (!TextUtils.isEmpty(textWithUnderline)) { + ic.setComposingText(textWithUnderline, 1); + } + mComposingStateManager.setAutoCorrectionIndicatorOn(newAutoCorrectionIndicator); } } } @@ -1696,9 +1728,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); @@ -1731,6 +1768,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar @Override public void pickSuggestionManually(int index, CharSequence suggestion) { + mComposingStateManager.onFinishComposingText(); SuggestedWords suggestions = mSuggestionsView.getSuggestions(); mVoiceProxy.flushAndLogAllTextModificationCounters(index, suggestion, mSettingsValues.mWordSeparators); @@ -2271,6 +2309,43 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar showOptionDialogInternal(builder.create()); } + private static class ComposingStateManager { + private boolean mAutoCorrectionIndicatorOn; + private boolean mIsComposing; + public ComposingStateManager() { + mAutoCorrectionIndicatorOn = false; + mIsComposing = false; + } + + private void onStartComposingText() { + if (!mIsComposing) { + if (LatinImeLogger.sDBG) { + Log.i(TAG, "Start composing text."); + } + mAutoCorrectionIndicatorOn = false; + mIsComposing = true; + } + } + + private void onFinishComposingText() { + if (mIsComposing) { + if (LatinImeLogger.sDBG) { + Log.i(TAG, "Finish composing text."); + } + mAutoCorrectionIndicatorOn = false; + mIsComposing = false; + } + } + + public boolean isAutoCorrectionIndicatorOn() { + return mAutoCorrectionIndicatorOn; + } + + public void setAutoCorrectionIndicatorOn(boolean on) { + mAutoCorrectionIndicatorOn = on; + } + } + @Override protected void dump(FileDescriptor fd, PrintWriter fout, String[] args) { super.dump(fd, fout, args); diff --git a/java/src/com/android/inputmethod/latin/SuggestedWords.java b/java/src/com/android/inputmethod/latin/SuggestedWords.java index 005db36bd..ed6359cfa 100644 --- a/java/src/com/android/inputmethod/latin/SuggestedWords.java +++ b/java/src/com/android/inputmethod/latin/SuggestedWords.java @@ -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; @@ -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() { @@ -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; @@ -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 = " diff --git a/java/src/com/android/inputmethod/latin/SuggestionsView.java b/java/src/com/android/inputmethod/latin/SuggestionsView.java index 3271b8253..937c2c9ff 100644 --- a/java/src/com/android/inputmethod/latin/SuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/SuggestionsView.java @@ -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; diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index 34c8c894b..b29ff1975 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -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. @@ -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 @@ -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; @@ -808,6 +811,7 @@ public class Utils { } public static boolean willAutoCorrect(SuggestedWords suggestions) { - return !suggestions.mTypedWordValid && suggestions.mHasMinimalSuggestion; + return !suggestions.mTypedWordValid && suggestions.mHasAutoCorrectionCandidate + && !suggestions.shouldBlockAutoCorrection(); } } |