From fa760d46369f1ee7baedd174cc8f973594c52970 Mon Sep 17 00:00:00 2001 From: Selim Cinek Date: Tue, 10 May 2016 15:50:53 -0400 Subject: [PATCH] Fixed a bug where the positioning on the lockscreen was wrong Because of a circular dependancy of calculating the notification heights and setting them to GONE, the views could be laid out in a wrong fashion. Another issue was that ambient notifications would still be taken into account as well as removed notifications. This also lead to a bug where the removal of notifications could lead to unnecessary add animations when swiping them away. Change-Id: If9ad81237a520b14dc6851df3af52406d192a7a7 Fixes: 28441832 --- .../android/systemui/statusbar/BaseStatusBar.java | 6 +++--- .../statusbar/phone/NotificationPanelView.java | 9 ++++++++- .../systemui/statusbar/phone/PhoneStatusBar.java | 1 + .../stack/NotificationChildrenContainer.java | 13 +++++++------ .../stack/NotificationStackScrollLayout.java | 13 ++++++++----- 5 files changed, 27 insertions(+), 15 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java index 8d7ef2725bcf4..959b14407c26e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/BaseStatusBar.java @@ -92,8 +92,8 @@ import com.android.internal.logging.MetricsProto.MetricsEvent; import com.android.internal.statusbar.IStatusBarService; import com.android.internal.statusbar.StatusBarIcon; import com.android.internal.widget.LockPatternUtils; -import com.android.keyguard.KeyguardUpdateMonitor; import com.android.keyguard.KeyguardHostView.OnDismissAction; +import com.android.keyguard.KeyguardUpdateMonitor; import com.android.systemui.DejankUtils; import com.android.systemui.Interpolators; import com.android.systemui.R; @@ -2177,7 +2177,7 @@ public abstract class BaseStatusBar extends SystemUI implements } else { boolean wasGone = entry.row.getVisibility() == View.GONE; entry.row.setVisibility(View.VISIBLE); - if (!childNotification) { + if (!childNotification && !entry.row.isRemoved()) { if (wasGone) { // notify the scroller of a child addition mStackScroller.generateAddAnimation(entry.row, @@ -2197,7 +2197,7 @@ public abstract class BaseStatusBar extends SystemUI implements mStackScroller.getChildCount() - 3); } - private boolean shouldShowOnKeyguard(StatusBarNotification sbn) { + public boolean shouldShowOnKeyguard(StatusBarNotification sbn) { return mShowLockscreenNotifications && !mNotificationData.isAmbient(sbn.getKey()); } 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 7e2fa2da94ce3..5256e4f6d1843 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java @@ -418,11 +418,18 @@ public class NotificationPanelView extends PanelView implements if (!(child instanceof ExpandableNotificationRow)) { continue; } + ExpandableNotificationRow row = (ExpandableNotificationRow) child; boolean suppressedSummary = mGroupManager.isSummaryOfSuppressedGroup( - ((ExpandableNotificationRow) child).getStatusBarNotification()); + row.getStatusBarNotification()); if (suppressedSummary) { continue; } + if (!mStatusBar.shouldShowOnKeyguard(row.getStatusBarNotification())) { + continue; + } + if (row.isRemoved()) { + continue; + } availableSpace -= child.getMinHeight() + notificationPadding; if (availableSpace >= 0 && count < maximum) { count++; 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 85857008180da..3864f26eef26e 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -1530,6 +1530,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, ArrayList toRemove = new ArrayList<>(notificationChildren); for (int i = 0; i < toRemove.size(); i++) { toRemove.get(i).setKeepInParent(true); + toRemove.get(i).setRemoved(true); } for (int i = 0; i < toRemove.size(); i++) { removeNotification(toRemove.get(i).getStatusBarNotification().getKey(), ranking); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationChildrenContainer.java b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationChildrenContainer.java index a1e89b75a9727..dafaf61df1ea6 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationChildrenContainer.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationChildrenContainer.java @@ -103,9 +103,8 @@ public class NotificationChildrenContainer extends ViewGroup { int childCount = Math.min(mChildren.size(), NUMBER_OF_CHILDREN_WHEN_CHILDREN_EXPANDED); for (int i = 0; i < childCount; i++) { View child = mChildren.get(i); - if (child.getVisibility() == View.GONE) { - continue; - } + // We need to layout all children even the GONE ones, such that the heights are + // calculated correctly as they are used to calculate how many we can fit on the screen child.layout(0, 0, child.getMeasuredWidth(), child.getMeasuredHeight()); mDividers.get(i).layout(0, 0, getWidth(), mDividerHeight); } @@ -138,17 +137,19 @@ public class NotificationChildrenContainer extends ViewGroup { int overflowIndex = childCount > collapsedChildren ? collapsedChildren - 1 : -1; for (int i = 0; i < childCount; i++) { ExpandableNotificationRow child = mChildren.get(i); + // We need to measure all children even the GONE ones, such that the heights are + // calculated correctly as they are used to calculate how many we can fit on the screen. boolean isOverflow = i == overflowIndex; child.setSingleLineWidthIndention(isOverflow && mOverflowNumber != null ? mOverflowNumber.getMeasuredWidth() : 0); child.measure(widthMeasureSpec, newHeightSpec); - height += child.getMeasuredHeight(); - // layout the divider View divider = mDividers.get(i); divider.measure(widthMeasureSpec, dividerHeightSpec); - height += mDividerHeight; + if (child.getVisibility() != GONE) { + height += child.getMeasuredHeight() + mDividerHeight; + } } mRealHeight = height; if (heightMode != MeasureSpec.UNSPECIFIED) { 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 fcd5cad7f6ec3..87dcb914acd6a 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/stack/NotificationStackScrollLayout.java @@ -480,19 +480,22 @@ public class NotificationStackScrollLayout extends ViewGroup @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); - measureChildren(widthMeasureSpec, heightMeasureSpec); + // We need to measure all children even the GONE ones, such that the heights are calculated + // correctly as they are used to calculate how many we can fit on the screen. + final int size = getChildCount(); + for (int i = 0; i < size; i++) { + measureChild(getChildAt(i), widthMeasureSpec, heightMeasureSpec); + } } @Override protected void onLayout(boolean changed, int l, int t, int r, int b) { - // we layout all our children centered on the top float centerX = getWidth() / 2.0f; for (int i = 0; i < getChildCount(); i++) { View child = getChildAt(i); - if (child.getVisibility() == GONE) { - continue; - } + // We need to layout all children even the GONE ones, such that the heights are + // calculated correctly as they are used to calculate how many we can fit on the screen float width = child.getMeasuredWidth(); float height = child.getMeasuredHeight(); child.layout((int) (centerX - width / 2.0f),