Clean up hiden notifications on Keyguard handling

Change-Id: Ifeabfdd1ed8c11b0796cc79bba81752518921be3
This commit is contained in:
Jorim Jaggi
2014-08-05 16:22:30 +02:00
parent 106c16fbd9
commit 62a7c831d5
3 changed files with 57 additions and 62 deletions

View File

@@ -1364,13 +1364,9 @@ public abstract class BaseStatusBar extends SystemUI implements
* Updates expanded, dimmed and locked states of notification rows.
*/
protected void updateRowStates() {
int maxKeyguardNotifications = getMaxKeyguardNotifications();
mKeyguardIconOverflowContainer.getIconsView().removeAllViews();
ArrayList<Entry> activeNotifications = mNotificationData.getActiveNotifications();
final int N = activeNotifications.size();
int visibleNotifications = 0;
boolean onKeyguard = mState == StatusBarState.KEYGUARD;
for (int i = 0; i < N; i++) {
NotificationData.Entry entry = activeNotifications.get(i);
@@ -1383,38 +1379,7 @@ public abstract class BaseStatusBar extends SystemUI implements
entry.row.setSystemExpanded(top);
}
}
boolean showOnKeyguard = shouldShowOnKeyguard(entry.notification);
if (onKeyguard && (visibleNotifications >= maxKeyguardNotifications
|| !showOnKeyguard)) {
entry.row.setVisibility(View.GONE);
if (showOnKeyguard) {
mKeyguardIconOverflowContainer.getIconsView().addNotification(entry);
}
} else {
boolean wasGone = entry.row.getVisibility() == View.GONE;
entry.row.setVisibility(View.VISIBLE);
if (wasGone) {
// notify the scroller of a child addition
mStackScroller.generateAddAnimation(entry.row, true /* fromMoreCard */);
}
visibleNotifications++;
}
}
if (onKeyguard && mKeyguardIconOverflowContainer.getIconsView().getChildCount() > 0) {
mKeyguardIconOverflowContainer.setVisibility(View.VISIBLE);
} else {
mKeyguardIconOverflowContainer.setVisibility(View.GONE);
}
mStackScroller.changeViewPosition(mKeyguardIconOverflowContainer,
mStackScroller.getChildCount() - 3);
mStackScroller.changeViewPosition(mDismissView, mStackScroller.getChildCount() - 2);
mStackScroller.changeViewPosition(mEmptyShadeView, mStackScroller.getChildCount() - 1);
}
private boolean shouldShowOnKeyguard(StatusBarNotification sbn) {
return mShowLockscreenNotifications && !mNotificationData.isAmbient(sbn.getKey());
}
protected void setZenMode(int mode) {

View File

@@ -158,6 +158,7 @@ import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
@@ -337,6 +338,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
: null;
private int mNavigationIconHints = 0;
private final HashSet<View> mOverflowNotifications = new HashSet<>();
private final HashSet<View> mOldOverflowNotifications = new HashSet<>();
// ensure quick settings is disabled until the current user makes it through the setup wizard
private boolean mUserSetup = false;
@@ -1355,13 +1358,33 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
private void updateNotificationShade() {
if (mStackScroller == null) return;
int speedbumpIndex = -1;
int maxKeyguardNotifications = getMaxKeyguardNotifications();
mKeyguardIconOverflowContainer.getIconsView().removeAllViews();
int visibleNotifications = 0;
boolean onKeyguard = mState == StatusBarState.KEYGUARD;
mOldOverflowNotifications.clear();
mOldOverflowNotifications.addAll(mOverflowNotifications);
ArrayList<Entry> activeNotifications = mNotificationData.getActiveNotifications();
ArrayList<ExpandableNotificationRow> toShow = new ArrayList<>(activeNotifications.size());
ArrayList<View> toShow = new ArrayList<>(activeNotifications.size());
final int N = activeNotifications.size();
for (int i=0; i<N; i++) {
Entry ent = activeNotifications.get(i);
int vis = ent.notification.getNotification().visibility;
// Decide whether to hide to notification because of Keyguard showing.
boolean showOnKeyguard = mShowLockscreenNotifications
&& !mNotificationData.isAmbient(ent.key);
if (onKeyguard && (visibleNotifications >= maxKeyguardNotifications
|| !showOnKeyguard)) {
if (showOnKeyguard) {
mKeyguardIconOverflowContainer.getIconsView().addNotification(ent);
mOverflowNotifications.add(ent.row);
}
continue;
}
// Display public version of the notification if we need to redact.
final boolean hideSensitive =
!userAllowsPrivateNotificationsInPublic(ent.notification.getUserId());
@@ -1379,12 +1402,23 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
}
}
toShow.add(ent.row);
visibleNotifications++;
// Handle speed bump.
if (speedbumpIndex == -1 && mNotificationData.isAmbient(ent.key)) {
speedbumpIndex = visibleNotifications-1;
}
}
if (onKeyguard && mKeyguardIconOverflowContainer.getIconsView().getChildCount() > 0) {
toShow.add(mKeyguardIconOverflowContainer);
}
ArrayList<View> toRemove = new ArrayList<View>();
for (int i=0; i< mStackScroller.getChildCount(); i++) {
View child = mStackScroller.getChildAt(i);
if (!toShow.contains(child) && child instanceof ExpandableNotificationRow) {
if ((child instanceof ExpandableNotificationRow
|| child == mKeyguardIconOverflowContainer) && !toShow.contains(child)) {
toRemove.add(child);
}
}
@@ -1396,6 +1430,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
View v = toShow.get(i);
if (v.getParent() == null) {
mStackScroller.addView(v);
if (mOldOverflowNotifications.contains(v)) {
mStackScroller.notifyAddFromMoreCard(v);
}
}
}
@@ -1422,7 +1459,15 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
j++;
}
updateRowStates();
updateSpeedbump();
mStackScroller.changeViewPosition(mEmptyShadeView,
mStackScroller.getChildCount() - 1);
mStackScroller.changeViewPosition(mDismissView,
mStackScroller.getChildCount() - 2);
mStackScroller.changeViewPosition(mKeyguardIconOverflowContainer,
mStackScroller.getChildCount() - 3);
mStackScroller.updateSpeedBumpIndex(speedbumpIndex);
updateClearAll();
updateEmptyShadeView();
@@ -1444,23 +1489,6 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
mNotificationPanel.setShadeEmpty(showEmptyShade);
}
private void updateSpeedbump() {
int speedbumpIndex = -1;
int currentIndex = 0;
ArrayList<Entry> activeNotifications = mNotificationData.getActiveNotifications();
final int N = activeNotifications.size();
for (int i = 0; i < N; i++) {
Entry entry = activeNotifications.get(i);
if (entry.row.getVisibility() != View.GONE &&
mNotificationData.isAmbient(entry.key)) {
speedbumpIndex = currentIndex;
break;
}
currentIndex++;
}
mStackScroller.updateSpeedBumpIndex(speedbumpIndex);
}
@Override
protected void updateNotifications() {
// TODO: Move this into updateNotificationIcons()?
@@ -2971,7 +2999,7 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
repositionNavigationBar();
updateExpandedViewPos(EXPANDED_LEAVE_ALONE);
updateShowSearchHoldoff();
updateRowStates();
updateNotificationShade();
}
@Override

View File

@@ -1520,7 +1520,7 @@ public class NotificationStackScrollLayout extends ViewGroup
super.onViewAdded(child);
mStackScrollAlgorithm.notifyChildrenChanged(this);
((ExpandableView) child).setOnHeightChangedListener(this);
generateAddAnimation(child, false /* fromMoreCard */);
generateAddAnimation(child);
}
public void setAnimationsEnabled(boolean animationsEnabled) {
@@ -1535,19 +1535,21 @@ public class NotificationStackScrollLayout extends ViewGroup
* Generate an animation for an added child view.
*
* @param child The view to be added.
* @param fromMoreCard Whether this add is coming from the "more" card on lockscreen.
*/
public void generateAddAnimation(View child, boolean fromMoreCard) {
private void generateAddAnimation(View child) {
if (mIsExpanded && mAnimationsEnabled && !mChangePositionInProgress) {
// Generate Animations
mChildrenToAddAnimated.add(child);
if (fromMoreCard) {
mFromMoreCardAdditions.add(child);
}
mNeedsAnimation = true;
}
}
public void notifyAddFromMoreCard(View v) {
if (mChildrenToAddAnimated.contains(v)) {
mFromMoreCardAdditions.add(v);
}
}
/**
* Change the position of child to a new location
*