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

Commit 53c2cf79 authored by Fabrice Di Meglio's avatar Fabrice Di Meglio
Browse files

Add support for saving and using the Preference's key value

- make public and hide the PreferenceGroupAdapter class
- add setActivated(int position) to be able to set the activated item
- udpate getView(int position, View convertView, ViewGroup parent) to set/unset
the activated item

Change-Id: I8a653ad6541bb6b7a043ba7c3d95e5ecad924a0d
parent 19de4fff
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -45,8 +45,11 @@ import android.widget.ListView;
 * adapter, use {@link PreferenceCategoryAdapter} instead.
 * 
 * @see PreferenceCategoryAdapter
 *
 * @hide
 */
class PreferenceGroupAdapter extends BaseAdapter implements OnPreferenceChangeInternalListener {
public class PreferenceGroupAdapter extends BaseAdapter
        implements OnPreferenceChangeInternalListener {
    
    private static final String TAG = "PreferenceGroupAdapter";

@@ -88,6 +91,8 @@ class PreferenceGroupAdapter extends BaseAdapter implements OnPreferenceChangeIn
        }
    };

    private int mActivatedPosition = -1;

    private static class PreferenceLayout implements Comparable<PreferenceLayout> {
        private int resId;
        private int widgetResId;
@@ -207,6 +212,10 @@ class PreferenceGroupAdapter extends BaseAdapter implements OnPreferenceChangeIn
        return this.getItem(position).getId();
    }

    public void setActivated(int position) {
        mActivatedPosition = position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        final Preference preference = this.getItem(position);
        // Build a PreferenceLayout to compare with known ones that are cacheable.
@@ -217,8 +226,9 @@ class PreferenceGroupAdapter extends BaseAdapter implements OnPreferenceChangeIn
        if (Collections.binarySearch(mPreferenceLayouts, mTempPreferenceLayout) < 0) {
            convertView = null;
        }

        return preference.getView(convertView, parent);
        View result = preference.getView(convertView, parent);
        result.setActivated(position == mActivatedPosition);
        return result;
    }

    @Override
+2 −1
Original line number Diff line number Diff line
@@ -23,7 +23,8 @@
    android:minHeight="?android:attr/listPreferredItemHeight"
    android:gravity="center_vertical"
    android:paddingStart="@dimen/preference_item_padding_side"
    android:paddingEnd="?android:attr/scrollbarSize">
    android:paddingEnd="?android:attr/scrollbarSize"
    android:background="?android:attr/activatedBackgroundIndicator">

    <LinearLayout
        android:layout_width="wrap_content"