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 | 5dc581a | 2019-06-19 17:24:59 -0700 | [diff] [blame] | 7 | import android.provider.Settings; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 8 | import android.view.LayoutInflater; |
| 9 | import android.view.View; |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 10 | import android.view.ViewGroup; |
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 | |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 13 | import androidx.annotation.NonNull; |
| 14 | import androidx.collection.ArrayMap; |
| 15 | |
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 | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 18 | import com.android.settingslib.Utils; |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 19 | import com.android.systemui.Dependency; |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 20 | import com.android.systemui.Interpolators; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 21 | import com.android.systemui.R; |
Beverly | 1be62f4 | 2018-12-19 17:17:48 -0500 | [diff] [blame] | 22 | import com.android.systemui.plugins.DarkIconDispatcher; |
| 23 | import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver; |
Beverly | 8fdb533 | 2019-02-04 14:29:49 -0500 | [diff] [blame] | 24 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
Selim Cinek | 999230c | 2019-06-19 15:36:44 -0700 | [diff] [blame] | 25 | import com.android.systemui.statusbar.CrossFadeHelper; |
Lucas Dupin | 2040337 | 2019-02-14 19:59:18 -0800 | [diff] [blame] | 26 | import com.android.systemui.statusbar.NotificationMediaManager; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 27 | import com.android.systemui.statusbar.NotificationShelf; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 28 | import com.android.systemui.statusbar.StatusBarIconView; |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 29 | import com.android.systemui.statusbar.StatusBarState; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 30 | import com.android.systemui.statusbar.notification.NotificationEntryManager; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 31 | import com.android.systemui.statusbar.notification.NotificationUtils; |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 32 | import com.android.systemui.statusbar.notification.NotificationWakeUpCoordinator; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 33 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 34 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
Selim Cinek | 5dc581a | 2019-06-19 17:24:59 -0700 | [diff] [blame] | 35 | import com.android.systemui.tuner.TunerService; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 36 | |
| 37 | import java.util.ArrayList; |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 38 | import java.util.Objects; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 39 | import java.util.function.Function; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * A controller for the space in the status bar to the left of the system icons. This area is |
| 43 | * normally reserved for notifications. |
| 44 | */ |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 45 | public class NotificationIconAreaController implements DarkReceiver, |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 46 | StatusBarStateController.StateListener, |
| 47 | NotificationWakeUpCoordinator.WakeUpListener { |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 48 | |
Selim Cinek | da330ff | 2019-06-11 15:41:28 -0700 | [diff] [blame] | 49 | public static final String HIGH_PRIORITY = "high_priority"; |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 50 | private static final long AOD_ICONS_APPEAR_DURATION = 200; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 51 | |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 52 | private final ContrastColorUtil mContrastColorUtil; |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 53 | private final NotificationEntryManager mEntryManager; |
| 54 | private final Runnable mUpdateStatusBarIcons = this::updateStatusBarIcons; |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 55 | private final StatusBarStateController mStatusBarStateController; |
Lucas Dupin | 2040337 | 2019-02-14 19:59:18 -0800 | [diff] [blame] | 56 | private final NotificationMediaManager mMediaManager; |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 57 | private final NotificationWakeUpCoordinator mWakeUpCoordinator; |
| 58 | private final KeyguardBypassController mBypassController; |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 59 | private final DozeParameters mDozeParameters; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 60 | |
Selim Cinek | 5dc581a | 2019-06-19 17:24:59 -0700 | [diff] [blame] | 61 | private boolean mShowSilentOnLockscreen = true; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 62 | private int mIconSize; |
| 63 | private int mIconHPadding; |
| 64 | private int mIconTint = Color.WHITE; |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 65 | private int mCenteredIconTint = Color.WHITE; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 66 | |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 67 | private StatusBar mStatusBar; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 68 | protected View mNotificationIconArea; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 69 | private NotificationIconContainer mNotificationIcons; |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 70 | private NotificationIconContainer mShelfIcons; |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 71 | protected View mCenteredIconArea; |
| 72 | private NotificationIconContainer mCenteredIcon; |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 73 | private NotificationIconContainer mAodIcons; |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 74 | private StatusBarIconView mCenteredIconView; |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 75 | private final Rect mTintArea = new Rect(); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 76 | private ViewGroup mNotificationScrollLayout; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 77 | private Context mContext; |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 78 | private int mAodIconAppearTranslation; |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 79 | |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 80 | private boolean mAnimationsEnabled; |
| 81 | private int mAodIconTint; |
| 82 | private boolean mFullyHidden; |
Selim Cinek | 999230c | 2019-06-19 15:36:44 -0700 | [diff] [blame] | 83 | private boolean mAodIconsVisible; |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 84 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 85 | public NotificationIconAreaController(Context context, StatusBar statusBar, |
Julia Reynolds | 12ad7ca | 2019-01-28 09:29:16 -0500 | [diff] [blame] | 86 | StatusBarStateController statusBarStateController, |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 87 | NotificationWakeUpCoordinator wakeUpCoordinator, |
| 88 | KeyguardBypassController keyguardBypassController, |
Lucas Dupin | 2040337 | 2019-02-14 19:59:18 -0800 | [diff] [blame] | 89 | NotificationMediaManager notificationMediaManager) { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 90 | mStatusBar = statusBar; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 91 | mContrastColorUtil = ContrastColorUtil.getInstance(context); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 92 | mContext = context; |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 93 | mEntryManager = Dependency.get(NotificationEntryManager.class); |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 94 | mStatusBarStateController = statusBarStateController; |
| 95 | mStatusBarStateController.addCallback(this); |
Lucas Dupin | 2040337 | 2019-02-14 19:59:18 -0800 | [diff] [blame] | 96 | mMediaManager = notificationMediaManager; |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 97 | mDozeParameters = DozeParameters.getInstance(mContext); |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 98 | mWakeUpCoordinator = wakeUpCoordinator; |
| 99 | wakeUpCoordinator.addListener(this); |
| 100 | mBypassController = keyguardBypassController; |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 101 | |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 102 | initializeNotificationAreaViews(context); |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 103 | reloadAodColor(); |
Selim Cinek | 5dc581a | 2019-06-19 17:24:59 -0700 | [diff] [blame] | 104 | |
| 105 | TunerService tunerService = Dependency.get(TunerService.class); |
| 106 | tunerService.addTunable((key, newValue) -> { |
| 107 | mShowSilentOnLockscreen = "1".equals(newValue); |
| 108 | }, Settings.Secure.LOCK_SCREEN_SHOW_SILENT_NOTIFICATIONS); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 111 | protected View inflateIconArea(LayoutInflater inflater) { |
| 112 | return inflater.inflate(R.layout.notification_icon_area, null); |
| 113 | } |
| 114 | |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 115 | /** |
| 116 | * Initializes the views that will represent the notification area. |
| 117 | */ |
| 118 | protected void initializeNotificationAreaViews(Context context) { |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 119 | reloadDimens(context); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 120 | |
| 121 | LayoutInflater layoutInflater = LayoutInflater.from(context); |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 122 | mNotificationIconArea = inflateIconArea(layoutInflater); |
Jason Monk | e59dc40 | 2018-08-16 12:05:01 -0400 | [diff] [blame] | 123 | mNotificationIcons = mNotificationIconArea.findViewById(R.id.notificationIcons); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 124 | |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 125 | mNotificationScrollLayout = mStatusBar.getNotificationScrollLayout(); |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 126 | |
| 127 | mCenteredIconArea = layoutInflater.inflate(R.layout.center_icon_area, null); |
| 128 | mCenteredIcon = mCenteredIconArea.findViewById(R.id.centeredIcon); |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 129 | |
| 130 | initAodIcons(); |
| 131 | } |
| 132 | |
| 133 | public void initAodIcons() { |
| 134 | boolean changed = mAodIcons != null; |
| 135 | if (changed) { |
| 136 | mAodIcons.setAnimationsEnabled(false); |
| 137 | mAodIcons.removeAllViews(); |
| 138 | } |
| 139 | mAodIcons = mStatusBar.getStatusBarWindow().findViewById( |
| 140 | R.id.clock_notification_icon_container); |
| 141 | mAodIcons.setOnLockScreen(true); |
Selim Cinek | 999230c | 2019-06-19 15:36:44 -0700 | [diff] [blame] | 142 | updateAodIconsVisibility(false /* animate */); |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 143 | updateAnimations(); |
| 144 | if (changed) { |
Selim Cinek | 999230c | 2019-06-19 15:36:44 -0700 | [diff] [blame] | 145 | updateAodNotificationIcons(); |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 146 | } |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | public void setupShelf(NotificationShelf shelf) { |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 150 | mShelfIcons = shelf.getShelfIcons(); |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 151 | shelf.setCollapsedIcons(mNotificationIcons); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 152 | } |
| 153 | |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 154 | public void onDensityOrFontScaleChanged(Context context) { |
| 155 | reloadDimens(context); |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 156 | final FrameLayout.LayoutParams params = generateIconLayoutParams(); |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 157 | for (int i = 0; i < mNotificationIcons.getChildCount(); i++) { |
| 158 | View child = mNotificationIcons.getChildAt(i); |
| 159 | child.setLayoutParams(params); |
Selim Cinek | 9ef119c | 2017-03-01 15:13:36 -0800 | [diff] [blame] | 160 | } |
| 161 | for (int i = 0; i < mShelfIcons.getChildCount(); i++) { |
| 162 | View child = mShelfIcons.getChildAt(i); |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 163 | child.setLayoutParams(params); |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 164 | } |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 165 | for (int i = 0; i < mCenteredIcon.getChildCount(); i++) { |
| 166 | View child = mCenteredIcon.getChildAt(i); |
| 167 | child.setLayoutParams(params); |
| 168 | } |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 169 | for (int i = 0; i < mAodIcons.getChildCount(); i++) { |
| 170 | View child = mAodIcons.getChildAt(i); |
| 171 | child.setLayoutParams(params); |
| 172 | } |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | @NonNull |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 176 | private FrameLayout.LayoutParams generateIconLayoutParams() { |
| 177 | return new FrameLayout.LayoutParams( |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 178 | mIconSize + 2 * mIconHPadding, getHeight()); |
| 179 | } |
| 180 | |
| 181 | private void reloadDimens(Context context) { |
| 182 | Resources res = context.getResources(); |
| 183 | mIconSize = res.getDimensionPixelSize(com.android.internal.R.dimen.status_bar_icon_size); |
| 184 | mIconHPadding = res.getDimensionPixelSize(R.dimen.status_bar_icon_padding); |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 185 | mAodIconAppearTranslation = res.getDimensionPixelSize( |
| 186 | R.dimen.shelf_appear_translation); |
Selim Cinek | 3e7592d | 2016-04-11 09:35:54 +0800 | [diff] [blame] | 187 | } |
| 188 | |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 189 | /** |
| 190 | * Returns the view that represents the notification area. |
| 191 | */ |
| 192 | public View getNotificationInnerAreaView() { |
| 193 | return mNotificationIconArea; |
| 194 | } |
| 195 | |
| 196 | /** |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 197 | * Returns the view that represents the centered notification area. |
| 198 | */ |
| 199 | public View getCenteredNotificationAreaView() { |
| 200 | return mCenteredIconArea; |
| 201 | } |
| 202 | |
| 203 | /** |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 204 | * See {@link com.android.systemui.statusbar.policy.DarkIconDispatcher#setIconsDarkArea}. |
| 205 | * 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] | 206 | * |
| 207 | * @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] | 208 | * @param darkIntensity |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 209 | */ |
Jason Monk | aa573e9 | 2017-01-27 17:00:29 -0500 | [diff] [blame] | 210 | public void onDarkChanged(Rect tintArea, float darkIntensity, int iconTint) { |
Jorim Jaggi | 8690558 | 2016-02-09 21:36:09 -0800 | [diff] [blame] | 211 | if (tintArea == null) { |
| 212 | mTintArea.setEmpty(); |
| 213 | } else { |
| 214 | mTintArea.set(tintArea); |
| 215 | } |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 216 | |
Evan Laird | dbeefe3 | 2018-04-03 16:52:41 -0400 | [diff] [blame] | 217 | if (mNotificationIconArea != null) { |
| 218 | if (DarkIconDispatcher.isInArea(tintArea, mNotificationIconArea)) { |
| 219 | mIconTint = iconTint; |
| 220 | } |
| 221 | } else { |
| 222 | mIconTint = iconTint; |
| 223 | } |
| 224 | |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 225 | if (mCenteredIconArea != null) { |
| 226 | if (DarkIconDispatcher.isInArea(tintArea, mCenteredIconArea)) { |
| 227 | mCenteredIconTint = iconTint; |
| 228 | } |
| 229 | } else { |
| 230 | mCenteredIconTint = iconTint; |
| 231 | } |
| 232 | |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 233 | applyNotificationIconsTint(); |
| 234 | } |
| 235 | |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 236 | protected int getHeight() { |
Jason Monk | 2a6ea9c | 2017-01-26 11:14:51 -0500 | [diff] [blame] | 237 | return mStatusBar.getStatusBarHeight(); |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 240 | protected boolean shouldShowNotificationIcon(NotificationEntry entry, |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 241 | boolean showAmbient, boolean showLowPriority, boolean hideDismissed, |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 242 | boolean hideRepliedMessages, boolean hideCurrentMedia, boolean hideCenteredIcon, |
Beverly | fd3b1dca | 2019-06-25 16:21:00 -0400 | [diff] [blame] | 243 | boolean hidePulsing, boolean onlyShowCenteredIcon) { |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 244 | |
Beverly | fd3b1dca | 2019-06-25 16:21:00 -0400 | [diff] [blame] | 245 | final boolean isCenteredNotificationIcon = mCenteredIconView != null |
| 246 | && entry.centeredIcon != null |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 247 | && Objects.equals(entry.centeredIcon, mCenteredIconView); |
Beverly | fd3b1dca | 2019-06-25 16:21:00 -0400 | [diff] [blame] | 248 | if (onlyShowCenteredIcon) { |
| 249 | return isCenteredNotificationIcon; |
| 250 | } |
| 251 | if (hideCenteredIcon && isCenteredNotificationIcon) { |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 252 | return false; |
| 253 | } |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 254 | if (mEntryManager.getNotificationData().isAmbient(entry.key) && !showAmbient) { |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 255 | return false; |
| 256 | } |
Lucas Dupin | 2040337 | 2019-02-14 19:59:18 -0800 | [diff] [blame] | 257 | if (hideCurrentMedia && entry.key.equals(mMediaManager.getMediaNotificationKey())) { |
| 258 | return false; |
| 259 | } |
Gus Prevas | caed15c | 2019-01-18 14:19:51 -0500 | [diff] [blame] | 260 | if (!showLowPriority && !entry.isHighPriority()) { |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 261 | return false; |
| 262 | } |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 263 | if (!entry.isTopLevelChild()) { |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 264 | return false; |
| 265 | } |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 266 | if (entry.getRow().getVisibility() == View.GONE) { |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 267 | return false; |
| 268 | } |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 269 | if (entry.isRowDismissed() && hideDismissed) { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 270 | return false; |
| 271 | } |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 272 | if (hideRepliedMessages && entry.isLastMessageFromReply()) { |
| 273 | return false; |
| 274 | } |
Julia Reynolds | c861a3d | 2018-02-15 10:34:49 -0500 | [diff] [blame] | 275 | // showAmbient == show in shade but not shelf |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 276 | if (!showAmbient && entry.shouldSuppressStatusBar()) { |
Julia Reynolds | c861a3d | 2018-02-15 10:34:49 -0500 | [diff] [blame] | 277 | return false; |
| 278 | } |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 279 | if (hidePulsing && entry.showingPulsing()) { |
| 280 | return false; |
| 281 | } |
Xiaohui Chen | eb04a99 | 2016-03-22 14:58:03 -0700 | [diff] [blame] | 282 | return true; |
| 283 | } |
| 284 | |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 285 | /** |
| 286 | * Updates the notifications with the given list of notifications to display. |
| 287 | */ |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 288 | public void updateNotificationIcons() { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 289 | updateStatusBarIcons(); |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 290 | updateShelfIcons(); |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 291 | updateCenterIcon(); |
Selim Cinek | 999230c | 2019-06-19 15:36:44 -0700 | [diff] [blame] | 292 | updateAodNotificationIcons(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 293 | |
| 294 | applyNotificationIconsTint(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 295 | } |
| 296 | |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 297 | private void updateShelfIcons() { |
| 298 | updateIconsForLayout(entry -> entry.expandedIcon, mShelfIcons, |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 299 | true /* showAmbient */, |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 300 | true /* showLowPriority */, |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 301 | false /* hideDismissed */, |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 302 | false /* hideRepliedMessages */, |
| 303 | false /* hideCurrentMedia */, |
Beverly | fd3b1dca | 2019-06-25 16:21:00 -0400 | [diff] [blame] | 304 | false /* hide centered icon */, |
| 305 | false /* hidePulsing */, |
| 306 | false /* onlyShowCenteredIcon */); |
Selim Cinek | 9bfc7a5 | 2018-06-11 16:09:00 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 309 | public void updateStatusBarIcons() { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 310 | updateIconsForLayout(entry -> entry.icon, mNotificationIcons, |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 311 | false /* showAmbient */, |
Selim Cinek | 5dc581a | 2019-06-19 17:24:59 -0700 | [diff] [blame] | 312 | true /* showLowPriority */, |
Gus Prevas | dddef39 | 2018-11-02 15:41:43 -0400 | [diff] [blame] | 313 | true /* hideDismissed */, |
Lucas Dupin | 2040337 | 2019-02-14 19:59:18 -0800 | [diff] [blame] | 314 | true /* hideRepliedMessages */, |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 315 | false /* hideCurrentMedia */, |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 316 | true /* hide centered icon */, |
Beverly | fd3b1dca | 2019-06-25 16:21:00 -0400 | [diff] [blame] | 317 | false /* hidePulsing */, |
| 318 | false /* onlyShowCenteredIcon */); |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | private void updateCenterIcon() { |
| 322 | updateIconsForLayout(entry -> entry.centeredIcon, mCenteredIcon, |
| 323 | false /* showAmbient */, |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 324 | true /* showLowPriority */, |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 325 | false /* hideDismissed */, |
| 326 | false /* hideRepliedMessages */, |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 327 | false /* hideCurrentMedia */, |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 328 | false /* hide centered icon */, |
Beverly | fd3b1dca | 2019-06-25 16:21:00 -0400 | [diff] [blame] | 329 | false /* hidePulsing */, |
| 330 | true/* onlyShowCenteredIcon */); |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 331 | } |
| 332 | |
Selim Cinek | 999230c | 2019-06-19 15:36:44 -0700 | [diff] [blame] | 333 | public void updateAodNotificationIcons() { |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 334 | updateIconsForLayout(entry -> entry.aodIcon, mAodIcons, |
| 335 | false /* showAmbient */, |
Selim Cinek | 5dc581a | 2019-06-19 17:24:59 -0700 | [diff] [blame] | 336 | mShowSilentOnLockscreen /* showLowPriority */, |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 337 | true /* hideDismissed */, |
| 338 | true /* hideRepliedMessages */, |
| 339 | true /* hideCurrentMedia */, |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 340 | true /* hide centered icon */, |
Beverly | fd3b1dca | 2019-06-25 16:21:00 -0400 | [diff] [blame] | 341 | mBypassController.getBypassEnabled() /* hidePulsing */, |
| 342 | false /* onlyShowCenteredIcon */); |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 345 | /** |
| 346 | * Updates the notification icons for a host layout. This will ensure that the notification |
| 347 | * host layout will have the same icons like the ones in here. |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 348 | * @param function A function to look up an icon view based on an entry |
| 349 | * @param hostLayout which layout should be updated |
Selim Cinek | 17e1b69 | 2016-12-02 18:19:11 -0800 | [diff] [blame] | 350 | * @param showAmbient should ambient notification icons be shown |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 351 | * @param hideDismissed should dismissed icons be hidden |
Selim Cinek | b0dc61b | 2018-05-22 18:49:36 -0700 | [diff] [blame] | 352 | * @param hideRepliedMessages should messages that have been replied to be hidden |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 353 | * @param hidePulsing should pulsing notifications be hidden |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 354 | */ |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 355 | private void updateIconsForLayout(Function<NotificationEntry, StatusBarIconView> function, |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 356 | NotificationIconContainer hostLayout, boolean showAmbient, boolean showLowPriority, |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 357 | boolean hideDismissed, boolean hideRepliedMessages, boolean hideCurrentMedia, |
Beverly | fd3b1dca | 2019-06-25 16:21:00 -0400 | [diff] [blame] | 358 | boolean hideCenteredIcon, boolean hidePulsing, boolean onlyShowCenteredIcon) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 359 | ArrayList<StatusBarIconView> toShow = new ArrayList<>( |
| 360 | mNotificationScrollLayout.getChildCount()); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 361 | |
| 362 | // Filter out ambient notifications and notification children. |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 363 | for (int i = 0; i < mNotificationScrollLayout.getChildCount(); i++) { |
| 364 | View view = mNotificationScrollLayout.getChildAt(i); |
| 365 | if (view instanceof ExpandableNotificationRow) { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 366 | NotificationEntry ent = ((ExpandableNotificationRow) view).getEntry(); |
Gus Prevas | 33619af | 2018-10-26 15:40:27 -0400 | [diff] [blame] | 367 | if (shouldShowNotificationIcon(ent, showAmbient, showLowPriority, hideDismissed, |
Beverly | fd3b1dca | 2019-06-25 16:21:00 -0400 | [diff] [blame] | 368 | hideRepliedMessages, hideCurrentMedia, hideCenteredIcon, hidePulsing, |
| 369 | onlyShowCenteredIcon)) { |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 370 | StatusBarIconView iconView = function.apply(ent); |
| 371 | if (iconView != null) { |
| 372 | toShow.add(iconView); |
| 373 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 374 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 375 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 376 | } |
| 377 | |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 378 | // In case we are changing the suppression of a group, the replacement shouldn't flicker |
| 379 | // and it should just be replaced instead. We therefore look for notifications that were |
| 380 | // just replaced by the child or vice-versa to suppress this. |
Selim Cinek | 49014f8 | 2016-11-04 14:55:30 -0700 | [diff] [blame] | 381 | |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 382 | ArrayMap<String, ArrayList<StatusBarIcon>> replacingIcons = new ArrayMap<>(); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 383 | ArrayList<View> toRemove = new ArrayList<>(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 384 | for (int i = 0; i < hostLayout.getChildCount(); i++) { |
| 385 | View child = hostLayout.getChildAt(i); |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 386 | if (!(child instanceof StatusBarIconView)) { |
| 387 | continue; |
| 388 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 389 | if (!toShow.contains(child)) { |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 390 | boolean iconWasReplaced = false; |
| 391 | StatusBarIconView removedIcon = (StatusBarIconView) child; |
| 392 | String removedGroupKey = removedIcon.getNotification().getGroupKey(); |
| 393 | for (int j = 0; j < toShow.size(); j++) { |
| 394 | StatusBarIconView candidate = toShow.get(j); |
| 395 | if (candidate.getSourceIcon().sameAs((removedIcon.getSourceIcon())) |
| 396 | && candidate.getNotification().getGroupKey().equals(removedGroupKey)) { |
| 397 | if (!iconWasReplaced) { |
| 398 | iconWasReplaced = true; |
| 399 | } else { |
| 400 | iconWasReplaced = false; |
| 401 | break; |
| 402 | } |
| 403 | } |
| 404 | } |
| 405 | if (iconWasReplaced) { |
| 406 | ArrayList<StatusBarIcon> statusBarIcons = replacingIcons.get(removedGroupKey); |
| 407 | if (statusBarIcons == null) { |
| 408 | statusBarIcons = new ArrayList<>(); |
| 409 | replacingIcons.put(removedGroupKey, statusBarIcons); |
| 410 | } |
| 411 | statusBarIcons.add(removedIcon.getStatusBarIcon()); |
| 412 | } |
| 413 | toRemove.add(removedIcon); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 414 | } |
| 415 | } |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 416 | // removing all duplicates |
| 417 | ArrayList<String> duplicates = new ArrayList<>(); |
| 418 | for (String key : replacingIcons.keySet()) { |
| 419 | ArrayList<StatusBarIcon> statusBarIcons = replacingIcons.get(key); |
| 420 | if (statusBarIcons.size() != 1) { |
| 421 | duplicates.add(key); |
| 422 | } |
| 423 | } |
| 424 | replacingIcons.removeAll(duplicates); |
| 425 | hostLayout.setReplacingIcons(replacingIcons); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 426 | |
| 427 | final int toRemoveCount = toRemove.size(); |
| 428 | for (int i = 0; i < toRemoveCount; i++) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 429 | hostLayout.removeView(toRemove.get(i)); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 430 | } |
| 431 | |
Selim Cinek | 0e8d77e | 2016-11-29 10:35:42 -0800 | [diff] [blame] | 432 | final FrameLayout.LayoutParams params = generateIconLayoutParams(); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 433 | for (int i = 0; i < toShow.size(); i++) { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 434 | StatusBarIconView v = toShow.get(i); |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 435 | // The view might still be transiently added if it was just removed and added again |
| 436 | hostLayout.removeTransientView(v); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 437 | if (v.getParent() == null) { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 438 | if (hideDismissed) { |
| 439 | v.setOnDismissListener(mUpdateStatusBarIcons); |
| 440 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 441 | hostLayout.addView(v, i, params); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 445 | hostLayout.setChangingViewPositions(true); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 446 | // Re-sort notification icons |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 447 | final int childCount = hostLayout.getChildCount(); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 448 | for (int i = 0; i < childCount; i++) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 449 | View actual = hostLayout.getChildAt(i); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 450 | StatusBarIconView expected = toShow.get(i); |
| 451 | if (actual == expected) { |
| 452 | continue; |
| 453 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 454 | hostLayout.removeView(expected); |
| 455 | hostLayout.addView(expected, i); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 456 | } |
Selim Cinek | 5b5beb01 | 2016-11-08 18:11:58 -0800 | [diff] [blame] | 457 | hostLayout.setChangingViewPositions(false); |
Selim Cinek | 72fc8db | 2017-06-06 18:07:47 -0700 | [diff] [blame] | 458 | hostLayout.setReplacingIcons(null); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 459 | } |
| 460 | |
| 461 | /** |
| 462 | * Applies {@link #mIconTint} to the notification icons. |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 463 | * Applies {@link #mCenteredIconTint} to the center notification icon. |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 464 | */ |
| 465 | private void applyNotificationIconsTint() { |
| 466 | for (int i = 0; i < mNotificationIcons.getChildCount(); i++) { |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 467 | final StatusBarIconView iv = (StatusBarIconView) mNotificationIcons.getChildAt(i); |
| 468 | if (iv.getWidth() != 0) { |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 469 | updateTintForIcon(iv, mIconTint); |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 470 | } else { |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 471 | iv.executeOnLayout(() -> updateTintForIcon(iv, mIconTint)); |
| 472 | } |
| 473 | } |
| 474 | |
| 475 | for (int i = 0; i < mCenteredIcon.getChildCount(); i++) { |
| 476 | final StatusBarIconView iv = (StatusBarIconView) mCenteredIcon.getChildAt(i); |
| 477 | if (iv.getWidth() != 0) { |
| 478 | updateTintForIcon(iv, mCenteredIconTint); |
| 479 | } else { |
| 480 | iv.executeOnLayout(() -> updateTintForIcon(iv, mCenteredIconTint)); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 481 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 482 | } |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 483 | |
| 484 | updateAodIconColors(); |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 485 | } |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 486 | |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 487 | private void updateTintForIcon(StatusBarIconView v, int tint) { |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 488 | boolean isPreL = Boolean.TRUE.equals(v.getTag(R.id.icon_is_pre_L)); |
| 489 | int color = StatusBarIconView.NO_COLOR; |
Lucas Dupin | a291d19 | 2018-06-07 13:59:42 -0700 | [diff] [blame] | 490 | boolean colorize = !isPreL || NotificationUtils.isGrayscale(v, mContrastColorUtil); |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 491 | if (colorize) { |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 492 | color = DarkIconDispatcher.getTint(mTintArea, v, tint); |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 493 | } |
| 494 | v.setStaticDrawableColor(color); |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 495 | v.setDecorColor(tint); |
Selim Cinek | 887da3c | 2017-10-06 13:37:32 -0700 | [diff] [blame] | 496 | } |
| 497 | |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 498 | /** |
| 499 | * Shows the icon view given in the center. |
| 500 | */ |
| 501 | public void showIconCentered(NotificationEntry entry) { |
| 502 | StatusBarIconView icon = entry == null ? null : entry.centeredIcon; |
| 503 | if (!Objects.equals(mCenteredIconView, icon)) { |
| 504 | mCenteredIconView = icon; |
| 505 | updateNotificationIcons(); |
| 506 | } |
Lucas Dupin | 987f193 | 2017-05-13 21:02:52 -0700 | [diff] [blame] | 507 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 508 | |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 509 | public void showIconIsolated(StatusBarIconView icon, boolean animated) { |
| 510 | mNotificationIcons.showIconIsolated(icon, animated); |
| 511 | } |
| 512 | |
| 513 | public void setIsolatedIconLocation(Rect iconDrawingRect, boolean requireStateUpdate) { |
| 514 | mNotificationIcons.setIsolatedIconLocation(iconDrawingRect, requireStateUpdate); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 515 | } |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 516 | |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 517 | @Override |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 518 | public void onDozingChanged(boolean isDozing) { |
| 519 | boolean animate = mDozeParameters.getAlwaysOn() |
| 520 | && !mDozeParameters.getDisplayNeedsBlanking(); |
| 521 | mAodIcons.setDozing(isDozing, animate, 0); |
| 522 | } |
| 523 | |
| 524 | public void setAnimationsEnabled(boolean enabled) { |
| 525 | mAnimationsEnabled = enabled; |
| 526 | updateAnimations(); |
| 527 | } |
| 528 | |
| 529 | @Override |
| 530 | public void onStateChanged(int newState) { |
Selim Cinek | 999230c | 2019-06-19 15:36:44 -0700 | [diff] [blame] | 531 | updateAodIconsVisibility(false /* animate */); |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 532 | updateAnimations(); |
| 533 | } |
| 534 | |
| 535 | private void updateAnimations() { |
| 536 | boolean inShade = mStatusBarStateController.getState() == StatusBarState.SHADE; |
| 537 | mAodIcons.setAnimationsEnabled(mAnimationsEnabled && !inShade); |
| 538 | mCenteredIcon.setAnimationsEnabled(mAnimationsEnabled && inShade); |
| 539 | mNotificationIcons.setAnimationsEnabled(mAnimationsEnabled && inShade); |
| 540 | } |
| 541 | |
| 542 | public void onThemeChanged() { |
| 543 | reloadAodColor(); |
| 544 | updateAodIconColors(); |
| 545 | } |
| 546 | |
| 547 | public void appearAodIcons() { |
| 548 | DozeParameters dozeParameters = DozeParameters.getInstance(mContext); |
| 549 | if (dozeParameters.shouldControlScreenOff()) { |
| 550 | mAodIcons.setTranslationY(-mAodIconAppearTranslation); |
| 551 | mAodIcons.setAlpha(0); |
| 552 | mAodIcons.animate() |
| 553 | .setInterpolator(Interpolators.DECELERATE_QUINT) |
| 554 | .translationY(0) |
| 555 | .setDuration(AOD_ICONS_APPEAR_DURATION) |
| 556 | .start(); |
| 557 | mAodIcons.animate() |
| 558 | .alpha(1) |
| 559 | .setInterpolator(Interpolators.LINEAR) |
| 560 | .setDuration(AOD_ICONS_APPEAR_DURATION) |
| 561 | .start(); |
Lucas Dupin | 7fc9dc1 | 2019-01-03 09:19:43 -0800 | [diff] [blame] | 562 | } |
Lucas Dupin | 23a8d3b | 2018-10-08 20:57:35 -0700 | [diff] [blame] | 563 | } |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 564 | |
| 565 | private void reloadAodColor() { |
| 566 | mAodIconTint = Utils.getColorAttrDefaultColor(mContext, |
| 567 | R.attr.wallpaperTextColor); |
| 568 | } |
| 569 | private void updateAodIconColors() { |
| 570 | for (int i = 0; i < mAodIcons.getChildCount(); i++) { |
| 571 | final StatusBarIconView iv = (StatusBarIconView) mAodIcons.getChildAt(i); |
| 572 | if (iv.getWidth() != 0) { |
| 573 | updateTintForIcon(iv, mAodIconTint); |
| 574 | } else { |
| 575 | iv.executeOnLayout(() -> updateTintForIcon(iv, mAodIconTint)); |
| 576 | } |
| 577 | } |
| 578 | } |
| 579 | |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 580 | @Override |
| 581 | public void onFullyHiddenChanged(boolean fullyHidden) { |
Selim Cinek | 999230c | 2019-06-19 15:36:44 -0700 | [diff] [blame] | 582 | boolean animate = true; |
| 583 | if (!mBypassController.getBypassEnabled()) { |
| 584 | animate = mDozeParameters.getAlwaysOn() && !mDozeParameters.getDisplayNeedsBlanking(); |
| 585 | // We only want the appear animations to happen when the notifications get fully hidden, |
| 586 | // since otherwise the unhide animation overlaps |
| 587 | animate &= fullyHidden; |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 588 | } |
Selim Cinek | 999230c | 2019-06-19 15:36:44 -0700 | [diff] [blame] | 589 | updateAodIconsVisibility(animate); |
| 590 | updateAodNotificationIcons(); |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 591 | } |
| 592 | |
| 593 | @Override |
| 594 | public void onPulseExpansionChanged(boolean expandingChanged) { |
| 595 | if (expandingChanged) { |
Selim Cinek | 999230c | 2019-06-19 15:36:44 -0700 | [diff] [blame] | 596 | updateAodIconsVisibility(true /* animate */); |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 597 | } |
| 598 | } |
| 599 | |
Selim Cinek | 999230c | 2019-06-19 15:36:44 -0700 | [diff] [blame] | 600 | private void updateAodIconsVisibility(boolean animate) { |
Selim Cinek | 820ba2d | 2019-06-18 18:59:09 -0700 | [diff] [blame] | 601 | boolean visible = mBypassController.getBypassEnabled() |
| 602 | || mWakeUpCoordinator.getNotificationsFullyHidden(); |
| 603 | if (mStatusBarStateController.getState() != StatusBarState.KEYGUARD) { |
| 604 | visible = false; |
| 605 | } |
| 606 | if (visible && mWakeUpCoordinator.isPulseExpanding()) { |
| 607 | visible = false; |
| 608 | } |
Selim Cinek | 999230c | 2019-06-19 15:36:44 -0700 | [diff] [blame] | 609 | if (mAodIconsVisible != visible) { |
| 610 | mAodIconsVisible = visible; |
| 611 | mAodIcons.animate().cancel(); |
| 612 | if (animate) { |
| 613 | boolean wasFullyInvisible = mAodIcons.getVisibility() != View.VISIBLE; |
| 614 | if (mAodIconsVisible) { |
| 615 | if (wasFullyInvisible) { |
| 616 | // No fading here, let's just appear the icons instead! |
| 617 | mAodIcons.setVisibility(View.VISIBLE); |
| 618 | mAodIcons.setAlpha(1.0f); |
| 619 | appearAodIcons(); |
| 620 | } else { |
| 621 | // We were fading out, let's fade in instead |
| 622 | CrossFadeHelper.fadeIn(mAodIcons); |
| 623 | } |
| 624 | } else { |
| 625 | CrossFadeHelper.fadeOut(mAodIcons); |
| 626 | } |
| 627 | } else { |
| 628 | mAodIcons.setAlpha(1.0f); |
| 629 | mAodIcons.setVisibility(visible ? View.VISIBLE : View.INVISIBLE); |
| 630 | } |
| 631 | } |
Selim Cinek | 195dfc5 | 2019-05-30 19:35:05 -0700 | [diff] [blame] | 632 | } |
Anthony Chen | 83092c6 | 2016-01-11 17:00:36 -0800 | [diff] [blame] | 633 | } |