Fix bug #14499324 Label of the "Language & input " page doesn't get updated

...as per the newly selected language

- use also title resource id when possible

Change-Id: Ibeb95d605cd79910c18f4529b749645c9ed0fc17
This commit is contained in:
Fabrice Di Meglio
2014-06-09 12:52:24 -07:00
parent d407f2a05c
commit a9e77993d1
4 changed files with 56 additions and 35 deletions

View File

@@ -175,10 +175,11 @@ public class SettingsActivity extends Activity
/** /**
* When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT}, * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
* this extra can also be specify to supply the title to be shown for * those extra can also be specify to supply the title or title res id to be shown for
* that fragment. * that fragment.
*/ */
public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title"; public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":settings:show_fragment_title";
public static final String EXTRA_SHOW_FRAGMENT_TITLE_RESID = ":settings:show_fragment_title_resid";
private static final String META_DATA_KEY_FRAGMENT_CLASS = private static final String META_DATA_KEY_FRAGMENT_CLASS =
"com.android.settings.FRAGMENT_CLASS"; "com.android.settings.FRAGMENT_CLASS";
@@ -192,6 +193,7 @@ public class SettingsActivity extends Activity
private String mFragmentClass; private String mFragmentClass;
private CharSequence mInitialTitle; private CharSequence mInitialTitle;
private int mInitialTitleResId;
// Show only these settings for restricted users // Show only these settings for restricted users
private int[] SETTINGS_FOR_RESTRICTED = { private int[] SETTINGS_FOR_RESTRICTED = {
@@ -478,9 +480,7 @@ public class SettingsActivity extends Activity
mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED); mSearchMenuItemExpanded = savedState.getBoolean(SAVE_KEY_SEARCH_MENU_EXPANDED);
mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY); mSearchQuery = savedState.getString(SAVE_KEY_SEARCH_QUERY);
final String initialTitle = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE); setTitleFromIntent(getIntent());
mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
setTitle(mInitialTitle);
ArrayList<DashboardCategory> categories = ArrayList<DashboardCategory> categories =
savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES); savedState.getParcelableArrayList(SAVE_KEY_CATEGORIES);
@@ -500,19 +500,17 @@ public class SettingsActivity extends Activity
mDisplayHomeAsUpEnabled = false; mDisplayHomeAsUpEnabled = false;
mDisplaySearch = false; mDisplaySearch = false;
} }
final String initialTitle = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE); setTitleFromIntent(getIntent());
mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
setTitle(mInitialTitle);
Bundle initialArguments = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS); Bundle initialArguments = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
switchToFragment( initialFragmentName, initialArguments, true, false, switchToFragment(initialFragmentName, initialArguments, true, false,
mInitialTitle, false); mInitialTitleResId, mInitialTitle, false);
} else { } else {
// No UP if we are displaying the main Dashboard // No UP if we are displaying the main Dashboard
mDisplayHomeAsUpEnabled = false; mDisplayHomeAsUpEnabled = false;
mInitialTitle = getText(R.string.dashboard_title); mInitialTitleResId = R.string.dashboard_title;
switchToFragment(DashboardSummary.class.getName(), null, false, false, switchToFragment(DashboardSummary.class.getName(), null, false, false,
mInitialTitle, false); mInitialTitleResId, mInitialTitle, false);
} }
} }
@@ -579,6 +577,20 @@ public class SettingsActivity extends Activity
} }
} }
private void setTitleFromIntent(Intent intent) {
final int initialTitleResId = intent.getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE_RESID, -1);
if (initialTitleResId > 0) {
mInitialTitle = null;
mInitialTitleResId = initialTitleResId;
setTitle(mInitialTitleResId);
} else {
mInitialTitleResId = -1;
final String initialTitle = intent.getStringExtra(EXTRA_SHOW_FRAGMENT_TITLE);
mInitialTitle = (initialTitle != null) ? initialTitle : getTitle();
setTitle(mInitialTitle);
}
}
@Override @Override
public void onBackStackChanged() { public void onBackStackChanged() {
setTitleFromBackStack(); setTitleFromBackStack();
@@ -588,7 +600,11 @@ public class SettingsActivity extends Activity
final int count = getFragmentManager().getBackStackEntryCount(); final int count = getFragmentManager().getBackStackEntryCount();
if (count == 0) { if (count == 0) {
setTitle(mInitialTitle); if (mInitialTitleResId > 0) {
setTitle(mInitialTitleResId);
} else {
setTitle(mInitialTitle);
}
return 0; return 0;
} }
@@ -753,16 +769,17 @@ 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, int resultRequestCode) { CharSequence titleText, Fragment resultTo, int resultRequestCode) {
String title; String title = null;
if (titleRes > 0) { if (titleRes < 0) {
title = getString(titleRes); if (titleText != null) {
} else if (titleText != null) { title = titleText.toString();
title = titleText.toString(); } else {
} else { // There not much we can do in that case
// There not much we can do in that case title = "";
title = ""; }
} }
Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode, title); Utils.startWithFragment(this, fragmentClass, args, resultTo, resultRequestCode,
titleRes, title);
} }
/** /**
@@ -801,7 +818,7 @@ public class SettingsActivity extends Activity
* Switch to a specific Fragment with taking care of validation, Title and BackStack * Switch to a specific Fragment with taking care of validation, Title and BackStack
*/ */
private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate, private Fragment switchToFragment(String fragmentName, Bundle args, boolean validate,
boolean addToBackStack, CharSequence title, boolean withTransition) { boolean addToBackStack, int titleResId, CharSequence title, boolean withTransition) {
if (validate && !isValidFragment(fragmentName)) { if (validate && !isValidFragment(fragmentName)) {
throw new IllegalArgumentException("Invalid fragment for this activity: " throw new IllegalArgumentException("Invalid fragment for this activity: "
+ fragmentName); + fragmentName);
@@ -815,7 +832,9 @@ public class SettingsActivity extends Activity
if (addToBackStack) { if (addToBackStack) {
transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS); transaction.addToBackStack(SettingsActivity.BACK_STACK_PREFS);
} }
if (title != null) { if (titleResId > 0) {
transaction.setBreadCrumbTitle(titleResId);
} else if (title != null) {
transaction.setBreadCrumbTitle(title); transaction.setBreadCrumbTitle(title);
} }
transaction.commitAllowingStateLoss(); transaction.commitAllowingStateLoss();
@@ -1270,10 +1289,9 @@ public class SettingsActivity extends Activity
if (current != null && current instanceof SearchResultsSummary) { if (current != null && current instanceof SearchResultsSummary) {
mSearchResultsFragment = (SearchResultsSummary) current; mSearchResultsFragment = (SearchResultsSummary) current;
} else { } else {
String title = getString(R.string.search_results_title);
mSearchResultsFragment = (SearchResultsSummary) switchToFragment( mSearchResultsFragment = (SearchResultsSummary) switchToFragment(
SearchResultsSummary.class.getName(), null, false, true, title, SearchResultsSummary.class.getName(), null, false, true,
true); R.string.search_results_title, null, true);
} }
mSearchResultsFragment.setSearchView(mSearchView); mSearchResultsFragment.setSearchView(mSearchView);
mSearchMenuItemExpanded = true; mSearchMenuItemExpanded = true;

View File

@@ -519,15 +519,16 @@ public class Utils {
* @param context The context. * @param context The context.
* @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 code in which
* @param resultRequestCode If resultTo is non-null, this is the request * to report the result.
* code in which to report the result. * @param titleResId resource id for the String to display for the title of this set
* of preferences.
* @param title String to display for the title of this set of preferences. * @param title String to display for the title of this set of preferences.
*/ */
public static void startWithFragment(Context context, String fragmentName, Bundle args, public static void startWithFragment(Context context, String fragmentName, Bundle args,
Fragment resultTo, int resultRequestCode, CharSequence title) { Fragment resultTo, int resultRequestCode, int titleResId, CharSequence title) {
Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, title); Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResId, title);
if (resultTo == null) { if (resultTo == null) {
context.startActivity(intent); context.startActivity(intent);
} else { } else {
@@ -543,16 +544,18 @@ public class Utils {
* @param context The Context. * @param context The Context.
* @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 titleResId Optional title resource id to show for this item.
* @param title Optional title to show for this item. * @param title Optional title to show for this item.
* @return Returns an Intent that can be launched to display the given * @return Returns an Intent that can be launched to display the given
* fragment. * fragment.
*/ */
public static Intent onBuildStartFragmentIntent(Context context, String fragmentName, public static Intent onBuildStartFragmentIntent(Context context, String fragmentName,
Bundle args, CharSequence title) { Bundle args, int titleResId, CharSequence title) {
Intent intent = new Intent(Intent.ACTION_MAIN); Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClass(context, SubSettings.class); intent.setClass(context, SubSettings.class);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, fragmentName); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, fragmentName);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, titleResId);
intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, title); intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, title);
return intent; return intent;
} }

View File

@@ -85,7 +85,7 @@ public class DashboardTileView extends FrameLayout implements View.OnClickListen
public void onClick(View v) { public void onClick(View v) {
if (mTile.fragment != null) { if (mTile.fragment != null) {
Utils.startWithFragment(getContext(), mTile.fragment, mTile.fragmentArguments, null, 0, Utils.startWithFragment(getContext(), mTile.fragment, mTile.fragmentArguments, null, 0,
mTile.getTitle(getResources())); mTile.titleRes, mTile.getTitle(getResources()));
} else if (mTile.intent != null) { } else if (mTile.intent != null) {
getContext().startActivity(mTile.intent); getContext().startActivity(mTile.intent);
} }

View File

@@ -181,7 +181,7 @@ public class SearchResultsSummary extends Fragment {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, key); args.putString(SettingsActivity.EXTRA_FRAGMENT_ARG_KEY, key);
Utils.startWithFragment(sa, className, args, null, 0, screenTitle); Utils.startWithFragment(sa, className, args, null, 0, -1, screenTitle);
} else { } else {
final Intent intent = new Intent(action); final Intent intent = new Intent(action);