From cc2751ba03fad6af5da0a7b5d421963e040d690f Mon Sep 17 00:00:00 2001 From: Yuichiro Hanada Date: Thu, 5 Sep 2013 17:56:00 +0900 Subject: [PATCH] Make commitCurrentAutoCorrection asynchronous. Change-Id: Ida230ca4243347fb3ab9fda7de3a9a18f886cd1c --- .../android/inputmethod/latin/LatinIME.java | 40 +++++++++++++------ .../inputmethod/latin/InputTestsBase.java | 7 +++- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java index a8a29a1d4..3d29c5a0b 100644 --- a/java/src/com/android/inputmethod/latin/LatinIME.java +++ b/java/src/com/android/inputmethod/latin/LatinIME.java @@ -2532,11 +2532,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen false /* isPrediction */); } - private void showSuggestionStrip(final SuggestedWords suggestedWords) { - if (suggestedWords.isEmpty()) { - clearSuggestionStrip(); - return; - } + private void setAutoCorrection(final SuggestedWords suggestedWords) { + if (suggestedWords.isEmpty()) return; final String autoCorrection; if (suggestedWords.mWillAutoCorrect) { autoCorrection = suggestedWords.getWord(SuggestedWords.INDEX_OF_AUTO_CORRECTION); @@ -2544,17 +2541,21 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen autoCorrection = suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD); } mWordComposer.setAutoCorrection(autoCorrection); + } + + private void showSuggestionStrip(final SuggestedWords suggestedWords) { + if (suggestedWords.isEmpty()) { + clearSuggestionStrip(); + return; + } + setAutoCorrection(suggestedWords); final boolean isAutoCorrection = suggestedWords.willAutoCorrect(); setSuggestedWords(suggestedWords, isAutoCorrection); setAutoCorrectionIndicator(isAutoCorrection); setSuggestionStripShown(isSuggestionsStripVisible()); } - private void commitCurrentAutoCorrection(final String separator, final Runnable callback) { - // Complete any pending suggestions query first - if (mHandler.hasPendingUpdateSuggestions()) { - updateSuggestionStrip(); - } + private void completeCommitCurrentAutoCorrection(final String separator) { final String typedAutoCorrection = mWordComposer.getAutoCorrectionOrNull(); final String typedWord = mWordComposer.getTypedWord(); final String autoCorrection = (typedAutoCorrection != null) @@ -2588,9 +2589,22 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen typedWord, autoCorrection)); } } - if (callback != null) { - callback.run(); - } + } + + private void commitCurrentAutoCorrection(final String separator, final Runnable callback) { + getSuggestedWordsOrOlderSuggestionsAsync(Suggest.SESSION_TYPING, + new OnGetSuggestedWordsCallback() { + @Override + public void onGetSuggestedWords(final SuggestedWords suggestedWords) { + if (suggestedWords != null) { + setAutoCorrection(suggestedWords); + } + completeCommitCurrentAutoCorrection(separator); + if (callback != null) { + callback.run(); + } + } + }); } // Called from {@link SuggestionStripView} through the {@link SuggestionStripView#Listener} diff --git a/tests/src/com/android/inputmethod/latin/InputTestsBase.java b/tests/src/com/android/inputmethod/latin/InputTestsBase.java index 0a1c4e963..da1fb6f0d 100644 --- a/tests/src/com/android/inputmethod/latin/InputTestsBase.java +++ b/tests/src/com/android/inputmethod/latin/InputTestsBase.java @@ -44,10 +44,12 @@ public class InputTestsBase extends ServiceTestCase { private static final String PREF_DEBUG_MODE = "debug_mode"; - // The message that sets the underline is posted with a 100 ms delay + // The message that sets the underline is posted with a 200 ms delay protected static final int DELAY_TO_WAIT_FOR_UNDERLINE = 200; - // The message that sets predictions is posted with a 100 ms delay + // The message that sets predictions is posted with a 200 ms delay protected static final int DELAY_TO_WAIT_FOR_PREDICTIONS = 200; + // The message that sets auto-corrections is posted within a 100 ms delay. + protected static final int DELAY_TO_WAIT_FOR_AUTOCORRECTION = 100; protected LatinIME mLatinIME; protected Keyboard mKeyboard; @@ -221,6 +223,7 @@ public class InputTestsBase extends ServiceTestCase { protected void type(final String stringToType) { for (int i = 0; i < stringToType.length(); i = stringToType.offsetByCodePoints(i, 1)) { type(stringToType.codePointAt(i)); + sleep(DELAY_TO_WAIT_FOR_AUTOCORRECTION); } }