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

Unverified Commit ac66dfbe 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]

Change-Id: I9b6fafd731c49bf4d875b0ad581ee1b4666daf17
parent fd8fe4bd
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.systemui.keyguard.ui.binder

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

object KeyguardBottomAreaVibrations {
@@ -27,6 +28,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 {
@@ -45,6 +54,7 @@ object KeyguardBottomAreaVibrations {
            }
            .compose()

    val ActivatedAlt = VibrationEffect.createPredefined(VibrationEffect.EFFECT_HEAVY_CLICK)
    val Activated =
        VibrationEffect.startComposition()
            .addPrimitive(
@@ -59,6 +69,7 @@ object KeyguardBottomAreaVibrations {
            )
            .compose()

    val DeactivatedAlt = VibrationEffect.createPredefined(VibrationEffect.EFFECT_HEAVY_CLICK)
    val Deactivated =
        VibrationEffect.startComposition()
            .addPrimitive(
+22 −4
Original line number Diff line number Diff line
@@ -276,7 +276,12 @@ object KeyguardBottomAreaViewBinder {
                            isVisible ->
                            settingsMenu.animateVisibility(visible = isVisible)
                            if (isVisible) {
                                vibratorHelper?.vibrate(KeyguardBottomAreaVibrations.Activated)
                                vibratorHelper?.vibrate(
                                    if (KeyguardBottomAreaVibrations.areAllPrimitivesSupported) {
                                        KeyguardBottomAreaVibrations.Activated
                                    } else {
                                        KeyguardBottomAreaVibrations.ActivatedAlt
                                    })
                                settingsMenu.setOnTouchListener(
                                    KeyguardSettingsButtonOnTouchListener(
                                        viewModel = viewModel.settingsMenuViewModel,
@@ -443,7 +448,12 @@ object KeyguardBottomAreaViewBinder {
                    shakeAnimator.doOnEnd { view.translationX = 0f }
                    shakeAnimator.start()

                    vibratorHelper?.vibrate(KeyguardBottomAreaVibrations.Shake)
                    vibratorHelper?.vibrate(
                        if (KeyguardBottomAreaVibrations.areAllPrimitivesSupported) {
                            KeyguardBottomAreaVibrations.Shake
                        } else {
                            KeyguardBottomAreaVibrations.ShakeAlt
                        })
                }
                view.onLongClickListener =
                    OnLongClickListener(falsingManager, viewModel, vibratorHelper, onTouchListener)
@@ -513,9 +523,17 @@ object KeyguardBottomAreaViewBinder {
                )
                vibratorHelper?.vibrate(
                    if (viewModel.isActivated) {
                        if (KeyguardBottomAreaVibrations.areAllPrimitivesSupported) {
                            KeyguardBottomAreaVibrations.Activated
                        } else {
                            KeyguardBottomAreaVibrations.ActivatedAlt
                        }
                    } else {
                        if (KeyguardBottomAreaVibrations.areAllPrimitivesSupported) {
                            KeyguardBottomAreaVibrations.Deactivated
                        } else {
                            KeyguardBottomAreaVibrations.DeactivatedAlt
                        }
                    }
                )
            }
+10 −2
Original line number Diff line number Diff line
@@ -117,9 +117,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(
+16 −3
Original line number Diff line number Diff line
@@ -227,7 +227,12 @@ object KeyguardQuickAffordanceViewBinder {
                    shakeAnimator.doOnEnd { view.translationX = 0f }
                    shakeAnimator.start()

                    vibratorHelper?.vibrate(KeyguardBottomAreaVibrations.Shake)
                    vibratorHelper?.vibrate(
                        if (KeyguardBottomAreaVibrations.areAllPrimitivesSupported) {
                            KeyguardBottomAreaVibrations.Shake
                        } else {
                            KeyguardBottomAreaVibrations.ShakeAlt
                        })
                }
                view.onLongClickListener =
                    OnLongClickListener(falsingManager, viewModel, vibratorHelper, onTouchListener)
@@ -306,9 +311,17 @@ object KeyguardQuickAffordanceViewBinder {
                )
                vibratorHelper?.vibrate(
                    if (viewModel.isActivated) {
                        if (KeyguardBottomAreaVibrations.areAllPrimitivesSupported) {
                            KeyguardBottomAreaVibrations.Activated
                        } else {
                            KeyguardBottomAreaVibrations.ActivatedAlt
                        }
                    } else {
                        if (KeyguardBottomAreaVibrations.areAllPrimitivesSupported) {
                            KeyguardBottomAreaVibrations.Deactivated
                        } else {
                            KeyguardBottomAreaVibrations.DeactivatedAlt
                        }
                    }
                )
            }
+8 −0
Original line number Diff line number Diff line
@@ -134,6 +134,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()
     */