Merge "DO NOT MERGE New back affordance small polish nits" into tm-qpr-dev

This commit is contained in:
Marvin Bernal
2023-03-10 03:29:31 +00:00
committed by Android (Google) Code Review
3 changed files with 71 additions and 63 deletions

View File

@@ -2,19 +2,15 @@ package com.android.systemui.navigationbar.gestural
import android.content.Context
import android.content.res.Configuration
import android.content.res.TypedArray
import android.graphics.Canvas
import android.graphics.Paint
import android.graphics.Path
import android.graphics.RectF
import android.util.MathUtils.min
import android.util.TypedValue
import android.view.View
import androidx.appcompat.view.ContextThemeWrapper
import androidx.dynamicanimation.animation.FloatPropertyCompat
import androidx.dynamicanimation.animation.SpringAnimation
import androidx.dynamicanimation.animation.SpringForce
import com.android.internal.R.style.Theme_DeviceDefault
import com.android.internal.util.LatencyTracker
import com.android.settingslib.Utils
import com.android.systemui.navigationbar.gestural.BackPanelController.DelayedOnAnimationEndListener
@@ -159,26 +155,21 @@ class BackPanel(
val isDeviceInNightTheme = resources.configuration.uiMode and
Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
val colorControlActivated = ContextThemeWrapper(context, Theme_DeviceDefault)
.run {
val typedValue = TypedValue()
val a: TypedArray = obtainStyledAttributes(typedValue.data,
intArrayOf(android.R.attr.colorControlActivated))
val color = a.getColor(0, 0)
a.recycle()
color
}
arrowPaint.color = Utils.getColorAttrDefaultColor(context,
if (isDeviceInNightTheme) {
com.android.internal.R.attr.colorAccentPrimary
} else {
com.android.internal.R.attr.textColorPrimary
}
)
val colorPrimary =
Utils.getColorAttrDefaultColor(context, com.android.internal.R.attr.colorPrimary)
arrowPaint.color = Utils.getColorAccentDefaultColor(context)
arrowBackgroundPaint.color = if (isDeviceInNightTheme) {
colorPrimary
} else {
colorControlActivated
}
arrowBackgroundPaint.color = Utils.getColorAttrDefaultColor(context,
if (isDeviceInNightTheme) {
com.android.internal.R.attr.colorSurface
} else {
com.android.internal.R.attr.colorAccentSecondary
}
)
}
inner class AnimatedFloat(
@@ -414,9 +405,9 @@ class BackPanel(
) {
horizontalTranslation.updateRestingPosition(restingParams.horizontalTranslation)
scale.updateRestingPosition(restingParams.scale)
arrowAlpha.updateRestingPosition(restingParams.arrowDimens.alpha)
backgroundAlpha.updateRestingPosition(restingParams.backgroundDimens.alpha)
arrowAlpha.updateRestingPosition(restingParams.arrowDimens.alpha, animate)
arrowLength.updateRestingPosition(restingParams.arrowDimens.length, animate)
arrowHeight.updateRestingPosition(restingParams.arrowDimens.height, animate)
scalePivotX.updateRestingPosition(restingParams.backgroundDimens.width, animate)

View File

@@ -55,12 +55,12 @@ private const val PX_PER_MS = 1
internal const val MIN_DURATION_ACTIVE_ANIMATION = 300L
private const val MIN_DURATION_CANCELLED_ANIMATION = 200L
private const val MIN_DURATION_COMMITTED_ANIMATION = 200L
private const val MIN_DURATION_COMMITTED_ANIMATION = 120L
private const val MIN_DURATION_INACTIVE_BEFORE_FLUNG_ANIMATION = 50L
private const val MIN_DURATION_CONSIDERED_AS_FLING = 100L
private const val FAILSAFE_DELAY_MS = 350L
private const val POP_ON_FLING_DELAY = 160L
private const val POP_ON_FLING_DELAY = 140L
internal val VIBRATE_ACTIVATED_EFFECT =
VibrationEffect.createPredefined(VibrationEffect.EFFECT_CLICK)
@@ -148,8 +148,6 @@ class BackPanelController internal constructor(
private var gestureSinceActionDown = 0L
private var gestureEntryTime = 0L
private var gestureActiveTime = 0L
private var gestureInactiveOrEntryTime = 0L
private var gestureArrowStrokeVisibleTime = 0L
private val elapsedTimeSinceActionDown
get() = SystemClock.uptimeMillis() - gestureSinceActionDown
@@ -441,34 +439,44 @@ class BackPanelController internal constructor(
updateArrowStateOnMove(yTranslation, xTranslation)
when (currentState) {
GestureState.ACTIVE -> {
stretchActiveBackIndicator(fullScreenProgress(xTranslation))
}
GestureState.ENTRY -> {
val progress = staticThresholdProgress(xTranslation)
stretchEntryBackIndicator(progress)
params.arrowStrokeAlphaSpring.get(progress).takeIf { it.isNewState }?.let {
mView.popArrowAlpha(0f, it.value)
}
}
GestureState.INACTIVE -> {
val progress = reactivationThresholdProgress(totalTouchDelta)
stretchInactiveBackIndicator(progress)
params.arrowStrokeAlphaSpring.get(progress).takeIf { it.isNewState }?.let {
gestureArrowStrokeVisibleTime = SystemClock.uptimeMillis()
mView.popArrowAlpha(0f, it.value)
}
}
else -> {}
val gestureProgress = when (currentState) {
GestureState.ACTIVE -> fullScreenProgress(xTranslation)
GestureState.ENTRY -> staticThresholdProgress(xTranslation)
GestureState.INACTIVE -> reactivationThresholdProgress(totalTouchDelta)
else -> null
}
// set y translation
gestureProgress?.let {
when (currentState) {
GestureState.ACTIVE -> stretchActiveBackIndicator(gestureProgress)
GestureState.ENTRY -> stretchEntryBackIndicator(gestureProgress)
GestureState.INACTIVE -> stretchInactiveBackIndicator(gestureProgress)
else -> {}
}
}
setArrowStrokeAlpha(gestureProgress)
setVerticalTranslation(yOffset)
}
private fun setArrowStrokeAlpha(gestureProgress: Float?) {
val strokeAlphaProgress = when (currentState) {
GestureState.ENTRY -> gestureProgress
GestureState.INACTIVE -> gestureProgress
GestureState.ACTIVE,
GestureState.FLUNG,
GestureState.COMMITTED -> 1f
GestureState.CANCELLED,
GestureState.GONE -> 0f
}
strokeAlphaProgress?.let { progress ->
params.arrowStrokeAlphaSpring.get(progress).takeIf { it.isNewState }?.let {
mView.popArrowAlpha(0f, it.value)
}
}
}
private fun setVerticalTranslation(yOffset: Float) {
val yTranslation = abs(yOffset)
val maxYOffset = (mView.height - params.entryIndicator.backgroundDimens.height) / 2f
@@ -599,7 +607,7 @@ class BackPanelController internal constructor(
private fun isFlungAwayFromEdge(endX: Float, startX: Float = touchDeltaStartX): Boolean {
val minDistanceConsideredForFling = ViewConfiguration.get(context).scaledTouchSlop
val flingDistance = abs(endX - startX)
val flingDistance = if (mView.isLeftPanel) endX - startX else startX - endX
val isPastFlingVelocity = isDragAwayFromEdge(
velocityPxPerSecThreshold =
ViewConfiguration.get(context).scaledMinimumFlingVelocity)
@@ -764,7 +772,7 @@ class BackPanelController internal constructor(
GestureState.ENTRY,
GestureState.INACTIVE -> params.entryIndicator.arrowDimens
GestureState.ACTIVE -> params.activeIndicator.arrowDimens
GestureState.FLUNG,
GestureState.FLUNG -> params.flungIndicator.arrowDimens
GestureState.COMMITTED -> params.committedIndicator.arrowDimens
GestureState.CANCELLED -> params.cancelledIndicator.arrowDimens
},
@@ -825,7 +833,6 @@ class BackPanelController internal constructor(
updateRestingArrowDimens()
gestureEntryTime = SystemClock.uptimeMillis()
gestureInactiveOrEntryTime = SystemClock.uptimeMillis()
}
GestureState.ACTIVE -> {
previousXTranslationOnActiveOffset = previousXTranslation
@@ -857,7 +864,13 @@ class BackPanelController internal constructor(
}
GestureState.INACTIVE -> {
gestureInactiveOrEntryTime = SystemClock.uptimeMillis()
// Typically entering INACTIVE means
// totalTouchDelta <= deactivationSwipeTriggerThreshold
// but because we can also independently enter this state
// if touch Y >> touch X, we force it to deactivationSwipeTriggerThreshold
// so that gesture progress in this state is consistent regardless of entry
totalTouchDelta = params.deactivationSwipeTriggerThreshold
val startingVelocity = convertVelocityToSpringStartingVelocity(
valueOnFastVelocity = -1.05f,

View File

@@ -9,8 +9,8 @@ import com.android.systemui.R
data class EdgePanelParams(private var resources: Resources) {
data class ArrowDimens(
val length: Float = 0f,
val height: Float = 0f,
val length: Float? = 0f,
val height: Float? = 0f,
val alpha: Float = 0f,
var alphaSpring: SpringForce? = null,
val heightSpring: SpringForce? = null,
@@ -139,17 +139,17 @@ data class EdgePanelParams(private var resources: Resources) {
entryWidthInterpolator = PathInterpolator(.19f, 1.27f, .71f, .86f)
entryWidthTowardsEdgeInterpolator = PathInterpolator(1f, -3f, 1f, 1.2f)
activeWidthInterpolator = PathInterpolator(.15f, .48f, .46f, .89f)
activeWidthInterpolator = PathInterpolator(.32f, 0f, .16f, .94f)
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 showArrowOnProgressValue = .23f
val showArrowOnProgressValueFactor = 1.05f
val entryActiveHorizontalTranslationSpring = createSpring(675f, 0.8f)
val entryActiveHorizontalTranslationSpring = createSpring(800f, 0.8f)
val activeCommittedArrowLengthSpring = createSpring(1500f, 0.29f)
val activeCommittedArrowHeightSpring = createSpring(1500f, 0.29f)
val flungCommittedEdgeCornerSpring = createSpring(10000f, 1f)
@@ -178,7 +178,7 @@ data class EdgePanelParams(private var resources: Resources) {
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),
alphaSpring = createSpring(900f, 1f),
alphaSpring = createSpring(1100f, 1f),
widthSpring = createSpring(450f, 0.65f),
heightSpring = createSpring(1500f, 0.45f),
farCornerRadiusSpring = createSpring(300f, 0.5f),
@@ -232,7 +232,7 @@ data class EdgePanelParams(private var resources: Resources) {
getDimen(R.dimen.navigation_edge_pre_threshold_edge_corners),
farCornerRadius =
getDimen(R.dimen.navigation_edge_pre_threshold_far_corners),
widthSpring = createSpring(200f, 0.65f),
widthSpring = createSpring(250f, 0.65f),
heightSpring = createSpring(1500f, 0.45f),
farCornerRadiusSpring = createSpring(200f, 1f),
edgeCornerRadiusSpring = createSpring(150f, 0.5f),
@@ -244,6 +244,8 @@ data class EdgePanelParams(private var resources: Resources) {
arrowDimens = activeIndicator.arrowDimens.copy(
lengthSpring = activeCommittedArrowLengthSpring,
heightSpring = activeCommittedArrowHeightSpring,
length = null,
height = null,
),
backgroundDimens = activeIndicator.backgroundDimens.copy(
alpha = 0f,
@@ -255,13 +257,15 @@ data class EdgePanelParams(private var resources: Resources) {
farCornerRadiusSpring = flungCommittedFarCornerSpring,
),
scale = 0.85f,
scaleSpring = createSpring(650f, 1f),
scaleSpring = createSpring(1150f, 1f),
)
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(
widthSpring = flungCommittedWidthSpring,