am 69a57bcd: [IL9] Move commitCurrentAutoCorrection to InputLogic

* commit '69a57bcdcd254b8e2dfbc367ef130114634c51a5':
  [IL9] Move commitCurrentAutoCorrection to InputLogic
main
Jean Chalard 2013-12-19 03:12:07 -08:00 committed by Android Git Automerger
commit 3ba13e6069
2 changed files with 50 additions and 44 deletions

View File

@ -1357,7 +1357,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
public void onTextInput(final String rawText) { public void onTextInput(final String rawText) {
mInputLogic.mConnection.beginBatchEdit(); mInputLogic.mConnection.beginBatchEdit();
if (mInputLogic.mWordComposer.isComposingWord()) { if (mInputLogic.mWordComposer.isComposingWord()) {
commitCurrentAutoCorrection(rawText); mInputLogic.commitCurrentAutoCorrection(mSettings.getCurrent(), rawText, mHandler);
} else { } else {
mInputLogic.resetComposingState(true /* alsoResetLastComposedWord */); mInputLogic.resetComposingState(true /* alsoResetLastComposedWord */);
} }
@ -1412,7 +1412,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// tapping probably is that the word you intend to type is not in the dictionary, // tapping probably is that the word you intend to type is not in the dictionary,
// 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(LastComposedWord.NOT_A_SEPARATOR); mInputLogic.commitCurrentAutoCorrection(currentSettingsValues,
LastComposedWord.NOT_A_SEPARATOR, mHandler);
} else { } else {
mInputLogic.commitTyped(LastComposedWord.NOT_A_SEPARATOR); mInputLogic.commitTyped(LastComposedWord.NOT_A_SEPARATOR);
} }
@ -1769,7 +1770,8 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
} }
private void updateSuggestionStrip() { // TODO[IL]: Move this to InputLogic and make private again
public void updateSuggestionStrip() {
mHandler.cancelUpdateSuggestionStrip(); mHandler.cancelUpdateSuggestionStrip();
final SettingsValues currentSettings = mSettings.getCurrent(); final SettingsValues currentSettings = mSettings.getCurrent();
@ -1934,46 +1936,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD)); suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD));
} }
// TODO[IL]: Move this to InputLogic and make private again
public void commitCurrentAutoCorrection(final String separator) {
// Complete any pending suggestions query first
if (mHandler.hasPendingUpdateSuggestions()) {
updateSuggestionStrip();
}
final String typedAutoCorrection = mInputLogic.mWordComposer.getAutoCorrectionOrNull();
final String typedWord = mInputLogic.mWordComposer.getTypedWord();
final String autoCorrection = (typedAutoCorrection != null)
? typedAutoCorrection : typedWord;
if (autoCorrection != null) {
if (TextUtils.isEmpty(typedWord)) {
throw new RuntimeException("We have an auto-correction but the typed word "
+ "is empty? Impossible! I must commit suicide.");
}
if (mSettings.isInternal()) {
LatinImeLoggerUtils.onAutoCorrection(
typedWord, autoCorrection, separator, mInputLogic.mWordComposer);
}
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
final SuggestedWords suggestedWords = mInputLogic.mSuggestedWords;
ResearchLogger.latinIme_commitCurrentAutoCorrection(typedWord, autoCorrection,
separator, mInputLogic.mWordComposer.isBatchMode(), suggestedWords);
}
commitChosenWord(autoCorrection, LastComposedWord.COMMIT_TYPE_DECIDED_WORD,
separator);
if (!typedWord.equals(autoCorrection)) {
// This will make the correction flash for a short while as a visual clue
// to the user that auto-correction happened. It has no other effect; in particular
// note that this won't affect the text inside the text field AT ALL: it only makes
// the segment of text starting at the supplied index and running for the length
// of the auto-correction flash. At this moment, the "typedWord" argument is
// ignored by TextView.
mInputLogic.mConnection.commitCorrection(
new CorrectionInfo(mInputLogic.mLastSelectionEnd - typedWord.length(),
typedWord, autoCorrection));
}
}
}
// Called from {@link SuggestionStripView} through the {@link SuggestionStripView#Listener} // Called from {@link SuggestionStripView} through the {@link SuggestionStripView#Listener}
// interface // interface
@Override @Override

View File

@ -21,6 +21,7 @@ import android.text.TextUtils;
import android.util.Log; import android.util.Log;
import android.view.KeyCharacterMap; import android.view.KeyCharacterMap;
import android.view.KeyEvent; import android.view.KeyEvent;
import android.view.inputmethod.CorrectionInfo;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.compat.SuggestionSpanUtils; import com.android.inputmethod.compat.SuggestionSpanUtils;
@ -401,7 +402,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);
mLatinIME.commitCurrentAutoCorrection(separator); commitCurrentAutoCorrection(settingsValues, separator, handler);
didAutoCorrect = true; didAutoCorrect = true;
} else { } else {
commitTyped(StringUtils.newSingleCodePointString(codePoint)); commitTyped(StringUtils.newSingleCodePointString(codePoint));
@ -904,4 +905,47 @@ public final class InputLogic {
separatorString); separatorString);
} }
} }
// TODO: Make this private
public void commitCurrentAutoCorrection(final SettingsValues settingsValues,
final String separator,
// TODO: Remove this argument.
final LatinIME.UIHandler handler) {
// Complete any pending suggestions query first
if (handler.hasPendingUpdateSuggestions()) {
mLatinIME.updateSuggestionStrip();
}
final String typedAutoCorrection = mWordComposer.getAutoCorrectionOrNull();
final String typedWord = mWordComposer.getTypedWord();
final String autoCorrection = (typedAutoCorrection != null)
? typedAutoCorrection : typedWord;
if (autoCorrection != null) {
if (TextUtils.isEmpty(typedWord)) {
throw new RuntimeException("We have an auto-correction but the typed word "
+ "is empty? Impossible! I must commit suicide.");
}
if (settingsValues.mIsInternal) {
LatinImeLoggerUtils.onAutoCorrection(
typedWord, autoCorrection, separator, mWordComposer);
}
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
final SuggestedWords suggestedWords = mSuggestedWords;
ResearchLogger.latinIme_commitCurrentAutoCorrection(typedWord, autoCorrection,
separator, mWordComposer.isBatchMode(), suggestedWords);
}
mLatinIME.commitChosenWord(autoCorrection, LastComposedWord.COMMIT_TYPE_DECIDED_WORD,
separator);
if (!typedWord.equals(autoCorrection)) {
// This will make the correction flash for a short while as a visual clue
// to the user that auto-correction happened. It has no other effect; in particular
// note that this won't affect the text inside the text field AT ALL: it only makes
// the segment of text starting at the supplied index and running for the length
// of the auto-correction flash. At this moment, the "typedWord" argument is
// ignored by TextView.
mConnection.commitCorrection(
new CorrectionInfo(mLastSelectionEnd - typedWord.length(),
typedWord, autoCorrection));
}
}
}
} }