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; |
Aurimas Liutikas | fd52c14 | 2018-04-17 09:50:46 -0700 | [diff] [blame] | 7 | import androidx.annotation.NonNull; |
| 8 | import androidx.collection.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; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 14 | import com.android.internal.util.ContrastColorUtil; |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 15 | import com.android.systemui.Dependency; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 16 | import com.android.systemui.R; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 18 | import com.android.systemui.statusbar.notification.NotificationData; |
| 19 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 20 | import com.android.systemui.statusbar.NotificationShelf; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 21 | import com.android.systemui.statusbar.StatusBarIconView; |
| 22 | import com.android.systemui.statusbar.notification.NotificationUtils; |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 23 | import com.android.systemui.statusbar.policy.DarkIconDispatcher; |
| 24 | import com.android.systemui.statusbar.policy.DarkIconDispatcher.DarkReceiver; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 25 | import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 26 | |
| 27 | import java.util.ArrayList; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 28 | import java.util.function.Function; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 29 | |
| 30 | /** |
| 31 | * A controller for the space in the status bar to the left of the system icons. This area is |
| 32 | * normally reserved for notifications. |
| 33 | */ |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 34 | public class NotificationIconAreaController implements DarkReceiver { |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 35 | private final ContrastColorUtil mContrastColorUtil; |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 36 | private final NotificationEntryManager mEntryManager; |
| 37 | private final Runnable mUpdateStatusBarIcons = this::updateStatusBarIcons; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 38 | |
| 39 | private int mIconSize; |
| 40 | private int mIconHPadding; |
| 41 | private int mIconTint = Color.WHITE; |
| 42 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 43 | private StatusBar mStatusBar; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 44 | protected View mNotificationIconArea; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 45 | private NotificationIconContainer mNotificationIcons; |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 46 | private NotificationIconContainer mShelfIcons; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 47 | private final Rect mTintArea = new Rect(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 48 | private NotificationStackScrollLayout mNotificationScrollLayout; |
| 49 | private Context mContext; |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 50 | private boolean mFullyDark; |
| 51 | private boolean mHasShelfIconsWhenFullyDark; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 52 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 53 | public NotificationIconAreaController(Context context, StatusBar statusBar) { |
| 54 | mStatusBar = statusBar; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 55 | mContrastColorUtil = ContrastColorUtil.getInstance(context); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 56 | mContext = context; |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 57 | mEntryManager = Dependency.get(NotificationEntryManager.class); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 58 | |
| 59 | initializeNotificationAreaViews(context); |
| 60 | } |
| 61 | |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 62 | protected View inflateIconArea(LayoutInflater inflater) { |
| 63 | return inflater.inflate(R.layout.notification_icon_area, null); |
| 64 | } |
| 65 | |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 66 | /** |
| 67 | * Initializes the views that will represent the notification area. |
| 68 | */ |
| 69 | protected void initializeNotificationAreaViews(Context context) { |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 70 | reloadDimens(context); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 71 | |
| 72 | LayoutInflater layoutInflater = LayoutInflater.from(context); |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 73 | mNotificationIconArea = inflateIconArea(layoutInflater); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 74 | mNotificationIcons = (NotificationIconContainer) mNotificationIconArea.findViewById( |
| 75 | R.id.notificationIcons); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 76 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 77 | mNotificationScrollLayout = mStatusBar.getNotificationScrollLayout(); |
| 78 | } |
| 79 | |
| 80 | public void setupShelf(NotificationShelf shelf) { |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 81 | mShelfIcons = shelf.getShelfIcons(); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 82 | shelf.setCollapsedIcons(mNotificationIcons); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 83 | } |
| 84 | |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 85 | public void onDensityOrFontScaleChanged(Context context) { |
| 86 | reloadDimens(context); |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 87 | final FrameLayout.LayoutParams params = generateIconLayoutParams(); |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 88 | for (int i = 0; i < mNotificationIcons.getChildCount(); i++) { |
| 89 | View child = mNotificationIcons.getChildAt(i); |
| 90 | child.setLayoutParams(params); |
Selim Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 91 | } |
| 92 | for (int i = 0; i < mShelfIcons.getChildCount(); i++) { |
| 93 | View child = mShelfIcons.getChildAt(i); |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 94 | child.setLayoutParams(params); |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
| 98 | @NonNull |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 99 | private FrameLayout.LayoutParams generateIconLayoutParams() { |
| 100 | return new FrameLayout.LayoutParams( |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 101 | mIconSize + 2 * mIconHPadding, getHeight()); |
| 102 | } |
| 103 | |
| 104 | private void reloadDimens(Context context) { |
| 105 | Resources res = context.getResources(); |
| 106 | mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size); |
| 107 | mIconHPadding = res.getDimensionPixelSize(R.dimen.status_bar_icon_padding); |
| 108 | } |
| 109 | |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 110 | /** |
| 111 | * Returns the view that represents the notification area. |
| 112 | */ |
| 113 | public View getNotificationInnerAreaView() { |
| 114 | return mNotificationIconArea; |
| 115 | } |
| 116 | |
| 117 | /** |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 118 | * See {@link com.android.systemui.statusbar.policy.DarkIconDispatcher#setIconsDarkArea}. |
| 119 | * 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] | 120 | * |
| 121 | * @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] | 122 | * @param darkIntensity |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 123 | */ |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 124 | public void onDarkChanged(Rect tintArea, float darkIntensity, int iconTint) { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 125 | if (tintArea == null) { |
| 126 | mTintArea.setEmpty(); |
| 127 | } else { |
| 128 | mTintArea.set(tintArea); |
| 129 | } |
Evan Laird | dbeefe3 | 2018-04-03 16:52:41 -0400 | [diff] [blame] | 130 | if (mNotificationIconArea != null) { |
| 131 | if (DarkIconDispatcher.isInArea(tintArea, mNotificationIconArea)) { |
| 132 | mIconTint = iconTint; |
| 133 | } |
| 134 | } else { |
| 135 | mIconTint = iconTint; |
| 136 | } |
| 137 | |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 138 | applyNotificationIconsTint(); |
| 139 | } |
| 140 | |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 141 | protected int getHeight() { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 142 | return mStatusBar.getStatusBarHeight(); |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 143 | } |
| 144 | |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 145 | protected boolean shouldShowNotificationIcon(NotificationData.Entry entry, |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 146 | boolean showAmbient, boolean hideDismissed, boolean hideRepliedMessages) { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 147 | if (mEntryManager.getNotificationData().isAmbient(entry.key) && !showAmbient) { |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 148 | return false; |
| 149 | } |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 150 | if (!StatusBar.isTopLevelChild(entry)) { |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 151 | return false; |
| 152 | } |
| 153 | if (entry.row.getVisibility() == View.GONE) { |
| 154 | return false; |
| 155 | } |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 156 | if (entry.row.isDismissed() && hideDismissed) { |
| 157 | return false; |
| 158 | } |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 159 | |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 160 | if (hideRepliedMessages && entry.isLastMessageFromReply()) { |
| 161 | return false; |
| 162 | } |
| 163 | |
Julia Reynolds | c861a3d | 2018-02-15 10:34:49 -0500 | [diff] [blame] | 164 | // showAmbient == show in shade but not shelf |
Julia Reynolds | aa96cf3 | 2018-04-17 09:09:04 -0400 | [diff] [blame] | 165 | if (!showAmbient && mEntryManager.getNotificationData().shouldSuppressStatusBar(entry)) { |
Julia Reynolds | c861a3d | 2018-02-15 10:34:49 -0500 | [diff] [blame] | 166 | return false; |
| 167 | } |
| 168 | |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 169 | return true; |
| 170 | } |
| 171 | |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 172 | /** |
| 173 | * Updates the notifications with the given list of notifications to display. |
| 174 | */ |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 175 | public void updateNotificationIcons() { |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 176 | |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 177 | updateStatusBarIcons(); |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 178 | updateShelfIcons(); |
| 179 | updateHasShelfIconsWhenFullyDark(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 180 | |
| 181 | applyNotificationIconsTint(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 182 | } |
| 183 | |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 184 | private void updateHasShelfIconsWhenFullyDark() { |
| 185 | boolean hasIconsWhenFullyDark = false; |
| 186 | for (int i = 0; i < mNotificationScrollLayout.getChildCount(); i++) { |
| 187 | View view = mNotificationScrollLayout.getChildAt(i); |
| 188 | if (view instanceof ExpandableNotificationRow) { |
| 189 | NotificationData.Entry ent = ((ExpandableNotificationRow) view).getEntry(); |
| 190 | if (shouldShowNotificationIcon(ent, |
| 191 | NotificationShelf.SHOW_AMBIENT_ICONS /* showAmbient */, |
| 192 | false /* hideDismissed */, |
| 193 | true /* hideReplied */)) { |
| 194 | hasIconsWhenFullyDark = true; |
| 195 | break; |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | mHasShelfIconsWhenFullyDark = hasIconsWhenFullyDark; |
| 200 | } |
| 201 | |
| 202 | public boolean hasShelfIconsWhenFullyDark() { |
| 203 | return mHasShelfIconsWhenFullyDark; |
| 204 | } |
| 205 | |
| 206 | private void updateShelfIcons() { |
| 207 | updateIconsForLayout(entry -> entry.expandedIcon, mShelfIcons, |
| 208 | NotificationShelf.SHOW_AMBIENT_ICONS, false /* hideDismissed */, |
| 209 | mFullyDark /* hideRepliedMessages */); |
| 210 | } |
| 211 | |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 212 | public void updateStatusBarIcons() { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 213 | updateIconsForLayout(entry -> entry.icon, mNotificationIcons, |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 214 | false /* showAmbient */, true /* hideDismissed */, true /* hideRepliedMessages */); |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 217 | /** |
| 218 | * Updates the notification icons for a host layout. This will ensure that the notification |
| 219 | * host layout will have the same icons like the ones in here. |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 220 | * @param function A function to look up an icon view based on an entry |
| 221 | * @param hostLayout which layout should be updated |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 222 | * @param showAmbient should ambient notification icons be shown |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 223 | * @param hideDismissed should dismissed icons be hidden |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 224 | * @param hideRepliedMessages should messages that have been replied to be hidden |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 225 | */ |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 226 | private void updateIconsForLayout(Function<NotificationData.Entry, StatusBarIconView> function, |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 227 | NotificationIconContainer hostLayout, boolean showAmbient, boolean hideDismissed, |
| 228 | boolean hideRepliedMessages) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 229 | ArrayList<StatusBarIconView> toShow = new ArrayList<>( |
| 230 | mNotificationScrollLayout.getChildCount()); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 231 | |
| 232 | // Filter out ambient notifications and notification children. |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 233 | for (int i = 0; i < mNotificationScrollLayout.getChildCount(); i++) { |
| 234 | View view = mNotificationScrollLayout.getChildAt(i); |
| 235 | if (view instanceof ExpandableNotificationRow) { |
| 236 | NotificationData.Entry ent = ((ExpandableNotificationRow) view).getEntry(); |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 237 | if (shouldShowNotificationIcon(ent, showAmbient, hideDismissed, |
| 238 | hideRepliedMessages)) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 239 | toShow.add(function.apply(ent)); |
| 240 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 241 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 242 | } |
| 243 | |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 244 | // In case we are changing the suppression of a group, the replacement shouldn't flicker |
| 245 | // and it should just be replaced instead. We therefore look for notifications that were |
| 246 | // just replaced by the child or vice-versa to suppress this. |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 247 | |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 248 | ArrayMap<String, ArrayList<StatusBarIcon>> replacingIcons = new ArrayMap<>(); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 249 | ArrayList<View> toRemove = new ArrayList<>(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 250 | for (int i = 0; i < hostLayout.getChildCount(); i++) { |
| 251 | View child = hostLayout.getChildAt(i); |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 252 | if (!(child instanceof StatusBarIconView)) { |
| 253 | continue; |
| 254 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 255 | if (!toShow.contains(child)) { |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 256 | boolean iconWasReplaced = false; |
| 257 | StatusBarIconView removedIcon = (StatusBarIconView) child; |
| 258 | String removedGroupKey = removedIcon.getNotification().getGroupKey(); |
| 259 | for (int j = 0; j < toShow.size(); j++) { |
| 260 | StatusBarIconView candidate = toShow.get(j); |
| 261 | if (candidate.getSourceIcon().sameAs((removedIcon.getSourceIcon())) |
| 262 | && candidate.getNotification().getGroupKey().equals(removedGroupKey)) { |
| 263 | if (!iconWasReplaced) { |
| 264 | iconWasReplaced = true; |
| 265 | } else { |
| 266 | iconWasReplaced = false; |
| 267 | break; |
| 268 | } |
| 269 | } |
| 270 | } |
| 271 | if (iconWasReplaced) { |
| 272 | ArrayList<StatusBarIcon> statusBarIcons = replacingIcons.get(removedGroupKey); |
| 273 | if (statusBarIcons == null) { |
| 274 | statusBarIcons = new ArrayList<>(); |
| 275 | replacingIcons.put(removedGroupKey, statusBarIcons); |
| 276 | } |
| 277 | statusBarIcons.add(removedIcon.getStatusBarIcon()); |
| 278 | } |
| 279 | toRemove.add(removedIcon); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 280 | } |
| 281 | } |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 282 | // removing all duplicates |
| 283 | ArrayList<String> duplicates = new ArrayList<>(); |
| 284 | for (String key : replacingIcons.keySet()) { |
| 285 | ArrayList<StatusBarIcon> statusBarIcons = replacingIcons.get(key); |
| 286 | if (statusBarIcons.size() != 1) { |
| 287 | duplicates.add(key); |
| 288 | } |
| 289 | } |
| 290 | replacingIcons.removeAll(duplicates); |
| 291 | hostLayout.setReplacingIcons(replacingIcons); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 292 | |
| 293 | final int toRemoveCount = toRemove.size(); |
| 294 | for (int i = 0; i < toRemoveCount; i++) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 295 | hostLayout.removeView(toRemove.get(i)); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 296 | } |
| 297 | |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 298 | final FrameLayout.LayoutParams params = generateIconLayoutParams(); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 299 | for (int i = 0; i < toShow.size(); i++) { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 300 | StatusBarIconView v = toShow.get(i); |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 301 | // The view might still be transiently added if it was just removed and added again |
| 302 | hostLayout.removeTransientView(v); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 303 | if (v.getParent() == null) { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 304 | if (hideDismissed) { |
| 305 | v.setOnDismissListener(mUpdateStatusBarIcons); |
| 306 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 307 | hostLayout.addView(v, i, params); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 311 | hostLayout.setChangingViewPositions(true); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 312 | // Re-sort notification icons |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 313 | final int childCount = hostLayout.getChildCount(); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 314 | for (int i = 0; i < childCount; i++) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 315 | View actual = hostLayout.getChildAt(i); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 316 | StatusBarIconView expected = toShow.get(i); |
| 317 | if (actual == expected) { |
| 318 | continue; |
| 319 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 320 | hostLayout.removeView(expected); |
| 321 | hostLayout.addView(expected, i); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 322 | } |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 323 | hostLayout.setChangingViewPositions(false); |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 324 | hostLayout.setReplacingIcons(null); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | /** |
| 328 | * Applies {@link #mIconTint} to the notification icons. |
| 329 | */ |
| 330 | private void applyNotificationIconsTint() { |
| 331 | for (int i = 0; i < mNotificationIcons.getChildCount(); i++) { |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 332 | final StatusBarIconView iv = (StatusBarIconView) mNotificationIcons.getChildAt(i); |
| 333 | if (iv.getWidth() != 0) { |
| 334 | updateTintForIcon(iv); |
| 335 | } else { |
| 336 | iv.executeOnLayout(() -> updateTintForIcon(iv)); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 337 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 338 | } |
| 339 | } |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 340 | |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 341 | private void updateTintForIcon(StatusBarIconView v) { |
| 342 | boolean isPreL = Boolean.TRUE.equals(v.getTag(R.id.icon_is_pre_L)); |
| 343 | int color = StatusBarIconView.NO_COLOR; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 344 | boolean colorize = !isPreL || NotificationUtils.isGrayscale(v, mContrastColorUtil); |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 345 | if (colorize) { |
| 346 | color = DarkIconDispatcher.getTint(mTintArea, v, mIconTint); |
| 347 | } |
| 348 | v.setStaticDrawableColor(color); |
| 349 | v.setDecorColor(mIconTint); |
| 350 | } |
| 351 | |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 352 | public void setFullyDark(boolean fullyDark) { |
| 353 | mFullyDark = fullyDark; |
| 354 | updateShelfIcons(); |
| 355 | } |
| 356 | |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 357 | public void setDark(boolean dark) { |
| 358 | mNotificationIcons.setDark(dark, false, 0); |
| 359 | mShelfIcons.setDark(dark, false, 0); |
| 360 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 361 | |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 362 | public void showIconIsolated(StatusBarIconView icon, boolean animated) { |
| 363 | mNotificationIcons.showIconIsolated(icon, animated); |
| 364 | } |
| 365 | |
| 366 | public void setIsolatedIconLocation(Rect iconDrawingRect, boolean requireStateUpdate) { |
| 367 | mNotificationIcons.setIsolatedIconLocation(iconDrawingRect, requireStateUpdate); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 368 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 369 | } |