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

Commit deaf23cd authored by Brad Hinegardner's avatar Brad Hinegardner Committed by Cherrypicker Worker
Browse files

Move shortcut falsing shake and vibration to onclicklistener

This moves the falsing-required shake and vibration to a traditional
OnClickListener, accomplishing two things:
- Allowing a11y users to have the same experience as non-a11y users
- Make the system feel a bit snappier, as the shortcuts now react sooner

Bug: 283042620
Test: manual - with MIGRATE_SPLIT_KEYGUARD_BOTTOM_AREA both on and off
(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:6c054354c82ac6b7dcd2d87d0b3f03544b21c9d2)
Merged-In: I2e09718bb2d70983275d0b3e214b344c13f9843b
Change-Id: I2e09718bb2d70983275d0b3e214b344c13f9843b
parent eea96871
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import android.view.View
import android.view.ViewGroup
import android.view.ViewPropertyAnimator
import android.widget.ImageView
import androidx.core.animation.CycleInterpolator
import androidx.core.animation.ObjectAnimator
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
@@ -393,6 +395,27 @@ object KeyguardBottomAreaViewBinder {
                    falsingManager,
                )
                view.setOnTouchListener(onTouchListener)
                view.setOnClickListener {
                    messageDisplayer.invoke(R.string.keyguard_affordance_press_too_short)
                    val amplitude =
                        view.context.resources
                            .getDimensionPixelSize(R.dimen.keyguard_affordance_shake_amplitude)
                            .toFloat()
                    val shakeAnimator =
                        ObjectAnimator.ofFloat(
                            view,
                            "translationX",
                            -amplitude / 2,
                            amplitude / 2,
                        )
                    shakeAnimator.duration =
                        KeyguardBottomAreaVibrations.ShakeAnimationDuration.inWholeMilliseconds
                    shakeAnimator.interpolator =
                        CycleInterpolator(KeyguardBottomAreaVibrations.ShakeAnimationCycles)
                    shakeAnimator.start()

                    vibratorHelper?.vibrate(KeyguardBottomAreaVibrations.Shake)
                }
                view.onLongClickListener =
                    OnLongClickListener(falsingManager, viewModel, vibratorHelper, onTouchListener)
            } else {
+3 −37
Original line number Diff line number Diff line
@@ -99,41 +99,7 @@ class KeyguardQuickAffordanceOnTouchListener(
                    // When not using a stylus, lifting the finger/pointer will actually cancel
                    // the long-press gesture. Calling cancel after the quick affordance was
                    // already long-press activated is a no-op, so it's safe to call from here.
                    cancel(
                        onAnimationEnd =
                            if (event.eventTime - event.downTime < longPressDurationMs) {
                                Runnable {
                                    messageDisplayer.invoke(
                                        R.string.keyguard_affordance_press_too_short
                                    )
                                    val amplitude =
                                        view.context.resources
                                            .getDimensionPixelSize(
                                                R.dimen.keyguard_affordance_shake_amplitude
                                            )
                                            .toFloat()
                                    val shakeAnimator =
                                        ObjectAnimator.ofFloat(
                                            view,
                                            "translationX",
                                            -amplitude / 2,
                                            amplitude / 2,
                                        )
                                    shakeAnimator.duration =
                                        KeyguardBottomAreaVibrations.ShakeAnimationDuration
                                            .inWholeMilliseconds
                                    shakeAnimator.interpolator =
                                        CycleInterpolator(
                                            KeyguardBottomAreaVibrations.ShakeAnimationCycles
                                        )
                                    shakeAnimator.start()

                                    vibratorHelper?.vibrate(KeyguardBottomAreaVibrations.Shake)
                                }
                            } else {
                                null
                            }
                    )
                    cancel()
                }
                false
            }
@@ -168,10 +134,10 @@ class KeyguardQuickAffordanceOnTouchListener(
        view.setOnClickListener(null)
    }

    fun cancel(onAnimationEnd: Runnable? = null) {
    fun cancel() {
        longPressAnimator?.cancel()
        longPressAnimator = null
        view.animate().scaleX(1f).scaleY(1f).withEndAction(onAnimationEnd)
        view.animate().scaleX(1f).scaleY(1f)
    }

    companion object {
+23 −0
Original line number Diff line number Diff line
@@ -23,6 +23,8 @@ import android.util.Size
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.core.animation.CycleInterpolator
import androidx.core.animation.ObjectAnimator
import androidx.core.view.isInvisible
import androidx.core.view.isVisible
import androidx.core.view.updateLayoutParams
@@ -216,6 +218,27 @@ object KeyguardQuickAffordanceViewBinder {
                    falsingManager,
                )
                view.setOnTouchListener(onTouchListener)
                view.setOnClickListener {
                    messageDisplayer.invoke(R.string.keyguard_affordance_press_too_short)
                    val amplitude =
                        view.context.resources
                            .getDimensionPixelSize(R.dimen.keyguard_affordance_shake_amplitude)
                            .toFloat()
                    val shakeAnimator =
                        ObjectAnimator.ofFloat(
                            view,
                            "translationX",
                            -amplitude / 2,
                            amplitude / 2,
                        )
                    shakeAnimator.duration =
                        KeyguardBottomAreaVibrations.ShakeAnimationDuration.inWholeMilliseconds
                    shakeAnimator.interpolator =
                        CycleInterpolator(KeyguardBottomAreaVibrations.ShakeAnimationCycles)
                    shakeAnimator.start()

                    vibratorHelper?.vibrate(KeyguardBottomAreaVibrations.Shake)
                }
                view.onLongClickListener =
                    OnLongClickListener(falsingManager, viewModel, vibratorHelper, onTouchListener)
            } else {