Make commitCurrentAutoCorrection asynchronous.
Change-Id: Ida230ca4243347fb3ab9fda7de3a9a18f886cd1cmain
parent
37e0fd2ff0
commit
cc2751ba03
|
@ -2532,11 +2532,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
false /* isPrediction */);
|
false /* isPrediction */);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showSuggestionStrip(final SuggestedWords suggestedWords) {
|
private void setAutoCorrection(final SuggestedWords suggestedWords) {
|
||||||
if (suggestedWords.isEmpty()) {
|
if (suggestedWords.isEmpty()) return;
|
||||||
clearSuggestionStrip();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final String autoCorrection;
|
final String autoCorrection;
|
||||||
if (suggestedWords.mWillAutoCorrect) {
|
if (suggestedWords.mWillAutoCorrect) {
|
||||||
autoCorrection = suggestedWords.getWord(SuggestedWords.INDEX_OF_AUTO_CORRECTION);
|
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);
|
autoCorrection = suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD);
|
||||||
}
|
}
|
||||||
mWordComposer.setAutoCorrection(autoCorrection);
|
mWordComposer.setAutoCorrection(autoCorrection);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void showSuggestionStrip(final SuggestedWords suggestedWords) {
|
||||||
|
if (suggestedWords.isEmpty()) {
|
||||||
|
clearSuggestionStrip();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setAutoCorrection(suggestedWords);
|
||||||
final boolean isAutoCorrection = suggestedWords.willAutoCorrect();
|
final boolean isAutoCorrection = suggestedWords.willAutoCorrect();
|
||||||
setSuggestedWords(suggestedWords, isAutoCorrection);
|
setSuggestedWords(suggestedWords, isAutoCorrection);
|
||||||
setAutoCorrectionIndicator(isAutoCorrection);
|
setAutoCorrectionIndicator(isAutoCorrection);
|
||||||
setSuggestionStripShown(isSuggestionsStripVisible());
|
setSuggestionStripShown(isSuggestionsStripVisible());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void commitCurrentAutoCorrection(final String separator, final Runnable callback) {
|
private void completeCommitCurrentAutoCorrection(final String separator) {
|
||||||
// Complete any pending suggestions query first
|
|
||||||
if (mHandler.hasPendingUpdateSuggestions()) {
|
|
||||||
updateSuggestionStrip();
|
|
||||||
}
|
|
||||||
final String typedAutoCorrection = mWordComposer.getAutoCorrectionOrNull();
|
final String typedAutoCorrection = mWordComposer.getAutoCorrectionOrNull();
|
||||||
final String typedWord = mWordComposer.getTypedWord();
|
final String typedWord = mWordComposer.getTypedWord();
|
||||||
final String autoCorrection = (typedAutoCorrection != null)
|
final String autoCorrection = (typedAutoCorrection != null)
|
||||||
|
@ -2588,9 +2589,22 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
|
||||||
typedWord, autoCorrection));
|
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}
|
// Called from {@link SuggestionStripView} through the {@link SuggestionStripView#Listener}
|
||||||
|
|
|
@ -44,10 +44,12 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
|
||||||
|
|
||||||
private static final String PREF_DEBUG_MODE = "debug_mode";
|
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;
|
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;
|
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 LatinIME mLatinIME;
|
||||||
protected Keyboard mKeyboard;
|
protected Keyboard mKeyboard;
|
||||||
|
@ -221,6 +223,7 @@ public class InputTestsBase extends ServiceTestCase<LatinIMEForTests> {
|
||||||
protected void type(final String stringToType) {
|
protected void type(final String stringToType) {
|
||||||
for (int i = 0; i < stringToType.length(); i = stringToType.offsetByCodePoints(i, 1)) {
|
for (int i = 0; i < stringToType.length(); i = stringToType.offsetByCodePoints(i, 1)) {
|
||||||
type(stringToType.codePointAt(i));
|
type(stringToType.codePointAt(i));
|
||||||
|
sleep(DELAY_TO_WAIT_FOR_AUTOCORRECTION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue