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