aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorTadashi G. Takaoka <takaoka@google.com>2014-11-07 12:48:59 -0800
committerTadashi G. Takaoka <takaoka@google.com>2014-12-12 13:53:13 +0900
commitafd52dfc601c635e8a729b30b4ccf7a7fd7ad134 (patch)
tree3d316b53d707f72f849429fe7adeb9407e027455 /java
parent8cfad7ed64d08c5a131c9c539aa4fc964030c214 (diff)
downloadlatinime-afd52dfc601c635e8a729b30b4ccf7a7fd7ad134.tar.gz
latinime-afd52dfc601c635e8a729b30b4ccf7a7fd7ad134.tar.xz
latinime-afd52dfc601c635e8a729b30b4ccf7a7fd7ad134.zip
Cleanup InputMethodInfoCache
Change-Id: I40afeb4557c3b1ad32bd90f67502a625df2bc3fb
Diffstat (limited to 'java')
-rw-r--r--java/src/com/android/inputmethod/latin/RichInputMethodManager.java54
1 files changed, 32 insertions, 22 deletions
diff --git a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
index cb1de6b17..d8b018989 100644
--- a/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
+++ b/java/src/com/android/inputmethod/latin/RichInputMethodManager.java
@@ -69,10 +69,6 @@ public class RichInputMethodManager {
private RichInputMethodSubtype mCurrentRichInputMethodSubtype;
private InputMethodInfo mShortcutInputMethodInfo;
private InputMethodSubtype mShortcutSubtype;
- final HashMap<InputMethodInfo, List<InputMethodSubtype>>
- mSubtypeListCacheWithImplicitlySelectedSubtypes = new HashMap<>();
- final HashMap<InputMethodInfo, List<InputMethodSubtype>>
- mSubtypeListCacheWithoutImplicitlySelectedSubtypes = new HashMap<>();
private static final int INDEX_NOT_FOUND = -1;
@@ -234,33 +230,57 @@ public class RichInputMethodManager {
private final InputMethodManager mImm;
private final String mImePackageName;
- private InputMethodInfo mCachedValue;
+ private InputMethodInfo mCachedThisImeInfo;
+ private final HashMap<InputMethodInfo, List<InputMethodSubtype>>
+ mCachedSubtypeListWithImplicitlySelected;
+ private final HashMap<InputMethodInfo, List<InputMethodSubtype>>
+ mCachedSubtypeListOnlyExplicitlySelected;
public InputMethodInfoCache(final InputMethodManager imm, final String imePackageName) {
mImm = imm;
mImePackageName = imePackageName;
+ mCachedSubtypeListWithImplicitlySelected = new HashMap<>();
+ mCachedSubtypeListOnlyExplicitlySelected = new HashMap<>();
}
- public synchronized InputMethodInfo get() {
- if (mCachedValue != null) {
- return mCachedValue;
+ public synchronized InputMethodInfo getInputMethodOfThisIme() {
+ if (mCachedThisImeInfo != null) {
+ return mCachedThisImeInfo;
}
for (final InputMethodInfo imi : mImm.getInputMethodList()) {
if (imi.getPackageName().equals(mImePackageName)) {
- mCachedValue = imi;
+ mCachedThisImeInfo = imi;
return imi;
}
}
throw new RuntimeException("Input method id for " + mImePackageName + " not found.");
}
+ public synchronized List<InputMethodSubtype> getEnabledInputMethodSubtypeList(
+ final InputMethodInfo imi, final boolean allowsImplicitlySelectedSubtypes) {
+ final HashMap<InputMethodInfo, List<InputMethodSubtype>> cache =
+ allowsImplicitlySelectedSubtypes
+ ? mCachedSubtypeListWithImplicitlySelected
+ : mCachedSubtypeListOnlyExplicitlySelected;
+ final List<InputMethodSubtype> cachedList = cache.get(imi);
+ if (cachedList != null) {
+ return cachedList;
+ }
+ final List<InputMethodSubtype> result = mImm.getEnabledInputMethodSubtypeList(
+ imi, allowsImplicitlySelectedSubtypes);
+ cache.put(imi, result);
+ return result;
+ }
+
public synchronized void clear() {
- mCachedValue = null;
+ mCachedThisImeInfo = null;
+ mCachedSubtypeListWithImplicitlySelected.clear();
+ mCachedSubtypeListOnlyExplicitlySelected.clear();
}
}
public InputMethodInfo getInputMethodInfoOfThisIme() {
- return mInputMethodInfoCache.get();
+ return mInputMethodInfoCache.getInputMethodOfThisIme();
}
public String getInputMethodIdOfThisIme() {
@@ -445,21 +465,11 @@ public class RichInputMethodManager {
private List<InputMethodSubtype> getEnabledInputMethodSubtypeList(final InputMethodInfo imi,
final boolean allowsImplicitlySelectedSubtypes) {
- final HashMap<InputMethodInfo, List<InputMethodSubtype>> cache =
- allowsImplicitlySelectedSubtypes
- ? mSubtypeListCacheWithImplicitlySelectedSubtypes
- : mSubtypeListCacheWithoutImplicitlySelectedSubtypes;
- final List<InputMethodSubtype> cachedList = cache.get(imi);
- if (null != cachedList) return cachedList;
- final List<InputMethodSubtype> result = mImmWrapper.mImm.getEnabledInputMethodSubtypeList(
+ return mInputMethodInfoCache.getEnabledInputMethodSubtypeList(
imi, allowsImplicitlySelectedSubtypes);
- cache.put(imi, result);
- return result;
}
public void refreshSubtypeCaches() {
- mSubtypeListCacheWithImplicitlySelectedSubtypes.clear();
- mSubtypeListCacheWithoutImplicitlySelectedSubtypes.clear();
mInputMethodInfoCache.clear();
updateCurrentSubtype(mImmWrapper.mImm.getCurrentInputMethodSubtype());
updateShortcutIme();