Merge "Make SuggestedWords partially immutable"

main
Tadashi G. Takaoka 2012-03-05 05:29:14 -08:00 committed by Android (Google) Code Review
commit 40b6e666e1
4 changed files with 17 additions and 23 deletions

View File

@ -1829,7 +1829,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
} }
final SuggestedWords suggestedWords = builder.build(); final SuggestedWords suggestedWords = builder.build();
if (Utils.shouldBlockAutoCorrectionBySafetyNet(suggestedWords, mSuggest)) { if (Utils.shouldBlockAutoCorrectionBySafetyNet(suggestedWords, mSuggest)) {
suggestedWords.setShouldBlockAutoCorrectionBySatefyNet(); suggestedWords.setShouldBlockAutoCorrectionBySafetyNet();
} }
showSuggestions(builder.build(), typedWord); showSuggestions(builder.build(), typedWord);
} }
@ -1886,7 +1886,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
@Override @Override
public void pickSuggestionManually(final int index, final CharSequence suggestion) { public void pickSuggestionManually(final int index, final CharSequence suggestion) {
mComposingStateManager.onFinishComposingText(); mComposingStateManager.onFinishComposingText();
final SuggestedWords suggestions = mSuggestionsView.getSuggestions(); final SuggestedWords suggestedWords = mSuggestionsView.getSuggestions();
mVoiceProxy.flushAndLogAllTextModificationCounters(index, suggestion, mVoiceProxy.flushAndLogAllTextModificationCounters(index, suggestion,
mSettingsValues.mWordSeparators); mSettingsValues.mWordSeparators);
@ -1910,8 +1910,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
if (suggestion.length() == 1 && isShowingPunctuationList()) { if (suggestion.length() == 1 && isShowingPunctuationList()) {
// Word separators are suggested before the user inputs something. // Word separators are suggested before the user inputs something.
// So, LatinImeLogger logs "" as a user's input. // So, LatinImeLogger logs "" as a user's input.
LatinImeLogger.logOnManualSuggestion( LatinImeLogger.logOnManualSuggestion("", suggestion.toString(), index, suggestedWords);
"", suggestion.toString(), index, suggestions.mWords);
// Rely on onCodeInput to do the complicated swapping/stripping logic consistently. // Rely on onCodeInput to do the complicated swapping/stripping logic consistently.
final int primaryCode = suggestion.charAt(0); final int primaryCode = suggestion.charAt(0);
onCodeInput(primaryCode, new int[] { primaryCode }, onCodeInput(primaryCode, new int[] { primaryCode },
@ -1922,7 +1921,7 @@ public class LatinIME extends InputMethodServiceCompatWrapper implements Keyboar
// We need to log before we commit, because the word composer will store away the user // We need to log before we commit, because the word composer will store away the user
// typed word. // typed word.
LatinImeLogger.logOnManualSuggestion(mWordComposer.getTypedWord().toString(), LatinImeLogger.logOnManualSuggestion(mWordComposer.getTypedWord().toString(),
suggestion.toString(), index, suggestions.mWords); suggestion.toString(), index, suggestedWords);
mExpectingUpdateSelection = true; mExpectingUpdateSelection = true;
commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK, commitChosenWord(suggestion, LastComposedWord.COMMIT_TYPE_MANUAL_PICK,
LastComposedWord.NOT_A_SEPARATOR); LastComposedWord.NOT_A_SEPARATOR);

View File

@ -44,7 +44,7 @@ public class LatinImeLogger implements SharedPreferences.OnSharedPreferenceChang
} }
public static void logOnManualSuggestion( public static void logOnManualSuggestion(
String before, String after, int position, List<CharSequence> suggestions) { String before, String after, int position, SuggestedWords suggestedWords) {
} }
public static void logOnAutoCorrection(String before, String after, int separatorCode) { public static void logOnAutoCorrection(String before, String after, int separatorCode) {

View File

@ -20,6 +20,7 @@ import android.text.TextUtils;
import android.view.inputmethod.CompletionInfo; import android.view.inputmethod.CompletionInfo;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
@ -27,14 +28,15 @@ import java.util.List;
public class SuggestedWords { public class SuggestedWords {
public static final SuggestedWords EMPTY = new SuggestedWords(null, false, false, false, null); public static final SuggestedWords EMPTY = new SuggestedWords(null, false, false, false, null);
public final List<CharSequence> mWords; private final List<CharSequence> mWords;
public final boolean mTypedWordValid; public final boolean mTypedWordValid;
public final boolean mHasAutoCorrectionCandidate; public final boolean mHasAutoCorrectionCandidate;
public final boolean mIsPunctuationSuggestions; public final boolean mIsPunctuationSuggestions;
private final List<SuggestedWordInfo> mSuggestedWordInfoList; private final List<SuggestedWordInfo> mSuggestedWordInfoList;
// TODO: Make the following member final.
private boolean mShouldBlockAutoCorrectionBySafetyNet; private boolean mShouldBlockAutoCorrectionBySafetyNet;
private SuggestedWords(List<CharSequence> words, boolean typedWordValid, SuggestedWords(List<CharSequence> words, boolean typedWordValid,
boolean hasAutoCorrectionCandidate, boolean isPunctuationSuggestions, boolean hasAutoCorrectionCandidate, boolean isPunctuationSuggestions,
List<SuggestedWordInfo> suggestedWordInfoList) { List<SuggestedWordInfo> suggestedWordInfoList) {
if (words != null) { if (words != null) {
@ -65,11 +67,8 @@ public class SuggestedWords {
return mHasAutoCorrectionCandidate && size() > 1 && !mTypedWordValid; return mHasAutoCorrectionCandidate && size() > 1 && !mTypedWordValid;
} }
public boolean isPunctuationSuggestions() { // TODO: Remove this method.
return mIsPunctuationSuggestions; public void setShouldBlockAutoCorrectionBySafetyNet() {
}
public void setShouldBlockAutoCorrectionBySatefyNet() {
mShouldBlockAutoCorrectionBySafetyNet = true; mShouldBlockAutoCorrectionBySafetyNet = true;
} }
@ -190,15 +189,11 @@ public class SuggestedWords {
@Override @Override
public String toString() { public String toString() {
// Pretty-print method to help debug // Pretty-print method to help debug
final StringBuilder sb = new StringBuilder("StringBuilder: mTypedWordValid = " return "SuggestedWords.Builder:"
+ mTypedWordValid + " ; mHasMinimalSuggestion = " + mHasMinimalSuggestion + " mTypedWordValid = " + mTypedWordValid
+ " ; mIsPunctuationSuggestions = " + mIsPunctuationSuggestions + " mHasMinimalSuggestion = " + mHasMinimalSuggestion
+ " --- "); + " mIsPunctuationSuggestions = " + mIsPunctuationSuggestions
for (CharSequence s : mWords) { + " mWords=" + Arrays.toString(mWords.toArray());
sb.append(s);
sb.append(" ; ");
}
return sb.toString();
} }
} }

View File

@ -335,7 +335,7 @@ public class SuggestionsView extends RelativeLayout implements OnClickListener,
public void layout(SuggestedWords suggestions, ViewGroup stripView, ViewGroup placer, public void layout(SuggestedWords suggestions, ViewGroup stripView, ViewGroup placer,
int stripWidth) { int stripWidth) {
if (suggestions.isPunctuationSuggestions()) { if (suggestions.mIsPunctuationSuggestions) {
layoutPunctuationSuggestions(suggestions, stripView); layoutPunctuationSuggestions(suggestions, stripView);
return; return;
} }