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

Commit 317f4d08 authored by Marvin Bernal's avatar Marvin Bernal Committed by Android (Google) Code Review
Browse files

Merge "Add pre-threshold fling vibration for Back gesture" into main

parents 29104e5e 2354d4d1
Loading
Loading
Loading
Loading
+34 −22
Original line number Diff line number Diff line
@@ -231,7 +231,6 @@ internal constructor(
            animation.removeEndListener(this)

            if (!canceled) {

                // The delay between finishing this animation and starting the runnable
                val delay = max(0, runnableDelay - elapsedTimeSinceEntry)

@@ -461,7 +460,6 @@ internal constructor(
    }

    private fun handleMoveEvent(event: MotionEvent) {

        val x = event.x
        val y = event.y

@@ -927,17 +925,7 @@ internal constructor(
            GestureState.ACTIVE -> {
                previousXTranslationOnActiveOffset = previousXTranslation
                updateRestingArrowDimens()
                if (featureFlags.isEnabled(ONE_WAY_HAPTICS_API_MIGRATION)) {
                    vibratorHelper.performHapticFeedback(
                        mView,
                        HapticFeedbackConstants.GESTURE_THRESHOLD_ACTIVATE
                    )
                } else {
                    vibratorHelper.cancel()
                    mainHandler.postDelayed(10L) {
                        vibratorHelper.vibrate(VIBRATE_ACTIVATED_EFFECT)
                    }
                }
                performActivatedHapticFeedback()
                val popVelocity =
                    if (previousState == GestureState.INACTIVE) {
                        POP_ON_INACTIVE_TO_ACTIVE_VELOCITY
@@ -958,25 +946,24 @@ internal constructor(

                mView.popOffEdge(POP_ON_INACTIVE_VELOCITY)

                if (featureFlags.isEnabled(ONE_WAY_HAPTICS_API_MIGRATION)) {
                    vibratorHelper.performHapticFeedback(
                        mView,
                        HapticFeedbackConstants.GESTURE_THRESHOLD_DEACTIVATE
                    )
                } else {
                    vibratorHelper.vibrate(VIBRATE_DEACTIVATED_EFFECT)
                }
                performDeactivatedHapticFeedback()
                updateRestingArrowDimens()
            }
            GestureState.FLUNG -> {
                // Typically a vibration is only played while transitioning to ACTIVE. However there
                // are instances where a fling to trigger back occurs while not in that state.
                // (e.g. A fling is detected before crossing the trigger threshold.)
                if (previousState != GestureState.ACTIVE) {
                    performActivatedHapticFeedback()
                }
                mainHandler.postDelayed(POP_ON_FLING_DELAY) {
                    mView.popScale(POP_ON_FLING_VELOCITY)
                }
                updateRestingArrowDimens()
                mainHandler.postDelayed(
                    onEndSetCommittedStateListener.runnable,
                    MIN_DURATION_FLING_ANIMATION
                )
                updateRestingArrowDimens()
            }
            GestureState.COMMITTED -> {
                // In most cases, animating between states is handled via `updateRestingArrowDimens`
@@ -1011,6 +998,31 @@ internal constructor(
        }
    }

    private fun performDeactivatedHapticFeedback() {
        if (featureFlags.isEnabled(ONE_WAY_HAPTICS_API_MIGRATION)) {
            vibratorHelper.performHapticFeedback(
                    mView,
                    HapticFeedbackConstants.GESTURE_THRESHOLD_DEACTIVATE
            )
        } else {
            vibratorHelper.vibrate(VIBRATE_DEACTIVATED_EFFECT)
        }
    }

    private fun performActivatedHapticFeedback() {
        if (featureFlags.isEnabled(ONE_WAY_HAPTICS_API_MIGRATION)) {
            vibratorHelper.performHapticFeedback(
                    mView,
                    HapticFeedbackConstants.GESTURE_THRESHOLD_ACTIVATE
            )
        } else {
            vibratorHelper.cancel()
            mainHandler.postDelayed(10L) {
                vibratorHelper.vibrate(VIBRATE_ACTIVATED_EFFECT)
            }
        }
    }

    private fun convertVelocityToAnimationFactor(
        valueOnFastVelocity: Float,
        valueOnSlowVelocity: Float,