Merge "Fade in/out UDFPS when dialogs show/hide" into tm-dev
This commit is contained in:
@@ -34,8 +34,10 @@ import android.widget.FrameLayout;
|
||||
* - optionally can override dozeTimeTick to adjust views for burn-in mitigation
|
||||
*/
|
||||
public abstract class UdfpsAnimationView extends FrameLayout {
|
||||
// mAlpha takes into consideration the status bar expansion amount to fade out icon when
|
||||
// the status bar is expanded
|
||||
private float mDialogSuggestedAlpha = 1f;
|
||||
private float mNotificationShadeExpansion = 0f;
|
||||
|
||||
// mAlpha takes into consideration the status bar expansion amount and dialog suggested alpha
|
||||
private int mAlpha;
|
||||
boolean mPauseAuth;
|
||||
|
||||
@@ -92,6 +94,10 @@ public abstract class UdfpsAnimationView extends FrameLayout {
|
||||
}
|
||||
|
||||
int calculateAlpha() {
|
||||
int alpha = expansionToAlpha(mNotificationShadeExpansion);
|
||||
alpha *= mDialogSuggestedAlpha;
|
||||
mAlpha = alpha;
|
||||
|
||||
return mPauseAuth ? mAlpha : 255;
|
||||
}
|
||||
|
||||
@@ -111,8 +117,26 @@ public abstract class UdfpsAnimationView extends FrameLayout {
|
||||
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) {
|
||||
mAlpha = expansionToAlpha(expansion);
|
||||
mNotificationShadeExpansion = expansion;
|
||||
updateAlpha();
|
||||
}
|
||||
|
||||
|
||||
@@ -15,10 +15,12 @@
|
||||
*/
|
||||
package com.android.systemui.biometrics
|
||||
|
||||
import android.animation.ValueAnimator
|
||||
import android.graphics.PointF
|
||||
import android.graphics.RectF
|
||||
import com.android.systemui.Dumpable
|
||||
import com.android.systemui.dump.DumpManager
|
||||
import com.android.systemui.animation.Interpolators
|
||||
import com.android.systemui.plugins.statusbar.StatusBarStateController
|
||||
import com.android.systemui.statusbar.phone.SystemUIDialogManager
|
||||
import com.android.systemui.statusbar.phone.panelstate.PanelExpansionListener
|
||||
@@ -50,7 +52,8 @@ abstract class UdfpsAnimationViewController<T : UdfpsAnimationView>(
|
||||
private val view: T
|
||||
get() = mView!!
|
||||
|
||||
private val dialogListener = SystemUIDialogManager.Listener { updatePauseAuth() }
|
||||
private var dialogAlphaAnimator: ValueAnimator? = null
|
||||
private val dialogListener = SystemUIDialogManager.Listener { runDialogAlphaAnimator() }
|
||||
|
||||
private val panelExpansionListener =
|
||||
PanelExpansionListener { fraction, expanded, tracking ->
|
||||
@@ -83,6 +86,29 @@ abstract class UdfpsAnimationViewController<T : UdfpsAnimationView>(
|
||||
*/
|
||||
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() {
|
||||
panelExpansionStateManager.addExpansionListener(panelExpansionListener)
|
||||
dialogManager.registerListener(dialogListener)
|
||||
@@ -106,6 +132,7 @@ abstract class UdfpsAnimationViewController<T : UdfpsAnimationView>(
|
||||
pw.println("mNotificationShadeVisible=$notificationShadeVisible")
|
||||
pw.println("shouldPauseAuth()=" + shouldPauseAuth())
|
||||
pw.println("isPauseAuth=" + view.isPauseAuth)
|
||||
pw.println("dialogSuggestedAlpha=" + view.dialogSuggestedAlpha)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -28,6 +28,7 @@ import android.view.MotionEvent;
|
||||
import com.android.keyguard.KeyguardUpdateMonitor;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.animation.ActivityLaunchAnimator;
|
||||
import com.android.systemui.animation.Interpolators;
|
||||
import com.android.systemui.dump.DumpManager;
|
||||
import com.android.systemui.plugins.statusbar.StatusBarStateController;
|
||||
import com.android.systemui.statusbar.LockscreenShadeTransitionController;
|
||||
@@ -112,6 +113,7 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
|
||||
mActivityLaunchAnimator = activityLaunchAnimator;
|
||||
|
||||
mUnlockedScreenOffDozeAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
|
||||
mUnlockedScreenOffDozeAnimator.setInterpolator(Interpolators.ALPHA_IN);
|
||||
mUnlockedScreenOffDozeAnimator.addUpdateListener(
|
||||
new ValueAnimator.AnimatorUpdateListener() {
|
||||
@Override
|
||||
@@ -245,7 +247,7 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
|
||||
return false;
|
||||
}
|
||||
|
||||
if (getDialogManager().shouldHideAffordance()) {
|
||||
if (mView.getDialogSuggestedAlpha() == 0f) {
|
||||
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
|
||||
* 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
|
||||
// the keyguard is occluded by some application - so instead use the input bouncer
|
||||
// hidden amount to determine the fade
|
||||
@@ -338,6 +341,10 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
|
||||
if (mIsLaunchingActivity && !mUdfpsRequested) {
|
||||
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);
|
||||
}
|
||||
@@ -369,6 +376,7 @@ public class UdfpsKeyguardViewController extends UdfpsAnimationViewController<Ud
|
||||
public void onStateChanged(int statusBarState) {
|
||||
mStatusBarState = statusBarState;
|
||||
mView.setStatusBarState(statusBarState);
|
||||
updateAlpha();
|
||||
updatePauseAuth();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -124,6 +124,7 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
|
||||
when(mView.getContext()).thenReturn(mResourceContext);
|
||||
when(mResourceContext.getString(anyInt())).thenReturn("test string");
|
||||
when(mKeyguardViewMediator.isAnimatingScreenOff()).thenReturn(false);
|
||||
when(mView.getDialogSuggestedAlpha()).thenReturn(1f);
|
||||
mController = new UdfpsKeyguardViewController(
|
||||
mView,
|
||||
mStatusBarStateController,
|
||||
@@ -144,7 +145,7 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
|
||||
@Test
|
||||
public void testRegistersExpansionChangedListenerOnAttached() {
|
||||
mController.onViewAttached();
|
||||
captureExpansionListeners();
|
||||
captureStatusBarExpansionListeners();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,7 +174,7 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
|
||||
public void testListenersUnregisteredOnDetached() {
|
||||
mController.onViewAttached();
|
||||
captureStatusBarStateListeners();
|
||||
captureExpansionListeners();
|
||||
captureStatusBarExpansionListeners();
|
||||
captureKeyguardStateControllerCallback();
|
||||
mController.onViewDetached();
|
||||
|
||||
@@ -200,10 +201,41 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
|
||||
public void testShouldPauseAuthBouncerShowing() {
|
||||
mController.onViewAttached();
|
||||
captureStatusBarStateListeners();
|
||||
|
||||
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
|
||||
@@ -367,7 +399,7 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
|
||||
public void testFadeInWithStatusBarExpansion() {
|
||||
// GIVEN view is attached
|
||||
mController.onViewAttached();
|
||||
captureExpansionListeners();
|
||||
captureStatusBarExpansionListeners();
|
||||
captureKeyguardStateControllerCallback();
|
||||
reset(mView);
|
||||
|
||||
@@ -382,7 +414,7 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
|
||||
public void testShowUdfpsBouncer() {
|
||||
// GIVEN view is attached and status bar expansion is 0
|
||||
mController.onViewAttached();
|
||||
captureExpansionListeners();
|
||||
captureStatusBarExpansionListeners();
|
||||
captureKeyguardStateControllerCallback();
|
||||
captureAltAuthInterceptor();
|
||||
updateStatusBarExpansion(0, true);
|
||||
@@ -401,9 +433,10 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
|
||||
public void testTransitionToFullShadeProgress() {
|
||||
// GIVEN view is attached and status bar expansion is 1f
|
||||
mController.onViewAttached();
|
||||
captureExpansionListeners();
|
||||
captureStatusBarExpansionListeners();
|
||||
updateStatusBarExpansion(1f, true);
|
||||
reset(mView);
|
||||
when(mView.getDialogSuggestedAlpha()).thenReturn(1f);
|
||||
|
||||
// WHEN we're transitioning to the full shade
|
||||
float transitionProgress = .6f;
|
||||
@@ -417,7 +450,7 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
|
||||
public void testShowUdfpsBouncer_transitionToFullShadeProgress() {
|
||||
// GIVEN view is attached and status bar expansion is 1f
|
||||
mController.onViewAttached();
|
||||
captureExpansionListeners();
|
||||
captureStatusBarExpansionListeners();
|
||||
captureKeyguardStateControllerCallback();
|
||||
captureAltAuthInterceptor();
|
||||
updateStatusBarExpansion(1f, true);
|
||||
@@ -440,7 +473,7 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
|
||||
mStatusBarStateListener = mStateListenerCaptor.getValue();
|
||||
}
|
||||
|
||||
private void captureExpansionListeners() {
|
||||
private void captureStatusBarExpansionListeners() {
|
||||
verify(mPanelExpansionStateManager, times(2))
|
||||
.addExpansionListener(mExpansionListenerCaptor.capture());
|
||||
// first (index=0) is from super class, UdfpsAnimationViewController.
|
||||
@@ -460,8 +493,6 @@ public class UdfpsKeyguardViewControllerTest extends SysuiTestCase {
|
||||
mAltAuthInterceptor = mAltAuthInterceptorCaptor.getValue();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void captureKeyguardStateControllerCallback() {
|
||||
verify(mKeyguardStateController).addCallback(
|
||||
mKeyguardStateControllerCallbackCaptor.capture());
|
||||
|
||||
Reference in New Issue
Block a user