diff --git a/mobile/android/base/preferences/GeckoPreferenceFragment.java b/mobile/android/base/preferences/GeckoPreferenceFragment.java index 4551c23eb36f..a1d031d93429 100644 --- a/mobile/android/base/preferences/GeckoPreferenceFragment.java +++ b/mobile/android/base/preferences/GeckoPreferenceFragment.java @@ -82,8 +82,7 @@ public class GeckoPreferenceFragment extends PreferenceFragment { } /** - * Return the title to use for this preference fragment. This allows - * for us to redisplay this fragment in a different locale. + * Return the title to use for this preference fragment. * * We only return titles for the preference screens that are * launched directly, and thus might need to be redisplayed. @@ -96,13 +95,12 @@ public class GeckoPreferenceFragment extends PreferenceFragment { return getString(R.string.settings_title); } - // We need this because we can launch straight into this category - // from the Data Reporting notification. + // We can launch this category from the Data Reporting notification. if (res == R.xml.preferences_privacy) { return getString(R.string.pref_category_privacy_short); } - // from the Awesomescreen with the magnifying glass. + // We can launch this category from the the magnifying glass in the quick search bar. if (res == R.xml.preferences_search) { return getString(R.string.pref_category_search); } @@ -110,6 +108,33 @@ public class GeckoPreferenceFragment extends PreferenceFragment { return null; } + /** + * Return the header id for this preference fragment. This allows + * us to select the correct header when launching a preference + * screen directly. + * + * We only return titles for the preference screens that are + * launched directly. + */ + private int getHeader() { + final int res = getResource(); + if (res == R.xml.preferences) { + return R.id.pref_header_general; + } + + // We can launch this category from the Data Reporting notification. + if (res == R.xml.preferences_privacy) { + return R.id.pref_header_privacy; + } + + // We can launch this category from the the magnifying glass in the quick search bar. + if (res == R.xml.preferences_search) { + return R.id.pref_header_search; + } + + return -1; + } + private void updateTitle() { final String newTitle = getTitle(); if (newTitle == null) { @@ -122,6 +147,7 @@ public class GeckoPreferenceFragment extends PreferenceFragment { // In a multi-pane activity, the title is "Settings", and the action // bar is along the top of the screen. We don't want to change those. activity.showBreadCrumbs(newTitle, newTitle); + ((GeckoPreferences) activity).switchToHeader(getHeader()); return; } diff --git a/mobile/android/base/preferences/GeckoPreferences.java b/mobile/android/base/preferences/GeckoPreferences.java index c88a41c6789f..52cd7fcabf89 100644 --- a/mobile/android/base/preferences/GeckoPreferences.java +++ b/mobile/android/base/preferences/GeckoPreferences.java @@ -5,6 +5,7 @@ package org.mozilla.gecko.preferences; +import android.annotation.TargetApi; import org.mozilla.gecko.AboutPages; import org.mozilla.gecko.AppConstants; import org.mozilla.gecko.AppConstants.Versions; @@ -108,7 +109,7 @@ OnSharedPreferenceChangeListener private static boolean sIsCharEncodingEnabled; private boolean mInitialized; private int mPrefsRequestId; - private PanelsPreferenceCategory mPanelsPreferenceCategory; + private List
mHeaders; // These match keys in resources/xml*/preferences*.xml private static final String PREFS_SEARCH_RESTORE_DEFAULTS = NON_PREF_PREFIX + "search.restore_defaults"; @@ -499,6 +500,23 @@ OnSharedPreferenceChangeListener iterator.remove(); } } + + mHeaders = target; + } + } + + @TargetApi(11) + public void switchToHeader(int id) { + if (mHeaders == null) { + // Can't switch to a header if there are no headers! + return; + } + + for (Header header : mHeaders) { + if (header.id == id) { + switchToHeader(header); + return; + } } } @@ -692,8 +710,6 @@ OnSharedPreferenceChangeListener i--; continue; } - } else if (pref instanceof PanelsPreferenceCategory) { - mPanelsPreferenceCategory = (PanelsPreferenceCategory) pref; } if (PREFS_ADVANCED.equals(key) && !RestrictedProfiles.isAllowed(this, Restriction.DISALLOW_DEVELOPER_TOOLS)) { diff --git a/mobile/android/base/resources/xml-v11/preference_headers.xml b/mobile/android/base/resources/xml-v11/preference_headers.xml index 59def7566b3a..2148f18a3bb5 100644 --- a/mobile/android/base/resources/xml-v11/preference_headers.xml +++ b/mobile/android/base/resources/xml-v11/preference_headers.xml @@ -10,7 +10,8 @@
+ android:title="@string/pref_header_general" + android:id="@+id/pref_header_general">
@@ -23,7 +24,8 @@
+ android:title="@string/pref_header_privacy_short" + android:id="@+id/pref_header_privacy">