From 2cd45dfba6a9105a305ea20b110ba5ac078a9dc6 Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Tue, 9 Jun 2015 18:00:07 -0700 Subject: [PATCH] Enabled appear and dissappear animations for the overflow card Bug: 21651647 Change-Id: I0732cb27ec8f88ae74fcff11340092879ba8bae3 --- .../ActivatableNotificationView.java | 15 ++++- .../systemui/statusbar/BaseStatusBar.java | 7 +-- .../systemui/statusbar/ExpandableView.java | 9 +++ .../statusbar/StackScrollerDecorView.java | 9 --- .../statusbar/phone/PhoneStatusBar.java | 3 +- .../stack/NotificationStackScrollLayout.java | 55 +++++++++++++++---- .../statusbar/stack/StackScrollState.java | 5 +- .../statusbar/stack/StackStateAnimator.java | 4 ++ 8 files changed, 77 insertions(+), 30 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java b/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java index c0b3a9bfb2729..8bee008a527ef 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java @@ -540,9 +540,7 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView private void startAppearAnimation(boolean isAppearing, float translationDirection, long delay, long duration, final Runnable onFinishedRunnable) { - if (mAppearAnimator != null) { - mAppearAnimator.cancel(); - } + cancelAppearAnimation(); mAnimationTranslationY = translationDirection * getActualHeight(); if (mAppearAnimationFraction == -1.0f) { // not initialized yet, we start anew @@ -613,6 +611,17 @@ public abstract class ActivatableNotificationView extends ExpandableOutlineView mAppearAnimator.start(); } + private void cancelAppearAnimation() { + if (mAppearAnimator != null) { + mAppearAnimator.cancel(); + } + } + + public void cancelAppearDrawing() { + cancelAppearAnimation(); + enableAppearDrawing(false); + } + private void updateAppearRect() { float inverseFraction = (1.0f - mAppearAnimationFraction); float translationFraction = mCurrentAppearInterpolator.getInterpolation(inverseFraction); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java index 6fb4b48910fce..09e4e5cb749d8 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java @@ -1840,11 +1840,8 @@ public abstract class BaseStatusBar extends SystemUI implements } } - if (onKeyguard && mKeyguardIconOverflowContainer.getIconsView().getChildCount() > 0) { - mKeyguardIconOverflowContainer.setVisibility(View.VISIBLE); - } else { - mKeyguardIconOverflowContainer.setVisibility(View.GONE); - } + mStackScroller.updateOverflowContainerVisibility(onKeyguard + && mKeyguardIconOverflowContainer.getIconsView().getChildCount() > 0); mStackScroller.changeViewPosition(mDismissView, mStackScroller.getChildCount() - 1); mStackScroller.changeViewPosition(mEmptyShadeView, mStackScroller.getChildCount() - 2); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableView.java b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableView.java index 3feec9e79098a..8c0335060d9bd 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/ExpandableView.java @@ -43,6 +43,7 @@ public abstract class ExpandableView extends FrameLayout { private ArrayList mMatchParentViews = new ArrayList(); private int mClipTopOptimization; private static Rect mClipRect = new Rect(); + private boolean mWillBeGone; public ExpandableView(Context context, AttributeSet attrs) { super(context, attrs); @@ -374,6 +375,14 @@ public abstract class ExpandableView extends FrameLayout { updateClipping(); } + public boolean willBeGone() { + return mWillBeGone; + } + + public void setWillBeGone(boolean willBeGone) { + mWillBeGone = willBeGone; + } + /** * A listener notifying when {@link #getActualHeight} changes. */ diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/StackScrollerDecorView.java b/packages/SystemUI/src/com/android/systemui/statusbar/StackScrollerDecorView.java index 64d80cc9680ae..2f66c41ada8f7 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/StackScrollerDecorView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/StackScrollerDecorView.java @@ -32,7 +32,6 @@ public abstract class StackScrollerDecorView extends ExpandableView { protected View mContent; private boolean mIsVisible; private boolean mAnimating; - private boolean mWillBeGone; public StackScrollerDecorView(Context context, AttributeSet attrs) { super(context, attrs); @@ -134,13 +133,5 @@ public abstract class StackScrollerDecorView extends ExpandableView { mContent.animate().cancel(); } - public boolean willBeGone() { - return mWillBeGone; - } - - public void setWillBeGone(boolean willBeGone) { - mWillBeGone = willBeGone; - } - protected abstract View findContentView(); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index f1e51a5295abb..74116c1a25cb1 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -32,7 +32,6 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.content.pm.IPackageManager; -import android.content.pm.PackageManager; import android.content.res.Configuration; import android.content.res.Resources; import android.database.ContentObserver; @@ -707,7 +706,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, R.layout.status_bar_notification_keyguard_overflow, mStackScroller, false); mKeyguardIconOverflowContainer.setOnActivatedListener(this); mKeyguardIconOverflowContainer.setOnClickListener(mOverflowClickListener); - mStackScroller.addView(mKeyguardIconOverflowContainer); + mStackScroller.setOverflowContainer(mKeyguardIconOverflowContainer); SpeedBumpView speedBump = (SpeedBumpView) LayoutInflater.from(mContext).inflate( R.layout.status_bar_notification_speed_bump, mStackScroller, false); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java index d8f6bcd17a2a7..6e0c85cba3890 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java @@ -43,6 +43,7 @@ import com.android.systemui.statusbar.EmptyShadeView; import com.android.systemui.statusbar.ExpandableNotificationRow; import com.android.systemui.statusbar.ExpandableView; import com.android.systemui.statusbar.NotificationData; +import com.android.systemui.statusbar.NotificationOverflowContainer; import com.android.systemui.statusbar.SpeedBumpView; import com.android.systemui.statusbar.StackScrollerDecorView; import com.android.systemui.statusbar.StatusBarState; @@ -226,6 +227,7 @@ public class NotificationStackScrollLayout extends ViewGroup private boolean mTrackingHeadsUp; private ScrimController mScrimController; private boolean mForceNoOverlappingRendering; + private NotificationOverflowContainer mOverflowContainer; public NotificationStackScrollLayout(Context context) { this(context, null); @@ -1368,17 +1370,11 @@ public class NotificationStackScrollLayout extends ViewGroup int childCount = getChildCount(); int count = 0; for (int i = 0; i < childCount; i++) { - View child = getChildAt(i); - if (child.getVisibility() != View.GONE) { + ExpandableView child = (ExpandableView) getChildAt(i); + if (child.getVisibility() != View.GONE && !child.willBeGone()) { count++; } } - if (mDismissView.willBeGone()) { - count--; - } - if (mEmptyShadeView.willBeGone()) { - count--; - } return count; } @@ -2470,7 +2466,7 @@ public class NotificationStackScrollLayout extends ViewGroup mEmptyShadeView.setVisibility(newVisibility); mEmptyShadeView.setWillBeGone(false); updateContentHeight(); - notifyHeightChangeListener(mDismissView); + notifyHeightChangeListener(mEmptyShadeView); } else { Runnable onFinishedRunnable = new Runnable() { @Override @@ -2478,7 +2474,7 @@ public class NotificationStackScrollLayout extends ViewGroup mEmptyShadeView.setVisibility(GONE); mEmptyShadeView.setWillBeGone(false); updateContentHeight(); - notifyHeightChangeListener(mDismissView); + notifyHeightChangeListener(mEmptyShadeView); } }; if (mAnimationsEnabled) { @@ -2492,6 +2488,45 @@ public class NotificationStackScrollLayout extends ViewGroup } } + public void setOverflowContainer(NotificationOverflowContainer overFlowContainer) { + mOverflowContainer = overFlowContainer; + addView(mOverflowContainer); + } + + public void updateOverflowContainerVisibility(boolean visible) { + int oldVisibility = mOverflowContainer.willBeGone() ? GONE + : mOverflowContainer.getVisibility(); + final int newVisibility = visible ? VISIBLE : GONE; + if (oldVisibility != newVisibility) { + Runnable onFinishedRunnable = new Runnable() { + @Override + public void run() { + mOverflowContainer.setVisibility(newVisibility); + mOverflowContainer.setWillBeGone(false); + updateContentHeight(); + notifyHeightChangeListener(mOverflowContainer); + } + }; + if (!mAnimationsEnabled || !mIsExpanded) { + mOverflowContainer.cancelAppearDrawing(); + onFinishedRunnable.run(); + } else if (newVisibility != GONE) { + mOverflowContainer.performAddAnimation(0, + StackStateAnimator.ANIMATION_DURATION_STANDARD); + mOverflowContainer.setVisibility(newVisibility); + mOverflowContainer.setWillBeGone(false); + updateContentHeight(); + notifyHeightChangeListener(mOverflowContainer); + } else { + mOverflowContainer.performRemoveAnimation( + StackStateAnimator.ANIMATION_DURATION_STANDARD, + 0.0f, + onFinishedRunnable); + mOverflowContainer.setWillBeGone(true); + } + } + } + public void updateDismissView(boolean visible) { int oldVisibility = mDismissView.willBeGone() ? GONE : mDismissView.getVisibility(); int newVisibility = visible ? VISIBLE : GONE; diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollState.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollState.java index feae590aecfe7..a70ad43a71de4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollState.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackScrollState.java @@ -210,7 +210,10 @@ public class StackScrollState { int oldVisibility = view.getVisibility(); int newVisibility = becomesInvisible ? View.INVISIBLE : View.VISIBLE; if (newVisibility != oldVisibility) { - view.setVisibility(newVisibility); + if (!(view instanceof ExpandableView) || !((ExpandableView) view).willBeGone()) { + // We don't want views to change visibility when they are animating to GONE + view.setVisibility(newVisibility); + } } // apply yTranslation diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackStateAnimator.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackStateAnimator.java index eac5e79960f3b..b943afe06ff35 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackStateAnimator.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/StackStateAnimator.java @@ -284,6 +284,10 @@ public class StackStateAnimator { boolean scaleChanging = child.getScaleX() != viewState.scale; float childAlpha = child.getVisibility() == View.INVISIBLE ? 0.0f : child.getAlpha(); boolean alphaChanging = viewState.alpha != childAlpha; + if (child instanceof ExpandableView) { + // We don't want views to change visibility when they are animating to GONE + alphaChanging &= !((ExpandableView) child).willBeGone(); + } // start translationY animation if (yTranslationChanging) {