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

Commit 468c3230 authored by Andrew Stadler's avatar Andrew Stadler
Browse files

Fix two bugs in PreferenceActivity headers

* Make Header fields public so activities can write them
* Recycle views properly
* Also made the HeaderAdapter and HeaderViewHolder static inner classes
  for a little extra efficiency.

Change-Id: If0a9276e4609e2e8568c7c5a6963f3ed3e25565f
parent 6394c0e5
Loading
Loading
Loading
Loading
+60 −0
Original line number Diff line number Diff line
@@ -138941,6 +138941,66 @@
 visibility="public"
>
</constructor>
<field name="fragment"
 type="java.lang.String"
 transient="false"
 volatile="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="fragmentArguments"
 type="android.os.Bundle"
 transient="false"
 volatile="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="icon"
 type="android.graphics.drawable.Drawable"
 transient="false"
 volatile="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="iconRes"
 type="int"
 transient="false"
 volatile="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="summary"
 type="java.lang.CharSequence"
 transient="false"
 volatile="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</field>
<field name="title"
 type="java.lang.CharSequence"
 transient="false"
 volatile="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</field>
</class>
<class name="PreferenceCategory"
 extends="android.preference.PreferenceGroup"
+31 −23
Original line number Diff line number Diff line
@@ -194,13 +194,13 @@ public abstract class PreferenceActivity extends ListActivity implements
        }
    };

    private class HeaderViewHolder {
    private static class HeaderAdapter extends ArrayAdapter<Header> {
        private static class HeaderViewHolder {
            ImageView icon;
            TextView title;
            TextView summary;
        }

    private class HeaderAdapter extends ArrayAdapter<Header> {
        private LayoutInflater mInflater;

        public HeaderAdapter(Context context, List<Header> objects) {
@@ -217,23 +217,31 @@ public abstract class PreferenceActivity extends ListActivity implements
                view = mInflater.inflate(com.android.internal.R.layout.preference_list_item,
                        parent, false);
                holder = new HeaderViewHolder();
                holder.icon = (ImageView)view.findViewById(
                        com.android.internal.R.id.icon);
                holder.title = (TextView)view.findViewById(
                        com.android.internal.R.id.title);
                holder.summary = (TextView)view.findViewById(
                        com.android.internal.R.id.summary);
                holder.icon = (ImageView) view.findViewById(com.android.internal.R.id.icon);
                holder.title = (TextView) view.findViewById(com.android.internal.R.id.title);
                holder.summary = (TextView) view.findViewById(com.android.internal.R.id.summary);
                view.setTag(holder);
            } else {
                view = convertView;
                holder = (HeaderViewHolder) view.getTag();
            }

            // All view fields must be updated every time, because the view may be recycled 
            Header header = getItem(position);
            if (header.icon != null) holder.icon.setImageDrawable(header.icon);
            else if (header.iconRes != 0) holder.icon.setImageResource(header.iconRes);
            if (header.title != null) holder.title.setText(header.title);
            if (header.summary != null) holder.summary.setText(header.summary);
            if (header.icon == null) {
                holder.icon.setImageDrawable(null);
                holder.icon.setImageResource(header.iconRes);
            } else {
                holder.icon.setImageResource(0);
                holder.icon.setImageDrawable(header.icon);
            }
            holder.title.setText(header.title);
            if (TextUtils.isEmpty(header.summary)) {
                holder.summary.setVisibility(View.GONE);
            } else {
                holder.summary.setVisibility(View.VISIBLE);
                holder.summary.setText(header.summary);
            }

            return view;
        }
@@ -247,38 +255,38 @@ public abstract class PreferenceActivity extends ListActivity implements
         * Title of the header that is shown to the user.
         * @attr ref android.R.styleable#PreferenceHeader_title
         */
        CharSequence title;
        public CharSequence title;

        /**
         * Optional summary describing what this header controls.
         * @attr ref android.R.styleable#PreferenceHeader_summary
         */
        CharSequence summary;
        public CharSequence summary;

        /**
         * Optional icon resource to show for this header.
         * @attr ref android.R.styleable#PreferenceHeader_icon
         */
        int iconRes;
        public int iconRes;

        /**
         * Optional icon drawable to show for this header.  (If this is non-null,
         * the iconRes will be ignored.)
         */
        Drawable icon;
        public Drawable icon;

        /**
         * Full class name of the fragment to display when this header is
         * selected.
         * @attr ref android.R.styleable#PreferenceHeader_fragment
         */
        String fragment;
        public String fragment;

        /**
         * Optional arguments to supply to the fragment when it is
         * instantiated.
         */
        Bundle fragmentArguments;
        public Bundle fragmentArguments;
    }

    @Override