зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1220833 - (Part 2) Properly select header on tablet when launching preference screen directly. r=sebastian
--HG-- extra : commitid : FOmtMqsG5VX extra : rebase_source : 3b0abf0cece511d13fa3a7f3778b9cc892b7f73f extra : histedit_source : 1be3cdf9a6bc5fbc058353ecb5e1b9615eda33cf
This commit is contained in:
Родитель
687444e529
Коммит
c7aa6f11f0
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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<Header> 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)) {
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<header android:fragment="org.mozilla.gecko.preferences.GeckoPreferenceFragment"
|
||||
android:title="@string/pref_header_general">
|
||||
android:title="@string/pref_header_general"
|
||||
android:id="@+id/pref_header_general">
|
||||
<extra android:name="resource"
|
||||
android:value="preferences_general_tablet"/>
|
||||
</header>
|
||||
|
@ -23,7 +24,8 @@
|
|||
</header>
|
||||
|
||||
<header android:fragment="org.mozilla.gecko.preferences.GeckoPreferenceFragment"
|
||||
android:title="@string/pref_header_privacy_short">
|
||||
android:title="@string/pref_header_privacy_short"
|
||||
android:id="@+id/pref_header_privacy">
|
||||
<extra android:name="resource"
|
||||
android:value="preferences_privacy"/>
|
||||
</header>
|
||||
|
|
Загрузка…
Ссылка в новой задаче