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

Commit cac78b65 authored by Jacky Wang's avatar Jacky Wang
Browse files

[Catalyst] Haptic preview does not work

NO_IFTTT=Catalyst only

Bug: 410756621
Flag: EXEMPT bugfix
Test: manual
Change-Id: Idbde2473dfd4e69b6006d47f487e80b4c7736c51
parent 33674e34
Loading
Loading
Loading
Loading
+6 −5
Original line number Diff line number Diff line
@@ -65,7 +65,6 @@ open class VibrationIntensitySliderPreference(
        return storage!!
    }


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

    @CallSuper
@@ -80,13 +79,15 @@ open class VibrationIntensitySliderPreference(
    }

    override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
        if (newValue as Int != Vibrator.VIBRATION_INTENSITY_OFF) {
        val intensity = newValue as Int
        // must make new value effective before preview
        (preference as SliderPreference).value = intensity
        if (intensity != Vibrator.VIBRATION_INTENSITY_OFF) {
            preference.context.playVibrationSettingsPreview(vibrationUsage)
        }
        return true
        return false // value has been updated
    }

    @CallSuper
    override fun isEnabled(context: Context) = storage?.isPreferenceEnabled() ?: true
    @CallSuper override fun isEnabled(context: Context) = storage?.isPreferenceEnabled() != false
}
// LINT.ThenChange(VibrationIntensityPreferenceController.java)
+11 −8
Original line number Diff line number Diff line
@@ -20,7 +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 androidx.preference.TwoStatePreference
import com.android.settingslib.datastore.KeyValueStore
import com.android.settingslib.metadata.PreferenceMetadata
import com.android.settingslib.metadata.SwitchPreference
@@ -44,9 +44,10 @@ open class VibrationIntensitySwitchPreference(
    @Usage val vibrationUsage: Int,
    @StringRes title: Int = 0,
    @StringRes summary: Int = 0,
) : SwitchPreference(key, title, summary),
    OnPreferenceChangeListener,
    SwitchPreferenceBinding {
) :
    SwitchPreference(key, title, summary),
    SwitchPreferenceBinding,
    Preference.OnPreferenceChangeListener {

    private var storage: VibrationIntensitySettingsStore? = null

@@ -66,13 +67,15 @@ open class VibrationIntensitySwitchPreference(
    }

    override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
        if (newValue as Boolean) {
        val isChecked = newValue as Boolean
        // must make new value effective before preview
        (preference as TwoStatePreference).setChecked(isChecked)
        if (isChecked) {
            preference.context.playVibrationSettingsPreview(vibrationUsage)
        }
        return true
        return false // value has been updated
    }

    @CallSuper
    override fun isEnabled(context: Context) = storage?.isPreferenceEnabled() ?: true
    @CallSuper override fun isEnabled(context: Context) = storage?.isPreferenceEnabled() != false
}
// LINT.ThenChange(VibrationTogglePreferenceController.java)
+6 −2
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.VibrationAttributes.Usage
import android.os.Vibrator
import android.provider.Settings
import androidx.preference.Preference
import androidx.preference.TwoStatePreference
import com.android.settings.R
import com.android.settings.contract.KEY_VIBRATION_HAPTICS
import com.android.settings.metrics.PreferenceActionMetricsProvider
@@ -77,11 +78,14 @@ class VibrationMainSwitchPreference :
    }

    override fun onPreferenceChange(preference: Preference, newValue: Any?): Boolean {
        if (newValue as Boolean) {
        val isChecked = newValue as Boolean
        // must make new value effective before preview
        (preference as TwoStatePreference).setChecked(isChecked)
        if (isChecked) {
            // Play a haptic as preview for the main toggle only when touch feedback is enabled.
            preference.context.playVibrationSettingsPreview(VibrationAttributes.USAGE_TOUCH)
        }
        return true
        return false // value has been updated
    }

    companion object {