Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 1 | package com.android.systemui.statusbar.phone; |
| 2 | |
| 3 | import android.content.Context; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 4 | import android.content.res.Resources; |
| 5 | import android.graphics.Color; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 6 | import android.graphics.Rect; |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 7 | import android.support.annotation.NonNull; |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 8 | import android.support.v4.util.ArrayMap; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 9 | import android.view.LayoutInflater; |
| 10 | import android.view.View; |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 11 | import android.widget.FrameLayout; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 12 | |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 13 | import com.android.internal.statusbar.StatusBarIcon; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 14 | import com.android.internal.util.NotificationColorUtil; |
| 15 | import com.android.systemui.R; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 16 | import com.android.systemui.statusbar.ExpandableNotificationRow; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 17 | import com.android.systemui.statusbar.NotificationData; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 18 | import com.android.systemui.statusbar.NotificationShelf; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 19 | import com.android.systemui.statusbar.StatusBarIconView; |
| 20 | import com.android.systemui.statusbar.notification.NotificationUtils; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 21 | import com.android.systemui.statusbar.policy.DarkIconDispatcher; |
| 22 | import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 23 | import com.android.systemui.statusbar.stack.NotificationStackScrollLayout; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 24 | |
| 25 | import java.util.ArrayList; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 26 | import java.util.function.Function; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * A controller for the space in the status bar to the left of the system icons. This area is |
| 30 | * normally reserved for notifications. |
| 31 | */ |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 32 | public class NotificationIconAreaController implements DarkReceiver { |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 33 | private final NotificationColorUtil mNotificationColorUtil; |
| 34 | |
| 35 | private int mIconSize; |
| 36 | private int mIconHPadding; |
| 37 | private int mIconTint = Color.WHITE; |
| 38 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 39 | private StatusBar mStatusBar; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 40 | protected View mNotificationIconArea; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 41 | private NotificationIconContainer mNotificationIcons; |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 42 | private NotificationIconContainer mShelfIcons; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 43 | private final Rect mTintArea = new Rect(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 44 | private NotificationStackScrollLayout mNotificationScrollLayout; |
| 45 | private Context mContext; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 46 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 47 | public NotificationIconAreaController(Context context, StatusBar statusBar) { |
| 48 | mStatusBar = statusBar; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 49 | mNotificationColorUtil = NotificationColorUtil.getInstance(context); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 50 | mContext = context; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 51 | |
| 52 | initializeNotificationAreaViews(context); |
| 53 | } |
| 54 | |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 55 | protected View inflateIconArea(LayoutInflater inflater) { |
| 56 | return inflater.inflate(R.layout.notification_icon_area, null); |
| 57 | } |
| 58 | |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 59 | /** |
| 60 | * Initializes the views that will represent the notification area. |
| 61 | */ |
| 62 | protected void initializeNotificationAreaViews(Context context) { |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 63 | reloadDimens(context); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 64 | |
| 65 | LayoutInflater layoutInflater = LayoutInflater.from(context); |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 66 | mNotificationIconArea = inflateIconArea(layoutInflater); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 67 | mNotificationIcons = (NotificationIconContainer) mNotificationIconArea.findViewById( |
| 68 | R.id.notificationIcons); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 69 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 70 | mNotificationScrollLayout = mStatusBar.getNotificationScrollLayout(); |
| 71 | } |
| 72 | |
| 73 | public void setupShelf(NotificationShelf shelf) { |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 74 | mShelfIcons = shelf.getShelfIcons(); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 75 | shelf.setCollapsedIcons(mNotificationIcons); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 76 | } |
| 77 | |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 78 | public void onDensityOrFontScaleChanged(Context context) { |
| 79 | reloadDimens(context); |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 80 | final FrameLayout.LayoutParams params = generateIconLayoutParams(); |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 81 | for (int i = 0; i < mNotificationIcons.getChildCount(); i++) { |
| 82 | View child = mNotificationIcons.getChildAt(i); |
| 83 | child.setLayoutParams(params); |
Selim Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 84 | } |
| 85 | for (int i = 0; i < mShelfIcons.getChildCount(); i++) { |
| 86 | View child = mShelfIcons.getChildAt(i); |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 87 | child.setLayoutParams(params); |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 88 | } |
| 89 | } |
| 90 | |
| 91 | @NonNull |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 92 | private FrameLayout.LayoutParams generateIconLayoutParams() { |
| 93 | return new FrameLayout.LayoutParams( |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 94 | mIconSize + 2 * mIconHPadding, getHeight()); |
| 95 | } |
| 96 | |
| 97 | private void reloadDimens(Context context) { |
| 98 | Resources res = context.getResources(); |
| 99 | mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size); |
| 100 | mIconHPadding = res.getDimensionPixelSize(R.dimen.status_bar_icon_padding); |
| 101 | } |
| 102 | |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 103 | /** |
| 104 | * Returns the view that represents the notification area. |
| 105 | */ |
| 106 | public View getNotificationInnerAreaView() { |
| 107 | return mNotificationIconArea; |
| 108 | } |
| 109 | |
| 110 | /** |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 111 | * See {@link com.android.systemui.statusbar.policy.DarkIconDispatcher#setIconsDarkArea}. |
| 112 | * Sets the color that should be used to tint any icons in the notification area. |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 113 | * |
| 114 | * @param tintArea the area in which to tint the icons, specified in screen coordinates |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 115 | * @param darkIntensity |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 116 | */ |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 117 | public void onDarkChanged(Rect tintArea, float darkIntensity, int iconTint) { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 118 | if (tintArea == null) { |
| 119 | mTintArea.setEmpty(); |
| 120 | } else { |
| 121 | mTintArea.set(tintArea); |
| 122 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 123 | mIconTint = iconTint; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 124 | applyNotificationIconsTint(); |
| 125 | } |
| 126 | |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 127 | protected int getHeight() { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 128 | return mStatusBar.getStatusBarHeight(); |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 131 | protected boolean shouldShowNotificationIcon(NotificationData.Entry entry, |
| 132 | NotificationData notificationData, boolean showAmbient) { |
Jorim Jaggi | fabc743 | 2017-05-15 02:40:05 +0200 | [diff] [blame] | 133 | if (notificationData.isAmbient(entry.key) && !showAmbient) { |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 134 | return false; |
| 135 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 136 | if (!StatusBar.isTopLevelChild(entry)) { |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 137 | return false; |
| 138 | } |
| 139 | if (entry.row.getVisibility() == View.GONE) { |
| 140 | return false; |
| 141 | } |
| 142 | |
| 143 | return true; |
| 144 | } |
| 145 | |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 146 | /** |
| 147 | * Updates the notifications with the given list of notifications to display. |
| 148 | */ |
| 149 | public void updateNotificationIcons(NotificationData notificationData) { |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 150 | |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 151 | updateIconsForLayout(notificationData, entry -> entry.icon, mNotificationIcons, |
| 152 | false /* showAmbient */); |
| 153 | updateIconsForLayout(notificationData, entry -> entry.expandedIcon, mShelfIcons, |
| 154 | NotificationShelf.SHOW_AMBIENT_ICONS); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 155 | |
| 156 | applyNotificationIconsTint(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | /** |
| 160 | * Updates the notification icons for a host layout. This will ensure that the notification |
| 161 | * host layout will have the same icons like the ones in here. |
| 162 | * |
| 163 | * @param notificationData the notification data to look up which notifications are relevant |
| 164 | * @param function A function to look up an icon view based on an entry |
| 165 | * @param hostLayout which layout should be updated |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 166 | * @param showAmbient should ambient notification icons be shown |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 167 | */ |
| 168 | private void updateIconsForLayout(NotificationData notificationData, |
| 169 | Function<NotificationData.Entry, StatusBarIconView> function, |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 170 | NotificationIconContainer hostLayout, boolean showAmbient) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 171 | ArrayList<StatusBarIconView> toShow = new ArrayList<>( |
| 172 | mNotificationScrollLayout.getChildCount()); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 173 | |
| 174 | // Filter out ambient notifications and notification children. |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 175 | for (int i = 0; i < mNotificationScrollLayout.getChildCount(); i++) { |
| 176 | View view = mNotificationScrollLayout.getChildAt(i); |
| 177 | if (view instanceof ExpandableNotificationRow) { |
| 178 | NotificationData.Entry ent = ((ExpandableNotificationRow) view).getEntry(); |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 179 | if (shouldShowNotificationIcon(ent, notificationData, showAmbient)) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 180 | toShow.add(function.apply(ent)); |
| 181 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 182 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 183 | } |
| 184 | |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 185 | // In case we are changing the suppression of a group, the replacement shouldn't flicker |
| 186 | // and it should just be replaced instead. We therefore look for notifications that were |
| 187 | // just replaced by the child or vice-versa to suppress this. |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 188 | |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 189 | ArrayMap<String, ArrayList<StatusBarIcon>> replacingIcons = new ArrayMap<>(); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 190 | ArrayList<View> toRemove = new ArrayList<>(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 191 | for (int i = 0; i < hostLayout.getChildCount(); i++) { |
| 192 | View child = hostLayout.getChildAt(i); |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 193 | if (!(child instanceof StatusBarIconView)) { |
| 194 | continue; |
| 195 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 196 | if (!toShow.contains(child)) { |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 197 | boolean iconWasReplaced = false; |
| 198 | StatusBarIconView removedIcon = (StatusBarIconView) child; |
| 199 | String removedGroupKey = removedIcon.getNotification().getGroupKey(); |
| 200 | for (int j = 0; j < toShow.size(); j++) { |
| 201 | StatusBarIconView candidate = toShow.get(j); |
| 202 | if (candidate.getSourceIcon().sameAs((removedIcon.getSourceIcon())) |
| 203 | && candidate.getNotification().getGroupKey().equals(removedGroupKey)) { |
| 204 | if (!iconWasReplaced) { |
| 205 | iconWasReplaced = true; |
| 206 | } else { |
| 207 | iconWasReplaced = false; |
| 208 | break; |
| 209 | } |
| 210 | } |
| 211 | } |
| 212 | if (iconWasReplaced) { |
| 213 | ArrayList<StatusBarIcon> statusBarIcons = replacingIcons.get(removedGroupKey); |
| 214 | if (statusBarIcons == null) { |
| 215 | statusBarIcons = new ArrayList<>(); |
| 216 | replacingIcons.put(removedGroupKey, statusBarIcons); |
| 217 | } |
| 218 | statusBarIcons.add(removedIcon.getStatusBarIcon()); |
| 219 | } |
| 220 | toRemove.add(removedIcon); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 221 | } |
| 222 | } |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 223 | // removing all duplicates |
| 224 | ArrayList<String> duplicates = new ArrayList<>(); |
| 225 | for (String key : replacingIcons.keySet()) { |
| 226 | ArrayList<StatusBarIcon> statusBarIcons = replacingIcons.get(key); |
| 227 | if (statusBarIcons.size() != 1) { |
| 228 | duplicates.add(key); |
| 229 | } |
| 230 | } |
| 231 | replacingIcons.removeAll(duplicates); |
| 232 | hostLayout.setReplacingIcons(replacingIcons); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 233 | |
| 234 | final int toRemoveCount = toRemove.size(); |
| 235 | for (int i = 0; i < toRemoveCount; i++) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 236 | hostLayout.removeView(toRemove.get(i)); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 237 | } |
| 238 | |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 239 | final FrameLayout.LayoutParams params = generateIconLayoutParams(); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 240 | for (int i = 0; i < toShow.size(); i++) { |
| 241 | View v = toShow.get(i); |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 242 | // The view might still be transiently added if it was just removed and added again |
| 243 | hostLayout.removeTransientView(v); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 244 | if (v.getParent() == null) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 245 | hostLayout.addView(v, i, params); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 249 | hostLayout.setChangingViewPositions(true); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 250 | // Re-sort notification icons |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 251 | final int childCount = hostLayout.getChildCount(); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 252 | for (int i = 0; i < childCount; i++) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 253 | View actual = hostLayout.getChildAt(i); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 254 | StatusBarIconView expected = toShow.get(i); |
| 255 | if (actual == expected) { |
| 256 | continue; |
| 257 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 258 | hostLayout.removeView(expected); |
| 259 | hostLayout.addView(expected, i); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 260 | } |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 261 | hostLayout.setChangingViewPositions(false); |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 262 | hostLayout.setReplacingIcons(null); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | /** |
| 266 | * Applies {@link #mIconTint} to the notification icons. |
| 267 | */ |
| 268 | private void applyNotificationIconsTint() { |
| 269 | for (int i = 0; i < mNotificationIcons.getChildCount(); i++) { |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 270 | final StatusBarIconView iv = (StatusBarIconView) mNotificationIcons.getChildAt(i); |
| 271 | if (iv.getWidth() != 0) { |
| 272 | updateTintForIcon(iv); |
| 273 | } else { |
| 274 | iv.executeOnLayout(() -> updateTintForIcon(iv)); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 275 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 276 | } |
| 277 | } |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 278 | |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 279 | private void updateTintForIcon(StatusBarIconView v) { |
| 280 | boolean isPreL = Boolean.TRUE.equals(v.getTag(R.id.icon_is_pre_L)); |
| 281 | int color = StatusBarIconView.NO_COLOR; |
| 282 | boolean colorize = !isPreL || NotificationUtils.isGrayscale(v, mNotificationColorUtil); |
| 283 | if (colorize) { |
| 284 | color = DarkIconDispatcher.getTint(mTintArea, v, mIconTint); |
| 285 | } |
| 286 | v.setStaticDrawableColor(color); |
| 287 | v.setDecorColor(mIconTint); |
| 288 | } |
| 289 | |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 290 | public void setDark(boolean dark) { |
| 291 | mNotificationIcons.setDark(dark, false, 0); |
| 292 | mShelfIcons.setDark(dark, false, 0); |
| 293 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 294 | } |