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

Commit aa45b424 authored by tmfang's avatar tmfang
Browse files

FooterPreference directs summary to title of preference

To compatible with preference controller design,
we override implementation of setSummary() which
directs summary to title of preference.

So, footer preference can be simply created in xml
and controlled by BasePreferenceController.

Test: visual, robotest
Bug: 124129485
Change-Id: I453ffc35761ecf24f2ac1415e0d674ac73c9c475
parent 2758853c
Loading
Loading
Loading
Loading
+19 −1
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.settingslib.widget;

import android.content.Context;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.util.AttributeSet;
import android.widget.TextView;
@@ -55,9 +56,26 @@ public class FooterPreference extends Preference {
        title.setLongClickable(false);
    }

    @Override
    public void setSummary(CharSequence summary) {
        setTitle(summary);
    }

    @Override
    public void setSummary(int summaryResId) {
        setTitle(summaryResId);
    }

    @Override
    public CharSequence getSummary() {
        return getTitle();
    }

    private void init() {
        setIcon(R.drawable.ic_info_outline_24);
        setKey(KEY_FOOTER);
        setOrder(ORDER_FOOTER);
        if (TextUtils.isEmpty(getKey())) {
            setKey(KEY_FOOTER);
        }
    }
}
+11 −10
Original line number Diff line number Diff line
@@ -37,28 +37,29 @@ import org.robolectric.RuntimeEnvironment;
public class FooterPreferenceTest {

    private Context mContext;
    private FooterPreference mFooterPreference;

    @Before
    public void setUp() {
        mContext = RuntimeEnvironment.application;
    }

    @Test
    public void createNewPreference_shouldSetKeyAndOrder() {
        final FooterPreference preference = new FooterPreference(mContext);

        assertThat(preference.getKey()).isEqualTo(FooterPreference.KEY_FOOTER);
        assertThat(preference.getOrder()).isEqualTo(FooterPreference.ORDER_FOOTER);
        mFooterPreference = new FooterPreference(mContext);
    }

    @Test
    public void bindPreference_shouldLinkifyContent() {
        final FooterPreference preference = new FooterPreference(mContext);
        final PreferenceViewHolder holder = PreferenceViewHolder.createInstanceForTests(
                LayoutInflater.from(mContext).inflate(R.layout.preference_footer, null));

        preference.onBindViewHolder(holder);
        mFooterPreference.onBindViewHolder(holder);

        assertThat(((TextView) holder.findViewById(android.R.id.title)).getMovementMethod())
                .isInstanceOf(LinkMovementMethod.class);
    }

    @Test
    public void setSummary_summarySet_shouldSetAsTitle() {
        mFooterPreference.setSummary("summary");

        assertThat(mFooterPreference.getTitle()).isEqualTo("summary");
    }
}