Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 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.stack; |
| 18 | |
Eliot Courtney | 5d3d2d0 | 2018-01-18 15:59:03 +0900 | [diff] [blame] | 19 | import android.annotation.Nullable; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 20 | import android.content.Context; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 21 | import android.view.View; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 22 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 23 | import com.android.systemui.R; |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 24 | import com.android.systemui.statusbar.ActivatableNotificationView; |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 25 | import com.android.systemui.statusbar.ExpandableNotificationRow; |
| 26 | import com.android.systemui.statusbar.ExpandableView; |
| 27 | import com.android.systemui.statusbar.NotificationData; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 28 | import com.android.systemui.statusbar.NotificationShelf; |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 29 | import com.android.systemui.statusbar.StatusBarState; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 30 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 31 | |
| 32 | import java.util.ArrayList; |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 33 | import java.util.Collection; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 34 | |
| 35 | /** |
| 36 | * A global state to track all input states for the algorithm. |
| 37 | */ |
| 38 | public class AmbientState { |
| 39 | private ArrayList<View> mDraggedViews = new ArrayList<View>(); |
| 40 | private int mScrollY; |
| 41 | private boolean mDimmed; |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 42 | private ActivatableNotificationView mActivatedChild; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 43 | private float mOverScrollTopAmount; |
| 44 | private float mOverScrollBottomAmount; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 45 | private int mSpeedBumpIndex = -1; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 46 | private boolean mDark; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 47 | private boolean mHideSensitive; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 48 | private HeadsUpManager mHeadsUpManager; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 49 | private float mStackTranslation; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 50 | private int mLayoutHeight; |
| 51 | private int mTopPadding; |
| 52 | private boolean mShadeExpanded; |
| 53 | private float mMaxHeadsUpTranslation; |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 54 | private boolean mDismissAllInProgress; |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 55 | private int mLayoutMinHeight; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 56 | private NotificationShelf mShelf; |
| 57 | private int mZDistanceBetweenElements; |
| 58 | private int mBaseZHeight; |
Selim Cinek | 91d4cba | 2016-11-10 19:59:48 -0800 | [diff] [blame] | 59 | private int mMaxLayoutHeight; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 60 | private ActivatableNotificationView mLastVisibleBackgroundChild; |
Selim Cinek | 727903c | 2016-12-06 17:28:10 -0800 | [diff] [blame] | 61 | private float mCurrentScrollVelocity; |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 62 | private int mStatusBarState; |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 63 | private float mExpandingVelocity; |
| 64 | private boolean mPanelTracking; |
| 65 | private boolean mExpansionChanging; |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 66 | private boolean mPanelFullWidth; |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 67 | private Collection<HeadsUpManager.HeadsUpEntry> mPulsing; |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 68 | private boolean mUnlockHintRunning; |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 69 | private boolean mQsCustomizerShowing; |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 70 | private int mIntrinsicPadding; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 71 | |
| 72 | public AmbientState(Context context) { |
| 73 | reload(context); |
| 74 | } |
| 75 | |
| 76 | /** |
| 77 | * Reload the dimens e.g. if the density changed. |
| 78 | */ |
| 79 | public void reload(Context context) { |
| 80 | mZDistanceBetweenElements = Math.max(1, context.getResources() |
| 81 | .getDimensionPixelSize(R.dimen.z_distance_between_notifications)); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 82 | mBaseZHeight = 4 * mZDistanceBetweenElements; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | /** |
| 86 | * @return the basic Z height on which notifications remain. |
| 87 | */ |
| 88 | public int getBaseZHeight() { |
| 89 | return mBaseZHeight; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * @return the distance in Z between two overlaying notifications. |
| 94 | */ |
| 95 | public int getZDistanceBetweenElements() { |
| 96 | return mZDistanceBetweenElements; |
| 97 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 98 | |
| 99 | public int getScrollY() { |
| 100 | return mScrollY; |
| 101 | } |
| 102 | |
| 103 | public void setScrollY(int scrollY) { |
| 104 | this.mScrollY = scrollY; |
| 105 | } |
| 106 | |
| 107 | public void onBeginDrag(View view) { |
| 108 | mDraggedViews.add(view); |
| 109 | } |
| 110 | |
| 111 | public void onDragFinished(View view) { |
| 112 | mDraggedViews.remove(view); |
| 113 | } |
| 114 | |
| 115 | public ArrayList<View> getDraggedViews() { |
| 116 | return mDraggedViews; |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * @param dimmed Whether we are in a dimmed state (on the lockscreen), where the backgrounds are |
| 121 | * translucent and everything is scaled back a bit. |
| 122 | */ |
| 123 | public void setDimmed(boolean dimmed) { |
| 124 | mDimmed = dimmed; |
| 125 | } |
| 126 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 127 | /** In dark mode, we draw as little as possible, assuming a black background */ |
| 128 | public void setDark(boolean dark) { |
| 129 | mDark = dark; |
| 130 | } |
| 131 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 132 | public void setHideSensitive(boolean hideSensitive) { |
| 133 | mHideSensitive = hideSensitive; |
| 134 | } |
| 135 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 136 | /** |
| 137 | * In dimmed mode, a child can be activated, which happens on the first tap of the double-tap |
| 138 | * interaction. This child is then scaled normally and its background is fully opaque. |
| 139 | */ |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 140 | public void setActivatedChild(ActivatableNotificationView activatedChild) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 141 | mActivatedChild = activatedChild; |
| 142 | } |
| 143 | |
| 144 | public boolean isDimmed() { |
| 145 | return mDimmed; |
| 146 | } |
| 147 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 148 | public boolean isDark() { |
| 149 | return mDark; |
| 150 | } |
| 151 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 152 | public boolean isHideSensitive() { |
| 153 | return mHideSensitive; |
| 154 | } |
| 155 | |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 156 | public ActivatableNotificationView getActivatedChild() { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 157 | return mActivatedChild; |
| 158 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 159 | |
| 160 | public void setOverScrollAmount(float amount, boolean onTop) { |
| 161 | if (onTop) { |
| 162 | mOverScrollTopAmount = amount; |
| 163 | } else { |
| 164 | mOverScrollBottomAmount = amount; |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | public float getOverScrollAmount(boolean top) { |
| 169 | return top ? mOverScrollTopAmount : mOverScrollBottomAmount; |
| 170 | } |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 171 | |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 172 | public int getSpeedBumpIndex() { |
| 173 | return mSpeedBumpIndex; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 174 | } |
| 175 | |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 176 | public void setSpeedBumpIndex(int shelfIndex) { |
| 177 | mSpeedBumpIndex = shelfIndex; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 178 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 179 | |
| 180 | public void setHeadsUpManager(HeadsUpManager headsUpManager) { |
| 181 | mHeadsUpManager = headsUpManager; |
| 182 | } |
| 183 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 184 | public float getStackTranslation() { |
| 185 | return mStackTranslation; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 188 | public void setStackTranslation(float stackTranslation) { |
| 189 | mStackTranslation = stackTranslation; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 190 | } |
| 191 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 192 | public void setLayoutHeight(int layoutHeight) { |
| 193 | mLayoutHeight = layoutHeight; |
| 194 | } |
| 195 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 196 | public float getTopPadding() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 197 | return mTopPadding; |
| 198 | } |
| 199 | |
| 200 | public void setTopPadding(int topPadding) { |
| 201 | mTopPadding = topPadding; |
| 202 | } |
| 203 | |
| 204 | public int getInnerHeight() { |
Selim Cinek | 91d4cba | 2016-11-10 19:59:48 -0800 | [diff] [blame] | 205 | return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding, mLayoutMinHeight); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 206 | } |
| 207 | |
| 208 | public boolean isShadeExpanded() { |
| 209 | return mShadeExpanded; |
| 210 | } |
| 211 | |
| 212 | public void setShadeExpanded(boolean shadeExpanded) { |
| 213 | mShadeExpanded = shadeExpanded; |
| 214 | } |
| 215 | |
| 216 | public void setMaxHeadsUpTranslation(float maxHeadsUpTranslation) { |
| 217 | mMaxHeadsUpTranslation = maxHeadsUpTranslation; |
| 218 | } |
| 219 | |
| 220 | public float getMaxHeadsUpTranslation() { |
| 221 | return mMaxHeadsUpTranslation; |
| 222 | } |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 223 | |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 224 | public void setDismissAllInProgress(boolean dismissAllInProgress) { |
| 225 | mDismissAllInProgress = dismissAllInProgress; |
| 226 | } |
| 227 | |
| 228 | public boolean isDismissAllInProgress() { |
| 229 | return mDismissAllInProgress; |
| 230 | } |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 231 | |
| 232 | public void setLayoutMinHeight(int layoutMinHeight) { |
| 233 | mLayoutMinHeight = layoutMinHeight; |
| 234 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 235 | |
| 236 | public void setShelf(NotificationShelf shelf) { |
| 237 | mShelf = shelf; |
| 238 | } |
| 239 | |
Eliot Courtney | 5d3d2d0 | 2018-01-18 15:59:03 +0900 | [diff] [blame] | 240 | @Nullable |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 241 | public NotificationShelf getShelf() { |
| 242 | return mShelf; |
| 243 | } |
Selim Cinek | 91d4cba | 2016-11-10 19:59:48 -0800 | [diff] [blame] | 244 | |
| 245 | public void setLayoutMaxHeight(int maxLayoutHeight) { |
| 246 | mMaxLayoutHeight = maxLayoutHeight; |
| 247 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 248 | |
| 249 | /** |
| 250 | * Sets the last visible view of the host layout, that has a background, i.e the very last |
| 251 | * view in the shade, without the clear all button. |
| 252 | */ |
| 253 | public void setLastVisibleBackgroundChild( |
| 254 | ActivatableNotificationView lastVisibleBackgroundChild) { |
| 255 | mLastVisibleBackgroundChild = lastVisibleBackgroundChild; |
| 256 | } |
| 257 | |
| 258 | public ActivatableNotificationView getLastVisibleBackgroundChild() { |
| 259 | return mLastVisibleBackgroundChild; |
| 260 | } |
Selim Cinek | 727903c | 2016-12-06 17:28:10 -0800 | [diff] [blame] | 261 | |
| 262 | public void setCurrentScrollVelocity(float currentScrollVelocity) { |
| 263 | mCurrentScrollVelocity = currentScrollVelocity; |
| 264 | } |
| 265 | |
| 266 | public float getCurrentScrollVelocity() { |
| 267 | return mCurrentScrollVelocity; |
| 268 | } |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 269 | |
| 270 | public boolean isOnKeyguard() { |
| 271 | return mStatusBarState == StatusBarState.KEYGUARD; |
| 272 | } |
| 273 | |
| 274 | public void setStatusBarState(int statusBarState) { |
| 275 | mStatusBarState = statusBarState; |
| 276 | } |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 277 | |
| 278 | public void setExpandingVelocity(float expandingVelocity) { |
| 279 | mExpandingVelocity = expandingVelocity; |
| 280 | } |
| 281 | |
| 282 | public void setExpansionChanging(boolean expansionChanging) { |
| 283 | mExpansionChanging = expansionChanging; |
| 284 | } |
| 285 | |
| 286 | public boolean isExpansionChanging() { |
| 287 | return mExpansionChanging; |
| 288 | } |
| 289 | |
| 290 | public float getExpandingVelocity() { |
| 291 | return mExpandingVelocity; |
| 292 | } |
| 293 | |
| 294 | public void setPanelTracking(boolean panelTracking) { |
| 295 | mPanelTracking = panelTracking; |
| 296 | } |
| 297 | |
Selim Cinek | be2c443 | 2017-05-30 12:11:09 -0700 | [diff] [blame] | 298 | public boolean hasPulsingNotifications() { |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 299 | return mPulsing != null; |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 300 | } |
| 301 | |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 302 | public void setPulsing(Collection<HeadsUpManager.HeadsUpEntry> hasPulsing) { |
| 303 | mPulsing = hasPulsing; |
| 304 | } |
| 305 | |
| 306 | public boolean isPulsing(NotificationData.Entry entry) { |
| 307 | if (mPulsing == null) { |
| 308 | return false; |
| 309 | } |
| 310 | for (HeadsUpManager.HeadsUpEntry e : mPulsing) { |
| 311 | if (e.entry == entry) { |
| 312 | return true; |
| 313 | } |
| 314 | } |
| 315 | return false; |
Adrian Roos | d83e999 | 2017-03-16 15:17:57 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Selim Cinek | d5ab645 | 2016-12-08 16:34:00 -0800 | [diff] [blame] | 318 | public boolean isPanelTracking() { |
| 319 | return mPanelTracking; |
| 320 | } |
Selim Cinek | fcff4c6 | 2016-12-27 14:26:06 +0100 | [diff] [blame] | 321 | |
| 322 | public boolean isPanelFullWidth() { |
| 323 | return mPanelFullWidth; |
| 324 | } |
| 325 | |
| 326 | public void setPanelFullWidth(boolean panelFullWidth) { |
| 327 | mPanelFullWidth = panelFullWidth; |
| 328 | } |
Selim Cinek | ec29d34 | 2017-05-05 18:31:49 -0700 | [diff] [blame] | 329 | |
| 330 | public void setUnlockHintRunning(boolean unlockHintRunning) { |
| 331 | mUnlockHintRunning = unlockHintRunning; |
| 332 | } |
| 333 | |
| 334 | public boolean isUnlockHintRunning() { |
| 335 | return mUnlockHintRunning; |
| 336 | } |
Selim Cinek | 5cf1d05 | 2017-06-01 17:36:46 -0700 | [diff] [blame] | 337 | |
| 338 | public boolean isQsCustomizerShowing() { |
| 339 | return mQsCustomizerShowing; |
| 340 | } |
| 341 | |
| 342 | public void setQsCustomizerShowing(boolean qsCustomizerShowing) { |
| 343 | mQsCustomizerShowing = qsCustomizerShowing; |
| 344 | } |
Selim Cinek | 1f62495 | 2017-06-08 19:11:50 -0700 | [diff] [blame] | 345 | |
| 346 | public void setIntrinsicPadding(int intrinsicPadding) { |
| 347 | mIntrinsicPadding = intrinsicPadding; |
| 348 | } |
| 349 | |
| 350 | public int getIntrinsicPadding() { |
| 351 | return mIntrinsicPadding; |
| 352 | } |
Selim Cinek | ebf4234 | 2017-07-13 15:46:10 +0200 | [diff] [blame] | 353 | |
| 354 | /** |
| 355 | * Similar to the normal is above shelf logic but doesn't allow it to be above in AOD1. |
| 356 | * |
| 357 | * @param expandableView the view to check |
| 358 | */ |
| 359 | public boolean isAboveShelf(ExpandableView expandableView) { |
| 360 | if (!(expandableView instanceof ExpandableNotificationRow)) { |
| 361 | return expandableView.isAboveShelf(); |
| 362 | } |
| 363 | ExpandableNotificationRow row = (ExpandableNotificationRow) expandableView; |
| 364 | return row.isAboveShelf() && !isDozingAndNotPulsing(row); |
| 365 | } |
| 366 | |
| 367 | /** |
| 368 | * @return whether a view is dozing and not pulsing right now |
| 369 | */ |
| 370 | public boolean isDozingAndNotPulsing(ExpandableView view) { |
| 371 | if (view instanceof ExpandableNotificationRow) { |
| 372 | return isDozingAndNotPulsing((ExpandableNotificationRow) view); |
| 373 | } |
| 374 | return false; |
| 375 | } |
| 376 | |
| 377 | /** |
| 378 | * @return whether a row is dozing and not pulsing right now |
| 379 | */ |
| 380 | public boolean isDozingAndNotPulsing(ExpandableNotificationRow row) { |
| 381 | return isDark() && !isPulsing(row.getEntry()); |
| 382 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 383 | } |