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.java128
1 files changed, 45 insertions, 83 deletions
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index bfc578082..44353ba06 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -78,7 +78,6 @@ import com.android.inputmethod.latin.suggestions.SuggestionStripView;
import com.android.inputmethod.latin.suggestions.SuggestionStripViewAccessor;
import com.android.inputmethod.latin.utils.ApplicationUtils;
import com.android.inputmethod.latin.utils.CapsModeUtils;
-import com.android.inputmethod.latin.utils.CompletionInfoUtils;
import com.android.inputmethod.latin.utils.CoordinateUtils;
import com.android.inputmethod.latin.utils.ImportantNoticeUtils;
import com.android.inputmethod.latin.utils.IntentUtils;
@@ -124,9 +123,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
private View mKeyPreviewBackingView;
private SuggestionStripView mSuggestionStripView;
- // TODO[IL]: remove this member completely.
- public CompletionInfo[] mApplicationSpecifiedCompletions;
-
private RichInputMethodManager mRichImm;
@UsedForTesting final KeyboardSwitcher mKeyboardSwitcher;
private final SubtypeSwitcher mSubtypeSwitcher;
@@ -192,8 +188,9 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final KeyboardSwitcher switcher = latinIme.mKeyboardSwitcher;
switch (msg.what) {
case MSG_UPDATE_SUGGESTION_STRIP:
+ cancelUpdateSuggestionStrip();
latinIme.mInputLogic.performUpdateSuggestionStripSync(
- latinIme.mSettings.getCurrent(), this /* handler */);
+ latinIme.mSettings.getCurrent());
break;
case MSG_UPDATE_SHIFT_STATE:
switcher.updateShiftState();
@@ -530,27 +527,31 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final EditorInfo editorInfo = getCurrentInputEditorInfo();
final InputAttributes inputAttributes = new InputAttributes(editorInfo, isFullscreenMode());
mSettings.loadSettings(this, locale, inputAttributes);
- AudioAndHapticFeedbackManager.getInstance().onSettingsChanged(mSettings.getCurrent());
- // To load the keyboard we need to load all the settings once, but resetting the
- // contacts dictionary should be deferred until after the new layout has been displayed
- // to improve responsivity. In the language switching process, we post a reopenDictionaries
- // message, then come here to read the settings for the new language before we change
- // the layout; at this time, we need to skip resetting the contacts dictionary. It will
- // be done later inside {@see #initSuggest()} when the reopenDictionaries message is
- // processed.
final SettingsValues currentSettingsValues = mSettings.getCurrent();
- final Suggest suggest = mInputLogic.mSuggest;
- if (!mHandler.hasPendingReopenDictionaries() && suggest != null) {
+ AudioAndHapticFeedbackManager.getInstance().onSettingsChanged(currentSettingsValues);
+ // This method is called on startup and language switch, before the new layout has
+ // been displayed. Opening dictionaries never affects responsivity as dictionaries are
+ // asynchronously loaded.
+ initOrResetSuggestForSettingsValues(mInputLogic.mSuggest, locale, currentSettingsValues);
+ }
+
+ private void initOrResetSuggestForSettingsValues(final Suggest oldSuggest,
+ final Locale locale, final SettingsValues settingsValues) {
+ if (!mHandler.hasPendingReopenDictionaries() && oldSuggest != null) {
// May need to reset dictionaries depending on the user settings.
final DictionaryFacilitatorForSuggest oldDictionaryFacilitator =
- suggest.mDictionaryFacilitator;
+ oldSuggest.mDictionaryFacilitator;
+ if (!oldDictionaryFacilitator.needsToBeRecreated(locale, settingsValues)) {
+ // Continue to use the same dictionary facilitator if no configuration has changed.
+ refreshPersonalizationDictionarySession();
+ return;
+ }
final DictionaryFacilitatorForSuggest dictionaryFacilitator =
- new DictionaryFacilitatorForSuggest(currentSettingsValues,
- oldDictionaryFacilitator);
+ new DictionaryFacilitatorForSuggest(settingsValues, oldDictionaryFacilitator);
// Create Suggest instance with the new dictionary facilitator.
- resetSuggest(new Suggest(suggest /* oldSuggest */, dictionaryFacilitator));
- } else if (suggest == null) {
- initSuggestForLocale(locale);
+ replaceSuggest(new Suggest(oldSuggest, dictionaryFacilitator));
+ } else if (oldSuggest == null) {
+ initSuggest();
}
}
@@ -610,13 +611,13 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
} else {
subtypeLocale = switcherSubtypeLocale;
}
- initSuggestForLocale(subtypeLocale);
+ initSuggestForLocale(mInputLogic.mSuggest, subtypeLocale);
}
- private void initSuggestForLocale(final Locale locale) {
+ private void initSuggestForLocale(final Suggest oldSuggest, final Locale locale) {
final SettingsValues settingsValues = mSettings.getCurrent();
final DictionaryFacilitatorForSuggest oldDictionaryFacilitator =
- (mInputLogic.mSuggest == null) ? null : mInputLogic.mSuggest.mDictionaryFacilitator;
+ (oldSuggest == null) ? null : oldSuggest.mDictionaryFacilitator;
// Creates new dictionary facilitator for the new locale.
final DictionaryFacilitatorForSuggest dictionaryFacilitator =
new DictionaryFacilitatorForSuggest(this /* context */, locale, settingsValues,
@@ -625,7 +626,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (settingsValues.mCorrectionEnabled) {
newSuggest.setAutoCorrectionThreshold(settingsValues.mAutoCorrectionThreshold);
}
- resetSuggest(newSuggest);
+ replaceSuggest(newSuggest);
}
/* package private */ void resetSuggestMainDict() {
@@ -633,10 +634,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mInputLogic.mSuggest.mDictionaryFacilitator;
final DictionaryFacilitatorForSuggest dictionaryFacilitator =
new DictionaryFacilitatorForSuggest(this /* listener */, oldDictionaryFacilitator);
- resetSuggest(new Suggest(mInputLogic.mSuggest /* oldSuggest */, dictionaryFacilitator));
+ replaceSuggest(new Suggest(mInputLogic.mSuggest /* oldSuggest */, dictionaryFacilitator));
}
- private void resetSuggest(final Suggest newSuggest) {
+ private void replaceSuggest(final Suggest newSuggest) {
if (ProductionFlag.USES_DEVELOPMENT_ONLY_DIAGNOSTICS) {
ResearchLogger.getInstance().initDictionary(newSuggest.mDictionaryFacilitator);
}
@@ -808,7 +809,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// The EditorInfo might have a flag that affects fullscreen mode.
// Note: This call should be done by InputMethodService?
updateFullscreenMode();
- mApplicationSpecifiedCompletions = null;
// The app calling setText() has the effect of clearing the composing
// span, so we should reset our state unconditionally, even if restarting is true.
@@ -875,7 +875,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
// This will set the punctuation suggestions if next word suggestion is off;
// otherwise it will clear the suggestion strip.
- setNeutralSuggestionStripInternal();
+ setNeutralSuggestionStrip();
mHandler.cancelUpdateSuggestionStrip();
mHandler.cancelDoubleSpacePeriodTimer();
@@ -950,8 +950,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
// 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)) {
+ mInputLogic.onUpdateSelection(oldSelStart, oldSelEnd, newSelStart, newSelEnd)) {
mKeyboardSwitcher.updateShiftState();
}
@@ -1030,8 +1029,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
return;
}
- mApplicationSpecifiedCompletions =
- CompletionInfoUtils.removeNulls(applicationSpecifiedCompletions);
final ArrayList<SuggestedWords.SuggestedWordInfo> applicationSuggestedWords =
SuggestedWords.getFromApplicationSpecifiedCompletions(
@@ -1046,18 +1043,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
}
}
- private void setSuggestionStripShownInternal(final boolean isSuggestionStripVisible) {
- // TODO: Modify this if we support suggestions with hard keyboard
- if (!onEvaluateInputViewShown() || !hasSuggestionStripView()) {
- return;
- }
- if (isSuggestionStripVisible) {
- mSuggestionStripView.setVisibility(View.VISIBLE);
- } else {
- mSuggestionStripView.setVisibility(isFullscreenMode() ? View.GONE : View.INVISIBLE);
- }
- }
-
private int getAdjustedBackingViewHeight() {
final int currentHeight = mKeyPreviewBackingView.getHeight();
if (currentHeight > 0) {
@@ -1295,7 +1280,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override
public void onStartBatchInput() {
- mInputLogic.onStartBatchInput(mSettings.getCurrent(), mKeyboardSwitcher, mHandler);
+ mInputLogic.onStartBatchInput(mSettings.getCurrent(), mKeyboardSwitcher, mHandler);
}
@Override
@@ -1305,7 +1290,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
@Override
public void onEndBatchInput(final InputPointers batchPointers) {
- mInputLogic.onEndBatchInput(mSettings.getCurrent(), batchPointers);
+ mInputLogic.onEndBatchInput(batchPointers);
}
@Override
@@ -1383,13 +1368,23 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
public void setSuggestedWords(final SuggestedWords suggestedWords,
final boolean isSuggestionStripVisible) {
mInputLogic.setSuggestedWords(suggestedWords);
+ // TODO: Modify this when we support suggestions with hard keyboard
if (!hasSuggestionStripView()) {
return;
}
+ mKeyboardSwitcher.onAutoCorrectionStateChanged(suggestedWords.mWillAutoCorrect);
+ if (!onEvaluateInputViewShown()) {
+ return;
+ }
+ if (!isSuggestionStripVisible) {
+ mSuggestionStripView.setVisibility(isFullscreenMode() ? View.GONE : View.INVISIBLE);
+ return;
+ }
+ mSuggestionStripView.setVisibility(View.VISIBLE);
+
final SettingsValues currentSettings = mSettings.getCurrent();
final boolean showSuggestions;
- if (SuggestedWords.EMPTY == suggestedWords
- || suggestedWords.isPunctuationSuggestions()
+ if (SuggestedWords.EMPTY == suggestedWords || suggestedWords.isPunctuationSuggestions()
|| !currentSettings.isSuggestionsRequested()) {
showSuggestions = !mSuggestionStripView.maybeShowImportantNoticeTitle(
currentSettings.mInputAttributes);
@@ -1400,8 +1395,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mSuggestionStripView.setSuggestions(suggestedWords,
SubtypeLocaleUtils.isRtlLanguage(mSubtypeSwitcher.getCurrentSubtype()));
}
- mKeyboardSwitcher.onAutoCorrectionStateChanged(suggestedWords.mWillAutoCorrect);
- setSuggestionStripShownInternal(isSuggestionStripVisible);
}
// TODO[IL]: Move this out of LatinIME.
@@ -1445,32 +1438,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
sequenceNumber, callback);
}
- // TODO[IL]: Move this to InputLogic
- public SuggestedWords maybeRetrieveOlderSuggestions(final String typedWord,
- final SuggestedWords suggestedWords, final SuggestedWords previousSuggestedWords) {
- // TODO: consolidate this into getSuggestedWords
- // We update the suggestion strip only when we have some suggestions to show, i.e. when
- // the suggestion count is > 1; else, we leave the old suggestions, with the typed word
- // replaced with the new one. However, when the length of the typed word is 1 or 0 (after
- // a deletion typically), we do want to remove the old suggestions. Also, if we are showing
- // the "add to dictionary" hint, we need to revert to suggestions - although it is unclear
- // how we can come here if it's displayed.
- if (suggestedWords.size() > 1 || typedWord.length() <= 1
- || !hasSuggestionStripView() || isShowingAddToDictionaryHint()) {
- return suggestedWords;
- } else {
- final SuggestedWords punctuationList =
- mSettings.getCurrent().mSpacingAndPunctuations.mSuggestPuncList;
- final SuggestedWords oldSuggestedWords = previousSuggestedWords == punctuationList
- ? SuggestedWords.EMPTY : previousSuggestedWords;
- final ArrayList<SuggestedWords.SuggestedWordInfo> typedWordAndPreviousSuggestions =
- SuggestedWords.getTypedWordAndPreviousSuggestions(typedWord, oldSuggestedWords);
- return new SuggestedWords(typedWordAndPreviousSuggestions, null /* rawSuggestions */,
- false /* typedWordValid */, false /* hasAutoCorrectionCandidate */,
- true /* isObsoleteSuggestions */, false /* isPrediction */);
- }
- }
-
@Override
public void showSuggestionStrip(final SuggestedWords sourceSuggestedWords) {
final SuggestedWords suggestedWords =
@@ -1511,15 +1478,10 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
mSuggestionStripView.showAddToDictionaryHint(word);
}
- // TODO[IL]: Define a clean interface for this
// This will show either an empty suggestion strip (if prediction is enabled) or
// punctuation suggestions (if it's disabled).
@Override
public void setNeutralSuggestionStrip() {
- setNeutralSuggestionStripInternal();
- }
-
- private void setNeutralSuggestionStripInternal() {
final SettingsValues currentSettings = mSettings.getCurrent();
final SuggestedWords neutralSuggestions = currentSettings.mBigramPredictionEnabled
? SuggestedWords.EMPTY : currentSettings.mSpacingAndPunctuations.mSuggestPuncList;
@@ -1733,7 +1695,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
final DictionaryFacilitatorForSuggest dictionaryFacilitator =
new DictionaryFacilitatorForSuggest(this, locale, mSettings.getCurrent(),
this /* listener */, oldDictionaryFacilitator);
- resetSuggest(new Suggest(locale, dictionaryFacilitator));
+ replaceSuggest(new Suggest(locale, dictionaryFacilitator));
}
// DO NOT USE THIS for any other purpose than testing.