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

Commit b5a7b757 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Support setting a specific content description for the widget in...

Merge "Support setting a specific content description for the widget in SelectorWithWidgetPreference" into main
parents 417e7e03 6ac7259f
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ public class SelectorWithWidgetPreference extends CheckBoxPreference {

    private View mExtraWidgetContainer;
    private ImageView mExtraWidget;
    @Nullable private String mExtraWidgetContentDescription;
    private boolean mIsCheckBox = false;  // whether to display this button as a checkbox

    private View.OnClickListener mExtraWidgetOnClickListener;
@@ -173,6 +174,12 @@ public class SelectorWithWidgetPreference extends CheckBoxPreference {

        setExtraWidgetOnClickListener(mExtraWidgetOnClickListener);

        if (mExtraWidget != null) {
            mExtraWidget.setContentDescription(mExtraWidgetContentDescription != null
                    ? mExtraWidgetContentDescription
                    : getContext().getString(R.string.settings_label));
        }

        if (Flags.allowSetTitleMaxLines()) {
            TextView title = (TextView) holder.findViewById(android.R.id.title);
            title.setMaxLines(mTitleMaxLines);
@@ -209,6 +216,17 @@ public class SelectorWithWidgetPreference extends CheckBoxPreference {
                ? View.VISIBLE : View.GONE);
    }

    /**
     * Sets the content description of the extra widget. If {@code null}, a default content
     * description will be used ("Settings").
     */
    public void setExtraWidgetContentDescription(@Nullable String contentDescription) {
        if (!TextUtils.equals(mExtraWidgetContentDescription, contentDescription)) {
            mExtraWidgetContentDescription = contentDescription;
            notifyChanged();
        }
    }

    /**
     * Returns whether this preference is a checkbox.
     */
+20 −0
Original line number Diff line number Diff line
@@ -183,6 +183,26 @@ public class SelectorWithWidgetPreferenceTest {
        assertThat(title.getMaxLines()).isEqualTo(titleMaxLines);
    }

    @Test
    public void onBindViewHolder_appliesWidgetContentDescription() {
        mPreference = new SelectorWithWidgetPreference(mContext);
        View view = LayoutInflater.from(mContext)
                .inflate(mPreference.getLayoutResource(), /* root= */ null);
        PreferenceViewHolder preferenceViewHolder =
                PreferenceViewHolder.createInstanceForTests(view);

        mPreference.setExtraWidgetContentDescription("this is clearer");
        mPreference.onBindViewHolder(preferenceViewHolder);

        View widget = preferenceViewHolder.findViewById(R.id.selector_extra_widget);
        assertThat(widget.getContentDescription().toString()).isEqualTo("this is clearer");

        mPreference.setExtraWidgetContentDescription(null);
        mPreference.onBindViewHolder(preferenceViewHolder);

        assertThat(widget.getContentDescription().toString()).isEqualTo("Settings");
    }

    @Test
    public void nullSummary_containerShouldBeGone() {
        mPreference.setSummary(null);