Loading res/xml/accessibility_vibration_intensity_settings.xml +5 −5 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ android:key="vibration_intensity_category_call" android:title="@string/accessibility_call_vibration_category_title"> <com.android.settings.widget.SeekBarPreference <com.android.settingslib.widget.SliderPreference android:key="vibration_intensity_preference_ring" android:title="@string/accessibility_ring_vibration_title" app:keywords="@string/keywords_ring_vibration" Loading @@ -47,13 +47,13 @@ android:key="vibration_intensity_category_notification_alarm" android:title="@string/accessibility_notification_alarm_vibration_category_title"> <com.android.settings.widget.SeekBarPreference <com.android.settingslib.widget.SliderPreference android:key="vibration_intensity_preference_notification" android:title="@string/accessibility_notification_vibration_title" app:keywords="@string/keywords_notification_vibration" app:controller="com.android.settings.accessibility.NotificationVibrationIntensityPreferenceController" /> <com.android.settings.widget.SeekBarPreference <com.android.settingslib.widget.SliderPreference android:key="vibration_intensity_preference_alarm" android:title="@string/accessibility_alarm_vibration_title" app:keywords="@string/keywords_alarm_vibration" Loading @@ -65,13 +65,13 @@ android:key="vibration_intensity_category_haptics" android:title="@string/accessibility_interactive_haptics_category_title"> <com.android.settings.widget.SeekBarPreference <com.android.settingslib.widget.SliderPreference android:key="vibration_intensity_preference_touch" android:title="@string/accessibility_touch_vibration_title" app:keywords="@string/keywords_touch_vibration" app:controller="com.android.settings.accessibility.HapticFeedbackIntensityPreferenceController" /> <com.android.settings.widget.SeekBarPreference <com.android.settingslib.widget.SliderPreference android:key="vibration_intensity_preference_media" android:title="@string/accessibility_media_vibration_title" app:keywords="@string/keywords_media_vibration" Loading src/com/android/settings/accessibility/VibrationIntensityPreferenceController.java +4 −3 Original line number Diff line number Diff line Loading @@ -24,10 +24,10 @@ import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.core.SliderPreferenceController; import com.android.settings.widget.SeekBarPreference; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStop; import com.android.settingslib.widget.SliderPreference; /** * Abstract preference controller for a vibration intensity setting, that displays multiple Loading Loading @@ -69,15 +69,16 @@ public abstract class VibrationIntensityPreferenceController extends SliderPrefe @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); final SeekBarPreference preference = screen.findPreference(getPreferenceKey()); final SliderPreference preference = screen.findPreference(getPreferenceKey()); mSettingsContentObserver.onDisplayPreference(this, preference); preference.setEnabled(mPreferenceConfig.isPreferenceEnabled()); preference.setSummaryProvider(unused -> mPreferenceConfig.getSummary()); preference.setMin(getMin()); preference.setMax(getMax()); preference.setSliderIncrement(1); // Discrete slider // Haptics previews played by the Settings app don't bypass user settings to be played. // The sliders continuously updates the intensity value so the previews can apply them. preference.setContinuousUpdates(true); preference.setUpdatesContinuously(true); } @Override Loading src/com/android/settings/core/SliderPreferenceController.java +3 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,9 @@ public abstract class SliderPreferenceController extends BasePreferenceControlle } else if (preference instanceof androidx.preference.SeekBarPreference) { ((androidx.preference.SeekBarPreference) preference) .setValue(getSliderPosition()); } else if (preference instanceof com.android.settingslib.widget.SliderPreference) { ((com.android.settingslib.widget.SliderPreference) preference) .setValue(getSliderPosition()); } } Loading tests/robotests/src/com/android/settings/accessibility/AlarmVibrationIntensityPreferenceControllerTest.java +12 −12 Original line number Diff line number Diff line Loading @@ -32,8 +32,8 @@ import androidx.test.core.app.ApplicationProvider; import com.android.settings.core.BasePreferenceController; import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor; import com.android.settings.widget.SeekBarPreference; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.widget.SliderPreference; import org.junit.Before; import org.junit.Test; Loading @@ -56,7 +56,7 @@ public class AlarmVibrationIntensityPreferenceControllerTest { private Context mContext; private Vibrator mVibrator; private AlarmVibrationIntensityPreferenceController mController; private SeekBarPreference mPreference; private SliderPreference mPreference; @Before public void setUp() { Loading @@ -69,7 +69,7 @@ public class AlarmVibrationIntensityPreferenceControllerTest { mController = new AlarmVibrationIntensityPreferenceController(mContext, PREFERENCE_KEY, Vibrator.VIBRATION_INTENSITY_HIGH); mLifecycle.addObserver(mController); mPreference = new SeekBarPreference(mContext); mPreference = new SliderPreference(mContext); mPreference.setSummary("Test summary"); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); mController.displayPreference(mScreen); Loading @@ -91,7 +91,7 @@ public class AlarmVibrationIntensityPreferenceControllerTest { mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo( assertThat(mPreference.getValue()).isEqualTo( mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_ALARM)); } Loading @@ -101,17 +101,17 @@ public class AlarmVibrationIntensityPreferenceControllerTest { when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.isEnabled()).isTrue(); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_SILENT); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.isEnabled()).isTrue(); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.isEnabled()).isTrue(); } Loading @@ -119,25 +119,25 @@ public class AlarmVibrationIntensityPreferenceControllerTest { public void updateState_shouldDisplayIntensityInSliderPosition() { updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH); updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_MEDIUM); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); } @Test public void setProgress_updatesIntensitySetting() throws Exception { public void setSliderPosition_updatesIntensitySetting() throws Exception { mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(readSetting(Settings.System.ALARM_VIBRATION_INTENSITY)) .isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); Loading tests/robotests/src/com/android/settings/accessibility/HapticFeedbackIntensityPreferenceControllerTest.java +16 −16 Original line number Diff line number Diff line Loading @@ -32,8 +32,8 @@ import androidx.test.core.app.ApplicationProvider; import com.android.settings.core.BasePreferenceController; import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor; import com.android.settings.widget.SeekBarPreference; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.widget.SliderPreference; import org.junit.Before; import org.junit.Test; Loading @@ -58,7 +58,7 @@ public class HapticFeedbackIntensityPreferenceControllerTest { private Context mContext; private Vibrator mVibrator; private HapticFeedbackIntensityPreferenceController mController; private SeekBarPreference mPreference; private SliderPreference mPreference; @Before public void setUp() { Loading @@ -71,7 +71,7 @@ public class HapticFeedbackIntensityPreferenceControllerTest { mController = new HapticFeedbackIntensityPreferenceController(mContext, PREFERENCE_KEY, Vibrator.VIBRATION_INTENSITY_HIGH); mLifecycle.addObserver(mController); mPreference = new SeekBarPreference(mContext); mPreference = new SliderPreference(mContext); mPreference.setSummary("Test summary"); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); mController.displayPreference(mScreen); Loading @@ -91,7 +91,7 @@ public class HapticFeedbackIntensityPreferenceControllerTest { Settings.System.putString(mContext.getContentResolver(), Settings.System.HAPTIC_FEEDBACK_INTENSITY, /* value= */ null); mController.updateState(mPreference); assertThat(mPreference.getProgress()) assertThat(mPreference.getValue()) .isEqualTo(mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_TOUCH)); } Loading @@ -101,17 +101,17 @@ public class HapticFeedbackIntensityPreferenceControllerTest { when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.isEnabled()).isTrue(); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_SILENT); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.isEnabled()).isTrue(); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.isEnabled()).isTrue(); } Loading @@ -121,44 +121,44 @@ public class HapticFeedbackIntensityPreferenceControllerTest { updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_MEDIUM); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); } @Test public void updateState_shouldDisplayIntensityInSliderPosition() { updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH); updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_MEDIUM); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); } @Test public void setProgress_updatesIntensityAndDependentSettings() throws Exception { public void setSliderPosition_updatesIntensityAndDependentSettings() throws Exception { mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY)) .isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); Loading Loading
res/xml/accessibility_vibration_intensity_settings.xml +5 −5 Original line number Diff line number Diff line Loading @@ -29,7 +29,7 @@ android:key="vibration_intensity_category_call" android:title="@string/accessibility_call_vibration_category_title"> <com.android.settings.widget.SeekBarPreference <com.android.settingslib.widget.SliderPreference android:key="vibration_intensity_preference_ring" android:title="@string/accessibility_ring_vibration_title" app:keywords="@string/keywords_ring_vibration" Loading @@ -47,13 +47,13 @@ android:key="vibration_intensity_category_notification_alarm" android:title="@string/accessibility_notification_alarm_vibration_category_title"> <com.android.settings.widget.SeekBarPreference <com.android.settingslib.widget.SliderPreference android:key="vibration_intensity_preference_notification" android:title="@string/accessibility_notification_vibration_title" app:keywords="@string/keywords_notification_vibration" app:controller="com.android.settings.accessibility.NotificationVibrationIntensityPreferenceController" /> <com.android.settings.widget.SeekBarPreference <com.android.settingslib.widget.SliderPreference android:key="vibration_intensity_preference_alarm" android:title="@string/accessibility_alarm_vibration_title" app:keywords="@string/keywords_alarm_vibration" Loading @@ -65,13 +65,13 @@ android:key="vibration_intensity_category_haptics" android:title="@string/accessibility_interactive_haptics_category_title"> <com.android.settings.widget.SeekBarPreference <com.android.settingslib.widget.SliderPreference android:key="vibration_intensity_preference_touch" android:title="@string/accessibility_touch_vibration_title" app:keywords="@string/keywords_touch_vibration" app:controller="com.android.settings.accessibility.HapticFeedbackIntensityPreferenceController" /> <com.android.settings.widget.SeekBarPreference <com.android.settingslib.widget.SliderPreference android:key="vibration_intensity_preference_media" android:title="@string/accessibility_media_vibration_title" app:keywords="@string/keywords_media_vibration" Loading
src/com/android/settings/accessibility/VibrationIntensityPreferenceController.java +4 −3 Original line number Diff line number Diff line Loading @@ -24,10 +24,10 @@ import androidx.preference.PreferenceScreen; import com.android.settings.R; import com.android.settings.core.SliderPreferenceController; import com.android.settings.widget.SeekBarPreference; import com.android.settingslib.core.lifecycle.LifecycleObserver; import com.android.settingslib.core.lifecycle.events.OnStart; import com.android.settingslib.core.lifecycle.events.OnStop; import com.android.settingslib.widget.SliderPreference; /** * Abstract preference controller for a vibration intensity setting, that displays multiple Loading Loading @@ -69,15 +69,16 @@ public abstract class VibrationIntensityPreferenceController extends SliderPrefe @Override public void displayPreference(PreferenceScreen screen) { super.displayPreference(screen); final SeekBarPreference preference = screen.findPreference(getPreferenceKey()); final SliderPreference preference = screen.findPreference(getPreferenceKey()); mSettingsContentObserver.onDisplayPreference(this, preference); preference.setEnabled(mPreferenceConfig.isPreferenceEnabled()); preference.setSummaryProvider(unused -> mPreferenceConfig.getSummary()); preference.setMin(getMin()); preference.setMax(getMax()); preference.setSliderIncrement(1); // Discrete slider // Haptics previews played by the Settings app don't bypass user settings to be played. // The sliders continuously updates the intensity value so the previews can apply them. preference.setContinuousUpdates(true); preference.setUpdatesContinuously(true); } @Override Loading
src/com/android/settings/core/SliderPreferenceController.java +3 −0 Original line number Diff line number Diff line Loading @@ -42,6 +42,9 @@ public abstract class SliderPreferenceController extends BasePreferenceControlle } else if (preference instanceof androidx.preference.SeekBarPreference) { ((androidx.preference.SeekBarPreference) preference) .setValue(getSliderPosition()); } else if (preference instanceof com.android.settingslib.widget.SliderPreference) { ((com.android.settingslib.widget.SliderPreference) preference) .setValue(getSliderPosition()); } } Loading
tests/robotests/src/com/android/settings/accessibility/AlarmVibrationIntensityPreferenceControllerTest.java +12 −12 Original line number Diff line number Diff line Loading @@ -32,8 +32,8 @@ import androidx.test.core.app.ApplicationProvider; import com.android.settings.core.BasePreferenceController; import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor; import com.android.settings.widget.SeekBarPreference; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.widget.SliderPreference; import org.junit.Before; import org.junit.Test; Loading @@ -56,7 +56,7 @@ public class AlarmVibrationIntensityPreferenceControllerTest { private Context mContext; private Vibrator mVibrator; private AlarmVibrationIntensityPreferenceController mController; private SeekBarPreference mPreference; private SliderPreference mPreference; @Before public void setUp() { Loading @@ -69,7 +69,7 @@ public class AlarmVibrationIntensityPreferenceControllerTest { mController = new AlarmVibrationIntensityPreferenceController(mContext, PREFERENCE_KEY, Vibrator.VIBRATION_INTENSITY_HIGH); mLifecycle.addObserver(mController); mPreference = new SeekBarPreference(mContext); mPreference = new SliderPreference(mContext); mPreference.setSummary("Test summary"); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); mController.displayPreference(mScreen); Loading @@ -91,7 +91,7 @@ public class AlarmVibrationIntensityPreferenceControllerTest { mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo( assertThat(mPreference.getValue()).isEqualTo( mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_ALARM)); } Loading @@ -101,17 +101,17 @@ public class AlarmVibrationIntensityPreferenceControllerTest { when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.isEnabled()).isTrue(); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_SILENT); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.isEnabled()).isTrue(); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.isEnabled()).isTrue(); } Loading @@ -119,25 +119,25 @@ public class AlarmVibrationIntensityPreferenceControllerTest { public void updateState_shouldDisplayIntensityInSliderPosition() { updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH); updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_MEDIUM); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); updateSetting(Settings.System.ALARM_VIBRATION_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); } @Test public void setProgress_updatesIntensitySetting() throws Exception { public void setSliderPosition_updatesIntensitySetting() throws Exception { mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(readSetting(Settings.System.ALARM_VIBRATION_INTENSITY)) .isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); Loading
tests/robotests/src/com/android/settings/accessibility/HapticFeedbackIntensityPreferenceControllerTest.java +16 −16 Original line number Diff line number Diff line Loading @@ -32,8 +32,8 @@ import androidx.test.core.app.ApplicationProvider; import com.android.settings.core.BasePreferenceController; import com.android.settings.testutils.shadow.ShadowInteractionJankMonitor; import com.android.settings.widget.SeekBarPreference; import com.android.settingslib.core.lifecycle.Lifecycle; import com.android.settingslib.widget.SliderPreference; import org.junit.Before; import org.junit.Test; Loading @@ -58,7 +58,7 @@ public class HapticFeedbackIntensityPreferenceControllerTest { private Context mContext; private Vibrator mVibrator; private HapticFeedbackIntensityPreferenceController mController; private SeekBarPreference mPreference; private SliderPreference mPreference; @Before public void setUp() { Loading @@ -71,7 +71,7 @@ public class HapticFeedbackIntensityPreferenceControllerTest { mController = new HapticFeedbackIntensityPreferenceController(mContext, PREFERENCE_KEY, Vibrator.VIBRATION_INTENSITY_HIGH); mLifecycle.addObserver(mController); mPreference = new SeekBarPreference(mContext); mPreference = new SliderPreference(mContext); mPreference.setSummary("Test summary"); when(mScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference); mController.displayPreference(mScreen); Loading @@ -91,7 +91,7 @@ public class HapticFeedbackIntensityPreferenceControllerTest { Settings.System.putString(mContext.getContentResolver(), Settings.System.HAPTIC_FEEDBACK_INTENSITY, /* value= */ null); mController.updateState(mPreference); assertThat(mPreference.getProgress()) assertThat(mPreference.getValue()) .isEqualTo(mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_TOUCH)); } Loading @@ -101,17 +101,17 @@ public class HapticFeedbackIntensityPreferenceControllerTest { when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_NORMAL); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.isEnabled()).isTrue(); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_SILENT); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.isEnabled()).isTrue(); when(mAudioManager.getRingerModeInternal()).thenReturn(AudioManager.RINGER_MODE_VIBRATE); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.isEnabled()).isTrue(); } Loading @@ -121,44 +121,44 @@ public class HapticFeedbackIntensityPreferenceControllerTest { updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_MEDIUM); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); } @Test public void updateState_shouldDisplayIntensityInSliderPosition() { updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_HIGH); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_HIGH); updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_MEDIUM); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_MEDIUM); updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_LOW); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_LOW); updateSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY, Vibrator.VIBRATION_INTENSITY_OFF); mController.updateState(mPreference); assertThat(mPreference.getProgress()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(mPreference.getValue()).isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); } @Test public void setProgress_updatesIntensityAndDependentSettings() throws Exception { public void setSliderPosition_updatesIntensityAndDependentSettings() throws Exception { mController.setSliderPosition(Vibrator.VIBRATION_INTENSITY_OFF); assertThat(readSetting(Settings.System.HAPTIC_FEEDBACK_INTENSITY)) .isEqualTo(Vibrator.VIBRATION_INTENSITY_OFF); Loading