Fixed the appearing of the statusbar icons

The statusbar icons are now correctly appearing
in case there are no notifications instead of just
jumping.

This also fixed the general case, where the icons wouldn't
fade correctly in landscape

Change-Id: I38c6970b7663a8654a27555c2230e68de81a6da8
Test: observe fading of statusbar icons with and without notifications
Bug: 33652489
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java
index 296c788..bc1b9fb 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationShelf.java
@@ -66,6 +66,7 @@
     private int mScrollFastThreshold;
     private int mStatusBarState;
     private float mMaxShelfEnd;
+    private int mRelativeOffset;
 
     public NotificationShelf(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -475,9 +476,21 @@
         return super.shouldHideBackground() || mHideBackground;
     }
 
-    private void setOpenedAmount(float openedAmount) {
+    @Override
+    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
+        super.onLayout(changed, left, top, right, bottom);
         mCollapsedIcons.getLocationOnScreen(mTmp);
-        int start = mTmp[0];
+        mRelativeOffset = mTmp[0];
+        getLocationOnScreen(mTmp);
+        mRelativeOffset -= mTmp[0];
+    }
+
+    private void setOpenedAmount(float openedAmount) {
+        if (!mAmbientState.isPanelFullWidth()) {
+            // We don't do a transformation at all, lets just assume we are fully opened
+            openedAmount = 1.0f;
+        }
+        int start = mRelativeOffset;
         if (isLayoutRtl()) {
             start = getWidth() - start - mCollapsedIcons.getWidth();
         }
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 7f6322a..7500aa7 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java
@@ -210,6 +210,7 @@
     private NotificationGroupManager mGroupManager;
     private boolean mOpening;
     private int mIndicationBottomPadding;
+    private boolean mIsFullWidth;
 
     public NotificationPanelView(Context context, AttributeSet attrs) {
         super(context, attrs);
@@ -302,6 +303,7 @@
     @Override
     protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
         super.onLayout(changed, left, top, right, bottom);
+        setIsFullWidth(mNotificationStackScroller.getWidth() == getWidth());
 
         // Update Clock Pivot
         mKeyguardStatusView.setPivotX(getWidth() / 2);
@@ -340,6 +342,11 @@
         updateMaxHeadsUpTranslation();
     }
 
+    private void setIsFullWidth(boolean isFullWidth) {
+        mIsFullWidth = isFullWidth;
+        mNotificationStackScroller.setIsFullWidth(isFullWidth);
+    }
+
     private void startQsSizeChangeAnimation(int oldHeight, final int newHeight) {
         if (mQsSizeChangeAnimator != null) {
             oldHeight = (int) mQsSizeChangeAnimator.getAnimatedValue();
@@ -736,7 +743,7 @@
 
     @Override
     protected float getOpeningHeight() {
-        return mNotificationStackScroller.getMinExpansionHeight();
+        return mNotificationStackScroller.getOpeningHeight();
     }
 
     @Override
@@ -2288,7 +2295,15 @@
         }
         mNotificationStackScroller.setExpandedHeight(expandedHeight);
         updateKeyguardBottomAreaAlpha();
-        setOpening(expandedHeight <= getOpeningHeight());
+        setOpening(isFullWidth() && expandedHeight < getOpeningHeight());
+    }
+
+    /**
+     * @return whether the notifications are displayed full width and don't have any margins on
+     *         the side.
+     */
+    public boolean isFullWidth() {
+        return mIsFullWidth;
     }
 
     private void setOpening(boolean opening) {
@@ -2401,12 +2416,11 @@
     }
 
     public boolean shouldHideNotificationIcons() {
-        return !mOpening && !isFullyCollapsed();
+        return !isFullWidth() || (!mOpening && !isFullyCollapsed());
     }
 
     public boolean shouldAnimateIconHiding() {
-        // TODO: handle this correctly, not completely working yet
-        return mNotificationStackScroller.getTranslationX() != 0;
+        return !isFullWidth();
     }
 
     private final FragmentListener mFragmentListener = new FragmentListener() {
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/AmbientState.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/AmbientState.java
index e1ff297..fe83dc4 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/AmbientState.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/AmbientState.java
@@ -58,6 +58,7 @@
     private float mExpandingVelocity;
     private boolean mPanelTracking;
     private boolean mExpansionChanging;
+    private boolean mPanelFullWidth;
 
     public AmbientState(Context context) {
         reload(context);
@@ -287,4 +288,12 @@
     public boolean isPanelTracking() {
         return mPanelTracking;
     }
+
+    public boolean isPanelFullWidth() {
+        return mPanelFullWidth;
+    }
+
+    public void setPanelFullWidth(boolean panelFullWidth) {
+        mPanelFullWidth = panelFullWidth;
+    }
 }
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 e7c2507..06cd769 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java
@@ -4012,6 +4012,18 @@
         mAmbientState.setExpandingVelocity(expandingVelocity);
     }
 
+    public float getOpeningHeight() {
+        if (mEmptyShadeView.getVisibility() == GONE) {
+            return getMinExpansionHeight();
+        } else {
+            return getAppearEndPosition();
+        }
+    }
+
+    public void setIsFullWidth(boolean isFullWidth) {
+        mAmbientState.setPanelFullWidth(isFullWidth);
+    }
+
     /**
      * A listener that is notified when some child locations might have changed.
      */