diff --git a/core/java/android/preference/PreferenceActivity.java b/core/java/android/preference/PreferenceActivity.java index 06666f459e5df..5e7f68b794bf0 100644 --- a/core/java/android/preference/PreferenceActivity.java +++ b/core/java/android/preference/PreferenceActivity.java @@ -16,6 +16,7 @@ package android.preference; +import android.animation.LayoutTransition; import android.annotation.Nullable; import android.annotation.StringRes; import android.annotation.XmlRes; @@ -87,7 +88,7 @@ import java.util.List; * items. Doing this implicitly switches the class into its new "headers * + fragments" mode rather than the old style of just showing a single * preferences list. - * + * *
For information about using {@code PreferenceActivity},
@@ -199,6 +200,9 @@ public abstract class PreferenceActivity extends ListActivity implements
private ViewGroup mPrefsContainer;
+ // Null if in legacy mode.
+ private ViewGroup mHeadersContainer;
+
private FragmentBreadCrumbs mFragmentBreadCrumbs;
private boolean mSinglePane;
@@ -292,7 +296,7 @@ public abstract class PreferenceActivity extends ListActivity implements
holder = (HeaderViewHolder) view.getTag();
}
- // All view fields must be updated every time, because the view may be recycled
+ // All view fields must be updated every time, because the view may be recycled
Header header = getItem(position);
if (mRemoveIconIfEmpty) {
if (header.iconRes == 0) {
@@ -469,7 +473,7 @@ public abstract class PreferenceActivity extends ListActivity implements
}
return breadCrumbShortTitle;
}
-
+
@Override
public int describeContents() {
return 0;
@@ -558,6 +562,7 @@ public abstract class PreferenceActivity extends ListActivity implements
mListFooter = (FrameLayout)findViewById(com.android.internal.R.id.list_footer);
mPrefsContainer = (ViewGroup) findViewById(com.android.internal.R.id.prefs_frame);
+ mHeadersContainer = (ViewGroup) findViewById(com.android.internal.R.id.headers);
boolean hidingHeaders = onIsHidingHeaders();
mSinglePane = hidingHeaders || !onIsMultiPane();
String initialFragment = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
@@ -575,66 +580,39 @@ public abstract class PreferenceActivity extends ListActivity implements
(int) HEADER_ID_UNDEFINED);
if (curHeader >= 0 && curHeader < mHeaders.size()) {
setSelectedHeader(mHeaders.get(curHeader));
+ } else if (!mSinglePane && initialFragment == null) {
+ switchToHeader(onGetInitialHeader());
}
+ } else {
+ // This will for instance hide breadcrumbs for single pane.
+ showBreadCrumbs(getTitle(), null);
+ }
+ } else {
+ if (!onIsHidingHeaders()) {
+ onBuildHeaders(mHeaders);
}
- } else {
- if (initialFragment != null && mSinglePane) {
- // If we are just showing a fragment, we want to run in
- // new fragment mode, but don't need to compute and show
- // the headers.
+ if (initialFragment != null) {
switchToHeader(initialFragment, initialArguments);
- if (initialTitle != 0) {
- CharSequence initialTitleStr = getText(initialTitle);
- CharSequence initialShortTitleStr = initialShortTitle != 0
- ? getText(initialShortTitle) : null;
- showBreadCrumbs(initialTitleStr, initialShortTitleStr);
- }
-
- } else {
- // We need to try to build the headers.
- onBuildHeaders(mHeaders);
-
- // If there are headers, then at this point we need to show
- // them and, depending on the screen, we may also show in-line
- // the currently selected preference fragment.
- if (mHeaders.size() > 0) {
- if (!mSinglePane) {
- if (initialFragment == null) {
- Header h = onGetInitialHeader();
- switchToHeader(h);
- } else {
- switchToHeader(initialFragment, initialArguments);
- }
- }
- }
+ } else if (!mSinglePane && mHeaders.size() > 0) {
+ switchToHeader(onGetInitialHeader());
}
}
- // The default configuration is to only show the list view. Adjust
- // visibility for other configurations.
- if (initialFragment != null && mSinglePane) {
- // Single pane, showing just a prefs fragment.
- findViewById(com.android.internal.R.id.headers).setVisibility(View.GONE);
- mPrefsContainer.setVisibility(View.VISIBLE);
- if (initialTitle != 0) {
- CharSequence initialTitleStr = getText(initialTitle);
- CharSequence initialShortTitleStr = initialShortTitle != 0
- ? getText(initialShortTitle) : null;
- showBreadCrumbs(initialTitleStr, initialShortTitleStr);
- }
- } else if (mHeaders.size() > 0) {
+ if (mHeaders.size() > 0) {
setListAdapter(new HeaderAdapter(this, mHeaders, mPreferenceHeaderItemResId,
mPreferenceHeaderRemoveEmptyIcon));
- if (!mSinglePane) {
- // Multi-pane.
- getListView().setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
- if (mCurHeader != null) {
- setSelectedHeader(mCurHeader);
- }
- mPrefsContainer.setVisibility(View.VISIBLE);
- }
- } else {
+ getListView().setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
+ }
+
+ if (mSinglePane && initialFragment != null && initialTitle != 0) {
+ CharSequence initialTitleStr = getText(initialTitle);
+ CharSequence initialShortTitleStr = initialShortTitle != 0
+ ? getText(initialShortTitle) : null;
+ showBreadCrumbs(initialTitleStr, initialShortTitleStr);
+ }
+
+ if (mHeaders.size() == 0 && initialFragment == null) {
// If there are no headers, we are in the old "just show a screen
// of preferences" mode.
setContentView(com.android.internal.R.layout.preference_list_content_single);
@@ -642,6 +620,25 @@ public abstract class PreferenceActivity extends ListActivity implements
mPrefsContainer = (ViewGroup) findViewById(com.android.internal.R.id.prefs);
mPreferenceManager = new PreferenceManager(this, FIRST_REQUEST_CODE);
mPreferenceManager.setOnPreferenceTreeClickListener(this);
+ mHeadersContainer = null;
+ } else if (mSinglePane) {
+ // Single-pane so one of the header or prefs containers must be hidden.
+ if (initialFragment != null || mCurHeader != null) {
+ mHeadersContainer.setVisibility(View.GONE);
+ } else {
+ mPrefsContainer.setVisibility(View.GONE);
+ }
+
+ // This animates our manual transitions between headers and prefs panel in single-pane.
+ // It also comes last so we don't animate any initial layout changes done above.
+ ViewGroup container = (ViewGroup) findViewById(
+ com.android.internal.R.id.prefs_container);
+ container.setLayoutTransition(new LayoutTransition());
+ } else {
+ // Multi-pane
+ if (mHeaders.size() > 0 && mCurHeader != null) {
+ setSelectedHeader(mCurHeader);
+ }
}
// see if we should show Back/Next buttons
@@ -697,12 +694,25 @@ public abstract class PreferenceActivity extends ListActivity implements
}
}
+ @Override
+ public void onBackPressed() {
+ if (mCurHeader != null && mSinglePane && getFragmentManager().getBackStackEntryCount() == 0
+ && getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT) == null) {
+ mCurHeader = null;
+
+ mPrefsContainer.setVisibility(View.GONE);
+ mHeadersContainer.setVisibility(View.VISIBLE);
+ getListView().clearChoices();
+ } else {
+ super.onBackPressed();
+ }
+ }
+
/**
* Returns true if this activity is currently showing the header list.
*/
public boolean hasHeaders() {
- return getListView().getVisibility() == View.VISIBLE
- && mPreferenceManager == null;
+ return mHeadersContainer != null && mHeadersContainer.getVisibility() == View.VISIBLE;
}
/**
@@ -718,7 +728,7 @@ public abstract class PreferenceActivity extends ListActivity implements
* and a preference fragment.
*/
public boolean isMultiPane() {
- return hasHeaders() && mPrefsContainer.getVisibility() == View.VISIBLE;
+ return !mSinglePane;
}
/**
@@ -820,14 +830,14 @@ public abstract class PreferenceActivity extends ListActivity implements
if (!"preference-headers".equals(nodeName)) {
throw new RuntimeException(
"XML document must start with