From 22105c51acec88fefb66b00e9a84b3df145832c0 Mon Sep 17 00:00:00 2001 From: Nick Chameyev Date: Mon, 16 Jan 2023 17:43:36 +0000 Subject: [Unfold animation] Do not show dark vignette when folding Disables darkening of the screen when folding a foldable device. It still adds the unfold overlay to block touches but it is transparent. Bug: 265420547 Test: manual folding/unfolding Change-Id: Icd054ee62a7993fd2804b373005c3bab4e396d62 --- .../src/com/android/systemui/flags/Flags.kt | 7 ++++ .../unfold/UnfoldLightRevealOverlayAnimation.kt | 39 ++++++++++++++++++---- 2 files changed, 40 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/flags/Flags.kt b/packages/SystemUI/src/com/android/systemui/flags/Flags.kt index 432fae124c9b..025fde71594d 100644 --- a/packages/SystemUI/src/com/android/systemui/flags/Flags.kt +++ b/packages/SystemUI/src/com/android/systemui/flags/Flags.kt @@ -530,6 +530,13 @@ object Flags { val OUTPUT_SWITCHER_SHOW_API_ENABLED = unreleasedFlag(2503, "output_switcher_show_api_enabled", teamfood = true) + // 2600 - unfold transitions + // TODO(b/265764985): Tracking Bug + @Keep + @JvmField + val ENABLE_DARK_VIGNETTE_WHEN_FOLDING = + unreleasedFlag(2600, "enable_dark_vignette_when_folding") + // TODO(b259590361): Tracking bug val EXPERIMENTAL_FLAG = unreleasedFlag(2, "exp_flag_release") } diff --git a/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt b/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt index 523cf68891a0..0069bb545ef4 100644 --- a/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt +++ b/packages/SystemUI/src/com/android/systemui/unfold/UnfoldLightRevealOverlayAnimation.kt @@ -36,6 +36,8 @@ import android.view.SurfaceSession import android.view.WindowManager import android.view.WindowlessWindowManager import com.android.systemui.dagger.qualifiers.Main +import com.android.systemui.flags.FeatureFlags +import com.android.systemui.flags.Flags import com.android.systemui.statusbar.LightRevealEffect import com.android.systemui.statusbar.LightRevealScrim import com.android.systemui.statusbar.LinearLightRevealEffect @@ -57,6 +59,7 @@ class UnfoldLightRevealOverlayAnimation @Inject constructor( private val context: Context, + private val featureFlags: FeatureFlags, private val deviceStateManager: DeviceStateManager, private val contentResolver: ContentResolver, private val displayManager: DisplayManager, @@ -81,6 +84,7 @@ constructor( private var scrimView: LightRevealScrim? = null private var isFolded: Boolean = false private var isUnfoldHandled: Boolean = true + private var overlayAddReason: AddOverlayReason? = null private var currentRotation: Int = context.display!!.rotation @@ -158,6 +162,8 @@ constructor( ensureInBackground() ensureOverlayRemoved() + overlayAddReason = reason + val newRoot = SurfaceControlViewHost(context, context.display!!, wwm) val params = getLayoutParams() val newView = @@ -170,11 +176,7 @@ constructor( .apply { revealEffect = createLightRevealEffect() isScrimOpaqueChangedListener = Consumer {} - revealAmount = - when (reason) { - FOLD -> TRANSPARENT - UNFOLD -> BLACK - } + revealAmount = calculateRevealAmount() } newRoot.setView(newView, params) @@ -207,6 +209,31 @@ constructor( root = newRoot } + private fun calculateRevealAmount(animationProgress: Float? = null): Float { + val overlayAddReason = overlayAddReason ?: UNFOLD + + if (animationProgress == null) { + // Animation progress is unknown, calculate the initial value based on the overlay + // add reason + return when (overlayAddReason) { + FOLD -> TRANSPARENT + UNFOLD -> BLACK + } + } + + val showVignetteWhenFolding = + featureFlags.isEnabled(Flags.ENABLE_DARK_VIGNETTE_WHEN_FOLDING) + + return if (!showVignetteWhenFolding && overlayAddReason == FOLD) { + // Do not darken the content when SHOW_VIGNETTE_WHEN_FOLDING flag is off + // and we are folding the device. We still add the overlay to block touches + // while the animation is running but the overlay is transparent. + TRANSPARENT + } else { + animationProgress + } + } + private fun getLayoutParams(): WindowManager.LayoutParams { val params: WindowManager.LayoutParams = WindowManager.LayoutParams() @@ -259,7 +286,7 @@ constructor( private inner class TransitionListener : TransitionProgressListener { override fun onTransitionProgress(progress: Float) { - executeInBackground { scrimView?.revealAmount = progress } + executeInBackground { scrimView?.revealAmount = calculateRevealAmount(progress) } } override fun onTransitionFinished() { -- cgit v1.2.3-59-g8ed1b