Fix bug #12890490 Crash in Settings observed after tap on Preferred Engine settings and Cloud print option

- when setting the Fragment's title use the CharSequence when the titleRes ID is "0"

Change-Id: I54e5379172632acfc967b5ea401ba90f73b41748
This commit is contained in:
Fabrice Di Meglio
2014-02-04 12:41:30 -08:00
parent b75d7275c1
commit dc77b738a7

View File

@@ -924,7 +924,7 @@ public class SettingsActivity extends Activity
public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes, public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
CharSequence titleText, Fragment resultTo, CharSequence titleText, Fragment resultTo,
int resultRequestCode) { int resultRequestCode) {
startWithFragment(fragmentClass, args, resultTo, resultRequestCode, titleRes, 0); startWithFragment(fragmentClass, args, resultTo, resultRequestCode, titleRes, titleText);
} }
/** /**
@@ -965,16 +965,16 @@ public class SettingsActivity extends Activity
* @param fragmentName The name of the fragment to display. * @param fragmentName The name of the fragment to display.
* @param args Optional arguments to supply to the fragment. * @param args Optional arguments to supply to the fragment.
* @param resultTo Option fragment that should receive the result of * @param resultTo Option fragment that should receive the result of
* the activity launch. * the activity launch.
* @param resultRequestCode If resultTo is non-null, this is the request * @param resultRequestCode If resultTo is non-null, this is the request code in which to
* code in which to report the result. * report the result.
* @param titleRes Resource ID of string to display for the title of * @param titleRes Resource ID of string to display for the title of. If the Resource ID is a
* this set of preferences. * valid one then it will be used to get the title. Otherwise the titleText
* @param shortTitleRes Resource ID of string to display for the short title of * argument will be used as the title.
* this set of preferences. * @param titleText string to display for the title of.
*/ */
private void startWithFragment(String fragmentName, Bundle args, Fragment resultTo, private void startWithFragment(String fragmentName, Bundle args, Fragment resultTo,
int resultRequestCode, int titleRes, int shortTitleRes) { int resultRequestCode, int titleRes, CharSequence titleText) {
Fragment f = Fragment.instantiate(this, fragmentName, args); Fragment f = Fragment.instantiate(this, fragmentName, args);
if (resultTo != null) { if (resultTo != null) {
f.setTargetFragment(resultTo, resultRequestCode); f.setTargetFragment(resultTo, resultRequestCode);
@@ -985,10 +985,17 @@ public class SettingsActivity extends Activity
transaction.addToBackStack(BACK_STACK_PREFS); transaction.addToBackStack(BACK_STACK_PREFS);
transaction.commitAllowingStateLoss(); transaction.commitAllowingStateLoss();
final CharSequence title = getText(titleRes); final TitlePair pair;
final TitlePair pair = new TitlePair(titleRes, null); final CharSequence cs;
if (titleRes != 0) {
pair = new TitlePair(titleRes, null);
cs = getText(titleRes);
} else {
pair = new TitlePair(0, titleText);
cs = titleText;
}
setTitle(cs);
mTitleStack.add(pair); mTitleStack.add(pair);
setTitle(title);
} }
/** /**
@@ -1583,7 +1590,7 @@ public class SettingsActivity extends Activity
/** /**
* Called when the user selects an item in the header list. The default * Called when the user selects an item in the header list. The default
* implementation will call either * implementation will call either
* {@link #startWithFragment(String, Bundle, Fragment, int, int, int)} * {@link #startWithFragment(String, android.os.Bundle, android.app.Fragment, int, int, CharSequence)}
* or {@link #switchToHeader(com.android.settings.SettingsActivity.Header, boolean)} * or {@link #switchToHeader(com.android.settings.SettingsActivity.Header, boolean)}
* as appropriate. * as appropriate.
* *