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

Commit bf200804 authored by Yvonne Jiang's avatar Yvonne Jiang
Browse files

[Settingslib] Add support to set a content description for SettingsSpinnerPreference.

Adding a method to set a custom content description of the Spinner.

Bug: 422867769
Flag: EXEMPT no-op until new method is used
Test: manual using Talkback
Change-Id: I00b14e9f4ac71f39305d6a86c5a6291deebdf12d
parent 55acb30c
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.settingslib.widget;

import android.content.Context;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.view.accessibility.AccessibilityEvent;
@@ -44,6 +45,7 @@ public class SettingsSpinnerPreference extends Preference
    private int mPosition;
    private boolean mShouldPerformClick;
    private int mOffset;
    private CharSequence mContentDescription;

    /**
     * Perform inflation from XML and apply a class-specific base style.
@@ -148,6 +150,12 @@ public class SettingsSpinnerPreference extends Preference
        notifyChanged();
    }

    /** Sets the content description of the spinner. */
    public void setContentDescription(@Nullable CharSequence contentDescription) {
        mContentDescription = contentDescription;
        notifyChanged();
    }

    @Override
    public void onBindViewHolder(PreferenceViewHolder holder) {
        super.onBindViewHolder(holder);
@@ -180,6 +188,9 @@ public class SettingsSpinnerPreference extends Preference
            // To show dropdown view.
            spinner.performClick();
        }
        if (!TextUtils.isEmpty(mContentDescription)) {
            spinner.setContentDescription(mContentDescription);
        }
    }

    private final AdapterView.OnItemSelectedListener mOnSelectedListener =