am 31747ba7: am abaf5827: Separate suggestions from SuggestionView
* commit '31747ba7874f57fe6b259e8744e42dbfe02a8d40': Separate suggestions from SuggestionViewmain
commit
2768f38ea1
|
@ -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;
|
||||||
|
@ -731,6 +733,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);
|
||||||
|
|
||||||
|
@ -995,7 +998,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) {
|
||||||
|
@ -1120,7 +1123,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);
|
||||||
}
|
}
|
||||||
|
@ -1983,8 +1986,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() {
|
||||||
|
@ -2000,11 +2003,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);
|
||||||
|
@ -2087,15 +2091,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 */,
|
||||||
|
@ -2117,7 +2122,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());
|
||||||
}
|
}
|
||||||
|
@ -2140,7 +2145,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);
|
||||||
}
|
}
|
||||||
|
@ -2165,7 +2170,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.
|
||||||
|
@ -2197,6 +2202,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();
|
||||||
}
|
}
|
||||||
|
@ -2252,7 +2258,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
|
||||||
|
@ -2269,7 +2275,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());
|
||||||
|
@ -2566,6 +2572,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