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

Unverified Commit 9d3155b1 authored by Ido Ben-Hur's avatar Ido Ben-Hur Committed by Michael Bestas
Browse files

QSLongPressEffect: Provide a fallback for devices with no primitives

Change-Id: Ia766c29adff7ea700346cd1c3f2c8f1c788ab078
parent 4f851738
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -80,6 +80,12 @@ constructor(

    private val snapEffect = LongPressHapticBuilder.createSnapEffect()

    private var hasPrimitives =
        vibratorHelper?.areAllPrimitivesSupported(
            VibrationEffect.Composition.PRIMITIVE_LOW_TICK,
            VibrationEffect.Composition.PRIMITIVE_SPIN
        ) ?: false

    val hasInitialized: Boolean
        get() = longPressHint != null

@@ -89,6 +95,7 @@ constructor(
    }

    fun playReverseHaptics(pausedProgress: Float) {
        if (!hasPrimitives) return
        val effect =
            LongPressHapticBuilder.createReversedEffect(
                pausedProgress,
@@ -100,9 +107,13 @@ constructor(
    }

    private fun vibrate(effect: VibrationEffect?) {
        if (vibratorHelper != null && effect != null) {
        if (vibratorHelper == null || effect == null) return
        if (!hasPrimitives) {
            val effect = VibrationEffect.createPredefined(VibrationEffect.EFFECT_CLICK)
            vibratorHelper.vibrate(effect)
            return
        }
        vibratorHelper.vibrate(effect)
    }

    fun handleActionDown() {
@@ -143,7 +154,7 @@ constructor(
    fun handleAnimationStart() {
        logEvent(qsTile?.tileSpec, state, "animation started")
        if (state == State.TIMEOUT_WAIT) {
            vibrate(longPressHint)
            if (hasPrimitives) vibrate(longPressHint)
            setState(State.RUNNING_FORWARD)
        }
    }