Add a new method to set state description
- This CL add a new method setSeekBarStateDescription() to set
the state of seek bar. Because in some case the description of
seek bar is not align progress of seek bar.
- Add test case
Bug: 157629483
Test: make -j42 RunSettingsRoboTests
Change-Id: I432e6f9deef59756b0a41244d50aaada1ddac6a9
diff --git a/src/com/android/settings/widget/SeekBarPreference.java b/src/com/android/settings/widget/SeekBarPreference.java
index bdd1ba9..ac28382 100644
--- a/src/com/android/settings/widget/SeekBarPreference.java
+++ b/src/com/android/settings/widget/SeekBarPreference.java
@@ -51,6 +51,7 @@
private boolean mShouldBlink;
private int mAccessibilityRangeInfoType = AccessibilityNodeInfo.RangeInfo.RANGE_TYPE_INT;
private CharSequence mSeekBarContentDescription;
+ private CharSequence mSeekBarStateDescription;
public SeekBarPreference(
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
@@ -124,6 +125,9 @@
} else if (!TextUtils.isEmpty(title)) {
mSeekBar.setContentDescription(title);
}
+ if (!TextUtils.isEmpty(mSeekBarStateDescription)) {
+ mSeekBar.setStateDescription(mSeekBarStateDescription);
+ }
if (mSeekBar instanceof DefaultIndicatorSeekBar) {
((DefaultIndicatorSeekBar) mSeekBar).setDefaultProgress(mDefaultProgress);
}
@@ -304,6 +308,18 @@
}
}
+ /**
+ * Specify the state description for this seek bar represents.
+ *
+ * @param stateDescription the state description of seek bar
+ */
+ public void setSeekBarStateDescription(CharSequence stateDescription) {
+ mSeekBarStateDescription = stateDescription;
+ if (mSeekBar != null) {
+ mSeekBar.setStateDescription(stateDescription);
+ }
+ }
+
@Override
protected Parcelable onSaveInstanceState() {
/*
diff --git a/tests/robotests/src/com/android/settings/widget/SeekBarPreferenceTest.java b/tests/robotests/src/com/android/settings/widget/SeekBarPreferenceTest.java
index f7dea22..42ed074 100644
--- a/tests/robotests/src/com/android/settings/widget/SeekBarPreferenceTest.java
+++ b/tests/robotests/src/com/android/settings/widget/SeekBarPreferenceTest.java
@@ -19,6 +19,7 @@
import static com.google.common.truth.Truth.assertThat;
import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import android.content.Context;
@@ -110,6 +111,13 @@
assertThat(seekBarPreference.isSelectable()).isTrue();
}
+ @Test
+ public void testSetSeekBarStateDescription() {
+ mSeekBarPreference.setSeekBarStateDescription("test");
+
+ verify(mSeekBarPreference).setSeekBarStateDescription("test");
+ }
+
public static class TestFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {