のねのBlog

パソコンの問題や、ソフトウェアの開発で起きた問題など書いていきます。よろしくお願いします^^。

PreferenceFragment

   385     public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
    386         // Override the fragment title for Wallpaper settings
    387         int titleRes = pref.getTitleRes();

    388         if (pref.getFragment().equals(WallpaperTypeSettings.class.getName())) {
    389             titleRes = R.string.wallpaper_settings_fragment_title;
    390         } else if (pref.getFragment().equals(OwnerInfoSettings.class.getName())
    391                 && UserHandle.myUserId() != UserHandle.USER_OWNER) {
    392             if (UserManager.get(this).isLinkedUser()) {
    393                 titleRes = R.string.profile_info_settings_title;
    394             } else {
    395                 titleRes = R.string.user_info_settings_title;
    396             }
    397         }
    398         startPreferencePanel(pref.getFragment(), pref.getExtras(), titleRes, pref.getTitle(),
    399                 null, 0);
    400         return true;
    401     }
    663     public int getTitleRes() {
    664         return mTitleRes;
    665     }
    847     public void startPreferencePanel(
                    String       fragmentClass,
                    Bundle       args,
                    int          titleRes,
    848             CharSequence titleText,
                    Fragment     resultTo,
                    int          resultRequestCode) {
    849         String title = null;
 
    850         if (titleRes < 0) { // 負のとき
    851             if (titleText != null) {
    852                 title = titleText.toString();
    853             } else {
    854                 // There not much we can do in that case
    855                 title = "";
    856             }
    857         }
    858         Utils.startWithFragment(
                        this, 
                        fragmentClass,
                        args,
                        resultTo,
                        resultRequestCode,
    859                 titleRes,
                        title, mIsShortcut);
    860     }
    594     public static void startWithFragment(
                    Context      context,
                    String       fragmentName,
                    Bundle       args,
    595             Fragment     resultTo,
                    int          resultRequestCode,
                    int          titleResId,
                    CharSequence title) {
    596         startWithFragment(context, fragmentName, args, resultTo, resultRequestCode,
    597                 titleResId, title, false /* not a shortcut */);
    598     }
    600     public static void startWithFragment(
                    Context      context,
                    String       fragmentName,
                    Bundle       args,
    601             Fragment     resultTo,
                    int          resultRequestCode,
                    int          titleResId,
                    CharSequence title,
    602             boolean      isShortcut) {
    603         Intent intent = onBuildStartFragmentIntent(context, fragmentName, args, titleResId,
    604                 title, isShortcut);

    605         if (resultTo == null) {
    606             context.startActivity(intent);
    607         } else {
    608             resultTo.startActivityForResult(intent, resultRequestCode);
    609         }
    610     }
    636     public static Intent onBuildStartFragmentIntent(
                    Context      context,
                    String       fragmentName,
    637             Bundle       args,
                    int          titleResId,
                    CharSequence title,
                    boolean      isShortcut) {
    638         Intent intent = new Intent(Intent.ACTION_MAIN);
    639         intent.setClass(context, SubSettings.class);
    640         intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT, fragmentName);
    641         intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
    642         intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, titleResId);
    643         intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE, title);
    644         intent.putExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_AS_SHORTCUT, isShortcut);
    645         return intent;
    646     }