diff options
Diffstat (limited to 'java/src')
6 files changed, 112 insertions, 34 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java index ef41cb6e4..e9d5580e8 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboardView.java @@ -205,10 +205,10 @@ public class LatinKeyboardView extends KeyboardView { @Override public boolean onTouchEvent(MotionEvent me) { LatinKeyboard keyboard = getLatinKeyboard(); + if (keyboard == null) return true; // If there was a sudden jump, return without processing the actual motion event. - if (handleSuddenJump(me)) - return true; + if (handleSuddenJump(me)) return true; // Reset any bounding box controls in the keyboard if (me.getAction() == MotionEvent.ACTION_DOWN) { diff --git a/java/src/com/android/inputmethod/latin/CandidateView.java b/java/src/com/android/inputmethod/latin/CandidateView.java index 30f4a59f9..d2d1f22dd 100644 --- a/java/src/com/android/inputmethod/latin/CandidateView.java +++ b/java/src/com/android/inputmethod/latin/CandidateView.java @@ -45,23 +45,22 @@ import android.widget.TextView; import java.util.ArrayList; public class CandidateView extends LinearLayout implements OnClickListener, OnLongClickListener { - private LatinIME mService; - private final ArrayList<View> mWords = new ArrayList<View>(); - private final TextView mPreviewText; - private final PopupWindow mPreviewPopup; - + private static final CharacterStyle BOLD_SPAN = new StyleSpan(Typeface.BOLD); + private static final CharacterStyle UNDERLINE_SPAN = new UnderlineSpan(); private static final int MAX_SUGGESTIONS = 16; + private final ArrayList<View> mWords = new ArrayList<View>(); private final boolean mConfigCandidateHighlightFontColorEnabled; + private final CharacterStyle mInvertedForegroundColorSpan; + private final CharacterStyle mInvertedBackgroundColorSpan; private final int mColorNormal; private final int mColorRecommended; private final int mColorOther; - private static final CharacterStyle BOLD_SPAN = new StyleSpan(Typeface.BOLD); - private static final CharacterStyle UNDERLINE_SPAN = new UnderlineSpan(); - private final CharacterStyle mInvertedForegroundColorSpan; - private final CharacterStyle mInvertedBackgroundColorSpan; + private final PopupWindow mPreviewPopup; + private final TextView mPreviewText; + private LatinIME mService; private SuggestedWords mSuggestions = SuggestedWords.EMPTY; private boolean mShowingAutoCorrectionInverted; private boolean mShowingAddToDictionary; @@ -186,9 +185,10 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo final TextView tv = (TextView)v.findViewById(R.id.candidate_word); final TextView dv = (TextView)v.findViewById(R.id.candidate_debug_info); tv.setTextColor(mColorNormal); + // TODO: Needs safety net? if (suggestions.mHasMinimalSuggestion - && ((i == 1 && !suggestions.mTypedWordValid) || - (i == 0 && suggestions.mTypedWordValid))) { + && ((i == 1 && !suggestions.mTypedWordValid) + || (i == 0 && suggestions.mTypedWordValid))) { final CharacterStyle style; if (mConfigCandidateHighlightFontColorEnabled) { style = BOLD_SPAN; @@ -329,7 +329,7 @@ public class CandidateView extends LinearLayout implements OnClickListener, OnLo mService.pickSuggestionManually(index, word); } } - + @Override public void onDetachedFromWindow() { super.onDetachedFromWindow(); diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 5d48d6b36..4e1c56cba 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -412,7 +412,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mSuggest.close(); } final SharedPreferences prefs = mPrefs; - mQuickFixes = prefs.getBoolean(Settings.PREF_QUICK_FIXES, true); + mQuickFixes = isQuickFixesEnabled(prefs); final Resources res = mResources; int mainDicResId = getMainDictionaryResourceId(res); @@ -1537,7 +1537,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private void showSuggestions(SuggestedWords suggestedWords, CharSequence typedWord) { setSuggestions(suggestedWords); if (suggestedWords.size() > 0) { - if (suggestedWords.hasAutoCorrectionWord()) { + if (Utils.shouldBlockedBySafetyNetForAutoCorrection(suggestedWords)) { + mBestWord = typedWord; + } else if (suggestedWords.hasAutoCorrectionWord()) { mBestWord = suggestedWords.getWord(1); } else { mBestWord = typedWord; @@ -2075,7 +2077,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mPopupOn = prefs.getBoolean(Settings.PREF_POPUP_ON, mResources.getBoolean(R.bool.config_default_popup_preview)); mAutoCap = prefs.getBoolean(Settings.PREF_AUTO_CAP, true); - mQuickFixes = prefs.getBoolean(Settings.PREF_QUICK_FIXES, true); + mQuickFixes = isQuickFixesEnabled(prefs); mAutoCorrectEnabled = isAutoCorrectEnabled(prefs); mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(prefs); @@ -2124,6 +2126,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mSuggest.setAutoCorrectionThreshold(autoCorrectionThreshold); } + private boolean isQuickFixesEnabled(SharedPreferences sp) { + final boolean showQuickFixesOption = mResources.getBoolean( + R.bool.config_enable_quick_fixes_option); + if (!showQuickFixesOption) { + return isAutoCorrectEnabled(sp); + } + return sp.getBoolean(Settings.PREF_QUICK_FIXES, mResources.getBoolean( + R.bool.config_default_quick_fixes)); + } + private boolean isAutoCorrectEnabled(SharedPreferences sp) { final String currentAutoCorrectionSetting = sp.getString( Settings.PREF_AUTO_CORRECTION_THRESHOLD, @@ -2134,8 +2146,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } private boolean isBigramSuggestionEnabled(SharedPreferences sp) { - // TODO: Define default value instead of 'true'. - return sp.getBoolean(Settings.PREF_BIGRAM_SUGGESTIONS, true); + final boolean showBigramSuggestionsOption = mResources.getBoolean( + R.bool.config_enable_bigram_suggestions_option); + if (!showBigramSuggestionsOption) { + return isAutoCorrectEnabled(sp); + } + return sp.getBoolean(Settings.PREF_BIGRAM_SUGGESTIONS, mResources.getBoolean( + R.bool.config_default_bigram_suggestions)); } private void initSuggestPuncList() { diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 75ebbe7e5..653dbeaba 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -1,6 +1,6 @@ /* * Copyright (C) 2008 The Android Open Source Project - * + * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at @@ -48,6 +48,7 @@ public class Settings extends PreferenceActivity DialogInterface.OnDismissListener, OnPreferenceClickListener { private static final String TAG = "Settings"; + public static final String PREF_GENERAL_SETTINGS_KEY = "general_settings"; public static final String PREF_VIBRATE_ON = "vibrate_on"; public static final String PREF_SOUND_ON = "sound_on"; public static final String PREF_POPUP_ON = "popup_on"; @@ -65,6 +66,8 @@ public class Settings extends PreferenceActivity public static final String PREF_AUTO_CORRECTION_THRESHOLD = "auto_correction_threshold"; public static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion"; + public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode"; + // Dialog ids private static final int VOICE_INPUT_CONFIRM_DIALOG = 0; @@ -111,40 +114,62 @@ public class Settings extends PreferenceActivity mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTIONS); ensureConsistencyOfAutoCorrectionSettings(); + final PreferenceGroup generalSettings = + (PreferenceGroup) findPreference(PREF_GENERAL_SETTINGS_KEY); + final PreferenceGroup textCorrectionGroup = + (PreferenceGroup) findPreference(PREF_PREDICTION_SETTINGS_KEY); + final boolean showSettingsKeyOption = getResources().getBoolean( R.bool.config_enable_show_settings_key_option); if (!showSettingsKeyOption) { - getPreferenceScreen().removePreference(mSettingsKeyPreference); + generalSettings.removePreference(mSettingsKeyPreference); } final boolean showVoiceKeyOption = getResources().getBoolean( R.bool.config_enable_show_voice_key_option); if (!showVoiceKeyOption) { - getPreferenceScreen().removePreference(mVoicePreference); + generalSettings.removePreference(mVoicePreference); } Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); if (vibrator == null || !vibrator.hasVibrator()) { - getPreferenceScreen().removePreference( - getPreferenceScreen().findPreference(PREF_VIBRATE_ON)); + generalSettings.removePreference(findPreference(PREF_VIBRATE_ON)); } final boolean showSubtypeSettings = getResources().getBoolean( R.bool.config_enable_show_subtype_settings); if (!showSubtypeSettings) { - getPreferenceScreen().removePreference(findPreference(PREF_SUBTYPES)); + generalSettings.removePreference(findPreference(PREF_SUBTYPES)); } final boolean showPopupOption = getResources().getBoolean( R.bool.config_enable_show_popup_on_keypress_option); if (!showPopupOption) { - getPreferenceScreen().removePreference(findPreference(PREF_POPUP_ON)); + generalSettings.removePreference(findPreference(PREF_POPUP_ON)); } final boolean showRecorrectionOption = getResources().getBoolean( R.bool.config_enable_show_recorrection_option); if (!showRecorrectionOption) { - getPreferenceScreen().removePreference(findPreference(PREF_RECORRECTION_ENABLED)); + generalSettings.removePreference(findPreference(PREF_RECORRECTION_ENABLED)); + } + + final boolean showQuickFixesOption = getResources().getBoolean( + R.bool.config_enable_quick_fixes_option); + if (!showQuickFixesOption) { + textCorrectionGroup.removePreference(findPreference(PREF_QUICK_FIXES)); + } + + final boolean showBigramSuggestionsOption = getResources().getBoolean( + R.bool.config_enable_bigram_suggestions_option); + if (!showBigramSuggestionsOption) { + textCorrectionGroup.removePreference(findPreference(PREF_BIGRAM_SUGGESTIONS)); + } + + final boolean showUsabilityModeStudyOption = getResources().getBoolean( + R.bool.config_enable_usability_study_mode_option); + if (!showUsabilityModeStudyOption) { + getPreferenceScreen().removePreference(findPreference(PREF_USABILITY_STUDY_MODE)); } } diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index a8454b23e..24c73e8ea 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -31,7 +31,7 @@ import java.util.Arrays; */ public class Suggest implements Dictionary.WordCallback { - public static final String TAG = "Suggest"; + public static final String TAG = Suggest.class.getSimpleName(); public static final int APPROX_MAX_WORD_LENGTH = 32; @@ -64,6 +64,8 @@ public class Suggest implements Dictionary.WordCallback { static final int LARGE_DICTIONARY_THRESHOLD = 200 * 1000; + private static boolean DBG = LatinImeLogger.sDBG; + private BinaryDictionary mMainDict; private Dictionary mUserDictionary; @@ -93,7 +95,7 @@ public class Suggest implements Dictionary.WordCallback { private ArrayList<CharSequence> mSuggestions = new ArrayList<CharSequence>(); ArrayList<CharSequence> mBigramSuggestions = new ArrayList<CharSequence>(); private ArrayList<CharSequence> mStringPool = new ArrayList<CharSequence>(); - private boolean mHaveCorrection; + private boolean mHaveAutoCorrection; private String mLowerOriginalWord; // TODO: Remove these member variables by passing more context to addWord() callback method @@ -198,7 +200,7 @@ public class Suggest implements Dictionary.WordCallback { public SuggestedWords.Builder getSuggestedWordBuilder(View view, WordComposer wordComposer, CharSequence prevWordForBigram) { LatinImeLogger.onStartSuggestion(prevWordForBigram); - mHaveCorrection = false; + mHaveAutoCorrection = false; mIsFirstCharCapitalized = wordComposer.isFirstCharCapitalized(); mIsAllUpperCase = wordComposer.isAllUpperCase(); collectGarbage(mSuggestions, mPrefMaxSuggestions); @@ -273,7 +275,10 @@ public class Suggest implements Dictionary.WordCallback { if (mSuggestions.size() > 0 && isValidWord(typedWord) && (mCorrectionMode == CORRECTION_FULL || mCorrectionMode == CORRECTION_FULL_BIGRAM)) { - mHaveCorrection = true; + if (DBG) { + Log.d(TAG, "Auto corrected by CORRECTION_FULL."); + } + mHaveAutoCorrection = true; } } if (mMainDict != null) mMainDict.getWords(wordComposer, this, mNextLettersFrequencies); @@ -289,7 +294,10 @@ public class Suggest implements Dictionary.WordCallback { + "(" + mAutoCorrectionThreshold + ")"); } if (normalizedScore >= mAutoCorrectionThreshold) { - mHaveCorrection = true; + if (DBG) { + Log.d(TAG, "Auto corrected by S-threthhold."); + } + mHaveAutoCorrection = true; } } } @@ -331,7 +339,10 @@ public class Suggest implements Dictionary.WordCallback { canAdd &= !TextUtils.equals(autoText, mSuggestions.get(i + 1)); } if (canAdd) { - mHaveCorrection = true; + if (DBG) { + Log.d(TAG, "Auto corrected by AUTOTEXT."); + } + mHaveAutoCorrection = true; mSuggestions.add(i + 1, autoText); i++; } @@ -374,7 +385,7 @@ public class Suggest implements Dictionary.WordCallback { } public boolean hasMinimalCorrection() { - return mHaveCorrection; + return mHaveAutoCorrection; } private boolean compareCaseInsensitive(final String mLowerOriginalWord, diff --git a/java/src/com/android/inputmethod/latin/Utils.java b/java/src/com/android/inputmethod/latin/Utils.java index 753e5d64f..d2582b115 100644 --- a/java/src/com/android/inputmethod/latin/Utils.java +++ b/java/src/com/android/inputmethod/latin/Utils.java @@ -36,6 +36,8 @@ import java.text.SimpleDateFormat; import java.util.Date; public class Utils { + private static final String TAG = Utils.class.getSimpleName(); + private static boolean DBG = LatinImeLogger.sDBG; /** * Cancel an {@link AsyncTask}. @@ -95,6 +97,29 @@ public class Utils { || imm.getEnabledInputMethodSubtypeList(null, false).size() > 1; } + + public static boolean shouldBlockedBySafetyNetForAutoCorrection(SuggestedWords suggestions) { + // Safety net for auto correction. + // Actually if we hit this safety net, it's actually a bug. + if (suggestions.size() <= 1 || suggestions.mTypedWordValid) return false; + CharSequence typedWord = suggestions.getWord(0); + CharSequence candidateWord = suggestions.getWord(1); + final int typedWordLength = typedWord.length(); + final int maxEditDistanceOfNativeDictionary = typedWordLength < 5 ? 2 : typedWordLength / 2; + final int distance = Utils.editDistance(typedWord, candidateWord); + if (DBG) { + Log.d(TAG, "Autocorrected edit distance = " + distance + + ", " + maxEditDistanceOfNativeDictionary); + } + if (distance > maxEditDistanceOfNativeDictionary) { + Log.w(TAG, "(Error) The edit distance of this correction exceeds limit. " + + "Turning off auto-correction."); + return true; + } else { + return false; + } + } + /* package */ static class RingCharBuffer { private static RingCharBuffer sRingCharBuffer = new RingCharBuffer(); private static final char PLACEHOLDER_DELIMITER_CHAR = '\uFFFC'; |