summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Lucas Dupin <dupin@google.com> 2018-11-12 18:18:15 -0800
committer Lucas Dupin <dupin@google.com> 2018-11-12 18:27:16 -0800
commit1a8b33da4bc03f570fea83a6e9254c7f960e742d (patch)
treea3235bb225dcc2ca0d13ca28dfc02feb06b9aea7
parent4e7b7c1abd3f42c9e3518845051f75e3db73f1f1 (diff)
Move dark amount to StatusBarStateController
Bug: 111405682 Change-Id: Ib3ef0d211a9e8fae31a77215879b9a4e1f583aea Fixes: 119226939 Test: unlock with fingerprint Test: press power to wake up, press power to sleep Test: press power to sleep, wake up with fingerprint
-rw-r--r--packages/SystemUI/src/com/android/systemui/doze/DozeReceiver.java5
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/StatusBarStateController.java109
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationDozeHelper.java5
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java10
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java76
5 files changed, 124 insertions, 81 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/doze/DozeReceiver.java b/packages/SystemUI/src/com/android/systemui/doze/DozeReceiver.java
index 30dfd3622198..4a2e06c058cb 100644
--- a/packages/SystemUI/src/com/android/systemui/doze/DozeReceiver.java
+++ b/packages/SystemUI/src/com/android/systemui/doze/DozeReceiver.java
@@ -22,11 +22,6 @@ package com.android.systemui.doze;
public interface DozeReceiver {
/**
- * If device enters or leaves doze mode
- */
- void setDozing(boolean dozing);
-
- /**
* Invoked every time a minute is elapsed in doze mode
*/
void dozeTimeTick();
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarStateController.java b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarStateController.java
index 12c0fcbed204..65476fda3bc9 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarStateController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/StatusBarStateController.java
@@ -18,11 +18,17 @@ package com.android.systemui.statusbar;
import static java.lang.annotation.RetentionPolicy.SOURCE;
+import android.animation.ObjectAnimator;
+import android.animation.ValueAnimator;
import android.annotation.IntDef;
-import android.util.ArraySet;
-import android.util.Log;
+import android.util.FloatProperty;
+import android.view.animation.Interpolator;
+
import com.android.internal.annotations.GuardedBy;
+import com.android.systemui.Interpolators;
+import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
import com.android.systemui.statusbar.phone.StatusBar;
+
import java.lang.annotation.Retention;
import java.util.ArrayList;
import java.util.Comparator;
@@ -38,14 +44,51 @@ public class StatusBarStateController {
private static final Comparator <RankedListener> mComparator
= (o1, o2) -> Integer.compare(o1.rank, o2.rank);
+ private static final FloatProperty<StatusBarStateController> SET_DARK_AMOUNT_PROPERTY =
+ new FloatProperty<StatusBarStateController>("mDozeAmount") {
+
+ @Override
+ public void setValue(StatusBarStateController object, float value) {
+ object.setDozeAmountInternal(value);
+ }
+
+ @Override
+ public Float get(StatusBarStateController object) {
+ return object.mDozeAmount;
+ }
+ };
private final ArrayList<RankedListener> mListeners = new ArrayList<>();
- private boolean mIsDozing;
private int mState;
private int mLastState;
private boolean mLeaveOpenOnKeyguardHide;
private boolean mKeyguardRequested;
+ /**
+ * If the device is currently dozing or not.
+ */
+ private boolean mIsDozing;
+
+ /**
+ * Current {@link #mDozeAmount} animator.
+ */
+ private ValueAnimator mDarkAnimator;
+
+ /**
+ * Current doze amount in this frame.
+ */
+ private float mDozeAmount;
+
+ /**
+ * Where the animator will stop.
+ */
+ private float mDozeAmountTarget;
+
+ /**
+ * The type of interpolator that should be used to the doze animation.
+ */
+ private Interpolator mDozeInterpolator = Interpolators.FAST_OUT_SLOW_IN;
+
// TODO: b/115739177 (remove this explicit ordering if we can)
@Retention(SOURCE)
@IntDef({RANK_STATUS_BAR, RANK_STATUS_BAR_WINDOW_CONTROLLER, RANK_STACK_SCROLLER, RANK_SHELF})
@@ -94,6 +137,14 @@ public class StatusBarStateController {
return mIsDozing;
}
+ public float getDozeAmount() {
+ return mDozeAmount;
+ }
+
+ public float getInterpolatedDozeAmount() {
+ return mDozeInterpolator.getInterpolation(mDozeAmount);
+ }
+
/**
* Update the dozing state from {@link StatusBar}'s perspective
* @param isDozing well, are we dozing?
@@ -116,6 +167,51 @@ public class StatusBarStateController {
return true;
}
+ /**
+ * Changes the current doze amount.
+ *
+ * @param dozeAmount New doze/dark amount.
+ * @param animated If change should be animated or not. This will cancel current animations.
+ */
+ public void setDozeAmount(float dozeAmount, boolean animated) {
+ if (mDarkAnimator != null && mDarkAnimator.isRunning()) {
+ if (animated && mDozeAmountTarget == dozeAmount) {
+ return;
+ } else {
+ mDarkAnimator.cancel();
+ }
+ }
+
+ mDozeAmountTarget = dozeAmount;
+ if (animated) {
+ startDozeAnimation();
+ } else {
+ setDozeAmountInternal(dozeAmount);
+ }
+ }
+
+ private void startDozeAnimation() {
+ if (mDozeAmount == 0f || mDozeAmount == 1f) {
+ mDozeInterpolator = mIsDozing
+ ? Interpolators.FAST_OUT_SLOW_IN
+ : Interpolators.TOUCH_RESPONSE_REVERSE;
+ }
+ mDarkAnimator = ObjectAnimator.ofFloat(this, SET_DARK_AMOUNT_PROPERTY, mDozeAmountTarget);
+ mDarkAnimator.setInterpolator(Interpolators.LINEAR);
+ mDarkAnimator.setDuration(StackStateAnimator.ANIMATION_DURATION_WAKEUP);
+ mDarkAnimator.start();
+ }
+
+ private void setDozeAmountInternal(float dozeAmount) {
+ mDozeAmount = dozeAmount;
+ float interpolatedAmount = mDozeInterpolator.getInterpolation(dozeAmount);
+ synchronized (mListeners) {
+ for (RankedListener rl : new ArrayList<>(mListeners)) {
+ rl.listener.onDozeAmountChanged(mDozeAmount, interpolatedAmount);
+ }
+ }
+ }
+
public boolean goingToFullShade() {
return mState == StatusBarState.SHADE && mLeaveOpenOnKeyguardHide;
}
@@ -230,5 +326,12 @@ public class StatusBarStateController {
* @param isDozing {@code true} if dozing according to {@link StatusBar}
*/
public default void onDozingChanged(boolean isDozing) {}
+
+ /**
+ * Callback to be notified when the doze amount changes. Useful for animations.
+ * @param linear A number from 0 to 1, where 1 means that the device is dozing.
+ * @param eased Same as {@code linear} but transformed by an interpolator.
+ */
+ default void onDozeAmountChanged(float linear, float eased) {}
}
}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationDozeHelper.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationDozeHelper.java
index fb362c5e506f..ef042bab7625 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationDozeHelper.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/NotificationDozeHelper.java
@@ -26,7 +26,7 @@ import android.widget.ImageView;
import com.android.systemui.Interpolators;
import com.android.systemui.R;
-import com.android.systemui.statusbar.phone.NotificationPanelView;
+import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
import java.util.function.Consumer;
@@ -63,13 +63,14 @@ public class NotificationDozeHelper {
}
}
+ // TODO: this should be using StatusBarStateController#getDozeAmount
public void startIntensityAnimation(ValueAnimator.AnimatorUpdateListener updateListener,
boolean dark, long delay, Animator.AnimatorListener listener) {
float startIntensity = dark ? 0f : 1f;
float endIntensity = dark ? 1f : 0f;
ValueAnimator animator = ValueAnimator.ofFloat(startIntensity, endIntensity);
animator.addUpdateListener(updateListener);
- animator.setDuration(NotificationPanelView.DOZE_ANIMATION_DURATION);
+ animator.setDuration(StackStateAnimator.ANIMATION_DURATION_WAKEUP);
animator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
animator.setStartDelay(delay);
if (listener != null) {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
index a315bf3c2d99..37c673cf84a3 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/stack/NotificationStackScrollLayout.java
@@ -4275,16 +4275,6 @@ public class NotificationStackScrollLayout extends ViewGroup implements ScrollAd
}
@ShadeViewRefactor(RefactorComponent.STATE_RESOLVER)
- public long getDarkAnimationDuration(boolean dark) {
- long duration = StackStateAnimator.ANIMATION_DURATION_WAKEUP;
- // Longer animation when sleeping with more than 1 notification
- if (dark && getNotGoneChildCount() > 2) {
- duration *= 1.2f;
- }
- return duration;
- }
-
- @ShadeViewRefactor(RefactorComponent.STATE_RESOLVER)
private int findDarkAnimationOriginIndex(@Nullable PointF screenLocation) {
if (screenLocation == null || screenLocation.y < mTopPadding) {
return AnimationEvent.DARK_ANIMATION_ORIGIN_INDEX_ABOVE;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
index f4c2e27ca272..f23e3fc57549 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -22,7 +22,6 @@ import static com.android.systemui.statusbar.notification.ActivityLaunchAnimator
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
-import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.app.ActivityManager;
import android.app.Fragment;
@@ -41,7 +40,6 @@ import android.graphics.Rect;
import android.os.PowerManager;
import android.os.SystemProperties;
import android.util.AttributeSet;
-import android.util.FloatProperty;
import android.util.Log;
import android.util.MathUtils;
import android.view.LayoutInflater;
@@ -51,7 +49,6 @@ import android.view.View;
import android.view.ViewGroup;
import android.view.WindowInsets;
import android.view.accessibility.AccessibilityManager;
-import android.view.animation.Interpolator;
import android.widget.FrameLayout;
import com.android.internal.logging.MetricsLogger;
@@ -104,7 +101,7 @@ public class NotificationPanelView extends PanelView implements
View.OnClickListener, NotificationStackScrollLayout.OnOverscrollTopChangedListener,
KeyguardAffordanceHelper.Callback, NotificationStackScrollLayout.OnEmptySpaceClickListener,
OnHeadsUpChangedListener, QS.HeightListener, ZenModeController.Callback,
- ConfigurationController.ConfigurationListener {
+ ConfigurationController.ConfigurationListener, StateListener {
private static final boolean DEBUG = false;
@@ -139,25 +136,9 @@ public class NotificationPanelView extends PanelView implements
private static final Rect mDummyDirtyRect = new Rect(0, 0, 1, 1);
- public static final long DOZE_ANIMATION_DURATION = 700;
-
private static final AnimationProperties CLOCK_ANIMATION_PROPERTIES = new AnimationProperties()
.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
- private static final FloatProperty<NotificationPanelView> SET_DARK_AMOUNT_PROPERTY =
- new FloatProperty<NotificationPanelView>("mInterpolatedDarkAmount") {
-
- @Override
- public void setValue(NotificationPanelView object, float value) {
- object.setDarkAmount(value, object.mDarkInterpolator.getInterpolation(value));
- }
- @Override
- public Float get(NotificationPanelView object) {
- return object.mLinearDarkAmount;
- }
- };
-
- private Interpolator mDarkInterpolator;
private final PowerManager mPowerManager;
private final AccessibilityManager mAccessibilityManager;
@@ -295,11 +276,9 @@ public class NotificationPanelView extends PanelView implements
*/
private boolean mSemiAwake;
- private float mDarkAmountTarget;
private boolean mPulsing;
private LockscreenGestureLogger mLockscreenGestureLogger = new LockscreenGestureLogger();
private boolean mNoVisibleNotifications = true;
- private ValueAnimator mDarkAnimator;
private boolean mUserSetupComplete;
private int mQsNotificationTopPadding;
private float mExpandOffset;
@@ -339,7 +318,6 @@ public class NotificationPanelView extends PanelView implements
private final NotificationEntryManager mEntryManager =
Dependency.get(NotificationEntryManager.class);
- private final StateListener mListener = this::setBarState;
private final CommandQueue mCommandQueue;
private final NotificationLockscreenUserManager mLockscreenUserManager =
Dependency.get(NotificationLockscreenUserManager.class);
@@ -388,7 +366,7 @@ public class NotificationPanelView extends PanelView implements
protected void onAttachedToWindow() {
super.onAttachedToWindow();
FragmentHostManager.get(this).addTagListener(QS.TAG, mFragmentListener);
- Dependency.get(StatusBarStateController.class).addListener(mListener);
+ Dependency.get(StatusBarStateController.class).addListener(this);
Dependency.get(ZenModeController.class).addCallback(this);
Dependency.get(ConfigurationController.class).addCallback(this);
}
@@ -397,7 +375,7 @@ public class NotificationPanelView extends PanelView implements
protected void onDetachedFromWindow() {
super.onDetachedFromWindow();
FragmentHostManager.get(this).removeTagListener(QS.TAG, mFragmentListener);
- Dependency.get(StatusBarStateController.class).removeListener(mListener);
+ Dependency.get(StatusBarStateController.class).removeListener(this);
Dependency.get(ZenModeController.class).removeCallback(this);
Dependency.get(ConfigurationController.class).removeCallback(this);
}
@@ -475,7 +453,8 @@ public class NotificationPanelView extends PanelView implements
mKeyguardBottomArea.initFrom(oldBottomArea);
addView(mKeyguardBottomArea, index);
initBottomArea();
- setDarkAmount(mLinearDarkAmount, mInterpolatedDarkAmount);
+ onDozeAmountChanged(mStatusBarStateController.getDozeAmount(),
+ mStatusBarStateController.getInterpolatedDozeAmount());
if (mKeyguardStatusBar != null) {
mKeyguardStatusBar.onThemeChanged();
@@ -1221,7 +1200,8 @@ public class NotificationPanelView extends PanelView implements
}
}
- private void setBarState(int statusBarState) {
+ @Override
+ public void onStateChanged(int statusBarState) {
boolean goingToFullShade = mStatusBarStateController.goingToFullShade();
boolean keyguardFadingAway = mKeyguardMonitor.isKeyguardFadingAway();
int oldState = mBarState;
@@ -2806,24 +2786,10 @@ public class NotificationPanelView extends PanelView implements
updateDozingVisibilities(animate);
}
- final float darkAmount = dozing ? 1 : 0;
- if (mDarkAnimator != null && mDarkAnimator.isRunning()) {
- if (animate && mDarkAmountTarget == darkAmount) {
- return;
- } else {
- mDarkAnimator.cancel();
- }
- if (mSemiAwake) {
- setDarkAmount(0, 0);
- }
- }
- mDarkAmountTarget = darkAmount;
- if (!mSemiAwake) {
- if (animate) {
- startDarkAnimation();
- } else {
- setDarkAmount(darkAmount, darkAmount);
- }
+ final float darkAmount = dozing && !mSemiAwake ? 1 : 0;
+ mStatusBarStateController.setDozeAmount(darkAmount, animate);
+ if (animate) {
+ mNotificationStackScroller.notifyDarkAnimationStart(mDozing);
}
}
@@ -2831,21 +2797,8 @@ public class NotificationPanelView extends PanelView implements
return mSemiAwake;
}
- private void startDarkAnimation() {
- if (mInterpolatedDarkAmount == 0f || mInterpolatedDarkAmount == 1f) {
- mDarkInterpolator = mDozing
- ? Interpolators.FAST_OUT_SLOW_IN
- : Interpolators.TOUCH_RESPONSE_REVERSE;
- }
- mNotificationStackScroller.notifyDarkAnimationStart(mDozing);
- mDarkAnimator = ObjectAnimator.ofFloat(this, SET_DARK_AMOUNT_PROPERTY, mDozing ? 1 : 0);
- mDarkAnimator.setInterpolator(Interpolators.LINEAR);
- mDarkAnimator.setDuration(
- mNotificationStackScroller.getDarkAnimationDuration(mDozing));
- mDarkAnimator.start();
- }
-
- private void setDarkAmount(float linearAmount, float amount) {
+ @Override
+ public void onDozeAmountChanged(float linearAmount, float amount) {
mInterpolatedDarkAmount = amount;
mLinearDarkAmount = linearAmount;
mKeyguardStatusBar.setDarkAmount(mInterpolatedDarkAmount);
@@ -3046,7 +2999,8 @@ public class NotificationPanelView extends PanelView implements
mSemiAwake = false;
mNotificationStackScroller.setDark(false /* dark */, true /* animate */,
null /* touchLocation */);
- startDarkAnimation();
+ mStatusBarStateController.setDozeAmount(0f, true /* animated */);
+ mNotificationStackScroller.notifyDarkAnimationStart(mDozing);
mStatusBar.updateScrimController();
return WAKE_UP_TO_SHADE;