Fix occasional jank when going to QS.

We change the listening state of the QS panel before the user
actually navigates there and when the animations are probably
not running (after expanding the panel).

Change-Id: Iad48b3459e7db09c423f6983a9fec17ec0088050
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 c82bdf6..fd2db8e 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -35,6 +35,7 @@
 import android.widget.TextView;
 
 import com.android.systemui.R;
+import com.android.systemui.qs.QSPanel;
 import com.android.systemui.statusbar.ExpandableView;
 import com.android.systemui.statusbar.FlingAnimationUtils;
 import com.android.systemui.statusbar.GestureRecorder;
@@ -61,7 +62,7 @@
     private KeyguardPageSwipeHelper mPageSwiper;
     private StatusBarHeaderView mHeader;
     private View mQsContainer;
-    private View mQsPanel;
+    private QSPanel mQsPanel;
     private View mKeyguardStatusView;
     private ObservableScrollView mScrollView;
     private TextView mClockView;
@@ -136,7 +137,7 @@
         mHeader.setOverlayParent(this);
         mKeyguardStatusView = findViewById(R.id.keyguard_status_view);
         mQsContainer = findViewById(R.id.quick_settings_container);
-        mQsPanel = findViewById(R.id.quick_settings_panel);
+        mQsPanel = (QSPanel) findViewById(R.id.quick_settings_panel);
         mClockView = (TextView) findViewById(R.id.clock_view);
         mScrollView = (ObservableScrollView) findViewById(R.id.scroll_view);
         mScrollView.setListener(this);
@@ -873,6 +874,20 @@
         super.onExpandingFinished();
         mNotificationStackScroller.onExpansionStopped();
         mIsExpanding = false;
+        if (mExpandedHeight == 0f) {
+            mHeader.setListening(false);
+            mQsPanel.setListening(false);
+        } else {
+            mHeader.setListening(true);
+            mQsPanel.setListening(true);
+        }
+    }
+
+    @Override
+    public void instantExpand() {
+        super.instantExpand();
+        mHeader.setListening(true);
+        mQsPanel.setListening(true);
     }
 
     @Override
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java
index 9e9de5d..3e2dcef 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBarHeaderView.java
@@ -45,6 +45,7 @@
     private static final float EXPANSION_RUBBERBAND_FACTOR = 0.35f;
 
     private boolean mExpanded;
+    private boolean mListening;
     private boolean mOverscrolled;
     private boolean mKeyguardShowing;
 
@@ -145,6 +146,14 @@
         return mExpandedHeight;
     }
 
+    public void setListening(boolean listening) {
+        if (listening == mListening) {
+            return;
+        }
+        mListening = listening;
+        updateBrightnessControllerState();
+    }
+
     public void setExpanded(boolean expanded, boolean overscrolled) {
         boolean changed = expanded != mExpanded;
         boolean overscrollChanged = overscrolled != mOverscrolled;
@@ -154,7 +163,6 @@
             updateHeights();
             updateVisibilities();
             updateSystemIconsLayoutParams();
-            updateBrightnessControllerState();
             updateZTranslation();
             updateClickTargets();
             updateWidth();
@@ -254,7 +262,7 @@
     }
 
     private void updateBrightnessControllerState() {
-        if (mExpanded) {
+        if (mListening) {
             mBrightnessController.registerCallbacks();
         } else {
             mBrightnessController.unregisterCallbacks();