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