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; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 7 | import android.view.LayoutInflater; |
| 8 | import android.view.View; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 9 | import android.view.ViewGroup; |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 10 | import android.widget.FrameLayout; |
Winson | c0d7058 | 2016-01-29 10:24:39 -0800 | [diff] [blame] | 11 | |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 12 | import androidx.annotation.NonNull; |
| 13 | import androidx.collection.ArrayMap; |
| 14 | |
Julia Reynolds | 12ad7ca | 2019-01-28 09:29:16 -0500 | [diff] [blame] | 15 | import com.android.internal.annotations.VisibleForTesting; |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 16 | import com.android.internal.statusbar.StatusBarIcon; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 17 | import com.android.internal.util.ContrastColorUtil; |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 18 | import com.android.systemui.Dependency; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 19 | import com.android.systemui.R; |
Beverly | 1be62f4 | 2018-12-19 17:17:48 -0500 | [diff] [blame] | 20 | import com.android.systemui.plugins.DarkIconDispatcher; |
| 21 | import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 22 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Julia Reynolds | 12ad7ca | 2019-01-28 09:29:16 -0500 | [diff] [blame] | 23 | import com.android.systemui.statusbar.NotificationListener; |
Lucas Dupin | 2040337 | 2019-02-14 19:59:18 -0800 | [diff] [blame] | 24 | import com.android.systemui.statusbar.NotificationMediaManager; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 25 | import com.android.systemui.statusbar.NotificationShelf; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 26 | import com.android.systemui.statusbar.StatusBarIconView; |
Lucas Dupin | 9d6172b | 2019-06-04 15:14:25 -0700 | [diff] [blame] | 27 | import com.android.systemui.statusbar.StatusBarState; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 28 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 29 | import com.android.systemui.statusbar.notification.NotificationUtils; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 30 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 31 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 32 | |
| 33 | import java.util.ArrayList; |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 34 | import java.util.Objects; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 35 | import java.util.function.Function; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 36 | |
| 37 | /** |
| 38 | * A controller for the space in the status bar to the left of the system icons. This area is |
| 39 | * normally reserved for notifications. |
| 40 | */ |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 41 | public class NotificationIconAreaController implements DarkReceiver, |
| 42 | StatusBarStateController.StateListener { |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 43 | |
Selim Cinek | 3c9b054 | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 44 | public static final String HIGH_PRIORITY = "high_priority"; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 45 | |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 46 | private final ContrastColorUtil mContrastColorUtil; |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 47 | private final NotificationEntryManager mEntryManager; |
| 48 | private final Runnable mUpdateStatusBarIcons = this::updateStatusBarIcons; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 49 | private final StatusBarStateController mStatusBarStateController; |
Lucas Dupin | 2040337 | 2019-02-14 19:59:18 -0800 | [diff] [blame] | 50 | private final NotificationMediaManager mMediaManager; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 51 | |
| 52 | private int mIconSize; |
| 53 | private int mIconHPadding; |
| 54 | private int mIconTint = Color.WHITE; |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 55 | private int mCenteredIconTint = Color.WHITE; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 56 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 57 | private StatusBar mStatusBar; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 58 | protected View mNotificationIconArea; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 59 | private NotificationIconContainer mNotificationIcons; |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 60 | private NotificationIconContainer mShelfIcons; |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 61 | protected View mCenteredIconArea; |
| 62 | private NotificationIconContainer mCenteredIcon; |
| 63 | private StatusBarIconView mCenteredIconView; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 64 | private final Rect mTintArea = new Rect(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 65 | private ViewGroup mNotificationScrollLayout; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 66 | private Context mContext; |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 67 | private boolean mFullyDark; |
Lucas Dupin | 9d6172b | 2019-06-04 15:14:25 -0700 | [diff] [blame] | 68 | private boolean mAnimationsEnabled; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 69 | |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 70 | /** |
| 71 | * Ratio representing being awake or in ambient mode, where 1 is dark and 0 awake. |
| 72 | */ |
| 73 | private float mDarkAmount; |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 74 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 75 | public NotificationIconAreaController(Context context, StatusBar statusBar, |
Julia Reynolds | 12ad7ca | 2019-01-28 09:29:16 -0500 | [diff] [blame] | 76 | StatusBarStateController statusBarStateController, |
Lucas Dupin | 2040337 | 2019-02-14 19:59:18 -0800 | [diff] [blame] | 77 | NotificationMediaManager notificationMediaManager) { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 78 | mStatusBar = statusBar; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 79 | mContrastColorUtil = ContrastColorUtil.getInstance(context); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 80 | mContext = context; |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 81 | mEntryManager = Dependency.get(NotificationEntryManager.class); |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 82 | mStatusBarStateController = statusBarStateController; |
| 83 | mStatusBarStateController.addCallback(this); |
Lucas Dupin | 2040337 | 2019-02-14 19:59:18 -0800 | [diff] [blame] | 84 | mMediaManager = notificationMediaManager; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 85 | |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 86 | initializeNotificationAreaViews(context); |
| 87 | } |
| 88 | |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 89 | protected View inflateIconArea(LayoutInflater inflater) { |
| 90 | return inflater.inflate(R.layout.notification_icon_area, null); |
| 91 | } |
| 92 | |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 93 | /** |
| 94 | * Initializes the views that will represent the notification area. |
| 95 | */ |
| 96 | protected void initializeNotificationAreaViews(Context context) { |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 97 | reloadDimens(context); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 98 | |
| 99 | LayoutInflater layoutInflater = LayoutInflater.from(context); |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 100 | mNotificationIconArea = inflateIconArea(layoutInflater); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 101 | mNotificationIcons = mNotificationIconArea.findViewById(R.id.notificationIcons); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 102 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 103 | mNotificationScrollLayout = mStatusBar.getNotificationScrollLayout(); |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 104 | |
| 105 | mCenteredIconArea = layoutInflater.inflate(R.layout.center_icon_area, null); |
| 106 | mCenteredIcon = mCenteredIconArea.findViewById(R.id.centeredIcon); |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | public void setupShelf(NotificationShelf shelf) { |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 110 | mShelfIcons = shelf.getShelfIcons(); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 111 | shelf.setCollapsedIcons(mNotificationIcons); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 112 | } |
| 113 | |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 114 | public void onDensityOrFontScaleChanged(Context context) { |
| 115 | reloadDimens(context); |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 116 | final FrameLayout.LayoutParams params = generateIconLayoutParams(); |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 117 | for (int i = 0; i < mNotificationIcons.getChildCount(); i++) { |
| 118 | View child = mNotificationIcons.getChildAt(i); |
| 119 | child.setLayoutParams(params); |
Selim Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 120 | } |
| 121 | for (int i = 0; i < mShelfIcons.getChildCount(); i++) { |
| 122 | View child = mShelfIcons.getChildAt(i); |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 123 | child.setLayoutParams(params); |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 124 | } |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 125 | for (int i = 0; i < mCenteredIcon.getChildCount(); i++) { |
| 126 | View child = mCenteredIcon.getChildAt(i); |
| 127 | child.setLayoutParams(params); |
| 128 | } |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | @NonNull |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 132 | private FrameLayout.LayoutParams generateIconLayoutParams() { |
| 133 | return new FrameLayout.LayoutParams( |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 134 | mIconSize + 2 * mIconHPadding, getHeight()); |
| 135 | } |
| 136 | |
| 137 | private void reloadDimens(Context context) { |
| 138 | Resources res = context.getResources(); |
| 139 | mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size); |
| 140 | mIconHPadding = res.getDimensionPixelSize(R.dimen.status_bar_icon_padding); |
| 141 | } |
| 142 | |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 143 | /** |
| 144 | * Returns the view that represents the notification area. |
| 145 | */ |
| 146 | public View getNotificationInnerAreaView() { |
| 147 | return mNotificationIconArea; |
| 148 | } |
| 149 | |
| 150 | /** |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 151 | * Returns the view that represents the centered notification area. |
| 152 | */ |
| 153 | public View getCenteredNotificationAreaView() { |
| 154 | return mCenteredIconArea; |
| 155 | } |
| 156 | |
| 157 | /** |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 158 | * See {@link com.android.systemui.statusbar.policy.DarkIconDispatcher#setIconsDarkArea}. |
| 159 | * 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] | 160 | * |
| 161 | * @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] | 162 | * @param darkIntensity |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 163 | */ |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 164 | public void onDarkChanged(Rect tintArea, float darkIntensity, int iconTint) { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 165 | if (tintArea == null) { |
| 166 | mTintArea.setEmpty(); |
| 167 | } else { |
| 168 | mTintArea.set(tintArea); |
| 169 | } |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 170 | |
Evan Laird | dbeefe3 | 2018-04-03 16:52:41 -0400 | [diff] [blame] | 171 | if (mNotificationIconArea != null) { |
| 172 | if (DarkIconDispatcher.isInArea(tintArea, mNotificationIconArea)) { |
| 173 | mIconTint = iconTint; |
| 174 | } |
| 175 | } else { |
| 176 | mIconTint = iconTint; |
| 177 | } |
| 178 | |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 179 | if (mCenteredIconArea != null) { |
| 180 | if (DarkIconDispatcher.isInArea(tintArea, mCenteredIconArea)) { |
| 181 | mCenteredIconTint = iconTint; |
| 182 | } |
| 183 | } else { |
| 184 | mCenteredIconTint = iconTint; |
| 185 | } |
| 186 | |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 187 | applyNotificationIconsTint(); |
| 188 | } |
| 189 | |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 190 | protected int getHeight() { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 191 | return mStatusBar.getStatusBarHeight(); |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 194 | protected boolean shouldShowNotificationIcon(NotificationEntry entry, |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 195 | boolean showAmbient, boolean showLowPriority, boolean hideDismissed, |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 196 | boolean hideRepliedMessages, boolean hideCurrentMedia, boolean hideCenteredIcon) { |
| 197 | |
| 198 | final boolean isCenteredNotificationIcon = entry.centeredIcon != null |
| 199 | && Objects.equals(entry.centeredIcon, mCenteredIconView); |
| 200 | if (hideCenteredIcon == isCenteredNotificationIcon) { |
| 201 | return false; |
| 202 | } |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 203 | if (mEntryManager.getNotificationData().isAmbient(entry.key) && !showAmbient) { |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 204 | return false; |
| 205 | } |
Lucas Dupin | 2040337 | 2019-02-14 19:59:18 -0800 | [diff] [blame] | 206 | if (hideCurrentMedia && entry.key.equals(mMediaManager.getMediaNotificationKey())) { |
| 207 | return false; |
| 208 | } |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 209 | if (!showLowPriority && !entry.isHighPriority()) { |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 210 | return false; |
| 211 | } |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 212 | if (!entry.isTopLevelChild()) { |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 213 | return false; |
| 214 | } |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 215 | if (entry.getRow().getVisibility() == View.GONE) { |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 216 | return false; |
| 217 | } |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 218 | if (entry.isRowDismissed() && hideDismissed) { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 219 | return false; |
| 220 | } |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 221 | if (hideRepliedMessages && entry.isLastMessageFromReply()) { |
| 222 | return false; |
| 223 | } |
Julia Reynolds | c861a3d | 2018-02-15 10:34:49 -0500 | [diff] [blame] | 224 | // showAmbient == show in shade but not shelf |
Beverly | 4bae644 | 2019-04-04 09:59:33 -0400 | [diff] [blame] | 225 | if ((!showAmbient || mFullyDark) && entry.shouldSuppressStatusBar()) { |
Julia Reynolds | c861a3d | 2018-02-15 10:34:49 -0500 | [diff] [blame] | 226 | return false; |
| 227 | } |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 228 | return true; |
| 229 | } |
| 230 | |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 231 | /** |
| 232 | * Updates the notifications with the given list of notifications to display. |
| 233 | */ |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 234 | public void updateNotificationIcons() { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 235 | updateStatusBarIcons(); |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 236 | updateShelfIcons(); |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 237 | updateCenterIcon(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 238 | |
| 239 | applyNotificationIconsTint(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 242 | private void updateShelfIcons() { |
| 243 | updateIconsForLayout(entry -> entry.expandedIcon, mShelfIcons, |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 244 | true /* showAmbient */, |
Selim Cinek | d34e9d8 | 2019-06-19 17:24:59 -0700 | [diff] [blame] | 245 | true /* showLowPriority */, |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 246 | false /* hideDismissed */, |
| 247 | mFullyDark /* hideRepliedMessages */, |
| 248 | mFullyDark /* hideCurrentMedia */, |
| 249 | true /* hide centered icon */); |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 252 | public void updateStatusBarIcons() { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 253 | updateIconsForLayout(entry -> entry.icon, mNotificationIcons, |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 254 | false /* showAmbient */, |
Selim Cinek | d34e9d8 | 2019-06-19 17:24:59 -0700 | [diff] [blame] | 255 | true /* showLowPriority */, |
Gus Prevas | dddef39 | 2018-11-02 15:41:43 -0400 | [diff] [blame] | 256 | true /* hideDismissed */, |
Lucas Dupin | 2040337 | 2019-02-14 19:59:18 -0800 | [diff] [blame] | 257 | true /* hideRepliedMessages */, |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 258 | false /* hideCurrentMedia */, |
| 259 | true /* hide centered icon */); |
| 260 | } |
| 261 | |
| 262 | private void updateCenterIcon() { |
| 263 | updateIconsForLayout(entry -> entry.centeredIcon, mCenteredIcon, |
| 264 | false /* showAmbient */, |
Selim Cinek | d34e9d8 | 2019-06-19 17:24:59 -0700 | [diff] [blame] | 265 | true /* showLowPriority */, |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 266 | false /* hideDismissed */, |
| 267 | false /* hideRepliedMessages */, |
| 268 | mFullyDark /* hideCurrentMedia */, |
| 269 | false /* hide centered icon */); |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 270 | } |
| 271 | |
Lucas Dupin | 9d6172b | 2019-06-04 15:14:25 -0700 | [diff] [blame] | 272 | /** |
| 273 | * If icons of the status bar should animate when they are added or removed. |
| 274 | */ |
| 275 | public void setAnimationsEnabled(boolean enabled) { |
| 276 | mAnimationsEnabled = enabled; |
| 277 | updateAnimations(); |
| 278 | } |
| 279 | |
| 280 | @Override |
| 281 | public void onStateChanged(int newState) { |
| 282 | updateAnimations(); |
| 283 | } |
| 284 | |
| 285 | private void updateAnimations() { |
| 286 | boolean inShade = mStatusBarStateController.getState() == StatusBarState.SHADE; |
| 287 | mCenteredIcon.setAnimationsEnabled(mAnimationsEnabled && inShade); |
| 288 | mNotificationIcons.setAnimationsEnabled(mAnimationsEnabled && inShade); |
| 289 | } |
| 290 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 291 | /** |
| 292 | * Updates the notification icons for a host layout. This will ensure that the notification |
| 293 | * host layout will have the same icons like the ones in here. |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 294 | * @param function A function to look up an icon view based on an entry |
| 295 | * @param hostLayout which layout should be updated |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 296 | * @param showAmbient should ambient notification icons be shown |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 297 | * @param hideDismissed should dismissed icons be hidden |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 298 | * @param hideRepliedMessages should messages that have been replied to be hidden |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 299 | */ |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 300 | private void updateIconsForLayout(Function<NotificationEntry, StatusBarIconView> function, |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 301 | NotificationIconContainer hostLayout, boolean showAmbient, boolean showLowPriority, |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 302 | boolean hideDismissed, boolean hideRepliedMessages, boolean hideCurrentMedia, |
| 303 | boolean hideCenteredIcon) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 304 | ArrayList<StatusBarIconView> toShow = new ArrayList<>( |
| 305 | mNotificationScrollLayout.getChildCount()); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 306 | |
| 307 | // Filter out ambient notifications and notification children. |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 308 | for (int i = 0; i < mNotificationScrollLayout.getChildCount(); i++) { |
| 309 | View view = mNotificationScrollLayout.getChildAt(i); |
| 310 | if (view instanceof ExpandableNotificationRow) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 311 | NotificationEntry ent = ((ExpandableNotificationRow) view).getEntry(); |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 312 | if (shouldShowNotificationIcon(ent, showAmbient, showLowPriority, hideDismissed, |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 313 | hideRepliedMessages, hideCurrentMedia, hideCenteredIcon)) { |
| 314 | StatusBarIconView iconView = function.apply(ent); |
| 315 | if (iconView != null) { |
| 316 | toShow.add(iconView); |
| 317 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 318 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 319 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 320 | } |
| 321 | |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 322 | // In case we are changing the suppression of a group, the replacement shouldn't flicker |
| 323 | // and it should just be replaced instead. We therefore look for notifications that were |
| 324 | // just replaced by the child or vice-versa to suppress this. |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 325 | |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 326 | ArrayMap<String, ArrayList<StatusBarIcon>> replacingIcons = new ArrayMap<>(); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 327 | ArrayList<View> toRemove = new ArrayList<>(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 328 | for (int i = 0; i < hostLayout.getChildCount(); i++) { |
| 329 | View child = hostLayout.getChildAt(i); |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 330 | if (!(child instanceof StatusBarIconView)) { |
| 331 | continue; |
| 332 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 333 | if (!toShow.contains(child)) { |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 334 | boolean iconWasReplaced = false; |
| 335 | StatusBarIconView removedIcon = (StatusBarIconView) child; |
| 336 | String removedGroupKey = removedIcon.getNotification().getGroupKey(); |
| 337 | for (int j = 0; j < toShow.size(); j++) { |
| 338 | StatusBarIconView candidate = toShow.get(j); |
| 339 | if (candidate.getSourceIcon().sameAs((removedIcon.getSourceIcon())) |
| 340 | && candidate.getNotification().getGroupKey().equals(removedGroupKey)) { |
| 341 | if (!iconWasReplaced) { |
| 342 | iconWasReplaced = true; |
| 343 | } else { |
| 344 | iconWasReplaced = false; |
| 345 | break; |
| 346 | } |
| 347 | } |
| 348 | } |
| 349 | if (iconWasReplaced) { |
| 350 | ArrayList<StatusBarIcon> statusBarIcons = replacingIcons.get(removedGroupKey); |
| 351 | if (statusBarIcons == null) { |
| 352 | statusBarIcons = new ArrayList<>(); |
| 353 | replacingIcons.put(removedGroupKey, statusBarIcons); |
| 354 | } |
| 355 | statusBarIcons.add(removedIcon.getStatusBarIcon()); |
| 356 | } |
| 357 | toRemove.add(removedIcon); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 358 | } |
| 359 | } |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 360 | // removing all duplicates |
| 361 | ArrayList<String> duplicates = new ArrayList<>(); |
| 362 | for (String key : replacingIcons.keySet()) { |
| 363 | ArrayList<StatusBarIcon> statusBarIcons = replacingIcons.get(key); |
| 364 | if (statusBarIcons.size() != 1) { |
| 365 | duplicates.add(key); |
| 366 | } |
| 367 | } |
| 368 | replacingIcons.removeAll(duplicates); |
| 369 | hostLayout.setReplacingIcons(replacingIcons); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 370 | |
| 371 | final int toRemoveCount = toRemove.size(); |
| 372 | for (int i = 0; i < toRemoveCount; i++) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 373 | hostLayout.removeView(toRemove.get(i)); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 374 | } |
| 375 | |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 376 | final FrameLayout.LayoutParams params = generateIconLayoutParams(); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 377 | for (int i = 0; i < toShow.size(); i++) { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 378 | StatusBarIconView v = toShow.get(i); |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 379 | // The view might still be transiently added if it was just removed and added again |
| 380 | hostLayout.removeTransientView(v); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 381 | if (v.getParent() == null) { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 382 | if (hideDismissed) { |
| 383 | v.setOnDismissListener(mUpdateStatusBarIcons); |
| 384 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 385 | hostLayout.addView(v, i, params); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 386 | } |
| 387 | } |
| 388 | |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 389 | hostLayout.setChangingViewPositions(true); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 390 | // Re-sort notification icons |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 391 | final int childCount = hostLayout.getChildCount(); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 392 | for (int i = 0; i < childCount; i++) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 393 | View actual = hostLayout.getChildAt(i); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 394 | StatusBarIconView expected = toShow.get(i); |
| 395 | if (actual == expected) { |
| 396 | continue; |
| 397 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 398 | hostLayout.removeView(expected); |
| 399 | hostLayout.addView(expected, i); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 400 | } |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 401 | hostLayout.setChangingViewPositions(false); |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 402 | hostLayout.setReplacingIcons(null); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 403 | } |
| 404 | |
| 405 | /** |
| 406 | * Applies {@link #mIconTint} to the notification icons. |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 407 | * Applies {@link #mCenteredIconTint} to the center notification icon. |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 408 | */ |
| 409 | private void applyNotificationIconsTint() { |
| 410 | for (int i = 0; i < mNotificationIcons.getChildCount(); i++) { |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 411 | final StatusBarIconView iv = (StatusBarIconView) mNotificationIcons.getChildAt(i); |
| 412 | if (iv.getWidth() != 0) { |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 413 | updateTintForIcon(iv, mIconTint); |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 414 | } else { |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 415 | iv.executeOnLayout(() -> updateTintForIcon(iv, mIconTint)); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | for (int i = 0; i < mCenteredIcon.getChildCount(); i++) { |
| 420 | final StatusBarIconView iv = (StatusBarIconView) mCenteredIcon.getChildAt(i); |
| 421 | if (iv.getWidth() != 0) { |
| 422 | updateTintForIcon(iv, mCenteredIconTint); |
| 423 | } else { |
| 424 | iv.executeOnLayout(() -> updateTintForIcon(iv, mCenteredIconTint)); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 425 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 426 | } |
| 427 | } |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 428 | |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 429 | private void updateTintForIcon(StatusBarIconView v, int tint) { |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 430 | boolean isPreL = Boolean.TRUE.equals(v.getTag(R.id.icon_is_pre_L)); |
| 431 | int color = StatusBarIconView.NO_COLOR; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 432 | boolean colorize = !isPreL || NotificationUtils.isGrayscale(v, mContrastColorUtil); |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 433 | if (colorize) { |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 434 | color = DarkIconDispatcher.getTint(mTintArea, v, tint); |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 435 | } |
| 436 | v.setStaticDrawableColor(color); |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 437 | v.setDecorColor(tint); |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 438 | } |
| 439 | |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 440 | public void setDark(boolean dark) { |
| 441 | mNotificationIcons.setDark(dark, false, 0); |
| 442 | mShelfIcons.setDark(dark, false, 0); |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 443 | mCenteredIcon.setDark(dark, false, 0); |
| 444 | } |
| 445 | |
| 446 | /** |
| 447 | * Shows the icon view given in the center. |
| 448 | */ |
| 449 | public void showIconCentered(NotificationEntry entry) { |
| 450 | StatusBarIconView icon = entry == null ? null : entry.centeredIcon; |
| 451 | if (!Objects.equals(mCenteredIconView, icon)) { |
| 452 | mCenteredIconView = icon; |
| 453 | updateNotificationIcons(); |
| 454 | } |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 455 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 456 | |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 457 | public void showIconIsolated(StatusBarIconView icon, boolean animated) { |
| 458 | mNotificationIcons.showIconIsolated(icon, animated); |
| 459 | } |
| 460 | |
| 461 | public void setIsolatedIconLocation(Rect iconDrawingRect, boolean requireStateUpdate) { |
| 462 | mNotificationIcons.setIsolatedIconLocation(iconDrawingRect, requireStateUpdate); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 463 | } |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 464 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 465 | @Override |
| 466 | public void onDozeAmountChanged(float linear, float eased) { |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 467 | mDarkAmount = linear; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 468 | boolean fullyDark = mDarkAmount == 1f; |
| 469 | if (mFullyDark != fullyDark) { |
| 470 | mFullyDark = fullyDark; |
| 471 | updateShelfIcons(); |
| 472 | } |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 473 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 474 | } |