Merge "Fix title when changing from portrait to landscape configuration"
This commit is contained in:
committed by
Android (Google) Code Review
commit
de40d9ed2f
@@ -133,6 +133,7 @@ public class SettingsActivity extends Activity
|
|||||||
// Constants for state save/restore
|
// Constants for state save/restore
|
||||||
private static final String SAVE_KEY_HEADERS_TAG = ":settings:headers";
|
private static final String SAVE_KEY_HEADERS_TAG = ":settings:headers";
|
||||||
private static final String SAVE_KEY_CURRENT_HEADER_TAG = ":settings:cur_header";
|
private static final String SAVE_KEY_CURRENT_HEADER_TAG = ":settings:cur_header";
|
||||||
|
private static final String SAVE_KEY_TITLES_TAG = ":settings:titles";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When starting this activity, the invoking Intent can contain this extra
|
* When starting this activity, the invoking Intent can contain this extra
|
||||||
@@ -312,11 +313,35 @@ public class SettingsActivity extends Activity
|
|||||||
private final ArrayList<Header> mHeaders = new ArrayList<Header>();
|
private final ArrayList<Header> mHeaders = new ArrayList<Header>();
|
||||||
private HeaderAdapter mHeaderAdapter;
|
private HeaderAdapter mHeaderAdapter;
|
||||||
|
|
||||||
private class TitlePair extends Pair<Integer, CharSequence> {
|
static private class TitlePair extends Pair<Integer, CharSequence> implements Parcelable {
|
||||||
|
|
||||||
public TitlePair(Integer first, CharSequence second) {
|
public TitlePair(Integer first, CharSequence second) {
|
||||||
super(first, second);
|
super(first, second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int describeContents() {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeToParcel(Parcel dest, int flags) {
|
||||||
|
dest.writeInt(first);
|
||||||
|
TextUtils.writeToParcel(second, dest, flags);
|
||||||
|
}
|
||||||
|
|
||||||
|
TitlePair(Parcel in) {
|
||||||
|
super(in.readInt(), TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final Creator<TitlePair> CREATOR = new Creator<TitlePair>() {
|
||||||
|
public TitlePair createFromParcel(Parcel source) {
|
||||||
|
return new TitlePair(source);
|
||||||
|
}
|
||||||
|
public TitlePair[] newArray(int size) {
|
||||||
|
return new TitlePair[size];
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
private final ArrayList<TitlePair> mTitleStack = new ArrayList<TitlePair>();
|
private final ArrayList<TitlePair> mTitleStack = new ArrayList<TitlePair>();
|
||||||
@@ -527,6 +552,18 @@ public class SettingsActivity extends Activity
|
|||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
// We are restarting from a previous saved state; used that to
|
// We are restarting from a previous saved state; used that to
|
||||||
// initialize, instead of starting fresh.
|
// initialize, instead of starting fresh.
|
||||||
|
|
||||||
|
ArrayList<TitlePair> titles =
|
||||||
|
savedInstanceState.getParcelableArrayList(SAVE_KEY_TITLES_TAG);
|
||||||
|
if (titles != null) {
|
||||||
|
mTitleStack.addAll(titles);
|
||||||
|
}
|
||||||
|
final int lastTitle = mTitleStack.size() - 1;
|
||||||
|
if (lastTitle >= 0) {
|
||||||
|
final TitlePair last = mTitleStack.get(lastTitle);
|
||||||
|
setTitleFromPair(last);
|
||||||
|
}
|
||||||
|
|
||||||
ArrayList<Header> headers =
|
ArrayList<Header> headers =
|
||||||
savedInstanceState.getParcelableArrayList(SAVE_KEY_HEADERS_TAG);
|
savedInstanceState.getParcelableArrayList(SAVE_KEY_HEADERS_TAG);
|
||||||
if (headers != null) {
|
if (headers != null) {
|
||||||
@@ -642,19 +679,21 @@ public class SettingsActivity extends Activity
|
|||||||
if (size > 0) {
|
if (size > 0) {
|
||||||
last = mTitleStack.size() - 1;
|
last = mTitleStack.size() - 1;
|
||||||
pair = mTitleStack.get(last);
|
pair = mTitleStack.get(last);
|
||||||
if (pair != null) {
|
setTitleFromPair(pair);
|
||||||
final CharSequence title;
|
|
||||||
if (pair.first > 0) {
|
|
||||||
title = getText(pair.first);
|
|
||||||
} else {
|
|
||||||
title = pair.second;
|
|
||||||
}
|
|
||||||
setTitle(title);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setTitleFromPair(TitlePair pair) {
|
||||||
|
final CharSequence title;
|
||||||
|
if (pair.first > 0) {
|
||||||
|
title = getText(pair.first);
|
||||||
|
} else {
|
||||||
|
title = pair.second;
|
||||||
|
}
|
||||||
|
setTitle(title);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Header list
|
* Returns the Header list
|
||||||
*/
|
*/
|
||||||
@@ -675,6 +714,10 @@ public class SettingsActivity extends Activity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mTitleStack.size() > 0) {
|
||||||
|
outState.putParcelableList(SAVE_KEY_TITLES_TAG, mTitleStack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Reference in New Issue
Block a user