diff options
13 files changed, 163 insertions, 311 deletions
diff --git a/java/res/values/config-common.xml b/java/res/values/config-common.xml index 36fd30aef..be22cceea 100644 --- a/java/res/values/config-common.xml +++ b/java/res/values/config-common.xml @@ -20,9 +20,6 @@ <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 50aa4a782..c8060dac3 100644 --- a/java/res/values/strings.xml +++ b/java/res/values/strings.xml @@ -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] --> <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 dd5ba540c..020d3afa6 100644 --- a/java/res/xml/prefs_screen_correction.xml +++ b/java/res/xml/prefs_screen_correction.xml @@ -67,10 +67,4 @@ 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 65a8d667e..d5bfe43b2 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1543,11 +1543,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // punctuation suggestions (if it's disabled). @Override public void setNeutralSuggestionStrip() { - final SettingsValues currentSettings = mSettings.getCurrent(); - final SuggestedWords neutralSuggestions = currentSettings.mBigramPredictionEnabled - ? SuggestedWords.getEmptyInstance() - : currentSettings.mSpacingAndPunctuations.mSuggestPuncList; - setSuggestedWords(neutralSuggestions); + setSuggestedWords(SuggestedWords.getEmptyInstance()); } // 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 3f1646beb..92bd60658 100644 --- a/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java +++ b/java/src/com/android/inputmethod/latin/inputlogic/InputLogic.java @@ -1405,11 +1405,6 @@ 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 ec29a7eb2..44c47fdfa 100644 --- a/java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java +++ b/java/src/com/android/inputmethod/latin/settings/CorrectionSettingsFragment.java @@ -19,12 +19,10 @@ 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.ListPreference; import android.preference.Preference; import com.android.inputmethod.dictionarypack.DictionarySettingsActivity; @@ -61,8 +59,6 @@ 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()); @@ -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) { 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 0ac19f76b..6ece59d17 100644 --- a/java/src/com/android/inputmethod/latin/settings/Settings.java +++ b/java/src/com/android/inputmethod/latin/settings/Settings.java @@ -80,7 +80,6 @@ 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 6224071ea..1d6199dd8 100644 --- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java +++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java @@ -73,8 +73,6 @@ 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; @@ -152,7 +150,6 @@ public class SettingsValues { && inputAttributes.mIsGeneralTextInput; mBlockPotentiallyOffensive = Settings.readBlockPotentiallyOffensive(prefs, res); mAutoCorrectEnabled = Settings.readAutoCorrectEnabled(autoCorrectionThresholdRawValue, res); - 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); @@ -307,12 +304,6 @@ 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( @@ -390,8 +381,6 @@ 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/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettings.java b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettings.java index 3ccd1b3e6..bd3572340 100644 --- a/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettings.java +++ b/java/src/com/android/inputmethod/latin/userdictionary/UserDictionarySettings.java @@ -16,6 +16,12 @@ package com.android.inputmethod.latin.userdictionary; +import static com.android.inputmethod.latin.userdictionary.UserDictionaryAddWordContents.EXTRA_LOCALE; +import static com.android.inputmethod.latin.userdictionary.UserDictionaryAddWordContents.EXTRA_MODE; +import static com.android.inputmethod.latin.userdictionary.UserDictionaryAddWordContents.EXTRA_WORD; +import static com.android.inputmethod.latin.userdictionary.UserDictionaryAddWordContents.MODE_EDIT; +import static com.android.inputmethod.latin.userdictionary.UserDictionaryAddWordContents.MODE_INSERT; + import com.android.inputmethod.latin.R; import android.app.ListFragment; @@ -25,7 +31,7 @@ import android.content.Intent; import android.database.Cursor; import android.os.Build; import android.os.Bundle; -import android.provider.UserDictionary; +import android.provider.UserDictionary.Words; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.Menu; @@ -48,32 +54,8 @@ import java.util.Locale; public class UserDictionarySettings extends ListFragment { - private static final String[] QUERY_PROJECTION = { - UserDictionary.Words._ID, UserDictionary.Words.WORD - }; - - private static final String[] ADAPTER_FROM = { - UserDictionary.Words.WORD, UserDictionary.Words.SHORTCUT - }; - - private static final int[] ADAPTER_TO = { - android.R.id.text1, - }; - - // Either the locale is empty (means the word is applicable to all locales) - // or the word equals our current locale - private static final String QUERY_SELECTION = - UserDictionary.Words.LOCALE + "=?"; - private static final String QUERY_SELECTION_ALL_LOCALES = - UserDictionary.Words.LOCALE + " is null"; - - private static final String DELETE_SELECTION = UserDictionary.Words.WORD + "=?"; - - private static final int OPTIONS_MENU_ADD = Menu.FIRST; - private Cursor mCursor; - - protected String mLocale; + private String mLocale; @Override public void onCreate(Bundle savedInstanceState) { @@ -142,21 +124,30 @@ public class UserDictionarySettings extends ListFragment { // TODO: it should be easy to make this more readable by making the special values // human-readable, like "all_locales" and "current_locales" strings, provided they // can be guaranteed not to match locales that may exist. - if ("".equals(locale)) { + if (TextUtils.isEmpty(locale)) { // Case-insensitive sort - return getActivity().managedQuery(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION, - QUERY_SELECTION_ALL_LOCALES, null, - "UPPER(" + UserDictionary.Words.WORD + ")"); + return getActivity().managedQuery( + Words.CONTENT_URI, + new String[] { Words._ID, Words.WORD }, + Words.LOCALE + " is null", + null, + "UPPER(" + Words.WORD + ")"); } - final String queryLocale = null != locale ? locale : Locale.getDefault().toString(); - return getActivity().managedQuery(UserDictionary.Words.CONTENT_URI, QUERY_PROJECTION, - QUERY_SELECTION, new String[] { queryLocale }, - "UPPER(" + UserDictionary.Words.WORD + ")"); + return getActivity().managedQuery( + Words.CONTENT_URI, + new String[] { Words._ID, Words.WORD }, + Words.LOCALE + "=?", + new String[] { locale }, + "UPPER(" + Words.WORD + ")"); } private ListAdapter createAdapter() { - return new MyAdapter(getActivity(), R.layout.user_dictionary_item, mCursor, - ADAPTER_FROM, ADAPTER_TO); + return new MyAdapter( + getActivity(), + R.layout.user_dictionary_item, + mCursor, + new String[] { Words.WORD }, + new int[] { android.R.id.text1 }); } @Override @@ -177,16 +168,15 @@ public class UserDictionarySettings extends ListFragment { return; } } - MenuItem actionItem = - menu.add(0, OPTIONS_MENU_ADD, 0, R.string.user_dict_settings_add_menu_title) - .setIcon(R.drawable.ic_menu_add); - actionItem.setShowAsAction( - MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); + menu.add(0, Menu.FIRST, 0, R.string.user_dict_settings_add_menu_title) + .setIcon(R.drawable.ic_menu_add) + .setShowAsAction( + MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_WITH_TEXT); } @Override public boolean onOptionsItemSelected(MenuItem item) { - if (item.getItemId() == OPTIONS_MENU_ADD) { + if (item.getItemId() == Menu.FIRST) { showAddOrEditDialog(null); return true; } @@ -199,11 +189,9 @@ public class UserDictionarySettings extends ListFragment { */ private void showAddOrEditDialog(final String editingWord) { final Bundle args = new Bundle(); - args.putInt(UserDictionaryAddWordContents.EXTRA_MODE, null == editingWord - ? UserDictionaryAddWordContents.MODE_INSERT - : UserDictionaryAddWordContents.MODE_EDIT); - args.putString(UserDictionaryAddWordContents.EXTRA_WORD, editingWord); - args.putString(UserDictionaryAddWordContents.EXTRA_LOCALE, mLocale); + args.putInt(EXTRA_MODE, editingWord == null ? MODE_INSERT : MODE_EDIT); + args.putString(EXTRA_WORD, editingWord); + args.putString(EXTRA_LOCALE, mLocale); getActivity(); } @@ -213,12 +201,11 @@ public class UserDictionarySettings extends ListFragment { // Handle a possible race-condition if (mCursor.isAfterLast()) return null; - return mCursor.getString( - mCursor.getColumnIndexOrThrow(UserDictionary.Words.WORD)); + return mCursor.getString(mCursor.getColumnIndexOrThrow(Words.WORD)); } public static void deleteWord(final String word, final ContentResolver resolver) { - resolver.delete(UserDictionary.Words.CONTENT_URI, DELETE_SELECTION, new String[] { word }); + resolver.delete(Words.CONTENT_URI, Words.WORD + "=?", new String[] { word }); } private static class MyAdapter extends SimpleCursorAdapter implements SectionIndexer { @@ -239,7 +226,7 @@ public class UserDictionarySettings extends ListFragment { if (null != c) { final String alphabet = context.getString(R.string.user_dict_fast_scroll_alphabet); - final int wordColIndex = c.getColumnIndexOrThrow(UserDictionary.Words.WORD); + final int wordColIndex = c.getColumnIndexOrThrow(Words.WORD); mIndexer = new AlphabetIndexer(c, wordColIndex, alphabet); } setViewBinder(mViewBinder); diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java index c76f6f446..a6c9bbee0 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java @@ -349,8 +349,8 @@ public class InputLogicTests extends InputTestsBase { assertEquals("manual pick then separator", EXPECTED_RESULT, mEditText.getText().toString()); } - // This test matches the one in InputLogicTestsNonEnglish. In some non-English languages, - // ! and ? are clustering punctuation signs. + // This test matches testClusteringPunctuationForFrench. + // In some non-English languages, ! and ? are clustering punctuation signs. public void testClusteringPunctuation() { final String WORD1_TO_TYPE = "test"; final String WORD2_TO_TYPE = "!!?!:!"; @@ -504,9 +504,11 @@ public class InputLogicTests extends InputTestsBase { type(" "); sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); runMessages(); - // Test the predictions have been cleared + // Corrections have been replaced with predictions. 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); sleep(DELAY_TO_WAIT_FOR_PREDICTIONS_MILLIS); runMessages(); @@ -529,23 +531,6 @@ 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"; @@ -737,4 +722,112 @@ public class InputLogicTests extends InputTestsBase { type(Constants.CODE_DELETE); ensureComposingSpanPos("space while in the middle of a word cancels composition", -1, -1); } + + public void testAutoCorrectForFrench() { + final String STRING_TO_TYPE = "irq "; + final String EXPECTED_RESULT = "ira "; + changeLanguage("fr"); + type(STRING_TO_TYPE); + assertEquals("simple auto-correct for French", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testManualPickThenSeparatorForFrench() { + final String WORD1_TO_TYPE = "test"; + final String WORD2_TO_TYPE = "!"; + final String EXPECTED_RESULT = "test !"; + changeLanguage("fr"); + type(WORD1_TO_TYPE); + pickSuggestionManually(WORD1_TO_TYPE); + type(WORD2_TO_TYPE); + assertEquals("manual pick then separator for French", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testClusteringPunctuationForFrench() { + final String WORD1_TO_TYPE = "test"; + final String WORD2_TO_TYPE = "!!?!:!"; + // In English, the expected result would be "test!!?!:!" + final String EXPECTED_RESULT = "test !!?! : !"; + changeLanguage("fr"); + type(WORD1_TO_TYPE); + pickSuggestionManually(WORD1_TO_TYPE); + type(WORD2_TO_TYPE); + assertEquals("clustering punctuation for French", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testWordThenSpaceThenPunctuationFromStripTwiceForFrench() { + final String WORD_TO_TYPE = "test "; + final String PUNCTUATION_FROM_STRIP = "!"; + final String EXPECTED_RESULT = "test !!"; + changeLanguage("fr"); + 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 for French", + EXPECTED_RESULT, mEditText.getText().toString()); + } + + public void testWordThenSpaceDisplaysPredictions() { + final String WORD_TO_TYPE = "beaujolais "; + final String EXPECTED_RESULT = "nouveau"; + changeLanguage("fr"); + 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); + } + + public void testAutoCorrectForGerman() { + final String STRING_TO_TYPE = "unf "; + final String EXPECTED_RESULT = "und "; + changeLanguage("de"); + type(STRING_TO_TYPE); + assertEquals("simple auto-correct for German", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + public void testAutoCorrectWithUmlautForGerman() { + final String STRING_TO_TYPE = "ueber "; + final String EXPECTED_RESULT = "über "; + changeLanguage("de"); + type(STRING_TO_TYPE); + assertEquals("auto-correct with umlaut for German", EXPECTED_RESULT, + mEditText.getText().toString()); + } + + // Corresponds to InputLogicTests#testDoubleSpace + public void testDoubleSpaceHindi() { + changeLanguage("hi"); + // Set default pref just in case + setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true); + // U+1F607 is an emoji + final String[] STRINGS_TO_TYPE = + new String[] { "this ", "a+ ", "\u1F607 ", "|| ", ") ", "( ", "% " }; + final String[] EXPECTED_RESULTS = + new String[] { "this| ", "a+| ", "\u1F607| ", "|| ", ")| ", "( ", "%| " }; + for (int i = 0; i < STRINGS_TO_TYPE.length; ++i) { + mEditText.setText(""); + type(STRINGS_TO_TYPE[i]); + assertEquals("double space processing", EXPECTED_RESULTS[i], + mEditText.getText().toString()); + } + } + + // Corresponds to InputLogicTests#testCancelDoubleSpace + public void testCancelDoubleSpaceHindi() { + changeLanguage("hi"); + final String STRING_TO_TYPE = "this "; + final String EXPECTED_RESULT = "this "; + type(STRING_TO_TYPE); + type(Constants.CODE_DELETE); + assertEquals("double space make a period", EXPECTED_RESULT, mEditText.getText().toString()); + } } diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java deleted file mode 100644 index 3cfd0e2a6..000000000 --- a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java +++ /dev/null @@ -1,155 +0,0 @@ -/* - * Copyright (C) 2012 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 - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.inputmethod.latin; - -import android.test.suitebuilder.annotation.LargeTest; - -import com.android.inputmethod.latin.common.Constants; -import com.android.inputmethod.latin.settings.Settings; - -@LargeTest -public class InputLogicTestsNonEnglish extends InputTestsBase { - final String NEXT_WORD_PREDICTION_OPTION = "next_word_prediction"; - - public void testAutoCorrectForFrench() { - final String STRING_TO_TYPE = "irq "; - final String EXPECTED_RESULT = "ira "; - changeLanguage("fr"); - type(STRING_TO_TYPE); - assertEquals("simple auto-correct for French", EXPECTED_RESULT, - mEditText.getText().toString()); - } - - public void testManualPickThenSeparatorForFrench() { - final String WORD1_TO_TYPE = "test"; - final String WORD2_TO_TYPE = "!"; - final String EXPECTED_RESULT = "test !"; - changeLanguage("fr"); - type(WORD1_TO_TYPE); - pickSuggestionManually(WORD1_TO_TYPE); - type(WORD2_TO_TYPE); - assertEquals("manual pick then separator for French", EXPECTED_RESULT, - mEditText.getText().toString()); - } - - public void testClusteringPunctuationForFrench() { - final String WORD1_TO_TYPE = "test"; - final String WORD2_TO_TYPE = "!!?!:!"; - // In English, the expected result would be "test!!?!:!" - final String EXPECTED_RESULT = "test !!?! : !"; - changeLanguage("fr"); - type(WORD1_TO_TYPE); - pickSuggestionManually(WORD1_TO_TYPE); - type(WORD2_TO_TYPE); - assertEquals("clustering punctuation for French", EXPECTED_RESULT, - mEditText.getText().toString()); - } - - public void testWordThenSpaceThenPunctuationFromStripTwiceForFrench() { - final String WORD_TO_TYPE = "test "; - final String PUNCTUATION_FROM_STRIP = "!"; - final String EXPECTED_RESULT = "test !!"; - final boolean defaultNextWordPredictionOption = - mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction); - final boolean previousNextWordPredictionOption = - setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, false, - defaultNextWordPredictionOption); - try { - changeLanguage("fr"); - 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 for French", - EXPECTED_RESULT, mEditText.getText().toString()); - } finally { - setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption, - defaultNextWordPredictionOption); - } - } - - public void testWordThenSpaceDisplaysPredictions() { - final String WORD_TO_TYPE = "beaujolais "; - final String EXPECTED_RESULT = "nouveau"; - final boolean defaultNextWordPredictionOption = - mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction); - final boolean previousNextWordPredictionOption = - setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, true, - defaultNextWordPredictionOption); - try { - changeLanguage("fr"); - 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() { - final String STRING_TO_TYPE = "unf "; - final String EXPECTED_RESULT = "und "; - changeLanguage("de"); - type(STRING_TO_TYPE); - assertEquals("simple auto-correct for German", EXPECTED_RESULT, - mEditText.getText().toString()); - } - - public void testAutoCorrectWithUmlautForGerman() { - final String STRING_TO_TYPE = "ueber "; - final String EXPECTED_RESULT = "über "; - changeLanguage("de"); - type(STRING_TO_TYPE); - assertEquals("auto-correct with umlaut for German", EXPECTED_RESULT, - mEditText.getText().toString()); - } - - // Corresponds to InputLogicTests#testDoubleSpace - public void testDoubleSpaceHindi() { - changeLanguage("hi"); - // Set default pref just in case - setBooleanPreference(Settings.PREF_KEY_USE_DOUBLE_SPACE_PERIOD, true, true); - // U+1F607 is an emoji - final String[] STRINGS_TO_TYPE = - new String[] { "this ", "a+ ", "\u1F607 ", "|| ", ") ", "( ", "% " }; - final String[] EXPECTED_RESULTS = - new String[] { "this| ", "a+| ", "\u1F607| ", "|| ", ")| ", "( ", "%| " }; - for (int i = 0; i < STRINGS_TO_TYPE.length; ++i) { - mEditText.setText(""); - type(STRINGS_TO_TYPE[i]); - assertEquals("double space processing", EXPECTED_RESULTS[i], - mEditText.getText().toString()); - } - } - - // Corresponds to InputLogicTests#testCancelDoubleSpace - public void testCancelDoubleSpaceHindi() { - changeLanguage("hi"); - final String STRING_TO_TYPE = "this "; - final String EXPECTED_RESULT = "this "; - type(STRING_TO_TYPE); - type(Constants.CODE_DELETE); - assertEquals("double space make a period", EXPECTED_RESULT, mEditText.getText().toString()); - } -} diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index 00e0b52cb..ea7823c64 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -77,7 +77,6 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { protected MyEditText mEditText; protected View mInputView; protected InputConnection mInputConnection; - private boolean mPreviousBigramPredictionSettings; private String mPreviousAutoCorrectSetting; // A helper class to ease span tests @@ -201,8 +200,6 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { setupService(); mLatinIME = getService(); setDebugMode(true); - mPreviousBigramPredictionSettings = setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, - true, true /* defaultValue */); mPreviousAutoCorrectSetting = setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, DEFAULT_AUTO_CORRECTION_THRESHOLD, DEFAULT_AUTO_CORRECTION_THRESHOLD); mLatinIME.onCreate(); @@ -233,8 +230,6 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> { mLatinIME.onFinishInput(); runMessages(); mLatinIME.mHandler.removeAllMessages(); - setBooleanPreference(Settings.PREF_BIGRAM_PREDICTIONS, mPreviousBigramPredictionSettings, - true /* defaultValue */); setStringPreference(Settings.PREF_AUTO_CORRECTION_THRESHOLD, mPreviousAutoCorrectSetting, DEFAULT_AUTO_CORRECTION_THRESHOLD); setDebugMode(false); diff --git a/tests/src/com/android/inputmethod/latin/PunctuationTests.java b/tests/src/com/android/inputmethod/latin/PunctuationTests.java index 3537918de..9ac220407 100644 --- a/tests/src/com/android/inputmethod/latin/PunctuationTests.java +++ b/tests/src/com/android/inputmethod/latin/PunctuationTests.java @@ -19,37 +19,23 @@ 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!! "; - 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); - } + 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()); } public void testWordThenSpaceThenPunctuationFromKeyboardTwice() { |