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

Commit a5e9e2df authored by Marvin Bernal's avatar Marvin Bernal Committed by Automerger Merge Worker
Browse files

DO NOT MERGE New Back Arrow in production am: d16eecfe

parents f6670bf9 d16eecfe
Loading
Loading
Loading
Loading
+55 −25
Original line number Diff line number Diff line
@@ -43,12 +43,18 @@
    <dimen name="navigation_edge_panel_height">268dp</dimen>
    <!-- The threshold to drag to trigger the edge action -->
    <dimen name="navigation_edge_action_drag_threshold">16dp</dimen>
    <!-- The drag distance to consider evaluating gesture -->
    <dimen name="navigation_edge_action_min_distance_to_start_animation">24dp</dimen>
    <!-- The threshold to progress back animation for edge swipe -->
    <dimen name="navigation_edge_action_progress_threshold">412dp</dimen>
    <!-- The minimum display position of the arrow on the screen -->
    <dimen name="navigation_edge_arrow_min_y">64dp</dimen>
    <!-- The amount by which the arrow is shifted to avoid the finger-->
    <dimen name="navigation_edge_finger_offset">64dp</dimen>
    <!-- The threshold to dynamically activate the edge action -->
    <dimen name="navigation_edge_action_reactivation_drag_threshold">32dp</dimen>
    <!-- The threshold to dynamically deactivate the edge action -->
    <dimen name="navigation_edge_action_deactivation_drag_threshold">32dp</dimen>

    <!-- The thickness of the arrow -->
    <dimen name="navigation_edge_arrow_thickness">4dp</dimen>
@@ -56,37 +62,61 @@
    <dimen name="navigation_edge_minimum_x_delta_for_switch">32dp</dimen>

    <!-- entry state -->
    <item name="navigation_edge_entry_scale" format="float" type="dimen">0.98</item>
    <dimen name="navigation_edge_entry_margin">4dp</dimen>
    <dimen name="navigation_edge_entry_background_width">8dp</dimen>
    <dimen name="navigation_edge_entry_background_height">60dp</dimen>
    <dimen name="navigation_edge_entry_edge_corners">30dp</dimen>
    <dimen name="navigation_edge_entry_far_corners">30dp</dimen>
    <dimen name="navigation_edge_entry_arrow_length">10dp</dimen>
    <dimen name="navigation_edge_entry_arrow_height">7dp</dimen>
    <item name="navigation_edge_entry_background_alpha" format="float" type="dimen">1.0</item>
    <dimen name="navigation_edge_entry_background_width">0dp</dimen>
    <dimen name="navigation_edge_entry_background_height">48dp</dimen>
    <dimen name="navigation_edge_entry_edge_corners">6dp</dimen>
    <dimen name="navigation_edge_entry_far_corners">6dp</dimen>
    <item name="navigation_edge_entry_arrow_alpha" format="float" type="dimen">0.0</item>
    <dimen name="navigation_edge_entry_arrow_length">8.6dp</dimen>
    <dimen name="navigation_edge_entry_arrow_height">5dp</dimen>

    <!-- pre-threshold -->
    <dimen name="navigation_edge_pre_threshold_margin">4dp</dimen>
    <dimen name="navigation_edge_pre_threshold_background_width">64dp</dimen>
    <dimen name="navigation_edge_pre_threshold_background_height">60dp</dimen>
    <dimen name="navigation_edge_pre_threshold_edge_corners">22dp</dimen>
    <dimen name="navigation_edge_pre_threshold_far_corners">26dp</dimen>

    <!-- post-threshold / active -->
    <item name="navigation_edge_pre_threshold_background_alpha" format="float" type="dimen">1.0
    </item>
    <item name="navigation_edge_pre_threshold_scale" format="float" type="dimen">0.98</item>
    <dimen name="navigation_edge_pre_threshold_background_width">51dp</dimen>
    <dimen name="navigation_edge_pre_threshold_background_height">46dp</dimen>
    <dimen name="navigation_edge_pre_threshold_edge_corners">16dp</dimen>
    <dimen name="navigation_edge_pre_threshold_far_corners">20dp</dimen>
    <item name="navigation_edge_pre_threshold_arrow_alpha" format="float" type="dimen">1.0</item>
    <dimen name="navigation_edge_pre_threshold_arrow_length">8dp</dimen>
    <dimen name="navigation_edge_pre_threshold_arrow_height">5.6dp</dimen>

    <!-- active (post-threshold) -->
    <item name="navigation_edge_active_scale" format="float" type="dimen">1.0</item>
    <dimen name="navigation_edge_active_margin">14dp</dimen>
    <dimen name="navigation_edge_active_background_width">60dp</dimen>
    <dimen name="navigation_edge_active_background_height">60dp</dimen>
    <dimen name="navigation_edge_active_edge_corners">30dp</dimen>
    <dimen name="navigation_edge_active_far_corners">30dp</dimen>
    <dimen name="navigation_edge_active_arrow_length">8dp</dimen>
    <dimen name="navigation_edge_active_arrow_height">9dp</dimen>

    <item name="navigation_edge_active_background_alpha" format="float" type="dimen">1.0</item>
    <dimen name="navigation_edge_active_background_width">48dp</dimen>
    <dimen name="navigation_edge_active_background_height">48dp</dimen>
    <dimen name="navigation_edge_active_edge_corners">24dp</dimen>
    <dimen name="navigation_edge_active_far_corners">24dp</dimen>
    <item name="navigation_edge_active_arrow_alpha" format="float" type="dimen">1.0</item>
    <dimen name="navigation_edge_active_arrow_length">6.4dp</dimen>
    <dimen name="navigation_edge_active_arrow_height">7.2dp</dimen>

    <!-- committed -->
    <item name="navigation_edge_committed_scale" format="float" type="dimen">0.85</item>
    <item name="navigation_edge_committed_alpha" format="float" type="dimen">0</item>

    <!-- cancelled -->
    <dimen name="navigation_edge_cancelled_background_width">0dp</dimen>

    <item name="navigation_edge_stretch_scale" format="float" type="dimen">1.0</item>
    <dimen name="navigation_edge_stretch_margin">18dp</dimen>
    <dimen name="navigation_edge_stretch_background_width">74dp</dimen>
    <dimen name="navigation_edge_stretch_background_height">60dp</dimen>
    <dimen name="navigation_edge_stretch_edge_corners">30dp</dimen>
    <dimen name="navigation_edge_stretch_far_corners">30dp</dimen>
    <dimen name="navigation_edge_stretched_arrow_length">7dp</dimen>
    <dimen name="navigation_edge_stretched_arrow_height">10dp</dimen>
    <dimen name="navigation_edge_stretch_background_width">60dp</dimen>
    <item name="navigation_edge_stretch_background_alpha" format="float" type="dimen">
        @dimen/navigation_edge_entry_background_alpha
    </item>
    <dimen name="navigation_edge_stretch_background_height">48dp</dimen>
    <dimen name="navigation_edge_stretch_edge_corners">24dp</dimen>
    <dimen name="navigation_edge_stretch_far_corners">24dp</dimen>
    <item name="navigation_edge_strech_arrow_alpha" format="float" type="dimen">1.0</item>
    <dimen name="navigation_edge_stretched_arrow_length">5.6dp</dimen>
    <dimen name="navigation_edge_stretched_arrow_height">8dp</dimen>

    <dimen name="navigation_edge_cancelled_arrow_length">12dp</dimen>
    <dimen name="navigation_edge_cancelled_arrow_height">0dp</dimen>
+288 −137

File changed.

Preview size limit exceeded, changes collapsed.

+585 −278

File changed.

Preview size limit exceeded, changes collapsed.

+250 −68
Original line number Diff line number Diff line
package com.android.systemui.navigationbar.gestural

import android.content.res.Resources
import android.util.TypedValue
import androidx.core.animation.PathInterpolator
import androidx.dynamicanimation.animation.SpringForce
import com.android.systemui.R

data class EdgePanelParams(private var resources: Resources) {

    data class ArrowDimens(
            val length: Float = 0f,
        val height: Float = 0f
            val height: Float = 0f,
            val alpha: Float = 0f,
            var alphaSpring: SpringForce? = null,
            val heightSpring: SpringForce? = null,
            val lengthSpring: SpringForce? = null,
    )

    data class BackgroundDimens(
        val width: Float = 0f,
            val width: Float? = 0f,
            val height: Float = 0f,
            val edgeCornerRadius: Float = 0f,
        val farCornerRadius: Float = 0f
            val farCornerRadius: Float = 0f,
            val alpha: Float = 0f,
            val widthSpring: SpringForce? = null,
            val heightSpring: SpringForce? = null,
            val farCornerRadiusSpring: SpringForce? = null,
            val edgeCornerRadiusSpring: SpringForce? = null,
            val alphaSpring: SpringForce? = null,
    )

    data class BackIndicatorDimens(
        val horizontalTranslation: Float = 0f,
        val arrowDimens: ArrowDimens = ArrowDimens(),
        val backgroundDimens: BackgroundDimens = BackgroundDimens()
            val horizontalTranslation: Float? = 0f,
            val scale: Float = 0f,
            val scalePivotX: Float = 0f,
            val arrowDimens: ArrowDimens,
            val backgroundDimens: BackgroundDimens,
            val verticalTranslationSpring: SpringForce? = null,
            val horizontalTranslationSpring: SpringForce? = null,
            val scaleSpring: SpringForce? = null,
    )

    var arrowThickness: Float = 0f
    lateinit var entryIndicator: BackIndicatorDimens
        private set
    lateinit var activeIndicator: BackIndicatorDimens
        private set
    var entryIndicator = BackIndicatorDimens()
    lateinit var cancelledIndicator: BackIndicatorDimens
        private set
    var activeIndicator = BackIndicatorDimens()
    lateinit var flungIndicator: BackIndicatorDimens
        private set
    var preThresholdIndicator = BackIndicatorDimens()
    lateinit var committedIndicator: BackIndicatorDimens
        private set
    var fullyStretchedIndicator = BackIndicatorDimens()
    lateinit var preThresholdIndicator: BackIndicatorDimens
        private set
    var cancelledEdgeCornerRadius: Float = 0f
    lateinit var fullyStretchedIndicator: BackIndicatorDimens
        private set
    var cancelledArrowDimens = ArrowDimens()

    // navigation bar edge constants
    var arrowPaddingEnd: Int = 0
        private set
    var arrowThickness: Float = 0f
        private set
    lateinit var arrowStrokeAlphaSpring: Step<SpringForce>
        private set
    lateinit var arrowStrokeAlphaInterpolator: Step<Float>
        private set

    // The closest to y
    var minArrowYPosition: Int = 0
        private set
    var fingerOffset: Int = 0
        private set
    var swipeTriggerThreshold: Float = 0f
    var staticTriggerThreshold: Float = 0f
        private set
    var reactivationTriggerThreshold: Float = 0f
        private set
    var deactivationSwipeTriggerThreshold: Float = 0f
        get() = -field
        private set
    var swipeProgressThreshold: Float = 0f
        private set
@@ -55,6 +85,26 @@ data class EdgePanelParams(private var resources: Resources) {
    var minDeltaForSwitch: Int = 0
        private set

    var minDragToStartAnimation: Float = 0f
        private set

    lateinit var entryWidthInterpolator: PathInterpolator
        private set
    lateinit var entryWidthTowardsEdgeInterpolator: PathInterpolator
        private set
    lateinit var activeWidthInterpolator: PathInterpolator
        private set
    lateinit var arrowAngleInterpolator: PathInterpolator
        private set
    lateinit var translationInterpolator: PathInterpolator
        private set
    lateinit var farCornerInterpolator: PathInterpolator
        private set
    lateinit var edgeCornerInterpolator: PathInterpolator
        private set
    lateinit var heightInterpolator: PathInterpolator
        private set

    init {
        update(resources)
    }
@@ -63,6 +113,10 @@ data class EdgePanelParams(private var resources: Resources) {
        return resources.getDimension(id)
    }

    private fun getDimenFloat(id: Int): Float {
        return TypedValue().run { resources.getValue(id, this, true); float }
    }

    private fun getPx(id: Int): Int {
        return resources.getDimensionPixelSize(id)
    }
@@ -73,72 +127,200 @@ data class EdgePanelParams(private var resources: Resources) {
        arrowPaddingEnd = getPx(R.dimen.navigation_edge_panel_padding)
        minArrowYPosition = getPx(R.dimen.navigation_edge_arrow_min_y)
        fingerOffset = getPx(R.dimen.navigation_edge_finger_offset)
        swipeTriggerThreshold = getDimen(R.dimen.navigation_edge_action_drag_threshold)
        staticTriggerThreshold = getDimen(R.dimen.navigation_edge_action_drag_threshold)
        reactivationTriggerThreshold =
                getDimen(R.dimen.navigation_edge_action_reactivation_drag_threshold)
        deactivationSwipeTriggerThreshold =
                getDimen(R.dimen.navigation_edge_action_deactivation_drag_threshold)
        swipeProgressThreshold = getDimen(R.dimen.navigation_edge_action_progress_threshold)
        minDeltaForSwitch = getPx(R.dimen.navigation_edge_minimum_x_delta_for_switch)
        minDragToStartAnimation =
                getDimen(R.dimen.navigation_edge_action_min_distance_to_start_animation)

        entryWidthInterpolator = PathInterpolator(.19f, 1.27f, .71f, .86f)
        entryWidthTowardsEdgeInterpolator = PathInterpolator(1f, -3f, 1f, 1.2f)
        activeWidthInterpolator = PathInterpolator(.15f, .48f, .46f, .89f)
        arrowAngleInterpolator = entryWidthInterpolator
        translationInterpolator = PathInterpolator(0.2f, 1.0f, 1.0f, 1.0f)
        farCornerInterpolator = PathInterpolator(.03f, .19f, .14f, 1.09f)
        edgeCornerInterpolator = PathInterpolator(0f, 1.11f, .85f, .84f)
        heightInterpolator = PathInterpolator(1f, .05f, .9f, -0.29f)

        val showArrowOnProgressValue = .2f
        val showArrowOnProgressValueFactor = 1.05f

        val entryActiveHorizontalTranslationSpring = createSpring(675f, 0.8f)
        val activeCommittedArrowLengthSpring = createSpring(1500f, 0.29f)
        val activeCommittedArrowHeightSpring = createSpring(1500f, 0.29f)
        val flungCommittedEdgeCornerSpring = createSpring(10000f, 1f)
        val flungCommittedFarCornerSpring = createSpring(10000f, 1f)
        val flungCommittedWidthSpring = createSpring(10000f, 1f)
        val flungCommittedHeightSpring = createSpring(10000f, 1f)

        entryIndicator = BackIndicatorDimens(
                horizontalTranslation = getDimen(R.dimen.navigation_edge_entry_margin),
                scale = getDimenFloat(R.dimen.navigation_edge_entry_scale),
                scalePivotX = getDimen(R.dimen.navigation_edge_pre_threshold_background_width),
                horizontalTranslationSpring = entryActiveHorizontalTranslationSpring,
                verticalTranslationSpring = createSpring(10000f, 0.9f),
                scaleSpring = createSpring(120f, 0.8f),
                arrowDimens = ArrowDimens(
                        length = getDimen(R.dimen.navigation_edge_entry_arrow_length),
                        height = getDimen(R.dimen.navigation_edge_entry_arrow_height),
                        alpha = 0f,
                        alphaSpring = createSpring(200f, 1f),
                        lengthSpring = createSpring(600f, 0.4f),
                        heightSpring = createSpring(600f, 0.4f),
                ),
                backgroundDimens = BackgroundDimens(
                        alpha = 1f,
                        width = getDimen(R.dimen.navigation_edge_entry_background_width),
                        height = getDimen(R.dimen.navigation_edge_entry_background_height),
                        edgeCornerRadius = getDimen(R.dimen.navigation_edge_entry_edge_corners),
                farCornerRadius = getDimen(R.dimen.navigation_edge_entry_far_corners)
                        farCornerRadius = getDimen(R.dimen.navigation_edge_entry_far_corners),
                        alphaSpring = createSpring(900f, 1f),
                        widthSpring = createSpring(450f, 0.65f),
                        heightSpring = createSpring(1500f, 0.45f),
                        farCornerRadiusSpring = createSpring(300f, 0.5f),
                        edgeCornerRadiusSpring = createSpring(150f, 0.5f),
                )
        )

        activeIndicator = BackIndicatorDimens(
                horizontalTranslation = getDimen(R.dimen.navigation_edge_active_margin),
                scale = getDimenFloat(R.dimen.navigation_edge_active_scale),
                horizontalTranslationSpring = entryActiveHorizontalTranslationSpring,
                scaleSpring = createSpring(450f, 0.415f),
                arrowDimens = ArrowDimens(
                        length = getDimen(R.dimen.navigation_edge_active_arrow_length),
                        height = getDimen(R.dimen.navigation_edge_active_arrow_height),
                        alpha = 1f,
                        lengthSpring = activeCommittedArrowLengthSpring,
                        heightSpring = activeCommittedArrowHeightSpring,
                ),
                backgroundDimens = BackgroundDimens(
                        alpha = 1f,
                        width = getDimen(R.dimen.navigation_edge_active_background_width),
                        height = getDimen(R.dimen.navigation_edge_active_background_height),
                        edgeCornerRadius = getDimen(R.dimen.navigation_edge_active_edge_corners),
                farCornerRadius = getDimen(R.dimen.navigation_edge_active_far_corners)

                        farCornerRadius = getDimen(R.dimen.navigation_edge_active_far_corners),
                        widthSpring = createSpring(375f, 0.675f),
                        heightSpring = createSpring(10000f, 1f),
                        edgeCornerRadiusSpring = createSpring(600f, 0.36f),
                        farCornerRadiusSpring = createSpring(2500f, 0.855f),
                )
        )

        preThresholdIndicator = BackIndicatorDimens(
                horizontalTranslation = getDimen(R.dimen.navigation_edge_pre_threshold_margin),
                scale = getDimenFloat(R.dimen.navigation_edge_pre_threshold_scale),
                scalePivotX = getDimen(R.dimen.navigation_edge_pre_threshold_background_width),
                scaleSpring = createSpring(120f, 0.8f),
                horizontalTranslationSpring = createSpring(6000f, 1f),
                arrowDimens = ArrowDimens(
                length = entryIndicator.arrowDimens.length,
                height = entryIndicator.arrowDimens.height,
                        length = getDimen(R.dimen.navigation_edge_pre_threshold_arrow_length),
                        height = getDimen(R.dimen.navigation_edge_pre_threshold_arrow_height),
                        alpha = 1f,
                        lengthSpring = createSpring(100f, 0.6f),
                        heightSpring = createSpring(100f, 0.6f),
                ),
                backgroundDimens = BackgroundDimens(
                        alpha = 1f,
                        width = getDimen(R.dimen.navigation_edge_pre_threshold_background_width),
                        height = getDimen(R.dimen.navigation_edge_pre_threshold_background_height),
                edgeCornerRadius = getDimen(R.dimen.navigation_edge_pre_threshold_edge_corners),
                farCornerRadius = getDimen(R.dimen.navigation_edge_pre_threshold_far_corners)
                        edgeCornerRadius =
                                getDimen(R.dimen.navigation_edge_pre_threshold_edge_corners),
                        farCornerRadius =
                                getDimen(R.dimen.navigation_edge_pre_threshold_far_corners),
                        widthSpring = createSpring(200f, 0.65f),
                        heightSpring = createSpring(1500f, 0.45f),
                        farCornerRadiusSpring = createSpring(200f, 1f),
                        edgeCornerRadiusSpring = createSpring(150f, 0.5f),
                )
        )

        committedIndicator = activeIndicator.copy(
                horizontalTranslation = null,
                arrowDimens = activeIndicator.arrowDimens.copy(
                        lengthSpring = activeCommittedArrowLengthSpring,
                        heightSpring = activeCommittedArrowHeightSpring,
                ),
                backgroundDimens = activeIndicator.backgroundDimens.copy(
                        alpha = 0f,
                        // explicitly set to null to preserve previous width upon state change
                        width = null,
                        widthSpring = flungCommittedWidthSpring,
                        heightSpring = flungCommittedHeightSpring,
                        edgeCornerRadiusSpring = flungCommittedEdgeCornerSpring,
                        farCornerRadiusSpring = flungCommittedFarCornerSpring,
                ),
                scale = 0.85f,
                scaleSpring = createSpring(650f, 1f),
        )

        flungIndicator = committedIndicator.copy(
                arrowDimens = committedIndicator.arrowDimens.copy(
                        lengthSpring = createSpring(850f, 0.46f),
                        heightSpring = createSpring(850f, 0.46f),
                ),
                backgroundDimens = committedIndicator.backgroundDimens.copy(
                        widthSpring = flungCommittedWidthSpring,
                        heightSpring = flungCommittedHeightSpring,
                        edgeCornerRadiusSpring = flungCommittedEdgeCornerSpring,
                        farCornerRadiusSpring = flungCommittedFarCornerSpring,
                )
        )

        cancelledIndicator = entryIndicator.copy(
                backgroundDimens = entryIndicator.backgroundDimens.copy(width = 0f)
        )

        fullyStretchedIndicator = BackIndicatorDimens(
                horizontalTranslation = getDimen(R.dimen.navigation_edge_stretch_margin),
                scale = getDimenFloat(R.dimen.navigation_edge_stretch_scale),
                horizontalTranslationSpring = null,
                verticalTranslationSpring = null,
                scaleSpring = null,
                arrowDimens = ArrowDimens(
                        length = getDimen(R.dimen.navigation_edge_stretched_arrow_length),
                        height = getDimen(R.dimen.navigation_edge_stretched_arrow_height),
                        alpha = 1f,
                        alphaSpring = null,
                        heightSpring = null,
                        lengthSpring = null,
                ),
                backgroundDimens = BackgroundDimens(
                        alpha = 1f,
                        width = getDimen(R.dimen.navigation_edge_stretch_background_width),
                        height = getDimen(R.dimen.navigation_edge_stretch_background_height),
                        edgeCornerRadius = getDimen(R.dimen.navigation_edge_stretch_edge_corners),
                farCornerRadius = getDimen(R.dimen.navigation_edge_stretch_far_corners)
                        farCornerRadius = getDimen(R.dimen.navigation_edge_stretch_far_corners),
                        alphaSpring = null,
                        widthSpring = null,
                        heightSpring = null,
                        edgeCornerRadiusSpring = null,
                        farCornerRadiusSpring = null,
                )
        )

        cancelledEdgeCornerRadius = getDimen(R.dimen.navigation_edge_cancelled_edge_corners)
        arrowStrokeAlphaInterpolator = Step(
                threshold = showArrowOnProgressValue,
                factor = showArrowOnProgressValueFactor,
                postThreshold = 1f,
                preThreshold = 0f
        )

        cancelledArrowDimens = ArrowDimens(
            length = getDimen(R.dimen.navigation_edge_cancelled_arrow_length),
            height = getDimen(R.dimen.navigation_edge_cancelled_arrow_height)
        entryIndicator.arrowDimens.alphaSpring?.let { alphaSpring ->
            arrowStrokeAlphaSpring = Step(
                    threshold = showArrowOnProgressValue,
                    factor = showArrowOnProgressValueFactor,
                    postThreshold = alphaSpring,
                    preThreshold = SpringForce().setStiffness(2000f).setDampingRatio(1f)
            )
        }
    }
}

fun createSpring(stiffness: Float, dampingRatio: Float): SpringForce {
    return SpringForce().setStiffness(stiffness).setDampingRatio(dampingRatio)
}
 No newline at end of file