Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License |
| 15 | */ |
| 16 | |
| 17 | package com.android.systemui.statusbar.phone; |
| 18 | |
felkachang | 3d00f35 | 2018-05-22 12:53:50 +0800 | [diff] [blame] | 19 | import android.graphics.Point; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 20 | import android.graphics.Rect; |
felkachang | 7749c9a | 2018-06-11 15:56:15 +0800 | [diff] [blame] | 21 | import android.view.DisplayCutout; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 22 | import android.view.View; |
felkachang | 3d00f35 | 2018-05-22 12:53:50 +0800 | [diff] [blame] | 23 | import android.view.WindowInsets; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 24 | |
| 25 | import com.android.internal.annotations.VisibleForTesting; |
Peter Cai | a8178f5 | 2019-05-22 13:01:01 +0800 | [diff] [blame] | 26 | import com.android.internal.widget.ViewClippingUtil; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 27 | import com.android.systemui.Dependency; |
| 28 | import com.android.systemui.R; |
Beverly | 1be62f4 | 2018-12-19 17:17:48 -0500 | [diff] [blame] | 29 | import com.android.systemui.plugins.DarkIconDispatcher; |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 30 | import com.android.systemui.plugins.statusbar.StatusBarStateController; |
| 31 | import com.android.systemui.statusbar.CommandQueue; |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 32 | import com.android.systemui.statusbar.CrossFadeHelper; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 33 | import com.android.systemui.statusbar.HeadsUpStatusBarView; |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 34 | import com.android.systemui.statusbar.StatusBarState; |
| 35 | import com.android.systemui.statusbar.SysuiStatusBarStateController; |
Selim Cinek | 8ee02b1 | 2019-07-22 14:49:18 -0700 | [diff] [blame] | 36 | import com.android.systemui.statusbar.notification.NotificationWakeUpCoordinator; |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 37 | import com.android.systemui.statusbar.notification.collection.NotificationEntry; |
Gus Prevas | ab33679 | 2018-11-14 13:52:20 -0500 | [diff] [blame] | 38 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 39 | import com.android.systemui.statusbar.notification.stack.NotificationStackScrollLayout; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 40 | import com.android.systemui.statusbar.policy.KeyguardStateController; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 41 | import com.android.systemui.statusbar.policy.OnHeadsUpChangedListener; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 42 | |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 43 | import java.util.function.BiConsumer; |
| 44 | import java.util.function.Consumer; |
| 45 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 46 | /** |
| 47 | * Controls the appearance of heads up notifications in the icon area and the header itself. |
| 48 | */ |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 49 | public class HeadsUpAppearanceController implements OnHeadsUpChangedListener, |
Selim Cinek | 8ee02b1 | 2019-07-22 14:49:18 -0700 | [diff] [blame] | 50 | DarkIconDispatcher.DarkReceiver, NotificationWakeUpCoordinator.WakeUpListener { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 51 | public static final int CONTENT_FADE_DURATION = 110; |
| 52 | public static final int CONTENT_FADE_DELAY = 100; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 53 | private final NotificationIconAreaController mNotificationIconAreaController; |
| 54 | private final HeadsUpManagerPhone mHeadsUpManager; |
| 55 | private final NotificationStackScrollLayout mStackScroller; |
| 56 | private final HeadsUpStatusBarView mHeadsUpStatusBarView; |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 57 | private final View mCenteredIconView; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 58 | private final View mClockView; |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 59 | private final View mOperatorNameView; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 60 | private final DarkIconDispatcher mDarkIconDispatcher; |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 61 | private final NotificationPanelViewController mNotificationPanelViewController; |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 62 | private final Consumer<ExpandableNotificationRow> |
| 63 | mSetTrackingHeadsUp = this::setTrackingHeadsUp; |
| 64 | private final Runnable mUpdatePanelTranslation = this::updatePanelTranslation; |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 65 | private final BiConsumer<Float, Float> mSetExpandedHeight = this::setAppearFraction; |
| 66 | private final KeyguardBypassController mBypassController; |
| 67 | private final StatusBarStateController mStatusBarStateController; |
| 68 | private final CommandQueue mCommandQueue; |
Selim Cinek | 8ee02b1 | 2019-07-22 14:49:18 -0700 | [diff] [blame] | 69 | private final NotificationWakeUpCoordinator mWakeUpCoordinator; |
felkachang | e6c03a0 | 2018-05-24 15:38:04 +0800 | [diff] [blame] | 70 | @VisibleForTesting |
| 71 | float mExpandedHeight; |
| 72 | @VisibleForTesting |
| 73 | boolean mIsExpanded; |
| 74 | @VisibleForTesting |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 75 | float mAppearFraction; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 76 | private ExpandableNotificationRow mTrackedChild; |
| 77 | private boolean mShown; |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 78 | private final View.OnLayoutChangeListener mStackScrollLayoutChangeListener = |
| 79 | (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) |
| 80 | -> updatePanelTranslation(); |
Peter Cai | a8178f5 | 2019-05-22 13:01:01 +0800 | [diff] [blame] | 81 | private final ViewClippingUtil.ClippingParameters mParentClippingParams = |
| 82 | new ViewClippingUtil.ClippingParameters() { |
| 83 | @Override |
| 84 | public boolean shouldFinish(View view) { |
| 85 | return view.getId() == R.id.status_bar; |
| 86 | } |
| 87 | }; |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 88 | private boolean mAnimationsEnabled = true; |
felkachang | 3d00f35 | 2018-05-22 12:53:50 +0800 | [diff] [blame] | 89 | Point mPoint; |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 90 | private KeyguardStateController mKeyguardStateController; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 91 | |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 92 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 93 | public HeadsUpAppearanceController( |
| 94 | NotificationIconAreaController notificationIconAreaController, |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 95 | HeadsUpManagerPhone headsUpManager, |
| 96 | View notificationShadeView, |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 97 | SysuiStatusBarStateController statusBarStateController, |
Selim Cinek | 8ee02b1 | 2019-07-22 14:49:18 -0700 | [diff] [blame] | 98 | KeyguardBypassController keyguardBypassController, |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 99 | KeyguardStateController keyguardStateController, |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 100 | NotificationWakeUpCoordinator wakeUpCoordinator, CommandQueue commandQueue, |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 101 | NotificationPanelViewController notificationPanelViewController, View statusBarView) { |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 102 | this(notificationIconAreaController, headsUpManager, statusBarStateController, |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 103 | keyguardBypassController, wakeUpCoordinator, keyguardStateController, |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 104 | commandQueue, |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 105 | statusBarView.findViewById(R.id.heads_up_status_bar_view), |
| 106 | notificationShadeView.findViewById(R.id.notification_stack_scroller), |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 107 | notificationPanelViewController, |
wilsonshih | e832194 | 2019-10-18 18:39:46 +0800 | [diff] [blame] | 108 | statusBarView.findViewById(R.id.clock), |
| 109 | statusBarView.findViewById(R.id.operator_name_frame), |
| 110 | statusBarView.findViewById(R.id.centered_icon_area)); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | @VisibleForTesting |
| 114 | public HeadsUpAppearanceController( |
| 115 | NotificationIconAreaController notificationIconAreaController, |
| 116 | HeadsUpManagerPhone headsUpManager, |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 117 | StatusBarStateController stateController, |
| 118 | KeyguardBypassController bypassController, |
Selim Cinek | 8ee02b1 | 2019-07-22 14:49:18 -0700 | [diff] [blame] | 119 | NotificationWakeUpCoordinator wakeUpCoordinator, |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 120 | KeyguardStateController keyguardStateController, |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 121 | CommandQueue commandQueue, |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 122 | HeadsUpStatusBarView headsUpStatusBarView, |
| 123 | NotificationStackScrollLayout stackScroller, |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 124 | NotificationPanelViewController notificationPanelViewController, |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 125 | View clockView, |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 126 | View operatorNameView, |
| 127 | View centeredIconView) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 128 | mNotificationIconAreaController = notificationIconAreaController; |
| 129 | mHeadsUpManager = headsUpManager; |
| 130 | mHeadsUpManager.addListener(this); |
| 131 | mHeadsUpStatusBarView = headsUpStatusBarView; |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 132 | mCenteredIconView = centeredIconView; |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 133 | headsUpStatusBarView.setOnDrawingRectChangedListener( |
| 134 | () -> updateIsolatedIconLocation(true /* requireUpdate */)); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 135 | mStackScroller = stackScroller; |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 136 | mNotificationPanelViewController = notificationPanelViewController; |
| 137 | notificationPanelViewController.addTrackingHeadsUpListener(mSetTrackingHeadsUp); |
| 138 | notificationPanelViewController.addVerticalTranslationListener(mUpdatePanelTranslation); |
| 139 | notificationPanelViewController.setHeadsUpAppearanceController(this); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 140 | mStackScroller.addOnExpandedHeightChangedListener(mSetExpandedHeight); |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 141 | mStackScroller.addOnLayoutChangeListener(mStackScrollLayoutChangeListener); |
Selim Cinek | f0c79e1 | 2018-05-14 17:17:31 -0700 | [diff] [blame] | 142 | mStackScroller.setHeadsUpAppearanceController(this); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 143 | mClockView = clockView; |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 144 | mOperatorNameView = operatorNameView; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 145 | mDarkIconDispatcher = Dependency.get(DarkIconDispatcher.class); |
| 146 | mDarkIconDispatcher.addDarkReceiver(this); |
felkachang | e6c03a0 | 2018-05-24 15:38:04 +0800 | [diff] [blame] | 147 | |
| 148 | mHeadsUpStatusBarView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() { |
| 149 | @Override |
| 150 | public void onLayoutChange(View v, int left, int top, int right, int bottom, |
| 151 | int oldLeft, int oldTop, int oldRight, int oldBottom) { |
| 152 | if (shouldBeVisible()) { |
| 153 | updateTopEntry(); |
| 154 | |
| 155 | // trigger scroller to notify the latest panel translation |
| 156 | mStackScroller.requestLayout(); |
| 157 | } |
| 158 | mHeadsUpStatusBarView.removeOnLayoutChangeListener(this); |
| 159 | } |
| 160 | }); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 161 | mBypassController = bypassController; |
| 162 | mStatusBarStateController = stateController; |
Selim Cinek | 8ee02b1 | 2019-07-22 14:49:18 -0700 | [diff] [blame] | 163 | mWakeUpCoordinator = wakeUpCoordinator; |
| 164 | wakeUpCoordinator.addListener(this); |
Dave Mankoff | bcaca8a | 2019-10-31 18:04:08 -0400 | [diff] [blame] | 165 | mCommandQueue = commandQueue; |
Lucas Dupin | d236ee3 | 2019-10-08 15:33:59 -0700 | [diff] [blame] | 166 | mKeyguardStateController = keyguardStateController; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 167 | } |
| 168 | |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 169 | |
| 170 | public void destroy() { |
| 171 | mHeadsUpManager.removeListener(this); |
| 172 | mHeadsUpStatusBarView.setOnDrawingRectChangedListener(null); |
Selim Cinek | 8ee02b1 | 2019-07-22 14:49:18 -0700 | [diff] [blame] | 173 | mWakeUpCoordinator.removeListener(this); |
Dave Mankoff | af8163f | 2020-01-08 14:24:35 -0500 | [diff] [blame] | 174 | mNotificationPanelViewController.removeTrackingHeadsUpListener(mSetTrackingHeadsUp); |
| 175 | mNotificationPanelViewController.removeVerticalTranslationListener(mUpdatePanelTranslation); |
| 176 | mNotificationPanelViewController.setHeadsUpAppearanceController(null); |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 177 | mStackScroller.removeOnExpandedHeightChangedListener(mSetExpandedHeight); |
Selim Cinek | 60ffea6 | 2018-03-22 13:16:44 -0700 | [diff] [blame] | 178 | mStackScroller.removeOnLayoutChangeListener(mStackScrollLayoutChangeListener); |
| 179 | mDarkIconDispatcher.removeDarkReceiver(this); |
| 180 | } |
| 181 | |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 182 | private void updateIsolatedIconLocation(boolean requireStateUpdate) { |
| 183 | mNotificationIconAreaController.setIsolatedIconLocation( |
| 184 | mHeadsUpStatusBarView.getIconDrawingRect(), requireStateUpdate); |
| 185 | } |
| 186 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 187 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 188 | public void onHeadsUpPinned(NotificationEntry entry) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 189 | updateTopEntry(); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 190 | updateHeader(entry); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 191 | } |
| 192 | |
felkachang | 3d00f35 | 2018-05-22 12:53:50 +0800 | [diff] [blame] | 193 | /** To count the distance from the window right boundary to scroller right boundary. The |
| 194 | * distance formula is the following: |
| 195 | * Y = screenSize - (SystemWindow's width + Scroller.getRight()) |
| 196 | * There are four modes MUST to be considered in Cut Out of RTL. |
| 197 | * No Cut Out: |
| 198 | * Scroller + NB |
| 199 | * NB + Scroller |
| 200 | * => SystemWindow = NavigationBar's width |
| 201 | * => Y = screenSize - (SystemWindow's width + Scroller.getRight()) |
| 202 | * Corner Cut Out or Tall Cut Out: |
| 203 | * cut out + Scroller + NB |
| 204 | * NB + Scroller + cut out |
| 205 | * => SystemWindow = NavigationBar's width |
| 206 | * => Y = screenSize - (SystemWindow's width + Scroller.getRight()) |
| 207 | * Double Cut Out: |
| 208 | * cut out left + Scroller + (NB + cut out right) |
| 209 | * SystemWindow = NavigationBar's width + cut out right width |
| 210 | * => Y = screenSize - (SystemWindow's width + Scroller.getRight()) |
| 211 | * (cut out left + NB) + Scroller + cut out right |
| 212 | * SystemWindow = NavigationBar's width + cut out left width |
| 213 | * => Y = screenSize - (SystemWindow's width + Scroller.getRight()) |
| 214 | * @return the translation X value for RTL. In theory, it should be negative. i.e. -Y |
| 215 | */ |
| 216 | private int getRtlTranslation() { |
felkachang | 3d00f35 | 2018-05-22 12:53:50 +0800 | [diff] [blame] | 217 | if (mPoint == null) { |
| 218 | mPoint = new Point(); |
| 219 | } |
| 220 | |
| 221 | int realDisplaySize = 0; |
| 222 | if (mStackScroller.getDisplay() != null) { |
| 223 | mStackScroller.getDisplay().getRealSize(mPoint); |
| 224 | realDisplaySize = mPoint.x; |
| 225 | } |
| 226 | |
| 227 | WindowInsets windowInset = mStackScroller.getRootWindowInsets(); |
felkachang | 7749c9a | 2018-06-11 15:56:15 +0800 | [diff] [blame] | 228 | DisplayCutout cutout = (windowInset != null) ? windowInset.getDisplayCutout() : null; |
| 229 | int sysWinLeft = (windowInset != null) ? windowInset.getStableInsetLeft() : 0; |
| 230 | int sysWinRight = (windowInset != null) ? windowInset.getStableInsetRight() : 0; |
| 231 | int cutoutLeft = (cutout != null) ? cutout.getSafeInsetLeft() : 0; |
| 232 | int cutoutRight = (cutout != null) ? cutout.getSafeInsetRight() : 0; |
| 233 | int leftInset = Math.max(sysWinLeft, cutoutLeft); |
| 234 | int rightInset = Math.max(sysWinRight, cutoutRight); |
| 235 | |
| 236 | return leftInset + mStackScroller.getRight() + rightInset - realDisplaySize; |
felkachang | 3d00f35 | 2018-05-22 12:53:50 +0800 | [diff] [blame] | 237 | } |
| 238 | |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 239 | public void updatePanelTranslation() { |
felkachang | 3d00f35 | 2018-05-22 12:53:50 +0800 | [diff] [blame] | 240 | float newTranslation; |
| 241 | if (mStackScroller.isLayoutRtl()) { |
| 242 | newTranslation = getRtlTranslation(); |
| 243 | } else { |
| 244 | newTranslation = mStackScroller.getLeft(); |
| 245 | } |
| 246 | newTranslation += mStackScroller.getTranslationX(); |
felkachang | e8a3536 | 2018-05-18 20:11:38 +0800 | [diff] [blame] | 247 | mHeadsUpStatusBarView.setPanelTranslation(newTranslation); |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 248 | } |
| 249 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 250 | private void updateTopEntry() { |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 251 | NotificationEntry newEntry = null; |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 252 | if (shouldBeVisible()) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 253 | newEntry = mHeadsUpManager.getTopEntry(); |
| 254 | } |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 255 | NotificationEntry previousEntry = mHeadsUpStatusBarView.getShowingEntry(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 256 | mHeadsUpStatusBarView.setEntry(newEntry); |
| 257 | if (newEntry != previousEntry) { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 258 | boolean animateIsolation = false; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 259 | if (newEntry == null) { |
| 260 | // no heads up anymore, lets start the disappear animation |
| 261 | |
| 262 | setShown(false); |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 263 | animateIsolation = !mIsExpanded; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 264 | } else if (previousEntry == null) { |
| 265 | // We now have a headsUp and didn't have one before. Let's start the disappear |
| 266 | // animation |
| 267 | setShown(true); |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 268 | animateIsolation = !mIsExpanded; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 269 | } |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 270 | updateIsolatedIconLocation(false /* requireUpdate */); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 271 | mNotificationIconAreaController.showIconIsolated(newEntry == null ? null |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 272 | : newEntry.icon, animateIsolation); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 273 | } |
| 274 | } |
| 275 | |
| 276 | private void setShown(boolean isShown) { |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 277 | if (mShown != isShown) { |
| 278 | mShown = isShown; |
| 279 | if (isShown) { |
Peter Cai | a8178f5 | 2019-05-22 13:01:01 +0800 | [diff] [blame] | 280 | updateParentClipping(false /* shouldClip */); |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 281 | mHeadsUpStatusBarView.setVisibility(View.VISIBLE); |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 282 | show(mHeadsUpStatusBarView); |
| 283 | hide(mClockView, View.INVISIBLE); |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 284 | if (mCenteredIconView.getVisibility() != View.GONE) { |
| 285 | hide(mCenteredIconView, View.INVISIBLE); |
| 286 | } |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 287 | if (mOperatorNameView != null) { |
| 288 | hide(mOperatorNameView, View.INVISIBLE); |
| 289 | } |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 290 | } else { |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 291 | show(mClockView); |
Beverly | 4077065 | 2019-02-15 15:49:49 -0500 | [diff] [blame] | 292 | if (mCenteredIconView.getVisibility() != View.GONE) { |
| 293 | show(mCenteredIconView); |
| 294 | } |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 295 | if (mOperatorNameView != null) { |
| 296 | show(mOperatorNameView); |
| 297 | } |
Peter Cai | a8178f5 | 2019-05-22 13:01:01 +0800 | [diff] [blame] | 298 | hide(mHeadsUpStatusBarView, View.GONE, () -> { |
| 299 | updateParentClipping(true /* shouldClip */); |
| 300 | }); |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 301 | } |
Selim Cinek | 8ee02b1 | 2019-07-22 14:49:18 -0700 | [diff] [blame] | 302 | // Show the status bar icons when the view gets shown / hidden |
| 303 | if (mStatusBarStateController.getState() != StatusBarState.SHADE) { |
| 304 | mCommandQueue.recomputeDisableFlags( |
| 305 | mHeadsUpStatusBarView.getContext().getDisplayId(), false); |
| 306 | } |
Selim Cinek | d03518c | 2018-03-15 12:13:51 -0700 | [diff] [blame] | 307 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 308 | } |
| 309 | |
Peter Cai | a8178f5 | 2019-05-22 13:01:01 +0800 | [diff] [blame] | 310 | private void updateParentClipping(boolean shouldClip) { |
| 311 | ViewClippingUtil.setClippingDeactivated( |
| 312 | mHeadsUpStatusBarView, !shouldClip, mParentClippingParams); |
| 313 | } |
| 314 | |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 315 | /** |
| 316 | * Hides the view and sets the state to endState when finished. |
| 317 | * |
| 318 | * @param view The view to hide. |
| 319 | * @param endState One of {@link View#INVISIBLE} or {@link View#GONE}. |
Peter Cai | a8178f5 | 2019-05-22 13:01:01 +0800 | [diff] [blame] | 320 | * @see HeadsUpAppearanceController#hide(View, int, Runnable) |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 321 | * @see View#setVisibility(int) |
| 322 | * |
| 323 | */ |
| 324 | private void hide(View view, int endState) { |
Peter Cai | a8178f5 | 2019-05-22 13:01:01 +0800 | [diff] [blame] | 325 | hide(view, endState, null); |
| 326 | } |
| 327 | |
| 328 | /** |
| 329 | * Hides the view and sets the state to endState when finished. |
| 330 | * |
| 331 | * @param view The view to hide. |
| 332 | * @param endState One of {@link View#INVISIBLE} or {@link View#GONE}. |
| 333 | * @param callback Runnable to be executed after the view has been hidden. |
| 334 | * @see View#setVisibility(int) |
| 335 | * |
| 336 | */ |
| 337 | private void hide(View view, int endState, Runnable callback) { |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 338 | if (mAnimationsEnabled) { |
| 339 | CrossFadeHelper.fadeOut(view, CONTENT_FADE_DURATION /* duration */, |
Peter Cai | a8178f5 | 2019-05-22 13:01:01 +0800 | [diff] [blame] | 340 | 0 /* delay */, () -> { |
| 341 | view.setVisibility(endState); |
| 342 | if (callback != null) { |
| 343 | callback.run(); |
| 344 | } |
| 345 | }); |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 346 | } else { |
| 347 | view.setVisibility(endState); |
Peter Cai | a8178f5 | 2019-05-22 13:01:01 +0800 | [diff] [blame] | 348 | if (callback != null) { |
| 349 | callback.run(); |
| 350 | } |
Tetsutoki Shiozawa | ce9645b | 2018-09-05 13:17:01 +0900 | [diff] [blame] | 351 | } |
| 352 | } |
| 353 | |
| 354 | private void show(View view) { |
| 355 | if (mAnimationsEnabled) { |
| 356 | CrossFadeHelper.fadeIn(view, CONTENT_FADE_DURATION /* duration */, |
| 357 | CONTENT_FADE_DELAY /* delay */); |
| 358 | } else { |
| 359 | view.setVisibility(View.VISIBLE); |
| 360 | } |
| 361 | } |
| 362 | |
| 363 | @VisibleForTesting |
| 364 | void setAnimationsEnabled(boolean enabled) { |
| 365 | mAnimationsEnabled = enabled; |
| 366 | } |
| 367 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 368 | @VisibleForTesting |
| 369 | public boolean isShown() { |
| 370 | return mShown; |
| 371 | } |
| 372 | |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 373 | /** |
| 374 | * Should the headsup status bar view be visible right now? This may be different from isShown, |
| 375 | * since the headsUp manager might not have notified us yet of the state change. |
| 376 | * |
| 377 | * @return if the heads up status bar view should be shown |
| 378 | */ |
| 379 | public boolean shouldBeVisible() { |
Selim Cinek | 8ee02b1 | 2019-07-22 14:49:18 -0700 | [diff] [blame] | 380 | boolean notificationsShown = !mWakeUpCoordinator.getNotificationsFullyHidden(); |
| 381 | boolean canShow = !mIsExpanded && notificationsShown; |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 382 | if (mBypassController.getBypassEnabled() && |
| 383 | (mStatusBarStateController.getState() == StatusBarState.KEYGUARD |
Lucas Dupin | c8f16e8 | 2019-09-17 18:24:50 -0400 | [diff] [blame] | 384 | || mKeyguardStateController.isKeyguardGoingAway()) |
Selim Cinek | 8ee02b1 | 2019-07-22 14:49:18 -0700 | [diff] [blame] | 385 | && notificationsShown) { |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 386 | canShow = true; |
| 387 | } |
| 388 | return canShow && mHeadsUpManager.hasPinnedHeadsUp(); |
Selim Cinek | 332c23f | 2018-03-16 17:37:50 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 391 | @Override |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 392 | public void onHeadsUpUnPinned(NotificationEntry entry) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 393 | updateTopEntry(); |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 394 | updateHeader(entry); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 395 | } |
| 396 | |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 397 | public void setAppearFraction(float expandedHeight, float appearFraction) { |
| 398 | boolean changed = expandedHeight != mExpandedHeight; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 399 | mExpandedHeight = expandedHeight; |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 400 | mAppearFraction = appearFraction; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 401 | boolean isExpanded = expandedHeight > 0; |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 402 | // We only notify if the expandedHeight changed and not on the appearFraction, since |
| 403 | // otherwise we may run into an infinite loop where the panel and this are constantly |
| 404 | // updating themselves over just a small fraction |
| 405 | if (changed) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 406 | updateHeadsUpHeaders(); |
| 407 | } |
| 408 | if (isExpanded != mIsExpanded) { |
| 409 | mIsExpanded = isExpanded; |
| 410 | updateTopEntry(); |
| 411 | } |
| 412 | } |
| 413 | |
| 414 | /** |
| 415 | * Set a headsUp to be tracked, meaning that it is currently being pulled down after being |
| 416 | * in a pinned state on the top. The expand animation is different in that case and we need |
| 417 | * to update the header constantly afterwards. |
| 418 | * |
| 419 | * @param trackedChild the tracked headsUp or null if it's not tracking anymore. |
| 420 | */ |
| 421 | public void setTrackingHeadsUp(ExpandableNotificationRow trackedChild) { |
| 422 | ExpandableNotificationRow previousTracked = mTrackedChild; |
| 423 | mTrackedChild = trackedChild; |
| 424 | if (previousTracked != null) { |
| 425 | updateHeader(previousTracked.getEntry()); |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | private void updateHeadsUpHeaders() { |
| 430 | mHeadsUpManager.getAllEntries().forEach(entry -> { |
| 431 | updateHeader(entry); |
| 432 | }); |
| 433 | } |
| 434 | |
Ned Burns | f81c4c4 | 2019-01-07 14:10:43 -0500 | [diff] [blame] | 435 | public void updateHeader(NotificationEntry entry) { |
Evan Laird | 9449285 | 2018-10-25 13:43:01 -0400 | [diff] [blame] | 436 | ExpandableNotificationRow row = entry.getRow(); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 437 | float headerVisibleAmount = 1.0f; |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 438 | if (row.isPinned() || row.isHeadsUpAnimatingAway() || row == mTrackedChild |
| 439 | || row.showingPulsing()) { |
| 440 | headerVisibleAmount = mAppearFraction; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 441 | } |
| 442 | row.setHeaderVisibleAmount(headerVisibleAmount); |
| 443 | } |
| 444 | |
| 445 | @Override |
| 446 | public void onDarkChanged(Rect area, float darkIntensity, int tint) { |
| 447 | mHeadsUpStatusBarView.onDarkChanged(area, darkIntensity, tint); |
| 448 | } |
| 449 | |
Selim Cinek | b2c5dc5 | 2019-06-24 15:46:52 -0700 | [diff] [blame] | 450 | public void onStateChanged() { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 451 | updateTopEntry(); |
| 452 | } |
felkachang | e6c03a0 | 2018-05-24 15:38:04 +0800 | [diff] [blame] | 453 | |
| 454 | void readFrom(HeadsUpAppearanceController oldController) { |
| 455 | if (oldController != null) { |
| 456 | mTrackedChild = oldController.mTrackedChild; |
| 457 | mExpandedHeight = oldController.mExpandedHeight; |
| 458 | mIsExpanded = oldController.mIsExpanded; |
Selim Cinek | c7e4cb5 | 2019-06-20 15:41:45 -0700 | [diff] [blame] | 459 | mAppearFraction = oldController.mAppearFraction; |
felkachang | e6c03a0 | 2018-05-24 15:38:04 +0800 | [diff] [blame] | 460 | } |
| 461 | } |
Selim Cinek | 8ee02b1 | 2019-07-22 14:49:18 -0700 | [diff] [blame] | 462 | |
| 463 | @Override |
| 464 | public void onFullyHiddenChanged(boolean isFullyHidden) { |
| 465 | updateTopEntry(); |
| 466 | } |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 467 | } |