diff options
author | 2015-03-13 14:50:54 -0700 | |
---|---|---|
committer | 2015-03-16 11:23:22 -0700 | |
commit | 5455179b54eb8230577f518db082796a3055685a (patch) | |
tree | 9e5c38575cbee4e96e2325e8c211a5b2a3a3d5fc | |
parent | 180a1e363f84f425e1b1d001e15e28df03f9181e (diff) | |
download | latinime-5455179b54eb8230577f518db082796a3055685a.tar.gz latinime-5455179b54eb8230577f518db082796a3055685a.tar.xz latinime-5455179b54eb8230577f518db082796a3055685a.zip |
Revert "Next-word suggestion bit in keyboard settings."
This reverts commit 1ae16dc3db170802d1b38273f477125a2a969d32.
Bug 19596067.
Change-Id: Ie7286acbb70b215d7bd08e271bcf14526b68576f
11 files changed, 101 insertions, 15 deletions
diff --git a/java/res/values/config-common.xml b/java/res/values/config-common.xml index be22cceea..fb20f7c3a 100644 --- a/java/res/values/config-common.xml +++ b/java/res/values/config-common.xml @@ -20,6 +20,9 @@ <resources> <bool name="config_block_potentially_offensive">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_next_word_prediction">true</bool> <integer name="config_delay_in_milliseconds_to_update_shift_state">100</integer> <integer name="config_double_space_period_timeout">1100</integer> diff --git a/java/res/values/strings.xml b/java/res/values/strings.xml index e4b3883af..54579f2d6 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -157,6 +157,11 @@ <!-- 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_aggressive">Very aggressive</string> + <!-- Option to enable using next word suggestions. After the user types a space, with this option on, the keyboard will try to predict the next word. --> + <string name="bigram_prediction">Next-word suggestions</string> + <!-- Description for "next word suggestion" option. This displays suggestions even when there is no input, based on the previous word. --> + <string name="bigram_prediction_summary">Use the previous word in making suggestions</string> + <!-- Option to enable gesture input. The user can input a word by tracing the letters of a word without releasing the finger from the screen. [CHAR LIMIT=30]--> <string name="gesture_input">Enable gesture typing</string> <!-- Description for "gesture_input" option. The user can input a word by tracing the letters of a word without releasing the finger from the screen. [CHAR LIMIT=65]--> diff --git a/java/res/xml/prefs_screen_correction.xml b/java/res/xml/prefs_screen_correction.xml index 284231bf1..a943dc1a3 100644 --- a/java/res/xml/prefs_screen_correction.xml +++ b/java/res/xml/prefs_screen_correction.xml @@ -65,4 +65,10 @@ android:summary="@string/use_contacts_dict_summary" android:defaultValue="true" android:persistent="true" /> + <CheckBoxPreference + android:key="next_word_prediction" + android:title="@string/bigram_prediction" + android:summary="@string/bigram_prediction_summary" + android:defaultValue="true" + android:persistent="true" /> </PreferenceScreen> diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 9fab6b413..4ddde1926 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1530,7 +1530,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // punctuation suggestions (if it's disabled). @Override public void setNeutralSuggestionStrip() { - setSuggestedWords(SuggestedWords.getEmptyInstance()); + final SettingsValues currentSettings = mSettings.getCurrent(); + final SuggestedWords neutralSuggestions = currentSettings.mBigramPredictionEnabled + ? SuggestedWords.getEmptyInstance() + : currentSettings.mSpacingAndPunctuations.mSuggestPuncList; + setSuggestedWords(neutralSuggestions); } // TODO: Make this private diff --git a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java index f3840f74e..7e513e5c3 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -1395,6 +1395,11 @@ public final class InputLogic { return; } + if (!mWordComposer.isComposingWord() && !settingsValues.mBigramPredictionEnabled) { + mSuggestionStripViewAccessor.setNeutralSuggestionStrip(); + return; + } + final AsyncResultHolder<SuggestedWords> holder = new AsyncResultHolder<>(); mInputLogicHandler.getSuggestedWords(inputStyle, SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() { diff --git a/java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java b/java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java index 44c47fdfa..24c39ebc4 100644 --- a/java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java +++ b/java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java @@ -19,10 +19,12 @@ package com.android.inputmethod.latin.settings; import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; import android.os.Build; import android.os.Bundle; +import android.preference.CheckBoxPreference; import android.preference.Preference; import com.android.inputmethod.dictionarypack.DictionarySettingsActivity; @@ -59,6 +61,8 @@ public final class CorrectionSettingsFragment extends SubScreenFragment { final Context context = getActivity(); final PackageManager pm = context.getPackageManager(); + ensureConsistencyOfAutoCorrectionSettings(); + final Preference dictionaryLink = findPreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY); final Intent intent = dictionaryLink.getIntent(); intent.setClassName(context.getPackageName(), DictionarySettingsActivity.class.getName()); @@ -78,6 +82,19 @@ public final class CorrectionSettingsFragment extends SubScreenFragment { } } + @Override + public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) { + ensureConsistencyOfAutoCorrectionSettings(); + } + + private void ensureConsistencyOfAutoCorrectionSettings() { + final CheckBoxPreference autoCorrectionPref = (CheckBoxPreference) findPreference( + Settings.PREF_AUTO_CORRECTION); + if (!autoCorrectionPref.isChecked()) { + setPreferenceEnabled(Settings.PREF_BIGRAM_PREDICTIONS, false); + } + } + private void overwriteUserDictionaryPreference(final Preference userDictionaryPreference) { final Activity activity = getActivity(); final TreeSet<String> localeList = UserDictionaryList.getUserDictionaryLocalesSet(activity); diff --git a/java/src/com/android/inputmethod/latin/settings/Settings.java b/java/src/com/android/inputmethod/latin/settings/Settings.java index 6567e7159..715f7bb38 100644 --- a/java/src/com/android/inputmethod/latin/settings/Settings.java +++ b/java/src/com/android/inputmethod/latin/settings/Settings.java @@ -83,6 +83,7 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang // TODO: consolidate key preview dismiss delay with the key preview animation parameters. public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY = "pref_key_preview_popup_dismiss_delay"; + public static final String PREF_BIGRAM_PREDICTIONS = "next_word_prediction"; public static final String PREF_GESTURE_INPUT = "gesture_input"; public static final String PREF_VIBRATION_DURATION_SETTINGS = "pref_vibration_duration_settings"; diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java index 3dbbfad9d..112d78639 100644 --- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java @@ -73,6 +73,8 @@ public class SettingsValues { public final boolean mUsePersonalizedDicts; public final boolean mUseDoubleSpacePeriod; public final boolean mBlockPotentiallyOffensive; + // Use bigrams to predict the next word when there is no input for it yet + public final boolean mBigramPredictionEnabled; public final boolean mGestureInputEnabled; public final boolean mGestureTrailEnabled; public final boolean mGestureFloatingPreviewTextEnabled; @@ -149,6 +151,7 @@ public class SettingsValues { final String autoCorrectionThresholdRawValue = mAutoCorrectEnabled ? res.getString(R.string.auto_correction_threshold_mode_index_modest) : res.getString(R.string.auto_correction_threshold_mode_index_off); + mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res); mDoubleSpacePeriodTimeout = res.getInteger(R.integer.config_double_space_period_timeout); mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration()); mEnableMetricsLogging = prefs.getBoolean(Settings.PREF_ENABLE_METRICS_LOGGING, true); @@ -302,6 +305,12 @@ public class SettingsValues { return prefs.getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true); } + private static boolean readBigramPredictionEnabled(final SharedPreferences prefs, + final Resources res) { + return prefs.getBoolean(Settings.PREF_BIGRAM_PREDICTIONS, res.getBoolean( + R.bool.config_default_next_word_prediction)); + } + private static float readAutoCorrectionThreshold(final Resources res, final String currentAutoCorrectionSetting) { final String[] autoCorrectionThresholdValues = res.getStringArray( @@ -379,6 +388,8 @@ public class SettingsValues { sb.append("" + mUseDoubleSpacePeriod); sb.append("\n mBlockPotentiallyOffensive = "); sb.append("" + mBlockPotentiallyOffensive); + sb.append("\n mBigramPredictionEnabled = "); + sb.append("" + mBigramPredictionEnabled); sb.append("\n mGestureInputEnabled = "); sb.append("" + mGestureInputEnabled); sb.append("\n mGestureTrailEnabled = "); diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java index e09b1e936..b1b48135f 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java @@ -502,11 +502,9 @@ public class InputLogicTests extends InputTestsBase { type(" "); sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); runMessages(); - // Corrections have been replaced with predictions. + // Test the predictions have been cleared SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest(); - String word = suggestedWords == null ? null : suggestedWords.getWord(0); - assertTrue("predictions after double-space-to-period is I or The", - "I".equals(word) || "The".equals(word)); + assertEquals("predictions cleared after double-space-to-period", suggestedWords.size(), 0); type(Constants.CODE_DELETE); sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); runMessages(); @@ -529,6 +527,23 @@ public class InputLogicTests extends InputTestsBase { suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null); } + public void testPredictionsAfterPeriod() { + mLatinIME.clearPersonalizedDictionariesForTest(); + final String WORD_TO_TYPE = "Barack. "; + type(WORD_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest(); + assertEquals("No prediction after period after inputting once.", 0, suggestedWords.size()); + + type(WORD_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); + runMessages(); + suggestedWords = mLatinIME.getSuggestedWordsForTest(); + assertEquals("Beginning-of-Sentence prediction after inputting 2 times.", "Barack", + suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null); + } + public void testPredictionsAfterRecorrection() { final String PREFIX = "A "; final String WORD_TO_TYPE = "Barack"; diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index d5e93744a..6ae38c615 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -78,6 +78,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { protected View mInputView; protected InputConnection mInputConnection; private boolean mPreviousAutoCorrectSetting; + private boolean mPreviousBigramPredictionSettings; // A helper class to ease span tests public static class SpanGetter { @@ -200,6 +201,8 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { setupService(); mLatinIME = getService(); setDebugMode(true); + mPreviousBigramPredictionSettings = setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, + true, true /* defaultValue */); mPreviousAutoCorrectSetting = setBooleanPreference(Settings.PREF_AUTO_CORRECTION, DEFAULT_AUTO_CORRECTION, DEFAULT_AUTO_CORRECTION); mLatinIME.onCreate(); @@ -230,6 +233,8 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { mLatinIME.onFinishInput(); runMessages(); mLatinIME.mHandler.removeAllMessages(); + setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, mPreviousBigramPredictionSettings, + true /* defaultValue */); setBooleanPreference(Settings.PREF_AUTO_CORRECTION, mPreviousAutoCorrectSetting, DEFAULT_AUTO_CORRECTION); setDebugMode(false); diff --git a/tests/src/com/android/inputmethod/latin/PunctuationTests.java b/tests/src/com/android/inputmethod/latin/PunctuationTests.java index 9ac220407..3537918de 100644 --- a/tests/src/com/android/inputmethod/latin/PunctuationTests.java +++ b/tests/src/com/android/inputmethod/latin/PunctuationTests.java @@ -19,23 +19,37 @@ package com.android.inputmethod.latin; import android.provider.Settings.Secure; import android.test.suitebuilder.annotation.LargeTest; +import com.android.inputmethod.latin.R; + @LargeTest public class PunctuationTests extends InputTestsBase { + final String NEXT_WORD_PREDICTION_OPTION = "next_word_prediction"; + public void testWordThenSpaceThenPunctuationFromStripTwice() { final String WORD_TO_TYPE = "this "; final String PUNCTUATION_FROM_STRIP = "!"; final String EXPECTED_RESULT = "this!! "; - mLatinIME.loadSettings(); - type(WORD_TO_TYPE); - sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); - runMessages(); - assertTrue("type word then type space should display punctuation strip", - mLatinIME.getSuggestedWordsForTest().isPunctuationSuggestions()); - pickSuggestionManually(PUNCTUATION_FROM_STRIP); - pickSuggestionManually(PUNCTUATION_FROM_STRIP); - assertEquals("type word then type space then punctuation from strip twice", - EXPECTED_RESULT, mEditText.getText().toString()); + final boolean defaultNextWordPredictionOption = + mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction); + final boolean previousNextWordPredictionOption = + setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, false, + defaultNextWordPredictionOption); + try { + mLatinIME.loadSettings(); + type(WORD_TO_TYPE); + sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); + runMessages(); + assertTrue("type word then type space should display punctuation strip", + mLatinIME.getSuggestedWordsForTest().isPunctuationSuggestions()); + pickSuggestionManually(PUNCTUATION_FROM_STRIP); + pickSuggestionManually(PUNCTUATION_FROM_STRIP); + assertEquals("type word then type space then punctuation from strip twice", + EXPECTED_RESULT, mEditText.getText().toString()); + } finally { + setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption, + defaultNextWordPredictionOption); + } } public void testWordThenSpaceThenPunctuationFromKeyboardTwice() { |