Merge "Fix opacity of expanded shade during transitions"
This commit is contained in:
committed by
Android (Google) Code Review
commit
d91f35fb96
@@ -138,7 +138,8 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
|
||||
protected float mScrimBehindAlphaKeyguard = SCRIM_BEHIND_ALPHA_KEYGUARD;
|
||||
protected float mScrimBehindAlphaUnlocking = SCRIM_BEHIND_ALPHA_UNLOCKING;
|
||||
|
||||
private float mFraction;
|
||||
// Assuming the shade is expanded during initialization
|
||||
private float mExpansionFraction = 1f;
|
||||
|
||||
private boolean mDarkenWhileDragging;
|
||||
protected boolean mAnimateChange;
|
||||
@@ -251,6 +252,7 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
|
||||
mCurrentBehindTint = state.getBehindTint();
|
||||
mCurrentInFrontAlpha = state.getFrontAlpha();
|
||||
mCurrentBehindAlpha = state.getBehindAlpha();
|
||||
applyExpansionToAlpha();
|
||||
|
||||
// Cancel blanking transitions that were pending before we requested a new state
|
||||
if (mPendingFrameCallback != null) {
|
||||
@@ -362,45 +364,50 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
|
||||
* @param fraction From 0 to 1 where 0 means collapse and 1 expanded.
|
||||
*/
|
||||
public void setPanelExpansion(float fraction) {
|
||||
if (mFraction != fraction) {
|
||||
mFraction = fraction;
|
||||
if (mExpansionFraction != fraction) {
|
||||
mExpansionFraction = fraction;
|
||||
|
||||
if (mState == ScrimState.UNLOCKED) {
|
||||
// Darken scrim as you pull down the shade when unlocked
|
||||
float behindFraction = getInterpolatedFraction();
|
||||
behindFraction = (float) Math.pow(behindFraction, 0.8f);
|
||||
mCurrentBehindAlpha = behindFraction * mScrimBehindAlphaKeyguard;
|
||||
mCurrentInFrontAlpha = 0;
|
||||
} else if (mState == ScrimState.KEYGUARD) {
|
||||
if (mUpdatePending) {
|
||||
return;
|
||||
}
|
||||
if (!(mState == ScrimState.UNLOCKED || mState == ScrimState.KEYGUARD)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Either darken of make the scrim transparent when you
|
||||
// pull down the shade
|
||||
float interpolatedFract = getInterpolatedFraction();
|
||||
if (mDarkenWhileDragging) {
|
||||
mCurrentBehindAlpha = MathUtils.lerp(mScrimBehindAlphaUnlocking,
|
||||
mScrimBehindAlphaKeyguard, interpolatedFract);
|
||||
mCurrentInFrontAlpha = (1f - interpolatedFract) * SCRIM_IN_FRONT_ALPHA_LOCKED;
|
||||
} else {
|
||||
mCurrentBehindAlpha = MathUtils.lerp(0 /* start */, mScrimBehindAlphaKeyguard,
|
||||
interpolatedFract);
|
||||
mCurrentInFrontAlpha = 0;
|
||||
}
|
||||
} else {
|
||||
applyExpansionToAlpha();
|
||||
|
||||
if (mUpdatePending) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mPinnedHeadsUpCount != 0) {
|
||||
updateHeadsUpScrim(false);
|
||||
}
|
||||
|
||||
updateScrim(false /* animate */, mScrimInFront, mCurrentInFrontAlpha);
|
||||
updateScrim(false /* animate */, mScrimBehind, mCurrentBehindAlpha);
|
||||
}
|
||||
}
|
||||
|
||||
private void applyExpansionToAlpha() {
|
||||
if (mState == ScrimState.UNLOCKED) {
|
||||
// Darken scrim as you pull down the shade when unlocked
|
||||
float behindFraction = getInterpolatedFraction();
|
||||
behindFraction = (float) Math.pow(behindFraction, 0.8f);
|
||||
mCurrentBehindAlpha = behindFraction * mScrimBehindAlphaKeyguard;
|
||||
mCurrentInFrontAlpha = 0;
|
||||
} else if (mState == ScrimState.KEYGUARD) {
|
||||
// Either darken of make the scrim transparent when you
|
||||
// pull down the shade
|
||||
float interpolatedFract = getInterpolatedFraction();
|
||||
if (mDarkenWhileDragging) {
|
||||
mCurrentBehindAlpha = MathUtils.lerp(mScrimBehindAlphaUnlocking,
|
||||
mScrimBehindAlphaKeyguard, interpolatedFract);
|
||||
mCurrentInFrontAlpha = (1f - interpolatedFract) * SCRIM_IN_FRONT_ALPHA_LOCKED;
|
||||
} else {
|
||||
mCurrentBehindAlpha = MathUtils.lerp(0 /* start */, mScrimBehindAlphaKeyguard,
|
||||
interpolatedFract);
|
||||
mCurrentInFrontAlpha = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Keyguard and shade scrim opacity varies according to how many notifications are visible.
|
||||
* @param notificationCount Number of visible notifications.
|
||||
@@ -496,7 +503,7 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
|
||||
}
|
||||
|
||||
private float getInterpolatedFraction() {
|
||||
float frac = mFraction;
|
||||
float frac = mExpansionFraction;
|
||||
// let's start this 20% of the way down the screen
|
||||
frac = frac * 1.2f - 0.2f;
|
||||
if (frac <= 0) {
|
||||
@@ -825,7 +832,7 @@ public class ScrimController implements ViewTreeObserver.OnPreDrawListener,
|
||||
} else {
|
||||
alpha = 1.0f - mTopHeadsUpDragAmount;
|
||||
}
|
||||
float expandFactor = (1.0f - mFraction);
|
||||
float expandFactor = (1.0f - mExpansionFraction);
|
||||
expandFactor = Math.max(expandFactor, 0.0f);
|
||||
return alpha * expandFactor;
|
||||
}
|
||||
|
||||
@@ -180,6 +180,7 @@ public class ScrimControllerTest extends SysuiTestCase {
|
||||
|
||||
@Test
|
||||
public void transitionToUnlocked() {
|
||||
mScrimController.setPanelExpansion(0f);
|
||||
mScrimController.transitionTo(ScrimState.UNLOCKED);
|
||||
mScrimController.finishAnimationsImmediately();
|
||||
// Front scrim should be transparent
|
||||
@@ -197,6 +198,7 @@ public class ScrimControllerTest extends SysuiTestCase {
|
||||
public void transitionToUnlockedFromAod() {
|
||||
// Simulate unlock with fingerprint
|
||||
mScrimController.transitionTo(ScrimState.AOD);
|
||||
mScrimController.setPanelExpansion(0f);
|
||||
mScrimController.finishAnimationsImmediately();
|
||||
mScrimController.transitionTo(ScrimState.UNLOCKED);
|
||||
// Immediately tinted after the transition starts
|
||||
@@ -324,6 +326,23 @@ public class ScrimControllerTest extends SysuiTestCase {
|
||||
verify(mAlarmManager).cancel(any(AlarmManager.OnAlarmListener.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConservesExpansionOpacityAfterTransition() {
|
||||
mScrimController.transitionTo(ScrimState.UNLOCKED);
|
||||
mScrimController.setPanelExpansion(0.5f);
|
||||
mScrimController.finishAnimationsImmediately();
|
||||
|
||||
final float expandedAlpha = mScrimBehind.getViewAlpha();
|
||||
|
||||
mScrimController.transitionTo(ScrimState.BRIGHTNESS_MIRROR);
|
||||
mScrimController.finishAnimationsImmediately();
|
||||
mScrimController.transitionTo(ScrimState.UNLOCKED);
|
||||
mScrimController.finishAnimationsImmediately();
|
||||
|
||||
Assert.assertEquals("Scrim expansion opacity wasn't conserved when transitioning back",
|
||||
expandedAlpha, mScrimBehind.getViewAlpha(), 0.01f);
|
||||
}
|
||||
|
||||
private void assertScrimTint(ScrimView scrimView, boolean tinted) {
|
||||
final boolean viewIsTinted = scrimView.getTint() != Color.TRANSPARENT;
|
||||
final String name = scrimView == mScrimInFront ? "front" : "back";
|
||||
|
||||
Reference in New Issue
Block a user