diff options
Diffstat (limited to 'java/src')
5 files changed, 92 insertions, 91 deletions
diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 51e878c88..cd57db360 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -74,9 +74,9 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha private int mMode = KeyboardId.MODE_TEXT; /* default value */ private int mImeOptions; private boolean mIsSymbols; - /** mIsAutoCompletionActive indicates that auto completed word will be input instead of + /** mIsAutoCorrectionActive indicates that auto corrected word will be input instead of * what user actually typed. */ - private boolean mIsAutoCompletionActive; + private boolean mIsAutoCorrectionActive; private boolean mVoiceKeyEnabled; private boolean mVoiceButtonOnPrimary; private int mSymbolsModeState = SYMBOLS_MODE_STATE_NONE; @@ -197,7 +197,7 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha Log.d(TAG, "keyboard cache size=" + mKeyboardCache.size() + ": HIT id=" + id); } - keyboard.onAutoCompletionStateChanged(mIsAutoCompletionActive); + keyboard.onAutoCorrectionStateChanged(mIsAutoCorrectionActive); keyboard.setShifted(false); return keyboard; } @@ -617,12 +617,12 @@ public class KeyboardSwitcher implements SharedPreferences.OnSharedPreferenceCha ? mInputView.getColorScheme() : KeyboardView.COLOR_SCHEME_WHITE; } - public void onAutoCompletionStateChanged(boolean isAutoCompletion) { - if (isAutoCompletion != mIsAutoCompletionActive) { + public void onAutoCorrectionStateChanged(boolean isAutoCorrection) { + if (isAutoCorrection != mIsAutoCorrectionActive) { LatinKeyboardView keyboardView = getInputView(); - mIsAutoCompletionActive = isAutoCompletion; + mIsAutoCorrectionActive = isAutoCorrection; keyboardView.invalidateKey(((LatinKeyboard) keyboardView.getKeyboard()) - .onAutoCompletionStateChanged(isAutoCompletion)); + .onAutoCorrectionStateChanged(isAutoCorrection)); } } diff --git a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java index 8087f030e..0a42857ff 100644 --- a/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java +++ b/java/src/com/android/inputmethod/keyboard/LatinKeyboard.java @@ -45,7 +45,7 @@ public class LatinKeyboard extends Keyboard { private static final int SPACE_LED_LENGTH_PERCENT = 80; private Drawable mShiftLockPreviewIcon; - private Drawable mSpaceAutoCompletionIndicator; + private Drawable mSpaceAutoCorrectionIndicator; private final Drawable mButtonArrowLeftIcon; private final Drawable mButtonArrowRightIcon; private final int mSpaceBarTextShadowColor; @@ -89,7 +89,7 @@ public class LatinKeyboard extends Keyboard { } mShiftLockPreviewIcon = res.getDrawable(R.drawable.sym_keyboard_feedback_shift_locked); setDefaultBounds(mShiftLockPreviewIcon); - mSpaceAutoCompletionIndicator = res.getDrawable(R.drawable.sym_keyboard_space_led); + mSpaceAutoCorrectionIndicator = res.getDrawable(R.drawable.sym_keyboard_space_led); mButtonArrowLeftIcon = res.getDrawable(R.drawable.sym_keyboard_language_arrows_left); mButtonArrowRightIcon = res.getDrawable(R.drawable.sym_keyboard_language_arrows_right); sSpacebarVerticalCorrection = res.getDimensionPixelOffset( @@ -100,22 +100,22 @@ public class LatinKeyboard extends Keyboard { /** * @return a key which should be invalidated. */ - public Key onAutoCompletionStateChanged(boolean isAutoCompletion) { - updateSpaceBarForLocale(isAutoCompletion); + public Key onAutoCorrectionStateChanged(boolean isAutoCorrection) { + updateSpaceBarForLocale(isAutoCorrection); return mSpaceKey; } - private void updateSpaceBarForLocale(boolean isAutoCompletion) { + private void updateSpaceBarForLocale(boolean isAutoCorrection) { final Resources res = mRes; // If application locales are explicitly selected. if (SubtypeSwitcher.getInstance().needsToDisplayLanguage()) { mSpaceKey.setIcon(new BitmapDrawable(res, - drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCompletion))); + drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCorrection))); } else { // sym_keyboard_space_led can be shared with Black and White symbol themes. - if (isAutoCompletion) { + if (isAutoCorrection) { mSpaceKey.setIcon(new BitmapDrawable(res, - drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCompletion))); + drawSpaceBar(OPACITY_FULLY_OPAQUE, isAutoCorrection))); } else { mSpaceKey.setIcon(mSpaceIcon); } @@ -173,7 +173,7 @@ public class LatinKeyboard extends Keyboard { } @SuppressWarnings("unused") - private Bitmap drawSpaceBar(int opacity, boolean isAutoCompletion) { + private Bitmap drawSpaceBar(int opacity, boolean isAutoCorrection) { final int width = mSpaceKey.mWidth; final int height = mSpaceIcon.getIntrinsicHeight(); final Bitmap buffer = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); @@ -212,13 +212,13 @@ public class LatinKeyboard extends Keyboard { } // Draw the spacebar icon at the bottom - if (isAutoCompletion) { + if (isAutoCorrection) { final int iconWidth = width * SPACE_LED_LENGTH_PERCENT / 100; - final int iconHeight = mSpaceAutoCompletionIndicator.getIntrinsicHeight(); + final int iconHeight = mSpaceAutoCorrectionIndicator.getIntrinsicHeight(); int x = (width - iconWidth) / 2; int y = height - iconHeight; - mSpaceAutoCompletionIndicator.setBounds(x, y, x + iconWidth, y + iconHeight); - mSpaceAutoCompletionIndicator.draw(canvas); + mSpaceAutoCorrectionIndicator.setBounds(x, y, x + iconWidth, y + iconHeight); + mSpaceAutoCorrectionIndicator.draw(canvas); } else { final int iconWidth = mSpaceIcon.getIntrinsicWidth(); final int iconHeight = mSpaceIcon.getIntrinsicHeight(); diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 46b735ab2..a34d883ba 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -63,6 +63,7 @@ import android.view.ViewParent; import android.view.Window; import android.view.WindowManager; import android.view.inputmethod.CompletionInfo; +import android.view.inputmethod.CorrectionInfo; import android.view.inputmethod.EditorInfo; import android.view.inputmethod.ExtractedText; import android.view.inputmethod.ExtractedTextRequest; @@ -119,7 +120,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private View mCandidateViewContainer; private CandidateView mCandidateView; private Suggest mSuggest; - private CompletionInfo[] mCompletions; + private CompletionInfo[] mApplicationSpecifiedCompletions; private AlertDialog mOptionsDialog; @@ -141,7 +142,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private CharSequence mBestWord; private boolean mPredicting; private boolean mPredictionOn; - private boolean mCompletionOn; + private boolean mApplicationSpecifiedCompletionOn; private boolean mHasDictionary; private boolean mAutoSpace; private boolean mJustAddedAutoSpace; @@ -393,7 +394,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen int[] dictionaries = getDictionary(orig); mSuggest = new Suggest(this, dictionaries); - loadAndSetAutoCompletionThreshold(prefs); + loadAndSetAutoCorrectionThreshold(prefs); if (mUserDictionary != null) mUserDictionary.close(); mUserDictionary = new UserDictionary(this, locale); if (mContactsDictionary == null) { @@ -519,8 +520,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mVoiceConnector.resetVoiceStates(isPasswordVariation(variation)); mInputTypeNoAutoCorrect = false; mPredictionOn = false; - mCompletionOn = false; - mCompletions = null; + mApplicationSpecifiedCompletionOn = false; + mApplicationSpecifiedCompletions = null; mEnteredText = null; final int mode; @@ -579,7 +580,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } if ((attribute.inputType & InputType.TYPE_TEXT_FLAG_AUTO_COMPLETE) != 0) { mPredictionOn = false; - mCompletionOn = isFullscreenMode(); + mApplicationSpecifiedCompletionOn = isFullscreenMode(); } break; default: @@ -654,7 +655,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen super.onFinishInput(); LatinImeLogger.commit(); - mKeyboardSwitcher.onAutoCompletionStateChanged(false); + mKeyboardSwitcher.onAutoCorrectionStateChanged(false); mVoiceConnector.flushVoiceInputLogs(mConfigurationChanging); @@ -789,7 +790,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void hideWindow() { LatinImeLogger.commit(); - mKeyboardSwitcher.onAutoCompletionStateChanged(false); + mKeyboardSwitcher.onAutoCorrectionStateChanged(false); if (TRACE) Debug.stopMethodTracing(); if (mOptionsDialog != null && mOptionsDialog.isShowing()) { @@ -803,22 +804,24 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } @Override - public void onDisplayCompletions(CompletionInfo[] completions) { + public void onDisplayCompletions(CompletionInfo[] applicationSpecifiedCompletions) { if (DEBUG) { Log.i("foo", "Received completions:"); - for (int i=0; i<(completions != null ? completions.length : 0); i++) { - Log.i("foo", " #" + i + ": " + completions[i]); + final int count = (applicationSpecifiedCompletions != null) + ? applicationSpecifiedCompletions.length : 0; + for (int i = 0; i < count; i++) { + Log.i("foo", " #" + i + ": " + applicationSpecifiedCompletions[i]); } } - if (mCompletionOn) { - mCompletions = completions; - if (completions == null) { + if (mApplicationSpecifiedCompletionOn) { + mApplicationSpecifiedCompletions = applicationSpecifiedCompletions; + if (applicationSpecifiedCompletions == null) { clearSuggestions(); return; } SuggestedWords.Builder builder = new SuggestedWords.Builder() - .setApplicationSpecifiedCompletions(completions) + .setApplicationSpecifiedCompletions(applicationSpecifiedCompletions) .setTypedWordValid(true) .setHasMinimalSuggestion(true); // When in fullscreen mode, show completions generated by the application @@ -1291,7 +1294,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen boolean pickedDefault = false; // Handle separator - InputConnection ic = getCurrentInputConnection(); + final InputConnection ic = getCurrentInputConnection(); if (ic != null) { ic.beginBatchEdit(); abortCorrection(false); @@ -1392,8 +1395,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private boolean isCandidateStripVisible() { boolean forceVisible = mCandidateView.isShowingAddToDictionaryHint() || TextEntryState.isCorrecting(); - return forceVisible || (isSuggestionShown() - && (isPredictionOn() || mCompletionOn || isShowingPunctuationList())); + return forceVisible || ( + isSuggestionShown() && (isPredictionOn() || mApplicationSpecifiedCompletionOn + || isShowingPunctuationList())); } public void switchToKeyboardView() { @@ -1431,7 +1435,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (mCandidateView != null) { mCandidateView.setSuggestions(words); if (mCandidateView.isConfigCandidateHighlightFontColorEnabled()) - mKeyboardSwitcher.onAutoCompletionStateChanged(words.hasAutoCorrectionWord()); + mKeyboardSwitcher.onAutoCorrectionStateChanged(words.hasAutoCorrectionWord()); } } @@ -1537,9 +1541,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (ic != null) { ic.beginBatchEdit(); } - if (mCompletionOn && mCompletions != null && index >= 0 - && index < mCompletions.length) { - CompletionInfo ci = mCompletions[index]; + if (mApplicationSpecifiedCompletionOn && mApplicationSpecifiedCompletions != null + && index >= 0 && index < mApplicationSpecifiedCompletions.length) { + CompletionInfo ci = mApplicationSpecifiedCompletions[index]; if (ic != null) { ic.commitCompletion(ci); } @@ -1650,7 +1654,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen break; } } - // If we didn't find a match, at least suggest completions + // If we didn't find a match, at least suggest corrections. if (foundWord == null && (mSuggest.isValidWord(touching.mWord) || mSuggest.isValidWord(touching.mWord.toString().toLowerCase()))) { @@ -2038,7 +2042,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mAutoCorrectEnabled = isAutoCorrectEnabled(prefs); mBigramSuggestionEnabled = mAutoCorrectEnabled && isBigramSuggestionEnabled(prefs); - loadAndSetAutoCompletionThreshold(prefs); + loadAndSetAutoCorrectionThreshold(prefs); mVoiceConnector.loadSettings(attribute, prefs); @@ -2049,50 +2053,47 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } /** - * load Auto completion threshold from SharedPreferences, - * and modify mSuggest's threshold. + * Load Auto correction threshold from SharedPreferences, and modify mSuggest's threshold. */ - private void loadAndSetAutoCompletionThreshold(SharedPreferences sp) { + private void loadAndSetAutoCorrectionThreshold(SharedPreferences sp) { // When mSuggest is not initialized, cannnot modify mSuggest's threshold. if (mSuggest == null) return; - // When auto completion setting is turned off, the threshold is ignored. + // When auto correction setting is turned off, the threshold is ignored. if (!isAutoCorrectEnabled(sp)) return; - final String currentAutoCompletionSetting = sp.getString( - Settings.PREF_AUTO_COMPLETION_THRESHOLD, - mResources.getString(R.string.auto_completion_threshold_mode_value_modest)); - final String[] autoCompletionThresholdValues = mResources.getStringArray( - R.array.auto_complete_threshold_values); - // When autoCompletionThreshold is greater than 1.0, - // auto completion is virtually turned off. - double autoCompletionThreshold = Double.MAX_VALUE; + final String currentAutoCorrectionSetting = sp.getString( + Settings.PREF_AUTO_CORRECTION_THRESHOLD, + mResources.getString(R.string.auto_correction_threshold_mode_value_modest)); + final String[] autoCorrectionThresholdValues = mResources.getStringArray( + R.array.auto_correction_threshold_mode_values); + // When autoCrrectionThreshold is greater than 1.0, auto correction is virtually turned off. + double autoCorrectionThreshold = Double.MAX_VALUE; try { - final int arrayIndex = Integer.valueOf(currentAutoCompletionSetting); - if (arrayIndex >= 0 && arrayIndex < autoCompletionThresholdValues.length) { - autoCompletionThreshold = Double.parseDouble( - autoCompletionThresholdValues[arrayIndex]); + final int arrayIndex = Integer.valueOf(currentAutoCorrectionSetting); + if (arrayIndex >= 0 && arrayIndex < autoCorrectionThresholdValues.length) { + autoCorrectionThreshold = Double.parseDouble( + autoCorrectionThresholdValues[arrayIndex]); } } catch (NumberFormatException e) { - // Whenever the threshold settings are correct, - // never come here. - autoCompletionThreshold = Double.MAX_VALUE; - Log.w(TAG, "Cannot load auto completion threshold setting." - + " currentAutoCompletionSetting: " + currentAutoCompletionSetting - + ", autoCompletionThresholdValues: " - + Arrays.toString(autoCompletionThresholdValues)); + // Whenever the threshold settings are correct, never come here. + autoCorrectionThreshold = Double.MAX_VALUE; + Log.w(TAG, "Cannot load auto correction threshold setting." + + " currentAutoCorrectionSetting: " + currentAutoCorrectionSetting + + ", autoCorrectionThresholdValues: " + + Arrays.toString(autoCorrectionThresholdValues)); } // TODO: This should be refactored : - // setAutoCompleteThreshold should be called outside of this method. - mSuggest.setAutoCompleteThreshold(autoCompletionThreshold); + // setAutoCorrectionThreshold should be called outside of this method. + mSuggest.setAutoCorrectionThreshold(autoCorrectionThreshold); } private boolean isAutoCorrectEnabled(SharedPreferences sp) { - final String currentAutoCompletionSetting = sp.getString( - Settings.PREF_AUTO_COMPLETION_THRESHOLD, - mResources.getString(R.string.auto_completion_threshold_mode_value_modest)); - final String autoCompletionOff = mResources.getString( - R.string.auto_completion_threshold_mode_value_off); - return !currentAutoCompletionSetting.equals(autoCompletionOff); + final String currentAutoCorrectionSetting = sp.getString( + Settings.PREF_AUTO_CORRECTION_THRESHOLD, + mResources.getString(R.string.auto_correction_threshold_mode_value_modest)); + final String autoCorrectionOff = mResources.getString( + R.string.auto_correction_threshold_mode_value_off); + return !currentAutoCorrectionSetting.equals(autoCorrectionOff); } private boolean isBigramSuggestionEnabled(SharedPreferences sp) { @@ -2166,7 +2167,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen p.println(" mPredicting=" + mPredicting); p.println(" mAutoCorrectOn=" + mAutoCorrectOn); p.println(" mAutoSpace=" + mAutoSpace); - p.println(" mCompletionOn=" + mCompletionOn); + p.println(" mApplicationSpecifiedCompletionOn=" + mApplicationSpecifiedCompletionOn); p.println(" TextEntryState.state=" + TextEntryState.getState()); p.println(" mSoundOn=" + mSoundOn); p.println(" mVibrateOn=" + mVibrateOn); diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 9c7c5aa71..d2ec917d0 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -57,7 +57,7 @@ public class Settings extends PreferenceActivity public static final String PREF_PREDICTION_SETTINGS_KEY = "prediction_settings"; public static final String PREF_QUICK_FIXES = "quick_fixes"; public static final String PREF_SHOW_SUGGESTIONS_SETTING = "show_suggestions_setting"; - public static final String PREF_AUTO_COMPLETION_THRESHOLD = "auto_completion_threshold"; + public static final String PREF_AUTO_CORRECTION_THRESHOLD = "auto_correction_threshold"; public static final String PREF_BIGRAM_SUGGESTIONS = "bigram_suggestion"; // Dialog ids @@ -66,7 +66,7 @@ public class Settings extends PreferenceActivity private CheckBoxPreference mQuickFixes; private ListPreference mVoicePreference; private ListPreference mSettingsKeyPreference; - private ListPreference mAutoCompletionThreshold; + private ListPreference mAutoCorrectionThreshold; private CheckBoxPreference mBigramSuggestion; private boolean mVoiceOn; @@ -77,11 +77,11 @@ public class Settings extends PreferenceActivity private boolean mOkClicked = false; private String mVoiceModeOff; - private void ensureConsistencyOfAutoCompletionSettings() { - final String autoCompletionOff = getResources().getString( - R.string.auto_completion_threshold_mode_value_off); - final String currentSetting = mAutoCompletionThreshold.getValue(); - mBigramSuggestion.setEnabled(!currentSetting.equals(autoCompletionOff)); + private void ensureConsistencyOfAutoCorrectionSettings() { + final String autoCorrectionOff = getResources().getString( + R.string.auto_correction_threshold_mode_value_off); + final String currentSetting = mAutoCorrectionThreshold.getValue(); + mBigramSuggestion.setEnabled(!currentSetting.equals(autoCorrectionOff)); } @Override protected void onCreate(Bundle icicle) { @@ -98,9 +98,9 @@ public class Settings extends PreferenceActivity .equals(mVoiceModeOff)); mLogger = VoiceInputLogger.getLogger(this); - mAutoCompletionThreshold = (ListPreference) findPreference(PREF_AUTO_COMPLETION_THRESHOLD); + mAutoCorrectionThreshold = (ListPreference) findPreference(PREF_AUTO_CORRECTION_THRESHOLD); mBigramSuggestion = (CheckBoxPreference) findPreference(PREF_BIGRAM_SUGGESTIONS); - ensureConsistencyOfAutoCompletionSettings(); + ensureConsistencyOfAutoCorrectionSettings(); final boolean showSettingsKeyOption = getResources().getBoolean( R.bool.config_enable_show_settings_key_option); @@ -155,7 +155,7 @@ public class Settings extends PreferenceActivity showVoiceConfirmation(); } } - ensureConsistencyOfAutoCompletionSettings(); + ensureConsistencyOfAutoCorrectionSettings(); mVoiceOn = !(prefs.getString(PREF_VOICE_SETTINGS_KEY, mVoiceModeOff) .equals(mVoiceModeOff)); updateVoiceModeSummary(); diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 237d7cb67..77e0a3dde 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -81,7 +81,7 @@ public class Suggest implements Dictionary.WordCallback { private boolean mAutoTextEnabled; - private double mAutoCompleteThreshold; + private double mAutoCorrectionThreshold; private int[] mPriorities = new int[mPrefMaxSuggestions]; private int[] mBigramPriorities = new int[PREF_MAX_BIGRAMS]; @@ -164,8 +164,8 @@ public class Suggest implements Dictionary.WordCallback { mUserBigramDictionary = userBigramDictionary; } - public void setAutoCompleteThreshold(double threshold) { - mAutoCompleteThreshold = threshold; + public void setAutoCorrectionThreshold(double threshold) { + mAutoCorrectionThreshold = threshold; } /** @@ -294,9 +294,9 @@ public class Suggest implements Dictionary.WordCallback { if (LatinImeLogger.sDBG) { Log.d(TAG, "Normalized " + mOriginalWord + "," + mSuggestions.get(0) + "," + mPriorities[0] + normalizedScore - + "(" + mAutoCompleteThreshold + ")"); + + "(" + mAutoCorrectionThreshold + ")"); } - if (normalizedScore >= mAutoCompleteThreshold) { + if (normalizedScore >= mAutoCorrectionThreshold) { mHaveCorrection = true; } } |