aboutsummaryrefslogtreecommitdiffstats
path: root/java/src
diff options
context:
space:
mode:
Diffstat (limited to 'java/src')
-rw-r--r--java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java20
-rw-r--r--java/src/com/android/inputmethod/latin/LatinIME.java50
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputMethodManager.java73
-rw-r--r--java/src/com/android/inputmethod/latin/Suggest.java1
-rw-r--r--java/src/com/android/inputmethod/latin/settings/DebugSettings.java2
-rw-r--r--java/src/com/android/inputmethod/latin/settings/SettingsValues.java5
-rw-r--r--java/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtils.java2
7 files changed, 84 insertions, 69 deletions
diff --git a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java
index cd18a6ba5..d6178fcee 100644
--- a/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java
+++ b/java/src/com/android/inputmethod/latin/DictionaryFacilitatorForSuggest.java
@@ -55,7 +55,6 @@ public class DictionaryFacilitatorForSuggest {
private final ConcurrentHashMap<String, Dictionary> mDictionaries =
CollectionUtils.newConcurrentHashMap();
- private HashSet<String> mDictionarySubsetForDebug = null;
private Dictionary mMainDictionary;
private ContactsBinaryDictionary mContactsDictionary;
@@ -85,7 +84,6 @@ public class DictionaryFacilitatorForSuggest {
mContext = context;
mLocale = locale;
mLatchForWaitingLoadingMainDictionary = new CountDownLatch(1);
- initForDebug(settingsValues);
loadMainDict(context, locale, listener);
setUserDictionary(new UserBinaryDictionary(context, locale));
resetAdditionalDictionaries(oldDictionaryFacilitator, settingsValues);
@@ -101,7 +99,6 @@ public class DictionaryFacilitatorForSuggest {
final DictionaryFacilitatorForSuggest oldDictionaryFacilitator) {
mContext = oldDictionaryFacilitator.mContext;
mLocale = oldDictionaryFacilitator.mLocale;
- mDictionarySubsetForDebug = oldDictionaryFacilitator.mDictionarySubsetForDebug;
mLatchForWaitingLoadingMainDictionary = new CountDownLatch(1);
loadMainDict(mContext, mLocale, listener);
// Transfer user dictionary.
@@ -130,7 +127,6 @@ public class DictionaryFacilitatorForSuggest {
mContext = oldDictionaryFacilitator.mContext;
mLocale = oldDictionaryFacilitator.mLocale;
mLatchForWaitingLoadingMainDictionary = new CountDownLatch(0);
- initForDebug(settingsValues);
// Transfer main dictionary.
setMainDictionary(oldDictionaryFacilitator.mMainDictionary);
oldDictionaryFacilitator.removeDictionary(Dictionary.TYPE_MAIN);
@@ -197,12 +193,12 @@ public class DictionaryFacilitatorForSuggest {
}
}
- // initialize a debug flag for the personalization
- private void initForDebug(final SettingsValues settingsValues) {
- if (settingsValues.mUseOnlyPersonalizationDictionaryForDebug) {
- mDictionarySubsetForDebug = new HashSet<String>();
- mDictionarySubsetForDebug.add(Dictionary.TYPE_PERSONALIZATION);
- }
+ public boolean needsToBeRecreated(final Locale newLocale,
+ final SettingsValues newSettingsValues) {
+ return !mLocale.equals(newLocale)
+ || (newSettingsValues.mUseContactsDict != (mContactsDictionary != null))
+ || (newSettingsValues.mUsePersonalizedDicts != (mUserHistoryDictionary != null))
+ || (newSettingsValues.mUsePersonalizedDicts != hasPersonalizationDictionary());
}
public void close() {
@@ -531,10 +527,6 @@ public class DictionaryFacilitatorForSuggest {
}
private void addOrReplaceDictionary(final String key, final Dictionary dict) {
- if (mDictionarySubsetForDebug != null && !mDictionarySubsetForDebug.contains(key)) {
- Log.w(TAG, "Ignore add " + key + " dictionary for debug.");
- return;
- }
final Dictionary oldDict;
if (dict == null) {
oldDict = mDictionaries.remove(key);
diff --git a/java/src/com/android/inputmethod/latin/LatinIME.java b/java/src/com/android/inputmethod/latin/LatinIME.java
index bfc578082..4c2454c32 100644
--- a/java/src/com/android/inputmethod/latin/LatinIME.java
+++ b/java/src/com/android/inputmethod/latin/LatinIME.java
@@ -530,27 +530,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);
}
}
@@ -610,13 +614,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 +629,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 +637,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);
}
@@ -1733,7 +1737,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/RichInputMethodManager.java b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
index 6b6bbf3a7..630a03670 100644
--- a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
+++ b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
@@ -50,7 +50,7 @@ public final class RichInputMethodManager {
private static final RichInputMethodManager sInstance = new RichInputMethodManager();
private InputMethodManagerCompatWrapper mImmWrapper;
- private InputMethodInfo mInputMethodInfoOfThisIme;
+ private InputMethodInfoCache mInputMethodInfoCache;
final HashMap<InputMethodInfo, List<InputMethodSubtype>>
mSubtypeListCacheWithImplicitlySelectedSubtypes = CollectionUtils.newHashMap();
final HashMap<InputMethodInfo, List<InputMethodSubtype>>
@@ -83,7 +83,8 @@ public final class RichInputMethodManager {
return;
}
mImmWrapper = new InputMethodManagerCompatWrapper(context);
- mInputMethodInfoOfThisIme = getInputMethodInfoOfThisIme(context);
+ mInputMethodInfoCache = new InputMethodInfoCache(
+ mImmWrapper.mImm, context.getPackageName());
// Initialize additional subtypes.
SubtypeLocaleUtils.init(context);
@@ -99,20 +100,10 @@ public final class RichInputMethodManager {
return mImmWrapper.mImm;
}
- private InputMethodInfo getInputMethodInfoOfThisIme(final Context context) {
- final String packageName = context.getPackageName();
- for (final InputMethodInfo imi : mImmWrapper.mImm.getInputMethodList()) {
- if (imi.getPackageName().equals(packageName)) {
- return imi;
- }
- }
- throw new RuntimeException("Input method id for " + packageName + " not found.");
- }
-
public List<InputMethodSubtype> getMyEnabledInputMethodSubtypeList(
boolean allowsImplicitlySelectedSubtypes) {
- return getEnabledInputMethodSubtypeList(mInputMethodInfoOfThisIme,
- allowsImplicitlySelectedSubtypes);
+ return getEnabledInputMethodSubtypeList(
+ getInputMethodInfoOfThisIme(), allowsImplicitlySelectedSubtypes);
}
public boolean switchToNextInputMethod(final IBinder token, final boolean onlyCurrentIme) {
@@ -153,10 +144,10 @@ public final class RichInputMethodManager {
private boolean switchToNextInputMethodAndSubtype(final IBinder token) {
final InputMethodManager imm = mImmWrapper.mImm;
final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList();
- final int currentIndex = getImiIndexInList(mInputMethodInfoOfThisIme, enabledImis);
+ final int currentIndex = getImiIndexInList(getInputMethodInfoOfThisIme(), enabledImis);
if (currentIndex == INDEX_NOT_FOUND) {
Log.w(TAG, "Can't find current IME in enabled IMEs: IME package="
- + mInputMethodInfoOfThisIme.getPackageName());
+ + getInputMethodInfoOfThisIme().getPackageName());
return false;
}
final InputMethodInfo nextImi = getNextNonAuxiliaryIme(currentIndex, enabledImis);
@@ -213,16 +204,45 @@ public final class RichInputMethodManager {
return true;
}
+ private static class InputMethodInfoCache {
+ private final InputMethodManager mImm;
+ private final String mImePackageName;
+
+ private InputMethodInfo mCachedValue;
+
+ public InputMethodInfoCache(final InputMethodManager imm, final String imePackageName) {
+ mImm = imm;
+ mImePackageName = imePackageName;
+ }
+
+ public synchronized InputMethodInfo get() {
+ if (mCachedValue != null) {
+ return mCachedValue;
+ }
+ for (final InputMethodInfo imi : mImm.getInputMethodList()) {
+ if (imi.getPackageName().equals(mImePackageName)) {
+ mCachedValue = imi;
+ return imi;
+ }
+ }
+ throw new RuntimeException("Input method id for " + mImePackageName + " not found.");
+ }
+
+ public synchronized void clear() {
+ mCachedValue = null;
+ }
+ }
+
public InputMethodInfo getInputMethodInfoOfThisIme() {
- return mInputMethodInfoOfThisIme;
+ return mInputMethodInfoCache.get();
}
public String getInputMethodIdOfThisIme() {
- return mInputMethodInfoOfThisIme.getId();
+ return getInputMethodInfoOfThisIme().getId();
}
public boolean checkIfSubtypeBelongsToThisImeAndEnabled(final InputMethodSubtype subtype) {
- return checkIfSubtypeBelongsToImeAndEnabled(mInputMethodInfoOfThisIme, subtype);
+ return checkIfSubtypeBelongsToImeAndEnabled(getInputMethodInfoOfThisIme(), subtype);
}
public boolean checkIfSubtypeBelongsToThisImeAndImplicitlyEnabled(
@@ -258,7 +278,7 @@ public final class RichInputMethodManager {
}
public boolean checkIfSubtypeBelongsToThisIme(final InputMethodSubtype subtype) {
- return getSubtypeIndexInIme(subtype, mInputMethodInfoOfThisIme) != INDEX_NOT_FOUND;
+ return getSubtypeIndexInIme(subtype, getInputMethodInfoOfThisIme()) != INDEX_NOT_FOUND;
}
private static int getSubtypeIndexInIme(final InputMethodSubtype subtype,
@@ -286,7 +306,8 @@ public final class RichInputMethodManager {
public boolean hasMultipleEnabledSubtypesInThisIme(
final boolean shouldIncludeAuxiliarySubtypes) {
- final List<InputMethodInfo> imiList = Collections.singletonList(mInputMethodInfoOfThisIme);
+ final List<InputMethodInfo> imiList = Collections.singletonList(
+ getInputMethodInfoOfThisIme());
return hasMultipleEnabledSubtypes(shouldIncludeAuxiliarySubtypes, imiList);
}
@@ -340,7 +361,7 @@ public final class RichInputMethodManager {
public InputMethodSubtype findSubtypeByLocaleAndKeyboardLayoutSet(final String localeString,
final String keyboardLayoutSetName) {
- final InputMethodInfo myImi = mInputMethodInfoOfThisIme;
+ final InputMethodInfo myImi = getInputMethodInfoOfThisIme();
final int count = myImi.getSubtypeCount();
for (int i = 0; i < count; i++) {
final InputMethodSubtype subtype = myImi.getSubtypeAt(i);
@@ -355,13 +376,14 @@ public final class RichInputMethodManager {
public void setInputMethodAndSubtype(final IBinder token, final InputMethodSubtype subtype) {
mImmWrapper.mImm.setInputMethodAndSubtype(
- token, mInputMethodInfoOfThisIme.getId(), subtype);
+ token, getInputMethodIdOfThisIme(), subtype);
}
public void setAdditionalInputMethodSubtypes(final InputMethodSubtype[] subtypes) {
mImmWrapper.mImm.setAdditionalInputMethodSubtypes(
- mInputMethodInfoOfThisIme.getId(), subtypes);
- // Clear the cache so that we go read the subtypes again next time.
+ getInputMethodIdOfThisIme(), subtypes);
+ // Clear the cache so that we go read the {@link InputMethodInfo} of this IME and list of
+ // subtypes again next time.
clearSubtypeCaches();
}
@@ -382,5 +404,6 @@ public final class RichInputMethodManager {
public void clearSubtypeCaches() {
mSubtypeListCacheWithImplicitlySelectedSubtypes.clear();
mSubtypeListCacheWithoutImplicitlySelectedSubtypes.clear();
+ mInputMethodInfoCache.clear();
}
}
diff --git a/java/src/com/android/inputmethod/latin/Suggest.java b/java/src/com/android/inputmethod/latin/Suggest.java
index f0e7d2f61..1747eeeda 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;
diff --git a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
index c87dd1589..11d369282 100644
--- a/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
+++ b/java/src/com/android/inputmethod/latin/settings/DebugSettings.java
@@ -42,8 +42,6 @@ public final class DebugSettings extends PreferenceFragment
public static final String PREF_FORCE_NON_DISTINCT_MULTITOUCH = "force_non_distinct_multitouch";
public static final String PREF_USABILITY_STUDY_MODE = "usability_study_mode";
public static final String PREF_STATISTICS_LOGGING = "enable_logging";
- public static final String PREF_USE_ONLY_PERSONALIZATION_DICTIONARY_FOR_DEBUG =
- "use_only_personalization_dictionary_for_debug";
public static final String PREF_KEY_PREVIEW_SHOW_UP_START_SCALE =
"pref_key_preview_show_up_start_scale";
public static final String PREF_KEY_PREVIEW_DISMISS_END_SCALE =
diff --git a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
index 77968f79a..50fbbb19f 100644
--- a/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
+++ b/java/src/com/android/inputmethod/latin/settings/SettingsValues.java
@@ -84,7 +84,6 @@ public final class SettingsValues {
public final float mAutoCorrectionThreshold;
public final boolean mCorrectionEnabled;
public final int mSuggestionVisibility;
- public final boolean mUseOnlyPersonalizationDictionaryForDebug;
public final int mDisplayOrientation;
private final AsyncResultHolder<AppWorkaroundsUtils> mAppWorkarounds;
@@ -168,8 +167,6 @@ public final class SettingsValues {
prefs, DebugSettings.PREF_KEY_PREVIEW_DISMISS_END_SCALE,
ResourceUtils.getFloatFromFraction(
res, R.fraction.config_key_preview_dismiss_end_scale));
- mUseOnlyPersonalizationDictionaryForDebug = prefs.getBoolean(
- DebugSettings.PREF_USE_ONLY_PERSONALIZATION_DICTIONARY_FOR_DEBUG, false);
mDisplayOrientation = res.getConfiguration().orientation;
mAppWorkarounds = new AsyncResultHolder<AppWorkaroundsUtils>();
final PackageInfo packageInfo = TargetPackageInfoGetterTask.getCachedPackageInfo(
@@ -390,8 +387,6 @@ public final class SettingsValues {
sb.append("" + mCorrectionEnabled);
sb.append("\n mSuggestionVisibility = ");
sb.append("" + mSuggestionVisibility);
- sb.append("\n mUseOnlyPersonalizationDictionaryForDebug = ");
- sb.append("" + mUseOnlyPersonalizationDictionaryForDebug);
sb.append("\n mDisplayOrientation = ");
sb.append("" + mDisplayOrientation);
sb.append("\n mAppWorkarounds = ");
diff --git a/java/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtils.java b/java/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtils.java
index ef1d0f42c..2bb30a2ba 100644
--- a/java/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtils.java
+++ b/java/src/com/android/inputmethod/latin/utils/AdditionalSubtypeUtils.java
@@ -27,6 +27,7 @@ import android.text.TextUtils;
import android.util.Log;
import android.view.inputmethod.InputMethodSubtype;
+import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.compat.InputMethodSubtypeCompatUtils;
import com.android.inputmethod.latin.R;
@@ -42,6 +43,7 @@ public final class AdditionalSubtypeUtils {
// This utility class is not publicly instantiable.
}
+ @UsedForTesting
public static boolean isAdditionalSubtype(final InputMethodSubtype subtype) {
return subtype.containsExtraValueKey(IS_ADDITIONAL_SUBTYPE);
}