Separate suggestions from SuggestionView
This is a cleanup change, but it's also necessary for Bug: 8152758 Change-Id: Id6ba06243f573fdb856f87d1df03277c9f2e5e71main
parent
bc218dda8b
commit
abaf5827e7
|
@ -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;
|
||||
|
@ -728,6 +730,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
|||
// otherwise it will clear the suggestion strip.
|
||||
setPunctuationSuggestions();
|
||||
}
|
||||
mSuggestedWords = SuggestedWords.EMPTY;
|
||||
|
||||
mConnection.resetCachesUponCursorMove(editorInfo.initialSelStart);
|
||||
|
||||
|
@ -992,7 +995,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) {
|
||||
|
@ -1117,7 +1120,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);
|
||||
}
|
||||
|
@ -1980,8 +1983,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() {
|
||||
|
@ -1997,11 +2000,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);
|
||||
|
@ -2084,15 +2088,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 */,
|
||||
|
@ -2114,7 +2119,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());
|
||||
}
|
||||
|
@ -2137,7 +2142,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);
|
||||
}
|
||||
|
@ -2162,7 +2167,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.
|
||||
|
@ -2194,6 +2199,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();
|
||||
}
|
||||
|
@ -2249,7 +2255,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
|
||||
|
@ -2266,7 +2272,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());
|
||||
|
@ -2563,6 +2569,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)
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -74,15 +74,22 @@ public class InputLogicTestsNonEnglish extends InputTestsBase {
|
|||
public void testWordThenSpaceDisplaysPredictions() {
|
||||
final String WORD_TO_TYPE = "beaujolais ";
|
||||
final String EXPECTED_RESULT = "nouveau";
|
||||
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();
|
||||
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));
|
||||
EXPECTED_RESULT, mLatinIME.getFirstSuggestedWord());
|
||||
} finally {
|
||||
setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, previousNextWordPredictionOption,
|
||||
defaultNextWordPredictionOption);
|
||||
}
|
||||
}
|
||||
|
||||
public void testAutoCorrectForGerman() {
|
||||
|
|
Loading…
Reference in New Issue