am 1ae16dc3: Next-word suggestion bit in keyboard settings.

* commit '1ae16dc3db170802d1b38273f477125a2a969d32':
  Next-word suggestion bit in keyboard settings.
main
Dan Zivkovic 2015-03-04 23:08:09 +00:00 committed by Android Git Automerger
commit 5512a84d3e
12 changed files with 32 additions and 141 deletions

View File

@ -20,9 +20,6 @@
<resources> <resources>
<bool name="config_block_potentially_offensive">true</bool> <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_delay_in_milliseconds_to_update_shift_state">100</integer>
<integer name="config_double_space_period_timeout">1100</integer> <integer name="config_double_space_period_timeout">1100</integer>

View File

@ -153,11 +153,6 @@
<!-- 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] --> <!-- 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> <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]--> <!-- 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> <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]--> <!-- 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]-->

View File

@ -67,10 +67,4 @@
android:summary="@string/use_contacts_dict_summary" android:summary="@string/use_contacts_dict_summary"
android:defaultValue="true" android:defaultValue="true"
android:persistent="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> </PreferenceScreen>

View File

@ -1543,11 +1543,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// punctuation suggestions (if it's disabled). // punctuation suggestions (if it's disabled).
@Override @Override
public void setNeutralSuggestionStrip() { public void setNeutralSuggestionStrip() {
final SettingsValues currentSettings = mSettings.getCurrent(); setSuggestedWords(SuggestedWords.getEmptyInstance());
final SuggestedWords neutralSuggestions = currentSettings.mBigramPredictionEnabled
? SuggestedWords.getEmptyInstance()
: currentSettings.mSpacingAndPunctuations.mSuggestPuncList;
setSuggestedWords(neutralSuggestions);
} }
// TODO: Make this private // TODO: Make this private

View File

@ -1405,11 +1405,6 @@ public final class InputLogic {
return; return;
} }
if (!mWordComposer.isComposingWord() && !settingsValues.mBigramPredictionEnabled) {
mSuggestionStripViewAccessor.setNeutralSuggestionStrip();
return;
}
final AsyncResultHolder<SuggestedWords> holder = new AsyncResultHolder<>(); final AsyncResultHolder<SuggestedWords> holder = new AsyncResultHolder<>();
mInputLogicHandler.getSuggestedWords(inputStyle, SuggestedWords.NOT_A_SEQUENCE_NUMBER, mInputLogicHandler.getSuggestedWords(inputStyle, SuggestedWords.NOT_A_SEQUENCE_NUMBER,
new OnGetSuggestedWordsCallback() { new OnGetSuggestedWordsCallback() {

View File

@ -19,12 +19,10 @@ package com.android.inputmethod.latin.settings;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo; import android.content.pm.ResolveInfo;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.Preference; import android.preference.Preference;
import com.android.inputmethod.dictionarypack.DictionarySettingsActivity; import com.android.inputmethod.dictionarypack.DictionarySettingsActivity;
@ -61,8 +59,6 @@ public final class CorrectionSettingsFragment extends SubScreenFragment {
final Context context = getActivity(); final Context context = getActivity();
final PackageManager pm = context.getPackageManager(); final PackageManager pm = context.getPackageManager();
ensureConsistencyOfAutoCorrectionSettings();
final Preference dictionaryLink = findPreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY); final Preference dictionaryLink = findPreference(Settings.PREF_CONFIGURE_DICTIONARIES_KEY);
final Intent intent = dictionaryLink.getIntent(); final Intent intent = dictionaryLink.getIntent();
intent.setClassName(context.getPackageName(), DictionarySettingsActivity.class.getName()); intent.setClassName(context.getPackageName(), DictionarySettingsActivity.class.getName());
@ -82,21 +78,6 @@ public final class CorrectionSettingsFragment extends SubScreenFragment {
} }
} }
@Override
public void onSharedPreferenceChanged(final SharedPreferences prefs, final String key) {
ensureConsistencyOfAutoCorrectionSettings();
}
private void ensureConsistencyOfAutoCorrectionSettings() {
final String autoCorrectionOff = getString(
R.string.auto_correction_threshold_mode_index_off);
final ListPreference autoCorrectionThresholdPref = (ListPreference)findPreference(
Settings.PREF_AUTO_CORRECTION_THRESHOLD);
final String currentSetting = autoCorrectionThresholdPref.getValue();
setPreferenceEnabled(
Settings.PREF_BIGRAM_PREDICTIONS, !currentSetting.equals(autoCorrectionOff));
}
private void overwriteUserDictionaryPreference(final Preference userDictionaryPreference) { private void overwriteUserDictionaryPreference(final Preference userDictionaryPreference) {
final Activity activity = getActivity(); final Activity activity = getActivity();
final TreeSet<String> localeList = UserDictionaryList.getUserDictionaryLocalesSet(activity); final TreeSet<String> localeList = UserDictionaryList.getUserDictionaryLocalesSet(activity);

View File

@ -80,7 +80,6 @@ public final class Settings implements SharedPreferences.OnSharedPreferenceChang
// TODO: consolidate key preview dismiss delay with the key preview animation parameters. // TODO: consolidate key preview dismiss delay with the key preview animation parameters.
public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY = public static final String PREF_KEY_PREVIEW_POPUP_DISMISS_DELAY =
"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_GESTURE_INPUT = "gesture_input";
public static final String PREF_VIBRATION_DURATION_SETTINGS = public static final String PREF_VIBRATION_DURATION_SETTINGS =
"pref_vibration_duration_settings"; "pref_vibration_duration_settings";

View File

@ -73,8 +73,6 @@ public class SettingsValues {
public final boolean mUsePersonalizedDicts; public final boolean mUsePersonalizedDicts;
public final boolean mUseDoubleSpacePeriod; public final boolean mUseDoubleSpacePeriod;
public final boolean mBlockPotentiallyOffensive; 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 mGestureInputEnabled;
public final boolean mGestureTrailEnabled; public final boolean mGestureTrailEnabled;
public final boolean mGestureFloatingPreviewTextEnabled; public final boolean mGestureFloatingPreviewTextEnabled;
@ -152,7 +150,6 @@ public class SettingsValues {
&& inputAttributes.mIsGeneralTextInput; && inputAttributes.mIsGeneralTextInput;
mBlockPotentiallyOffensive = Settings.readBlockPotentiallyOffensive(prefs, res); mBlockPotentiallyOffensive = Settings.readBlockPotentiallyOffensive(prefs, res);
mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(autoCorrectionThresholdRawValue, res); mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(autoCorrectionThresholdRawValue, res);
mBigramPredictionEnabled = readBigramPredictionEnabled(prefs, res);
mDoubleSpacePeriodTimeout = res.getInteger(R.integer.config_double_space_period_timeout); mDoubleSpacePeriodTimeout = res.getInteger(R.integer.config_double_space_period_timeout);
mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration()); mHasHardwareKeyboard = Settings.readHasHardwareKeyboard(res.getConfiguration());
mEnableMetricsLogging = prefs.getBoolean(Settings.PREF_ENABLE_METRICS_LOGGING, true); mEnableMetricsLogging = prefs.getBoolean(Settings.PREF_ENABLE_METRICS_LOGGING, true);
@ -307,12 +304,6 @@ public class SettingsValues {
return prefs.getBoolean(Settings.PREF_SHOW_SUGGESTIONS, true); 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, private static float readAutoCorrectionThreshold(final Resources res,
final String currentAutoCorrectionSetting) { final String currentAutoCorrectionSetting) {
final String[] autoCorrectionThresholdValues = res.getStringArray( final String[] autoCorrectionThresholdValues = res.getStringArray(
@ -390,8 +381,6 @@ public class SettingsValues {
sb.append("" + mUseDoubleSpacePeriod); sb.append("" + mUseDoubleSpacePeriod);
sb.append("\n mBlockPotentiallyOffensive = "); sb.append("\n mBlockPotentiallyOffensive = ");
sb.append("" + mBlockPotentiallyOffensive); sb.append("" + mBlockPotentiallyOffensive);
sb.append("\n mBigramPredictionEnabled = ");
sb.append("" + mBigramPredictionEnabled);
sb.append("\n mGestureInputEnabled = "); sb.append("\n mGestureInputEnabled = ");
sb.append("" + mGestureInputEnabled); sb.append("" + mGestureInputEnabled);
sb.append("\n mGestureTrailEnabled = "); sb.append("\n mGestureTrailEnabled = ");

View File

@ -504,9 +504,11 @@ public class InputLogicTests extends InputTestsBase {
type(" "); type(" ");
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages(); runMessages();
// Test the predictions have been cleared // Corrections have been replaced with predictions.
SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest(); SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
assertEquals("predictions cleared after double-space-to-period", suggestedWords.size(), 0); 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));
type(Constants.CODE_DELETE); type(Constants.CODE_DELETE);
sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS);
runMessages(); runMessages();
@ -529,23 +531,6 @@ public class InputLogicTests extends InputTestsBase {
suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null); 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() { public void testPredictionsAfterRecorrection() {
final String PREFIX = "A "; final String PREFIX = "A ";
final String WORD_TO_TYPE = "Barack"; final String WORD_TO_TYPE = "Barack";

View File

@ -23,7 +23,6 @@ import com.android.inputmethod.latin.settings.Settings;
@LargeTest @LargeTest
public class InputLogicTestsNonEnglish extends InputTestsBase { public class InputLogicTestsNonEnglish extends InputTestsBase {
final String NEXT_WORD_PREDICTION_OPTION = "next_word_prediction";
public void testAutoCorrectForFrench() { public void testAutoCorrectForFrench() {
final String STRING_TO_TYPE = "irq "; final String STRING_TO_TYPE = "irq ";
@ -63,48 +62,28 @@ public class InputLogicTestsNonEnglish extends InputTestsBase {
final String WORD_TO_TYPE = "test "; final String WORD_TO_TYPE = "test ";
final String PUNCTUATION_FROM_STRIP = "!"; final String PUNCTUATION_FROM_STRIP = "!";
final String EXPECTED_RESULT = "test !!"; final String EXPECTED_RESULT = "test !!";
final boolean defaultNextWordPredictionOption = changeLanguage("fr");
mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction); type(WORD_TO_TYPE);
final boolean previousNextWordPredictionOption = sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS);
setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, false, runMessages();
defaultNextWordPredictionOption); assertTrue("type word then type space should display punctuation strip",
try { mLatinIME.getSuggestedWordsForTest().isPunctuationSuggestions());
changeLanguage("fr"); pickSuggestionManually(PUNCTUATION_FROM_STRIP);
type(WORD_TO_TYPE); pickSuggestionManually(PUNCTUATION_FROM_STRIP);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); assertEquals("type word then type space then punctuation from strip twice for French",
runMessages(); EXPECTED_RESULT, mEditText.getText().toString());
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 for French",
EXPECTED_RESULT, mEditText.getText().toString());
} finally {
setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption,
defaultNextWordPredictionOption);
}
} }
public void testWordThenSpaceDisplaysPredictions() { public void testWordThenSpaceDisplaysPredictions() {
final String WORD_TO_TYPE = "beaujolais "; final String WORD_TO_TYPE = "beaujolais ";
final String EXPECTED_RESULT = "nouveau"; final String EXPECTED_RESULT = "nouveau";
final boolean defaultNextWordPredictionOption = changeLanguage("fr");
mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction); type(WORD_TO_TYPE);
final boolean previousNextWordPredictionOption = sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS);
setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, true, runMessages();
defaultNextWordPredictionOption); final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
try { assertEquals("type word then type space yields predictions for French",
changeLanguage("fr"); EXPECTED_RESULT, suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
type(WORD_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS);
runMessages();
final SuggestedWords suggestedWords = mLatinIME.getSuggestedWordsForTest();
assertEquals("type word then type space yields predictions for French",
EXPECTED_RESULT, suggestedWords.size() > 0 ? suggestedWords.getWord(0) : null);
} finally {
setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption,
defaultNextWordPredictionOption);
}
} }
public void testAutoCorrectForGerman() { public void testAutoCorrectForGerman() {

View File

@ -77,7 +77,6 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
protected MyEditText mEditText; protected MyEditText mEditText;
protected View mInputView; protected View mInputView;
protected InputConnection mInputConnection; protected InputConnection mInputConnection;
private boolean mPreviousBigramPredictionSettings;
private String mPreviousAutoCorrectSetting; private String mPreviousAutoCorrectSetting;
// A helper class to ease span tests // A helper class to ease span tests
@ -201,8 +200,6 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
setupService(); setupService();
mLatinIME = getService(); mLatinIME = getService();
setDebugMode(true); setDebugMode(true);
mPreviousBigramPredictionSettings = setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS,
true, true /* defaultValue */);
mPreviousAutoCorrectSetting = setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, mPreviousAutoCorrectSetting = setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD,
DEFAULT_AUTO_CORRECTION_THRESHOLD, DEFAULT_AUTO_CORRECTION_THRESHOLD); DEFAULT_AUTO_CORRECTION_THRESHOLD, DEFAULT_AUTO_CORRECTION_THRESHOLD);
mLatinIME.onCreate(); mLatinIME.onCreate();
@ -233,8 +230,6 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
mLatinIME.onFinishInput(); mLatinIME.onFinishInput();
runMessages(); runMessages();
mLatinIME.mHandler.removeAllMessages(); mLatinIME.mHandler.removeAllMessages();
setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, mPreviousBigramPredictionSettings,
true /* defaultValue */);
setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, mPreviousAutoCorrectSetting, setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, mPreviousAutoCorrectSetting,
DEFAULT_AUTO_CORRECTION_THRESHOLD); DEFAULT_AUTO_CORRECTION_THRESHOLD);
setDebugMode(false); setDebugMode(false);

View File

@ -19,37 +19,23 @@ package com.android.inputmethod.latin;
import android.provider.Settings.Secure; import android.provider.Settings.Secure;
import android.test.suitebuilder.annotation.LargeTest; import android.test.suitebuilder.annotation.LargeTest;
import com.android.inputmethod.latin.R;
@LargeTest @LargeTest
public class PunctuationTests extends InputTestsBase { public class PunctuationTests extends InputTestsBase {
final String NEXT_WORD_PREDICTION_OPTION = "next_word_prediction";
public void testWordThenSpaceThenPunctuationFromStripTwice() { public void testWordThenSpaceThenPunctuationFromStripTwice() {
final String WORD_TO_TYPE = "this "; final String WORD_TO_TYPE = "this ";
final String PUNCTUATION_FROM_STRIP = "!"; final String PUNCTUATION_FROM_STRIP = "!";
final String EXPECTED_RESULT = "this!! "; final String EXPECTED_RESULT = "this!! ";
final boolean defaultNextWordPredictionOption = mLatinIME.loadSettings();
mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction); type(WORD_TO_TYPE);
final boolean previousNextWordPredictionOption = sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS);
setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, false, runMessages();
defaultNextWordPredictionOption); assertTrue("type word then type space should display punctuation strip",
try { mLatinIME.getSuggestedWordsForTest().isPunctuationSuggestions());
mLatinIME.loadSettings(); pickSuggestionManually(PUNCTUATION_FROM_STRIP);
type(WORD_TO_TYPE); pickSuggestionManually(PUNCTUATION_FROM_STRIP);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE_MILLIS); assertEquals("type word then type space then punctuation from strip twice",
runMessages(); EXPECTED_RESULT, mEditText.getText().toString());
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() { public void testWordThenSpaceThenPunctuationFromKeyboardTwice() {