Improve volume slider
In the Settings, the Preference#onBindViewHolder will be invoked 3 times when a preference is getting highlighted. This caused that a disabled volume slider becomes enabled after getting highlighted. This change is to optimize the init method of VolumeSeekbarPreference to speed up the initial process and fix the unexpected behavior. Bug: 275352565 Test: manual test and robotest pass Change-Id: I77f28386f6d6e4a45297f1ca7bcbaf16ed6136a4
This commit is contained in:
@@ -131,6 +131,11 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
||||
|
||||
protected void init() {
|
||||
if (mSeekBar == null) return;
|
||||
// It's unnecessary to set up relevant volumizer configuration if preference is disabled.
|
||||
if (!isEnabled()) {
|
||||
mSeekBar.setEnabled(false);
|
||||
return;
|
||||
}
|
||||
final SeekBarVolumizer.Callback sbvc = new SeekBarVolumizer.Callback() {
|
||||
@Override
|
||||
public void onSampleStarting(SeekBarVolumizer sbv) {
|
||||
@@ -179,10 +184,6 @@ public class VolumeSeekBarPreference extends SeekBarPreference {
|
||||
if (mListener != null) {
|
||||
mListener.onUpdateMuteState();
|
||||
}
|
||||
if (!isEnabled()) {
|
||||
mSeekBar.setEnabled(false);
|
||||
mVolumizer.stop();
|
||||
}
|
||||
}
|
||||
|
||||
protected void updateIconView() {
|
||||
|
@@ -81,6 +81,7 @@ public class VolumeSeekBarPreferenceTest {
|
||||
|
||||
@Test
|
||||
public void init_listenerIsCalled() {
|
||||
when(mPreference.isEnabled()).thenReturn(true);
|
||||
doCallRealMethod().when(mPreference).setListener(mListener);
|
||||
doCallRealMethod().when(mPreference).init();
|
||||
|
||||
@@ -92,6 +93,18 @@ public class VolumeSeekBarPreferenceTest {
|
||||
|
||||
@Test
|
||||
public void init_listenerNotSet_noException() {
|
||||
when(mPreference.isEnabled()).thenReturn(true);
|
||||
doCallRealMethod().when(mPreference).init();
|
||||
|
||||
mPreference.init();
|
||||
|
||||
verify(mPreference, never()).updateContentDescription(CONTENT_DESCRIPTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void init_preferenceIsDisabled_shouldNotInvokeListener() {
|
||||
when(mPreference.isEnabled()).thenReturn(false);
|
||||
doCallRealMethod().when(mPreference).setListener(mListener);
|
||||
doCallRealMethod().when(mPreference).init();
|
||||
|
||||
mPreference.init();
|
||||
|
Reference in New Issue
Block a user