aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod
diff options
context:
space:
mode:
authorKeisuke Kuroyanagi <ksk@google.com>2014-02-27 22:31:57 +0900
committerKeisuke Kuroyanagi <ksk@google.com>2014-02-27 22:31:57 +0900
commite9926b0d11d481c6534c059384c9a5a858ebdaae (patch)
tree6dd7239da1140798b4f024860b7483e1c9c661a5 /java/src/com/android/inputmethod
parent66c96e881330538f2dbd85e97d9c636c06af5826 (diff)
downloadlatinime-e9926b0d11d481c6534c059384c9a5a858ebdaae.tar.gz
latinime-e9926b0d11d481c6534c059384c9a5a858ebdaae.tar.xz
latinime-e9926b0d11d481c6534c059384c9a5a858ebdaae.zip
Remove redundant creation of dictionary facilitator.
Change-Id: I2edab4e3ba4ea0b9b13f9bb224aac86cac9b9f31
Diffstat (limited to 'java/src/com/android/inputmethod')
-rw-r--r--java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java10
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java50
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java1
3 files changed, 38 insertions, 23 deletions
diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java
index e767e4be9..26d5dda4e 100644
--- a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java
+++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java
@@ -186,6 +186,16 @@ public class DictionaryFacilitatorForSuggest {
}
}
+ public boolean needsToBeRecreated(final Locale newLocale,
+ final SettingsValues newSettingsValues) {
+ return !mLocale.equals(newLocale)
+ || (newSettingsValues.mUseContactsDict != (mContactsDictionary != null))
+ || (newSettingsValues.mUsePersonalizedDicts != (mUserHistoryDictionary != null))
+ || (newSettingsValues.mUsePersonalizedDicts != hasPersonalizationDictionary())
+ || (newSettingsValues.mUseOnlyPersonalizationDictionaryForDebug
+ != (mDictionarySubsetForDebug != null));
+ }
+
// initialize a debug flag for the personalization
private void initForDebug(final SettingsValues settingsValues) {
if (settingsValues.mUseOnlyPersonalizationDictionaryForDebug) {
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index 44282a492..793c1c4ac 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -508,27 +508,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) {
+ initSuggestForLocale(oldSuggest, locale);
}
}
@@ -588,13 +592,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,
@@ -603,7 +607,7 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
if (settingsValues.mCorrectionEnabled) {
newSuggest.setAutoCorrectionThreshold(settingsValues.mAutoCorrectionThreshold);
}
- resetSuggest(newSuggest);
+ replaceSuggest(newSuggest);
}
/* package private */ void resetSuggestMainDict() {
@@ -611,10 +615,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);
}
@@ -1719,7 +1723,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.
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index abf831a28..499a98d65 100644
--- a/java/src/com/android/inputmethod/latin/Suggest.java
+++ b/java/src/com/android/inputmethod/latin/Suggest.java
@@ -59,6 +59,7 @@ public final class Suggest {
// Locale used for upper- and title-casing words
public final Locale mLocale;
+ // TODO: Move dictionaryFacilitator constructing logics from LatinIME to Suggest.
public Suggest(final Locale locale,
final DictionaryFacilitatorForSuggest dictionaryFacilitator) {
mLocale = locale;