diff options
20 files changed, 120 insertions, 61 deletions
diff --git a/java/src/com/android/inputmethod/latin/BinaryDictionary.java b/java/src/com/android/inputmethod/latin/BinaryDictionary.java index 2d958e17d..f4c8e61ed 100644 --- a/java/src/com/android/inputmethod/latin/BinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/BinaryDictionary.java @@ -135,11 +135,12 @@ public class BinaryDictionary extends Dictionary { } } - // proximityInfo may not be null. + // proximityInfo and/or prevWordForBigrams may not be null. @Override - public void getWords(final WordComposer codes, final WordCallback callback, - final ProximityInfo proximityInfo) { - final int count = getSuggestions(codes, proximityInfo, mOutputChars, mScores); + public void getWords(final WordComposer codes, final CharSequence prevWordForBigrams, + final WordCallback callback, final ProximityInfo proximityInfo) { + final int count = getSuggestions(codes, prevWordForBigrams, proximityInfo, mOutputChars, + mScores); for (int j = 0; j < count; ++j) { if (mScores[j] < 1) break; @@ -161,7 +162,8 @@ public class BinaryDictionary extends Dictionary { // proximityInfo may not be null. /* package for test */ int getSuggestions(final WordComposer codes, - final ProximityInfo proximityInfo, char[] outputChars, int[] scores) { + final CharSequence prevWordForBigrams, final ProximityInfo proximityInfo, + char[] outputChars, int[] scores) { if (!isValidDictionary()) return -1; final int codesSize = codes.size(); @@ -175,6 +177,7 @@ public class BinaryDictionary extends Dictionary { Arrays.fill(outputChars, (char) 0); Arrays.fill(scores, 0); + // TODO: pass the previous word to native code return getSuggestionsNative( mNativeDict, proximityInfo.getNativeProximityInfo(), codes.getXCoordinates(), codes.getYCoordinates(), mInputCodes, codesSize, diff --git a/java/src/com/android/inputmethod/latin/Dictionary.java b/java/src/com/android/inputmethod/latin/Dictionary.java index 9d26a2343..a405aa409 100644 --- a/java/src/com/android/inputmethod/latin/Dictionary.java +++ b/java/src/com/android/inputmethod/latin/Dictionary.java @@ -61,11 +61,13 @@ public abstract class Dictionary { * Searches for words in the dictionary that match the characters in the composer. Matched * words are added through the callback object. * @param composer the key sequence to match + * @param prevWordForBigrams the previous word, or null if none * @param callback the callback object to send matched words to as possible candidates * @param proximityInfo the object for key proximity. May be ignored by some implementations. * @see WordCallback#addWord(char[], int, int, int, int, int) */ - abstract public void getWords(final WordComposer composer, final WordCallback callback, + abstract public void getWords(final WordComposer composer, + final CharSequence prevWordForBigrams, final WordCallback callback, final ProximityInfo proximityInfo); /** diff --git a/java/src/com/android/inputmethod/latin/DictionaryCollection.java b/java/src/com/android/inputmethod/latin/DictionaryCollection.java index 5de770a4a..37deb0c5d 100644 --- a/java/src/com/android/inputmethod/latin/DictionaryCollection.java +++ b/java/src/com/android/inputmethod/latin/DictionaryCollection.java @@ -50,10 +50,10 @@ public class DictionaryCollection extends Dictionary { } @Override - public void getWords(final WordComposer composer, final WordCallback callback, - final ProximityInfo proximityInfo) { + public void getWords(final WordComposer composer, final CharSequence prevWordForBigrams, + final WordCallback callback, final ProximityInfo proximityInfo) { for (final Dictionary dict : mDictionaries) - dict.getWords(composer, callback, proximityInfo); + dict.getWords(composer, prevWordForBigrams, callback, proximityInfo); } @Override diff --git a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java index 53e8b74de..7d2ccdf5f 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableBinaryDictionary.java @@ -173,20 +173,21 @@ abstract public class ExpandableBinaryDictionary extends Dictionary { } @Override - public void getWords(final WordComposer codes, final WordCallback callback, - final ProximityInfo proximityInfo) { + public void getWords(final WordComposer codes, final CharSequence prevWordForBigrams, + final WordCallback callback, final ProximityInfo proximityInfo) { asyncReloadDictionaryIfRequired(); - getWordsInner(codes, callback, proximityInfo); + getWordsInner(codes, prevWordForBigrams, callback, proximityInfo); } - protected final void getWordsInner(final WordComposer codes, final WordCallback callback, + protected final void getWordsInner(final WordComposer codes, + final CharSequence prevWordForBigrams, final WordCallback callback, final ProximityInfo proximityInfo) { // Ensure that there are no concurrent calls to getWords. If there are, do nothing and // return. if (mLocalDictionaryController.tryLock()) { try { if (mBinaryDictionary != null) { - mBinaryDictionary.getWords(codes, callback, proximityInfo); + mBinaryDictionary.getWords(codes, prevWordForBigrams, callback, proximityInfo); } } finally { mLocalDictionaryController.unlock(); diff --git a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java index 46d11fa37..fe21ebe87 100644 --- a/java/src/com/android/inputmethod/latin/ExpandableDictionary.java +++ b/java/src/com/android/inputmethod/latin/ExpandableDictionary.java @@ -192,8 +192,8 @@ public class ExpandableDictionary extends Dictionary { } @Override - public void getWords(final WordComposer codes, final WordCallback callback, - final ProximityInfo proximityInfo) { + public void getWords(final WordComposer codes, final CharSequence prevWordForBigrams, + final WordCallback callback, final ProximityInfo proximityInfo) { synchronized (mUpdatingLock) { // If we need to update, start off a background task if (mRequiresReload) startDictionaryLoadingTaskLocked(); @@ -203,10 +203,11 @@ public class ExpandableDictionary extends Dictionary { if (codes.size() >= BinaryDictionary.MAX_WORD_LENGTH) { return; } - getWordsInner(codes, callback, proximityInfo); + getWordsInner(codes, prevWordForBigrams, callback, proximityInfo); } - protected final void getWordsInner(final WordComposer codes, final WordCallback callback, + protected final void getWordsInner(final WordComposer codes, + final CharSequence prevWordForBigrams, final WordCallback callback, @SuppressWarnings("unused") final ProximityInfo proximityInfo) { mInputLength = codes.size(); if (mCodes.length < mInputLength) mCodes = new int[mInputLength][]; diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index caa7f9312..b30d1e35c 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1817,7 +1817,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } @Override - public void pickSuggestionManually(final int index, final CharSequence suggestion) { + public void pickSuggestionManually(final int index, final CharSequence suggestion, + int x, int y) { final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions(); if (SPACE_STATE_PHANTOM == mSpaceState && suggestion.length() > 0) { @@ -1840,6 +1841,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (ic != null) { final CompletionInfo completionInfo = mApplicationSpecifiedCompletions[index]; ic.commitCompletion(completionInfo); + if (ProductionFlag.IS_EXPERIMENTAL) { + ResearchLogger.latinIME_pickApplicationSpecifiedCompletion(index, + completionInfo.getText(), x, y); + } } return; } @@ -1850,6 +1855,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // So, LatinImeLogger logs "" as a user's input. LatinImeLogger.logOnManualSuggestion("", suggestion.toString(), index, suggestedWords); // Rely on onCodeInput to do the complicated swapping/stripping logic consistently. + if (ProductionFlag.IS_EXPERIMENTAL) { + ResearchLogger.latinIME_punctuationSuggestion(index, suggestion, x, y); + } final int primaryCode = suggestion.charAt(0); onCodeInput(primaryCode, KeyboardActionListener.SUGGESTION_STRIP_COORDINATE, @@ -1858,8 +1866,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } // We need to log before we commit, because the word composer will store away the user // typed word. - LatinImeLogger.logOnManualSuggestion(mWordComposer.getTypedWord().toString(), + final String replacedWord = mWordComposer.getTypedWord().toString(); + LatinImeLogger.logOnManualSuggestion(replacedWord, suggestion.toString(), index, suggestedWords); + if (ProductionFlag.IS_EXPERIMENTAL) { + ResearchLogger.latinIME_pickSuggestionManually(replacedWord, index, suggestion, x, y); + } mExpectingUpdateSelection = true; commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK, LastComposedWord.NOT_A_SEPARATOR); diff --git a/java/src/com/android/inputmethod/latin/ResearchLogger.java b/java/src/com/android/inputmethod/latin/ResearchLogger.java index 4e90dd624..27f2e2a59 100644 --- a/java/src/com/android/inputmethod/latin/ResearchLogger.java +++ b/java/src/com/android/inputmethod/latin/ResearchLogger.java @@ -375,6 +375,10 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang private static final boolean SUDDENJUMPINGTOUCHEVENTHANDLER_ONTOUCHEVENT_ENABLED = DEFAULT_ENABLED; private static final boolean SUGGESTIONSVIEW_SETSUGGESTIONS_ENABLED = DEFAULT_ENABLED; + private static final boolean LATINIME_PICKAPPLICATIONSPECIFIEDCOMPLETION_ENABLED + = DEFAULT_ENABLED; + private static final boolean LATINIME_PICKPUNCTUATIONSUGGESTION_ENABLED = DEFAULT_ENABLED; + private static final boolean LATINIME_PICKSUGGESTIONMANUALLY_ENABLED = DEFAULT_ENABLED; } public static void logUnstructured(String logGroup, final String details) { @@ -633,6 +637,30 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang } } + public static void latinIME_pickApplicationSpecifiedCompletion(final int index, + final CharSequence text, int x, int y) { + if (UnsLogGroup.LATINIME_PICKAPPLICATIONSPECIFIEDCOMPLETION_ENABLED) { + final String s = String.valueOf(index) + '\t' + text + '\t' + x + '\t' + y; + logUnstructured("latinIME_pickApplicationSpecifiedCompletion", s); + } + } + + public static void latinIME_pickSuggestionManually(final String replacedWord, + final int index, CharSequence suggestion, int x, int y) { + if (UnsLogGroup.LATINIME_PICKSUGGESTIONMANUALLY_ENABLED) { + final String s = String.valueOf(index) + '\t' + suggestion + '\t' + x + '\t' + y; + logUnstructured("latinIME_pickSuggestionManually", s); + } + } + + public static void latinIME_punctuationSuggestion(final int index, + final CharSequence suggestion, int x, int y) { + if (UnsLogGroup.LATINIME_PICKPUNCTUATIONSUGGESTION_ENABLED) { + final String s = String.valueOf(index) + '\t' + suggestion + '\t' + x + '\t' + y; + logUnstructured("latinIME_pickPunctuationSuggestion", s); + } + } + public static void latinIME_switchToKeyboardView() { if (UnsLogGroup.LATINIME_SWITCHTOKEYBOARDVIEW_ENABLED) { final String s = "Switch to keyboard view."; diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java index 51ebfdad6..86753e2cc 100644 --- a/java/src/com/android/inputmethod/latin/Suggest.java +++ b/java/src/com/android/inputmethod/latin/Suggest.java @@ -340,7 +340,7 @@ public class Suggest implements Dictionary.WordCallback { if (key.equals(DICT_KEY_USER_HISTORY_UNIGRAM) || key.equals(DICT_KEY_WHITELIST)) continue; final Dictionary dictionary = mUnigramDictionaries.get(key); - dictionary.getWords(wordComposerForLookup, this, proximityInfo); + dictionary.getWords(wordComposerForLookup, prevWordForBigram, this, proximityInfo); } } diff --git a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java index 80825a887..188259ff8 100644 --- a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java +++ b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsBinaryDictionary.java @@ -30,10 +30,11 @@ public class SynchronouslyLoadedContactsBinaryDictionary extends ContactsBinaryD } @Override - public synchronized void getWords(final WordComposer codes, final WordCallback callback, + public synchronized void getWords(final WordComposer codes, + final CharSequence prevWordForBigrams, final WordCallback callback, final ProximityInfo proximityInfo) { syncReloadDictionaryIfRequired(); - getWordsInner(codes, callback, proximityInfo); + getWordsInner(codes, prevWordForBigrams, callback, proximityInfo); } @Override diff --git a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsDictionary.java b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsDictionary.java index 444c7f5f0..a8b871cdf 100644 --- a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsDictionary.java +++ b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedContactsDictionary.java @@ -29,10 +29,11 @@ public class SynchronouslyLoadedContactsDictionary extends ContactsDictionary { } @Override - public synchronized void getWords(final WordComposer codes, final WordCallback callback, + public synchronized void getWords(final WordComposer codes, + final CharSequence prevWordForBigrams, final WordCallback callback, final ProximityInfo proximityInfo) { blockingReloadDictionaryIfRequired(); - getWordsInner(codes, callback, proximityInfo); + getWordsInner(codes, prevWordForBigrams, callback, proximityInfo); } @Override diff --git a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserDictionary.java b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserDictionary.java index e52b46ac0..50e8b249e 100644 --- a/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserDictionary.java +++ b/java/src/com/android/inputmethod/latin/SynchronouslyLoadedUserDictionary.java @@ -32,10 +32,11 @@ public class SynchronouslyLoadedUserDictionary extends UserDictionary { } @Override - public synchronized void getWords(final WordComposer codes, final WordCallback callback, + public synchronized void getWords(final WordComposer codes, + final CharSequence prevWordForBigrams, final WordCallback callback, final ProximityInfo proximityInfo) { blockingReloadDictionaryIfRequired(); - getWordsInner(codes, callback, proximityInfo); + getWordsInner(codes, prevWordForBigrams, callback, proximityInfo); } @Override diff --git a/java/src/com/android/inputmethod/latin/UserDictionary.java b/java/src/com/android/inputmethod/latin/UserDictionary.java index 51b993343..6beeaace9 100644 --- a/java/src/com/android/inputmethod/latin/UserDictionary.java +++ b/java/src/com/android/inputmethod/latin/UserDictionary.java @@ -174,9 +174,10 @@ public class UserDictionary extends ExpandableDictionary { } @Override - public synchronized void getWords(final WordComposer codes, final WordCallback callback, + public synchronized void getWords(final WordComposer codes, + final CharSequence prevWordForBigrams, final WordCallback callback, final ProximityInfo proximityInfo) { - super.getWords(codes, callback, proximityInfo); + super.getWords(codes, prevWordForBigrams, callback, proximityInfo); } @Override diff --git a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java index 44dac30d7..34e214da7 100644 --- a/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java +++ b/java/src/com/android/inputmethod/latin/spellcheck/AndroidSpellCheckerService.java @@ -588,7 +588,7 @@ public class AndroidSpellCheckerService extends SpellCheckerService try { dictInfo = mDictionaryPool.takeOrGetNull(); if (null == dictInfo) return getNotInDictEmptySuggestions(); - dictInfo.mDictionary.getWords(composer, suggestionsGatherer, + dictInfo.mDictionary.getWords(composer, null, suggestionsGatherer, dictInfo.mProximityInfo); isInDict = dictInfo.mDictionary.isValidWord(text); if (!isInDict && CAPITALIZE_NONE != capitalizeType) { diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java index 01d51d463..4e1410415 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java @@ -72,7 +72,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, OnLongClickListener { public interface Listener { public boolean addWordToDictionary(String word); - public void pickSuggestionManually(int index, CharSequence word); + public void pickSuggestionManually(int index, CharSequence word, int x, int y); } // The maximum number of suggestions available. See {@link Suggest#mPrefMaxSuggestions}. @@ -717,7 +717,9 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, public boolean onCustomRequest(int requestCode) { final int index = requestCode; final CharSequence word = mSuggestedWords.getWord(index); - mListener.pickSuggestionManually(index, word); + // TODO: change caller path so coordinates are passed through here + mListener.pickSuggestionManually(index, word, NOT_A_TOUCH_COORDINATE, + NOT_A_TOUCH_COORDINATE); dismissMoreSuggestions(); return true; } @@ -867,7 +869,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, return; final CharSequence word = mSuggestedWords.getWord(index); - mListener.pickSuggestionManually(index, word); + mListener.pickSuggestionManually(index, word, mLastX, mLastY); } @Override diff --git a/native/jni/src/bigram_dictionary.cpp b/native/jni/src/bigram_dictionary.cpp index 87ca1e9ed..320b0af68 100644 --- a/native/jni/src/bigram_dictionary.cpp +++ b/native/jni/src/bigram_dictionary.cpp @@ -30,7 +30,6 @@ BigramDictionary::BigramDictionary(const unsigned char *dict, int maxWordLength, : DICT(dict), MAX_WORD_LENGTH(maxWordLength), mParentDictionary(parentDictionary) { if (DEBUG_DICT) { AKLOGI("BigramDictionary - constructor"); - AKLOGI("Has Bigram : %d", hasBigram); } } @@ -109,6 +108,8 @@ int BigramDictionary::getBigrams(unsigned short *prevWord, int prevWordLength, i const uint8_t* const root = DICT; int pos = getBigramListForWord(root, prevWord, prevWordLength); + // getBigramListForWord returns 0 if this word is not in the dictionary or has no bigrams + if (0 == pos) return 0; int bigramFlags; int bigramCount = 0; do { @@ -130,6 +131,8 @@ int BigramDictionary::getBigrams(unsigned short *prevWord, int prevWordLength, i return bigramCount; } +// Returns a pointer to the start of the bigram list. +// If the word is not found or has no bigrams, this function returns 0. int BigramDictionary::getBigramListForWord(const uint8_t* const root, const unsigned short *prevWord, const int prevWordLength) { int pos = BinaryFormat::getTerminalPosition(root, prevWord, prevWordLength); diff --git a/native/jni/src/dictionary.h b/native/jni/src/dictionary.h index 5638bbf8c..66a5c2150 100644 --- a/native/jni/src/dictionary.h +++ b/native/jni/src/dictionary.h @@ -58,8 +58,6 @@ class Dictionary { static int wideStrLen(unsigned short *str); private: - bool hasBigram(); - const unsigned char *mDict; // Used only for the mmap version of dictionary loading, but we use these as dummy variables diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java index 11eb6ab19..6c3cb16c7 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java @@ -30,7 +30,7 @@ public class InputLogicTests extends InputTestsBase { final String WORD_TO_TYPE = "this"; final String EXPECTED_RESULT = "this"; type(WORD_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE); + pickSuggestionManually(0, WORD_TO_TYPE); mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1); type(Keyboard.CODE_DELETE); assertEquals("press suggestion then backspace", EXPECTED_RESULT, @@ -44,7 +44,7 @@ public class InputLogicTests extends InputTestsBase { type(WORD_TO_TYPE); // Choose the auto-correction, which is always in position 0. For "tgis", the // auto-correction should be "this". - mLatinIME.pickSuggestionManually(0, WORD_TO_PICK); + pickSuggestionManually(0, WORD_TO_PICK); mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1); assertEquals("pick typed word over auto-correction then backspace", WORD_TO_PICK, mTextView.getText().toString()); @@ -59,7 +59,7 @@ public class InputLogicTests extends InputTestsBase { type(WORD_TO_TYPE); // Choose the typed word, which should be in position 1 (because position 0 should // be occupied by the "this" auto-correction, as checked by testAutoCorrect()) - mLatinIME.pickSuggestionManually(1, WORD_TO_TYPE); + pickSuggestionManually(1, WORD_TO_TYPE); mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1); assertEquals("pick typed word over auto-correction then backspace", WORD_TO_TYPE, mTextView.getText().toString()); @@ -75,7 +75,7 @@ public class InputLogicTests extends InputTestsBase { type(WORD_TO_TYPE); // Choose the second suggestion, which should be in position 2 and should be "thus" // when "tgis is typed. - mLatinIME.pickSuggestionManually(2, WORD_TO_PICK); + pickSuggestionManually(2, WORD_TO_PICK); mLatinIME.onUpdateSelection(0, 0, WORD_TO_TYPE.length(), WORD_TO_TYPE.length(), -1, -1); assertEquals("pick different suggestion then backspace", WORD_TO_PICK, mTextView.getText().toString()); @@ -171,7 +171,7 @@ public class InputLogicTests extends InputTestsBase { final String WORD_TO_TYPE = "this"; final String EXPECTED_RESULT = WORD_TO_TYPE; type(WORD_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE); + pickSuggestionManually(0, WORD_TO_TYPE); assertEquals("no space after manual pick", EXPECTED_RESULT, mTextView.getText().toString()); } @@ -181,7 +181,7 @@ public class InputLogicTests extends InputTestsBase { final String WORD2_TO_TYPE = "is"; final String EXPECTED_RESULT = "this is"; type(WORD1_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE); + pickSuggestionManually(0, WORD1_TO_TYPE); type(WORD2_TO_TYPE); assertEquals("manual pick then type", EXPECTED_RESULT, mTextView.getText().toString()); } @@ -191,7 +191,7 @@ public class InputLogicTests extends InputTestsBase { final String WORD2_TO_TYPE = "!"; final String EXPECTED_RESULT = "this!"; type(WORD1_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE); + pickSuggestionManually(0, WORD1_TO_TYPE); type(WORD2_TO_TYPE); assertEquals("manual pick then separator", EXPECTED_RESULT, mTextView.getText().toString()); } @@ -201,7 +201,7 @@ public class InputLogicTests extends InputTestsBase { final String WORD2_TO_TYPE = " is"; final String EXPECTED_RESULT = "this is"; type(WORD1_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE); + pickSuggestionManually(0, WORD1_TO_TYPE); type(WORD2_TO_TYPE); assertEquals("manual pick then space then type", EXPECTED_RESULT, mTextView.getText().toString()); @@ -212,11 +212,11 @@ public class InputLogicTests extends InputTestsBase { final String WORD2_TO_PICK = "is"; final String EXPECTED_RESULT = "this is"; type(WORD1_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE); + pickSuggestionManually(0, WORD1_TO_TYPE); // Here we fake picking a word through bigram prediction. This test is taking // advantage of the fact that Latin IME blindly trusts the caller of #pickSuggestionManually // to actually pass the right string. - mLatinIME.pickSuggestionManually(1, WORD2_TO_PICK); + pickSuggestionManually(1, WORD2_TO_PICK); assertEquals("manual pick then manual pick", EXPECTED_RESULT, mTextView.getText().toString()); } diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java index b2b9601b6..78143ac5b 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTestsNonEnglish.java @@ -33,7 +33,7 @@ public class InputLogicTestsNonEnglish extends InputTestsBase { final String EXPECTED_RESULT = "test !"; changeLanguage("fr"); type(WORD1_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE); + pickSuggestionManually(0, WORD1_TO_TYPE); type(WORD2_TO_TYPE); assertEquals("manual pick then separator for French", EXPECTED_RESULT, mTextView.getText().toString()); @@ -49,8 +49,8 @@ public class InputLogicTestsNonEnglish extends InputTestsBase { runMessages(); assertTrue("type word then type space should display punctuation strip", mLatinIME.isShowingPunctuationList()); - mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); - mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); + pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); + pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); assertEquals("type word then type space then punctuation from strip twice for French", EXPECTED_RESULT, mTextView.getText().toString()); } diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index 991635e3f..838effe2c 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -278,6 +278,11 @@ public class InputTestsBase extends ServiceTestCase<LatinIME> { waitForDictionaryToBeLoaded(); } + protected void pickSuggestionManually(final int index, final CharSequence suggestion) { + mLatinIME.pickSuggestionManually(index, suggestion, + KeyboardActionListener.NOT_A_TOUCH_COORDINATE, + KeyboardActionListener.NOT_A_TOUCH_COORDINATE); + } // Helper to avoid writing the try{}catch block each time protected static void sleep(final int milliseconds) { diff --git a/tests/src/com/android/inputmethod/latin/PunctuationTests.java b/tests/src/com/android/inputmethod/latin/PunctuationTests.java index b907970f0..e1d4c46f8 100644 --- a/tests/src/com/android/inputmethod/latin/PunctuationTests.java +++ b/tests/src/com/android/inputmethod/latin/PunctuationTests.java @@ -38,8 +38,8 @@ public class PunctuationTests extends InputTestsBase { runMessages(); assertTrue("type word then type space should display punctuation strip", mLatinIME.isShowingPunctuationList()); - mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); - mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); + pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); + pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); assertEquals("type word then type space then punctuation from strip twice", EXPECTED_RESULT, mTextView.getText().toString()); } finally { @@ -62,9 +62,9 @@ public class PunctuationTests extends InputTestsBase { final String PUNCTUATION_FROM_STRIP = "!"; final String EXPECTED_RESULT = "this!! is"; type(WORD1_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE); - mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); - mLatinIME.pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); + pickSuggestionManually(0, WORD1_TO_TYPE); + pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); + pickSuggestionManually(0, PUNCTUATION_FROM_STRIP); type(WORD2_TO_TYPE); assertEquals("pick word then pick punctuation twice then type", EXPECTED_RESULT, mTextView.getText().toString()); @@ -75,8 +75,8 @@ public class PunctuationTests extends InputTestsBase { final String WORD2_TO_PICK = "!is"; final String EXPECTED_RESULT = "this!is"; type(WORD1_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD1_TO_TYPE); - mLatinIME.pickSuggestionManually(1, WORD2_TO_PICK); + pickSuggestionManually(0, WORD1_TO_TYPE); + pickSuggestionManually(1, WORD2_TO_PICK); assertEquals("manual pick then manual pick a word with punct at start", EXPECTED_RESULT, mTextView.getText().toString()); } @@ -86,7 +86,7 @@ public class PunctuationTests extends InputTestsBase { final String PUNCTUATION = ":"; final String EXPECTED_RESULT = "this:"; type(WORD_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE); + pickSuggestionManually(0, WORD_TO_TYPE); type(PUNCTUATION); assertEquals("manually pick word then colon", EXPECTED_RESULT, mTextView.getText().toString()); @@ -97,7 +97,7 @@ public class PunctuationTests extends InputTestsBase { final String PUNCTUATION = "("; final String EXPECTED_RESULT = "this ("; type(WORD_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE); + pickSuggestionManually(0, WORD_TO_TYPE); type(PUNCTUATION); assertEquals("manually pick word then open paren", EXPECTED_RESULT, mTextView.getText().toString()); @@ -108,7 +108,7 @@ public class PunctuationTests extends InputTestsBase { final String PUNCTUATION = ")"; final String EXPECTED_RESULT = "this)"; type(WORD_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE); + pickSuggestionManually(0, WORD_TO_TYPE); type(PUNCTUATION); assertEquals("manually pick word then close paren", EXPECTED_RESULT, mTextView.getText().toString()); @@ -119,7 +119,7 @@ public class PunctuationTests extends InputTestsBase { final String SPECIAL_KEY = ":-)"; final String EXPECTED_RESULT = "this :-)"; type(WORD_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE); + pickSuggestionManually(0, WORD_TO_TYPE); mLatinIME.onTextInput(SPECIAL_KEY); assertEquals("manually pick word then press the smiley key", EXPECTED_RESULT, mTextView.getText().toString()); @@ -130,7 +130,7 @@ public class PunctuationTests extends InputTestsBase { final String SPECIAL_KEY = ".com"; final String EXPECTED_RESULT = "this.com"; type(WORD_TO_TYPE); - mLatinIME.pickSuggestionManually(0, WORD_TO_TYPE); + pickSuggestionManually(0, WORD_TO_TYPE); mLatinIME.onTextInput(SPECIAL_KEY); assertEquals("manually pick word then press the .com key", EXPECTED_RESULT, mTextView.getText().toString()); |