Bug 962047 - Default search engines are not displayed after turning on search suggestions. r=margaret

This commit is contained in:
Chenxia Liu 2014-01-23 15:35:28 -08:00
Родитель 9fe218dee9
Коммит 2b3a75ff8e
2 изменённых файлов: 14 добавлений и 4 удалений

Просмотреть файл

@ -80,8 +80,12 @@ public abstract class CustomListPreference extends Preference implements View.On
protected abstract int getPreferenceLayoutResource(); protected abstract int getPreferenceLayoutResource();
/** /**
* Set whether this object's UI should display this as the default item. To ensure proper ordering, * Set whether this object's UI should display this as the default item.
* this method should only be called after this Preference is added to the PreferenceCategory. * 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. * @param isDefault Flag indicating if this represents the default list item.
*/ */
public void setIsDefault(boolean isDefault) { public void setIsDefault(boolean isDefault) {

Просмотреть файл

@ -16,6 +16,7 @@ import org.json.JSONObject;
import org.mozilla.gecko.GeckoAppShell; import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent; import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.util.GeckoEventListener; import org.mozilla.gecko.util.GeckoEventListener;
import org.mozilla.gecko.util.ThreadUtils;
public class SearchPreferenceCategory extends CustomListCategory implements GeckoEventListener { public class SearchPreferenceCategory extends CustomListCategory implements GeckoEventListener {
public static final String LOGTAG = "SearchPrefCategory"; public static final String LOGTAG = "SearchPrefCategory";
@ -81,7 +82,7 @@ public class SearchPreferenceCategory extends CustomListCategory implements Geck
JSONObject engineJSON = engines.getJSONObject(i); JSONObject engineJSON = engines.getJSONObject(i);
final String engineName = engineJSON.getString("name"); final String engineName = engineJSON.getString("name");
SearchEnginePreference enginePreference = new SearchEnginePreference(getContext(), this); final SearchEnginePreference enginePreference = new SearchEnginePreference(getContext(), this);
enginePreference.setSearchEngineFromJSON(engineJSON); enginePreference.setSearchEngineFromJSON(engineJSON);
enginePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() { enginePreference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override @Override
@ -100,7 +101,12 @@ public class SearchPreferenceCategory extends CustomListCategory implements Geck
// We set this here, not in setSearchEngineFromJSON, because it allows us to // We set this here, not in setSearchEngineFromJSON, because it allows us to
// keep a reference to the default engine to use when the AlertDialog // keep a reference to the default engine to use when the AlertDialog
// callbacks are used. // callbacks are used.
ThreadUtils.postToUiThread(new Runnable() {
@Override
public void run() {
enginePreference.setIsDefault(true); enginePreference.setIsDefault(true);
}
});
mDefaultReference = enginePreference; mDefaultReference = enginePreference;
} }
} catch (JSONException e) { } catch (JSONException e) {