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
This commit is contained in:
@@ -51,6 +51,7 @@ public class SeekBarPreference extends RestrictedPreference
|
|||||||
private boolean mShouldBlink;
|
private boolean mShouldBlink;
|
||||||
private int mAccessibilityRangeInfoType = AccessibilityNodeInfo.RangeInfo.RANGE_TYPE_INT;
|
private int mAccessibilityRangeInfoType = AccessibilityNodeInfo.RangeInfo.RANGE_TYPE_INT;
|
||||||
private CharSequence mSeekBarContentDescription;
|
private CharSequence mSeekBarContentDescription;
|
||||||
|
private CharSequence mSeekBarStateDescription;
|
||||||
|
|
||||||
public SeekBarPreference(
|
public SeekBarPreference(
|
||||||
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
|
||||||
@@ -124,6 +125,9 @@ public class SeekBarPreference extends RestrictedPreference
|
|||||||
} else if (!TextUtils.isEmpty(title)) {
|
} else if (!TextUtils.isEmpty(title)) {
|
||||||
mSeekBar.setContentDescription(title);
|
mSeekBar.setContentDescription(title);
|
||||||
}
|
}
|
||||||
|
if (!TextUtils.isEmpty(mSeekBarStateDescription)) {
|
||||||
|
mSeekBar.setStateDescription(mSeekBarStateDescription);
|
||||||
|
}
|
||||||
if (mSeekBar instanceof DefaultIndicatorSeekBar) {
|
if (mSeekBar instanceof DefaultIndicatorSeekBar) {
|
||||||
((DefaultIndicatorSeekBar) mSeekBar).setDefaultProgress(mDefaultProgress);
|
((DefaultIndicatorSeekBar) mSeekBar).setDefaultProgress(mDefaultProgress);
|
||||||
}
|
}
|
||||||
@@ -304,6 +308,18 @@ public class SeekBarPreference extends RestrictedPreference
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
@Override
|
||||||
protected Parcelable onSaveInstanceState() {
|
protected Parcelable onSaveInstanceState() {
|
||||||
/*
|
/*
|
||||||
|
@@ -19,6 +19,7 @@ package com.android.settings.widget;
|
|||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -110,6 +111,13 @@ public class SeekBarPreferenceTest {
|
|||||||
assertThat(seekBarPreference.isSelectable()).isTrue();
|
assertThat(seekBarPreference.isSelectable()).isTrue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetSeekBarStateDescription() {
|
||||||
|
mSeekBarPreference.setSeekBarStateDescription("test");
|
||||||
|
|
||||||
|
verify(mSeekBarPreference).setSeekBarStateDescription("test");
|
||||||
|
}
|
||||||
|
|
||||||
public static class TestFragment extends PreferenceFragmentCompat {
|
public static class TestFragment extends PreferenceFragmentCompat {
|
||||||
@Override
|
@Override
|
||||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||||
|
Reference in New Issue
Block a user