Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6c34adb9 authored by Sang Tae Park's avatar Sang Tae Park Committed by Ricardo Cerqueira
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
parent 7039b79e
Loading
Loading
Loading
Loading
+56 −2
Original line number Diff line number Diff line
@@ -156,6 +156,10 @@ public abstract class PreferenceActivity extends ListActivity implements
     */
    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
@@ -164,6 +168,11 @@ public abstract class PreferenceActivity extends ListActivity implements
    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
@@ -548,6 +557,13 @@ public abstract class PreferenceActivity extends ListActivity implements
                    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 {
@@ -581,6 +597,13 @@ public abstract class PreferenceActivity extends ListActivity implements
                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));
@@ -1062,6 +1085,20 @@ public abstract class PreferenceActivity extends ListActivity implements
        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.
@@ -1098,6 +1135,18 @@ public abstract class PreferenceActivity extends ListActivity implements
        }
    }

    // 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
@@ -1307,7 +1356,12 @@ public abstract class PreferenceActivity extends ListActivity implements
    public void startPreferencePanel(String fragmentClass, Bundle args, int titleRes,
            CharSequence titleText, Fragment resultTo, int resultRequestCode) {
        if (mSinglePane) {
            // 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) {