blob: ebf4cda457e7aadae6f2606e968204c3590c90b7 [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;
Selim Cinekebf42342017-07-13 15:46:10 +020067 private Collection<HeadsUpManager.HeadsUpEntry> 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 Cinek281c2022016-10-13 19:14:43 -070071
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 Cinekdb167372016-11-17 15:41:17 -080082 mBaseZHeight = 4 * mZDistanceBetweenElements;
Selim Cinek281c2022016-10-13 19:14:43 -070083 }
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 Jaggid552d9d2014-05-07 19:41:13 +020098
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 Spurlockbf370992014-06-17 13:58:31 -0400127 /** 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 Jaggiae441282014-08-01 02:45:18 +0200132 public void setHideSensitive(boolean hideSensitive) {
133 mHideSensitive = hideSensitive;
134 }
135
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200136 /**
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 Cineka32ab602014-06-11 15:06:01 +0200140 public void setActivatedChild(ActivatableNotificationView activatedChild) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200141 mActivatedChild = activatedChild;
142 }
143
144 public boolean isDimmed() {
145 return mDimmed;
146 }
147
John Spurlockbf370992014-06-17 13:58:31 -0400148 public boolean isDark() {
149 return mDark;
150 }
151
Jorim Jaggiae441282014-08-01 02:45:18 +0200152 public boolean isHideSensitive() {
153 return mHideSensitive;
154 }
155
Selim Cineka32ab602014-06-11 15:06:01 +0200156 public ActivatableNotificationView getActivatedChild() {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200157 return mActivatedChild;
158 }
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200159
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 Cinekc27437b2014-05-14 10:23:33 +0200171
Selim Cinekdb167372016-11-17 15:41:17 -0800172 public int getSpeedBumpIndex() {
173 return mSpeedBumpIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200174 }
175
Selim Cinekdb167372016-11-17 15:41:17 -0800176 public void setSpeedBumpIndex(int shelfIndex) {
177 mSpeedBumpIndex = shelfIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200178 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700179
180 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
181 mHeadsUpManager = headsUpManager;
182 }
183
Selim Cineka59ecc32015-04-07 10:51:49 -0700184 public float getStackTranslation() {
185 return mStackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700186 }
187
Selim Cineka59ecc32015-04-07 10:51:49 -0700188 public void setStackTranslation(float stackTranslation) {
189 mStackTranslation = stackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700190 }
191
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700192 public void setLayoutHeight(int layoutHeight) {
193 mLayoutHeight = layoutHeight;
194 }
195
Selim Cineka59ecc32015-04-07 10:51:49 -0700196 public float getTopPadding() {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700197 return mTopPadding;
198 }
199
200 public void setTopPadding(int topPadding) {
201 mTopPadding = topPadding;
202 }
203
204 public int getInnerHeight() {
Selim Cinek91d4cba2016-11-10 19:59:48 -0800205 return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding, mLayoutMinHeight);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700206 }
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 Cineka59ecc32015-04-07 10:51:49 -0700223
Selim Cinek9c17b772015-07-07 20:37:09 -0700224 public void setDismissAllInProgress(boolean dismissAllInProgress) {
225 mDismissAllInProgress = dismissAllInProgress;
226 }
227
228 public boolean isDismissAllInProgress() {
229 return mDismissAllInProgress;
230 }
Selim Cinekbc243a92016-09-27 16:35:13 -0700231
232 public void setLayoutMinHeight(int layoutMinHeight) {
233 mLayoutMinHeight = layoutMinHeight;
234 }
Selim Cinek281c2022016-10-13 19:14:43 -0700235
236 public void setShelf(NotificationShelf shelf) {
237 mShelf = shelf;
238 }
239
Eliot Courtney5d3d2d02018-01-18 15:59:03 +0900240 @Nullable
Selim Cinek281c2022016-10-13 19:14:43 -0700241 public NotificationShelf getShelf() {
242 return mShelf;
243 }
Selim Cinek91d4cba2016-11-10 19:59:48 -0800244
245 public void setLayoutMaxHeight(int maxLayoutHeight) {
246 mMaxLayoutHeight = maxLayoutHeight;
247 }
Selim Cinekdb167372016-11-17 15:41:17 -0800248
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 Cinek727903c2016-12-06 17:28:10 -0800261
262 public void setCurrentScrollVelocity(float currentScrollVelocity) {
263 mCurrentScrollVelocity = currentScrollVelocity;
264 }
265
266 public float getCurrentScrollVelocity() {
267 return mCurrentScrollVelocity;
268 }
Selim Cinek355652a2016-12-07 13:32:12 -0800269
270 public boolean isOnKeyguard() {
271 return mStatusBarState == StatusBarState.KEYGUARD;
272 }
273
274 public void setStatusBarState(int statusBarState) {
275 mStatusBarState = statusBarState;
276 }
Selim Cinekd5ab6452016-12-08 16:34:00 -0800277
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 Cinekbe2c4432017-05-30 12:11:09 -0700298 public boolean hasPulsingNotifications() {
Selim Cinekebf42342017-07-13 15:46:10 +0200299 return mPulsing != null;
Adrian Roosd83e9992017-03-16 15:17:57 -0700300 }
301
Selim Cinekebf42342017-07-13 15:46:10 +0200302 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 Roosd83e9992017-03-16 15:17:57 -0700316 }
317
Selim Cinekd5ab6452016-12-08 16:34:00 -0800318 public boolean isPanelTracking() {
319 return mPanelTracking;
320 }
Selim Cinekfcff4c62016-12-27 14:26:06 +0100321
322 public boolean isPanelFullWidth() {
323 return mPanelFullWidth;
324 }
325
326 public void setPanelFullWidth(boolean panelFullWidth) {
327 mPanelFullWidth = panelFullWidth;
328 }
Selim Cinekec29d342017-05-05 18:31:49 -0700329
330 public void setUnlockHintRunning(boolean unlockHintRunning) {
331 mUnlockHintRunning = unlockHintRunning;
332 }
333
334 public boolean isUnlockHintRunning() {
335 return mUnlockHintRunning;
336 }
Selim Cinek5cf1d052017-06-01 17:36:46 -0700337
338 public boolean isQsCustomizerShowing() {
339 return mQsCustomizerShowing;
340 }
341
342 public void setQsCustomizerShowing(boolean qsCustomizerShowing) {
343 mQsCustomizerShowing = qsCustomizerShowing;
344 }
Selim Cinek1f624952017-06-08 19:11:50 -0700345
346 public void setIntrinsicPadding(int intrinsicPadding) {
347 mIntrinsicPadding = intrinsicPadding;
348 }
349
350 public int getIntrinsicPadding() {
351 return mIntrinsicPadding;
352 }
Selim Cinekebf42342017-07-13 15:46:10 +0200353
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 Jaggid552d9d2014-05-07 19:41:13 +0200383}