Merge "Fade in/out UDFPS when dialogs show/hide" into tm-dev am: 08d40fc88a

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/16987142

Change-Id: Ibc34a6bde095cdd525e9c84f6d2b3726afcf0b66
This commit is contained in:
Beverly Tai
2022-03-01 13:14:02 +00:00
committed by Automerger Merge Worker
4 changed files with 107 additions and 17 deletions

View File

@@ -34,8 +34,10 @@ import android.widget.FrameLayout;
* - optionally can override dozeTimeTick to adjust views for burn-in mitigation * - optionally can override dozeTimeTick to adjust views for burn-in mitigation
*/ */
public abstract class UdfpsAnimationView extends FrameLayout { public abstract class UdfpsAnimationView extends FrameLayout {
// mAlpha takes into consideration the status bar expansion amount to fade out icon when private float mDialogSuggestedAlpha = 1f;
// the status bar is expanded private float mNotificationShadeExpansion = 0f;
// mAlpha takes into consideration the status bar expansion amount and dialog suggested alpha
private int mAlpha; private int mAlpha;
boolean mPauseAuth; boolean mPauseAuth;
@@ -92,6 +94,10 @@ public abstract class UdfpsAnimationView extends FrameLayout {
} }
int calculateAlpha() { int calculateAlpha() {
int alpha = expansionToAlpha(mNotificationShadeExpansion);
alpha *= mDialogSuggestedAlpha;
mAlpha = alpha;
return mPauseAuth ? mAlpha : 255; return mPauseAuth ? mAlpha : 255;
} }
@@ -111,8 +117,26 @@ public abstract class UdfpsAnimationView extends FrameLayout {
return (int) ((1 - percent) * 255); return (int) ((1 - percent) * 255);
} }
/**
* Set the suggested alpha based on whether a dialog was recently shown or hidden.
* @param dialogSuggestedAlpha value from 0f to 1f.
*/
public void setDialogSuggestedAlpha(float dialogSuggestedAlpha) {
mDialogSuggestedAlpha = dialogSuggestedAlpha;
updateAlpha();
}
public float getDialogSuggestedAlpha() {
return mDialogSuggestedAlpha;
}
/**
* Sets the amount the notification shade is expanded. This will influence the opacity of the
* this visual affordance.
* @param expansion amount the shade has expanded from 0f to 1f.
*/
public void onExpansionChanged(float expansion) { public void onExpansionChanged(float expansion) {
mAlpha = expansionToAlpha(expansion); mNotificationShadeExpansion = expansion;
updateAlpha(); updateAlpha();
} }

View File

@@ -15,10 +15,12 @@
*/ */
package com.android.systemui.biometrics package com.android.systemui.biometrics
import android.animation.ValueAnimator
import android.graphics.PointF import android.graphics.PointF
import android.graphics.RectF import android.graphics.RectF
import com.android.systemui.Dumpable import com.android.systemui.Dumpable
import com.android.systemui.dump.DumpManager import com.android.systemui.dump.DumpManager
import com.android.systemui.animation.Interpolators
import com.android.systemui.plugins.statusbar.StatusBarStateController import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.statusbar.phone.SystemUIDialogManager import com.android.systemui.statusbar.phone.SystemUIDialogManager
import com.android.systemui.statusbar.phone.panelstate.PanelExpansionListener import com.android.systemui.statusbar.phone.panelstate.PanelExpansionListener
@@ -50,7 +52,8 @@ abstract class UdfpsAnimationViewController<T : UdfpsAnimationView>(
private val view: T private val view: T
get() = mView!! get() = mView!!
private val dialogListener = SystemUIDialogManager.Listener { updatePauseAuth() } private var dialogAlphaAnimator: ValueAnimator? = null
private val dialogListener = SystemUIDialogManager.Listener { runDialogAlphaAnimator() }
private val panelExpansionListener = private val panelExpansionListener =
PanelExpansionListener { fraction, expanded, tracking -> PanelExpansionListener { fraction, expanded, tracking ->
@@ -83,6 +86,29 @@ abstract class UdfpsAnimationViewController<T : UdfpsAnimationView>(
*/ */
open val paddingY: Int = 0 open val paddingY: Int = 0
open fun updateAlpha() {
view.updateAlpha()
}
fun runDialogAlphaAnimator() {
val hideAffordance = dialogManager.shouldHideAffordance()
dialogAlphaAnimator?.cancel()
dialogAlphaAnimator = ValueAnimator.ofFloat(
view.calculateAlpha() / 255f,
if (hideAffordance) 0f else 1f)
.apply {
duration = if (hideAffordance) 83L else 200L
interpolator = if (hideAffordance) Interpolators.LINEAR else Interpolators.ALPHA_IN
addUpdateListener { animatedValue ->
view.setDialogSuggestedAlpha(animatedValue.animatedValue as Float)
updateAlpha()
updatePauseAuth()
}
start()
}
}
override fun onViewAttached() { override fun onViewAttached() {
panelExpansionStateManager.addExpansionListener(panelExpansionListener) panelExpansionStateManager.addExpansionListener(panelExpansionListener)
dialogManager.registerListener(dialogListener) dialogManager.registerListener(dialogListener)
@@ -106,6 +132,7 @@ abstract class UdfpsAnimationViewController<T : UdfpsAnimationView>(
pw.println("mNotificationShadeVisible=$notificationShadeVisible") pw.println("mNotificationShadeVisible=$notificationShadeVisible")
pw.println("shouldPauseAuth()=" + shouldPauseAuth()) pw.println("shouldPauseAuth()=" + shouldPauseAuth())
pw.println("isPauseAuth=" + view.isPauseAuth) pw.println("isPauseAuth=" + view.isPauseAuth)
pw.println("dialogSuggestedAlpha=" + view.dialogSuggestedAlpha)
} }
/** /**

View File

@@ -28,6 +28,7 @@ import android.view.MotionEvent;
import com.android.keyguard.KeyguardUpdateMonitor; import com.android.keyguard.KeyguardUpdateMonitor;
import com.android.systemui.R; import com.android.systemui.R;
import com.android.systemui.animation.ActivityLaunchAnimator; import com.android.systemui.animation.ActivityLaunchAnimator;
import com.android.systemui.animation.Interpolators;
import com.android.systemui.dump.DumpManager; import com.android.systemui.dump.DumpManager;
import com.android.systemui.plugins.statusbar.StatusBarStateController; import com.android.systemui.plugins.statusbar.StatusBarStateController;
import com.android.systemui.statusbar.LockscreenShadeTransitionController; import com.android.systemui.statusbar.LockscreenShadeTransitionController;
@@ -112,6 +113,7 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
mActivityLaunchAnimator = activityLaunchAnimator; mActivityLaunchAnimator = activityLaunchAnimator;
mUnlockedScreenOffDozeAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD); mUnlockedScreenOffDozeAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
mUnlockedScreenOffDozeAnimator.setInterpolator(Interpolators.ALPHA_IN);
mUnlockedScreenOffDozeAnimator.addUpdateListener( mUnlockedScreenOffDozeAnimator.addUpdateListener(
new ValueAnimator.AnimatorUpdateListener() { new ValueAnimator.AnimatorUpdateListener() {
@Override @Override
@@ -245,7 +247,7 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
return false; return false;
} }
if (getDialogManager().shouldHideAffordance()) { if (mView.getDialogSuggestedAlpha() == 0f) {
return true; return true;
} }
@@ -321,7 +323,8 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
* Update alpha for the UDFPS lock screen affordance. The AoD UDFPS visual affordance's * Update alpha for the UDFPS lock screen affordance. The AoD UDFPS visual affordance's
* alpha is based on the doze amount. * alpha is based on the doze amount.
*/ */
private void updateAlpha() { @Override
public void updateAlpha() {
// fade icon on transitions to showing the status bar, but if mUdfpsRequested, then // fade icon on transitions to showing the status bar, but if mUdfpsRequested, then
// the keyguard is occluded by some application - so instead use the input bouncer // the keyguard is occluded by some application - so instead use the input bouncer
// hidden amount to determine the fade // hidden amount to determine the fade
@@ -338,6 +341,10 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
if (mIsLaunchingActivity && !mUdfpsRequested) { if (mIsLaunchingActivity && !mUdfpsRequested) {
alpha *= (1.0f - mActivityLaunchProgress); alpha *= (1.0f - mActivityLaunchProgress);
} }
// Fade out alpha when a dialog is shown
// Fade in alpha when a dialog is hidden
alpha *= mView.getDialogSuggestedAlpha();
} }
mView.setUnpausedAlpha(alpha); mView.setUnpausedAlpha(alpha);
} }
@@ -369,6 +376,7 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
public void onStateChanged(int statusBarState) { public void onStateChanged(int statusBarState) {
mStatusBarState = statusBarState; mStatusBarState = statusBarState;
mView.setStatusBarState(statusBarState); mView.setStatusBarState(statusBarState);
updateAlpha();
updatePauseAuth(); updatePauseAuth();
} }
}; };

View File

@@ -124,6 +124,7 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
when(mView.getContext()).thenReturn(mResourceContext); when(mView.getContext()).thenReturn(mResourceContext);
when(mResourceContext.getString(anyInt())).thenReturn("test string"); when(mResourceContext.getString(anyInt())).thenReturn("test string");
when(mKeyguardViewMediator.isAnimatingScreenOff()).thenReturn(false); when(mKeyguardViewMediator.isAnimatingScreenOff()).thenReturn(false);
when(mView.getDialogSuggestedAlpha()).thenReturn(1f);
mController = new UdfpsKeyguardViewController( mController = new UdfpsKeyguardViewController(
mView, mView,
mStatusBarStateController, mStatusBarStateController,
@@ -144,7 +145,7 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
@Test @Test
public void testRegistersExpansionChangedListenerOnAttached() { public void testRegistersExpansionChangedListenerOnAttached() {
mController.onViewAttached(); mController.onViewAttached();
captureExpansionListeners(); captureStatusBarExpansionListeners();
} }
@Test @Test
@@ -173,7 +174,7 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
public void testListenersUnregisteredOnDetached() { public void testListenersUnregisteredOnDetached() {
mController.onViewAttached(); mController.onViewAttached();
captureStatusBarStateListeners(); captureStatusBarStateListeners();
captureExpansionListeners(); captureStatusBarExpansionListeners();
captureKeyguardStateControllerCallback(); captureKeyguardStateControllerCallback();
mController.onViewDetached(); mController.onViewDetached();
@@ -200,10 +201,41 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
public void testShouldPauseAuthBouncerShowing() { public void testShouldPauseAuthBouncerShowing() {
mController.onViewAttached(); mController.onViewAttached();
captureStatusBarStateListeners(); captureStatusBarStateListeners();
sendStatusBarStateChanged(StatusBarState.KEYGUARD); sendStatusBarStateChanged(StatusBarState.KEYGUARD);
assertFalse(mController.shouldPauseAuth()); captureAltAuthInterceptor();
when(mStatusBarKeyguardViewManager.isBouncerShowing()).thenReturn(true);
mAltAuthInterceptor.onBouncerVisibilityChanged();
assertTrue(mController.shouldPauseAuth());
}
@Test
public void testShouldPauseAuthDialogSuggestedAlpha0() {
mController.onViewAttached();
captureStatusBarStateListeners();
when(mView.getDialogSuggestedAlpha()).thenReturn(0f);
sendStatusBarStateChanged(StatusBarState.KEYGUARD);
assertTrue(mController.shouldPauseAuth());
}
@Test
public void testFadeFromDialogSuggestedAlpha() {
// GIVEN view is attached and status bar expansion is 1f
mController.onViewAttached();
captureStatusBarStateListeners();
captureStatusBarExpansionListeners();
updateStatusBarExpansion(1f, true);
reset(mView);
// WHEN dialog suggested alpha is .6f
when(mView.getDialogSuggestedAlpha()).thenReturn(.6f);
sendStatusBarStateChanged(StatusBarState.KEYGUARD);
// THEN alpha is updated based on dialog suggested alpha
verify(mView).setUnpausedAlpha((int) (.6f * 255));
} }
@Test @Test
@@ -367,7 +399,7 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
public void testFadeInWithStatusBarExpansion() { public void testFadeInWithStatusBarExpansion() {
// GIVEN view is attached // GIVEN view is attached
mController.onViewAttached(); mController.onViewAttached();
captureExpansionListeners(); captureStatusBarExpansionListeners();
captureKeyguardStateControllerCallback(); captureKeyguardStateControllerCallback();
reset(mView); reset(mView);
@@ -382,7 +414,7 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
public void testShowUdfpsBouncer() { public void testShowUdfpsBouncer() {
// GIVEN view is attached and status bar expansion is 0 // GIVEN view is attached and status bar expansion is 0
mController.onViewAttached(); mController.onViewAttached();
captureExpansionListeners(); captureStatusBarExpansionListeners();
captureKeyguardStateControllerCallback(); captureKeyguardStateControllerCallback();
captureAltAuthInterceptor(); captureAltAuthInterceptor();
updateStatusBarExpansion(0, true); updateStatusBarExpansion(0, true);
@@ -401,9 +433,10 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
public void testTransitionToFullShadeProgress() { public void testTransitionToFullShadeProgress() {
// GIVEN view is attached and status bar expansion is 1f // GIVEN view is attached and status bar expansion is 1f
mController.onViewAttached(); mController.onViewAttached();
captureExpansionListeners(); captureStatusBarExpansionListeners();
updateStatusBarExpansion(1f, true); updateStatusBarExpansion(1f, true);
reset(mView); reset(mView);
when(mView.getDialogSuggestedAlpha()).thenReturn(1f);
// WHEN we're transitioning to the full shade // WHEN we're transitioning to the full shade
float transitionProgress = .6f; float transitionProgress = .6f;
@@ -417,7 +450,7 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
public void testShowUdfpsBouncer_transitionToFullShadeProgress() { public void testShowUdfpsBouncer_transitionToFullShadeProgress() {
// GIVEN view is attached and status bar expansion is 1f // GIVEN view is attached and status bar expansion is 1f
mController.onViewAttached(); mController.onViewAttached();
captureExpansionListeners(); captureStatusBarExpansionListeners();
captureKeyguardStateControllerCallback(); captureKeyguardStateControllerCallback();
captureAltAuthInterceptor(); captureAltAuthInterceptor();
updateStatusBarExpansion(1f, true); updateStatusBarExpansion(1f, true);
@@ -440,7 +473,7 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
mStatusBarStateListener = mStateListenerCaptor.getValue(); mStatusBarStateListener = mStateListenerCaptor.getValue();
} }
private void captureExpansionListeners() { private void captureStatusBarExpansionListeners() {
verify(mPanelExpansionStateManager, times(2)) verify(mPanelExpansionStateManager, times(2))
.addExpansionListener(mExpansionListenerCaptor.capture()); .addExpansionListener(mExpansionListenerCaptor.capture());
// first (index=0) is from super class, UdfpsAnimationViewController. // first (index=0) is from super class, UdfpsAnimationViewController.
@@ -460,8 +493,6 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
mAltAuthInterceptor = mAltAuthInterceptorCaptor.getValue(); mAltAuthInterceptor = mAltAuthInterceptorCaptor.getValue();
} }
private void captureKeyguardStateControllerCallback() { private void captureKeyguardStateControllerCallback() {
verify(mKeyguardStateController).addCallback( verify(mKeyguardStateController).addCallback(
mKeyguardStateControllerCallbackCaptor.capture()); mKeyguardStateControllerCallbackCaptor.capture());