[View Controllers] (1/3) Move KeyguardStatusBarView's animation
methods out of NotificationPanelViewController and into KeyguardStatusBarViewController. Test: atest and manual Bug: 195442899 Change-Id: I97d1a59191a0cc892fefe2ca26ec176fd256872a
This commit is contained in:
@@ -34,7 +34,10 @@ public interface KeyguardStatusBarViewComponent {
|
||||
/** Simple factory for {@link KeyguardStatusBarViewComponent}. */
|
||||
@Subcomponent.Factory
|
||||
interface Factory {
|
||||
KeyguardStatusBarViewComponent build(@BindsInstance KeyguardStatusBarView view);
|
||||
KeyguardStatusBarViewComponent build(
|
||||
@BindsInstance KeyguardStatusBarView view,
|
||||
@BindsInstance KeyguardStatusBarViewController.ViewStateProvider
|
||||
viewStateProvider);
|
||||
}
|
||||
|
||||
/** Builds a {@link KeyguardStatusViewController}. */
|
||||
|
||||
@@ -19,16 +19,21 @@ package com.android.systemui.statusbar.phone;
|
||||
import static com.android.systemui.statusbar.events.SystemStatusAnimationSchedulerKt.ANIMATING_IN;
|
||||
import static com.android.systemui.statusbar.events.SystemStatusAnimationSchedulerKt.ANIMATING_OUT;
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.content.res.Resources;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.keyguard.CarrierTextController;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.animation.Interpolators;
|
||||
import com.android.systemui.battery.BatteryMeterViewController;
|
||||
import com.android.systemui.statusbar.events.SystemStatusAnimationCallback;
|
||||
import com.android.systemui.statusbar.events.SystemStatusAnimationScheduler;
|
||||
import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
|
||||
import com.android.systemui.statusbar.policy.BatteryController;
|
||||
import com.android.systemui.statusbar.policy.ConfigurationController;
|
||||
import com.android.systemui.statusbar.policy.UserInfoController;
|
||||
@@ -52,6 +57,7 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
|
||||
private final StatusBarIconController mStatusBarIconController;
|
||||
private final StatusBarIconController.TintedIconManager.Factory mTintedIconManagerFactory;
|
||||
private final BatteryMeterViewController mBatteryMeterViewController;
|
||||
private final ViewStateProvider mViewStateProvider;
|
||||
|
||||
private final ConfigurationController.ConfigurationListener mConfigurationListener =
|
||||
new ConfigurationController.ConfigurationListener() {
|
||||
@@ -103,11 +109,19 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
|
||||
private final UserInfoController.OnUserInfoChangedListener mOnUserInfoChangedListener =
|
||||
(name, picture, userAccount) -> mView.onUserInfoChanged(picture);
|
||||
|
||||
private final ValueAnimator.AnimatorUpdateListener mAnimatorUpdateListener =
|
||||
animation -> {
|
||||
mKeyguardStatusBarAnimateAlpha = (float) animation.getAnimatedValue();
|
||||
updateViewState();
|
||||
};
|
||||
|
||||
private final List<String> mBlockedIcons;
|
||||
|
||||
private boolean mBatteryListening;
|
||||
private StatusBarIconController.TintedIconManager mTintedIconManager;
|
||||
|
||||
private float mKeyguardStatusBarAnimateAlpha = 1f;
|
||||
|
||||
@Inject
|
||||
public KeyguardStatusBarViewController(
|
||||
KeyguardStatusBarView view,
|
||||
@@ -118,7 +132,8 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
|
||||
UserInfoController userInfoController,
|
||||
StatusBarIconController statusBarIconController,
|
||||
StatusBarIconController.TintedIconManager.Factory tintedIconManagerFactory,
|
||||
BatteryMeterViewController batteryMeterViewController) {
|
||||
BatteryMeterViewController batteryMeterViewController,
|
||||
ViewStateProvider viewStateProvider) {
|
||||
super(view);
|
||||
mCarrierTextController = carrierTextController;
|
||||
mConfigurationController = configurationController;
|
||||
@@ -128,6 +143,7 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
|
||||
mStatusBarIconController = statusBarIconController;
|
||||
mTintedIconManagerFactory = tintedIconManagerFactory;
|
||||
mBatteryMeterViewController = batteryMeterViewController;
|
||||
mViewStateProvider = viewStateProvider;
|
||||
|
||||
Resources r = getResources();
|
||||
mBlockedIcons = Collections.unmodifiableList(Arrays.asList(
|
||||
@@ -205,6 +221,49 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
|
||||
mView.setTopClipping(notificationPanelTop - mView.getTop());
|
||||
}
|
||||
|
||||
/** Animate the keyguard status bar in. */
|
||||
public void animateKeyguardStatusBarIn() {
|
||||
mView.setVisibility(View.VISIBLE);
|
||||
mView.setAlpha(0f);
|
||||
ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
|
||||
anim.addUpdateListener(mAnimatorUpdateListener);
|
||||
anim.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
|
||||
anim.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
|
||||
anim.start();
|
||||
}
|
||||
|
||||
/** Animate the keyguard status bar out. */
|
||||
public void animateKeyguardStatusBarOut(long startDelay, long duration) {
|
||||
ValueAnimator anim = ValueAnimator.ofFloat(mView.getAlpha(), 0f);
|
||||
anim.addUpdateListener(mAnimatorUpdateListener);
|
||||
anim.setStartDelay(startDelay);
|
||||
anim.setDuration(duration);
|
||||
anim.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
|
||||
anim.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mView.setVisibility(View.INVISIBLE);
|
||||
mView.setAlpha(1f);
|
||||
mKeyguardStatusBarAnimateAlpha = 1f;
|
||||
}
|
||||
});
|
||||
anim.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the {@link KeyguardStatusBarView} state based on what the {@link ViewStateProvider}
|
||||
* provides.
|
||||
*/
|
||||
public void updateViewState() {
|
||||
ViewState newViewState = mViewStateProvider.provideViewState();
|
||||
if (!newViewState.mShouldUpdate) {
|
||||
return;
|
||||
}
|
||||
updateViewState(
|
||||
newViewState.mAlpha * mKeyguardStatusBarAnimateAlpha,
|
||||
newViewState.mVisibility);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the {@link KeyguardStatusBarView} state based on the provided values.
|
||||
*/
|
||||
@@ -219,4 +278,23 @@ public class KeyguardStatusBarViewController extends ViewController<KeyguardStat
|
||||
pw.println(" mBatteryListening: " + mBatteryListening);
|
||||
mView.dump(fd, pw, args);
|
||||
}
|
||||
|
||||
/** An interface that provides the desired state of {@link KeyguardStatusBarView}. */
|
||||
public interface ViewStateProvider {
|
||||
/** Provides the state. */
|
||||
ViewState provideViewState();
|
||||
}
|
||||
|
||||
/** A POJO for the desired state of {@link KeyguardStatusBarView}. */
|
||||
static class ViewState {
|
||||
final boolean mShouldUpdate;
|
||||
final float mAlpha;
|
||||
final int mVisibility;
|
||||
|
||||
ViewState(boolean shouldUpdate, float alpha, int visibility) {
|
||||
this.mShouldUpdate = shouldUpdate;
|
||||
this.mAlpha = alpha;
|
||||
this.mVisibility = visibility;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,7 +298,7 @@ public class NotificationPanelViewController extends PanelViewController {
|
||||
&& !mDelayShowingKeyguardStatusBar
|
||||
&& !mBiometricUnlockController.isBiometricUnlock()) {
|
||||
mFirstBypassAttempt = false;
|
||||
animateKeyguardStatusBarIn(StackStateAnimator.ANIMATION_DURATION_STANDARD);
|
||||
mKeyguardStatusBarViewController.animateKeyguardStatusBarIn();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -436,7 +436,6 @@ public class NotificationPanelViewController extends PanelViewController {
|
||||
private boolean mQsTouchAboveFalsingThreshold;
|
||||
private int mQsFalsingThreshold;
|
||||
|
||||
private float mKeyguardStatusBarAnimateAlpha = 1f;
|
||||
private HeadsUpTouchHelper mHeadsUpTouchHelper;
|
||||
private boolean mListenForHeadsUp;
|
||||
private int mNavigationBarBottomHeight;
|
||||
@@ -687,6 +686,27 @@ public class NotificationPanelViewController extends PanelViewController {
|
||||
}
|
||||
};
|
||||
|
||||
private final KeyguardStatusBarViewController.ViewStateProvider mViewStateProvider =
|
||||
new KeyguardStatusBarViewController.ViewStateProvider() {
|
||||
@Override
|
||||
public KeyguardStatusBarViewController.ViewState provideViewState() {
|
||||
float alphaQsExpansion = 1 - Math.min(1, computeQsExpansionFraction() * 2);
|
||||
float newAlpha = Math.min(getKeyguardContentsAlpha(), alphaQsExpansion)
|
||||
* (1.0f - mKeyguardHeadsUpShowingAmount);
|
||||
|
||||
boolean hideForBypass =
|
||||
mFirstBypassAttempt && mUpdateMonitor.shouldListenForFace()
|
||||
|| mDelayShowingKeyguardStatusBar;
|
||||
int newVisibility = newAlpha != 0f && !mDozing && !hideForBypass
|
||||
? View.VISIBLE : View.INVISIBLE;
|
||||
|
||||
return new KeyguardStatusBarViewController.ViewState(
|
||||
/* shouldAnimate= */ mKeyguardShowing,
|
||||
newAlpha,
|
||||
newVisibility);
|
||||
}
|
||||
};
|
||||
|
||||
@Inject
|
||||
public NotificationPanelViewController(NotificationPanelView view,
|
||||
@Main Resources resources,
|
||||
@@ -893,7 +913,9 @@ public class NotificationPanelViewController extends PanelViewController {
|
||||
}
|
||||
|
||||
mKeyguardStatusBarViewController =
|
||||
mKeyguardStatusBarViewComponentFactory.build(mKeyguardStatusBar)
|
||||
mKeyguardStatusBarViewComponentFactory.build(
|
||||
mKeyguardStatusBar,
|
||||
mViewStateProvider)
|
||||
.getKeyguardStatusBarViewController();
|
||||
mKeyguardStatusBarViewController.init();
|
||||
|
||||
@@ -2174,59 +2196,6 @@ public class NotificationPanelViewController extends PanelViewController {
|
||||
}
|
||||
}
|
||||
|
||||
private final Runnable mAnimateKeyguardStatusBarInvisibleEndRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mKeyguardStatusBar.setVisibility(View.INVISIBLE);
|
||||
mKeyguardStatusBar.setAlpha(1f);
|
||||
mKeyguardStatusBarAnimateAlpha = 1f;
|
||||
}
|
||||
};
|
||||
|
||||
private void animateKeyguardStatusBarOut() {
|
||||
ValueAnimator anim = ValueAnimator.ofFloat(mKeyguardStatusBar.getAlpha(), 0f);
|
||||
anim.addUpdateListener(mStatusBarAnimateAlphaListener);
|
||||
anim.setStartDelay(mKeyguardStateController.isKeyguardFadingAway()
|
||||
? mKeyguardStateController.getKeyguardFadingAwayDelay() : 0);
|
||||
|
||||
long duration;
|
||||
if (mKeyguardStateController.isKeyguardFadingAway()) {
|
||||
duration = mKeyguardStateController.getShortenedFadingAwayDuration();
|
||||
} else {
|
||||
duration = StackStateAnimator.ANIMATION_DURATION_STANDARD;
|
||||
}
|
||||
anim.setDuration(duration);
|
||||
|
||||
anim.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
|
||||
anim.addListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mAnimateKeyguardStatusBarInvisibleEndRunnable.run();
|
||||
}
|
||||
});
|
||||
anim.start();
|
||||
}
|
||||
|
||||
private final ValueAnimator.AnimatorUpdateListener
|
||||
mStatusBarAnimateAlphaListener =
|
||||
new ValueAnimator.AnimatorUpdateListener() {
|
||||
@Override
|
||||
public void onAnimationUpdate(ValueAnimator animation) {
|
||||
mKeyguardStatusBarAnimateAlpha = (float) animation.getAnimatedValue();
|
||||
updateHeaderKeyguardAlpha();
|
||||
}
|
||||
};
|
||||
|
||||
private void animateKeyguardStatusBarIn(long duration) {
|
||||
mKeyguardStatusBar.setVisibility(View.VISIBLE);
|
||||
mKeyguardStatusBar.setAlpha(0f);
|
||||
ValueAnimator anim = ValueAnimator.ofFloat(0f, 1f);
|
||||
anim.addUpdateListener(mStatusBarAnimateAlphaListener);
|
||||
anim.setDuration(duration);
|
||||
anim.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
|
||||
anim.start();
|
||||
}
|
||||
|
||||
private final Runnable mAnimateKeyguardBottomAreaInvisibleEndRunnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@@ -2279,7 +2248,7 @@ public class NotificationPanelViewController extends PanelViewController {
|
||||
mQsExpansionHeight = height;
|
||||
updateQsExpansion();
|
||||
requestScrollerTopPaddingUpdate(false /* animate */);
|
||||
updateHeaderKeyguardAlpha();
|
||||
mKeyguardStatusBarViewController.updateViewState();
|
||||
if (mBarState == StatusBarState.SHADE_LOCKED || mBarState == KEYGUARD) {
|
||||
updateKeyguardBottomAreaAlpha();
|
||||
positionClockAndNotifications();
|
||||
@@ -3003,7 +2972,7 @@ public class NotificationPanelViewController extends PanelViewController {
|
||||
*/
|
||||
private void updateHeader() {
|
||||
if (mBarState == KEYGUARD) {
|
||||
updateHeaderKeyguardAlpha();
|
||||
mKeyguardStatusBarViewController.updateViewState();
|
||||
}
|
||||
updateQsExpansion();
|
||||
}
|
||||
@@ -3051,23 +3020,6 @@ public class NotificationPanelViewController extends PanelViewController {
|
||||
return alpha;
|
||||
}
|
||||
|
||||
private void updateHeaderKeyguardAlpha() {
|
||||
if (!mKeyguardShowing) {
|
||||
return;
|
||||
}
|
||||
float alphaQsExpansion = 1 - Math.min(1, computeQsExpansionFraction() * 2);
|
||||
float newAlpha = Math.min(getKeyguardContentsAlpha(), alphaQsExpansion)
|
||||
* mKeyguardStatusBarAnimateAlpha;
|
||||
newAlpha *= 1.0f - mKeyguardHeadsUpShowingAmount;
|
||||
mKeyguardStatusBar.setAlpha(newAlpha);
|
||||
boolean
|
||||
hideForBypass =
|
||||
mFirstBypassAttempt && mUpdateMonitor.shouldListenForFace()
|
||||
|| mDelayShowingKeyguardStatusBar;
|
||||
mKeyguardStatusBar.setVisibility(
|
||||
newAlpha != 0f && !mDozing && !hideForBypass ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
|
||||
private void updateKeyguardBottomAreaAlpha() {
|
||||
// There are two possible panel expansion behaviors:
|
||||
// • User dragging up to unlock: we want to fade out as quick as possible
|
||||
@@ -3294,7 +3246,7 @@ public class NotificationPanelViewController extends PanelViewController {
|
||||
private void updateDozingVisibilities(boolean animate) {
|
||||
mKeyguardBottomArea.setDozing(mDozing, animate);
|
||||
if (!mDozing && animate) {
|
||||
animateKeyguardStatusBarIn(StackStateAnimator.ANIMATION_DURATION_STANDARD);
|
||||
mKeyguardStatusBarViewController.animateKeyguardStatusBarIn();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3381,7 +3333,7 @@ public class NotificationPanelViewController extends PanelViewController {
|
||||
|
||||
private void setKeyguardHeadsUpShowingAmount(float amount) {
|
||||
mKeyguardHeadsUpShowingAmount = amount;
|
||||
updateHeaderKeyguardAlpha();
|
||||
mKeyguardStatusBarViewController.updateViewState();
|
||||
}
|
||||
|
||||
private float getKeyguardHeadsUpShowingAmount() {
|
||||
@@ -4478,11 +4430,22 @@ public class NotificationPanelViewController extends PanelViewController {
|
||||
|
||||
if (oldState == KEYGUARD && (goingToFullShade
|
||||
|| statusBarState == StatusBarState.SHADE_LOCKED)) {
|
||||
animateKeyguardStatusBarOut();
|
||||
|
||||
long startDelay;
|
||||
long duration;
|
||||
if (mKeyguardStateController.isKeyguardFadingAway()) {
|
||||
startDelay = mKeyguardStateController.getKeyguardFadingAwayDelay();
|
||||
duration = mKeyguardStateController.getShortenedFadingAwayDuration();
|
||||
} else {
|
||||
startDelay = 0;
|
||||
duration = StackStateAnimator.ANIMATION_DURATION_STANDARD;
|
||||
}
|
||||
mKeyguardStatusBarViewController.animateKeyguardStatusBarOut(startDelay, duration);
|
||||
updateQSMinHeight();
|
||||
} else if (oldState == StatusBarState.SHADE_LOCKED
|
||||
&& statusBarState == KEYGUARD) {
|
||||
animateKeyguardStatusBarIn(StackStateAnimator.ANIMATION_DURATION_STANDARD);
|
||||
mKeyguardStatusBarViewController.animateKeyguardStatusBarIn();
|
||||
|
||||
mNotificationStackScrollLayoutController.resetScrollPosition();
|
||||
// Only animate header if the header is visible. If not, it will partially
|
||||
// animate out
|
||||
|
||||
@@ -65,6 +65,8 @@ public class KeyguardStatusBarViewControllerTest extends SysuiTestCase {
|
||||
private FeatureFlags mFeatureFlags;
|
||||
@Mock
|
||||
private BatteryMeterViewController mBatteryMeterViewController;
|
||||
@Mock
|
||||
private KeyguardStatusBarViewController.ViewStateProvider mViewStateProvider;
|
||||
|
||||
private KeyguardStatusBarView mKeyguardStatusBarView;
|
||||
private KeyguardStatusBarViewController mController;
|
||||
@@ -89,7 +91,8 @@ public class KeyguardStatusBarViewControllerTest extends SysuiTestCase {
|
||||
mUserInfoController,
|
||||
mStatusBarIconController,
|
||||
new StatusBarIconController.TintedIconManager.Factory(mFeatureFlags),
|
||||
mBatteryMeterViewController
|
||||
mBatteryMeterViewController,
|
||||
mViewStateProvider
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -399,7 +399,7 @@ public class NotificationPanelViewTest extends SysuiTestCase {
|
||||
.thenReturn(mKeyguardClockSwitchController);
|
||||
when(mKeyguardStatusViewComponent.getKeyguardStatusViewController())
|
||||
.thenReturn(mKeyguardStatusViewController);
|
||||
when(mKeyguardStatusBarViewComponentFactory.build(any()))
|
||||
when(mKeyguardStatusBarViewComponentFactory.build(any(), any()))
|
||||
.thenReturn(mKeyguardStatusBarViewComponent);
|
||||
when(mKeyguardStatusBarViewComponent.getKeyguardStatusBarViewController())
|
||||
.thenReturn(mKeyguardStatusBarViewController);
|
||||
|
||||
Reference in New Issue
Block a user