diff options
| author | 2023-03-10 03:48:45 +0000 | |
|---|---|---|
| committer | 2023-03-10 03:48:45 +0000 | |
| commit | cb0fa35791ef1993cfa9b26a78a969e921f9801c (patch) | |
| tree | ef7ab31311c1f974facd73db9e81a4d0c73a828d | |
| parent | 996fbec1b7a0cf426fe7085add506669f8ad4b4a (diff) | |
| parent | 92e8dafec8a932b9733aff787aa44d8bf71ced79 (diff) | |
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>
3 files changed, 69 insertions, 61 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 f335733b430c..c76cfbdfe48c 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanel.kt +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanel.kt @@ -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 - } - - val colorPrimary = - Utils.getColorAttrDefaultColor(context, com.android.internal.R.attr.colorPrimary) - - arrowPaint.color = Utils.getColorAccentDefaultColor(context) + arrowPaint.color = Utils.getColorAttrDefaultColor(context, + if (isDeviceInNightTheme) { + com.android.internal.R.attr.colorAccentPrimary + } else { + com.android.internal.R.attr.textColorPrimary + } + ) - 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) 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 367d12547b9f..ce1c8daf1d45 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanelController.kt +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/BackPanelController.kt @@ -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) + val gestureProgress = when (currentState) { + GestureState.ACTIVE -> fullScreenProgress(xTranslation) + GestureState.ENTRY -> staticThresholdProgress(xTranslation) + GestureState.INACTIVE -> reactivationThresholdProgress(totalTouchDelta) + else -> null + } - params.arrowStrokeAlphaSpring.get(progress).takeIf { it.isNewState }?.let { - gestureArrowStrokeVisibleTime = SystemClock.uptimeMillis() - mView.popArrowAlpha(0f, it.value) - } + gestureProgress?.let { + when (currentState) { + GestureState.ACTIVE -> stretchActiveBackIndicator(gestureProgress) + GestureState.ENTRY -> stretchEntryBackIndicator(gestureProgress) + GestureState.INACTIVE -> stretchInactiveBackIndicator(gestureProgress) + else -> {} } - else -> {} } - // set y translation + 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, 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 0c0002221244..d46333a50c8d 100644 --- a/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgePanelParams.kt +++ b/packages/SystemUI/src/com/android/systemui/navigationbar/gestural/EdgePanelParams.kt @@ -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, |