aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/latin/LatinIME.java
diff options
context:
space:
mode:
Diffstat (limited to 'java/src/com/android/inputmethod/latin/LatinIME.java')
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java63
1 files changed, 27 insertions, 36 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index ec14e9fea..efc14fc86 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -789,7 +789,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (mSuggestionStripView != null) {
// This will set the punctuation suggestions if next word suggestion is off;
// otherwise it will clear the suggestion strip.
- setPunctuationSuggestions();
+ setNeutralSuggestionStrip();
}
// Sometimes, while rotating, for some reason the framework tells the app we are not
@@ -912,8 +912,14 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
composingSpanEnd, mInputLogic.mConnection);
}
- if (mInputLogic.onUpdateSelection(mSettings.getCurrent(), oldSelStart, oldSelEnd,
- newSelStart, newSelEnd, composingSpanStart, composingSpanEnd)) {
+ // If the keyboard is not visible, we don't need to do all the housekeeping work, as it
+ // will be reset when the keyboard shows up anyway.
+ // TODO: revisit this when LatinIME supports hardware keyboards.
+ // NOTE: the test harness subclasses LatinIME and overrides isInputViewShown().
+ // TODO: find a better way to simulate actual execution.
+ if (isInputViewShown() &&
+ mInputLogic.onUpdateSelection(mSettings.getCurrent(), oldSelStart, oldSelEnd,
+ newSelStart, newSelEnd, composingSpanStart, composingSpanEnd)) {
mKeyboardSwitcher.updateShiftState();
}
@@ -984,7 +990,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
if (!mSettings.getCurrent().isApplicationSpecifiedCompletionsOn()) return;
if (applicationSpecifiedCompletions == null) {
- clearSuggestionStrip();
+ setNeutralSuggestionStrip();
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.latinIME_onDisplayCompletions(null);
}
@@ -999,13 +1005,12 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final SuggestedWords suggestedWords = new SuggestedWords(
applicationSuggestedWords,
false /* typedWordValid */,
- false /* hasAutoCorrectionCandidate */,
+ false /* willAutoCorrect */,
false /* isPunctuationSuggestions */,
false /* isObsoleteSuggestions */,
false /* isPrediction */);
// When in fullscreen mode, show completions generated by the application
setSuggestedWords(suggestedWords);
- setAutoCorrectionIndicator(false);
setSuggestionStripShown(true);
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.latinIME_onDisplayCompletions(applicationSpecifiedCompletions);
@@ -1324,21 +1329,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
// TODO[IL]: Define a clear interface for this
- public void clearSuggestionStrip() {
- setSuggestedWords(SuggestedWords.EMPTY);
- setAutoCorrectionIndicator(false);
- }
-
- // TODO[IL]: Define a clear interface for this
public void setSuggestedWords(final SuggestedWords words) {
- mInputLogic.mSuggestedWords = words;
if (mSuggestionStripView != null) {
mSuggestionStripView.setSuggestions(words);
mKeyboardSwitcher.onAutoCorrectionStateChanged(words.mWillAutoCorrect);
}
- }
-
- private void setAutoCorrectionIndicator(final boolean newAutoCorrectionIndicator) {
+ mInputLogic.mSuggestedWords = words;
+ final boolean newAutoCorrectionIndicator = words.mWillAutoCorrect;
// Put a blue underline to a word in TextView which will be auto-corrected.
if (mInputLogic.mIsAutoCorrectionIndicatorOn != newAutoCorrectionIndicator
&& mInputLogic.mWordComposer.isComposingWord()) {
@@ -1424,14 +1421,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
- private void showSuggestionStripWithTypedWord(final SuggestedWords suggestedWords,
+ private void showSuggestionStripWithTypedWord(final SuggestedWords sourceSuggestedWords,
final String typedWord) {
- if (suggestedWords.isEmpty()) {
- // No auto-correction is available, clear the cached values.
- AccessibilityUtils.getInstance().setAutoCorrection(null, null);
- clearSuggestionStrip();
- return;
- }
+ final SuggestedWords suggestedWords =
+ sourceSuggestedWords.isEmpty() ? SuggestedWords.EMPTY : sourceSuggestedWords;
final String autoCorrection;
if (suggestedWords.mWillAutoCorrect) {
autoCorrection = suggestedWords.getWord(SuggestedWords.INDEX_OF_AUTO_CORRECTION);
@@ -1440,23 +1433,20 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// because it may differ from mWordComposer.mTypedWord.
autoCorrection = typedWord;
}
- mInputLogic.mWordComposer.setAutoCorrection(autoCorrection);
+ if (SuggestedWords.EMPTY != suggestedWords) {
+ mInputLogic.mWordComposer.setAutoCorrection(autoCorrection);
+ }
setSuggestedWords(suggestedWords);
- setAutoCorrectionIndicator(suggestedWords.mWillAutoCorrect);
setSuggestionStripShown(isSuggestionsStripVisible());
- // An auto-correction is available, cache it in accessibility code so
- // we can be speak it if the user touches a key that will insert it.
+ // Cache the auto-correction in accessibility code so we can speak it if the user
+ // touches a key that will insert it.
AccessibilityUtils.getInstance().setAutoCorrection(suggestedWords, typedWord);
}
// TODO[IL]: Define a clean interface for this
public void showSuggestionStrip(final SuggestedWords suggestedWords) {
- if (suggestedWords.isEmpty()) {
- clearSuggestionStrip();
- return;
- }
- showSuggestionStripWithTypedWord(suggestedWords,
- suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD));
+ showSuggestionStripWithTypedWord(suggestedWords, suggestedWords.isEmpty() ? null
+ : suggestedWords.getWord(SuggestedWords.INDEX_OF_TYPED_WORD));
}
// Called from {@link SuggestionStripView} through the {@link SuggestionStripView#Listener}
@@ -1555,14 +1545,15 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
// TODO[IL]: Define a clean interface for this
- public void setPunctuationSuggestions() {
+ // This will show either an empty suggestion strip (if prediction is enabled) or
+ // punctuation suggestions (if it's disabled).
+ public void setNeutralSuggestionStrip() {
final SettingsValues currentSettings = mSettings.getCurrent();
if (currentSettings.mBigramPredictionEnabled) {
- clearSuggestionStrip();
+ setSuggestedWords(SuggestedWords.EMPTY);
} else {
setSuggestedWords(currentSettings.mSpacingAndPunctuations.mSuggestPuncList);
}
- setAutoCorrectionIndicator(false);
setSuggestionStripShown(isSuggestionsStripVisible());
}