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 mKeyPreviewBackingView;
|
||||||
private View mSuggestionsContainer;
|
private View mSuggestionsContainer;
|
||||||
private SuggestionStripView mSuggestionStripView;
|
private SuggestionStripView mSuggestionStripView;
|
||||||
|
// Never null
|
||||||
|
private SuggestedWords mSuggestedWords = SuggestedWords.EMPTY;
|
||||||
@UsedForTesting Suggest mSuggest;
|
@UsedForTesting Suggest mSuggest;
|
||||||
private CompletionInfo[] mApplicationSpecifiedCompletions;
|
private CompletionInfo[] mApplicationSpecifiedCompletions;
|
||||||
private ApplicationInfo mTargetApplicationInfo;
|
private ApplicationInfo mTargetApplicationInfo;
|
||||||
|
@ -728,6 +730,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
// otherwise it will clear the suggestion strip.
|
// otherwise it will clear the suggestion strip.
|
||||||
setPunctuationSuggestions();
|
setPunctuationSuggestions();
|
||||||
}
|
}
|
||||||
|
mSuggestedWords = SuggestedWords.EMPTY;
|
||||||
|
|
||||||
mConnection.resetCachesUponCursorMove(editorInfo.initialSelStart);
|
mConnection.resetCachesUponCursorMove(editorInfo.initialSelStart);
|
||||||
|
|
||||||
|
@ -992,7 +995,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
false /* isPrediction */);
|
false /* isPrediction */);
|
||||||
// When in fullscreen mode, show completions generated by the application
|
// When in fullscreen mode, show completions generated by the application
|
||||||
final boolean isAutoCorrection = false;
|
final boolean isAutoCorrection = false;
|
||||||
setSuggestionStrip(suggestedWords, isAutoCorrection);
|
setSuggestedWords(suggestedWords, isAutoCorrection);
|
||||||
setAutoCorrectionIndicator(isAutoCorrection);
|
setAutoCorrectionIndicator(isAutoCorrection);
|
||||||
setSuggestionStripShown(true);
|
setSuggestionStripShown(true);
|
||||||
if (ProductionFlag.IS_EXPERIMENTAL) {
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
||||||
|
@ -1117,7 +1120,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
if (mSettings.getCurrent().mBigramPredictionEnabled) {
|
if (mSettings.getCurrent().mBigramPredictionEnabled) {
|
||||||
clearSuggestionStrip();
|
clearSuggestionStrip();
|
||||||
} else {
|
} else {
|
||||||
setSuggestionStrip(mSettings.getCurrent().mSuggestPuncList, false);
|
setSuggestedWords(mSettings.getCurrent().mSuggestPuncList, false);
|
||||||
}
|
}
|
||||||
mConnection.resetCachesUponCursorMove(newCursorPosition);
|
mConnection.resetCachesUponCursorMove(newCursorPosition);
|
||||||
}
|
}
|
||||||
|
@ -1980,8 +1983,8 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
// Outside LatinIME, only used by the test suite.
|
// Outside LatinIME, only used by the test suite.
|
||||||
@UsedForTesting
|
@UsedForTesting
|
||||||
boolean isShowingPunctuationList() {
|
boolean isShowingPunctuationList() {
|
||||||
if (mSuggestionStripView == null) return false;
|
if (mSuggestedWords == null) return false;
|
||||||
return mSettings.getCurrent().mSuggestPuncList == mSuggestionStripView.getSuggestions();
|
return mSettings.getCurrent().mSuggestPuncList == mSuggestedWords;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isSuggestionsStripVisible() {
|
private boolean isSuggestionsStripVisible() {
|
||||||
|
@ -1997,11 +2000,12 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearSuggestionStrip() {
|
private void clearSuggestionStrip() {
|
||||||
setSuggestionStrip(SuggestedWords.EMPTY, false);
|
setSuggestedWords(SuggestedWords.EMPTY, false);
|
||||||
setAutoCorrectionIndicator(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) {
|
if (mSuggestionStripView != null) {
|
||||||
mSuggestionStripView.setSuggestions(words);
|
mSuggestionStripView.setSuggestions(words);
|
||||||
mKeyboardSwitcher.onAutoCorrectionStateChanged(isAutoCorrection);
|
mKeyboardSwitcher.onAutoCorrectionStateChanged(isAutoCorrection);
|
||||||
|
@ -2084,15 +2088,16 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
}
|
}
|
||||||
|
|
||||||
private SuggestedWords getOlderSuggestions(final String typedWord) {
|
private SuggestedWords getOlderSuggestions(final String typedWord) {
|
||||||
SuggestedWords previousSuggestions = mSuggestionStripView.getSuggestions();
|
SuggestedWords previousSuggestedWords = mSuggestedWords;
|
||||||
if (previousSuggestions == mSettings.getCurrent().mSuggestPuncList) {
|
if (previousSuggestedWords == mSettings.getCurrent().mSuggestPuncList) {
|
||||||
previousSuggestions = SuggestedWords.EMPTY;
|
previousSuggestedWords = SuggestedWords.EMPTY;
|
||||||
}
|
}
|
||||||
if (typedWord == null) {
|
if (typedWord == null) {
|
||||||
return previousSuggestions;
|
return previousSuggestedWords;
|
||||||
}
|
}
|
||||||
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
|
final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
|
||||||
SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, previousSuggestions);
|
SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord,
|
||||||
|
previousSuggestedWords);
|
||||||
return new SuggestedWords(typedWordAndPreviousSuggestions,
|
return new SuggestedWords(typedWordAndPreviousSuggestions,
|
||||||
false /* typedWordValid */,
|
false /* typedWordValid */,
|
||||||
false /* hasAutoCorrectionCandidate */,
|
false /* hasAutoCorrectionCandidate */,
|
||||||
|
@ -2114,7 +2119,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
}
|
}
|
||||||
mWordComposer.setAutoCorrection(autoCorrection);
|
mWordComposer.setAutoCorrection(autoCorrection);
|
||||||
final boolean isAutoCorrection = suggestedWords.willAutoCorrect();
|
final boolean isAutoCorrection = suggestedWords.willAutoCorrect();
|
||||||
setSuggestionStrip(suggestedWords, isAutoCorrection);
|
setSuggestedWords(suggestedWords, isAutoCorrection);
|
||||||
setAutoCorrectionIndicator(isAutoCorrection);
|
setAutoCorrectionIndicator(isAutoCorrection);
|
||||||
setSuggestionStripShown(isSuggestionsStripVisible());
|
setSuggestionStripShown(isSuggestionsStripVisible());
|
||||||
}
|
}
|
||||||
|
@ -2137,7 +2142,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
Stats.onAutoCorrection(typedWord, autoCorrection, separatorString, mWordComposer);
|
Stats.onAutoCorrection(typedWord, autoCorrection, separatorString, mWordComposer);
|
||||||
}
|
}
|
||||||
if (ProductionFlag.IS_EXPERIMENTAL) {
|
if (ProductionFlag.IS_EXPERIMENTAL) {
|
||||||
final SuggestedWords suggestedWords = mSuggestionStripView.getSuggestions();
|
final SuggestedWords suggestedWords = mSuggestedWords;
|
||||||
ResearchLogger.latinIme_commitCurrentAutoCorrection(typedWord, autoCorrection,
|
ResearchLogger.latinIme_commitCurrentAutoCorrection(typedWord, autoCorrection,
|
||||||
separatorString, mWordComposer.isBatchMode(), suggestedWords);
|
separatorString, mWordComposer.isBatchMode(), suggestedWords);
|
||||||
}
|
}
|
||||||
|
@ -2162,7 +2167,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
// interface
|
// interface
|
||||||
@Override
|
@Override
|
||||||
public void pickSuggestionManually(final int index, final String suggestion) {
|
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 this is a punctuation picked from the suggestion strip, pass it to onCodeInput
|
||||||
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.
|
||||||
|
@ -2194,6 +2199,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
if (mSettings.getCurrent().isApplicationSpecifiedCompletionsOn()
|
if (mSettings.getCurrent().isApplicationSpecifiedCompletionsOn()
|
||||||
&& mApplicationSpecifiedCompletions != null
|
&& mApplicationSpecifiedCompletions != null
|
||||||
&& index >= 0 && index < mApplicationSpecifiedCompletions.length) {
|
&& index >= 0 && index < mApplicationSpecifiedCompletions.length) {
|
||||||
|
mSuggestedWords = SuggestedWords.EMPTY;
|
||||||
if (mSuggestionStripView != null) {
|
if (mSuggestionStripView != null) {
|
||||||
mSuggestionStripView.clear();
|
mSuggestionStripView.clear();
|
||||||
}
|
}
|
||||||
|
@ -2249,7 +2255,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
*/
|
*/
|
||||||
private void commitChosenWord(final String chosenWord, final int commitType,
|
private void commitChosenWord(final String chosenWord, final int commitType,
|
||||||
final String separatorString) {
|
final String separatorString) {
|
||||||
final SuggestedWords suggestedWords = mSuggestionStripView.getSuggestions();
|
final SuggestedWords suggestedWords = mSuggestedWords;
|
||||||
mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(
|
mConnection.commitText(SuggestionSpanUtils.getTextWithSuggestionSpan(
|
||||||
this, chosenWord, suggestedWords, mIsMainDictionaryAvailable), 1);
|
this, chosenWord, suggestedWords, mIsMainDictionaryAvailable), 1);
|
||||||
// Add the word to the user history dictionary
|
// Add the word to the user history dictionary
|
||||||
|
@ -2266,7 +2272,7 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
if (mSettings.getCurrent().mBigramPredictionEnabled) {
|
if (mSettings.getCurrent().mBigramPredictionEnabled) {
|
||||||
clearSuggestionStrip();
|
clearSuggestionStrip();
|
||||||
} else {
|
} else {
|
||||||
setSuggestionStrip(mSettings.getCurrent().mSuggestPuncList, false);
|
setSuggestedWords(mSettings.getCurrent().mSuggestPuncList, false);
|
||||||
}
|
}
|
||||||
setAutoCorrectionIndicator(false);
|
setAutoCorrectionIndicator(false);
|
||||||
setSuggestionStripShown(isSuggestionsStripVisible());
|
setSuggestionStripShown(isSuggestionsStripVisible());
|
||||||
|
@ -2563,6 +2569,12 @@ public final class LatinIME extends InputMethodService implements KeyboardAction
|
||||||
dialog.show();
|
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) {
|
public void debugDumpStateAndCrashWithException(final String context) {
|
||||||
final StringBuilder s = new StringBuilder();
|
final StringBuilder s = new StringBuilder();
|
||||||
s.append("Target application : ").append(mTargetApplicationInfo.name)
|
s.append("Target application : ").append(mTargetApplicationInfo.name)
|
||||||
|
|
|
@ -644,10 +644,6 @@ public final class SuggestionStripView extends RelativeLayout implements OnClick
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SuggestedWords getSuggestions() {
|
|
||||||
return mSuggestedWords;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void clear() {
|
public void clear() {
|
||||||
mSuggestionsStrip.removeAllViews();
|
mSuggestionsStrip.removeAllViews();
|
||||||
removeAllViews();
|
removeAllViews();
|
||||||
|
|
|
@ -74,15 +74,22 @@ public class InputLogicTestsNonEnglish extends InputTestsBase {
|
||||||
public void testWordThenSpaceDisplaysPredictions() {
|
public void testWordThenSpaceDisplaysPredictions() {
|
||||||
final String WORD_TO_TYPE = "beaujolais ";
|
final String WORD_TO_TYPE = "beaujolais ";
|
||||||
final String EXPECTED_RESULT = "nouveau";
|
final String EXPECTED_RESULT = "nouveau";
|
||||||
changeLanguage("fr");
|
final boolean defaultNextWordPredictionOption =
|
||||||
type(WORD_TO_TYPE);
|
mLatinIME.getResources().getBoolean(R.bool.config_default_next_word_prediction);
|
||||||
sleep(DELAY_TO_WAIT_FOR_UNDERLINE);
|
final boolean previousNextWordPredictionOption =
|
||||||
runMessages();
|
setBooleanPreference(NEXT_WORD_PREDICTION_OPTION, true,
|
||||||
final SuggestionStripView suggestionStripView =
|
defaultNextWordPredictionOption);
|
||||||
(SuggestionStripView)mInputView.findViewById(R.id.suggestion_strip_view);
|
try {
|
||||||
final SuggestedWords suggestedWords = suggestionStripView.getSuggestions();
|
changeLanguage("fr");
|
||||||
assertEquals("type word then type space yields predictions for French",
|
type(WORD_TO_TYPE);
|
||||||
EXPECTED_RESULT, suggestedWords.getWord(0));
|
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() {
|
public void testAutoCorrectForGerman() {
|
||||||
|
|
Loading…
Reference in New Issue