am 31747ba7: am abaf5827: Separate suggestions from SuggestionView

* commit '31747ba7874f57fe6b259e8744e42dbfe02a8d40':
  Separate suggestions from SuggestionView
This commit is contained in:
Jean Chalard 2013-02-28 21:20:22 -08:00 committed by Android Git Automerger
commit 2768f38ea1
3 changed files with 44 additions and 29 deletions

View file

@ -132,6 +132,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
private View mKeyPreviewBackingView;
private View mSuggestionsContainer;
private SuggestionStripView mSuggestionStripView;
// Never null
private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
@UsedForTesting Suggest mSuggest;
private CompletionInfo[] mApplicationSpecifiedCompletions;
private ApplicationInfo mTargetApplicationInfo;
@ -731,6 +733,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// otherwise it will clear the suggestion strip.
setPunctuationSuggestions();
}
mSuggestedWords = SuggestedWords.EMPTY;
mConnection.resetCachesUponCursorMove(editorInfo.initialSelStart);
@ -995,7 +998,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
false /* isPrediction */);
// When in fullscreen mode, show completions generated by the application
final boolean isAutoCorrection = false;
setSuggestionStrip(suggestedWords, isAutoCorrection);
setSuggestedWords(suggestedWords, isAutoCorrection);
setAutoCorrectionIndicator(isAutoCorrection);
setSuggestionStripShown(true);
if (ProductionFlag.IS_EXPERIMENTAL) {
@ -1120,7 +1123,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
if (mSettings.getCurrent().mBigramPredictionEnabled) {
clearSuggestionStrip();
} else {
setSuggestionStrip(mSettings.getCurrent().mSuggestPuncList, false);
setSuggestedWords(mSettings.getCurrent().mSuggestPuncList, false);
}
mConnection.resetCachesUponCursorMove(newCursorPosition);
}
@ -1983,8 +1986,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// Outside LatinIME, only used by the test suite.
@UsedForTesting
boolean isShowingPunctuationList() {
if (mSuggestionStripView == null) return false;
return mSettings.getCurrent().mSuggestPuncList == mSuggestionStripView.getSuggestions();
if (mSuggestedWords == null) return false;
return mSettings.getCurrent().mSuggestPuncList == mSuggestedWords;
}
private boolean isSuggestionsStripVisible() {
@ -2000,11 +2003,12 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
}
private void clearSuggestionStrip() {
setSuggestionStrip(SuggestedWords.EMPTY, false);
setSuggestedWords(SuggestedWords.EMPTY, false);
setAutoCorrectionIndicator(false);
}
private void setSuggestionStrip(final SuggestedWords words, final boolean isAutoCorrection) {
private void setSuggestedWords(final SuggestedWords words, final boolean isAutoCorrection) {
mSuggestedWords = words;
if (mSuggestionStripView != null) {
mSuggestionStripView.setSuggestions(words);
mKeyboardSwitcher.onAutoCorrectionStateChanged(isAutoCorrection);
@ -2087,15 +2091,16 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
}
private SuggestedWords getOlderSuggestions(final String typedWord) {
SuggestedWords previousSuggestions = mSuggestionStripView.getSuggestions();
if (previousSuggestions == mSettings.getCurrent().mSuggestPuncList) {
previousSuggestions = SuggestedWords.EMPTY;
SuggestedWords previousSuggestedWords = mSuggestedWords;
if (previousSuggestedWords == mSettings.getCurrent().mSuggestPuncList) {
previousSuggestedWords = SuggestedWords.EMPTY;
}
if (typedWord == null) {
return previousSuggestions;
return previousSuggestedWords;
}
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, previousSuggestions);
SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord,
previousSuggestedWords);
return new SuggestedWords(typedWordAndPreviousSuggestions,
false /* typedWordValid */,
false /* hasAutoCorrectionCandidate */,
@ -2117,7 +2122,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
}
mWordComposer.setAutoCorrection(autoCorrection);
final boolean isAutoCorrection = suggestedWords.willAutoCorrect();
setSuggestionStrip(suggestedWords, isAutoCorrection);
setSuggestedWords(suggestedWords, isAutoCorrection);
setAutoCorrectionIndicator(isAutoCorrection);
setSuggestionStripShown(isSuggestionsStripVisible());
}
@ -2140,7 +2145,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
Stats.onAutoCorrection(typedWord, autoCorrection, separatorString, mWordComposer);
}
if (ProductionFlag.IS_EXPERIMENTAL) {
final SuggestedWords suggestedWords = mSuggestionStripView.getSuggestions();
final SuggestedWords suggestedWords = mSuggestedWords;
ResearchLogger.latinIme_commitCurrentAutoCorrection(typedWord, autoCorrection,
separatorString, mWordComposer.isBatchMode(), suggestedWords);
}
@ -2165,7 +2170,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
// interface
@Override
public void pickSuggestionManually(final int index, final String suggestion) {
final SuggestedWords suggestedWords = mSuggestionStripView.getSuggestions();
final SuggestedWords suggestedWords = mSuggestedWords;
// If this is a punctuation picked from the suggestion strip, pass it to onCodeInput
if (suggestion.length() == 1 && isShowingPunctuationList()) {
// Word separators are suggested before the user inputs something.
@ -2197,6 +2202,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
if (mSettings.getCurrent().isApplicationSpecifiedCompletionsOn()
&& mApplicationSpecifiedCompletions != null
&& index >= 0 && index < mApplicationSpecifiedCompletions.length) {
mSuggestedWords = SuggestedWords.EMPTY;
if (mSuggestionStripView != null) {
mSuggestionStripView.clear();
}
@ -2252,7 +2258,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
*/
private void commitChosenWord(final String chosenWord, final int commitType,
final String separatorString) {
final SuggestedWords suggestedWords = mSuggestionStripView.getSuggestions();
final SuggestedWords suggestedWords = mSuggestedWords;
mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(
this, chosenWord, suggestedWords, mIsMainDictionaryAvailable), 1);
// Add the word to the user history dictionary
@ -2269,7 +2275,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
if (mSettings.getCurrent().mBigramPredictionEnabled) {
clearSuggestionStrip();
} else {
setSuggestionStrip(mSettings.getCurrent().mSuggestPuncList, false);
setSuggestedWords(mSettings.getCurrent().mSuggestPuncList, false);
}
setAutoCorrectionIndicator(false);
setSuggestionStripShown(isSuggestionsStripVisible());
@ -2566,6 +2572,12 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
dialog.show();
}
// TODO: can this be removed somehow without breaking the tests?
@UsedForTesting
/* package for test */ String getFirstSuggestedWord() {
return mSuggestedWords.size() > 0 ? mSuggestedWords.getWord(0) : null;
}
public void debugDumpStateAndCrashWithException(final String context) {
final StringBuilder s = new StringBuilder();
s.append("Target application : ").append(mTargetApplicationInfo.name)

View file

@ -644,10 +644,6 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
return false;
}
public SuggestedWords getSuggestions() {
return mSuggestedWords;
}
public void clear() {
mSuggestionsStrip.removeAllViews();
removeAllViews();

View file

@ -74,15 +74,22 @@ public class InputLogicTestsNonEnglish extends InputTestsBase {
public void testWordThenSpaceDisplaysPredictions() {
final String WORD_TO_TYPE = "beaujolais ";
final String EXPECTED_RESULT = "nouveau";
changeLanguage("fr");
type(WORD_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
runMessages();
final SuggestionStripView suggestionStripView =
(SuggestionStripView)mInputView.findViewById(R.id.suggestion_strip_view);
final SuggestedWords suggestedWords = suggestionStripView.getSuggestions();
assertEquals("type word then type space yields predictions for French",
EXPECTED_RESULT, suggestedWords.getWord(0));
final boolean defaultNextWordPredictionOption =
mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction);
final boolean previousNextWordPredictionOption =
setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, true,
defaultNextWordPredictionOption);
try {
changeLanguage("fr");
type(WORD_TO_TYPE);
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
runMessages();
assertEquals("type word then type space yields predictions for French",
EXPECTED_RESULT, mLatinIME.getFirstSuggestedWord());
} finally {
setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption,
defaultNextWordPredictionOption);
}
}
public void testAutoCorrectForGerman() {