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

Commit de81197c authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Migrate SeekBarPreference to SliderPreference for haptics" into main

parents 7cbc882f 9e74fdbf
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -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"
@@ -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"
@@ -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"
+4 −3
Original line number Diff line number Diff line
@@ -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
@@ -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
+3 −0
Original line number Diff line number Diff line
@@ -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());
        }
    }

+12 −12
Original line number Diff line number Diff line
@@ -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;
@@ -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() {
@@ -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);
@@ -91,7 +91,7 @@ public class AlarmVibrationIntensityPreferenceControllerTest {

        mController.updateState(mPreference);

        assertThat(mPreference.getProgress()).isEqualTo(
        assertThat(mPreference.getValue()).isEqualTo(
                mVibrator.getDefaultVibrationIntensity(VibrationAttributes.USAGE_ALARM));
    }

@@ -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();
    }

@@ -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);
+16 −16
Original line number Diff line number Diff line
@@ -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;
@@ -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() {
@@ -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);
@@ -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));
    }

@@ -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();
    }

@@ -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