diff options
4 files changed, 298 insertions, 236 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanel.kt b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanel.kt index a256b59ac076..e931f8f5398a 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanel.kt +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanel.kt @@ -18,10 +18,7 @@ import com.android.systemui.navigationbar.gestural.BackPanelController.DelayedOn private const val TAG = "BackPanel" private const val DEBUG = false -class BackPanel( - context: Context, - private val latencyTracker: LatencyTracker -) : View(context) { +class BackPanel(context: Context, private val latencyTracker: LatencyTracker) : View(context) { var arrowsPointLeft = false set(value) { @@ -42,39 +39,39 @@ class BackPanel( // True if the panel is currently on the left of the screen var isLeftPanel = false - /** - * Used to track back arrow latency from [android.view.MotionEvent.ACTION_DOWN] to [onDraw] - */ + /** Used to track back arrow latency from [android.view.MotionEvent.ACTION_DOWN] to [onDraw] */ private var trackingBackArrowLatency = false - /** - * The length of the arrow measured horizontally. Used for animating [arrowPath] - */ - private var arrowLength = AnimatedFloat( + /** The length of the arrow measured horizontally. Used for animating [arrowPath] */ + private var arrowLength = + AnimatedFloat( name = "arrowLength", minimumVisibleChange = SpringAnimation.MIN_VISIBLE_CHANGE_PIXELS - ) + ) /** * The height of the arrow measured vertically from its center to its top (i.e. half the total * height). Used for animating [arrowPath] */ - var arrowHeight = AnimatedFloat( + var arrowHeight = + AnimatedFloat( name = "arrowHeight", minimumVisibleChange = SpringAnimation.MIN_VISIBLE_CHANGE_ROTATION_DEGREES - ) + ) - val backgroundWidth = AnimatedFloat( + val backgroundWidth = + AnimatedFloat( name = "backgroundWidth", minimumVisibleChange = SpringAnimation.MIN_VISIBLE_CHANGE_PIXELS, minimumValue = 0f, - ) + ) - val backgroundHeight = AnimatedFloat( + val backgroundHeight = + AnimatedFloat( name = "backgroundHeight", minimumVisibleChange = SpringAnimation.MIN_VISIBLE_CHANGE_PIXELS, minimumValue = 0f, - ) + ) /** * Corners of the background closer to the edge of the screen (where the arrow appeared from). @@ -88,17 +85,19 @@ class BackPanel( */ val backgroundFarCornerRadius = AnimatedFloat("backgroundFarCornerRadius") - var scale = AnimatedFloat( + var scale = + AnimatedFloat( name = "scale", minimumVisibleChange = SpringAnimation.MIN_VISIBLE_CHANGE_SCALE, minimumValue = 0f - ) + ) - val scalePivotX = AnimatedFloat( + val scalePivotX = + AnimatedFloat( name = "scalePivotX", minimumVisibleChange = SpringAnimation.MIN_VISIBLE_CHANGE_PIXELS, minimumValue = backgroundWidth.pos / 2, - ) + ) /** * Left/right position of the background relative to the canvas. Also corresponds with the @@ -107,21 +106,24 @@ class BackPanel( */ var horizontalTranslation = AnimatedFloat(name = "horizontalTranslation") - var arrowAlpha = AnimatedFloat( + var arrowAlpha = + AnimatedFloat( name = "arrowAlpha", minimumVisibleChange = SpringAnimation.MIN_VISIBLE_CHANGE_ALPHA, minimumValue = 0f, maximumValue = 1f - ) + ) - val backgroundAlpha = AnimatedFloat( + val backgroundAlpha = + AnimatedFloat( name = "backgroundAlpha", minimumVisibleChange = SpringAnimation.MIN_VISIBLE_CHANGE_ALPHA, minimumValue = 0f, maximumValue = 1f - ) + ) - private val allAnimatedFloat = setOf( + private val allAnimatedFloat = + setOf( arrowLength, arrowHeight, backgroundWidth, @@ -132,7 +134,7 @@ class BackPanel( horizontalTranslation, arrowAlpha, backgroundAlpha - ) + ) /** * Canvas vertical translation. How far up/down the arrow and background appear relative to the @@ -140,43 +142,45 @@ class BackPanel( */ var verticalTranslation = AnimatedFloat("verticalTranslation") - /** - * Use for drawing debug info. Can only be set if [DEBUG]=true - */ + /** Use for drawing debug info. Can only be set if [DEBUG]=true */ var drawDebugInfo: ((canvas: Canvas) -> Unit)? = null set(value) { if (DEBUG) field = value } internal fun updateArrowPaint(arrowThickness: Float) { - arrowPaint.strokeWidth = arrowThickness - val isDeviceInNightTheme = resources.configuration.uiMode and - Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES + val isDeviceInNightTheme = + resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == + Configuration.UI_MODE_NIGHT_YES - arrowPaint.color = Utils.getColorAttrDefaultColor(context, + arrowPaint.color = + Utils.getColorAttrDefaultColor( + context, if (isDeviceInNightTheme) { com.android.internal.R.attr.materialColorOnSecondaryContainer } else { com.android.internal.R.attr.materialColorOnSecondaryFixed } - ) + ) - arrowBackgroundPaint.color = Utils.getColorAttrDefaultColor(context, + arrowBackgroundPaint.color = + Utils.getColorAttrDefaultColor( + context, if (isDeviceInNightTheme) { com.android.internal.R.attr.materialColorSecondaryContainer } else { com.android.internal.R.attr.materialColorSecondaryFixedDim } - ) + ) } inner class AnimatedFloat( - name: String, - private val minimumVisibleChange: Float? = null, - private val minimumValue: Float? = null, - private val maximumValue: Float? = null, + name: String, + private val minimumVisibleChange: Float? = null, + private val minimumValue: Float? = null, + private val maximumValue: Float? = null, ) { // The resting position when not stretched by a touch drag @@ -207,19 +211,21 @@ class BackPanel( } init { - val floatProp = object : FloatPropertyCompat<AnimatedFloat>(name) { - override fun setValue(animatedFloat: AnimatedFloat, value: Float) { - animatedFloat.pos = value - } + val floatProp = + object : FloatPropertyCompat<AnimatedFloat>(name) { + override fun setValue(animatedFloat: AnimatedFloat, value: Float) { + animatedFloat.pos = value + } - override fun getValue(animatedFloat: AnimatedFloat): Float = animatedFloat.pos - } - animation = SpringAnimation(this, floatProp).apply { - spring = SpringForce() - this@AnimatedFloat.minimumValue?.let { setMinValue(it) } - this@AnimatedFloat.maximumValue?.let { setMaxValue(it) } - this@AnimatedFloat.minimumVisibleChange?.let { minimumVisibleChange = it } - } + override fun getValue(animatedFloat: AnimatedFloat): Float = animatedFloat.pos + } + animation = + SpringAnimation(this, floatProp).apply { + spring = SpringForce() + this@AnimatedFloat.minimumValue?.let { setMinValue(it) } + this@AnimatedFloat.maximumValue?.let { setMaxValue(it) } + this@AnimatedFloat.minimumVisibleChange?.let { minimumVisibleChange = it } + } } fun snapTo(newPosition: Float) { @@ -233,11 +239,10 @@ class BackPanel( snapTo(restingPosition) } - fun stretchTo( - stretchAmount: Float, - startingVelocity: Float? = null, - springForce: SpringForce? = null + stretchAmount: Float, + startingVelocity: Float? = null, + springForce: SpringForce? = null ) { animation.apply { startingVelocity?.let { @@ -297,8 +302,8 @@ class BackPanel( } fun addAnimationEndListener( - animatedFloat: AnimatedFloat, - endListener: DelayedOnAnimationEndListener + animatedFloat: AnimatedFloat, + endListener: DelayedOnAnimationEndListener ): Boolean { return if (animatedFloat.isRunning) { animatedFloat.addEndListener(endListener) @@ -314,51 +319,51 @@ class BackPanel( } fun setStretch( - horizontalTranslationStretchAmount: Float, - arrowStretchAmount: Float, - arrowAlphaStretchAmount: Float, - backgroundAlphaStretchAmount: Float, - backgroundWidthStretchAmount: Float, - backgroundHeightStretchAmount: Float, - edgeCornerStretchAmount: Float, - farCornerStretchAmount: Float, - fullyStretchedDimens: EdgePanelParams.BackIndicatorDimens + horizontalTranslationStretchAmount: Float, + arrowStretchAmount: Float, + arrowAlphaStretchAmount: Float, + backgroundAlphaStretchAmount: Float, + backgroundWidthStretchAmount: Float, + backgroundHeightStretchAmount: Float, + edgeCornerStretchAmount: Float, + farCornerStretchAmount: Float, + fullyStretchedDimens: EdgePanelParams.BackIndicatorDimens ) { horizontalTranslation.stretchBy( - finalPosition = fullyStretchedDimens.horizontalTranslation, - amount = horizontalTranslationStretchAmount + finalPosition = fullyStretchedDimens.horizontalTranslation, + amount = horizontalTranslationStretchAmount ) arrowLength.stretchBy( - finalPosition = fullyStretchedDimens.arrowDimens.length, - amount = arrowStretchAmount + finalPosition = fullyStretchedDimens.arrowDimens.length, + amount = arrowStretchAmount ) arrowHeight.stretchBy( - finalPosition = fullyStretchedDimens.arrowDimens.height, - amount = arrowStretchAmount + finalPosition = fullyStretchedDimens.arrowDimens.height, + amount = arrowStretchAmount ) arrowAlpha.stretchBy( - finalPosition = fullyStretchedDimens.arrowDimens.alpha, - amount = arrowAlphaStretchAmount + finalPosition = fullyStretchedDimens.arrowDimens.alpha, + amount = arrowAlphaStretchAmount ) backgroundAlpha.stretchBy( - finalPosition = fullyStretchedDimens.backgroundDimens.alpha, - amount = backgroundAlphaStretchAmount + finalPosition = fullyStretchedDimens.backgroundDimens.alpha, + amount = backgroundAlphaStretchAmount ) backgroundWidth.stretchBy( - finalPosition = fullyStretchedDimens.backgroundDimens.width, - amount = backgroundWidthStretchAmount + finalPosition = fullyStretchedDimens.backgroundDimens.width, + amount = backgroundWidthStretchAmount ) backgroundHeight.stretchBy( - finalPosition = fullyStretchedDimens.backgroundDimens.height, - amount = backgroundHeightStretchAmount + finalPosition = fullyStretchedDimens.backgroundDimens.height, + amount = backgroundHeightStretchAmount ) backgroundEdgeCornerRadius.stretchBy( - finalPosition = fullyStretchedDimens.backgroundDimens.edgeCornerRadius, - amount = edgeCornerStretchAmount + finalPosition = fullyStretchedDimens.backgroundDimens.edgeCornerRadius, + amount = edgeCornerStretchAmount ) backgroundFarCornerRadius.stretchBy( - finalPosition = fullyStretchedDimens.backgroundDimens.farCornerRadius, - amount = farCornerStretchAmount + finalPosition = fullyStretchedDimens.backgroundDimens.farCornerRadius, + amount = farCornerStretchAmount ) } @@ -373,8 +378,11 @@ class BackPanel( } fun popArrowAlpha(startingVelocity: Float, springForce: SpringForce? = null) { - arrowAlpha.stretchTo(stretchAmount = 0f, startingVelocity = startingVelocity, - springForce = springForce) + arrowAlpha.stretchTo( + stretchAmount = 0f, + startingVelocity = startingVelocity, + springForce = springForce + ) } fun resetStretch() { @@ -392,12 +400,10 @@ class BackPanel( backgroundFarCornerRadius.snapToRestingPosition() } - /** - * Updates resting arrow and background size not accounting for stretch - */ + /** Updates resting arrow and background size not accounting for stretch */ internal fun setRestingDimens( - restingParams: EdgePanelParams.BackIndicatorDimens, - animate: Boolean = true + restingParams: EdgePanelParams.BackIndicatorDimens, + animate: Boolean = true ) { horizontalTranslation.updateRestingPosition(restingParams.horizontalTranslation) scale.updateRestingPosition(restingParams.scale) @@ -410,27 +416,29 @@ class BackPanel( backgroundWidth.updateRestingPosition(restingParams.backgroundDimens.width, animate) backgroundHeight.updateRestingPosition(restingParams.backgroundDimens.height, animate) backgroundEdgeCornerRadius.updateRestingPosition( - restingParams.backgroundDimens.edgeCornerRadius, animate + restingParams.backgroundDimens.edgeCornerRadius, + animate ) backgroundFarCornerRadius.updateRestingPosition( - restingParams.backgroundDimens.farCornerRadius, animate + restingParams.backgroundDimens.farCornerRadius, + animate ) } fun animateVertically(yPos: Float) = verticalTranslation.stretchTo(yPos) fun setSpring( - horizontalTranslation: SpringForce? = null, - verticalTranslation: SpringForce? = null, - scale: SpringForce? = null, - arrowLength: SpringForce? = null, - arrowHeight: SpringForce? = null, - arrowAlpha: SpringForce? = null, - backgroundAlpha: SpringForce? = null, - backgroundFarCornerRadius: SpringForce? = null, - backgroundEdgeCornerRadius: SpringForce? = null, - backgroundWidth: SpringForce? = null, - backgroundHeight: SpringForce? = null, + horizontalTranslation: SpringForce? = null, + verticalTranslation: SpringForce? = null, + scale: SpringForce? = null, + arrowLength: SpringForce? = null, + arrowHeight: SpringForce? = null, + arrowAlpha: SpringForce? = null, + backgroundAlpha: SpringForce? = null, + backgroundFarCornerRadius: SpringForce? = null, + backgroundEdgeCornerRadius: SpringForce? = null, + backgroundWidth: SpringForce? = null, + backgroundHeight: SpringForce? = null, ) { arrowLength?.let { this.arrowLength.spring = it } arrowHeight?.let { this.arrowHeight.spring = it } @@ -459,26 +467,28 @@ class BackPanel( if (!isLeftPanel) canvas.scale(-1f, 1f, canvasWidth / 2.0f, 0f) - canvas.translate( - horizontalTranslation.pos, - height * 0.5f + verticalTranslation.pos - ) + canvas.translate(horizontalTranslation.pos, height * 0.5f + verticalTranslation.pos) canvas.scale(scale.pos, scale.pos, scalePivotX, 0f) - val arrowBackground = arrowBackgroundRect.apply { - left = 0f - top = -halfHeight - right = backgroundWidth - bottom = halfHeight - }.toPathWithRoundCorners( - topLeft = edgeCorner, - bottomLeft = edgeCorner, - topRight = farCorner, - bottomRight = farCorner + val arrowBackground = + arrowBackgroundRect + .apply { + left = 0f + top = -halfHeight + right = backgroundWidth + bottom = halfHeight + } + .toPathWithRoundCorners( + topLeft = edgeCorner, + bottomLeft = edgeCorner, + topRight = farCorner, + bottomRight = farCorner + ) + canvas.drawPath( + arrowBackground, + arrowBackgroundPaint.apply { alpha = (255 * backgroundAlpha.pos).toInt() } ) - canvas.drawPath(arrowBackground, - arrowBackgroundPaint.apply { alpha = (255 * backgroundAlpha.pos).toInt() }) val dx = arrowLength.pos val dy = arrowHeight.pos @@ -487,8 +497,8 @@ class BackPanel( // either the tip or the back of the arrow, whichever is closer val arrowOffset = (backgroundWidth - dx) / 2 canvas.translate( - /* dx= */ arrowOffset, - /* dy= */ 0f /* pass 0 for the y position since the canvas was already translated */ + /* dx= */ arrowOffset, + /* dy= */ 0f /* pass 0 for the y position since the canvas was already translated */ ) val arrowPointsAwayFromEdge = !arrowsPointLeft.xor(isLeftPanel) @@ -500,8 +510,8 @@ class BackPanel( } val arrowPath = calculateArrowPath(dx = dx, dy = dy) - val arrowPaint = arrowPaint - .apply { alpha = (255 * min(arrowAlpha.pos, backgroundAlpha.pos)).toInt() } + val arrowPaint = + arrowPaint.apply { alpha = (255 * min(arrowAlpha.pos, backgroundAlpha.pos)).toInt() } canvas.drawPath(arrowPath, arrowPaint) canvas.restore() @@ -519,17 +529,23 @@ class BackPanel( } private fun RectF.toPathWithRoundCorners( - topLeft: Float = 0f, - topRight: Float = 0f, - bottomRight: Float = 0f, - bottomLeft: Float = 0f - ): Path = Path().apply { - val corners = floatArrayOf( - topLeft, topLeft, - topRight, topRight, - bottomRight, bottomRight, - bottomLeft, bottomLeft - ) - addRoundRect(this@toPathWithRoundCorners, corners, Path.Direction.CW) - } -}
\ No newline at end of file + topLeft: Float = 0f, + topRight: Float = 0f, + bottomRight: Float = 0f, + bottomLeft: Float = 0f + ): Path = + Path().apply { + val corners = + floatArrayOf( + topLeft, + topLeft, + topRight, + topRight, + bottomRight, + bottomRight, + bottomLeft, + bottomLeft + ) + addRoundRect(this@toPathWithRoundCorners, corners, Path.Direction.CW) + } +} diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanelController.kt b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanelController.kt index f8086f5f6fb4..b208434c3218 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanelController.kt +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanelController.kt @@ -27,7 +27,6 @@ import android.view.Gravity import android.view.HapticFeedbackConstants import android.view.MotionEvent import android.view.VelocityTracker -import android.view.View import android.view.ViewConfiguration import android.view.WindowManager import androidx.annotation.VisibleForTesting @@ -164,6 +163,7 @@ internal constructor( private val elapsedTimeSinceInactive get() = systemClock.uptimeMillis() - gestureInactiveTime + private val elapsedTimeSinceEntry get() = systemClock.uptimeMillis() - gestureEntryTime @@ -612,6 +612,7 @@ internal constructor( } private var previousPreThresholdWidthInterpolator = params.entryWidthInterpolator + private fun preThresholdWidthStretchAmount(progress: Float): Float { val interpolator = run { val isPastSlop = totalTouchDeltaInactive > viewConfiguration.scaledTouchSlop @@ -677,8 +678,7 @@ internal constructor( velocityTracker?.run { computeCurrentVelocity(PX_PER_SEC) xVelocity.takeIf { mView.isLeftPanel } ?: (xVelocity * -1) - } - ?: 0f + } ?: 0f val isPastFlingVelocityThreshold = flingVelocity > viewConfiguration.scaledMinimumFlingVelocity return flingDistance > minFlingDistance && isPastFlingVelocityThreshold @@ -1006,15 +1006,15 @@ internal constructor( private fun performDeactivatedHapticFeedback() { vibratorHelper.performHapticFeedback( - mView, - HapticFeedbackConstants.GESTURE_THRESHOLD_DEACTIVATE + mView, + HapticFeedbackConstants.GESTURE_THRESHOLD_DEACTIVATE ) } private fun performActivatedHapticFeedback() { vibratorHelper.performHapticFeedback( - mView, - HapticFeedbackConstants.GESTURE_THRESHOLD_ACTIVATE + mView, + HapticFeedbackConstants.GESTURE_THRESHOLD_ACTIVATE ) } @@ -1028,8 +1028,7 @@ internal constructor( velocityTracker?.run { computeCurrentVelocity(PX_PER_MS) MathUtils.smoothStep(slowVelocityBound, fastVelocityBound, abs(xVelocity)) - } - ?: valueOnFastVelocity + } ?: valueOnFastVelocity return MathUtils.lerp(valueOnFastVelocity, valueOnSlowVelocity, 1 - factor) } diff --git a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgePanelParams.kt b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgePanelParams.kt index 439b7e18e0df..db8749f59d9c 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgePanelParams.kt +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgePanelParams.kt @@ -10,92 +10,114 @@ import com.android.systemui.res.R data class EdgePanelParams(private var resources: Resources) { data class ArrowDimens( - val length: Float? = 0f, - val height: Float? = 0f, - val alpha: Float = 0f, - val heightSpring: SpringForce? = null, - val lengthSpring: SpringForce? = null, - var alphaSpring: Step<SpringForce>? = null, - var alphaInterpolator: Step<Float>? = null + val length: Float? = 0f, + val height: Float? = 0f, + val alpha: Float = 0f, + val heightSpring: SpringForce? = null, + val lengthSpring: SpringForce? = null, + var alphaSpring: Step<SpringForce>? = null, + var alphaInterpolator: Step<Float>? = null ) data class BackgroundDimens( - val width: Float? = 0f, - val height: Float = 0f, - val edgeCornerRadius: 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, + val width: Float? = 0f, + val height: Float = 0f, + val edgeCornerRadius: 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 scale: Float = 0f, - val scalePivotX: Float? = null, - val arrowDimens: ArrowDimens, - val backgroundDimens: BackgroundDimens, - val verticalTranslationSpring: SpringForce? = null, - val horizontalTranslationSpring: SpringForce? = null, - val scaleSpring: SpringForce? = null, + val horizontalTranslation: Float? = 0f, + val scale: Float = 0f, + val scalePivotX: Float? = null, + val arrowDimens: ArrowDimens, + val backgroundDimens: BackgroundDimens, + val verticalTranslationSpring: SpringForce? = null, + val horizontalTranslationSpring: SpringForce? = null, + val scaleSpring: SpringForce? = null, ) lateinit var entryIndicator: BackIndicatorDimens private set + lateinit var activeIndicator: BackIndicatorDimens private set + lateinit var cancelledIndicator: BackIndicatorDimens private set + lateinit var flungIndicator: BackIndicatorDimens private set + lateinit var committedIndicator: BackIndicatorDimens private set + lateinit var preThresholdIndicator: BackIndicatorDimens private set + lateinit var fullyStretchedIndicator: BackIndicatorDimens private set // navigation bar edge constants var arrowPaddingEnd: Int = 0 private set + var arrowThickness: Float = 0f private set + // The closest to y var minArrowYPosition: Int = 0 private set + var fingerOffset: Int = 0 private set + var staticTriggerThreshold: Float = 0f private set + var reactivationTriggerThreshold: Float = 0f private set + var deactivationTriggerThreshold: Float = 0f get() = -field private set + lateinit var dynamicTriggerThresholdRange: ClosedRange<Float> private set + var swipeProgressThreshold: Float = 0f private set lateinit var entryWidthInterpolator: Interpolator private set + lateinit var entryWidthTowardsEdgeInterpolator: Interpolator private set + lateinit var activeWidthInterpolator: Interpolator private set + lateinit var arrowAngleInterpolator: Interpolator private set + lateinit var horizontalTranslationInterpolator: Interpolator private set + lateinit var verticalTranslationInterpolator: Interpolator private set + lateinit var farCornerInterpolator: Interpolator private set + lateinit var edgeCornerInterpolator: Interpolator private set + lateinit var heightInterpolator: Interpolator private set @@ -108,7 +130,10 @@ data class EdgePanelParams(private var resources: Resources) { } private fun getDimenFloat(id: Int): Float { - return TypedValue().run { resources.getValue(id, this, true); float } + return TypedValue().run { + resources.getValue(id, this, true) + float + } } private fun getPx(id: Int): Int { @@ -123,11 +148,10 @@ data class EdgePanelParams(private var resources: Resources) { fingerOffset = getPx(R.dimen.navigation_edge_finger_offset) staticTriggerThreshold = getDimen(R.dimen.navigation_edge_action_drag_threshold) reactivationTriggerThreshold = - getDimen(R.dimen.navigation_edge_action_reactivation_drag_threshold) + getDimen(R.dimen.navigation_edge_action_reactivation_drag_threshold) deactivationTriggerThreshold = - getDimen(R.dimen.navigation_edge_action_deactivation_drag_threshold) - dynamicTriggerThresholdRange = - reactivationTriggerThreshold..deactivationTriggerThreshold + getDimen(R.dimen.navigation_edge_action_deactivation_drag_threshold) + dynamicTriggerThresholdRange = reactivationTriggerThreshold..deactivationTriggerThreshold swipeProgressThreshold = getDimen(R.dimen.navigation_edge_action_progress_threshold) entryWidthInterpolator = PathInterpolator(.19f, 1.27f, .71f, .86f) @@ -149,27 +173,31 @@ data class EdgePanelParams(private var resources: Resources) { val commonArrowDimensAlphaThreshold = .165f val commonArrowDimensAlphaFactor = 1.05f - val commonArrowDimensAlphaSpring = Step( - threshold = commonArrowDimensAlphaThreshold, - factor = commonArrowDimensAlphaFactor, - postThreshold = createSpring(180f, 0.9f), - preThreshold = createSpring(2000f, 0.6f) - ) - val commonArrowDimensAlphaSpringInterpolator = Step( - threshold = commonArrowDimensAlphaThreshold, - factor = commonArrowDimensAlphaFactor, - postThreshold = 1f, - preThreshold = 0f - ) - - entryIndicator = BackIndicatorDimens( + val commonArrowDimensAlphaSpring = + Step( + threshold = commonArrowDimensAlphaThreshold, + factor = commonArrowDimensAlphaFactor, + postThreshold = createSpring(180f, 0.9f), + preThreshold = createSpring(2000f, 0.6f) + ) + val commonArrowDimensAlphaSpringInterpolator = + Step( + threshold = commonArrowDimensAlphaThreshold, + factor = commonArrowDimensAlphaFactor, + postThreshold = 1f, + preThreshold = 0f + ) + + 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 = createSpring(800f, 0.76f), verticalTranslationSpring = createSpring(30000f, 1f), scaleSpring = createSpring(120f, 0.8f), - arrowDimens = ArrowDimens( + arrowDimens = + ArrowDimens( length = getDimen(R.dimen.navigation_edge_entry_arrow_length), height = getDimen(R.dimen.navigation_edge_entry_arrow_height), alpha = 0f, @@ -177,8 +205,9 @@ data class EdgePanelParams(private var resources: Resources) { heightSpring = createSpring(600f, 0.4f), alphaSpring = commonArrowDimensAlphaSpring, alphaInterpolator = commonArrowDimensAlphaSpringInterpolator - ), - backgroundDimens = BackgroundDimens( + ), + backgroundDimens = + BackgroundDimens( alpha = 1f, width = getDimen(R.dimen.navigation_edge_entry_background_width), height = getDimen(R.dimen.navigation_edge_entry_background_height), @@ -188,16 +217,18 @@ data class EdgePanelParams(private var resources: Resources) { heightSpring = createSpring(1500f, 0.45f), farCornerRadiusSpring = createSpring(300f, 0.5f), edgeCornerRadiusSpring = createSpring(150f, 0.5f), - ) - ) + ) + ) - activeIndicator = BackIndicatorDimens( + activeIndicator = + BackIndicatorDimens( horizontalTranslation = getDimen(R.dimen.navigation_edge_active_margin), scale = getDimenFloat(R.dimen.navigation_edge_active_scale), horizontalTranslationSpring = createSpring(1000f, 0.8f), scaleSpring = createSpring(325f, 0.55f), scalePivotX = getDimen(R.dimen.navigation_edge_active_background_width), - arrowDimens = ArrowDimens( + arrowDimens = + ArrowDimens( length = getDimen(R.dimen.navigation_edge_active_arrow_length), height = getDimen(R.dimen.navigation_edge_active_arrow_height), alpha = 1f, @@ -205,8 +236,9 @@ data class EdgePanelParams(private var resources: Resources) { heightSpring = activeCommittedArrowHeightSpring, alphaSpring = commonArrowDimensAlphaSpring, alphaInterpolator = commonArrowDimensAlphaSpringInterpolator - ), - backgroundDimens = BackgroundDimens( + ), + backgroundDimens = + BackgroundDimens( alpha = 1f, width = getDimen(R.dimen.navigation_edge_active_background_width), height = getDimen(R.dimen.navigation_edge_active_background_height), @@ -216,16 +248,18 @@ data class EdgePanelParams(private var resources: Resources) { heightSpring = createSpring(10000f, 1f), edgeCornerRadiusSpring = createSpring(2600f, 0.855f), farCornerRadiusSpring = createSpring(1200f, 0.30f), - ) - ) + ) + ) - preThresholdIndicator = BackIndicatorDimens( + 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( + arrowDimens = + ArrowDimens( length = getDimen(R.dimen.navigation_edge_pre_threshold_arrow_length), height = getDimen(R.dimen.navigation_edge_pre_threshold_arrow_height), alpha = 1f, @@ -233,32 +267,36 @@ data class EdgePanelParams(private var resources: Resources) { heightSpring = createSpring(100f, 0.6f), alphaSpring = commonArrowDimensAlphaSpring, alphaInterpolator = commonArrowDimensAlphaSpringInterpolator - ), - backgroundDimens = BackgroundDimens( + ), + 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), + getDimen(R.dimen.navigation_edge_pre_threshold_edge_corners), farCornerRadius = - getDimen(R.dimen.navigation_edge_pre_threshold_far_corners), + getDimen(R.dimen.navigation_edge_pre_threshold_far_corners), widthSpring = createSpring(650f, 1f), heightSpring = createSpring(1500f, 0.45f), farCornerRadiusSpring = createSpring(300f, 1f), edgeCornerRadiusSpring = createSpring(250f, 0.5f), - ) - ) + ) + ) - committedIndicator = activeIndicator.copy( + committedIndicator = + activeIndicator.copy( horizontalTranslation = null, scalePivotX = null, - arrowDimens = activeIndicator.arrowDimens.copy( + arrowDimens = + activeIndicator.arrowDimens.copy( lengthSpring = activeCommittedArrowLengthSpring, heightSpring = activeCommittedArrowHeightSpring, length = null, height = null, - ), - backgroundDimens = activeIndicator.backgroundDimens.copy( + ), + backgroundDimens = + activeIndicator.backgroundDimens.copy( alpha = 0f, // explicitly set to null to preserve previous width upon state change width = null, @@ -267,49 +305,57 @@ data class EdgePanelParams(private var resources: Resources) { edgeCornerRadiusSpring = flungCommittedEdgeCornerSpring, farCornerRadiusSpring = flungCommittedFarCornerSpring, alphaSpring = createSpring(1400f, 1f), - ), + ), scale = 0.86f, scaleSpring = createSpring(5700f, 1f), - ) + ) - flungIndicator = committedIndicator.copy( - arrowDimens = committedIndicator.arrowDimens.copy( + flungIndicator = + committedIndicator.copy( + arrowDimens = + committedIndicator.arrowDimens.copy( lengthSpring = createSpring(850f, 0.46f), heightSpring = createSpring(850f, 0.46f), length = activeIndicator.arrowDimens.length, height = activeIndicator.arrowDimens.height - ), - backgroundDimens = committedIndicator.backgroundDimens.copy( + ), + backgroundDimens = + committedIndicator.backgroundDimens.copy( widthSpring = flungCommittedWidthSpring, heightSpring = flungCommittedHeightSpring, edgeCornerRadiusSpring = flungCommittedEdgeCornerSpring, farCornerRadiusSpring = flungCommittedFarCornerSpring, - ) - ) + ) + ) - cancelledIndicator = entryIndicator.copy( - backgroundDimens = entryIndicator.backgroundDimens.copy( + cancelledIndicator = + entryIndicator.copy( + backgroundDimens = + entryIndicator.backgroundDimens.copy( width = 0f, alpha = 0f, alphaSpring = createSpring(450f, 1f) - ) - ) + ) + ) - fullyStretchedIndicator = BackIndicatorDimens( + 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( + 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( + ), + backgroundDimens = + BackgroundDimens( alpha = 1f, width = getDimen(R.dimen.navigation_edge_stretch_background_width), height = getDimen(R.dimen.navigation_edge_stretch_background_height), @@ -320,11 +366,11 @@ data class EdgePanelParams(private var resources: Resources) { heightSpring = null, edgeCornerRadiusSpring = null, farCornerRadiusSpring = null, - ) - ) + ) + ) } } fun createSpring(stiffness: Float, dampingRatio: Float): SpringForce { return SpringForce().setStiffness(stiffness).setDampingRatio(dampingRatio) -}
\ No newline at end of file +} diff --git a/packages/SystemUI/tests/src/com/android/systemui/navigationbar/gestural/BackPanelControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/navigationbar/gestural/BackPanelControllerTest.kt index f1c97dd45f09..23cf7fb9c73d 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/navigationbar/gestural/BackPanelControllerTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/navigationbar/gestural/BackPanelControllerTest.kt @@ -55,6 +55,7 @@ class BackPanelControllerTest : SysuiTestCase() { companion object { private const val START_X: Float = 0f } + private val kosmos = testKosmos() private lateinit var mBackPanelController: BackPanelController private lateinit var systemClock: FakeSystemClock |