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