Fix up the QS gutter

 - Don't show when collapsed, show divider instead
 - Don't show when no notifications
 - Animate between states while expanding/collapsing
 - Other visual cleanup

Test: visual
Change-Id: I923c963fa70d63601b6a181299b04c5fc49922bb
Fixes: 38199857
Fixes: 38483355
Fixes: 38409326
Fixes: 38417776
(cherry picked from commit 4de5d3c03dfc49a1cdf7f9e9a0676c36987cea06)
diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QS.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QS.java
index 4a5a681..d571243 100644
--- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QS.java
+++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/qs/QS.java
@@ -62,6 +62,9 @@
 
     View getHeader();
 
+    default void setHasNotifications(boolean hasNotifications) {
+    }
+
     @ProvidesInterface(version = HeightListener.VERSION)
     public interface HeightListener {
         public static final int VERSION = 1;
diff --git a/packages/SystemUI/res/layout/qs_footer.xml b/packages/SystemUI/res/layout/qs_footer.xml
index c92c811..577be2f 100644
--- a/packages/SystemUI/res/layout/qs_footer.xml
+++ b/packages/SystemUI/res/layout/qs_footer.xml
@@ -27,20 +27,22 @@
     android:clipChildren="false"
     android:clipToPadding="false"
     android:paddingTop="0dp"
-    android:paddingEnd="8dp"
-    android:paddingStart="16dp"
     android:gravity="center_vertical"
     android:orientation="horizontal">
 
     <include
         android:id="@+id/date_time_alarm_group"
         layout="@layout/status_bar_alarm_group"
+        android:layout_marginStart="16dp"
+        android:layout_marginEnd="8dp"
         android:layout_width="wrap_content"
         android:layout_height="match_parent" />
 
     <LinearLayout
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
+        android:layout_marginStart="16dp"
+        android:layout_marginEnd="8dp"
         android:gravity="end">
 
         <com.android.systemui.statusbar.phone.MultiUserSwitch
@@ -113,4 +115,9 @@
             android:padding="14dp" />
     </LinearLayout>
 
+    <include layout="@layout/qs_divider"
+        android:layout_width="match_parent"
+        android:layout_height="1dp"
+        android:layout_gravity="bottom" />
+
 </com.android.systemui.qs.QSFooter>
diff --git a/packages/SystemUI/res/layout/quick_status_bar_expanded_header.xml b/packages/SystemUI/res/layout/quick_status_bar_expanded_header.xml
index 2502d41..005e955 100644
--- a/packages/SystemUI/res/layout/quick_status_bar_expanded_header.xml
+++ b/packages/SystemUI/res/layout/quick_status_bar_expanded_header.xml
@@ -41,8 +41,8 @@
         android:clipChildren="false"
         android:clipToPadding="false"
         android:gravity="center"
-        android:paddingStart="8dp"
-        android:paddingEnd="8dp"
+        android:paddingStart="16dp"
+        android:paddingEnd="16dp"
         android:orientation="horizontal">
 
 
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSContainerImpl.java b/packages/SystemUI/src/com/android/systemui/qs/QSContainerImpl.java
index 189c04c..149b5cc 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSContainerImpl.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSContainerImpl.java
@@ -17,14 +17,11 @@
 package com.android.systemui.qs;
 
 import android.content.Context;
-import android.graphics.Canvas;
-import android.graphics.Paint;
 import android.graphics.Point;
 import android.util.AttributeSet;
 import android.view.View;
 import android.widget.FrameLayout;
 
-import com.android.settingslib.Utils;
 import com.android.systemui.R;
 import com.android.systemui.qs.customize.QSCustomizer;
 
@@ -44,6 +41,7 @@
     private QSFooter mQSFooter;
     private int mGutterHeight;
     private View mBackground;
+    private float mFullElevation;
 
     public QSContainerImpl(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -59,6 +57,7 @@
         mQSFooter = findViewById(R.id.qs_footer);
         mBackground = findViewById(R.id.qs_background);
         mGutterHeight = getContext().getResources().getDimensionPixelSize(R.dimen.qs_gutter_height);
+        mFullElevation = mQSPanel.getElevation();
     }
 
     @Override
@@ -85,7 +84,7 @@
     @Override
     protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
         super.onLayout(changed, left, top, right, bottom);
-        updateBottom();
+        updateExpansion();
     }
 
     /**
@@ -96,27 +95,47 @@
      */
     public void setHeightOverride(int heightOverride) {
         mHeightOverride = heightOverride;
-        updateBottom();
+        updateExpansion();
     }
 
-    public void updateBottom() {
+    public void updateExpansion() {
         int height = calculateContainerHeight();
-        setBottom(getTop() + height + mGutterHeight);
+        int gutterHeight = Math.round(mQsExpansion * mGutterHeight);
+        setBottom(getTop() + height + gutterHeight);
         mQSDetail.setBottom(getTop() + height);
-        mBackground.setBottom(mQSDetail.getBottom());
+        mBackground.setBottom(getTop() + height);
         // Pin QS Footer to the bottom of the panel.
         mQSFooter.setTranslationY(height - mQSFooter.getHeight());
+
+        float elevation = mQsExpansion * mFullElevation;
+        mQSDetail.setElevation(elevation);
+        mBackground.setElevation(elevation);
+        mQSFooter.setElevation(elevation);
+        mQSPanel.setElevation(elevation);
     }
 
     protected int calculateContainerHeight() {
         int heightOverride = mHeightOverride != -1 ? mHeightOverride : getMeasuredHeight();
         return mQSCustomizer.isCustomizing() ? mQSCustomizer.getHeight()
-                : (int) (mQsExpansion * (heightOverride - mHeader.getHeight()))
+                : Math.round(mQsExpansion * (heightOverride - mHeader.getHeight()))
                 + mHeader.getHeight();
     }
 
     public void setExpansion(float expansion) {
         mQsExpansion = expansion;
-        updateBottom();
+        updateExpansion();
+    }
+
+    public void setGutterEnabled(boolean gutterEnabled) {
+        if (gutterEnabled == (mGutterHeight != 0)) {
+            return;
+        }
+        if (gutterEnabled) {
+            mGutterHeight = getContext().getResources().getDimensionPixelSize(
+                    R.dimen.qs_gutter_height);
+        } else {
+            mGutterHeight = 0;
+        }
+        updateExpansion();
     }
 }
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java b/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java
index 063f5df..87b042d 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSFooter.java
@@ -235,6 +235,7 @@
         }
 
         TouchAnimator.Builder animatorBuilder = new TouchAnimator.Builder();
+        animatorBuilder.setStartDelay(QSAnimator.EXPANDED_TILE_DELAY);
 
         if (mShowEditIcon) {
             animatorBuilder.addFloat(mEdit, "alpha", 0, 1);
diff --git a/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java b/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java
index 3f090f8..61fd624 100644
--- a/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java
+++ b/packages/SystemUI/src/com/android/systemui/qs/QSFragment.java
@@ -34,7 +34,6 @@
 import com.android.systemui.Interpolators;
 import com.android.systemui.R;
 import com.android.systemui.R.id;
-import com.android.systemui.R.style;
 import com.android.systemui.plugins.qs.QS;
 import com.android.systemui.qs.customize.QSCustomizer;
 import com.android.systemui.statusbar.phone.NotificationsQuickSettingsContainer;
@@ -130,6 +129,11 @@
         return mHeader;
     }
 
+    @Override
+    public void setHasNotifications(boolean hasNotifications) {
+        mContainer.setGutterEnabled(hasNotifications);
+    }
+
     public void setPanelView(HeightListener panelView) {
         mPanelView = panelView;
     }
@@ -307,7 +311,7 @@
 
     public void notifyCustomizeChanged() {
         // The customize state changed, so our height changed.
-        mContainer.updateBottom();
+        mContainer.updateExpansion();
         mQSPanel.setVisibility(!mQSCustomizer.isCustomizing() ? View.VISIBLE : View.INVISIBLE);
         mHeader.setVisibility(!mQSCustomizer.isCustomizing() ? View.VISIBLE : View.INVISIBLE);
         mFooter.setVisibility(!mQSCustomizer.isCustomizing() ? View.VISIBLE : View.INVISIBLE);
@@ -340,7 +344,7 @@
     }
 
     public int getQsMinExpansionHeight() {
-        return mHeader.getHeight() + mGutterHeight;
+        return mHeader.getHeight();
     }
 
     @Override
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 af2f7e9..6aab8e1 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -2535,6 +2535,9 @@
 
     public void setNoVisibleNotifications(boolean noNotifications) {
         mNoVisibleNotifications = noNotifications;
+        if (mQs != null) {
+            mQs.setHasNotifications(!noNotifications);
+        }
     }
 
     public void setPulsing(boolean pulsing) {