diff options
Diffstat (limited to 'libs')
3 files changed, 57 insertions, 19 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossActivityBackAnimation.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossActivityBackAnimation.kt index ee740fb70f1c..3339173c7aa7 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossActivityBackAnimation.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/CrossActivityBackAnimation.kt @@ -109,6 +109,7 @@ abstract class CrossActivityBackAnimation( private val postCommitFlingSpring = SpringForce(SPRING_SCALE) .setStiffness(SpringForce.STIFFNESS_LOW) .setDampingRatio(SpringForce.DAMPING_RATIO_LOW_BOUNCY) + protected var gestureProgress = 0f /** Background color to be used during the animation, also see [getBackgroundColor] */ protected var customizedBackgroundColor = 0 @@ -212,6 +213,7 @@ abstract class CrossActivityBackAnimation( private fun onGestureProgress(backEvent: BackEvent) { val progress = gestureInterpolator.getInterpolation(backEvent.progress) + gestureProgress = progress currentClosingRect.setInterpolatedRectF(startClosingRect, targetClosingRect, progress) val yOffset = getYOffset(currentClosingRect, backEvent.touchY) currentClosingRect.offset(0f, yOffset) @@ -257,9 +259,11 @@ abstract class CrossActivityBackAnimation( } // kick off spring animation with the current velocity from the pre-commit phase, this - // affects the scaling of the closing activity during post-commit + // affects the scaling of the closing and/or opening activity during post-commit + val startVelocity = + if (gestureProgress < 0.1f) -DEFAULT_FLING_VELOCITY else -velocity * SPRING_SCALE val flingAnimation = SpringAnimation(postCommitFlingScale, SPRING_SCALE) - .setStartVelocity(min(0f, -velocity * SPRING_SCALE)) + .setStartVelocity(startVelocity.coerceIn(-MAX_FLING_VELOCITY, 0f)) .setStartValue(SPRING_SCALE) .setSpring(postCommitFlingSpring) flingAnimation.start() @@ -315,19 +319,22 @@ abstract class CrossActivityBackAnimation( isLetterboxed = false enteringHasSameLetterbox = false lastPostCommitFlingScale = SPRING_SCALE + gestureProgress = 0f } protected fun applyTransform( leash: SurfaceControl?, rect: RectF, alpha: Float, - baseTransformation: Transformation? = null + baseTransformation: Transformation? = null, + flingMode: FlingMode = FlingMode.NO_FLING ) { if (leash == null || !leash.isValid) return tempRectF.set(rect) - if (leash == closingTarget?.leash) { - lastPostCommitFlingScale = (postCommitFlingScale.value / SPRING_SCALE).coerceIn( - minimumValue = MAX_FLING_SCALE, maximumValue = lastPostCommitFlingScale + if (flingMode != FlingMode.NO_FLING) { + lastPostCommitFlingScale = min( + postCommitFlingScale.value / SPRING_SCALE, + if (flingMode == FlingMode.FLING_BOUNCE) 1f else lastPostCommitFlingScale ) // apply an additional scale to the closing target to account for fling velocity tempRectF.scaleCentered(lastPostCommitFlingScale) @@ -529,14 +536,30 @@ abstract class CrossActivityBackAnimation( private const val MAX_SCRIM_ALPHA_DARK = 0.8f private const val MAX_SCRIM_ALPHA_LIGHT = 0.2f private const val SPRING_SCALE = 100f - private const val MAX_FLING_SCALE = 0.6f + private const val MAX_FLING_VELOCITY = 1000f + private const val DEFAULT_FLING_VELOCITY = 120f + } + + enum class FlingMode { + NO_FLING, + + /** + * This is used for the closing target in custom cross-activity back animations. When the + * back gesture is flung, the closing target shrinks a bit further with a spring motion. + */ + FLING_SHRINK, + + /** + * This is used for the closing and opening target in the default cross-activity back + * animation. When the back gesture is flung, the closing and opening targets shrink a + * bit further and then bounce back with a spring motion. + */ + FLING_BOUNCE } } // The target will loose focus when alpha == 0, so keep a minimum value for it. -private fun keepMinimumAlpha(transAlpha: Float): Float { - return max(transAlpha.toDouble(), 0.005).toFloat() -} +private fun keepMinimumAlpha(transAlpha: Float) = max(transAlpha, 0.005f) private fun isDarkMode(context: Context): Boolean { return context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/CustomCrossActivityBackAnimation.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/back/CustomCrossActivityBackAnimation.kt index c4aafea50a62..c738ce542f8a 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/CustomCrossActivityBackAnimation.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/CustomCrossActivityBackAnimation.kt @@ -57,7 +57,6 @@ class CustomCrossActivityBackAnimation( private var enterAnimation: Animation? = null private var closeAnimation: Animation? = null private val transformation = Transformation() - private var gestureProgress = 0f override val allowEnteringYShift = false @@ -105,7 +104,6 @@ class CustomCrossActivityBackAnimation( } override fun getPreCommitEnteringBaseTransformation(progress: Float): Transformation { - gestureProgress = progress transformation.clear() enterAnimation!!.getTransformationAt(progress * PRE_COMMIT_MAX_PROGRESS, transformation) return transformation @@ -134,7 +132,13 @@ class CustomCrossActivityBackAnimation( if (closingTarget == null || enteringTarget == null) return val closingProgress = closeAnimation!!.getPostCommitProgress(linearProgress) - applyTransform(closingTarget!!.leash, currentClosingRect, closingProgress, closeAnimation!!) + applyTransform( + closingTarget!!.leash, + currentClosingRect, + closingProgress, + closeAnimation!!, + FlingMode.FLING_SHRINK + ) val enteringProgress = MathUtils.lerp( gestureProgress * PRE_COMMIT_MAX_PROGRESS, 1f, @@ -144,7 +148,8 @@ class CustomCrossActivityBackAnimation( enteringTarget!!.leash, currentEnteringRect, enteringProgress, - enterAnimation!! + enterAnimation!!, + FlingMode.NO_FLING ) applyTransaction() } @@ -153,11 +158,12 @@ class CustomCrossActivityBackAnimation( leash: SurfaceControl, rect: RectF, progress: Float, - animation: Animation + animation: Animation, + flingMode: FlingMode ) { transformation.clear() animation.getTransformationAt(progress, transformation) - applyTransform(leash, rect, transformation.alpha, transformation) + applyTransform(leash, rect, transformation.alpha, transformation, flingMode) } override fun finishAnimation() { @@ -166,7 +172,6 @@ class CustomCrossActivityBackAnimation( enterAnimation?.reset() enterAnimation = null transformation.clear() - gestureProgress = 0f super.finishAnimation() } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/back/DefaultCrossActivityBackAnimation.kt b/libs/WindowManager/Shell/src/com/android/wm/shell/back/DefaultCrossActivityBackAnimation.kt index b377a42b911c..3b5eb3613d2a 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/back/DefaultCrossActivityBackAnimation.kt +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/back/DefaultCrossActivityBackAnimation.kt @@ -90,9 +90,19 @@ constructor( val closingAlpha = max(1f - linearProgress * 5, 0f) val progress = postCommitInterpolator.getInterpolation(linearProgress) currentClosingRect.setInterpolatedRectF(startClosingRect, targetClosingRect, progress) - applyTransform(closingTarget?.leash, currentClosingRect, closingAlpha) + applyTransform( + closingTarget?.leash, + currentClosingRect, + closingAlpha, + flingMode = FlingMode.FLING_BOUNCE + ) currentEnteringRect.setInterpolatedRectF(startEnteringRect, targetEnteringRect, progress) - applyTransform(enteringTarget?.leash, currentEnteringRect, 1f) + applyTransform( + enteringTarget?.leash, + currentEnteringRect, + 1f, + flingMode = FlingMode.FLING_BOUNCE + ) applyTransaction() } |