2323import android .provider .Telephony .Sms ;
2424import android .support .annotation .NonNull ;
2525import android .support .annotation .Nullable ;
26+ import android .support .annotation .StringRes ;
2627import android .support .v4 .app .ActivityCompat ;
2728import android .support .v4 .app .Fragment ;
2829import android .support .v4 .app .FragmentManager ;
@@ -116,13 +117,14 @@ public class MainActivity extends ThemeActivity implements
116117 private static final int REQUEST_PERMISSIONS_BACKUP_SERVICE = 6 ;
117118
118119 public static final String EXTRA_PERMISSIONS = "permissions" ;
119- private static final String SCREEN_TITLE = "title " ;
120+ private static final String SCREEN_TITLE_RES = "titleRes " ;
120121
121122 private Preferences preferences ;
122123 private AuthPreferences authPreferences ;
123124 private OAuth2Client oauth2Client ;
124125 private Intent fallbackAuthIntent ;
125126 private Intent changeDefaultPackageIntent ;
127+ private PreferenceTitles preferenceTitles ;
126128
127129 @ Override
128130 public void onCreate (Bundle bundle ) {
@@ -136,7 +138,7 @@ public void onCreate(Bundle bundle) {
136138 oauth2Client = new OAuth2Client (authPreferences .getOAuth2ClientId ());
137139 fallbackAuthIntent = new Intent (this , OAuth2WebAuthActivity .class ).setData (oauth2Client .requestUrl ());
138140 changeDefaultPackageIntent = new Intent (ACTION_CHANGE_DEFAULT ).putExtra (EXTRA_PACKAGE_NAME , getPackageName ());
139-
141+ preferenceTitles = new PreferenceTitles ( getResources (), R . xml . preferences );
140142 preferences = new Preferences (this );
141143 if (bundle == null ) {
142144 showFragment (new MainSettings (), null );
@@ -237,8 +239,11 @@ public boolean onPreferenceStartFragment(PreferenceFragmentCompat caller, Prefer
237239 if (LOCAL_LOGV ) {
238240 Log .v (TAG , "onPreferenceStartFragment(" + preference + ")" );
239241 }
240- final Fragment fragment = Fragment .instantiate (this , preference .getFragment (),
241- new BundleBuilder ().putString (SCREEN_TITLE , String .valueOf (preference .getTitle ())).build ());
242+ final Fragment fragment = Fragment .instantiate (
243+ this ,
244+ preference .getFragment (),
245+ new BundleBuilder ().putInt (SCREEN_TITLE_RES , preferenceTitles .getTitleRes (preference .getKey ())).build ());
246+
242247 showFragment (fragment , preference .getKey ());
243248 return true ;
244249 }
@@ -318,13 +323,13 @@ public boolean onPreferenceStartScreen(PreferenceFragmentCompat caller, Preferen
318323 onBackStackChanged ();
319324 }
320325
321- private @ Nullable CharSequence getCurrentTitle () {
326+ private @ StringRes int getCurrentTitle () {
322327 final int entryCount = getSupportFragmentManager ().getBackStackEntryCount ();
323328 if (entryCount == 0 ) {
324- return null ;
329+ return 0 ;
325330 } else {
326331 final BackStackEntry entry = getSupportFragmentManager ().getBackStackEntryAt (entryCount - 1 );
327- return entry .getBreadCrumbTitle ();
332+ return entry .getBreadCrumbTitleRes ();
328333 }
329334 }
330335
@@ -409,7 +414,7 @@ private void showFragment(@NonNull Fragment fragment, @Nullable String rootKey)
409414 .replace (R .id .preferences_container , fragment , rootKey );
410415 if (rootKey != null ) {
411416 tx .addToBackStack (null );
412- tx .setBreadCrumbTitle (args .getString ( SCREEN_TITLE ));
417+ tx .setBreadCrumbTitle (args .getInt ( SCREEN_TITLE_RES ));
413418 }
414419 tx .commit ();
415420 }
0 commit comments