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

Unverified Commit 4f851738 authored by Fabian Leutenegger's avatar Fabian Leutenegger Committed by Michael Bestas
Browse files

SystemUI: Check if primitive vibrations are supported in new quick affordances



 * and provide an alternative if not

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

Co-authored-by: default avatarMichael Bestas <mkbestas@lineageos.org>
Change-Id: I9b6fafd731c49bf4d875b0ad581ee1b4666daf17
parent 4b9aabcc
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.systemui.keyguard.ui.binder

import android.os.VibrationEffect
import com.android.systemui.Flags
import com.android.systemui.statusbar.VibratorHelper
import kotlin.time.Duration.Companion.milliseconds

object KeyguardBottomAreaVibrations {
@@ -38,6 +39,14 @@ object KeyguardBottomAreaVibrations {
    private const val SmallVibrationScale = 0.3f
    private const val BigVibrationScale = 0.6f

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

    val ShakeAlt = VibrationEffect.createPredefined(VibrationEffect.EFFECT_DOUBLE_CLICK)
    val Shake =
        VibrationEffect.startComposition()
            .apply {
@@ -56,12 +65,14 @@ object KeyguardBottomAreaVibrations {
            }
            .compose()

    val ActivatedAlt = VibrationEffect.createPredefined(VibrationEffect.EFFECT_HEAVY_CLICK)
    val Activated =
        VibrationEffect.startComposition()
            .addPrimitive(VibrationEffect.Composition.PRIMITIVE_TICK, BigVibrationScale, 0)
            .addPrimitive(VibrationEffect.Composition.PRIMITIVE_QUICK_RISE, 0.1f, 0)
            .compose()

    val DeactivatedAlt = VibrationEffect.createPredefined(VibrationEffect.EFFECT_HEAVY_CLICK)
    val Deactivated =
        VibrationEffect.startComposition()
            .addPrimitive(VibrationEffect.Composition.PRIMITIVE_TICK, BigVibrationScale, 0)
+10 −2
Original line number Diff line number Diff line
@@ -115,9 +115,17 @@ class KeyguardQuickAffordanceOnTouchListener(
        view.setOnClickListener {
            vibratorHelper?.vibrate(
                if (viewModel.isActivated) {
                    if (KeyguardBottomAreaVibrations.areAllPrimitivesSupported) {
                        KeyguardBottomAreaVibrations.Activated
                    } else {
                        KeyguardBottomAreaVibrations.ActivatedAlt
                    }
                } else {
                    if (KeyguardBottomAreaVibrations.areAllPrimitivesSupported) {
                        KeyguardBottomAreaVibrations.Deactivated
                    } else {
                        KeyguardBottomAreaVibrations.DeactivatedAlt
                    }
                }
            )
            viewModel.onClicked(
+9 −1
Original line number Diff line number Diff line
@@ -65,7 +65,15 @@ object KeyguardSettingsViewBinder {
                            view.animateVisibility(visible = isVisible)
                            if (isVisible) {
                                if (!Flags.msdlFeedback()) {
                                    vibratorHelper.vibrate(KeyguardBottomAreaVibrations.Activated)
                                    vibratorHelper.vibrate(
                                        if (
                                            KeyguardBottomAreaVibrations.areAllPrimitivesSupported
                                        ) {
                                            KeyguardBottomAreaVibrations.Activated
                                        } else {
                                            KeyguardBottomAreaVibrations.ActivatedAlt
                                        }
                                    )
                                }
                                val textView = view.requireViewById(R.id.text) as TextView
                                view.setOnTouchListener(
+17 −3
Original line number Diff line number Diff line
@@ -50,9 +50,17 @@ constructor(private val msdlPlayer: MSDLPlayer, private val vibratorHelper: Vibr
            // history updates.
            val vibration =
                if (isActivated) {
                    if (KeyguardBottomAreaVibrations.areAllPrimitivesSupported) {
                        KeyguardBottomAreaVibrations.Activated
                    } else {
                        KeyguardBottomAreaVibrations.ActivatedAlt
                    }
                } else {
                    if (KeyguardBottomAreaVibrations.areAllPrimitivesSupported) {
                        KeyguardBottomAreaVibrations.Deactivated
                    } else {
                        KeyguardBottomAreaVibrations.DeactivatedAlt
                    }
                }
            vibratorHelper.vibrate(vibration)
        }
@@ -62,7 +70,13 @@ constructor(private val msdlPlayer: MSDLPlayer, private val vibratorHelper: Vibr
        if (Flags.msdlFeedback()) {
            msdlPlayer.playToken(MSDLToken.FAILURE)
        } else {
            vibratorHelper.vibrate(KeyguardBottomAreaVibrations.Shake)
            vibratorHelper.vibrate(
                if (KeyguardBottomAreaVibrations.areAllPrimitivesSupported) {
                    KeyguardBottomAreaVibrations.Shake
                } else {
                    KeyguardBottomAreaVibrations.ShakeAlt
                },
            )
        }
    }

+8 −0
Original line number Diff line number Diff line
@@ -136,6 +136,14 @@ public class VibratorHelper {
        return mVibrator != null && mVibrator.hasVibrator();
    }

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

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