public void updateNotificationIcons(NotificationData notificationData) { final LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( mIconSize + 2 * mIconHPadding, mPhoneStatusBar.getStatusBarHeight()); ArrayList<NotificationData.Entry> activeNotifications = notificationData.getActiveNotifications(); final int N = activeNotifications.size(); ArrayList<StatusBarIconView> toShow = new ArrayList<>(N); // Filter out ambient notifications and notification children. for (int i = 0; i < N; i++) { NotificationData.Entry ent = activeNotifications.get(i); if (notificationData.isAmbient(ent.key) && !NotificationData.showNotificationEvenIfUnprovisioned(ent.notification)) { continue; } if (!PhoneStatusBar.isTopLevelChild(ent)) { continue; } toShow.add(ent.icon); } ArrayList<View> toRemove = new ArrayList<>(); for (int i = 0; i < mNotificationIcons.getChildCount(); i++) { View child = mNotificationIcons.getChildAt(i); if (!toShow.contains(child)) { toRemove.add(child); } } final int toRemoveCount = toRemove.size(); for (int i = 0; i < toRemoveCount; i++) { mNotificationIcons.removeView(toRemove.get(i)); } for (int i = 0; i < toShow.size(); i++) { View v = toShow.get(i); if (v.getParent() == null) { mNotificationIcons.addView(v, i, params); } } // Resort notification icons final int childCount = mNotificationIcons.getChildCount(); for (int i = 0; i < childCount; i++) { View actual = mNotificationIcons.getChildAt(i); StatusBarIconView expected = toShow.get(i); if (actual == expected) { continue; } mNotificationIcons.removeView(expected); mNotificationIcons.addView(expected, i); } applyNotificationIconsTint(); }
private void applyNotificationIconsTint() { for (int i = 0; i < mNotificationIcons.getChildCount(); i++) { StatusBarIconView v = (StatusBarIconView) mNotificationIcons.getChildAt(i); boolean isPreL = Boolean.TRUE.equals(v.getTag(R.id.icon_is_pre_L)); boolean colorize = !isPreL || isGrayscale(v); if (colorize) { v.setImageTintList(ColorStateList.valueOf(mIconTint)); } } }