am c28f0288: [IL42] Inline getSuggestedWordsOrOlderSuggestionsAsync

* commit 'c28f02880c307c1bf7c11a755765ea6354150bd4':
  [IL42] Inline getSuggestedWordsOrOlderSuggestionsAsync
main
Jean Chalard 2013-12-26 05:17:48 -08:00 committed by Android Git Automerger
commit 654fe9724d
2 changed files with 34 additions and 39 deletions

View File

@ -182,7 +182,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
switch (msg.what) { switch (msg.what) {
case MSG_UPDATE_SUGGESTION_STRIP: case MSG_UPDATE_SUGGESTION_STRIP:
latinIme.mInputLogic.performUpdateSuggestionStripSync( latinIme.mInputLogic.performUpdateSuggestionStripSync(
latinIme.mSettings.getCurrent(), this); latinIme.mSettings.getCurrent(), this /* handler */,
latinIme.mInputUpdater);
break; break;
case MSG_UPDATE_SHIFT_STATE: case MSG_UPDATE_SHIFT_STATE:
switcher.updateShiftState(); switcher.updateShiftState();
@ -1245,13 +1246,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// Implementation of {@link KeyboardActionListener}. // Implementation of {@link KeyboardActionListener}.
@Override @Override
public void onCodeInput(final int primaryCode, final int x, final int y) { public void onCodeInput(final int primaryCode, final int x, final int y) {
mInputLogic.onCodeInput(primaryCode, x, y, mHandler, mKeyboardSwitcher, mSubtypeSwitcher); mInputLogic.onCodeInput(primaryCode, x, y, mHandler, mInputUpdater,
mKeyboardSwitcher, mSubtypeSwitcher);
} }
// Called from PointerTracker through the KeyboardActionListener interface // Called from PointerTracker through the KeyboardActionListener interface
@Override @Override
public void onTextInput(final String rawText) { public void onTextInput(final String rawText) {
mInputLogic.onTextInput(mSettings.getCurrent(), rawText, mHandler); mInputLogic.onTextInput(mSettings.getCurrent(), rawText, mHandler, mInputUpdater);
mKeyboardSwitcher.updateShiftState(); mKeyboardSwitcher.updateShiftState();
mKeyboardSwitcher.onCodeInput(Constants.CODE_OUTPUT_TEXT); mKeyboardSwitcher.onCodeInput(Constants.CODE_OUTPUT_TEXT);
} }
@ -1564,20 +1566,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
additionalFeaturesOptions, sessionId, sequenceNumber, callback); additionalFeaturesOptions, sessionId, sequenceNumber, callback);
} }
// TODO[IL]: Move this to InputLogic? // TODO[IL]: Move this to InputLogic
public void getSuggestedWordsOrOlderSuggestionsAsync(final int sessionId, public SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord,
final int sequenceNumber, final OnGetSuggestedWordsCallback callback) {
mInputUpdater.getSuggestedWords(sessionId, sequenceNumber,
new OnGetSuggestedWordsCallback() {
@Override
public void onGetSuggestedWords(SuggestedWords suggestedWords) {
callback.onGetSuggestedWords(maybeRetrieveOlderSuggestions(
mInputLogic.mWordComposer.getTypedWord(), suggestedWords));
}
});
}
private SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord,
final SuggestedWords suggestedWords) { final SuggestedWords suggestedWords) {
// TODO: consolidate this into getSuggestedWords // TODO: consolidate this into getSuggestedWords
// We update the suggestion strip only when we have some suggestions to show, i.e. when // We update the suggestion strip only when we have some suggestions to show, i.e. when

View File

@ -140,11 +140,11 @@ public final class InputLogic {
* @param rawText the text to input. * @param rawText the text to input.
*/ */
public void onTextInput(final SettingsValues settingsValues, final String rawText, public void onTextInput(final SettingsValues settingsValues, final String rawText,
// TODO: remove this argument // TODO: remove these arguments
final LatinIME.UIHandler handler) { final LatinIME.UIHandler handler, final LatinIME.InputUpdater inputUpdater) {
mConnection.beginBatchEdit(); mConnection.beginBatchEdit();
if (mWordComposer.isComposingWord()) { if (mWordComposer.isComposingWord()) {
commitCurrentAutoCorrection(settingsValues, rawText, handler); commitCurrentAutoCorrection(settingsValues, rawText, handler, inputUpdater);
} else { } else {
resetComposingState(true /* alsoResetLastComposedWord */); resetComposingState(true /* alsoResetLastComposedWord */);
} }
@ -180,9 +180,9 @@ public final class InputLogic {
* @param y the y-coordinate where the user pressed the key, or NOT_A_COORDINATE. * @param y the y-coordinate where the user pressed the key, or NOT_A_COORDINATE.
*/ */
public void onCodeInput(final int code, final int x, final int y, public void onCodeInput(final int code, final int x, final int y,
// TODO: remove these three arguments // TODO: remove these four arguments
final LatinIME.UIHandler handler, final KeyboardSwitcher keyboardSwitcher, final LatinIME.UIHandler handler, final LatinIME.InputUpdater inputUpdater,
final SubtypeSwitcher subtypeSwitcher) { final KeyboardSwitcher keyboardSwitcher, final SubtypeSwitcher subtypeSwitcher) {
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) { if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.latinIME_onCodeInput(code, x, y); ResearchLogger.latinIME_onCodeInput(code, x, y);
} }
@ -273,17 +273,17 @@ public final class InputLogic {
} else { } else {
// No action label, and the action from imeOptions is NONE: this is a regular // No action label, and the action from imeOptions is NONE: this is a regular
// enter key that should input a carriage return. // enter key that should input a carriage return.
didAutoCorrect = handleNonSpecialCharacter(settingsValues, didAutoCorrect = handleNonSpecialCharacter(settingsValues, Constants.CODE_ENTER,
Constants.CODE_ENTER, x, y, spaceState, keyboardSwitcher, handler); x, y, spaceState, keyboardSwitcher, handler, inputUpdater);
} }
break; break;
case Constants.CODE_SHIFT_ENTER: case Constants.CODE_SHIFT_ENTER:
didAutoCorrect = handleNonSpecialCharacter(settingsValues, didAutoCorrect = handleNonSpecialCharacter(settingsValues, Constants.CODE_ENTER,
Constants.CODE_ENTER, x, y, spaceState, keyboardSwitcher, handler); x, y, spaceState, keyboardSwitcher, handler, inputUpdater);
break; break;
default: default:
didAutoCorrect = handleNonSpecialCharacter(settingsValues, didAutoCorrect = handleNonSpecialCharacter(settingsValues,
code, x, y, spaceState, keyboardSwitcher, handler); code, x, y, spaceState, keyboardSwitcher, handler, inputUpdater);
break; break;
} }
keyboardSwitcher.onCodeInput(code); keyboardSwitcher.onCodeInput(code);
@ -329,7 +329,7 @@ public final class InputLogic {
// so we do not attempt to correct, on the assumption that if that was a dictionary // so we do not attempt to correct, on the assumption that if that was a dictionary
// word, the user would probably have gestured instead. // word, the user would probably have gestured instead.
commitCurrentAutoCorrection(settingsValues, LastComposedWord.NOT_A_SEPARATOR, commitCurrentAutoCorrection(settingsValues, LastComposedWord.NOT_A_SEPARATOR,
handler); handler, inputUpdater);
} else { } else {
commitTyped(settingsValues, LastComposedWord.NOT_A_SEPARATOR); commitTyped(settingsValues, LastComposedWord.NOT_A_SEPARATOR);
} }
@ -431,13 +431,14 @@ public final class InputLogic {
private boolean handleNonSpecialCharacter(final SettingsValues settingsValues, private boolean handleNonSpecialCharacter(final SettingsValues settingsValues,
final int codePoint, final int x, final int y, final int spaceState, final int codePoint, final int x, final int y, final int spaceState,
// TODO: remove these arguments // TODO: remove these arguments
final KeyboardSwitcher keyboardSwitcher, final LatinIME.UIHandler handler) { final KeyboardSwitcher keyboardSwitcher, final LatinIME.UIHandler handler,
final LatinIME.InputUpdater inputUpdater) {
mSpaceState = SpaceState.NONE; mSpaceState = SpaceState.NONE;
final boolean didAutoCorrect; final boolean didAutoCorrect;
if (settingsValues.isWordSeparator(codePoint) if (settingsValues.isWordSeparator(codePoint)
|| Character.getType(codePoint) == Character.OTHER_SYMBOL) { || Character.getType(codePoint) == Character.OTHER_SYMBOL) {
didAutoCorrect = handleSeparator(settingsValues, codePoint, x, y, spaceState, didAutoCorrect = handleSeparator(settingsValues, codePoint, x, y, spaceState,
keyboardSwitcher, handler); keyboardSwitcher, handler, inputUpdater);
} else { } else {
didAutoCorrect = false; didAutoCorrect = false;
if (SpaceState.PHANTOM == spaceState) { if (SpaceState.PHANTOM == spaceState) {
@ -577,7 +578,8 @@ public final class InputLogic {
private boolean handleSeparator(final SettingsValues settingsValues, private boolean handleSeparator(final SettingsValues settingsValues,
final int codePoint, final int x, final int y, final int spaceState, final int codePoint, final int x, final int y, final int spaceState,
// TODO: remove these arguments // TODO: remove these arguments
final KeyboardSwitcher keyboardSwitcher, final LatinIME.UIHandler handler) { final KeyboardSwitcher keyboardSwitcher, final LatinIME.UIHandler handler,
final LatinIME.InputUpdater inputUpdater) {
boolean didAutoCorrect = false; boolean didAutoCorrect = false;
// We avoid sending spaces in languages without spaces if we were composing. // We avoid sending spaces in languages without spaces if we were composing.
final boolean shouldAvoidSendingCode = Constants.CODE_SPACE == codePoint final boolean shouldAvoidSendingCode = Constants.CODE_SPACE == codePoint
@ -593,7 +595,7 @@ public final class InputLogic {
if (settingsValues.mCorrectionEnabled) { if (settingsValues.mCorrectionEnabled) {
final String separator = shouldAvoidSendingCode ? LastComposedWord.NOT_A_SEPARATOR final String separator = shouldAvoidSendingCode ? LastComposedWord.NOT_A_SEPARATOR
: StringUtils.newSingleCodePointString(codePoint); : StringUtils.newSingleCodePointString(codePoint);
commitCurrentAutoCorrection(settingsValues, separator, handler); commitCurrentAutoCorrection(settingsValues, separator, handler, inputUpdater);
didAutoCorrect = true; didAutoCorrect = true;
} else { } else {
commitTyped(settingsValues, StringUtils.newSingleCodePointString(codePoint)); commitTyped(settingsValues, StringUtils.newSingleCodePointString(codePoint));
@ -991,7 +993,7 @@ public final class InputLogic {
public void performUpdateSuggestionStripSync(final SettingsValues settingsValues, public void performUpdateSuggestionStripSync(final SettingsValues settingsValues,
// TODO: Remove this variable // TODO: Remove this variable
final LatinIME.UIHandler handler) { final LatinIME.UIHandler handler, final LatinIME.InputUpdater inputUpdater) {
handler.cancelUpdateSuggestionStrip(); handler.cancelUpdateSuggestionStrip();
// Check if we have a suggestion engine attached. // Check if we have a suggestion engine attached.
@ -1009,11 +1011,14 @@ public final class InputLogic {
} }
final AsyncResultHolder<SuggestedWords> holder = new AsyncResultHolder<SuggestedWords>(); final AsyncResultHolder<SuggestedWords> holder = new AsyncResultHolder<SuggestedWords>();
mLatinIME.getSuggestedWordsOrOlderSuggestionsAsync(Suggest.SESSION_TYPING, inputUpdater.getSuggestedWords(Suggest.SESSION_TYPING,
SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() { SuggestedWords.NOT_A_SEQUENCE_NUMBER, new OnGetSuggestedWordsCallback() {
@Override @Override
public void onGetSuggestedWords(final SuggestedWords suggestedWords) { public void onGetSuggestedWords(final SuggestedWords suggestedWords) {
holder.set(suggestedWords); final SuggestedWords suggestedWordsWithMaybeOlderSuggestions =
mLatinIME.maybeRetrieveOlderSuggestions(
mWordComposer.getTypedWord(), suggestedWords);
holder.set(suggestedWordsWithMaybeOlderSuggestions);
} }
} }
); );
@ -1551,11 +1556,11 @@ public final class InputLogic {
// TODO: Make this private // TODO: Make this private
public void commitCurrentAutoCorrection(final SettingsValues settingsValues, public void commitCurrentAutoCorrection(final SettingsValues settingsValues,
final String separator, final String separator,
// TODO: Remove this argument. // TODO: Remove these arguments.
final LatinIME.UIHandler handler) { final LatinIME.UIHandler handler, final LatinIME.InputUpdater inputUpdater) {
// Complete any pending suggestions query first // Complete any pending suggestions query first
if (handler.hasPendingUpdateSuggestions()) { if (handler.hasPendingUpdateSuggestions()) {
performUpdateSuggestionStripSync(settingsValues, handler); performUpdateSuggestionStripSync(settingsValues, handler, inputUpdater);
} }
final String typedAutoCorrection = mWordComposer.getAutoCorrectionOrNull(); final String typedAutoCorrection = mWordComposer.getAutoCorrectionOrNull();
final String typedWord = mWordComposer.getTypedWord(); final String typedWord = mWordComposer.getTypedWord();