Merge "Add a wrapper to updateSuggestions / Predictions (A48)"

This commit is contained in:
Jean Chalard 2012-07-04 21:08:21 -07:00 committed by Android (Google) Code Review
commit 0726f466f7

View File

@ -208,13 +208,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final KeyboardSwitcher switcher = latinIme.mKeyboardSwitcher; final KeyboardSwitcher switcher = latinIme.mKeyboardSwitcher;
switch (msg.what) { switch (msg.what) {
case MSG_UPDATE_SUGGESTIONS: case MSG_UPDATE_SUGGESTIONS:
latinIme.updateSuggestions(); latinIme.updateSuggestionsOrPredictions(false /* isPredictions */);
break; break;
case MSG_UPDATE_SHIFT_STATE: case MSG_UPDATE_SHIFT_STATE:
switcher.updateShiftState(); switcher.updateShiftState();
break; break;
case MSG_SET_BIGRAM_PREDICTIONS: case MSG_SET_BIGRAM_PREDICTIONS:
latinIme.updateBigramPredictions(); latinIme.updateSuggestionsOrPredictions(true /* isPredictions */);
break; break;
} }
} }
@ -1003,7 +1003,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// the composing word, reset the last composed word, tell the inputconnection about it. // the composing word, reset the last composed word, tell the inputconnection about it.
private void resetEntireInputState() { private void resetEntireInputState() {
resetComposingState(true /* alsoResetLastComposedWord */); resetComposingState(true /* alsoResetLastComposedWord */);
updateSuggestions(); updateSuggestionsOrPredictions(false /* isPredictions */);
mConnection.finishComposingText(); mConnection.finishComposingText();
} }
@ -1026,7 +1026,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD, typedWord.toString(), LastComposedWord.COMMIT_TYPE_USER_TYPED_WORD, typedWord.toString(),
separatorCode, prevWord); separatorCode, prevWord);
} }
updateSuggestions(); updateSuggestionsOrPredictions(false /* isPredictions */);
} }
public int getCurrentAutoCapsState() { public int getCurrentAutoCapsState() {
@ -1694,7 +1694,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
} }
public void updateSuggestions() { public void updateSuggestionsOrPredictions(final boolean isPredictions) {
if (isPredictions) {
updateBigramPredictions();
} else {
updateSuggestions();
}
}
private void updateSuggestions() {
mHandler.cancelUpdateSuggestions(); mHandler.cancelUpdateSuggestions();
mHandler.cancelUpdateBigramPredictions(); mHandler.cancelUpdateBigramPredictions();
@ -1775,7 +1783,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Complete any pending suggestions query first // Complete any pending suggestions query first
if (mHandler.hasPendingUpdateSuggestions()) { if (mHandler.hasPendingUpdateSuggestions()) {
mHandler.cancelUpdateSuggestions(); mHandler.cancelUpdateSuggestions();
updateSuggestions(); updateSuggestionsOrPredictions(false /* isPredictions */);
} }
final CharSequence autoCorrection = mWordComposer.getAutoCorrectionOrNull(); final CharSequence autoCorrection = mWordComposer.getAutoCorrectionOrNull();
if (autoCorrection != null) { if (autoCorrection != null) {
@ -1885,7 +1893,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (!showingAddToDictionaryHint) { if (!showingAddToDictionaryHint) {
// If we're not showing the "Touch again to save", then show corrections again. // 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. // In case the cursor position doesn't change, make sure we show the suggestions again.
updateBigramPredictions(); updateSuggestionsOrPredictions(true /* isPredictions */);
// Updating the predictions right away may be slow and feel unresponsive on slower // Updating the predictions right away may be slow and feel unresponsive on slower
// terminals. On the other hand if we just postUpdateBigramPredictions() it will // terminals. On the other hand if we just postUpdateBigramPredictions() it will
// take a noticeable delay to update them which may feel uneasy. // take a noticeable delay to update them which may feel uneasy.