Permalink
Browse files

extend PreferenceActivity for title text on a single pane mode

startPreferencePanel() ignores titleText on a single pane mode
this commits extends PreferenceActivity by adding EXTRA_SHOW_FRAGMENT_TITLE_TEXT to intent

ported from CM9, http://review.cyanogenmod.org/#/c/14919
AOSP part verified, but not merged

Change-Id: Ie0702dc20b17504148f4da9cc83a6d7865d95423
Signed-off-by: Chet Kener <Cl3Kener@gmail.com>
  • Loading branch information...
pastime1971 authored and akhilnarang committed Apr 19, 2012
1 parent f4b25b9 commit 3411a42dac476e280115d918a2ad5d54b00c8995
Showing with 56 additions and 2 deletions.
  1. +56 −2 core/java/android/preference/PreferenceActivity.java
@@ -158,6 +158,10 @@
*/
public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":android:show_fragment_title";
// fix for title text for startPreferencePanel in a single pane mode
/** @hide */
public static final String EXTRA_SHOW_FRAGMENT_TITLE_TEXT = ":android:show_fragment_title_text";
/**
* When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
* this extra can also be specify to supply the short title to be shown for
@@ -166,6 +170,11 @@
public static final String EXTRA_SHOW_FRAGMENT_SHORT_TITLE
= ":android:show_fragment_short_title";
// fix for short title text for startPreferencePanel in a single pane mode
/** @hide */
public static final String EXTRA_SHOW_FRAGMENT_SHORT_TITLE_TEXT
= ":android:show_fragment_short_title_text";
/**
* When starting this activity, the invoking Intent can contain this extra
* boolean that the header list should not be displayed. This is most often
@@ -589,6 +598,13 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
CharSequence initialShortTitleStr = initialShortTitle != 0
? getText(initialShortTitle) : null;
showBreadCrumbs(initialTitleStr, initialShortTitleStr);
} else {
CharSequence initialTitleStr = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE_TEXT);
if ( initialTitleStr != null ) {
CharSequence initialShortTitleStr
= getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT_SHORT_TITLE_TEXT);
showBreadCrumbs(initialTitleStr, initialShortTitleStr);
}
}
} else {
@@ -622,6 +638,13 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
CharSequence initialShortTitleStr = initialShortTitle != 0
? getText(initialShortTitle) : null;
showBreadCrumbs(initialTitleStr, initialShortTitleStr);
} else {
CharSequence initialTitleStr = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE_TEXT);
if ( initialTitleStr != null ) {
CharSequence initialShortTitleStr
= getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT_SHORT_TITLE_TEXT);
showBreadCrumbs(initialTitleStr, initialShortTitleStr);
}
}
} else if (mHeaders.size() > 0) {
setListAdapter(new HeaderAdapter(this, mHeaders, mPreferenceHeaderItemResId,
@@ -1103,7 +1126,21 @@ public Intent onBuildStartFragmentIntent(String fragmentName, Bundle args,
intent.putExtra(EXTRA_NO_HEADERS, true);
return intent;
}
// fix for title text for startPreferencePanel in a single pane mode
/** @hide */
public Intent onBuildStartFragmentIntent(String fragmentName, Bundle args,
CharSequence titleText, CharSequence shortTitleText) {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(this, getClass());
intent.putExtra(EXTRA_SHOW_FRAGMENT, fragmentName);
intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
intent.putExtra(EXTRA_SHOW_FRAGMENT_TITLE_TEXT, titleText);
intent.putExtra(EXTRA_SHOW_FRAGMENT_SHORT_TITLE_TEXT, shortTitleText);
intent.putExtra(EXTRA_NO_HEADERS, true);
return intent;
}
/**
* Like {@link #startWithFragment(String, Bundle, Fragment, int, int, int)}
* but uses a 0 titleRes.
@@ -1141,6 +1178,18 @@ public void startWithFragment(String fragmentName, Bundle args,
}
}
// fix for title text for startPreferencePanel in a single pane mode
/** @hide */
public void startWithFragment(String fragmentName, Bundle args, Fragment resultTo,
int resultRequestCode, CharSequence titleText, CharSequence shortTitleText) {
Intent intent = onBuildStartFragmentIntent(fragmentName, args, titleText, shortTitleText);
if (resultTo == null) {
startActivity(intent);
} else {
resultTo.startActivityForResult(intent, resultRequestCode);
}
}
/**
* Change the base title of the bread crumbs for the current preferences.
* This will normally be called for you. See
@@ -1356,7 +1405,12 @@ public void startPreferenceFragment(Fragment fragment, boolean push) {
public void startPreferencePanel(String fragmentClass, Bundle args, @StringRes int titleRes,
CharSequence titleText, Fragment resultTo, int resultRequestCode) {
if (mSinglePane) {
startWithFragment(fragmentClass, args, resultTo, resultRequestCode, titleRes, 0);
// fix for title text for startPreferencePanel in a single pane mode
if (titleRes == 0 && titleText != null) {
startWithFragment(fragmentClass, args, resultTo, resultRequestCode, titleText, null);
} else {
startWithFragment(fragmentClass, args, resultTo, resultRequestCode, titleRes, 0);
}
} else {
Fragment f = Fragment.instantiate(this, fragmentClass, args);
if (resultTo != null) {

0 comments on commit 3411a42

Please sign in to comment.