Merge changes I1dbd1fd7,I4fb6c38d into tm-qpr-dev

* changes:
  Power scrim reveal - adjust for rotation
  Bouncer - Remove cases that forced it to stay open
This commit is contained in:
Matt Pietal
2022-11-12 11:48:02 +00:00
committed by Android (Google) Code Review
3 changed files with 97 additions and 61 deletions

View File

@@ -18,6 +18,8 @@ import android.view.View
import com.android.systemui.animation.Interpolators import com.android.systemui.animation.Interpolators
import com.android.systemui.statusbar.LightRevealEffect.Companion.getPercentPastThreshold import com.android.systemui.statusbar.LightRevealEffect.Companion.getPercentPastThreshold
import com.android.systemui.util.getColorWithAlpha import com.android.systemui.util.getColorWithAlpha
import com.android.systemui.util.leak.RotationUtils
import com.android.systemui.util.leak.RotationUtils.Rotation
import java.util.function.Consumer import java.util.function.Consumer
/** /**
@@ -72,17 +74,14 @@ object LiftReveal : LightRevealEffect {
val initialWidthMultiplier = (1f - OVAL_INITIAL_WIDTH_PERCENT) / 2f val initialWidthMultiplier = (1f - OVAL_INITIAL_WIDTH_PERCENT) / 2f
with(scrim) { with(scrim) {
revealGradientEndColorAlpha = 1f - getPercentPastThreshold( revealGradientEndColorAlpha =
amount, FADE_END_COLOR_OUT_THRESHOLD) 1f - getPercentPastThreshold(amount, FADE_END_COLOR_OUT_THRESHOLD)
setRevealGradientBounds( setRevealGradientBounds(
scrim.width * initialWidthMultiplier + scrim.width * initialWidthMultiplier + -scrim.width * ovalWidthIncreaseAmount,
-scrim.width * ovalWidthIncreaseAmount, scrim.height * OVAL_INITIAL_TOP_PERCENT - scrim.height * interpolatedAmount,
scrim.height * OVAL_INITIAL_TOP_PERCENT - scrim.width * (1f - initialWidthMultiplier) + scrim.width * ovalWidthIncreaseAmount,
scrim.height * interpolatedAmount, scrim.height * OVAL_INITIAL_BOTTOM_PERCENT + scrim.height * interpolatedAmount
scrim.width * (1f - initialWidthMultiplier) + )
scrim.width * ovalWidthIncreaseAmount,
scrim.height * OVAL_INITIAL_BOTTOM_PERCENT +
scrim.height * interpolatedAmount)
} }
} }
} }
@@ -97,12 +96,17 @@ class LinearLightRevealEffect(private val isVertical: Boolean) : LightRevealEffe
scrim.interpolatedRevealAmount = interpolatedAmount scrim.interpolatedRevealAmount = interpolatedAmount
scrim.startColorAlpha = scrim.startColorAlpha =
getPercentPastThreshold(1 - interpolatedAmount, getPercentPastThreshold(
threshold = 1 - START_COLOR_REVEAL_PERCENTAGE) 1 - interpolatedAmount,
threshold = 1 - START_COLOR_REVEAL_PERCENTAGE
)
scrim.revealGradientEndColorAlpha = scrim.revealGradientEndColorAlpha =
1f - getPercentPastThreshold(interpolatedAmount, 1f -
threshold = REVEAL_GRADIENT_END_COLOR_ALPHA_START_PERCENTAGE) getPercentPastThreshold(
interpolatedAmount,
threshold = REVEAL_GRADIENT_END_COLOR_ALPHA_START_PERCENTAGE
)
// Start changing gradient bounds later to avoid harsh gradient in the beginning // Start changing gradient bounds later to avoid harsh gradient in the beginning
val gradientBoundsAmount = lerp(GRADIENT_START_BOUNDS_PERCENTAGE, 1.0f, interpolatedAmount) val gradientBoundsAmount = lerp(GRADIENT_START_BOUNDS_PERCENTAGE, 1.0f, interpolatedAmount)
@@ -179,7 +183,7 @@ class PowerButtonReveal(
*/ */
private val OFF_SCREEN_START_AMOUNT = 0.05f private val OFF_SCREEN_START_AMOUNT = 0.05f
private val WIDTH_INCREASE_MULTIPLIER = 1.25f private val INCREASE_MULTIPLIER = 1.25f
override fun setRevealAmountOnScrim(amount: Float, scrim: LightRevealScrim) { override fun setRevealAmountOnScrim(amount: Float, scrim: LightRevealScrim) {
val interpolatedAmount = Interpolators.FAST_OUT_SLOW_IN_REVERSE.getInterpolation(amount) val interpolatedAmount = Interpolators.FAST_OUT_SLOW_IN_REVERSE.getInterpolation(amount)
@@ -188,15 +192,36 @@ class PowerButtonReveal(
with(scrim) { with(scrim) {
revealGradientEndColorAlpha = 1f - fadeAmount revealGradientEndColorAlpha = 1f - fadeAmount
interpolatedRevealAmount = interpolatedAmount interpolatedRevealAmount = interpolatedAmount
@Rotation val rotation = RotationUtils.getRotation(scrim.getContext())
if (rotation == RotationUtils.ROTATION_NONE) {
setRevealGradientBounds( setRevealGradientBounds(
width * (1f + OFF_SCREEN_START_AMOUNT) - width * (1f + OFF_SCREEN_START_AMOUNT) -
width * WIDTH_INCREASE_MULTIPLIER * interpolatedAmount, width * INCREASE_MULTIPLIER * interpolatedAmount,
powerButtonY - powerButtonY - height * interpolatedAmount,
height * interpolatedAmount,
width * (1f + OFF_SCREEN_START_AMOUNT) + width * (1f + OFF_SCREEN_START_AMOUNT) +
width * WIDTH_INCREASE_MULTIPLIER * interpolatedAmount, width * INCREASE_MULTIPLIER * interpolatedAmount,
powerButtonY + powerButtonY + height * interpolatedAmount
height * interpolatedAmount) )
} else if (rotation == RotationUtils.ROTATION_LANDSCAPE) {
setRevealGradientBounds(
powerButtonY - width * interpolatedAmount,
(-height * OFF_SCREEN_START_AMOUNT) -
height * INCREASE_MULTIPLIER * interpolatedAmount,
powerButtonY + width * interpolatedAmount,
(-height * OFF_SCREEN_START_AMOUNT) +
height * INCREASE_MULTIPLIER * interpolatedAmount
)
} else {
// RotationUtils.ROTATION_SEASCAPE
setRevealGradientBounds(
(width - powerButtonY) - width * interpolatedAmount,
height * (1f + OFF_SCREEN_START_AMOUNT) -
height * INCREASE_MULTIPLIER * interpolatedAmount,
(width - powerButtonY) + width * interpolatedAmount,
height * (1f + OFF_SCREEN_START_AMOUNT) +
height * INCREASE_MULTIPLIER * interpolatedAmount
)
}
} }
} }
} }
@@ -208,9 +233,7 @@ class PowerButtonReveal(
*/ */
class LightRevealScrim(context: Context?, attrs: AttributeSet?) : View(context, attrs) { class LightRevealScrim(context: Context?, attrs: AttributeSet?) : View(context, attrs) {
/** /** Listener that is called if the scrim's opaqueness changes */
* Listener that is called if the scrim's opaqueness changes
*/
lateinit var isScrimOpaqueChangedListener: Consumer<Boolean> lateinit var isScrimOpaqueChangedListener: Consumer<Boolean>
/** /**
@@ -224,8 +247,11 @@ class LightRevealScrim(context: Context?, attrs: AttributeSet?) : View(context,
revealEffect.setRevealAmountOnScrim(value, this) revealEffect.setRevealAmountOnScrim(value, this)
updateScrimOpaque() updateScrimOpaque()
Trace.traceCounter(Trace.TRACE_TAG_APP, "light_reveal_amount", Trace.traceCounter(
(field * 100).toInt()) Trace.TRACE_TAG_APP,
"light_reveal_amount",
(field * 100).toInt()
)
invalidate() invalidate()
} }
} }
@@ -250,10 +276,10 @@ class LightRevealScrim(context: Context?, attrs: AttributeSet?) : View(context,
/** /**
* Alpha of the fill that can be used in the beginning of the animation to hide the content. * Alpha of the fill that can be used in the beginning of the animation to hide the content.
* Normally the gradient bounds are animated from small size so the content is not visible, * Normally the gradient bounds are animated from small size so the content is not visible, but
* but if the start gradient bounds allow to see some content this could be used to make the * if the start gradient bounds allow to see some content this could be used to make the reveal
* reveal smoother. It can help to add fade in effect in the beginning of the animation. * smoother. It can help to add fade in effect in the beginning of the animation. The color of
* The color of the fill is determined by [revealGradientEndColor]. * the fill is determined by [revealGradientEndColor].
* *
* 0 - no fill and content is visible, 1 - the content is covered with the start color * 0 - no fill and content is visible, 1 - the content is covered with the start color
*/ */
@@ -281,9 +307,7 @@ class LightRevealScrim(context: Context?, attrs: AttributeSet?) : View(context,
} }
} }
/** /** Is the scrim currently fully opaque */
* Is the scrim currently fully opaque
*/
var isScrimOpaque = false var isScrimOpaque = false
private set(value) { private set(value) {
if (field != value) { if (field != value) {
@@ -318,11 +342,17 @@ class LightRevealScrim(context: Context?, attrs: AttributeSet?) : View(context,
* Paint used to draw a transparent-to-white radial gradient. This will be scaled and translated * Paint used to draw a transparent-to-white radial gradient. This will be scaled and translated
* via local matrix in [onDraw] so we never need to construct a new shader. * via local matrix in [onDraw] so we never need to construct a new shader.
*/ */
private val gradientPaint = Paint().apply { private val gradientPaint =
shader = RadialGradient( Paint().apply {
0f, 0f, 1f, shader =
intArrayOf(Color.TRANSPARENT, Color.WHITE), floatArrayOf(0f, 1f), RadialGradient(
Shader.TileMode.CLAMP) 0f,
0f,
1f,
intArrayOf(Color.TRANSPARENT, Color.WHITE),
floatArrayOf(0f, 1f),
Shader.TileMode.CLAMP
)
// SRC_OVER ensures that we draw the semitransparent pixels over other views in the same // SRC_OVER ensures that we draw the semitransparent pixels over other views in the same
// window, rather than outright replacing them. // window, rather than outright replacing them.
@@ -347,8 +377,8 @@ class LightRevealScrim(context: Context?, attrs: AttributeSet?) : View(context,
* simply a helper method that sets [revealGradientCenter], [revealGradientWidth], and * simply a helper method that sets [revealGradientCenter], [revealGradientWidth], and
* [revealGradientHeight] for you. * [revealGradientHeight] for you.
* *
* This method does not call [invalidate] - you should do so once you're done changing * This method does not call [invalidate]
* properties. * - you should do so once you're done changing properties.
*/ */
fun setRevealGradientBounds(left: Float, top: Float, right: Float, bottom: Float) { fun setRevealGradientBounds(left: Float, top: Float, right: Float, bottom: Float) {
revealGradientWidth = right - left revealGradientWidth = right - left
@@ -359,8 +389,12 @@ class LightRevealScrim(context: Context?, attrs: AttributeSet?) : View(context,
} }
override fun onDraw(canvas: Canvas?) { override fun onDraw(canvas: Canvas?) {
if (canvas == null || revealGradientWidth <= 0 || revealGradientHeight <= 0 || if (
revealAmount == 0f) { canvas == null ||
revealGradientWidth <= 0 ||
revealGradientHeight <= 0 ||
revealAmount == 0f
) {
if (revealAmount < 1f) { if (revealAmount < 1f) {
canvas?.drawColor(revealGradientEndColor) canvas?.drawColor(revealGradientEndColor)
} }
@@ -383,8 +417,10 @@ class LightRevealScrim(context: Context?, attrs: AttributeSet?) : View(context,
} }
private fun setPaintColorFilter() { private fun setPaintColorFilter() {
gradientPaint.colorFilter = PorterDuffColorFilter( gradientPaint.colorFilter =
PorterDuffColorFilter(
getColorWithAlpha(revealGradientEndColor, revealGradientEndColorAlpha), getColorWithAlpha(revealGradientEndColor, revealGradientEndColorAlpha),
PorterDuff.Mode.MULTIPLY) PorterDuff.Mode.MULTIPLY
)
} }
} }

View File

@@ -469,7 +469,7 @@ public class StatusBarKeyguardViewManager implements RemoteInputController.Callb
// Don't expand to the bouncer. Instead transition back to the lock screen (see // Don't expand to the bouncer. Instead transition back to the lock screen (see
// CentralSurfaces#showBouncerOrLockScreenIfKeyguard) // CentralSurfaces#showBouncerOrLockScreenIfKeyguard)
return; return;
} else if (primaryBouncerNeedsScrimming()) { } else if (needsFullscreenBouncer()) {
if (mPrimaryBouncer != null) { if (mPrimaryBouncer != null) {
mPrimaryBouncer.setExpansion(KeyguardBouncer.EXPANSION_VISIBLE); mPrimaryBouncer.setExpansion(KeyguardBouncer.EXPANSION_VISIBLE);
} else { } else {

View File

@@ -222,9 +222,16 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
} }
@Test @Test
public void onPanelExpansionChanged_neverHidesScrimmedBouncer() { public void onPanelExpansionChanged_neverHidesFullscreenBouncer() {
when(mPrimaryBouncer.isShowing()).thenReturn(true); when(mPrimaryBouncer.isShowing()).thenReturn(true);
when(mPrimaryBouncer.isScrimmed()).thenReturn(true); when(mKeyguardSecurityModel.getSecurityMode(anyInt())).thenReturn(
KeyguardSecurityModel.SecurityMode.SimPuk);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
verify(mPrimaryBouncer).setExpansion(eq(KeyguardBouncer.EXPANSION_VISIBLE));
reset(mPrimaryBouncer);
when(mKeyguardSecurityModel.getSecurityMode(anyInt())).thenReturn(
KeyguardSecurityModel.SecurityMode.SimPin);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT); mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
verify(mPrimaryBouncer).setExpansion(eq(KeyguardBouncer.EXPANSION_VISIBLE)); verify(mPrimaryBouncer).setExpansion(eq(KeyguardBouncer.EXPANSION_VISIBLE));
} }
@@ -270,13 +277,6 @@ public class StatusBarKeyguardViewManagerTest extends SysuiTestCase {
verify(mPrimaryBouncer, never()).show(eq(false), eq(false)); verify(mPrimaryBouncer, never()).show(eq(false), eq(false));
} }
@Test
public void onPanelExpansionChanged_neverTranslatesBouncerWhenOccluded() {
mStatusBarKeyguardViewManager.setOccluded(true /* occluded */, false /* animate */);
mStatusBarKeyguardViewManager.onPanelExpansionChanged(EXPANSION_EVENT);
verify(mPrimaryBouncer, never()).setExpansion(eq(0.5f));
}
@Test @Test
public void onPanelExpansionChanged_neverTranslatesBouncerWhenWakeAndUnlock() { public void onPanelExpansionChanged_neverTranslatesBouncerWhenWakeAndUnlock() {
when(mBiometricUnlockController.getMode()) when(mBiometricUnlockController.getMode())