diff options
| author | 2024-10-08 07:34:43 +0000 | |
|---|---|---|
| committer | 2024-10-08 07:34:43 +0000 | |
| commit | d2ebbe2148d0faedae43c12822bc60d223530b3a (patch) | |
| tree | 2e48b9ead0e140f4f90bea99af19862ba0f2c451 | |
| parent | 175b32aaf501541366ff2d847d04020a7482c082 (diff) | |
| parent | ee335b206abeb31e27972230b5761bc8eb853191 (diff) | |
Merge "Enable and configure interruptions in Flexiglass" into main
3 files changed, 73 insertions, 1 deletions
diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneContainer.kt b/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneContainer.kt index 56de096effce..417f2b8922e4 100644 --- a/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneContainer.kt +++ b/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneContainer.kt @@ -81,7 +81,6 @@ fun SceneContainer( initialScene = initialSceneKey, canChangeScene = { toScene -> viewModel.canChangeScene(toScene) }, transitions = SceneContainerTransitions, - enableInterruptions = false, ) } diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneContainerInterruptionHandler.kt b/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneContainerInterruptionHandler.kt new file mode 100644 index 000000000000..7e99847a7200 --- /dev/null +++ b/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneContainerInterruptionHandler.kt @@ -0,0 +1,72 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.systemui.scene.ui.composable + +import com.android.compose.animation.scene.InterruptionHandler +import com.android.compose.animation.scene.InterruptionResult +import com.android.compose.animation.scene.SceneKey +import com.android.compose.animation.scene.content.state.TransitionState +import com.android.systemui.scene.shared.model.Scenes +import com.android.systemui.scene.ui.composable.transitions.TO_BOUNCER_FADE_FRACTION + +object SceneContainerInterruptionHandler : InterruptionHandler { + override fun onInterruption( + interrupted: TransitionState.Transition.ChangeScene, + newTargetScene: SceneKey, + ): InterruptionResult? { + return handleTransitionToGoneDuringTransitionToBouncer(interrupted, newTargetScene) + } + + /** + * Handle the case where we start transitioning to Bouncer but then we are interrupted to + * transition to Gone, for instance because face auth kicked in. + */ + private fun handleTransitionToGoneDuringTransitionToBouncer( + transition: TransitionState.Transition.ChangeScene, + targetScene: SceneKey, + ): InterruptionResult? { + if (targetScene != Scenes.Gone || !transition.isTransitioningFromOrTo(Scenes.Bouncer)) { + return null + } + + // Animate Bouncer => Gone only when the bouncer is fully opaque, otherwise animate + // OtherScene => Gone and reverse the OtherScene => Bouncer transition (note: OtherScene is + // usually the Lockscreen scene). + val otherScene: SceneKey + val animatesFromBouncer = + if (transition.isTransitioning(to = Scenes.Bouncer)) { + otherScene = transition.fromScene + transition.progress >= TO_BOUNCER_FADE_FRACTION + } else { + otherScene = transition.toScene + transition.progress <= 1f - TO_BOUNCER_FADE_FRACTION + } + + return if (animatesFromBouncer) { + InterruptionResult( + animateFrom = Scenes.Bouncer, + + // We don't want the content of the lockscreen to be shown during the Bouncer => + // Launcher transition. We disable chaining of the transitions so that only the + // Bouncer and Launcher scenes are composed. + chain = false, + ) + } else { + InterruptionResult(animateFrom = otherScene) + } + } +} diff --git a/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneContainerTransitions.kt b/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneContainerTransitions.kt index 8728521348de..dc545b8bf7c2 100644 --- a/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneContainerTransitions.kt +++ b/packages/SystemUI/compose/features/src/com/android/systemui/scene/ui/composable/SceneContainerTransitions.kt @@ -46,6 +46,7 @@ import com.android.systemui.shade.ui.composable.Shade * Please keep the list sorted alphabetically. */ val SceneContainerTransitions = transitions { + interruptionHandler = SceneContainerInterruptionHandler // Overscroll progress starts linearly with some resistance (3f) and slowly approaches 0.2f defaultOverscrollProgressConverter = ProgressConverter.tanh(maxProgress = 0.2f, tilt = 3f) |