aboutsummaryrefslogtreecommitdiffstats
path: root/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2013-05-09 19:20:27 +0900
committerJean Chalard <jchalard@google.com>2013-05-10 14:41:36 +0900
commita2ec5e8338c82f1e49c3d98f502dcc30c9c12fb0 (patch)
tree09ab7753ca1b3e85276f47b27190c84037850756 /java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
parentb0aabbfbe0144272df816160e7b0b569bbba55cd (diff)
downloadlatinime-a2ec5e8338c82f1e49c3d98f502dcc30c9c12fb0.tar.gz
latinime-a2ec5e8338c82f1e49c3d98f502dcc30c9c12fb0.tar.xz
latinime-a2ec5e8338c82f1e49c3d98f502dcc30c9c12fb0.zip
Reuse old preferences if possible.
This is an optimization. It also happens to work around what seems to be a framework bug in JB MR1 / MR1.1. Bug: 8771179 Change-Id: I62cc7acdc8656d75f8a50c068c4e9d8c6ceb74a0
Diffstat (limited to 'java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java')
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java31
1 files changed, 24 insertions, 7 deletions
diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java b/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
index fb75d6dc0..618322357 100644
--- a/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
+++ b/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
@@ -66,6 +66,8 @@ public final class DictionarySettingsFragment extends PreferenceFragment
private boolean mChangedSettings;
private DictionaryListInterfaceState mDictionaryListInterfaceState =
new DictionaryListInterfaceState();
+ private TreeMap<String, WordListPreference> mCurrentPreferenceMap =
+ new TreeMap<String, WordListPreference>(); // never null
private final BroadcastReceiver mConnectivityChangedReceiver = new BroadcastReceiver() {
@Override
@@ -278,7 +280,7 @@ public final class DictionarySettingsFragment extends PreferenceFragment
return result;
} else {
final String systemLocaleString = Locale.getDefault().toString();
- final TreeMap<String, WordListPreference> prefList =
+ final TreeMap<String, WordListPreference> prefMap =
new TreeMap<String, WordListPreference>();
final int idIndex = cursor.getColumnIndex(MetadataDbHelper.WORDLISTID_COLUMN);
final int versionIndex = cursor.getColumnIndex(MetadataDbHelper.VERSION_COLUMN);
@@ -299,16 +301,31 @@ public final class DictionarySettingsFragment extends PreferenceFragment
// The key is sorted in lexicographic order, according to the match level, then
// the description.
final String key = matchLevelString + "." + description + "." + wordlistId;
- final WordListPreference existingPref = prefList.get(key);
+ final WordListPreference existingPref = prefMap.get(key);
if (null == existingPref || hasPriority(status, existingPref.mStatus)) {
- final WordListPreference pref = new WordListPreference(activity,
- mDictionaryListInterfaceState, mClientId, wordlistId, version, locale,
- description, status, filesize);
- prefList.put(key, pref);
+ final WordListPreference oldPreference = mCurrentPreferenceMap.get(key);
+ final WordListPreference pref;
+ if (null != oldPreference
+ && oldPreference.mVersion == version
+ && oldPreference.mLocale.equals(locale)) {
+ // If the old preference has all the new attributes, reuse it. We test
+ // for version and locale because although attributes other than status
+ // need to be the same, others have been tested through the key of the
+ // map. Also, status may differ so we don't want to use #equals() here.
+ pref = oldPreference;
+ pref.mStatus = status;
+ } else {
+ // Otherwise, discard it and create a new one instead.
+ pref = new WordListPreference(activity, mDictionaryListInterfaceState,
+ mClientId, wordlistId, version, locale, description, status,
+ filesize);
+ }
+ prefMap.put(key, pref);
}
} while (cursor.moveToNext());
cursor.close();
- return prefList.values();
+ mCurrentPreferenceMap = prefMap;
+ return prefMap.values();
}
}