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

Commit 33674e34 authored by Jacky Wang's avatar Jacky Wang
Browse files

Revert "Trigger haptics preview after setting has been applied"

This reverts commit 361804bd.

NO_IFTTT=Catalyst only

Bug: 410756621
Test: N/A
Flag: EXEMPT rollback
Change-Id: I480995188e8d6ab248a44a73dc0c07df503c3b6d
parent b3d75a2e
Loading
Loading
Loading
Loading
+4 −13
Original line number Diff line number Diff line
@@ -27,8 +27,8 @@ import kotlin.math.min

/** SettingsStore for vibration intensity preferences with custom default value. */
class VibrationIntensitySettingsStore(
    private val context: Context,
    @Usage private val vibrationUsage: Int,
    context: Context,
    @Usage vibrationUsage: Int,
    override val keyValueStoreDelegate: KeyValueStore = SettingsSystemStore.get(context),
    private val defaultIntensity: Int = context.getDefaultVibrationIntensity(vibrationUsage),
    private val supportedIntensityLevels: Int = context.getSupportedVibrationIntensityLevels(),
@@ -49,17 +49,8 @@ class VibrationIntensitySettingsStore(
            intensityToValue(valueType, Vibrator.VIBRATION_INTENSITY_OFF)
        }

    override fun <T : Any> setValue(key: String, valueType: Class<T>, value: T?) {
        val intensityValue: Int? = value?.let { nonNullValue ->
            valueToIntensity(valueType, nonNullValue)
        }
        keyValueStoreDelegate.setInt(key, intensityValue)
        if (isPreferenceEnabled() &&
                intensityValue != null &&
                intensityValue != Vibrator.VIBRATION_INTENSITY_OFF) {
            context.playVibrationSettingsPreview(vibrationUsage)
        }
    }
    override fun <T : Any> setValue(key: String, valueType: Class<T>, value: T?) =
        keyValueStoreDelegate.setInt(key, value?.let { valueToIntensity(valueType, it) })

    @Suppress("UNCHECKED_CAST")
    private fun <T: Any> intensityToValue(valueType: Class<T>, intensity: Int): T? =
+10 −1
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.os.Vibrator
import androidx.annotation.CallSuper
import androidx.annotation.StringRes
import androidx.preference.Preference
import androidx.preference.Preference.OnPreferenceChangeListener
import com.android.settingslib.datastore.KeyValueStore
import com.android.settingslib.metadata.IntRangeValuePreference
import com.android.settingslib.metadata.PreferenceMetadata
@@ -46,7 +47,7 @@ open class VibrationIntensitySliderPreference(
    @Usage val vibrationUsage: Int,
    @StringRes override val title: Int = 0,
    @StringRes override val summary: Int = 0,
) : IntRangeValuePreference, SliderPreferenceBinding {
) : IntRangeValuePreference, SliderPreferenceBinding, OnPreferenceChangeListener {

    private var storage: VibrationIntensitySettingsStore? = null

@@ -70,6 +71,7 @@ open class VibrationIntensitySliderPreference(
    @CallSuper
    override fun bind(preference: Preference, metadata: PreferenceMetadata) {
        super.bind(preference, metadata)
        preference.onPreferenceChangeListener = this
        (preference as SliderPreference).apply {
            // 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.
@@ -77,6 +79,13 @@ open class VibrationIntensitySliderPreference(
        }
    }

    override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
        if (newValue as Int != Vibrator.VIBRATION_INTENSITY_OFF) {
            preference.context.playVibrationSettingsPreview(vibrationUsage)
        }
        return true
    }

    @CallSuper
    override fun isEnabled(context: Context) = storage?.isPreferenceEnabled() ?: true
}
+15 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.os.VibrationAttributes.Usage
import androidx.annotation.CallSuper
import androidx.annotation.StringRes
import androidx.preference.Preference
import androidx.preference.Preference.OnPreferenceChangeListener
import com.android.settingslib.datastore.KeyValueStore
import com.android.settingslib.metadata.PreferenceMetadata
import com.android.settingslib.metadata.SwitchPreference
@@ -44,6 +45,7 @@ open class VibrationIntensitySwitchPreference(
    @StringRes title: Int = 0,
    @StringRes summary: Int = 0,
) : SwitchPreference(key, title, summary),
    OnPreferenceChangeListener,
    SwitchPreferenceBinding {

    private var storage: VibrationIntensitySettingsStore? = null
@@ -57,6 +59,19 @@ open class VibrationIntensitySwitchPreference(

    override fun dependencies(context: Context) = arrayOf(VibrationMainSwitchPreference.KEY)

    @CallSuper
    override fun bind(preference: Preference, metadata: PreferenceMetadata) {
        super.bind(preference, metadata)
        preference.onPreferenceChangeListener = this
    }

    override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
        if (newValue as Boolean) {
            preference.context.playVibrationSettingsPreview(vibrationUsage)
        }
        return true
    }

    @CallSuper
    override fun isEnabled(context: Context) = storage?.isPreferenceEnabled() ?: true
}
+16 −9
Original line number Diff line number Diff line
@@ -39,7 +39,8 @@ import com.android.settingslib.widget.MainSwitchPreferenceBinding
class VibrationMainSwitchPreference :
    BooleanValuePreference,
    MainSwitchPreferenceBinding,
    PreferenceActionMetricsProvider {
    PreferenceActionMetricsProvider,
    Preference.OnPreferenceChangeListener {

    override val key
        get() = KEY
@@ -70,6 +71,19 @@ class VibrationMainSwitchPreference :
    override val sensitivityLevel: Int
        get() = SensitivityLevel.NO_SENSITIVITY

    override fun bind(preference: Preference, metadata: PreferenceMetadata) {
        super.bind(preference, metadata)
        preference.onPreferenceChangeListener = this
    }

    override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
        if (newValue as Boolean) {
            // Play a haptic as preview for the main toggle only when touch feedback is enabled.
            preference.context.playVibrationSettingsPreview(VibrationAttributes.USAGE_TOUCH)
        }
        return true
    }

    companion object {
        const val KEY = Settings.System.VIBRATE_ON
    }
@@ -77,20 +91,13 @@ class VibrationMainSwitchPreference :

/** Provides SettingsStore for vibration main switch with custom default value. */
class VibrationMainSwitchStore(
    private val context: Context,
    context: Context,
    override val keyValueStoreDelegate: KeyValueStore = SettingsSystemStore.get(context),
) : KeyValueStoreDelegate {

    @Suppress("UNCHECKED_CAST")
    override fun <T : Any> getDefaultValue(key: String, valueType: Class<T>) = DEFAULT_VALUE as T

    override fun <T : Any> setValue(key: String, valueType: Class<T>, value: T?) {
        keyValueStoreDelegate.setValue(key, valueType, value)
        if (value == true) {
            context.playVibrationSettingsPreview(VibrationAttributes.USAGE_TOUCH)
        }
    }

    companion object {
        private const val DEFAULT_VALUE = true
    }