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

Commit 01a12efd authored by Fabian Leutenegger's avatar Fabian Leutenegger Committed by Michael Bestas
Browse files

SystemUI: Check primitive vibration support in new quick affordances

 * and provide an alternative if not

[SamarV-121: Use HEAVY_CLICK effect on activation and deactivation]

Change-Id: I9b6fafd731c49bf4d875b0ad581ee1b4666daf17
parent a2f21ee7
Loading
Loading
Loading
Loading
+25 −3
Original line number Diff line number Diff line
@@ -383,6 +383,12 @@ object KeyguardBottomAreaViewBinder {
        private val longPressDurationMs = ViewConfiguration.getLongPressTimeout().toLong()
        private var longPressAnimator: ViewPropertyAnimator? = null

        private val areAllPrimitivesSupported = vibratorHelper?.areAllPrimitivesSupported(
            VibrationEffect.Composition.PRIMITIVE_TICK,
            VibrationEffect.Composition.PRIMITIVE_QUICK_RISE,
            VibrationEffect.Composition.PRIMITIVE_QUICK_FALL
        ) ?: false

        @SuppressLint("ClickableViewAccessibility")
        override fun onTouch(v: View?, event: MotionEvent?): Boolean {
            return when (event?.actionMasked) {
@@ -470,7 +476,12 @@ object KeyguardBottomAreaViewBinder {
                                            CycleInterpolator(ShakeAnimationCycles)
                                        shakeAnimator.start()

                                        vibratorHelper?.vibrate(Vibrations.Shake)
                                        vibratorHelper?.vibrate(
                                            if (areAllPrimitivesSupported) {
                                                Vibrations.Shake
                                            } else {
                                                Vibrations.ShakeAlt
                                            })
                                    }
                                } else {
                                    null
@@ -493,9 +504,17 @@ object KeyguardBottomAreaViewBinder {
            view.setOnClickListener {
                vibratorHelper?.vibrate(
                    if (viewModel.isActivated) {
                        if (areAllPrimitivesSupported) {
                            Vibrations.Activated
                        } else {
                            Vibrations.ActivatedAlt
                        }
                    } else {
                        if (areAllPrimitivesSupported) {
                            Vibrations.Deactivated
                        } else {
                            Vibrations.DeactivatedAlt
                        }
                    }
                )
                viewModel.onClicked(
@@ -623,6 +642,7 @@ object KeyguardBottomAreaViewBinder {
                    }
                }
                .compose()
        val ShakeAlt = VibrationEffect.createPredefined(VibrationEffect.EFFECT_DOUBLE_CLICK)

        val Activated =
            VibrationEffect.startComposition()
@@ -637,6 +657,7 @@ object KeyguardBottomAreaViewBinder {
                    0,
                )
                .compose()
        val ActivatedAlt = VibrationEffect.createPredefined(VibrationEffect.EFFECT_HEAVY_CLICK)

        val Deactivated =
            VibrationEffect.startComposition()
@@ -651,5 +672,6 @@ object KeyguardBottomAreaViewBinder {
                    0,
                )
                .compose()
        val DeactivatedAlt = VibrationEffect.createPredefined(VibrationEffect.EFFECT_HEAVY_CLICK)
    }
}
+9 −0
Original line number Diff line number Diff line
@@ -123,6 +123,15 @@ public class VibratorHelper {
        return mVibrator != null && mVibrator.hasVibrator();
    }

    /**
     * @see areAllPrimitivesSupported#hasVibrator()
     */
    public boolean areAllPrimitivesSupported(
        @NonNull @VibrationEffect.Composition.PrimitiveType int... primitiveIds) {
        return mVibrator != null &&
            mVibrator.areAllPrimitivesSupported(primitiveIds);
    }

    /**
     * @see Vibrator#cancel()
     */