From b28934adac63504010f20e94e3dc8d0035cc5b9c Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Thu, 5 Jul 2012 14:50:10 +0900 Subject: [PATCH 01/19] Fix tab key's navigation behavior Bug: 6435484 Change-Id: Iffe459c117ad438e96ec6f5c7e64fb80b32d227e --- java/res/xml-sw600dp/key_styles_common.xml | 11 +++++++++++ java/res/xml-sw768dp/key_styles_common.xml | 11 +++++++++++ .../com/android/inputmethod/keyboard/KeyboardId.java | 6 ++++-- .../android/inputmethod/latin/InputAttributes.java | 3 --- java/src/com/android/inputmethod/latin/LatinIME.java | 4 ---- .../com/android/inputmethod/latin/SettingsValues.java | 4 ---- 6 files changed, 26 insertions(+), 13 deletions(-) diff --git a/java/res/xml-sw600dp/key_styles_common.xml b/java/res/xml-sw600dp/key_styles_common.xml index a1b2eb475..bf2e76a6b 100644 --- a/java/res/xml-sw600dp/key_styles_common.xml +++ b/java/res/xml-sw600dp/key_styles_common.xml @@ -133,6 +133,17 @@ latin:keyIconPreview="!icon/tab_key_preview" latin:backgroundType="functional" /> + + + + + + Date: Fri, 29 Jun 2012 15:20:28 +0900 Subject: [PATCH 02/19] Factorize some common code (A49) Also add some comment to clarify what's happening inside those methods Change-Id: I5b9b1e105b3145f0b050f35d12c5b6ca6e4a4d8c --- .../android/inputmethod/latin/LatinIME.java | 58 +++++++------------ 1 file changed, 22 insertions(+), 36 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 21f0ea007..4089462e8 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1003,7 +1003,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // the composing word, reset the last composed word, tell the inputconnection about it. private void resetEntireInputState() { resetComposingState(true /* alsoResetLastComposedWord */); - updateSuggestionsOrPredictions(false /* isPredictions */); + clearSuggestions(); mConnection.finishComposingText(); } @@ -1695,7 +1695,20 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } public void updateSuggestionsOrPredictions(final boolean isPredictions) { - if (isPredictions) { + mHandler.cancelUpdateSuggestions(); + mHandler.cancelUpdateBigramPredictions(); + + // Check if we have a suggestion engine attached. + if (mSuggest == null || !mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) { + if (mWordComposer.isComposingWord()) { + Log.w(TAG, "Called updateSuggestionsOrPredictions but suggestions were not " + + "requested!"); + mWordComposer.setAutoCorrection(mWordComposer.getTypedWord()); + } + return; + } + + if (isPredictions || !mWordComposer.isComposingWord()) { updateBigramPredictions(); } else { updateSuggestions(); @@ -1703,27 +1716,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } private void updateSuggestions() { - mHandler.cancelUpdateSuggestions(); - mHandler.cancelUpdateBigramPredictions(); - - // Check if we have a suggestion engine attached. - if ((mSuggest == null || !mCurrentSettings.isSuggestionsRequested(mDisplayOrientation))) { - if (mWordComposer.isComposingWord()) { - Log.w(TAG, "Called updateSuggestions but suggestions were not requested!"); - mWordComposer.setAutoCorrection(mWordComposer.getTypedWord()); - } - return; - } - - if (!mWordComposer.isComposingWord()) { - // We are never called with an empty word composer, but if because of a bug - // we are, what we should do here is just call updateBigramsPredictions. This will - // update the predictions if the "predict next word" option is on, or display - // punctuation signs if it's off. - updateBigramPredictions(); - return; - } - // TODO: May need a better way of retrieving previous word final CharSequence prevWord = mConnection.getPreviousWord(mCurrentSettings.mWordSeparators); final CharSequence typedWord = mWordComposer.getTypedWord(); @@ -1741,6 +1733,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (suggestedWords.size() > 1 || typedWord.length() == 1 || !suggestedWords.mTypedWordValid || mSuggestionsView.isShowingAddToDictionaryHint()) { + // We know suggestedWords.size() > 1 showSuggestions(suggestedWords, typedWord); } else { SuggestedWords previousSuggestions = mSuggestionsView.getSuggestions(); @@ -1757,11 +1750,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen false /* isPunctuationSuggestions */, true /* isObsoleteSuggestions */, false /* isPrediction */); + // getTypedWordAndPreviousSuggestions never returns an empty array, so we know we have + // at least one element here. showSuggestions(obsoleteSuggestedWords, typedWord); } } - public void showSuggestions(final SuggestedWords suggestedWords, final CharSequence typedWord) { + private void showSuggestions(final SuggestedWords suggestedWords, + final CharSequence typedWord) { + // This method is only ever called by updateSuggestions or updateBigramPredictions. final CharSequence autoCorrection; if (suggestedWords.size() > 0) { if (suggestedWords.mWillAutoCorrect) { @@ -1928,18 +1925,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen separatorCode, prevWord); } - public void updateBigramPredictions() { - mHandler.cancelUpdateSuggestions(); - mHandler.cancelUpdateBigramPredictions(); - - if (mSuggest == null || !mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) { - if (mWordComposer.isComposingWord()) { - Log.w(TAG, "Called updateBigramPredictions but suggestions were not requested!"); - mWordComposer.setAutoCorrection(mWordComposer.getTypedWord()); - } - return; - } - + private void updateBigramPredictions() { if (!mCurrentSettings.mBigramPredictionEnabled) { setPunctuationSuggestions(); return; From cbfd2e1fdb83a2fc315b5b6351221f3d65afe25a Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 29 Jun 2012 15:42:29 +0900 Subject: [PATCH 03/19] Pull up a common variable into the wrapping method (A50) Change-Id: I0b62098308169b5c44ced25ffb902766e3732fbf --- .../android/inputmethod/latin/LatinIME.java | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 4089462e8..2d81298b0 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1708,17 +1708,19 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen return; } + final CharSequence typedWord; if (isPredictions || !mWordComposer.isComposingWord()) { - updateBigramPredictions(); + typedWord = ""; + updateBigramPredictions(typedWord); } else { - updateSuggestions(); + typedWord = mWordComposer.getTypedWord(); + updateSuggestions(typedWord); } } - private void updateSuggestions() { + private void updateSuggestions(final CharSequence typedWord) { // TODO: May need a better way of retrieving previous word final CharSequence prevWord = mConnection.getPreviousWord(mCurrentSettings.mWordSeparators); - final CharSequence typedWord = mWordComposer.getTypedWord(); // getSuggestedWords handles gracefully a null value of prevWord final SuggestedWords suggestedWords = mSuggest.getSuggestedWords(mWordComposer, prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), @@ -1925,7 +1927,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen separatorCode, prevWord); } - private void updateBigramPredictions() { + private void updateBigramPredictions(final CharSequence typedWord) { if (!mCurrentSettings.mBigramPredictionEnabled) { setPunctuationSuggestions(); return; @@ -1946,9 +1948,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } if (null != suggestedWords && suggestedWords.size() > 0) { - // Explicitly supply an empty typed word (the no-second-arg version of - // showSuggestions will retrieve the word near the cursor, we don't want that here) - showSuggestions(suggestedWords, ""); + // Typed word is always empty. We pass it because the no-second-arg version of + // showSuggestions will retrieve the word near the cursor, and we don't want that here + showSuggestions(suggestedWords, typedWord); } else { clearSuggestions(); } From ea80794dd43d44fe53884b4b8f4567af3d0e8331 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 29 Jun 2012 15:54:51 +0900 Subject: [PATCH 04/19] Put some more code in common (A51) Change-Id: If1589e29728df20713c75e08df7f47f0de9202d4 --- .../android/inputmethod/latin/LatinIME.java | 41 ++++++++----------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 2d81298b0..387a3f7ce 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1709,16 +1709,27 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } final CharSequence typedWord; + final SuggestedWords suggestions; if (isPredictions || !mWordComposer.isComposingWord()) { + if (!mCurrentSettings.mBigramPredictionEnabled) { + setPunctuationSuggestions(); + return; + } typedWord = ""; - updateBigramPredictions(typedWord); + suggestions = updateBigramPredictions(typedWord); } else { typedWord = mWordComposer.getTypedWord(); - updateSuggestions(typedWord); + suggestions = updateSuggestions(typedWord); + } + + if (null != suggestions && suggestions.size() > 0) { + showSuggestions(suggestions, typedWord); + } else { + clearSuggestions(); } } - private void updateSuggestions(final CharSequence typedWord) { + private SuggestedWords updateSuggestions(final CharSequence typedWord) { // TODO: May need a better way of retrieving previous word final CharSequence prevWord = mConnection.getPreviousWord(mCurrentSettings.mWordSeparators); // getSuggestedWords handles gracefully a null value of prevWord @@ -1735,8 +1746,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (suggestedWords.size() > 1 || typedWord.length() == 1 || !suggestedWords.mTypedWordValid || mSuggestionsView.isShowingAddToDictionaryHint()) { - // We know suggestedWords.size() > 1 - showSuggestions(suggestedWords, typedWord); + return suggestedWords; } else { SuggestedWords previousSuggestions = mSuggestionsView.getSuggestions(); if (previousSuggestions == mCurrentSettings.mSuggestPuncList) { @@ -1745,16 +1755,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final ArrayList typedWordAndPreviousSuggestions = SuggestedWords.getTypedWordAndPreviousSuggestions( typedWord, previousSuggestions); - final SuggestedWords obsoleteSuggestedWords = - new SuggestedWords(typedWordAndPreviousSuggestions, + return new SuggestedWords(typedWordAndPreviousSuggestions, false /* typedWordValid */, false /* hasAutoCorrectionCandidate */, false /* isPunctuationSuggestions */, true /* isObsoleteSuggestions */, false /* isPrediction */); - // getTypedWordAndPreviousSuggestions never returns an empty array, so we know we have - // at least one element here. - showSuggestions(obsoleteSuggestedWords, typedWord); } } @@ -1927,12 +1933,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen separatorCode, prevWord); } - private void updateBigramPredictions(final CharSequence typedWord) { - if (!mCurrentSettings.mBigramPredictionEnabled) { - setPunctuationSuggestions(); - return; - } - + private SuggestedWords updateBigramPredictions(final CharSequence typedWord) { final SuggestedWords suggestedWords; if (mCurrentSettings.mCorrectionEnabled) { final CharSequence prevWord = mConnection.getThisWord(mCurrentSettings.mWordSeparators); @@ -1947,13 +1948,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen suggestedWords = null; } - if (null != suggestedWords && suggestedWords.size() > 0) { - // Typed word is always empty. We pass it because the no-second-arg version of - // showSuggestions will retrieve the word near the cursor, and we don't want that here - showSuggestions(suggestedWords, typedWord); - } else { - clearSuggestions(); - } + return suggestedWords; } public void setPunctuationSuggestions() { From 4cba560dbbd8696673642d1a10d2d433418e54e2 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Fri, 29 Jun 2012 16:00:18 +0900 Subject: [PATCH 05/19] Small simplification (A52) Change-Id: I56bc5b9b584de5a14b41fc32c19f7fefb3b12e88 --- java/src/com/android/inputmethod/latin/LatinIME.java | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 387a3f7ce..930c9cfd1 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1934,21 +1934,17 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } private SuggestedWords updateBigramPredictions(final CharSequence typedWord) { - final SuggestedWords suggestedWords; if (mCurrentSettings.mCorrectionEnabled) { final CharSequence prevWord = mConnection.getThisWord(mCurrentSettings.mWordSeparators); if (!TextUtils.isEmpty(prevWord)) { - suggestedWords = mSuggest.getSuggestedWords(mWordComposer, + // If we call getSuggestedWord with mCorrectionEnabled == false or with + // an empty prevWord, we'll get a 0-sized list of suggestions. + return mSuggest.getSuggestedWords(mWordComposer, prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), mCurrentSettings.mCorrectionEnabled, true); - } else { - suggestedWords = null; } - } else { - suggestedWords = null; } - - return suggestedWords; + return null; } public void setPunctuationSuggestions() { From 078336603617f6c9cc4f917eb81c299a8cf8ab11 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 5 Jul 2012 11:17:17 +0900 Subject: [PATCH 06/19] Remove a redundant test (A53) Change-Id: If711074fdcb586e35d02e421c845f2c9024ca718 --- .../com/android/inputmethod/latin/LatinIME.java | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 930c9cfd1..dce1075e7 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1934,17 +1934,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } private SuggestedWords updateBigramPredictions(final CharSequence typedWord) { - if (mCurrentSettings.mCorrectionEnabled) { - final CharSequence prevWord = mConnection.getThisWord(mCurrentSettings.mWordSeparators); - if (!TextUtils.isEmpty(prevWord)) { - // If we call getSuggestedWord with mCorrectionEnabled == false or with - // an empty prevWord, we'll get a 0-sized list of suggestions. - return mSuggest.getSuggestedWords(mWordComposer, - prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), - mCurrentSettings.mCorrectionEnabled, true); - } - } - return null; + final CharSequence prevWord = mConnection.getThisWord(mCurrentSettings.mWordSeparators); + return mSuggest.getSuggestedWords(mWordComposer, + prevWord, mKeyboardSwitcher.getKeyboard().getProximityInfo(), + mCurrentSettings.mCorrectionEnabled, true); } public void setPunctuationSuggestions() { From 3d8e7a62fc6182c12ca28c29ceeee52ed4b9eea7 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 5 Jul 2012 11:28:05 +0900 Subject: [PATCH 07/19] Remove a useless method, rename another. (A54) Change-Id: If36b5375b04f68deeb72bcece3cb8d37aed57f59 --- java/src/com/android/inputmethod/latin/LatinIME.java | 2 +- .../inputmethod/latin/suggestions/SuggestionsView.java | 8 ++------ 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index dce1075e7..ae01dc013 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1105,7 +1105,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } @Override - public boolean addWordToDictionary(String word) { + public boolean addWordToUserDictionary(String word) { mUserDictionary.addWordToUserDictionary(word, 128); // Suggestion strip should be updated after the operation of adding word to the // user dictionary diff --git a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java index 642a551ce..4d33f4ba5 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/SuggestionsView.java @@ -71,7 +71,7 @@ import java.util.ArrayList; public class SuggestionsView extends RelativeLayout implements OnClickListener, OnLongClickListener { public interface Listener { - public boolean addWordToDictionary(String word); + public boolean addWordToUserDictionary(String word); public void pickSuggestionManually(int index, CharSequence word, int x, int y); } @@ -718,10 +718,6 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, mPreviewPopup.dismiss(); } - private void addToDictionary(CharSequence word) { - mListener.addWordToDictionary(word.toString()); - } - private final KeyboardActionListener mMoreSuggestionsListener = new KeyboardActionListener.Adapter() { @Override @@ -863,7 +859,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener, @Override public void onClick(View view) { if (mParams.isAddToDictionaryShowing(view)) { - addToDictionary(mParams.getAddToDictionaryWord()); + mListener.addWordToUserDictionary(mParams.getAddToDictionaryWord().toString()); clear(); return; } From d6ac0443f0250281872fd889c81d8cbd71e72736 Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Wed, 4 Jul 2012 18:22:40 +0900 Subject: [PATCH 08/19] Initialize SubtypeLocale from Settings Bug: 6781106 Change-Id: I22f04af4fabf93346ab6f72c1841f096afaccb96 --- java/src/com/android/inputmethod/latin/Settings.java | 4 ++++ java/src/com/android/inputmethod/latin/SubtypeLocale.java | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/java/src/com/android/inputmethod/latin/Settings.java b/java/src/com/android/inputmethod/latin/Settings.java index 4c89a6e91..70acdc771 100644 --- a/java/src/com/android/inputmethod/latin/Settings.java +++ b/java/src/com/android/inputmethod/latin/Settings.java @@ -111,6 +111,10 @@ public class Settings extends InputMethodSettingsFragment final Resources res = getResources(); final Context context = getActivity(); + // When we are called from the Settings application but we are not already running, the + // {@link SubtypeLocale} class may not have been initialized. It is safe to call + // {@link SubtypeLocale#init(Context)} multiple times. + SubtypeLocale.init(context); mVoicePreference = (ListPreference) findPreference(PREF_VOICE_MODE); mShowCorrectionSuggestionsPreference = (ListPreference) findPreference(PREF_SHOW_SUGGESTIONS_SETTING); diff --git a/java/src/com/android/inputmethod/latin/SubtypeLocale.java b/java/src/com/android/inputmethod/latin/SubtypeLocale.java index acc17ef3f..21c9c0d1e 100644 --- a/java/src/com/android/inputmethod/latin/SubtypeLocale.java +++ b/java/src/com/android/inputmethod/latin/SubtypeLocale.java @@ -41,6 +41,7 @@ public class SubtypeLocale { public static final String QWERTY = "qwerty"; public static final int UNKNOWN_KEYBOARD_LAYOUT = R.string.subtype_generic; + private static boolean sInitialized = false; private static String[] sPredefinedKeyboardLayoutSet; // Keyboard layout to its display name map. private static final HashMap sKeyboardLayoutToDisplayNameMap = @@ -69,7 +70,10 @@ public class SubtypeLocale { // Intentional empty constructor for utility class. } - public static void init(Context context) { + // Note that this initialization method can be called multiple times. + public static synchronized void init(Context context) { + if (sInitialized) return; + final Resources res = context.getResources(); final String[] predefinedLayoutSet = res.getStringArray(R.array.predefined_layouts); @@ -109,6 +113,8 @@ public class SubtypeLocale { final String keyboardLayoutSet = keyboardLayoutSetMap[i + 1]; sLocaleAndExtraValueToKeyboardLayoutSetMap.put(key, keyboardLayoutSet); } + + sInitialized = true; } public static String[] getPredefinedKeyboardLayoutSet() { From 414f14436e4fa6a8a8bb888d20b50a4d82e9e34c Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 5 Jul 2012 11:31:12 +0900 Subject: [PATCH 09/19] Remove an unused method (A55) Change-Id: I9974b88923b85cd6bec74f7607067c660f36f040 --- .../android/inputmethod/latin/LatinIME.java | 23 ------------------- .../inputmethod/latin/ResearchLogger.java | 7 ------ 2 files changed, 30 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 1f6092c50..a8d076484 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -48,9 +48,7 @@ import android.util.Printer; import android.view.KeyCharacterMap; import android.view.KeyEvent; import android.view.View; -import android.view.ViewGroup; import android.view.ViewGroup.LayoutParams; -import android.view.ViewParent; import android.view.Window; import android.view.WindowManager; import android.view.inputmethod.CompletionInfo; @@ -1646,27 +1644,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen return mCurrentSettings.isSuggestionsRequested(mDisplayOrientation); } - public void switchToKeyboardView() { - if (DEBUG) { - Log.d(TAG, "Switch to keyboard view."); - } - if (ProductionFlag.IS_EXPERIMENTAL) { - ResearchLogger.latinIME_switchToKeyboardView(); - } - View v = mKeyboardSwitcher.getKeyboardView(); - if (v != null) { - // Confirms that the keyboard view doesn't have parent view. - ViewParent p = v.getParent(); - if (p != null && p instanceof ViewGroup) { - ((ViewGroup) p).removeView(v); - } - setInputView(v); - } - setSuggestionStripShown(isSuggestionsStripVisible()); - updateInputViewShown(); - mHandler.postUpdateSuggestions(); - } - public void clearSuggestions() { setSuggestions(SuggestedWords.EMPTY, false); setAutoCorrectionIndicator(false); diff --git a/java/src/com/android/inputmethod/latin/ResearchLogger.java b/java/src/com/android/inputmethod/latin/ResearchLogger.java index e83d7c84a..2de0194fd 100644 --- a/java/src/com/android/inputmethod/latin/ResearchLogger.java +++ b/java/src/com/android/inputmethod/latin/ResearchLogger.java @@ -933,13 +933,6 @@ public class ResearchLogger implements SharedPreferences.OnSharedPreferenceChang EVENTKEYS_NULLVALUES); } - private static final String[] EVENTKEYS_LATINIME_SWITCHTOKEYBOARDVIEW = { - "LatinIMESwitchToKeyboardView" - }; - public static void latinIME_switchToKeyboardView() { - getInstance().enqueueEvent(EVENTKEYS_LATINIME_SWITCHTOKEYBOARDVIEW, EVENTKEYS_NULLVALUES); - } - private static final String[] EVENTKEYS_LATINKEYBOARDVIEW_ONLONGPRESS = { "LatinKeyboardViewOnLongPress" }; From d81e7d24d384a2bb1aeda65d9b423e4b1d23f185 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 5 Jul 2012 11:34:48 +0900 Subject: [PATCH 10/19] Simplification (A56) If suggestion and prediction messages both happen to be in the queue, the latest one will win (update the suggestion strip later than the other, overwriting any previous suggestions). So when we enqueue either one, it is always safe to cancel all messages of both types. Change-Id: Iad9dd06d08c49f60cac16b88edcc9531a18ec02e --- .../android/inputmethod/latin/LatinIME.java | 21 +++++++------------ 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index a8d076484..e7d1c53bd 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -218,12 +218,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } public void postUpdateSuggestions() { - removeMessages(MSG_UPDATE_SUGGESTIONS); + cancelUpdateSuggestionStrip(); sendMessageDelayed(obtainMessage(MSG_UPDATE_SUGGESTIONS), mDelayUpdateSuggestions); } - public void cancelUpdateSuggestions() { + public void cancelUpdateSuggestionStrip() { removeMessages(MSG_UPDATE_SUGGESTIONS); + removeMessages(MSG_SET_BIGRAM_PREDICTIONS); } public boolean hasPendingUpdateSuggestions() { @@ -240,14 +241,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } public void postUpdateBigramPredictions() { - removeMessages(MSG_SET_BIGRAM_PREDICTIONS); + cancelUpdateSuggestionStrip(); sendMessageDelayed(obtainMessage(MSG_SET_BIGRAM_PREDICTIONS), mDelayUpdateSuggestions); } - public void cancelUpdateBigramPredictions() { - removeMessages(MSG_SET_BIGRAM_PREDICTIONS); - } - public void startDoubleSpacesTimer() { mDoubleSpaceTimerStart = SystemClock.uptimeMillis(); } @@ -737,7 +734,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen KeyboardView inputView = mKeyboardSwitcher.getKeyboardView(); if (inputView != null) inputView.cancelAllMessages(); // Remove pending messages related to update suggestions - mHandler.cancelUpdateSuggestions(); + mHandler.cancelUpdateSuggestionStrip(); } @Override @@ -1547,7 +1544,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen final int spaceState) { // Should dismiss the "Touch again to save" message when handling separator if (mSuggestionsView != null && mSuggestionsView.dismissAddToDictionaryHint()) { - mHandler.cancelUpdateBigramPredictions(); mHandler.postUpdateSuggestions(); } @@ -1586,7 +1582,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mHandler.startDoubleSpacesTimer(); if (!mConnection.isCursorTouchingWord(mCurrentSettings)) { - mHandler.cancelUpdateSuggestions(); mHandler.postUpdateBigramPredictions(); } } else { @@ -1668,8 +1663,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen } public void updateSuggestionsOrPredictions(final boolean isPredictions) { - mHandler.cancelUpdateSuggestions(); - mHandler.cancelUpdateBigramPredictions(); + mHandler.cancelUpdateSuggestionStrip(); // Check if we have a suggestion engine attached. if (mSuggest == null || !mCurrentSettings.isSuggestionsRequested(mDisplayOrientation)) { @@ -1760,7 +1754,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private void commitCurrentAutoCorrection(final int separatorCodePoint) { // Complete any pending suggestions query first if (mHandler.hasPendingUpdateSuggestions()) { - mHandler.cancelUpdateSuggestions(); + mHandler.cancelUpdateSuggestionStrip(); updateSuggestionsOrPredictions(false /* isPredictions */); } final CharSequence autoCorrection = mWordComposer.getAutoCorrectionOrNull(); @@ -2024,7 +2018,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // separator. } mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; - mHandler.cancelUpdateBigramPredictions(); mHandler.postUpdateSuggestions(); } From f254e3fec7744dc1eb2cc09ac157986c3b2b5408 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 5 Jul 2012 12:36:06 +0900 Subject: [PATCH 11/19] Fix a bug where the caps mode would not be changed Bug: 6766059 Change-Id: I378f9d35c4904c4f373260bda5863235d833eb31 --- .../android/inputmethod/latin/LatinIME.java | 10 ++--- .../latin/RichInputConnection.java | 17 ++++++-- .../latin/RichInputConnectionTests.java | 41 ++++++++++++------- 3 files changed, 46 insertions(+), 22 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 722f323a2..3abdbf983 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -146,7 +146,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen private LastComposedWord mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; private WordComposer mWordComposer = new WordComposer(); - private RichInputConnection mConnection = new RichInputConnection(); + private RichInputConnection mConnection = new RichInputConnection(this); // Keep track of the last selection range to decide if we need to show word alternatives private static final int NOT_A_CURSOR_POSITION = -1; @@ -542,7 +542,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen if (mDisplayOrientation != conf.orientation) { mDisplayOrientation = conf.orientation; mHandler.startOrientationChanging(); - mConnection.beginBatchEdit(getCurrentInputConnection()); + mConnection.beginBatchEdit(); commitTyped(LastComposedWord.NOT_A_SEPARATOR); mConnection.finishComposingText(); mConnection.endBatchEdit(); @@ -1218,7 +1218,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mDeleteCount = 0; } mLastKeyTime = when; - mConnection.beginBatchEdit(getCurrentInputConnection()); + mConnection.beginBatchEdit(); if (ProductionFlag.IS_EXPERIMENTAL) { ResearchLogger.latinIME_onCodeInput(primaryCode, x, y); @@ -1307,7 +1307,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public void onTextInput(CharSequence text) { - mConnection.beginBatchEdit(getCurrentInputConnection()); + mConnection.beginBatchEdit(); commitTyped(LastComposedWord.NOT_A_SEPARATOR); text = specificTldProcessingOnTextInput(text); if (SPACE_STATE_PHANTOM == mSpaceState) { @@ -1836,7 +1836,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mKeyboardSwitcher.updateShiftState(); resetComposingState(true /* alsoResetLastComposedWord */); final CompletionInfo completionInfo = mApplicationSpecifiedCompletions[index]; - mConnection.beginBatchEdit(getCurrentInputConnection()); + mConnection.beginBatchEdit(); mConnection.commitCompletion(completionInfo); mConnection.endBatchEdit(); if (ProductionFlag.IS_EXPERIMENTAL) { diff --git a/java/src/com/android/inputmethod/latin/RichInputConnection.java b/java/src/com/android/inputmethod/latin/RichInputConnection.java index 40d327ebb..a37f480b7 100644 --- a/java/src/com/android/inputmethod/latin/RichInputConnection.java +++ b/java/src/com/android/inputmethod/latin/RichInputConnection.java @@ -16,6 +16,7 @@ package com.android.inputmethod.latin; +import android.inputmethodservice.InputMethodService; import android.text.TextUtils; import android.util.Log; import android.view.KeyEvent; @@ -41,16 +42,18 @@ public class RichInputConnection { private static final Pattern spaceRegex = Pattern.compile("\\s+"); private static final int INVALID_CURSOR_POSITION = -1; + private final InputMethodService mParent; InputConnection mIC; int mNestLevel; - public RichInputConnection() { + public RichInputConnection(final InputMethodService parent) { + mParent = parent; mIC = null; mNestLevel = 0; } - public void beginBatchEdit(final InputConnection newInputConnection) { + public void beginBatchEdit() { if (++mNestLevel == 1) { - mIC = newInputConnection; + mIC = mParent.getCurrentInputConnection(); if (null != mIC) mIC.beginBatchEdit(); } else { if (DBG) { @@ -84,16 +87,19 @@ public class RichInputConnection { } public int getCursorCapsMode(final int inputType) { + mIC = mParent.getCurrentInputConnection(); if (null == mIC) return Constants.TextUtils.CAP_MODE_OFF; return mIC.getCursorCapsMode(inputType); } public CharSequence getTextBeforeCursor(final int i, final int j) { + mIC = mParent.getCurrentInputConnection(); if (null != mIC) return mIC.getTextBeforeCursor(i, j); return null; } public CharSequence getTextAfterCursor(final int i, final int j) { + mIC = mParent.getCurrentInputConnection(); if (null != mIC) return mIC.getTextAfterCursor(i, j); return null; } @@ -104,6 +110,7 @@ public class RichInputConnection { } public void performEditorAction(final int actionId) { + mIC = mParent.getCurrentInputConnection(); if (null != mIC) mIC.performEditorAction(actionId); } @@ -133,6 +140,7 @@ public class RichInputConnection { } public CharSequence getPreviousWord(final String sentenceSeperators) { + mIC = mParent.getCurrentInputConnection(); //TODO: Should fix this. This could be slow! if (null == mIC) return null; CharSequence prev = mIC.getTextBeforeCursor(LOOKBACK_CHARACTER_NUM, 0); @@ -194,6 +202,7 @@ public class RichInputConnection { } public CharSequence getThisWord(String sentenceSeperators) { + mIC = mParent.getCurrentInputConnection(); if (null == mIC) return null; final CharSequence prev = mIC.getTextBeforeCursor(LOOKBACK_CHARACTER_NUM, 0); return getThisWord(prev, sentenceSeperators); @@ -233,6 +242,7 @@ public class RichInputConnection { } private int getCursorPosition() { + mIC = mParent.getCurrentInputConnection(); if (null == mIC) return INVALID_CURSOR_POSITION; final ExtractedText extracted = mIC.getExtractedText(new ExtractedTextRequest(), 0); if (extracted == null) { @@ -250,6 +260,7 @@ public class RichInputConnection { * @return a range containing the text surrounding the cursor */ public Range getWordRangeAtCursor(String sep, int additionalPrecedingWordsCount) { + mIC = mParent.getCurrentInputConnection(); if (mIC == null || sep == null) { return null; } diff --git a/tests/src/com/android/inputmethod/latin/RichInputConnectionTests.java b/tests/src/com/android/inputmethod/latin/RichInputConnectionTests.java index 9ce581df8..7bd7b0e5a 100644 --- a/tests/src/com/android/inputmethod/latin/RichInputConnectionTests.java +++ b/tests/src/com/android/inputmethod/latin/RichInputConnectionTests.java @@ -16,6 +16,7 @@ package com.android.inputmethod.latin; +import android.inputmethodservice.InputMethodService; import android.test.AndroidTestCase; import android.view.inputmethod.ExtractedText; import android.view.inputmethod.ExtractedTextRequest; @@ -83,6 +84,17 @@ public class RichInputConnectionTests extends AndroidTestCase { } } + private class MockInputMethodService extends InputMethodService { + InputConnection mInputConnection; + public void setInputConnection(final InputConnection inputConnection) { + mInputConnection = inputConnection; + } + @Override + public InputConnection getCurrentInputConnection() { + return mInputConnection; + } + } + /************************** Tests ************************/ /** @@ -122,14 +134,14 @@ public class RichInputConnectionTests extends AndroidTestCase { */ public void testGetWordRangeAtCursor() { ExtractedText et = new ExtractedText(); - final RichInputConnection ic = new RichInputConnection(); - InputConnection mockConnection; - mockConnection = new MockConnection("word wo", "rd", et); + final MockInputMethodService mockInputMethodService = new MockInputMethodService(); + final RichInputConnection ic = new RichInputConnection(mockInputMethodService); + mockInputMethodService.setInputConnection(new MockConnection("word wo", "rd", et)); et.startOffset = 0; et.selectionStart = 7; Range r; - ic.beginBatchEdit(mockConnection); + ic.beginBatchEdit(); // basic case r = ic.getWordRangeAtCursor(" ", 0); assertEquals("word", r.mWord); @@ -140,37 +152,38 @@ public class RichInputConnectionTests extends AndroidTestCase { ic.endBatchEdit(); // tab character instead of space - mockConnection = new MockConnection("one\tword\two", "rd", et); - ic.beginBatchEdit(mockConnection); + mockInputMethodService.setInputConnection(new MockConnection("one\tword\two", "rd", et)); + ic.beginBatchEdit(); r = ic.getWordRangeAtCursor("\t", 1); ic.endBatchEdit(); assertEquals("word\tword", r.mWord); // only one word doesn't go too far - mockConnection = new MockConnection("one\tword\two", "rd", et); - ic.beginBatchEdit(mockConnection); + mockInputMethodService.setInputConnection(new MockConnection("one\tword\two", "rd", et)); + ic.beginBatchEdit(); r = ic.getWordRangeAtCursor("\t", 1); ic.endBatchEdit(); assertEquals("word\tword", r.mWord); // tab or space - mockConnection = new MockConnection("one word\two", "rd", et); - ic.beginBatchEdit(mockConnection); + mockInputMethodService.setInputConnection(new MockConnection("one word\two", "rd", et)); + ic.beginBatchEdit(); r = ic.getWordRangeAtCursor(" \t", 1); ic.endBatchEdit(); assertEquals("word\tword", r.mWord); // tab or space multiword - mockConnection = new MockConnection("one word\two", "rd", et); - ic.beginBatchEdit(mockConnection); + mockInputMethodService.setInputConnection(new MockConnection("one word\two", "rd", et)); + ic.beginBatchEdit(); r = ic.getWordRangeAtCursor(" \t", 2); ic.endBatchEdit(); assertEquals("one word\tword", r.mWord); // splitting on supplementary character final String supplementaryChar = "\uD840\uDC8A"; - mockConnection = new MockConnection("one word" + supplementaryChar + "wo", "rd", et); - ic.beginBatchEdit(mockConnection); + mockInputMethodService.setInputConnection( + new MockConnection("one word" + supplementaryChar + "wo", "rd", et)); + ic.beginBatchEdit(); r = ic.getWordRangeAtCursor(supplementaryChar, 0); ic.endBatchEdit(); assertEquals("word", r.mWord); From 0e9e7e337defe97d4ede8c59d0e925f5401f9292 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 5 Jul 2012 11:43:03 +0900 Subject: [PATCH 12/19] Cleanup (A57) We stopped cancelling manual picks a few weeks ago. This code is dead. Change-Id: I4032fcc3c95e9379f1839fe860a1b8a9bd7d0bc7 --- .../inputmethod/latin/LastComposedWord.java | 4 +-- .../android/inputmethod/latin/LatinIME.java | 25 +++++++------------ .../inputmethod/latin/InputLogicTests.java | 20 +++++++++++++++ 3 files changed, 31 insertions(+), 18 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LastComposedWord.java b/java/src/com/android/inputmethod/latin/LastComposedWord.java index 318aecb50..974af2584 100644 --- a/java/src/com/android/inputmethod/latin/LastComposedWord.java +++ b/java/src/com/android/inputmethod/latin/LastComposedWord.java @@ -73,10 +73,10 @@ public class LastComposedWord { } public boolean canRevertCommit() { - return mActive && !TextUtils.isEmpty(mCommittedWord); + return mActive && !TextUtils.isEmpty(mCommittedWord) && !didCommitTypedWord(); } - public boolean didCommitTypedWord() { + private boolean didCommitTypedWord() { return TextUtils.equals(mTypedWord, mCommittedWord); } diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 80dda9c19..90e4fcf89 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -2000,23 +2000,16 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mUserHistoryDictionary.cancelAddingUserHistory( previousWord.toString(), committedWord.toString()); } - if (0 == separatorLength || mLastComposedWord.didCommitTypedWord()) { - // This is the case when we cancel a manual pick. - // We should restart suggestion on the word right away. - mWordComposer.resumeSuggestionOnLastComposedWord(mLastComposedWord); - mConnection.setComposingText(originallyTypedWord, 1); - } else { - mConnection.commitText(originallyTypedWord, 1); - // Re-insert the separator - sendKeyCodePoint(mLastComposedWord.mSeparatorCode); - Utils.Stats.onSeparator(mLastComposedWord.mSeparatorCode, WordComposer.NOT_A_COORDINATE, - WordComposer.NOT_A_COORDINATE); - if (ProductionFlag.IS_EXPERIMENTAL) { - ResearchLogger.latinIME_revertCommit(originallyTypedWord); - } - // Don't restart suggestion yet. We'll restart if the user deletes the - // separator. + mConnection.commitText(originallyTypedWord, 1); + // Re-insert the separator + sendKeyCodePoint(mLastComposedWord.mSeparatorCode); + Utils.Stats.onSeparator(mLastComposedWord.mSeparatorCode, WordComposer.NOT_A_COORDINATE, + WordComposer.NOT_A_COORDINATE); + if (ProductionFlag.IS_EXPERIMENTAL) { + ResearchLogger.latinIME_revertCommit(originallyTypedWord); } + // Don't restart suggestion yet. We'll restart if the user deletes the + // separator. mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; mHandler.postUpdateSuggestions(); } diff --git a/tests/src/com/android/inputmethod/latin/InputLogicTests.java b/tests/src/com/android/inputmethod/latin/InputLogicTests.java index f1ccfdd1d..7790299b0 100644 --- a/tests/src/com/android/inputmethod/latin/InputLogicTests.java +++ b/tests/src/com/android/inputmethod/latin/InputLogicTests.java @@ -126,6 +126,26 @@ public class InputLogicTests extends InputTestsBase { mTextView.getText().toString()); } + public void testAutoCorrectWithSpaceThenRevert() { + final String STRING_TO_TYPE = "tgis "; + final String EXPECTED_RESULT = "tgis "; + type(STRING_TO_TYPE); + mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1); + type(Keyboard.CODE_DELETE); + assertEquals("auto-correct with space then revert", EXPECTED_RESULT, + mTextView.getText().toString()); + } + + public void testAutoCorrectToSelfDoesNotRevert() { + final String STRING_TO_TYPE = "this "; + final String EXPECTED_RESULT = "this"; + type(STRING_TO_TYPE); + mLatinIME.onUpdateSelection(0, 0, STRING_TO_TYPE.length(), STRING_TO_TYPE.length(), -1, -1); + type(Keyboard.CODE_DELETE); + assertEquals("auto-correct with space does not revert", EXPECTED_RESULT, + mTextView.getText().toString()); + } + public void testDoubleSpace() { final String STRING_TO_TYPE = "this "; final String EXPECTED_RESULT = "this. "; From 746e014eb54f0d6278b948868dff4863bfe85ad8 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 5 Jul 2012 12:05:07 +0900 Subject: [PATCH 13/19] Show predictions in the right cases (A58) After reverting an auto-correct we always have a separator after the previously inserted word, and the cursor is never touching a word. Showing predictions is the right thing to do, while calling postUpdateSuggestions will invariably yield an invariably blank suggestion strip, which is not very helpful. Likewise, after we pick a suggestion, we should be showing the predictions unless showing the addToDictionary hint. There was a bug here in the corner case that the word would be a candidate for user dictionary, but the user dictionary provider is not available: in this case we should be showing predictions, but we were showing an unhelpful empty suggestion bar. Change-Id: I287bb5eb4af762bd5a433e85e185fab6d203e91a --- java/src/com/android/inputmethod/latin/LatinIME.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 90e4fcf89..62c7bbda7 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1874,7 +1874,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen mSuggestionsView.showAddToDictionaryHint( suggestion, mCurrentSettings.mHintToSaveText); } else { - mHandler.postUpdateSuggestions(); + // Here we just manually picked a suggestion. We should be showing the predictions! + mHandler.postUpdateBigramPredictions(); } } } @@ -2011,7 +2012,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen // Don't restart suggestion yet. We'll restart if the user deletes the // separator. mLastComposedWord = LastComposedWord.NOT_A_COMPOSED_WORD; - mHandler.postUpdateSuggestions(); + // We have a separator between the word and the cursor: we should show predictions. + mHandler.postUpdateBigramPredictions(); } public boolean isWordSeparator(int code) { From 663dbfd1cc0c88fe65dd56946cbbbade455da9ac Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 5 Jul 2012 12:44:13 +0900 Subject: [PATCH 14/19] Simplification & UI improvement (A59) The responsivity is better like this. This does not seem to feel slow as the previous comment seemed to indicate. Also remove a stale comment. Change-Id: I4e7bf9fe28716e112db182e44b3fa88ee4526bb4 --- java/src/com/android/inputmethod/latin/LatinIME.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 62c7bbda7..bbd38dd70 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1863,12 +1863,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen Utils.Stats.onSeparator((char)Keyboard.CODE_SPACE, WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE); if (!showingAddToDictionaryHint) { - // If we're not showing the "Touch again to save", then show corrections again. - // In case the cursor position doesn't change, make sure we show the suggestions again. - updateSuggestionsOrPredictions(true /* isPredictions */); - // Updating the predictions right away may be slow and feel unresponsive on slower - // terminals. On the other hand if we just postUpdateBigramPredictions() it will - // take a noticeable delay to update them which may feel uneasy. + // If we're not showing the "Touch again to save", then show predictions. + mHandler.postUpdateBigramPredictions(); } else { if (mIsUserDictionaryAvailable) { mSuggestionsView.showAddToDictionaryHint( From b1dc8ad5f244337f91fcdac2a17078f5b9239cb7 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 5 Jul 2012 12:45:42 +0900 Subject: [PATCH 15/19] Simplification (A60) Change-Id: I99e912d3edfc7dd3f17ee835331d5fcba976750c --- java/src/com/android/inputmethod/latin/LatinIME.java | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index bbd38dd70..357a2a0bd 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1862,17 +1862,11 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen Utils.Stats.onSeparator((char)Keyboard.CODE_SPACE, WordComposer.NOT_A_COORDINATE, WordComposer.NOT_A_COORDINATE); - if (!showingAddToDictionaryHint) { + if (showingAddToDictionaryHint && mIsUserDictionaryAvailable) { + mSuggestionsView.showAddToDictionaryHint(suggestion, mCurrentSettings.mHintToSaveText); + } else { // If we're not showing the "Touch again to save", then show predictions. mHandler.postUpdateBigramPredictions(); - } else { - if (mIsUserDictionaryAvailable) { - mSuggestionsView.showAddToDictionaryHint( - suggestion, mCurrentSettings.mHintToSaveText); - } else { - // Here we just manually picked a suggestion. We should be showing the predictions! - mHandler.postUpdateBigramPredictions(); - } } } From 66a2e96fb442f6517beace6670dc956acd16da38 Mon Sep 17 00:00:00 2001 From: Jean Chalard Date: Thu, 5 Jul 2012 13:05:17 +0900 Subject: [PATCH 16/19] Remove useless code (A61) Just after this, clear() will be called, removing the suggestion strip from the screen. It will later be displayed again through onStartInputView, which will update its content. Change-Id: I15c23ad2adecab76b0791d7fc222d15b6533f3bd --- java/src/com/android/inputmethod/latin/LatinIME.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index 357a2a0bd..78b7eaa44 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -1102,9 +1102,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen @Override public boolean addWordToUserDictionary(String word) { mUserDictionary.addWordToUserDictionary(word, 128); - // Suggestion strip should be updated after the operation of adding word to the - // user dictionary - mHandler.postUpdateSuggestions(); return true; } From c646102b94533e1b5d160dcd101de40bce27c4cb Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Fri, 6 Jul 2012 15:17:11 +0900 Subject: [PATCH 17/19] Update Makefile of LatinIME native code for the unbundled build Change-Id: I117e2429c5f5e75a6ffe84b5869afb2e033f2b2d --- native/jni/Android.mk | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/native/jni/Android.mk b/native/jni/Android.mk index d40063ed5..a7486ae90 100644 --- a/native/jni/Android.mk +++ b/native/jni/Android.mk @@ -68,10 +68,12 @@ endif # FLAG_DO_PROFILE LOCAL_MODULE := libjni_latinime_common_static LOCAL_MODULE_TAGS := optional -ifdef HISTORICAL_NDK_VERSIONS_ROOT # In the platform build system +ifdef ANDROID_BUILD_TOP # In the platform build system include external/stlport/libstlport.mk -else # In the NDK build system -LOCAL_C_INCLUDES += external/stlport/stlport bionic +else # In the unbundled build system +LOCAL_NDK_VERSION := 7 +LOCAL_SDK_VERSION := 14 +LOCAL_NDK_STL_VARIANT := stlport_static endif include $(BUILD_STATIC_LIBRARY) @@ -81,12 +83,6 @@ include $(CLEAR_VARS) # All code in LOCAL_WHOLE_STATIC_LIBRARIES will be built into this shared library. LOCAL_WHOLE_STATIC_LIBRARIES := libjni_latinime_common_static -ifdef HISTORICAL_NDK_VERSIONS_ROOT # In the platform build system -LOCAL_SHARED_LIBRARIES := libstlport -else # In the NDK build system -LOCAL_SHARED_LIBRARIES := libstlport_static -endif - ifeq ($(FLAG_DO_PROFILE), true) $(warning Making profiling version of native library) LOCAL_SHARED_LIBRARIES += libcutils libutils @@ -100,8 +96,12 @@ endif # FLAG_DO_PROFILE LOCAL_MODULE := libjni_latinime LOCAL_MODULE_TAGS := optional -ifdef HISTORICAL_NDK_VERSIONS_ROOT # In the platform build system -include external/stlport/libstlport.mk +ifdef ANDROID_BUILD_TOP # In the platform build system +LOCAL_STATIC_LIBRARIES += libstlport_static +else # In the unbundled build system +LOCAL_NDK_VERSION := 7 +LOCAL_SDK_VERSION := 14 +LOCAL_NDK_STL_VARIANT := stlport_static endif include $(BUILD_SHARED_LIBRARY) From 48a436081fc6886dbeecf1f2b25fd754952f0fe1 Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Fri, 6 Jul 2012 15:35:13 +0900 Subject: [PATCH 18/19] Fix the build Change-Id: Iff324c705b46cfae27ea9b6b8dc8b0a0d56a193d --- native/jni/Android.mk | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/native/jni/Android.mk b/native/jni/Android.mk index a7486ae90..c5cea1143 100644 --- a/native/jni/Android.mk +++ b/native/jni/Android.mk @@ -68,13 +68,12 @@ endif # FLAG_DO_PROFILE LOCAL_MODULE := libjni_latinime_common_static LOCAL_MODULE_TAGS := optional -ifdef ANDROID_BUILD_TOP # In the platform build system +# In the platform build system include external/stlport/libstlport.mk -else # In the unbundled build system -LOCAL_NDK_VERSION := 7 -LOCAL_SDK_VERSION := 14 -LOCAL_NDK_STL_VARIANT := stlport_static -endif +# In the unbundled build system +#LOCAL_NDK_VERSION := 7 +#LOCAL_SDK_VERSION := 14 +#LOCAL_NDK_STL_VARIANT := stlport_static include $(BUILD_STATIC_LIBRARY) ###################################### @@ -96,13 +95,12 @@ endif # FLAG_DO_PROFILE LOCAL_MODULE := libjni_latinime LOCAL_MODULE_TAGS := optional -ifdef ANDROID_BUILD_TOP # In the platform build system +# In the platform build system LOCAL_STATIC_LIBRARIES += libstlport_static -else # In the unbundled build system -LOCAL_NDK_VERSION := 7 -LOCAL_SDK_VERSION := 14 -LOCAL_NDK_STL_VARIANT := stlport_static -endif +# In the unbundled build system +#LOCAL_NDK_VERSION := 7 +#LOCAL_SDK_VERSION := 14 +#LOCAL_NDK_STL_VARIANT := stlport_static include $(BUILD_SHARED_LIBRARY) From f52c1c50ef71c4a30c65c1400394efbed6b2c4c9 Mon Sep 17 00:00:00 2001 From: Ken Wakasa Date: Fri, 6 Jul 2012 15:53:51 +0900 Subject: [PATCH 19/19] Revert "Fix the build" This reverts commit 48a436081fc6886dbeecf1f2b25fd754952f0fe1. --- native/jni/Android.mk | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/native/jni/Android.mk b/native/jni/Android.mk index c5cea1143..a7486ae90 100644 --- a/native/jni/Android.mk +++ b/native/jni/Android.mk @@ -68,12 +68,13 @@ endif # FLAG_DO_PROFILE LOCAL_MODULE := libjni_latinime_common_static LOCAL_MODULE_TAGS := optional -# In the platform build system +ifdef ANDROID_BUILD_TOP # In the platform build system include external/stlport/libstlport.mk -# In the unbundled build system -#LOCAL_NDK_VERSION := 7 -#LOCAL_SDK_VERSION := 14 -#LOCAL_NDK_STL_VARIANT := stlport_static +else # In the unbundled build system +LOCAL_NDK_VERSION := 7 +LOCAL_SDK_VERSION := 14 +LOCAL_NDK_STL_VARIANT := stlport_static +endif include $(BUILD_STATIC_LIBRARY) ###################################### @@ -95,12 +96,13 @@ endif # FLAG_DO_PROFILE LOCAL_MODULE := libjni_latinime LOCAL_MODULE_TAGS := optional -# In the platform build system +ifdef ANDROID_BUILD_TOP # In the platform build system LOCAL_STATIC_LIBRARIES += libstlport_static -# In the unbundled build system -#LOCAL_NDK_VERSION := 7 -#LOCAL_SDK_VERSION := 14 -#LOCAL_NDK_STL_VARIANT := stlport_static +else # In the unbundled build system +LOCAL_NDK_VERSION := 7 +LOCAL_SDK_VERSION := 14 +LOCAL_NDK_STL_VARIANT := stlport_static +endif include $(BUILD_SHARED_LIBRARY)