aboutsummaryrefslogtreecommitdiffstats
path: root/java
diff options
context:
space:
mode:
authorJean Chalard <jchalard@google.com>2014-02-14 01:38:52 -0800
committerAndroid Git Automerger <android-git-automerger@android.com>2014-02-14 01:38:52 -0800
commit82b92b21470931691417b428bdb2d5db2eae8ae0 (patch)
tree3e8792bc6ba3e79f745638fa3d9e345062e0225a /java
parent0a206ef1e52dcf33ca0ecefa0def641fcaa1530f (diff)
parentfdc417321345037fdcf31de95fbaf7cc195856b3 (diff)
downloadlatinime-82b92b21470931691417b428bdb2d5db2eae8ae0.tar.gz
latinime-82b92b21470931691417b428bdb2d5db2eae8ae0.tar.xz
latinime-82b92b21470931691417b428bdb2d5db2eae8ae0.zip
am fdc41732: Merge "Fix a view-related crash"
* commit 'fdc417321345037fdcf31de95fbaf7cc195856b3': Fix a view-related crash
Diffstat (limited to 'java')
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java14
-rw-r--r--java/src/com/android/inputmethod/dictionarypack/WordListPreference.java5
2 files changed, 14 insertions, 5 deletions
diff --git a/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java b/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
index 7bbd041e7..d18639741 100644
--- a/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
+++ b/java/src/com/android/inputmethod/dictionarypack/DictionarySettingsFragment.java
@@ -317,15 +317,19 @@ public final class DictionarySettingsFragment extends PreferenceFragment
final WordListPreference pref;
if (null != oldPreference
&& oldPreference.mVersion == version
+ && oldPreference.hasStatus(status)
&& 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.
+ // If the old preference has all the new attributes, reuse it. Ideally, we
+ // should reuse the old pref even if its status is different and call
+ // setStatus here, but setStatus calls Preference#setSummary() which needs
+ // to be done on the UI thread and we're not on the UI thread here. We
+ // could do all this work on the UI thread, but in this case it's probably
+ // lighter to stay on a background thread and throw this old preference out.
pref = oldPreference;
- pref.setStatus(status);
} else {
// Otherwise, discard it and create a new one instead.
+ // TODO: when the status is different from the old one, we need to
+ // animate the old one out before animating the new one in.
pref = new WordListPreference(activity, mDictionaryListInterfaceState,
mClientId, wordlistId, version, locale, description, status,
filesize);
diff --git a/java/src/com/android/inputmethod/dictionarypack/WordListPreference.java b/java/src/com/android/inputmethod/dictionarypack/WordListPreference.java
index ba1fce1a8..aea16af0d 100644
--- a/java/src/com/android/inputmethod/dictionarypack/WordListPreference.java
+++ b/java/src/com/android/inputmethod/dictionarypack/WordListPreference.java
@@ -98,6 +98,10 @@ public final class WordListPreference extends Preference {
setSummary(getSummary(status));
}
+ public boolean hasStatus(final int status) {
+ return status == mStatus;
+ }
+
@Override
public View onCreateView(final ViewGroup parent) {
final View orphanedView = mInterfaceState.findFirstOrphanedView();
@@ -217,6 +221,7 @@ public final class WordListPreference extends Preference {
progressBar.setIds(mClientId, mWordlistId);
progressBar.setMax(mFilesize);
final boolean showProgressBar = (MetadataDbHelper.STATUS_DOWNLOADING == mStatus);
+ setSummary(getSummary(mStatus));
status.setVisibility(showProgressBar ? View.INVISIBLE : View.VISIBLE);
progressBar.setVisibility(showProgressBar ? View.VISIBLE : View.INVISIBLE);