From 2b3a75ff8eabb26b719414844c6de4ac2551a1c2 Mon Sep 17 00:00:00 2001 From: Chenxia Liu Date: Thu, 23 Jan 2014 15:35:28 -0800 Subject: [PATCH] Bug 962047 - Default search engines are not displayed after turning on search suggestions. r=margaret --- .../android/base/preferences/CustomListPreference.java | 8 ++++++-- .../base/preferences/SearchPreferenceCategory.java | 10 ++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/mobile/android/base/preferences/CustomListPreference.java b/mobile/android/base/preferences/CustomListPreference.java index 502e134c7057..cafb392ffceb 100644 --- a/mobile/android/base/preferences/CustomListPreference.java +++ b/mobile/android/base/preferences/CustomListPreference.java @@ -80,8 +80,12 @@ public abstract class CustomListPreference extends Preference implements View.On protected abstract int getPreferenceLayoutResource(); /** - * Set whether this object's UI should display this as the default item. To ensure proper ordering, - * this method should only be called after this Preference is added to the PreferenceCategory. + * Set whether this object's UI should display this as the default item. + * Note: This must be called from the UI thread because it touches the view hierarchy. + * + * To ensure proper ordering, this method should only be called after this Preference + * is added to the PreferenceCategory. + * * @param isDefault Flag indicating if this represents the default list item. */ public void setIsDefault(boolean isDefault) { diff --git a/mobile/android/base/preferences/SearchPreferenceCategory.java b/mobile/android/base/preferences/SearchPreferenceCategory.java index 121f1283a626..0c2fcb6ccc79 100644 --- a/mobile/android/base/preferences/SearchPreferenceCategory.java +++ b/mobile/android/base/preferences/SearchPreferenceCategory.java @@ -16,6 +16,7 @@ import org.json.JSONObject; import org.mozilla.gecko.GeckoAppShell; import org.mozilla.gecko.GeckoEvent; import org.mozilla.gecko.util.GeckoEventListener; +import org.mozilla.gecko.util.ThreadUtils; public class SearchPreferenceCategory extends CustomListCategory implements GeckoEventListener { public static final String LOGTAG = "SearchPrefCategory"; @@ -81,7 +82,7 @@ public class SearchPreferenceCategory extends CustomListCategory implements Geck JSONObject engineJSON = engines.getJSONObject(i); final String engineName = engineJSON.getString("name"); - SearchEnginePreference enginePreference = new SearchEnginePreference(getContext(), this); + final SearchEnginePreference enginePreference = new SearchEnginePreference(getContext(), this); enginePreference.setSearchEngineFromJSON(engineJSON); enginePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override @@ -100,7 +101,12 @@ public class SearchPreferenceCategory extends CustomListCategory implements Geck // We set this here, not in setSearchEngineFromJSON, because it allows us to // keep a reference to the default engine to use when the AlertDialog // callbacks are used. - enginePreference.setIsDefault(true); + ThreadUtils.postToUiThread(new Runnable() { + @Override + public void run() { + enginePreference.setIsDefault(true); + } + }); mDefaultReference = enginePreference; } } catch (JSONException e) {