am e5040f6b: Merge "[IL103] Save the typed word separately in SuggestedWords."

* commit 'e5040f6b0d4101c55c11d5e200dc2b203b7cbdc0':
  [IL103] Save the typed word separately in SuggestedWords.
main
Jean Chalard 2014-01-29 19:47:01 -08:00 committed by Android Git Automerger
commit 285ab4af53
3 changed files with 26 additions and 7 deletions

View File

@ -1538,6 +1538,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} }
} }
// [IL] TODO: remove the second argument
public void unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip( public void unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(
final SuggestedWords suggestedWords, final String typedWord) { final SuggestedWords suggestedWords, final String typedWord) {
// Note that it's very important here that suggestedWords.mWillAutoCorrect is false. // Note that it's very important here that suggestedWords.mWillAutoCorrect is false.
@ -1547,7 +1548,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// the text to adapt it. // the text to adapt it.
// TODO: remove mIsAutoCorrectionIndicatorOn (see comment on definition) // TODO: remove mIsAutoCorrectionIndicatorOn (see comment on definition)
mInputLogic.mIsAutoCorrectionIndicatorOn = false; mInputLogic.mIsAutoCorrectionIndicatorOn = false;
mHandler.showSuggestionStripWithTypedWord(suggestedWords, typedWord); mHandler.showSuggestionStripWithTypedWord(suggestedWords, suggestedWords.mTypedWord);
} }
// TODO: Make this private // TODO: Make this private

View File

@ -68,6 +68,21 @@ public final class SuggestedWords {
final boolean isObsoleteSuggestions, final boolean isObsoleteSuggestions,
final boolean isPrediction, final boolean isPrediction,
final int sequenceNumber) { final int sequenceNumber) {
this(suggestedWordInfoList,
suggestedWordInfoList.isEmpty() ? null
: suggestedWordInfoList.get(INDEX_OF_TYPED_WORD).mWord,
typedWordValid, willAutoCorrect, isPunctuationSuggestions,
isObsoleteSuggestions, isPrediction, sequenceNumber);
}
public SuggestedWords(final ArrayList<SuggestedWordInfo> suggestedWordInfoList,
final String typedWord,
final boolean typedWordValid,
final boolean willAutoCorrect,
final boolean isPunctuationSuggestions,
final boolean isObsoleteSuggestions,
final boolean isPrediction,
final int sequenceNumber) {
mSuggestedWordInfoList = suggestedWordInfoList; mSuggestedWordInfoList = suggestedWordInfoList;
mTypedWordValid = typedWordValid; mTypedWordValid = typedWordValid;
mWillAutoCorrect = willAutoCorrect; mWillAutoCorrect = willAutoCorrect;
@ -75,7 +90,7 @@ public final class SuggestedWords {
mIsObsoleteSuggestions = isObsoleteSuggestions; mIsObsoleteSuggestions = isObsoleteSuggestions;
mIsPrediction = isPrediction; mIsPrediction = isPrediction;
mSequenceNumber = sequenceNumber; mSequenceNumber = sequenceNumber;
mTypedWord = suggestedWordInfoList.isEmpty() ? null : getWord(INDEX_OF_TYPED_WORD); mTypedWord = typedWord;
} }
public boolean isEmpty() { public boolean isEmpty() {
@ -279,17 +294,21 @@ public final class SuggestedWords {
// words from the member ArrayList as some other parties may expect the object to never change. // words from the member ArrayList as some other parties may expect the object to never change.
public SuggestedWords getSuggestedWordsExcludingTypedWord() { public SuggestedWords getSuggestedWordsExcludingTypedWord() {
final ArrayList<SuggestedWordInfo> newSuggestions = CollectionUtils.newArrayList(); final ArrayList<SuggestedWordInfo> newSuggestions = CollectionUtils.newArrayList();
String typedWord = null;
for (int i = 0; i < mSuggestedWordInfoList.size(); ++i) { for (int i = 0; i < mSuggestedWordInfoList.size(); ++i) {
final SuggestedWordInfo info = mSuggestedWordInfoList.get(i); final SuggestedWordInfo info = mSuggestedWordInfoList.get(i);
if (SuggestedWordInfo.KIND_TYPED != info.mKind) { if (SuggestedWordInfo.KIND_TYPED != info.mKind) {
newSuggestions.add(info); newSuggestions.add(info);
} else {
assert(null == typedWord);
typedWord = info.mWord;
} }
} }
// We should never autocorrect, so we say the typed word is valid. Also, in this case, // We should never autocorrect, so we say the typed word is valid. Also, in this case,
// no auto-correction should take place hence willAutoCorrect = false. // no auto-correction should take place hence willAutoCorrect = false.
return new SuggestedWords(newSuggestions, true /* typedWordValid */, return new SuggestedWords(newSuggestions, typedWord, true /* typedWordValid */,
false /* willAutoCorrect */, mIsPunctuationSuggestions, mIsObsoleteSuggestions, false /* willAutoCorrect */, mIsPunctuationSuggestions, mIsObsoleteSuggestions,
mIsPrediction); mIsPrediction, NOT_A_SEQUENCE_NUMBER);
} }
// Creates a new SuggestedWordInfo from the currently suggested words that removes all but the // Creates a new SuggestedWordInfo from the currently suggested words that removes all but the

View File

@ -1225,11 +1225,10 @@ public final class InputLogic {
} else { } else {
// We found suggestion spans in the word. We'll create the SuggestedWords out of // We found suggestion spans in the word. We'll create the SuggestedWords out of
// them, and make willAutoCorrect false. // them, and make willAutoCorrect false.
final SuggestedWords suggestedWords = new SuggestedWords(suggestions, final SuggestedWords suggestedWords = new SuggestedWords(suggestions, typedWord,
true /* typedWordValid */, false /* willAutoCorrect */, true /* typedWordValid */, false /* willAutoCorrect */,
false /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */, false /* isPunctuationSuggestions */, false /* isObsoleteSuggestions */,
false /* isPrediction */); false /* isPrediction */, SuggestedWords.NOT_A_SEQUENCE_NUMBER);
// We need to pass typedWord because mWordComposer.mTypedWord may differ from typedWord.
mLatinIME.unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(suggestedWords, mLatinIME.unsetIsAutoCorrectionIndicatorOnAndCallShowSuggestionStrip(suggestedWords,
typedWord); typedWord);
} }