blob: 91a4b07c2109731cedc4ecb1361e443f685a3e09 [file] [log] [blame]
Jorim Jaggid552d9d2014-05-07 19:41:13 +02001/*
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
17package com.android.systemui.statusbar.stack;
18
Eliot Courtney5d3d2d02018-01-18 15:59:03 +090019import android.annotation.Nullable;
Selim Cinek281c2022016-10-13 19:14:43 -070020import android.content.Context;
Jorim Jaggid552d9d2014-05-07 19:41:13 +020021import android.view.View;
Selim Cineka59ecc32015-04-07 10:51:49 -070022
Selim Cinek281c2022016-10-13 19:14:43 -070023import com.android.systemui.R;
Selim Cineka32ab602014-06-11 15:06:01 +020024import com.android.systemui.statusbar.ActivatableNotificationView;
Selim Cinekebf42342017-07-13 15:46:10 +020025import com.android.systemui.statusbar.ExpandableNotificationRow;
26import com.android.systemui.statusbar.ExpandableView;
27import com.android.systemui.statusbar.NotificationData;
Selim Cinek281c2022016-10-13 19:14:43 -070028import com.android.systemui.statusbar.NotificationShelf;
Selim Cinek355652a2016-12-07 13:32:12 -080029import com.android.systemui.statusbar.StatusBarState;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070030import com.android.systemui.statusbar.policy.HeadsUpManager;
Jorim Jaggid552d9d2014-05-07 19:41:13 +020031
32import java.util.ArrayList;
Selim Cinekebf42342017-07-13 15:46:10 +020033import java.util.Collection;
Jorim Jaggid552d9d2014-05-07 19:41:13 +020034
35/**
36 * A global state to track all input states for the algorithm.
37 */
38public class AmbientState {
39 private ArrayList<View> mDraggedViews = new ArrayList<View>();
40 private int mScrollY;
41 private boolean mDimmed;
Selim Cineka32ab602014-06-11 15:06:01 +020042 private ActivatableNotificationView mActivatedChild;
Selim Cinek8d9ff9c2014-05-12 15:13:04 +020043 private float mOverScrollTopAmount;
44 private float mOverScrollBottomAmount;
Selim Cinekdb167372016-11-17 15:41:17 -080045 private int mSpeedBumpIndex = -1;
John Spurlockbf370992014-06-17 13:58:31 -040046 private boolean mDark;
Jorim Jaggiae441282014-08-01 02:45:18 +020047 private boolean mHideSensitive;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070048 private HeadsUpManager mHeadsUpManager;
Selim Cineka59ecc32015-04-07 10:51:49 -070049 private float mStackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070050 private int mLayoutHeight;
51 private int mTopPadding;
52 private boolean mShadeExpanded;
53 private float mMaxHeadsUpTranslation;
Selim Cinek9c17b772015-07-07 20:37:09 -070054 private boolean mDismissAllInProgress;
Selim Cinekbc243a92016-09-27 16:35:13 -070055 private int mLayoutMinHeight;
Selim Cinek281c2022016-10-13 19:14:43 -070056 private NotificationShelf mShelf;
57 private int mZDistanceBetweenElements;
58 private int mBaseZHeight;
Selim Cinek91d4cba2016-11-10 19:59:48 -080059 private int mMaxLayoutHeight;
Selim Cinekdb167372016-11-17 15:41:17 -080060 private ActivatableNotificationView mLastVisibleBackgroundChild;
Selim Cinek727903c2016-12-06 17:28:10 -080061 private float mCurrentScrollVelocity;
Selim Cinek355652a2016-12-07 13:32:12 -080062 private int mStatusBarState;
Selim Cinekd5ab6452016-12-08 16:34:00 -080063 private float mExpandingVelocity;
64 private boolean mPanelTracking;
65 private boolean mExpansionChanging;
Selim Cinekfcff4c62016-12-27 14:26:06 +010066 private boolean mPanelFullWidth;
yoshiki iguchi4e30e762018-02-06 12:09:23 +090067 private boolean mPulsing;
Selim Cinekec29d342017-05-05 18:31:49 -070068 private boolean mUnlockHintRunning;
Selim Cinek5cf1d052017-06-01 17:36:46 -070069 private boolean mQsCustomizerShowing;
Selim Cinek1f624952017-06-08 19:11:50 -070070 private int mIntrinsicPadding;
Selim Cinek2627d722018-01-19 12:16:49 -080071 private int mExpandAnimationTopChange;
72 private ExpandableNotificationRow mExpandingNotification;
Lucas Dupin16cfe452018-02-08 13:14:50 -080073 private int mDarkTopPadding;
Lucas Dupinb561eda2018-04-09 17:25:04 -070074 private float mDarkAmount;
Selim Cinek281c2022016-10-13 19:14:43 -070075
76 public AmbientState(Context context) {
77 reload(context);
78 }
79
80 /**
81 * Reload the dimens e.g. if the density changed.
82 */
83 public void reload(Context context) {
Selim Cinek2627d722018-01-19 12:16:49 -080084 mZDistanceBetweenElements = getZDistanceBetweenElements(context);
85 mBaseZHeight = getBaseHeight(mZDistanceBetweenElements);
86 }
87
88 private static int getZDistanceBetweenElements(Context context) {
89 return Math.max(1, context.getResources()
Selim Cinek281c2022016-10-13 19:14:43 -070090 .getDimensionPixelSize(R.dimen.z_distance_between_notifications));
Selim Cinek2627d722018-01-19 12:16:49 -080091 }
92
93 private static int getBaseHeight(int zdistanceBetweenElements) {
94 return 4 * zdistanceBetweenElements;
95 }
96
97 /**
98 * @return the launch height for notifications that are launched
99 */
100 public static int getNotificationLaunchHeight(Context context) {
101 int zDistance = getZDistanceBetweenElements(context);
102 return getBaseHeight(zDistance) * 2;
Selim Cinek281c2022016-10-13 19:14:43 -0700103 }
104
105 /**
106 * @return the basic Z height on which notifications remain.
107 */
108 public int getBaseZHeight() {
109 return mBaseZHeight;
110 }
111
112 /**
113 * @return the distance in Z between two overlaying notifications.
114 */
115 public int getZDistanceBetweenElements() {
116 return mZDistanceBetweenElements;
117 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200118
119 public int getScrollY() {
120 return mScrollY;
121 }
122
123 public void setScrollY(int scrollY) {
124 this.mScrollY = scrollY;
125 }
126
127 public void onBeginDrag(View view) {
128 mDraggedViews.add(view);
129 }
130
131 public void onDragFinished(View view) {
132 mDraggedViews.remove(view);
133 }
134
135 public ArrayList<View> getDraggedViews() {
136 return mDraggedViews;
137 }
138
139 /**
140 * @param dimmed Whether we are in a dimmed state (on the lockscreen), where the backgrounds are
141 * translucent and everything is scaled back a bit.
142 */
143 public void setDimmed(boolean dimmed) {
144 mDimmed = dimmed;
145 }
146
John Spurlockbf370992014-06-17 13:58:31 -0400147 /** In dark mode, we draw as little as possible, assuming a black background */
148 public void setDark(boolean dark) {
149 mDark = dark;
150 }
151
Lucas Dupinb561eda2018-04-09 17:25:04 -0700152 /** Dark ratio of the status bar **/
153 public void setDarkAmount(float darkAmount) {
154 mDarkAmount = darkAmount;
155 }
156
157 /** Returns the dark ratio of the status bar */
158 public float getDarkAmount() {
159 return mDarkAmount;
160 }
161
Jorim Jaggiae441282014-08-01 02:45:18 +0200162 public void setHideSensitive(boolean hideSensitive) {
163 mHideSensitive = hideSensitive;
164 }
165
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200166 /**
167 * In dimmed mode, a child can be activated, which happens on the first tap of the double-tap
168 * interaction. This child is then scaled normally and its background is fully opaque.
169 */
Selim Cineka32ab602014-06-11 15:06:01 +0200170 public void setActivatedChild(ActivatableNotificationView activatedChild) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200171 mActivatedChild = activatedChild;
172 }
173
174 public boolean isDimmed() {
175 return mDimmed;
176 }
177
John Spurlockbf370992014-06-17 13:58:31 -0400178 public boolean isDark() {
179 return mDark;
180 }
181
Jorim Jaggiae441282014-08-01 02:45:18 +0200182 public boolean isHideSensitive() {
183 return mHideSensitive;
184 }
185
Selim Cineka32ab602014-06-11 15:06:01 +0200186 public ActivatableNotificationView getActivatedChild() {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200187 return mActivatedChild;
188 }
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200189
190 public void setOverScrollAmount(float amount, boolean onTop) {
191 if (onTop) {
192 mOverScrollTopAmount = amount;
193 } else {
194 mOverScrollBottomAmount = amount;
195 }
196 }
197
198 public float getOverScrollAmount(boolean top) {
199 return top ? mOverScrollTopAmount : mOverScrollBottomAmount;
200 }
Selim Cinekc27437b2014-05-14 10:23:33 +0200201
Selim Cinekdb167372016-11-17 15:41:17 -0800202 public int getSpeedBumpIndex() {
203 return mSpeedBumpIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200204 }
205
Selim Cinekdb167372016-11-17 15:41:17 -0800206 public void setSpeedBumpIndex(int shelfIndex) {
207 mSpeedBumpIndex = shelfIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200208 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700209
210 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
211 mHeadsUpManager = headsUpManager;
212 }
213
Selim Cineka59ecc32015-04-07 10:51:49 -0700214 public float getStackTranslation() {
215 return mStackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700216 }
217
Selim Cineka59ecc32015-04-07 10:51:49 -0700218 public void setStackTranslation(float stackTranslation) {
219 mStackTranslation = stackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700220 }
221
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700222 public void setLayoutHeight(int layoutHeight) {
223 mLayoutHeight = layoutHeight;
224 }
225
Selim Cineka59ecc32015-04-07 10:51:49 -0700226 public float getTopPadding() {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700227 return mTopPadding;
228 }
229
230 public void setTopPadding(int topPadding) {
231 mTopPadding = topPadding;
232 }
233
234 public int getInnerHeight() {
Selim Cinekc25989e2018-02-16 16:42:14 -0800235 return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding, mLayoutMinHeight);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700236 }
237
238 public boolean isShadeExpanded() {
239 return mShadeExpanded;
240 }
241
242 public void setShadeExpanded(boolean shadeExpanded) {
243 mShadeExpanded = shadeExpanded;
244 }
245
246 public void setMaxHeadsUpTranslation(float maxHeadsUpTranslation) {
247 mMaxHeadsUpTranslation = maxHeadsUpTranslation;
248 }
249
250 public float getMaxHeadsUpTranslation() {
251 return mMaxHeadsUpTranslation;
252 }
Selim Cineka59ecc32015-04-07 10:51:49 -0700253
Selim Cinek9c17b772015-07-07 20:37:09 -0700254 public void setDismissAllInProgress(boolean dismissAllInProgress) {
255 mDismissAllInProgress = dismissAllInProgress;
256 }
257
258 public boolean isDismissAllInProgress() {
259 return mDismissAllInProgress;
260 }
Selim Cinekbc243a92016-09-27 16:35:13 -0700261
262 public void setLayoutMinHeight(int layoutMinHeight) {
263 mLayoutMinHeight = layoutMinHeight;
264 }
Selim Cinek281c2022016-10-13 19:14:43 -0700265
266 public void setShelf(NotificationShelf shelf) {
267 mShelf = shelf;
268 }
269
Eliot Courtney5d3d2d02018-01-18 15:59:03 +0900270 @Nullable
Selim Cinek281c2022016-10-13 19:14:43 -0700271 public NotificationShelf getShelf() {
272 return mShelf;
273 }
Selim Cinek91d4cba2016-11-10 19:59:48 -0800274
275 public void setLayoutMaxHeight(int maxLayoutHeight) {
276 mMaxLayoutHeight = maxLayoutHeight;
277 }
Selim Cinekdb167372016-11-17 15:41:17 -0800278
279 /**
280 * Sets the last visible view of the host layout, that has a background, i.e the very last
281 * view in the shade, without the clear all button.
282 */
283 public void setLastVisibleBackgroundChild(
284 ActivatableNotificationView lastVisibleBackgroundChild) {
285 mLastVisibleBackgroundChild = lastVisibleBackgroundChild;
286 }
287
288 public ActivatableNotificationView getLastVisibleBackgroundChild() {
289 return mLastVisibleBackgroundChild;
290 }
Selim Cinek727903c2016-12-06 17:28:10 -0800291
292 public void setCurrentScrollVelocity(float currentScrollVelocity) {
293 mCurrentScrollVelocity = currentScrollVelocity;
294 }
295
296 public float getCurrentScrollVelocity() {
297 return mCurrentScrollVelocity;
298 }
Selim Cinek355652a2016-12-07 13:32:12 -0800299
300 public boolean isOnKeyguard() {
301 return mStatusBarState == StatusBarState.KEYGUARD;
302 }
303
304 public void setStatusBarState(int statusBarState) {
305 mStatusBarState = statusBarState;
306 }
Selim Cinekd5ab6452016-12-08 16:34:00 -0800307
308 public void setExpandingVelocity(float expandingVelocity) {
309 mExpandingVelocity = expandingVelocity;
310 }
311
312 public void setExpansionChanging(boolean expansionChanging) {
313 mExpansionChanging = expansionChanging;
314 }
315
316 public boolean isExpansionChanging() {
317 return mExpansionChanging;
318 }
319
320 public float getExpandingVelocity() {
321 return mExpandingVelocity;
322 }
323
324 public void setPanelTracking(boolean panelTracking) {
325 mPanelTracking = panelTracking;
326 }
327
Selim Cinekbe2c4432017-05-30 12:11:09 -0700328 public boolean hasPulsingNotifications() {
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900329 return mPulsing;
Adrian Roosd83e9992017-03-16 15:17:57 -0700330 }
331
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900332 public void setPulsing(boolean hasPulsing) {
Selim Cinekebf42342017-07-13 15:46:10 +0200333 mPulsing = hasPulsing;
334 }
335
336 public boolean isPulsing(NotificationData.Entry entry) {
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900337 if (!mPulsing || mHeadsUpManager == null) {
Selim Cinekebf42342017-07-13 15:46:10 +0200338 return false;
339 }
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900340 return mHeadsUpManager.getAllEntries().anyMatch(e -> (e == entry));
Adrian Roosd83e9992017-03-16 15:17:57 -0700341 }
342
Selim Cinekd5ab6452016-12-08 16:34:00 -0800343 public boolean isPanelTracking() {
344 return mPanelTracking;
345 }
Selim Cinekfcff4c62016-12-27 14:26:06 +0100346
347 public boolean isPanelFullWidth() {
348 return mPanelFullWidth;
349 }
350
351 public void setPanelFullWidth(boolean panelFullWidth) {
352 mPanelFullWidth = panelFullWidth;
353 }
Selim Cinekec29d342017-05-05 18:31:49 -0700354
355 public void setUnlockHintRunning(boolean unlockHintRunning) {
356 mUnlockHintRunning = unlockHintRunning;
357 }
358
359 public boolean isUnlockHintRunning() {
360 return mUnlockHintRunning;
361 }
Selim Cinek5cf1d052017-06-01 17:36:46 -0700362
363 public boolean isQsCustomizerShowing() {
364 return mQsCustomizerShowing;
365 }
366
367 public void setQsCustomizerShowing(boolean qsCustomizerShowing) {
368 mQsCustomizerShowing = qsCustomizerShowing;
369 }
Selim Cinek1f624952017-06-08 19:11:50 -0700370
371 public void setIntrinsicPadding(int intrinsicPadding) {
372 mIntrinsicPadding = intrinsicPadding;
373 }
374
375 public int getIntrinsicPadding() {
376 return mIntrinsicPadding;
377 }
Selim Cinekebf42342017-07-13 15:46:10 +0200378
379 /**
380 * Similar to the normal is above shelf logic but doesn't allow it to be above in AOD1.
381 *
382 * @param expandableView the view to check
383 */
384 public boolean isAboveShelf(ExpandableView expandableView) {
385 if (!(expandableView instanceof ExpandableNotificationRow)) {
386 return expandableView.isAboveShelf();
387 }
388 ExpandableNotificationRow row = (ExpandableNotificationRow) expandableView;
389 return row.isAboveShelf() && !isDozingAndNotPulsing(row);
390 }
391
392 /**
393 * @return whether a view is dozing and not pulsing right now
394 */
395 public boolean isDozingAndNotPulsing(ExpandableView view) {
396 if (view instanceof ExpandableNotificationRow) {
397 return isDozingAndNotPulsing((ExpandableNotificationRow) view);
398 }
399 return false;
400 }
401
402 /**
403 * @return whether a row is dozing and not pulsing right now
404 */
405 public boolean isDozingAndNotPulsing(ExpandableNotificationRow row) {
406 return isDark() && !isPulsing(row.getEntry());
407 }
Selim Cinek2627d722018-01-19 12:16:49 -0800408
409 public void setExpandAnimationTopChange(int expandAnimationTopChange) {
410 mExpandAnimationTopChange = expandAnimationTopChange;
411 }
412
413 public void setExpandingNotification(ExpandableNotificationRow row) {
414 mExpandingNotification = row;
415 }
416
417 public ExpandableNotificationRow getExpandingNotification() {
418 return mExpandingNotification;
419 }
420
421 public int getExpandAnimationTopChange() {
422 return mExpandAnimationTopChange;
423 }
Lucas Dupin16cfe452018-02-08 13:14:50 -0800424
425 /**
Lucas Dupin16cfe452018-02-08 13:14:50 -0800426 * @return {@code true } when shade is completely dark: in AOD or ambient display.
427 */
428 public boolean isFullyDark() {
Lucas Dupinb561eda2018-04-09 17:25:04 -0700429 return mDarkAmount == 1;
Lucas Dupin16cfe452018-02-08 13:14:50 -0800430 }
431
432 public void setDarkTopPadding(int darkTopPadding) {
433 mDarkTopPadding = darkTopPadding;
434 }
435
436 public int getDarkTopPadding() {
437 return mDarkTopPadding;
438 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200439}