blob: 7c1c566a57bf365aa0aee8e1a0e6db4fed808658 [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 boolean mFullyDark;
74 private int mDarkTopPadding;
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
Jorim Jaggiae441282014-08-01 02:45:18 +0200152 public void setHideSensitive(boolean hideSensitive) {
153 mHideSensitive = hideSensitive;
154 }
155
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200156 /**
157 * In dimmed mode, a child can be activated, which happens on the first tap of the double-tap
158 * interaction. This child is then scaled normally and its background is fully opaque.
159 */
Selim Cineka32ab602014-06-11 15:06:01 +0200160 public void setActivatedChild(ActivatableNotificationView activatedChild) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200161 mActivatedChild = activatedChild;
162 }
163
164 public boolean isDimmed() {
165 return mDimmed;
166 }
167
John Spurlockbf370992014-06-17 13:58:31 -0400168 public boolean isDark() {
169 return mDark;
170 }
171
Jorim Jaggiae441282014-08-01 02:45:18 +0200172 public boolean isHideSensitive() {
173 return mHideSensitive;
174 }
175
Selim Cineka32ab602014-06-11 15:06:01 +0200176 public ActivatableNotificationView getActivatedChild() {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200177 return mActivatedChild;
178 }
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200179
180 public void setOverScrollAmount(float amount, boolean onTop) {
181 if (onTop) {
182 mOverScrollTopAmount = amount;
183 } else {
184 mOverScrollBottomAmount = amount;
185 }
186 }
187
188 public float getOverScrollAmount(boolean top) {
189 return top ? mOverScrollTopAmount : mOverScrollBottomAmount;
190 }
Selim Cinekc27437b2014-05-14 10:23:33 +0200191
Selim Cinekdb167372016-11-17 15:41:17 -0800192 public int getSpeedBumpIndex() {
193 return mSpeedBumpIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200194 }
195
Selim Cinekdb167372016-11-17 15:41:17 -0800196 public void setSpeedBumpIndex(int shelfIndex) {
197 mSpeedBumpIndex = shelfIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200198 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700199
200 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
201 mHeadsUpManager = headsUpManager;
202 }
203
Selim Cineka59ecc32015-04-07 10:51:49 -0700204 public float getStackTranslation() {
205 return mStackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700206 }
207
Selim Cineka59ecc32015-04-07 10:51:49 -0700208 public void setStackTranslation(float stackTranslation) {
209 mStackTranslation = stackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700210 }
211
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700212 public void setLayoutHeight(int layoutHeight) {
213 mLayoutHeight = layoutHeight;
214 }
215
Selim Cineka59ecc32015-04-07 10:51:49 -0700216 public float getTopPadding() {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700217 return mTopPadding;
218 }
219
220 public void setTopPadding(int topPadding) {
221 mTopPadding = topPadding;
222 }
223
224 public int getInnerHeight() {
Selim Cinekc25989e2018-02-16 16:42:14 -0800225 return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding, mLayoutMinHeight);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700226 }
227
228 public boolean isShadeExpanded() {
229 return mShadeExpanded;
230 }
231
232 public void setShadeExpanded(boolean shadeExpanded) {
233 mShadeExpanded = shadeExpanded;
234 }
235
236 public void setMaxHeadsUpTranslation(float maxHeadsUpTranslation) {
237 mMaxHeadsUpTranslation = maxHeadsUpTranslation;
238 }
239
240 public float getMaxHeadsUpTranslation() {
241 return mMaxHeadsUpTranslation;
242 }
Selim Cineka59ecc32015-04-07 10:51:49 -0700243
Selim Cinek9c17b772015-07-07 20:37:09 -0700244 public void setDismissAllInProgress(boolean dismissAllInProgress) {
245 mDismissAllInProgress = dismissAllInProgress;
246 }
247
248 public boolean isDismissAllInProgress() {
249 return mDismissAllInProgress;
250 }
Selim Cinekbc243a92016-09-27 16:35:13 -0700251
252 public void setLayoutMinHeight(int layoutMinHeight) {
253 mLayoutMinHeight = layoutMinHeight;
254 }
Selim Cinek281c2022016-10-13 19:14:43 -0700255
256 public void setShelf(NotificationShelf shelf) {
257 mShelf = shelf;
258 }
259
Eliot Courtney5d3d2d02018-01-18 15:59:03 +0900260 @Nullable
Selim Cinek281c2022016-10-13 19:14:43 -0700261 public NotificationShelf getShelf() {
262 return mShelf;
263 }
Selim Cinek91d4cba2016-11-10 19:59:48 -0800264
265 public void setLayoutMaxHeight(int maxLayoutHeight) {
266 mMaxLayoutHeight = maxLayoutHeight;
267 }
Selim Cinekdb167372016-11-17 15:41:17 -0800268
269 /**
270 * Sets the last visible view of the host layout, that has a background, i.e the very last
271 * view in the shade, without the clear all button.
272 */
273 public void setLastVisibleBackgroundChild(
274 ActivatableNotificationView lastVisibleBackgroundChild) {
275 mLastVisibleBackgroundChild = lastVisibleBackgroundChild;
276 }
277
278 public ActivatableNotificationView getLastVisibleBackgroundChild() {
279 return mLastVisibleBackgroundChild;
280 }
Selim Cinek727903c2016-12-06 17:28:10 -0800281
282 public void setCurrentScrollVelocity(float currentScrollVelocity) {
283 mCurrentScrollVelocity = currentScrollVelocity;
284 }
285
286 public float getCurrentScrollVelocity() {
287 return mCurrentScrollVelocity;
288 }
Selim Cinek355652a2016-12-07 13:32:12 -0800289
290 public boolean isOnKeyguard() {
291 return mStatusBarState == StatusBarState.KEYGUARD;
292 }
293
294 public void setStatusBarState(int statusBarState) {
295 mStatusBarState = statusBarState;
296 }
Selim Cinekd5ab6452016-12-08 16:34:00 -0800297
298 public void setExpandingVelocity(float expandingVelocity) {
299 mExpandingVelocity = expandingVelocity;
300 }
301
302 public void setExpansionChanging(boolean expansionChanging) {
303 mExpansionChanging = expansionChanging;
304 }
305
306 public boolean isExpansionChanging() {
307 return mExpansionChanging;
308 }
309
310 public float getExpandingVelocity() {
311 return mExpandingVelocity;
312 }
313
314 public void setPanelTracking(boolean panelTracking) {
315 mPanelTracking = panelTracking;
316 }
317
Selim Cinekbe2c4432017-05-30 12:11:09 -0700318 public boolean hasPulsingNotifications() {
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900319 return mPulsing;
Adrian Roosd83e9992017-03-16 15:17:57 -0700320 }
321
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900322 public void setPulsing(boolean hasPulsing) {
Selim Cinekebf42342017-07-13 15:46:10 +0200323 mPulsing = hasPulsing;
324 }
325
326 public boolean isPulsing(NotificationData.Entry entry) {
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900327 if (!mPulsing || mHeadsUpManager == null) {
Selim Cinekebf42342017-07-13 15:46:10 +0200328 return false;
329 }
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900330 return mHeadsUpManager.getAllEntries().anyMatch(e -> (e == entry));
Adrian Roosd83e9992017-03-16 15:17:57 -0700331 }
332
Selim Cinekd5ab6452016-12-08 16:34:00 -0800333 public boolean isPanelTracking() {
334 return mPanelTracking;
335 }
Selim Cinekfcff4c62016-12-27 14:26:06 +0100336
337 public boolean isPanelFullWidth() {
338 return mPanelFullWidth;
339 }
340
341 public void setPanelFullWidth(boolean panelFullWidth) {
342 mPanelFullWidth = panelFullWidth;
343 }
Selim Cinekec29d342017-05-05 18:31:49 -0700344
345 public void setUnlockHintRunning(boolean unlockHintRunning) {
346 mUnlockHintRunning = unlockHintRunning;
347 }
348
349 public boolean isUnlockHintRunning() {
350 return mUnlockHintRunning;
351 }
Selim Cinek5cf1d052017-06-01 17:36:46 -0700352
353 public boolean isQsCustomizerShowing() {
354 return mQsCustomizerShowing;
355 }
356
357 public void setQsCustomizerShowing(boolean qsCustomizerShowing) {
358 mQsCustomizerShowing = qsCustomizerShowing;
359 }
Selim Cinek1f624952017-06-08 19:11:50 -0700360
361 public void setIntrinsicPadding(int intrinsicPadding) {
362 mIntrinsicPadding = intrinsicPadding;
363 }
364
365 public int getIntrinsicPadding() {
366 return mIntrinsicPadding;
367 }
Selim Cinekebf42342017-07-13 15:46:10 +0200368
369 /**
370 * Similar to the normal is above shelf logic but doesn't allow it to be above in AOD1.
371 *
372 * @param expandableView the view to check
373 */
374 public boolean isAboveShelf(ExpandableView expandableView) {
375 if (!(expandableView instanceof ExpandableNotificationRow)) {
376 return expandableView.isAboveShelf();
377 }
378 ExpandableNotificationRow row = (ExpandableNotificationRow) expandableView;
379 return row.isAboveShelf() && !isDozingAndNotPulsing(row);
380 }
381
382 /**
383 * @return whether a view is dozing and not pulsing right now
384 */
385 public boolean isDozingAndNotPulsing(ExpandableView view) {
386 if (view instanceof ExpandableNotificationRow) {
387 return isDozingAndNotPulsing((ExpandableNotificationRow) view);
388 }
389 return false;
390 }
391
392 /**
393 * @return whether a row is dozing and not pulsing right now
394 */
395 public boolean isDozingAndNotPulsing(ExpandableNotificationRow row) {
396 return isDark() && !isPulsing(row.getEntry());
397 }
Selim Cinek2627d722018-01-19 12:16:49 -0800398
399 public void setExpandAnimationTopChange(int expandAnimationTopChange) {
400 mExpandAnimationTopChange = expandAnimationTopChange;
401 }
402
403 public void setExpandingNotification(ExpandableNotificationRow row) {
404 mExpandingNotification = row;
405 }
406
407 public ExpandableNotificationRow getExpandingNotification() {
408 return mExpandingNotification;
409 }
410
411 public int getExpandAnimationTopChange() {
412 return mExpandAnimationTopChange;
413 }
Lucas Dupin16cfe452018-02-08 13:14:50 -0800414
415 /**
416 * {@see isFullyDark}
417 */
418 public void setFullyDark(boolean fullyDark) {
419 mFullyDark = fullyDark;
420 }
421
422 /**
423 * @return {@code true } when shade is completely dark: in AOD or ambient display.
424 */
425 public boolean isFullyDark() {
426 return mFullyDark;
427 }
428
429 public void setDarkTopPadding(int darkTopPadding) {
430 mDarkTopPadding = darkTopPadding;
431 }
432
433 public int getDarkTopPadding() {
434 return mDarkTopPadding;
435 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200436}