Enabled appear and dissappear animations for the overflow card

Bug: 21651647
Change-Id: I0732cb27ec8f88ae74fcff11340092879ba8bae3
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java b/packages/SystemUI/src/com/android/systemui/statusbar/ActivatableNotificationView.java
index c0b3a9b..8bee008 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 @@
 
     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 @@
         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 6fb4b48..09e4e5c 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 @@
             }
         }
 
-        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 3feec9e..8c03350 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 @@
     private ArrayList<View> mMatchParentViews = new ArrayList<View>();
     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 @@
         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 64d80cc..2f66c41 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 @@
     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 @@
         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 f1e51a52..74116c1 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.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 @@
                         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 d8f6bcd..6e0c85c 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.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 @@
     private boolean mTrackingHeadsUp;
     private ScrimController mScrimController;
     private boolean mForceNoOverlappingRendering;
+    private NotificationOverflowContainer mOverflowContainer;
 
     public NotificationStackScrollLayout(Context context) {
         this(context, null);
@@ -1368,17 +1370,11 @@
         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 @@
                 mEmptyShadeView.setVisibility(newVisibility);
                 mEmptyShadeView.setWillBeGone(false);
                 updateContentHeight();
-                notifyHeightChangeListener(mDismissView);
+                notifyHeightChangeListener(mEmptyShadeView);
             } else {
                 Runnable onFinishedRunnable = new Runnable() {
                     @Override
@@ -2478,7 +2474,7 @@
                         mEmptyShadeView.setVisibility(GONE);
                         mEmptyShadeView.setWillBeGone(false);
                         updateContentHeight();
-                        notifyHeightChangeListener(mDismissView);
+                        notifyHeightChangeListener(mEmptyShadeView);
                     }
                 };
                 if (mAnimationsEnabled) {
@@ -2492,6 +2488,45 @@
         }
     }
 
+    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 feae590..a70ad43 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 @@
         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 eac5e79..b943afe 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 @@
         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) {