DO NOT MERGE New back affordance small polish nits am: 92e8dafec8

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21483766

Change-Id: I0a72d025dc0e18c2eefe2f5e5a53a3197f3b4630
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Marvin Bernal
2023-03-10 03:48:45 +00:00
committed by Automerger Merge Worker
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.Context
import android.content.res.Configuration import android.content.res.Configuration
import android.content.res.TypedArray
import android.graphics.Canvas import android.graphics.Canvas
import android.graphics.Paint import android.graphics.Paint
import android.graphics.Path import android.graphics.Path
import android.graphics.RectF import android.graphics.RectF
import android.util.MathUtils.min import android.util.MathUtils.min
import android.util.TypedValue
import android.view.View import android.view.View
import androidx.appcompat.view.ContextThemeWrapper
import androidx.dynamicanimation.animation.FloatPropertyCompat import androidx.dynamicanimation.animation.FloatPropertyCompat
import androidx.dynamicanimation.animation.SpringAnimation import androidx.dynamicanimation.animation.SpringAnimation
import androidx.dynamicanimation.animation.SpringForce import androidx.dynamicanimation.animation.SpringForce
import com.android.internal.R.style.Theme_DeviceDefault
import com.android.internal.util.LatencyTracker import com.android.internal.util.LatencyTracker
import com.android.settingslib.Utils import com.android.settingslib.Utils
import com.android.systemui.navigationbar.gestural.BackPanelController.DelayedOnAnimationEndListener import com.android.systemui.navigationbar.gestural.BackPanelController.DelayedOnAnimationEndListener
@@ -159,26 +155,21 @@ class BackPanel(
val isDeviceInNightTheme = resources.configuration.uiMode and val isDeviceInNightTheme = resources.configuration.uiMode and
Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES
val colorControlActivated = ContextThemeWrapper(context, Theme_DeviceDefault) arrowPaint.color = Utils.getColorAttrDefaultColor(context,
.run { if (isDeviceInNightTheme) {
val typedValue = TypedValue() com.android.internal.R.attr.colorAccentPrimary
val a: TypedArray = obtainStyledAttributes(typedValue.data, } else {
intArrayOf(android.R.attr.colorControlActivated)) com.android.internal.R.attr.textColorPrimary
val color = a.getColor(0, 0) }
a.recycle() )
color
}
val colorPrimary = arrowBackgroundPaint.color = Utils.getColorAttrDefaultColor(context,
Utils.getColorAttrDefaultColor(context, com.android.internal.R.attr.colorPrimary) if (isDeviceInNightTheme) {
com.android.internal.R.attr.colorSurface
arrowPaint.color = Utils.getColorAccentDefaultColor(context) } else {
com.android.internal.R.attr.colorAccentSecondary
arrowBackgroundPaint.color = if (isDeviceInNightTheme) { }
colorPrimary )
} else {
colorControlActivated
}
} }
inner class AnimatedFloat( inner class AnimatedFloat(
@@ -414,9 +405,9 @@ class BackPanel(
) { ) {
horizontalTranslation.updateRestingPosition(restingParams.horizontalTranslation) horizontalTranslation.updateRestingPosition(restingParams.horizontalTranslation)
scale.updateRestingPosition(restingParams.scale) scale.updateRestingPosition(restingParams.scale)
arrowAlpha.updateRestingPosition(restingParams.arrowDimens.alpha)
backgroundAlpha.updateRestingPosition(restingParams.backgroundDimens.alpha) backgroundAlpha.updateRestingPosition(restingParams.backgroundDimens.alpha)
arrowAlpha.updateRestingPosition(restingParams.arrowDimens.alpha, animate)
arrowLength.updateRestingPosition(restingParams.arrowDimens.length, animate) arrowLength.updateRestingPosition(restingParams.arrowDimens.length, animate)
arrowHeight.updateRestingPosition(restingParams.arrowDimens.height, animate) arrowHeight.updateRestingPosition(restingParams.arrowDimens.height, animate)
scalePivotX.updateRestingPosition(restingParams.backgroundDimens.width, 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 internal const val MIN_DURATION_ACTIVE_ANIMATION = 300L
private const val MIN_DURATION_CANCELLED_ANIMATION = 200L 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_INACTIVE_BEFORE_FLUNG_ANIMATION = 50L
private const val MIN_DURATION_CONSIDERED_AS_FLING = 100L private const val MIN_DURATION_CONSIDERED_AS_FLING = 100L
private const val FAILSAFE_DELAY_MS = 350L 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 = internal val VIBRATE_ACTIVATED_EFFECT =
VibrationEffect.createPredefined(VibrationEffect.EFFECT_CLICK) VibrationEffect.createPredefined(VibrationEffect.EFFECT_CLICK)
@@ -148,8 +148,6 @@ class BackPanelController internal constructor(
private var gestureSinceActionDown = 0L private var gestureSinceActionDown = 0L
private var gestureEntryTime = 0L private var gestureEntryTime = 0L
private var gestureActiveTime = 0L private var gestureActiveTime = 0L
private var gestureInactiveOrEntryTime = 0L
private var gestureArrowStrokeVisibleTime = 0L
private val elapsedTimeSinceActionDown private val elapsedTimeSinceActionDown
get() = SystemClock.uptimeMillis() - gestureSinceActionDown get() = SystemClock.uptimeMillis() - gestureSinceActionDown
@@ -441,34 +439,44 @@ class BackPanelController internal constructor(
updateArrowStateOnMove(yTranslation, xTranslation) updateArrowStateOnMove(yTranslation, xTranslation)
when (currentState) { val gestureProgress = when (currentState) {
GestureState.ACTIVE -> { GestureState.ACTIVE -> fullScreenProgress(xTranslation)
stretchActiveBackIndicator(fullScreenProgress(xTranslation)) GestureState.ENTRY -> staticThresholdProgress(xTranslation)
} GestureState.INACTIVE -> reactivationThresholdProgress(totalTouchDelta)
GestureState.ENTRY -> { else -> null
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 -> {}
} }
// set y translation gestureProgress?.let {
when (currentState) {
GestureState.ACTIVE -> stretchActiveBackIndicator(gestureProgress)
GestureState.ENTRY -> stretchEntryBackIndicator(gestureProgress)
GestureState.INACTIVE -> stretchInactiveBackIndicator(gestureProgress)
else -> {}
}
}
setArrowStrokeAlpha(gestureProgress)
setVerticalTranslation(yOffset) 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) { private fun setVerticalTranslation(yOffset: Float) {
val yTranslation = abs(yOffset) val yTranslation = abs(yOffset)
val maxYOffset = (mView.height - params.entryIndicator.backgroundDimens.height) / 2f 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 { private fun isFlungAwayFromEdge(endX: Float, startX: Float = touchDeltaStartX): Boolean {
val minDistanceConsideredForFling = ViewConfiguration.get(context).scaledTouchSlop val minDistanceConsideredForFling = ViewConfiguration.get(context).scaledTouchSlop
val flingDistance = abs(endX - startX) val flingDistance = if (mView.isLeftPanel) endX - startX else startX - endX
val isPastFlingVelocity = isDragAwayFromEdge( val isPastFlingVelocity = isDragAwayFromEdge(
velocityPxPerSecThreshold = velocityPxPerSecThreshold =
ViewConfiguration.get(context).scaledMinimumFlingVelocity) ViewConfiguration.get(context).scaledMinimumFlingVelocity)
@@ -764,7 +772,7 @@ class BackPanelController internal constructor(
GestureState.ENTRY, GestureState.ENTRY,
GestureState.INACTIVE -> params.entryIndicator.arrowDimens GestureState.INACTIVE -> params.entryIndicator.arrowDimens
GestureState.ACTIVE -> params.activeIndicator.arrowDimens GestureState.ACTIVE -> params.activeIndicator.arrowDimens
GestureState.FLUNG, GestureState.FLUNG -> params.flungIndicator.arrowDimens
GestureState.COMMITTED -> params.committedIndicator.arrowDimens GestureState.COMMITTED -> params.committedIndicator.arrowDimens
GestureState.CANCELLED -> params.cancelledIndicator.arrowDimens GestureState.CANCELLED -> params.cancelledIndicator.arrowDimens
}, },
@@ -825,7 +833,6 @@ class BackPanelController internal constructor(
updateRestingArrowDimens() updateRestingArrowDimens()
gestureEntryTime = SystemClock.uptimeMillis() gestureEntryTime = SystemClock.uptimeMillis()
gestureInactiveOrEntryTime = SystemClock.uptimeMillis()
} }
GestureState.ACTIVE -> { GestureState.ACTIVE -> {
previousXTranslationOnActiveOffset = previousXTranslation previousXTranslationOnActiveOffset = previousXTranslation
@@ -857,7 +864,13 @@ class BackPanelController internal constructor(
} }
GestureState.INACTIVE -> { 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( val startingVelocity = convertVelocityToSpringStartingVelocity(
valueOnFastVelocity = -1.05f, valueOnFastVelocity = -1.05f,

View File

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