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

Commit e72f237d authored by Dianne Hackborn's avatar Dianne Hackborn
Browse files

More work on making prefs work well on small screens.

Tweak padding so layouts now look decent, a few extensions so that
the correct title can be shown.

Change-Id: Ieace16bf4962d66564c6e2f67fb588e582943850
parent b18a047d
Loading
Loading
Loading
Loading
+60 −0
Original line number Original line Diff line number Diff line
@@ -153982,6 +153982,17 @@
 visibility="public"
 visibility="public"
>
>
</method>
</method>
<method name="getTitleRes"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getView"
<method name="getView"
 return="android.view.View"
 return="android.view.View"
 abstract="false"
 abstract="false"
@@ -154889,6 +154900,10 @@
</parameter>
</parameter>
<parameter name="args" type="android.os.Bundle">
<parameter name="args" type="android.os.Bundle">
</parameter>
</parameter>
<parameter name="titleRes" type="int">
</parameter>
<parameter name="shortTitleRes" type="int">
</parameter>
</method>
</method>
<method name="onGetInitialHeader"
<method name="onGetInitialHeader"
 return="android.preference.PreferenceActivity.Header"
 return="android.preference.PreferenceActivity.Header"
@@ -155094,6 +155109,29 @@
<parameter name="resultRequestCode" type="int">
<parameter name="resultRequestCode" type="int">
</parameter>
</parameter>
</method>
</method>
<method name="startWithFragment"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="fragmentName" type="java.lang.String">
</parameter>
<parameter name="args" type="android.os.Bundle">
</parameter>
<parameter name="resultTo" type="android.app.Fragment">
</parameter>
<parameter name="resultRequestCode" type="int">
</parameter>
<parameter name="titleRes" type="int">
</parameter>
<parameter name="shortTitleRes" type="int">
</parameter>
</method>
<method name="switchToHeader"
<method name="switchToHeader"
 return="void"
 return="void"
 abstract="false"
 abstract="false"
@@ -155155,6 +155193,28 @@
 visibility="public"
 visibility="public"
>
>
</field>
</field>
<field name="EXTRA_SHOW_FRAGMENT_SHORT_TITLE"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;:android:show_fragment_short_title&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="EXTRA_SHOW_FRAGMENT_TITLE"
 type="java.lang.String"
 transient="false"
 volatile="false"
 value="&quot;:android:show_fragment_title&quot;"
 static="true"
 final="true"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="HEADER_ID_UNDEFINED"
<field name="HEADER_ID_UNDEFINED"
 type="long"
 type="long"
 transient="false"
 transient="false"
+15 −0
Original line number Original line Diff line number Diff line
@@ -89,6 +89,7 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis


    private int mOrder = DEFAULT_ORDER;
    private int mOrder = DEFAULT_ORDER;
    private CharSequence mTitle;
    private CharSequence mTitle;
    private int mTitleRes;
    private CharSequence mSummary;
    private CharSequence mSummary;
    /**
    /**
     * mIconResId is overridden by mIcon, if mIcon is specified.
     * mIconResId is overridden by mIcon, if mIcon is specified.
@@ -214,6 +215,7 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
                    break;
                    break;
                    
                    
                case com.android.internal.R.styleable.Preference_title:
                case com.android.internal.R.styleable.Preference_title:
                    mTitleRes = a.getResourceId(attr, 0);
                    mTitle = a.getString(attr);
                    mTitle = a.getString(attr);
                    break;
                    break;
                    
                    
@@ -582,6 +584,7 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
     */
     */
    public void setTitle(CharSequence title) {
    public void setTitle(CharSequence title) {
        if (title == null && mTitle != null || title != null && !title.equals(mTitle)) {
        if (title == null && mTitle != null || title != null && !title.equals(mTitle)) {
            mTitleRes = 0;
            mTitle = title;
            mTitle = title;
            notifyChanged();
            notifyChanged();
        }
        }
@@ -595,6 +598,18 @@ public class Preference implements Comparable<Preference>, OnDependencyChangeLis
     */
     */
    public void setTitle(int titleResId) {
    public void setTitle(int titleResId) {
        setTitle(mContext.getString(titleResId));
        setTitle(mContext.getString(titleResId));
        mTitleRes = titleResId;
    }
    
    /**
     * Returns the title resource ID of this Preference.  If the title did
     * not come from a resource, 0 is returned.
     *
     * @return The title resource.
     * @see #setTitle(int)
     */
    public int getTitleRes() {
        return mTitleRes;
    }
    }


    /**
    /**
+79 −19
Original line number Original line Diff line number Diff line
@@ -132,12 +132,27 @@ public abstract class PreferenceActivity extends ListActivity implements


    /**
    /**
     * 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 a Bundle of arguments to pass
     * this extra can also be specified to supply a Bundle of arguments to pass
     * to that fragment when it is instantiated during the initial creation
     * to that fragment when it is instantiated during the initial creation
     * of PreferenceActivity.
     * of PreferenceActivity.
     */
     */
    public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":android:show_fragment_args";
    public static final String EXTRA_SHOW_FRAGMENT_ARGUMENTS = ":android:show_fragment_args";


    /**
     * When starting this activity and using {@link #EXTRA_SHOW_FRAGMENT},
     * this extra can also be specify to supply the title to be shown for
     * that fragment.
     */
    public static final String EXTRA_SHOW_FRAGMENT_TITLE = ":android:show_fragment_title";

    /**
     * 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
     * that fragment.
     */
    public static final String EXTRA_SHOW_FRAGMENT_SHORT_TITLE
            = ":android:show_fragment_short_title";

    /**
    /**
     * When starting this activity, the invoking Intent can contain this extra
     * When starting this activity, the invoking Intent can contain this extra
     * boolean that the header list should not be displayed.  This is most often
     * boolean that the header list should not be displayed.  This is most often
@@ -488,7 +503,12 @@ public abstract class PreferenceActivity extends ListActivity implements
    protected void onCreate(Bundle savedInstanceState) {
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        super.onCreate(savedInstanceState);


        if (getResources().getConfiguration().isLayoutSizeAtLeast(
                Configuration.SCREENLAYOUT_SIZE_LARGE)) {
            setContentView(com.android.internal.R.layout.preference_list_content_large);
        } else {
            setContentView(com.android.internal.R.layout.preference_list_content);
            setContentView(com.android.internal.R.layout.preference_list_content);
        }


        mListFooter = (FrameLayout)findViewById(com.android.internal.R.id.list_footer);
        mListFooter = (FrameLayout)findViewById(com.android.internal.R.id.list_footer);
        mPrefsContainer = (ViewGroup) findViewById(com.android.internal.R.id.prefs_frame);
        mPrefsContainer = (ViewGroup) findViewById(com.android.internal.R.id.prefs_frame);
@@ -496,6 +516,8 @@ public abstract class PreferenceActivity extends ListActivity implements
        mSinglePane = hidingHeaders || !onIsMultiPane();
        mSinglePane = hidingHeaders || !onIsMultiPane();
        String initialFragment = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
        String initialFragment = getIntent().getStringExtra(EXTRA_SHOW_FRAGMENT);
        Bundle initialArguments = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
        Bundle initialArguments = getIntent().getBundleExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS);
        int initialTitle = getIntent().getIntExtra(EXTRA_SHOW_FRAGMENT_TITLE, 0);
        int initialShortTitle = getIntent().getIntExtra(EXTRA_SHOW_FRAGMENT_SHORT_TITLE, 0);


        if (savedInstanceState != null) {
        if (savedInstanceState != null) {
            // We are restarting from a previous saved state; used that to
            // We are restarting from a previous saved state; used that to
@@ -516,6 +538,12 @@ public abstract class PreferenceActivity extends ListActivity implements
                // new fragment mode, but don't need to compute and show
                // new fragment mode, but don't need to compute and show
                // the headers.
                // the headers.
                switchToHeader(initialFragment, initialArguments);
                switchToHeader(initialFragment, initialArguments);
                if (initialTitle != 0) {
                    CharSequence initialTitleStr = getText(initialTitle);
                    CharSequence initialShortTitleStr = initialShortTitle != 0
                            ? getText(initialShortTitle) : null;
                    showBreadCrumbs(initialTitleStr, initialShortTitleStr);
                }


            } else {
            } else {
                // We need to try to build the headers.
                // We need to try to build the headers.
@@ -557,7 +585,12 @@ public abstract class PreferenceActivity extends ListActivity implements
        } else {
        } else {
            // If there are no headers, we are in the old "just show a screen
            // If there are no headers, we are in the old "just show a screen
            // of preferences" mode.
            // of preferences" mode.
            if (getResources().getConfiguration().isLayoutSizeAtLeast(
                    Configuration.SCREENLAYOUT_SIZE_LARGE)) {
                setContentView(com.android.internal.R.layout.preference_list_content_single_large);
            } else {
                setContentView(com.android.internal.R.layout.preference_list_content_single);
                setContentView(com.android.internal.R.layout.preference_list_content_single);
            }
            mListFooter = (FrameLayout) findViewById(com.android.internal.R.id.list_footer);
            mListFooter = (FrameLayout) findViewById(com.android.internal.R.id.list_footer);
            mPrefsContainer = (ViewGroup) findViewById(com.android.internal.R.id.prefs);
            mPrefsContainer = (ViewGroup) findViewById(com.android.internal.R.id.prefs);
            mPreferenceManager = new PreferenceManager(this, FIRST_REQUEST_CODE);
            mPreferenceManager = new PreferenceManager(this, FIRST_REQUEST_CODE);
@@ -942,7 +975,8 @@ public abstract class PreferenceActivity extends ListActivity implements


    /**
    /**
     * 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 {@link #startWithFragment(String, Bundle, Fragment, int)}
     * implementation will call either
     * {@link #startWithFragment(String, Bundle, Fragment, int, int, int)}
     * or {@link #switchToHeader(Header)} as appropriate.
     * or {@link #switchToHeader(Header)} as appropriate.
     *
     *
     * @param header The header that was selected.
     * @param header The header that was selected.
@@ -951,7 +985,14 @@ public abstract class PreferenceActivity extends ListActivity implements
    public void onHeaderClick(Header header, int position) {
    public void onHeaderClick(Header header, int position) {
        if (header.fragment != null) {
        if (header.fragment != null) {
            if (mSinglePane) {
            if (mSinglePane) {
                startWithFragment(header.fragment, header.fragmentArguments, null, 0);
                int titleRes = header.breadCrumbTitleRes;
                int shortTitleRes = header.breadCrumbShortTitleRes;
                if (titleRes == 0) {
                    titleRes = header.titleRes;
                    shortTitleRes = 0;
                }
                startWithFragment(header.fragment, header.fragmentArguments, null, 0,
                        titleRes, shortTitleRes);
            } else {
            } else {
                switchToHeader(header);
                switchToHeader(header);
            }
            }
@@ -961,7 +1002,7 @@ public abstract class PreferenceActivity extends ListActivity implements
    }
    }


    /**
    /**
     * Called by {@link #startWithFragment(String, Bundle, Fragment, int)} when
     * Called by {@link #startWithFragment(String, Bundle, Fragment, int, int, int)} when
     * in single-pane mode, to build an Intent to launch a new activity showing
     * in single-pane mode, to build an Intent to launch a new activity showing
     * the selected fragment.  The default implementation constructs an Intent
     * the selected fragment.  The default implementation constructs an Intent
     * that re-launches the current activity with the appropriate arguments to
     * that re-launches the current activity with the appropriate arguments to
@@ -969,18 +1010,32 @@ public abstract class PreferenceActivity extends ListActivity implements
     * 
     * 
     * @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 titleRes Optional resource ID of title to show for this item.
     * @param titleRes Optional resource ID of short 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 Intent onBuildStartFragmentIntent(String fragmentName, Bundle args) {
    public Intent onBuildStartFragmentIntent(String fragmentName, Bundle args,
            int titleRes, int shortTitleRes) {
        Intent intent = new Intent(Intent.ACTION_MAIN);
        Intent intent = new Intent(Intent.ACTION_MAIN);
        intent.setClass(this, getClass());
        intent.setClass(this, getClass());
        intent.putExtra(EXTRA_SHOW_FRAGMENT, fragmentName);
        intent.putExtra(EXTRA_SHOW_FRAGMENT, fragmentName);
        intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
        intent.putExtra(EXTRA_SHOW_FRAGMENT_ARGUMENTS, args);
        intent.putExtra(EXTRA_SHOW_FRAGMENT_TITLE, titleRes);
        intent.putExtra(EXTRA_SHOW_FRAGMENT_SHORT_TITLE, shortTitleRes);
        intent.putExtra(EXTRA_NO_HEADERS, true);
        intent.putExtra(EXTRA_NO_HEADERS, true);
        return intent;
        return intent;
    }
    }
    
    
    /**
     * Like {@link #startWithFragment(String, Bundle, Fragment, int, int, int)}
     * but uses a 0 titleRes.
     */
    public void startWithFragment(String fragmentName, Bundle args,
            Fragment resultTo, int resultRequestCode) {
        startWithFragment(fragmentName, args, resultTo, resultRequestCode, 0, 0);
    }

    /**
    /**
     * Start a new instance of this activity, showing only the given
     * Start a new instance of this activity, showing only the given
     * preference fragment.  When launched in this mode, the header list
     * preference fragment.  When launched in this mode, the header list
@@ -993,10 +1048,14 @@ public abstract class PreferenceActivity extends ListActivity implements
     * 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 report the result.
     * code in which to report the result.
     * @param titleRes Resource ID of string to display for the title of
     * this set of preferences.
     * @param titleRes Resource ID of string to display for the short title of
     * this set of preferences.
     */
     */
    public void startWithFragment(String fragmentName, Bundle args,
    public void startWithFragment(String fragmentName, Bundle args,
            Fragment resultTo, int resultRequestCode) {
            Fragment resultTo, int resultRequestCode, int titleRes, int shortTitleRes) {
        Intent intent = onBuildStartFragmentIntent(fragmentName, args);
        Intent intent = onBuildStartFragmentIntent(fragmentName, args, titleRes, shortTitleRes);
        if (resultTo == null) {
        if (resultTo == null) {
            startActivity(intent);
            startActivity(intent);
        } else {
        } else {
@@ -1013,16 +1072,16 @@ public abstract class PreferenceActivity extends ListActivity implements
        if (mFragmentBreadCrumbs == null) {
        if (mFragmentBreadCrumbs == null) {
            View crumbs = findViewById(android.R.id.title);
            View crumbs = findViewById(android.R.id.title);
            // For screens with a different kind of title, don't create breadcrumbs.
            // For screens with a different kind of title, don't create breadcrumbs.
            if (!(crumbs instanceof FragmentBreadCrumbs)) return;
            try {
            mFragmentBreadCrumbs = (FragmentBreadCrumbs) findViewById(android.R.id.title);
                mFragmentBreadCrumbs = (FragmentBreadCrumbs)crumbs;
            } catch (ClassCastException e) {
                return;
            }
            if (mFragmentBreadCrumbs == null) {
            if (mFragmentBreadCrumbs == null) {
                mFragmentBreadCrumbs = new FragmentBreadCrumbs(this);
                if (title != null) {
                ActionBar actionBar = getActionBar();
                    setTitle(title);
                if (actionBar != null) {
                    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
                            ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
                    actionBar.setCustomView(mFragmentBreadCrumbs);
                }
                }
                return;
            }
            }
            mFragmentBreadCrumbs.setMaxVisible(2);
            mFragmentBreadCrumbs.setMaxVisible(2);
            mFragmentBreadCrumbs.setActivity(this);
            mFragmentBreadCrumbs.setActivity(this);
@@ -1190,7 +1249,7 @@ public abstract class PreferenceActivity extends ListActivity implements
    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) {
        if (mSinglePane) {
        if (mSinglePane) {
            startWithFragment(fragmentClass, args, resultTo, resultRequestCode);
            startWithFragment(fragmentClass, args, resultTo, resultRequestCode, titleRes, 0);
        } else {
        } else {
            Fragment f = Fragment.instantiate(this, fragmentClass, args);
            Fragment f = Fragment.instantiate(this, fragmentClass, args);
            if (resultTo != null) {
            if (resultTo != null) {
@@ -1236,7 +1295,8 @@ public abstract class PreferenceActivity extends ListActivity implements
    
    
    @Override
    @Override
    public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
    public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
        startPreferencePanel(pref.getFragment(), pref.getExtras(), 0, pref.getTitle(), null, 0);
        startPreferencePanel(pref.getFragment(), pref.getExtras(), pref.getTitleRes(),
                pref.getTitle(), null, 0);
        return true;
        return true;
    }
    }


+9 −2
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import android.app.Activity;
import android.app.Fragment;
import android.app.Fragment;
import android.content.Intent;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.os.Bundle;
import android.os.Handler;
import android.os.Handler;
import android.os.Message;
import android.os.Message;
@@ -151,9 +152,15 @@ public abstract class PreferenceFragment extends Fragment implements
    @Override
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {
            Bundle savedInstanceState) {
        if (getResources().getConfiguration().isLayoutSizeAtLeast(
                Configuration.SCREENLAYOUT_SIZE_LARGE)) {
            return inflater.inflate(com.android.internal.R.layout.preference_list_fragment_large,
                    container, false);
        } else {
            return inflater.inflate(com.android.internal.R.layout.preference_list_fragment,
            return inflater.inflate(com.android.internal.R.layout.preference_list_fragment,
                    container, false);
                    container, false);
        }
        }
    }


    @Override
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
    public void onActivityCreated(Bundle savedInstanceState) {
+0 −26
Original line number Original line Diff line number Diff line
@@ -36,8 +36,6 @@
            android:layout_height="match_parent"
            android:layout_height="match_parent"
            android:layout_marginRight="@dimen/preference_screen_side_margin_negative"
            android:layout_marginRight="@dimen/preference_screen_side_margin_negative"
            android:layout_marginLeft="@dimen/preference_screen_side_margin"
            android:layout_marginLeft="@dimen/preference_screen_side_margin"
            android:layout_marginTop="32dp"
            android:layout_marginBottom="32dp"
            android:layout_weight="10">
            android:layout_weight="10">


            <ListView android:id="@android:id/list"
            <ListView android:id="@android:id/list"
@@ -61,33 +59,9 @@
                android:layout_width="0px"
                android:layout_width="0px"
                android:layout_height="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="20"
                android:layout_weight="20"
                android:layout_marginLeft="@dimen/preference_screen_side_margin"
                android:layout_marginRight="@dimen/preference_screen_side_margin"
                android:layout_marginTop="16dp"
                android:layout_marginBottom="16dp"
                android:background="?attr/detailsElementBackground"
                android:orientation="vertical"
                android:orientation="vertical"
                android:visibility="gone" >
                android:visibility="gone" >


            <!-- Breadcrumb inserted here -->
            <android.app.FragmentBreadCrumbs
                android:id="@android:id/title"
                android:layout_height="72dip"
                android:layout_width="match_parent"
                android:paddingTop="16dip"
                android:paddingBottom="8dip"
                android:gravity="center_vertical|left"
                android:layout_marginLeft="48dip"
                android:layout_marginRight="48dip"
                />

            <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="1dip"
                    android:paddingLeft="32dip"
                    android:paddingRight="32dip"
                    android:src="#404040"
                />
            <android.preference.PreferenceFrameLayout android:id="@+id/prefs"
            <android.preference.PreferenceFrameLayout android:id="@+id/prefs"
                    android:layout_width="match_parent"
                    android:layout_width="match_parent"
                    android:layout_height="0dip"
                    android:layout_height="0dip"
Loading