Merge "[ML18] Make WordComposer#getAutoCorrection a word info"

main
Jean Chalard 2014-10-08 13:04:25 +00:00 committed by Android (Google) Code Review
commit 15335d7526
3 changed files with 28 additions and 39 deletions

View File

@ -1539,7 +1539,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private void setSuggestedWords(final SuggestedWords suggestedWords) { private void setSuggestedWords(final SuggestedWords suggestedWords) {
final SettingsValues currentSettingsValues = mSettings.getCurrent(); final SettingsValues currentSettingsValues = mSettings.getCurrent();
mInputLogic.setSuggestedWords(suggestedWords, currentSettingsValues, mHandler); mInputLogic.setSuggestedWords(suggestedWords);
// TODO: Modify this when we support suggestions with hard keyboard // TODO: Modify this when we support suggestions with hard keyboard
if (!hasSuggestionStripView()) { if (!hasSuggestionStripView()) {
return; return;

View File

@ -18,6 +18,7 @@ package com.android.inputmethod.latin;
import com.android.inputmethod.event.CombinerChain; import com.android.inputmethod.event.CombinerChain;
import com.android.inputmethod.event.Event; import com.android.inputmethod.event.Event;
import com.android.inputmethod.latin.SuggestedWords.SuggestedWordInfo;
import com.android.inputmethod.latin.define.DebugFlags; import com.android.inputmethod.latin.define.DebugFlags;
import com.android.inputmethod.latin.utils.CoordinateUtils; import com.android.inputmethod.latin.utils.CoordinateUtils;
import com.android.inputmethod.latin.utils.StringUtils; import com.android.inputmethod.latin.utils.StringUtils;
@ -48,8 +49,7 @@ public final class WordComposer {
// The list of events that served to compose this string. // The list of events that served to compose this string.
private final ArrayList<Event> mEvents; private final ArrayList<Event> mEvents;
private final InputPointers mInputPointers = new InputPointers(MAX_WORD_LENGTH); private final InputPointers mInputPointers = new InputPointers(MAX_WORD_LENGTH);
private String mAutoCorrection; private SuggestedWordInfo mAutoCorrection;
private String mAutoCorrectionDictionaryType;
private boolean mIsResumed; private boolean mIsResumed;
private boolean mIsBatchMode; private boolean mIsBatchMode;
// A memory of the last rejected batch mode suggestion, if any. This goes like this: the user // A memory of the last rejected batch mode suggestion, if any. This goes like this: the user
@ -418,25 +418,17 @@ public final class WordComposer {
/** /**
* Sets the auto-correction for this word. * Sets the auto-correction for this word.
*/ */
public void setAutoCorrection(final String correction, String dictType) { public void setAutoCorrection(final SuggestedWordInfo autoCorrection) {
mAutoCorrection = correction; mAutoCorrection = autoCorrection;
mAutoCorrectionDictionaryType = dictType;
} }
/** /**
* @return the auto-correction for this word, or null if none. * @return the auto-correction for this word, or null if none.
*/ */
public String getAutoCorrectionOrNull() { public SuggestedWordInfo getAutoCorrectionOrNull() {
return mAutoCorrection; return mAutoCorrection;
} }
/**
* @return the auto-correction dictionary type or null if none.
*/
public String getAutoCorrectionDictionaryTypeOrNull() {
return mAutoCorrectionDictionaryType;
}
/** /**
* @return whether we started composing this word by resuming suggestion on an existing string * @return whether we started composing this word by resuming suggestion on an existing string
*/ */

View File

@ -607,25 +607,21 @@ public final class InputLogic {
// TODO: on the long term, this method should become private, but it will be difficult. // TODO: on the long term, this method should become private, but it will be difficult.
// Especially, how do we deal with InputMethodService.onDisplayCompletions? // Especially, how do we deal with InputMethodService.onDisplayCompletions?
public void setSuggestedWords(final SuggestedWords suggestedWords, public void setSuggestedWords(final SuggestedWords suggestedWords) {
final SettingsValues settingsValues, final LatinIME.UIHandler handler) {
if (!suggestedWords.isEmpty()) { if (!suggestedWords.isEmpty()) {
final String autoCorrection; final SuggestedWordInfo suggestedWordInfo;
final String dictType;
if (suggestedWords.mWillAutoCorrect) { if (suggestedWords.mWillAutoCorrect) {
SuggestedWordInfo info = suggestedWords.getInfo( suggestedWordInfo = suggestedWords.getInfo(SuggestedWords.INDEX_OF_AUTO_CORRECTION);
SuggestedWords.INDEX_OF_AUTO_CORRECTION);
autoCorrection = info.mWord;
dictType = info.mSourceDict.mDictType;
} else { } else {
// We can't use suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD) // We can't use suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD)
// because it may differ from mWordComposer.mTypedWord. // because it may differ from mWordComposer.mTypedWord.
autoCorrection = suggestedWords.mTypedWord; suggestedWordInfo = new SuggestedWordInfo(suggestedWords.mTypedWord,
dictType = Dictionary.TYPE_USER_TYPED; SuggestedWordInfo.MAX_SCORE,
SuggestedWordInfo.KIND_TYPED, Dictionary.DICTIONARY_USER_TYPED,
SuggestedWordInfo.NOT_AN_INDEX /* indexOfTouchPointOfSecondWord */,
SuggestedWordInfo.NOT_A_CONFIDENCE /* autoCommitFirstWordConfidence */);
} }
// TODO: Use the SuggestedWordInfo to set the auto correction when mWordComposer.setAutoCorrection(suggestedWordInfo);
// user typed word is available via SuggestedWordInfo.
mWordComposer.setAutoCorrection(autoCorrection, dictType);
} }
mSuggestedWords = suggestedWords; mSuggestedWords = suggestedWords;
final boolean newAutoCorrectionIndicator = suggestedWords.mWillAutoCorrect; final boolean newAutoCorrectionIndicator = suggestedWords.mWillAutoCorrect;
@ -2092,19 +2088,19 @@ public final class InputLogic {
// INPUT_STYLE_TYPING. // INPUT_STYLE_TYPING.
performUpdateSuggestionStripSync(settingsValues, SuggestedWords.INPUT_STYLE_TYPING); performUpdateSuggestionStripSync(settingsValues, SuggestedWords.INPUT_STYLE_TYPING);
} }
final String typedAutoCorrection = mWordComposer.getAutoCorrectionOrNull(); final SuggestedWordInfo autoCorrectionOrNull = mWordComposer.getAutoCorrectionOrNull();
final String typedWord = mWordComposer.getTypedWord(); final String typedWord = mWordComposer.getTypedWord();
final String autoCorrection = (typedAutoCorrection != null) final String stringToCommit = (autoCorrectionOrNull != null)
? typedAutoCorrection : typedWord; ? autoCorrectionOrNull.mWord : typedWord;
if (autoCorrection != null) { if (stringToCommit != null) {
if (TextUtils.isEmpty(typedWord)) { if (TextUtils.isEmpty(typedWord)) {
throw new RuntimeException("We have an auto-correction but the typed word " throw new RuntimeException("We have an auto-correction but the typed word "
+ "is empty? Impossible! I must commit suicide."); + "is empty? Impossible! I must commit suicide.");
} }
final boolean isBatchMode = mWordComposer.isBatchMode(); final boolean isBatchMode = mWordComposer.isBatchMode();
commitChosenWord(settingsValues, autoCorrection, commitChosenWord(settingsValues, stringToCommit,
LastComposedWord.COMMIT_TYPE_DECIDED_WORD, separator); LastComposedWord.COMMIT_TYPE_DECIDED_WORD, separator);
if (!typedWord.equals(autoCorrection)) { if (!typedWord.equals(stringToCommit)) {
// This will make the correction flash for a short while as a visual clue // 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 // 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 // note that this won't affect the text inside the text field AT ALL: it only makes
@ -2112,13 +2108,14 @@ public final class InputLogic {
// of the auto-correction flash. At this moment, the "typedWord" argument is // of the auto-correction flash. At this moment, the "typedWord" argument is
// ignored by TextView. // ignored by TextView.
mConnection.commitCorrection(new CorrectionInfo( mConnection.commitCorrection(new CorrectionInfo(
mConnection.getExpectedSelectionEnd() - autoCorrection.length(), mConnection.getExpectedSelectionEnd() - stringToCommit.length(),
typedWord, autoCorrection)); typedWord, stringToCommit));
StatsUtils.onAutoCorrection(typedWord, autoCorrection, isBatchMode, StatsUtils.onAutoCorrection(typedWord, stringToCommit, isBatchMode,
mWordComposer.getAutoCorrectionDictionaryTypeOrNull()); null == autoCorrectionOrNull
StatsUtils.onWordCommitAutoCorrect(autoCorrection, isBatchMode); ? null : autoCorrectionOrNull.mSourceDict.mDictType);
StatsUtils.onWordCommitAutoCorrect(stringToCommit, isBatchMode);
} else { } else {
StatsUtils.onWordCommitUserTyped(autoCorrection, isBatchMode); StatsUtils.onWordCommitUserTyped(stringToCommit, isBatchMode);
} }
} }
} }