Loading packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/binder/KeyguardSurfaceBehindParamsApplierTest.kt +2 −5 Original line number Diff line number Diff line Loading @@ -67,6 +67,7 @@ class KeyguardSurfaceBehindParamsApplierTest : SysuiTestCase() { executor = executor, keyguardViewController = keyguardViewController, interactor = interactor, context = context, ) doAnswer { Loading @@ -83,11 +84,7 @@ class KeyguardSurfaceBehindParamsApplierTest : SysuiTestCase() { @Test fun testNotAnimating_setParamsWithNoAnimation() { underTest.viewParams = KeyguardSurfaceBehindModel( alpha = 0.3f, translationY = 300f, ) underTest.viewParams = KeyguardSurfaceBehindModel(alpha = 0.3f, translationY = 300f) // A surface has not yet been provided, so we shouldn't have set animating to false OR true // just yet. Loading packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardSurfaceBehindInteractor.kt +1 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ import kotlinx.coroutines.flow.onStart * Distance over which the surface behind the keyguard is animated in during a Y-translation * animation. */ const val SURFACE_TRANSLATION_Y_DISTANCE_DP = 250 const val SURFACE_TRANSLATION_Y_DISTANCE_DP = 200 @SysUISingleton class KeyguardSurfaceBehindInteractor Loading packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/SwipeToDismissInteractor.kt +14 −8 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn /** Loading @@ -52,13 +52,19 @@ constructor( */ val dismissFling: StateFlow<FlingInfo?> = shadeRepository.currentFling .filter { flingInfo -> .map { flingInfo -> if ( flingInfo != null && !flingInfo.expand && keyguardInteractor.statusBarState.value != StatusBarState.SHADE_LOCKED && transitionInteractor.startedKeyguardTransitionStep.value.to == KeyguardState.LOCKSCREEN && keyguardInteractor.isKeyguardDismissible.value ) { flingInfo } else { null } } .stateIn(backgroundScope, SharingStarted.Eagerly, null) } packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardSurfaceBehindParamsApplier.kt +59 −11 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.systemui.keyguard.ui.binder import android.animation.Animator import android.animation.AnimatorListenerAdapter import android.animation.ValueAnimator import android.content.Context import android.graphics.Matrix import android.util.Log import android.view.RemoteAnimationTarget Loading @@ -28,6 +29,7 @@ import android.view.View import androidx.dynamicanimation.animation.FloatValueHolder import androidx.dynamicanimation.animation.SpringAnimation import androidx.dynamicanimation.animation.SpringForce import com.android.internal.R import com.android.keyguard.KeyguardViewController import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Main Loading @@ -37,6 +39,16 @@ import com.android.systemui.keyguard.shared.model.KeyguardSurfaceBehindModel import com.android.wm.shell.shared.animation.Interpolators import java.util.concurrent.Executor import javax.inject.Inject import kotlin.math.max /** Damping ratio to use for animations resulting from touch gesture fling animation. */ private const val TOUCH_FLING_DAMPING_RATIO = 0.992f /** * Fastest swipe velocity we'll use for the spring animations. Higher values will result in an * unreasonable amount of overshoot. */ private const val FASTEST_SWIPE_VELOCITY = -21500f /** * Applies [KeyguardSurfaceBehindViewParams] to a RemoteAnimationTarget, starting and managing Loading @@ -49,6 +61,7 @@ constructor( @Main private val executor: Executor, private val keyguardViewController: KeyguardViewController, private val interactor: KeyguardSurfaceBehindInteractor, context: Context, ) { private var surfaceBehind: RemoteAnimationTarget? = null set(value) { Loading @@ -62,14 +75,12 @@ constructor( private val matrix = Matrix() private val tmpFloat = FloatArray(9) private val defaultSpring = SpringForce().apply { stiffness = 675f } private var animatedTranslationY = FloatValueHolder() private val translateYSpring = SpringAnimation(animatedTranslationY).apply { spring = SpringForce().apply { stiffness = 275f dampingRatio = 0.98f } spring = defaultSpring addUpdateListener { _, _, _ -> applyToSurfaceBehind() } addEndListener { _, _, _, _ -> try { Loading @@ -84,7 +95,7 @@ constructor( private var animatedAlpha = 0f private var alphaAnimator = ValueAnimator.ofFloat(0f, 1f).apply { duration = 150 duration = 125 interpolator = Interpolators.ALPHA_IN addUpdateListener { animatedAlpha = it.animatedValue as Float Loading @@ -99,6 +110,10 @@ constructor( ) } /** Rounded corner radius to apply to the surface behind the keyguard. */ private val roundedCornerRadius = context.resources.getDimensionPixelSize(R.dimen.rounded_corner_radius).toFloat() /** * ViewParams to apply to the surface provided to [applyParamsToSurface]. If the surface is null * these will be applied once someone gives us a surface via [applyParamsToSurface]. Loading Loading @@ -162,7 +177,15 @@ constructor( // If the spring isn't running yet, set the start value. Otherwise, respect the // current position. animatedTranslationY.value = viewParams.animateFromTranslationY translateYSpring.setStartVelocity(viewParams.startVelocity) translateYSpring.setStartVelocity( max(FASTEST_SWIPE_VELOCITY, viewParams.startVelocity) ) translateYSpring.setSpring( defaultSpring.apply { dampingRatio = if (viewParams.startVelocity > 0f) TOUCH_FLING_DAMPING_RATIO else 1f } ) } translateYSpring.animateToFinalPosition(viewParams.translationY) Loading @@ -182,7 +205,7 @@ constructor( Log.d( TAG, "Attempting to modify params of surface that isn't " + "animating. Ignoring." "animating. Ignoring.", ) matrix.set(Matrix.IDENTITY_MATRIX) return@execute Loading @@ -206,17 +229,42 @@ constructor( with(SurfaceControl.Transaction()) { setMatrix( sc, matrix.apply { setTranslate(/* dx= */ 0f, translationY) }, tmpFloat matrix.apply { setTranslate(/* dx= */ 0f, translationY) val percentTranslated = 1f - (animatedTranslationY.value / viewParams.animateFromTranslationY) setScale( 95f + (5f * percentTranslated), 95f + (5f * percentTranslated), surfaceBehind!!.screenSpaceBounds.width() / 2f, surfaceBehind!!.screenSpaceBounds.height() * .75f, ) }, tmpFloat, ) setAlpha(sc, alpha) setCornerRadius(sc, roundedCornerRadius) apply() } } else { val percentTranslated = 1f - (translationY / viewParams.animateFromTranslationY) surfaceTransactionApplier.scheduleApply( SyncRtSurfaceTransactionApplier.SurfaceParams.Builder(sc) .withMatrix(matrix.apply { setTranslate(/* dx= */ 0f, translationY) }) .withMatrix( matrix.apply { setScale( .93f + (.07f * percentTranslated), .93f + (.07f * percentTranslated), surfaceBehind!!.screenSpaceBounds.width() / 2f, surfaceBehind!!.screenSpaceBounds.height() * .66f, ) postTranslate(/* dx= */ 0f, translationY) } ) .withAlpha(alpha) .withCornerRadius(roundedCornerRadius) .build() ) } Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/keyguard/ui/binder/KeyguardSurfaceBehindParamsApplierTest.kt +2 −5 Original line number Diff line number Diff line Loading @@ -67,6 +67,7 @@ class KeyguardSurfaceBehindParamsApplierTest : SysuiTestCase() { executor = executor, keyguardViewController = keyguardViewController, interactor = interactor, context = context, ) doAnswer { Loading @@ -83,11 +84,7 @@ class KeyguardSurfaceBehindParamsApplierTest : SysuiTestCase() { @Test fun testNotAnimating_setParamsWithNoAnimation() { underTest.viewParams = KeyguardSurfaceBehindModel( alpha = 0.3f, translationY = 300f, ) underTest.viewParams = KeyguardSurfaceBehindModel(alpha = 0.3f, translationY = 300f) // A surface has not yet been provided, so we shouldn't have set animating to false OR true // just yet. Loading
packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/KeyguardSurfaceBehindInteractor.kt +1 −1 Original line number Diff line number Diff line Loading @@ -39,7 +39,7 @@ import kotlinx.coroutines.flow.onStart * Distance over which the surface behind the keyguard is animated in during a Y-translation * animation. */ const val SURFACE_TRANSLATION_Y_DISTANCE_DP = 250 const val SURFACE_TRANSLATION_Y_DISTANCE_DP = 200 @SysUISingleton class KeyguardSurfaceBehindInteractor Loading
packages/SystemUI/src/com/android/systemui/keyguard/domain/interactor/SwipeToDismissInteractor.kt +14 −8 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn /** Loading @@ -52,13 +52,19 @@ constructor( */ val dismissFling: StateFlow<FlingInfo?> = shadeRepository.currentFling .filter { flingInfo -> .map { flingInfo -> if ( flingInfo != null && !flingInfo.expand && keyguardInteractor.statusBarState.value != StatusBarState.SHADE_LOCKED && transitionInteractor.startedKeyguardTransitionStep.value.to == KeyguardState.LOCKSCREEN && keyguardInteractor.isKeyguardDismissible.value ) { flingInfo } else { null } } .stateIn(backgroundScope, SharingStarted.Eagerly, null) }
packages/SystemUI/src/com/android/systemui/keyguard/ui/binder/KeyguardSurfaceBehindParamsApplier.kt +59 −11 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ package com.android.systemui.keyguard.ui.binder import android.animation.Animator import android.animation.AnimatorListenerAdapter import android.animation.ValueAnimator import android.content.Context import android.graphics.Matrix import android.util.Log import android.view.RemoteAnimationTarget Loading @@ -28,6 +29,7 @@ import android.view.View import androidx.dynamicanimation.animation.FloatValueHolder import androidx.dynamicanimation.animation.SpringAnimation import androidx.dynamicanimation.animation.SpringForce import com.android.internal.R import com.android.keyguard.KeyguardViewController import com.android.systemui.dagger.SysUISingleton import com.android.systemui.dagger.qualifiers.Main Loading @@ -37,6 +39,16 @@ import com.android.systemui.keyguard.shared.model.KeyguardSurfaceBehindModel import com.android.wm.shell.shared.animation.Interpolators import java.util.concurrent.Executor import javax.inject.Inject import kotlin.math.max /** Damping ratio to use for animations resulting from touch gesture fling animation. */ private const val TOUCH_FLING_DAMPING_RATIO = 0.992f /** * Fastest swipe velocity we'll use for the spring animations. Higher values will result in an * unreasonable amount of overshoot. */ private const val FASTEST_SWIPE_VELOCITY = -21500f /** * Applies [KeyguardSurfaceBehindViewParams] to a RemoteAnimationTarget, starting and managing Loading @@ -49,6 +61,7 @@ constructor( @Main private val executor: Executor, private val keyguardViewController: KeyguardViewController, private val interactor: KeyguardSurfaceBehindInteractor, context: Context, ) { private var surfaceBehind: RemoteAnimationTarget? = null set(value) { Loading @@ -62,14 +75,12 @@ constructor( private val matrix = Matrix() private val tmpFloat = FloatArray(9) private val defaultSpring = SpringForce().apply { stiffness = 675f } private var animatedTranslationY = FloatValueHolder() private val translateYSpring = SpringAnimation(animatedTranslationY).apply { spring = SpringForce().apply { stiffness = 275f dampingRatio = 0.98f } spring = defaultSpring addUpdateListener { _, _, _ -> applyToSurfaceBehind() } addEndListener { _, _, _, _ -> try { Loading @@ -84,7 +95,7 @@ constructor( private var animatedAlpha = 0f private var alphaAnimator = ValueAnimator.ofFloat(0f, 1f).apply { duration = 150 duration = 125 interpolator = Interpolators.ALPHA_IN addUpdateListener { animatedAlpha = it.animatedValue as Float Loading @@ -99,6 +110,10 @@ constructor( ) } /** Rounded corner radius to apply to the surface behind the keyguard. */ private val roundedCornerRadius = context.resources.getDimensionPixelSize(R.dimen.rounded_corner_radius).toFloat() /** * ViewParams to apply to the surface provided to [applyParamsToSurface]. If the surface is null * these will be applied once someone gives us a surface via [applyParamsToSurface]. Loading Loading @@ -162,7 +177,15 @@ constructor( // If the spring isn't running yet, set the start value. Otherwise, respect the // current position. animatedTranslationY.value = viewParams.animateFromTranslationY translateYSpring.setStartVelocity(viewParams.startVelocity) translateYSpring.setStartVelocity( max(FASTEST_SWIPE_VELOCITY, viewParams.startVelocity) ) translateYSpring.setSpring( defaultSpring.apply { dampingRatio = if (viewParams.startVelocity > 0f) TOUCH_FLING_DAMPING_RATIO else 1f } ) } translateYSpring.animateToFinalPosition(viewParams.translationY) Loading @@ -182,7 +205,7 @@ constructor( Log.d( TAG, "Attempting to modify params of surface that isn't " + "animating. Ignoring." "animating. Ignoring.", ) matrix.set(Matrix.IDENTITY_MATRIX) return@execute Loading @@ -206,17 +229,42 @@ constructor( with(SurfaceControl.Transaction()) { setMatrix( sc, matrix.apply { setTranslate(/* dx= */ 0f, translationY) }, tmpFloat matrix.apply { setTranslate(/* dx= */ 0f, translationY) val percentTranslated = 1f - (animatedTranslationY.value / viewParams.animateFromTranslationY) setScale( 95f + (5f * percentTranslated), 95f + (5f * percentTranslated), surfaceBehind!!.screenSpaceBounds.width() / 2f, surfaceBehind!!.screenSpaceBounds.height() * .75f, ) }, tmpFloat, ) setAlpha(sc, alpha) setCornerRadius(sc, roundedCornerRadius) apply() } } else { val percentTranslated = 1f - (translationY / viewParams.animateFromTranslationY) surfaceTransactionApplier.scheduleApply( SyncRtSurfaceTransactionApplier.SurfaceParams.Builder(sc) .withMatrix(matrix.apply { setTranslate(/* dx= */ 0f, translationY) }) .withMatrix( matrix.apply { setScale( .93f + (.07f * percentTranslated), .93f + (.07f * percentTranslated), surfaceBehind!!.screenSpaceBounds.width() / 2f, surfaceBehind!!.screenSpaceBounds.height() * .66f, ) postTranslate(/* dx= */ 0f, translationY) } ) .withAlpha(alpha) .withCornerRadius(roundedCornerRadius) .build() ) } Loading