diff options
Diffstat (limited to 'java')
12 files changed, 54 insertions, 47 deletions
diff --git a/java/res/values/config.xml b/java/res/values/config.xml index f0b12e92b..133bb0a06 100644 --- a/java/res/values/config.xml +++ b/java/res/values/config.xml @@ -22,17 +22,17 @@ <bool name="config_use_fullscreen_mode">false</bool> <bool name="config_enable_show_voice_key_option">true</bool> <bool name="config_enable_show_popup_on_keypress_option">true</bool> - <bool name="config_enable_bigram_suggestions_option">true</bool> + <bool name="config_enable_next_word_suggestions_option">true</bool> <!-- TODO: Disable the following configuration for production. --> <bool name="config_enable_usability_study_mode_option">true</bool> <!-- Whether or not Popup on key press is enabled by default --> <bool name="config_default_popup_preview">true</bool> - <!-- Default value for bigram suggestion: while showing suggestions for a word should we weigh + <!-- Default value for next word suggestion: while showing suggestions for a word should we weigh in the previous word? --> - <bool name="config_default_bigram_suggestions">true</bool> - <!-- Default value for bigram prediction: after entering a word and a space only, should we look + <bool name="config_default_next_word_suggestions">true</bool> + <!-- Default value for next word prediction: after entering a word and a space only, should we look at input history to suggest a hopefully helpful suggestions for the next word? --> - <bool name="config_default_bigram_prediction">false</bool> + <bool name="config_default_next_word_prediction">true</bool> <bool name="config_default_sound_enabled">false</bool> <bool name="config_default_vibration_enabled">true</bool> <integer name="config_delay_update_suggestions">100</integer> diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index a22c68cb8..28acd0fcc 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -118,13 +118,13 @@ <!-- Option to suggest auto correction suggestions very aggressively. Auto-corrects to a word which has even large edit distance from typed word. [CHAR LIMIT=20] --> <string name="auto_correction_threshold_mode_very_aggeressive">Very aggressive</string> - <!-- Option to enable bigram correction --> - <string name="bigram_suggestion">Bigram suggestions</string> - <!-- Description for auto correction --> - <string name="bigram_suggestion_summary">Use previous word to improve suggestion</string> - <!-- Option to enable using user-history bigram when no input --> - <string name="bigram_prediction">Bigram prediction</string> - <!-- Description for auto correction --> + <!-- Option to enable next word correction --> + <string name="bigram_suggestion">Next word suggestions</string> + <!-- Option to enable next word suggestion. This uses the previous word in an attempt to improve the suggestions quality --> + <string name="bigram_suggestion_summary">Use previous word to improve suggestions</string> + <!-- Option to enable using next word prediction --> + <string name="bigram_prediction">Next word prediction</string> + <!-- Description for "next word prediction" option. This displays suggestions even when there is no input, based on the previous word. --> <string name="bigram_prediction_summary">Use previous word also for prediction</string> <!-- Indicates that a word has been added to the dictionary --> diff --git a/java/res/xml/prefs.xml b/java/res/xml/prefs.xml index c5c647aac..ab5d44b24 100644 --- a/java/res/xml/prefs.xml +++ b/java/res/xml/prefs.xml @@ -111,18 +111,18 @@ android:persistent="true" android:defaultValue="true" /> <CheckBoxPreference - android:key="bigram_suggestion" + android:key="next_word_suggestion" android:title="@string/bigram_suggestion" android:summary="@string/bigram_suggestion_summary" android:persistent="true" android:defaultValue="true" /> <CheckBoxPreference - android:key="bigram_prediction" - android:dependency="bigram_suggestion" + android:key="next_word_prediction" + android:dependency="next_word_suggestion" android:title="@string/bigram_prediction" android:summary="@string/bigram_prediction_summary" android:persistent="true" - android:defaultValue="false" /> + android:defaultValue="true" /> <CheckBoxPreference android:key="enable_span_insert" android:title="@string/enable_span_insert" diff --git a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java index 5c351e41f..43c19d7eb 100644 --- a/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java +++ b/java/src/com/android/inputmethod/compat/SuggestionSpanUtils.java @@ -136,6 +136,8 @@ public class SuggestionSpanUtils { ? (OBJ_FLAG_EASY_CORRECT | OBJ_FLAG_MISSPELLED) : 0; + // TODO: We should avoid adding suggestion span candidates that came from the bigram + // prediction. final Object[] args = { context, null, suggestionsList.toArray(new String[suggestionsList.size()]), flag, (Class<?>) SuggestionSpanPickedNotificationReceiver.class }; diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java index efa4021b0..f9b6b72c7 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSet.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSet.java @@ -25,6 +25,7 @@ import android.text.InputType; import android.util.Log; import android.util.Xml; import android.view.inputmethod.EditorInfo; +import android.view.inputmethod.InputMethodSubtype; import com.android.inputmethod.compat.EditorInfoCompatUtils; import com.android.inputmethod.keyboard.KeyboardSet.Params.ElementParams; @@ -242,7 +243,10 @@ public class KeyboardSet { return this; } - public Builder setSubtype(Locale inputLocale, boolean asciiCapable) { + public Builder setSubtype(InputMethodSubtype subtype) { + final Locale inputLocale = SubtypeLocale.getSubtypeLocale(subtype); + final boolean asciiCapable = subtype.containsExtraValueKey( + LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE); final boolean deprecatedForceAscii = StringUtils.inPrivateImeOptions( mPackageName, LatinIME.IME_OPTION_FORCE_ASCII, mEditorInfo); final boolean forceAscii = EditorInfoCompatUtils.hasFlagForceAscii( diff --git a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java index 93d8704de..3bc63f3dd 100644 --- a/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java +++ b/java/src/com/android/inputmethod/keyboard/KeyboardSwitcher.java @@ -137,10 +137,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions { final KeyboardSet.Builder builder = new KeyboardSet.Builder(mThemeContext, editorInfo); builder.setScreenGeometry(mThemeContext.getResources().getConfiguration().orientation, mThemeContext.getResources().getDisplayMetrics().widthPixels); - builder.setSubtype( - mSubtypeSwitcher.getInputLocale(), - mSubtypeSwitcher.currentSubtypeContainsExtraValueKey( - LatinIME.SUBTYPE_EXTRA_VALUE_ASCII_CAPABLE)); + builder.setSubtype(mSubtypeSwitcher.getCurrentSubtype()); builder.setOptions( settingsValues.isVoiceKeyEnabled(editorInfo), settingsValues.isVoiceKeyOnMain(), @@ -384,7 +381,7 @@ public class KeyboardSwitcher implements KeyboardState.SwitchActions { public void onNetworkStateChanged() { if (mKeyboardView != null) { - mKeyboardView.updateShortcutKey(SubtypeSwitcher.getInstance().isShortcutImeReady()); + mKeyboardView.updateShortcutKey(mSubtypeSwitcher.isShortcutImeReady()); } } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index db57044e9..8a26d2b9e 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -713,9 +713,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mSuggest.setAutoCorrectionThreshold(mSettingsValues.mAutoCorrectionThreshold); } - if (mSubtypeSwitcher.isKeyboardMode()) { - switcher.loadKeyboard(editorInfo, mSettingsValues); - } + switcher.loadKeyboard(editorInfo, mSettingsValues); if (mSuggestionsView != null) mSuggestionsView.clear(); diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 7b98a7188..6bc049894 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -66,8 +66,8 @@ public class Settings extends InputMethodSettingsActivity public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY = "pref_key_preview_popup_dismiss_delay"; public static final String PREF_KEY_USE_CONTACTS_DICT = "pref_key_use_contacts_dict"; - public static final String PREF_BIGRAM_SUGGESTION = "bigram_suggestion"; - public static final String PREF_BIGRAM_PREDICTIONS = "bigram_prediction"; + public static final String PREF_BIGRAM_SUGGESTION = "next_word_suggestion"; + public static final String PREF_BIGRAM_PREDICTIONS = "next_word_prediction"; public static final String PREF_KEY_ENABLE_SPAN_INSERT = "enable_span_insert"; public static final String PREF_VIBRATION_DURATION_SETTINGS = "pref_vibration_duration_settings"; @@ -167,7 +167,7 @@ public class Settings extends InputMethodSettingsActivity } final boolean showBigramSuggestionsOption = res.getBoolean( - R.bool.config_enable_bigram_suggestions_option); + R.bool.config_enable_next_word_suggestions_option); if (!showBigramSuggestionsOption) { textCorrectionGroup.removePreference(mBigramSuggestion); if (null != mBigramPrediction) { diff --git a/java/src/com/android/inputmethod/latin/SettingsValues.java b/java/src/com/android/inputmethod/latin/SettingsValues.java index 103678403..49ab7f9d7 100644 --- a/java/src/com/android/inputmethod/latin/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/SettingsValues.java @@ -236,18 +236,18 @@ public class SettingsValues { private static boolean isBigramSuggestionEnabled(final SharedPreferences sp, final Resources resources, final boolean autoCorrectEnabled) { final boolean showBigramSuggestionsOption = resources.getBoolean( - R.bool.config_enable_bigram_suggestions_option); + R.bool.config_enable_next_word_suggestions_option); if (!showBigramSuggestionsOption) { return autoCorrectEnabled; } return sp.getBoolean(Settings.PREF_BIGRAM_SUGGESTION, resources.getBoolean( - R.bool.config_default_bigram_suggestions)); + R.bool.config_default_next_word_suggestions)); } private static boolean isBigramPredictionEnabled(final SharedPreferences sp, final Resources resources) { return sp.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, resources.getBoolean( - R.bool.config_default_bigram_prediction)); + R.bool.config_default_next_word_prediction)); } private static double getAutoCorrectionThreshold(final Resources resources, diff --git a/java/src/com/android/inputmethod/latin/SubtypeLocale.java b/java/src/com/android/inputmethod/latin/SubtypeLocale.java index ba67f3358..fac74f0b5 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeLocale.java +++ b/java/src/com/android/inputmethod/latin/SubtypeLocale.java @@ -18,6 +18,7 @@ package com.android.inputmethod.latin; import android.content.Context; import android.content.res.Resources; +import android.view.inputmethod.InputMethodSubtype; import java.util.Locale; @@ -120,4 +121,14 @@ public class SubtypeLocale { // - It also does not work with unicode surrogate code points. return s.toUpperCase(locale).charAt(0) + s.substring(1); } + + public static String getSubtypeLocaleString(InputMethodSubtype subtype) { + final String keyboardLocale = subtype.getExtraValueOf( + LatinIME.SUBTYPE_EXTRA_VALUE_KEYBOARD_LOCALE); + return keyboardLocale != null ? keyboardLocale : subtype.getLocale(); + } + + public static Locale getSubtypeLocale(InputMethodSubtype subtype) { + return LocaleUtils.constructLocaleFromString(getSubtypeLocaleString(subtype)); + } } diff --git a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java index 7541bd31b..3ed7f8700 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java +++ b/java/src/com/android/inputmethod/latin/SubtypeSwitcher.java @@ -419,30 +419,23 @@ public class SubtypeSwitcher { } } - public boolean isKeyboardMode() { + // TODO: Remove this method + private boolean isKeyboardMode() { return KEYBOARD_MODE.equals(getCurrentSubtypeMode()); } - ///////////////////////////// - // Other utility functions // - ///////////////////////////// - - public String getCurrentSubtypeExtraValue() { - // If null, return what an empty ExtraValue would return : the empty string. - return mCurrentSubtype.getExtraValue(); + // TODO: Remove this method + private String getCurrentSubtypeMode() { + return mCurrentSubtype.getMode(); } + // TODO: Remove this method public boolean currentSubtypeContainsExtraValueKey(String key) { // If null, return what an empty ExtraValue would return : false. return mCurrentSubtype.containsExtraValueKey(key); } - public String getCurrentSubtypeExtraValueOf(String key) { - // If null, return what an empty ExtraValue would return : null. - return mCurrentSubtype.getExtraValueOf(key); - } - - public String getCurrentSubtypeMode() { - return mCurrentSubtype.getMode(); + public InputMethodSubtype getCurrentSubtype() { + return mCurrentSubtype; } } diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index b31f3019c..0fcac58a6 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -261,7 +261,9 @@ public class Suggest implements Dictionary.WordCallback { SuggestedWordInfo.removeDups(mSuggestions); return new SuggestedWords(mSuggestions, - false /* typedWordValid */, + // TODO: Just assuming the suggestions that came from the bigram prediction are + // valid now. Need to assign a correct value for typedWordValid. + true /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* allowsToBeAutoCorrected */, false /* isPunctuationSuggestions */, |