blob: 4d8da441c039530872d760e623ddc13fbefafb9c [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
Selim Cinek281c2022016-10-13 19:14:43 -070019import android.content.Context;
Jorim Jaggid552d9d2014-05-07 19:41:13 +020020import android.view.View;
Selim Cineka59ecc32015-04-07 10:51:49 -070021
Selim Cinek281c2022016-10-13 19:14:43 -070022import com.android.systemui.R;
Selim Cineka32ab602014-06-11 15:06:01 +020023import com.android.systemui.statusbar.ActivatableNotificationView;
Selim Cinekebf42342017-07-13 15:46:10 +020024import com.android.systemui.statusbar.ExpandableNotificationRow;
25import com.android.systemui.statusbar.ExpandableView;
26import com.android.systemui.statusbar.NotificationData;
Selim Cinek281c2022016-10-13 19:14:43 -070027import com.android.systemui.statusbar.NotificationShelf;
Selim Cinek355652a2016-12-07 13:32:12 -080028import com.android.systemui.statusbar.StatusBarState;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070029import com.android.systemui.statusbar.policy.HeadsUpManager;
Jorim Jaggid552d9d2014-05-07 19:41:13 +020030
31import java.util.ArrayList;
Selim Cinekebf42342017-07-13 15:46:10 +020032import java.util.Collection;
Jorim Jaggid552d9d2014-05-07 19:41:13 +020033
34/**
35 * A global state to track all input states for the algorithm.
36 */
37public class AmbientState {
38 private ArrayList<View> mDraggedViews = new ArrayList<View>();
39 private int mScrollY;
40 private boolean mDimmed;
Selim Cineka32ab602014-06-11 15:06:01 +020041 private ActivatableNotificationView mActivatedChild;
Selim Cinek8d9ff9c2014-05-12 15:13:04 +020042 private float mOverScrollTopAmount;
43 private float mOverScrollBottomAmount;
Selim Cinekdb167372016-11-17 15:41:17 -080044 private int mSpeedBumpIndex = -1;
John Spurlockbf370992014-06-17 13:58:31 -040045 private boolean mDark;
Jorim Jaggiae441282014-08-01 02:45:18 +020046 private boolean mHideSensitive;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070047 private HeadsUpManager mHeadsUpManager;
Selim Cineka59ecc32015-04-07 10:51:49 -070048 private float mStackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070049 private int mLayoutHeight;
50 private int mTopPadding;
51 private boolean mShadeExpanded;
52 private float mMaxHeadsUpTranslation;
Selim Cinek9c17b772015-07-07 20:37:09 -070053 private boolean mDismissAllInProgress;
Selim Cinekbc243a92016-09-27 16:35:13 -070054 private int mLayoutMinHeight;
Selim Cinek281c2022016-10-13 19:14:43 -070055 private NotificationShelf mShelf;
56 private int mZDistanceBetweenElements;
57 private int mBaseZHeight;
Selim Cinek91d4cba2016-11-10 19:59:48 -080058 private int mMaxLayoutHeight;
Selim Cinekdb167372016-11-17 15:41:17 -080059 private ActivatableNotificationView mLastVisibleBackgroundChild;
Selim Cinek727903c2016-12-06 17:28:10 -080060 private float mCurrentScrollVelocity;
Selim Cinek355652a2016-12-07 13:32:12 -080061 private int mStatusBarState;
Selim Cinekd5ab6452016-12-08 16:34:00 -080062 private float mExpandingVelocity;
63 private boolean mPanelTracking;
64 private boolean mExpansionChanging;
Selim Cinekfcff4c62016-12-27 14:26:06 +010065 private boolean mPanelFullWidth;
Selim Cinekebf42342017-07-13 15:46:10 +020066 private Collection<HeadsUpManager.HeadsUpEntry> mPulsing;
Selim Cinekec29d342017-05-05 18:31:49 -070067 private boolean mUnlockHintRunning;
Selim Cinek5cf1d052017-06-01 17:36:46 -070068 private boolean mQsCustomizerShowing;
Selim Cinek1f624952017-06-08 19:11:50 -070069 private int mIntrinsicPadding;
Selim Cinek281c2022016-10-13 19:14:43 -070070
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 Cinekdb167372016-11-17 15:41:17 -080081 mBaseZHeight = 4 * mZDistanceBetweenElements;
Selim Cinek281c2022016-10-13 19:14:43 -070082 }
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 Jaggid552d9d2014-05-07 19:41:13 +020097
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 Spurlockbf370992014-06-17 13:58:31 -0400126 /** 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 Jaggiae441282014-08-01 02:45:18 +0200131 public void setHideSensitive(boolean hideSensitive) {
132 mHideSensitive = hideSensitive;
133 }
134
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200135 /**
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 Cineka32ab602014-06-11 15:06:01 +0200139 public void setActivatedChild(ActivatableNotificationView activatedChild) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200140 mActivatedChild = activatedChild;
141 }
142
143 public boolean isDimmed() {
144 return mDimmed;
145 }
146
John Spurlockbf370992014-06-17 13:58:31 -0400147 public boolean isDark() {
148 return mDark;
149 }
150
Jorim Jaggiae441282014-08-01 02:45:18 +0200151 public boolean isHideSensitive() {
152 return mHideSensitive;
153 }
154
Selim Cineka32ab602014-06-11 15:06:01 +0200155 public ActivatableNotificationView getActivatedChild() {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200156 return mActivatedChild;
157 }
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200158
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 Cinekc27437b2014-05-14 10:23:33 +0200170
Selim Cinekdb167372016-11-17 15:41:17 -0800171 public int getSpeedBumpIndex() {
172 return mSpeedBumpIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200173 }
174
Selim Cinekdb167372016-11-17 15:41:17 -0800175 public void setSpeedBumpIndex(int shelfIndex) {
176 mSpeedBumpIndex = shelfIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200177 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700178
179 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
180 mHeadsUpManager = headsUpManager;
181 }
182
Selim Cineka59ecc32015-04-07 10:51:49 -0700183 public float getStackTranslation() {
184 return mStackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700185 }
186
Selim Cineka59ecc32015-04-07 10:51:49 -0700187 public void setStackTranslation(float stackTranslation) {
188 mStackTranslation = stackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700189 }
190
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700191 public void setLayoutHeight(int layoutHeight) {
192 mLayoutHeight = layoutHeight;
193 }
194
Selim Cineka59ecc32015-04-07 10:51:49 -0700195 public float getTopPadding() {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700196 return mTopPadding;
197 }
198
199 public void setTopPadding(int topPadding) {
200 mTopPadding = topPadding;
201 }
202
203 public int getInnerHeight() {
Selim Cinek91d4cba2016-11-10 19:59:48 -0800204 return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding, mLayoutMinHeight);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700205 }
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 Cineka59ecc32015-04-07 10:51:49 -0700222
Selim Cinek9c17b772015-07-07 20:37:09 -0700223 public void setDismissAllInProgress(boolean dismissAllInProgress) {
224 mDismissAllInProgress = dismissAllInProgress;
225 }
226
227 public boolean isDismissAllInProgress() {
228 return mDismissAllInProgress;
229 }
Selim Cinekbc243a92016-09-27 16:35:13 -0700230
231 public void setLayoutMinHeight(int layoutMinHeight) {
232 mLayoutMinHeight = layoutMinHeight;
233 }
Selim Cinek281c2022016-10-13 19:14:43 -0700234
235 public void setShelf(NotificationShelf shelf) {
236 mShelf = shelf;
237 }
238
239 public NotificationShelf getShelf() {
240 return mShelf;
241 }
Selim Cinek91d4cba2016-11-10 19:59:48 -0800242
243 public void setLayoutMaxHeight(int maxLayoutHeight) {
244 mMaxLayoutHeight = maxLayoutHeight;
245 }
Selim Cinekdb167372016-11-17 15:41:17 -0800246
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 Cinek727903c2016-12-06 17:28:10 -0800259
260 public void setCurrentScrollVelocity(float currentScrollVelocity) {
261 mCurrentScrollVelocity = currentScrollVelocity;
262 }
263
264 public float getCurrentScrollVelocity() {
265 return mCurrentScrollVelocity;
266 }
Selim Cinek355652a2016-12-07 13:32:12 -0800267
268 public boolean isOnKeyguard() {
269 return mStatusBarState == StatusBarState.KEYGUARD;
270 }
271
272 public void setStatusBarState(int statusBarState) {
273 mStatusBarState = statusBarState;
274 }
Selim Cinekd5ab6452016-12-08 16:34:00 -0800275
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 Cinekbe2c4432017-05-30 12:11:09 -0700296 public boolean hasPulsingNotifications() {
Selim Cinekebf42342017-07-13 15:46:10 +0200297 return mPulsing != null;
Adrian Roosd83e9992017-03-16 15:17:57 -0700298 }
299
Selim Cinekebf42342017-07-13 15:46:10 +0200300 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 Roosd83e9992017-03-16 15:17:57 -0700314 }
315
Selim Cinekd5ab6452016-12-08 16:34:00 -0800316 public boolean isPanelTracking() {
317 return mPanelTracking;
318 }
Selim Cinekfcff4c62016-12-27 14:26:06 +0100319
320 public boolean isPanelFullWidth() {
321 return mPanelFullWidth;
322 }
323
324 public void setPanelFullWidth(boolean panelFullWidth) {
325 mPanelFullWidth = panelFullWidth;
326 }
Selim Cinekec29d342017-05-05 18:31:49 -0700327
328 public void setUnlockHintRunning(boolean unlockHintRunning) {
329 mUnlockHintRunning = unlockHintRunning;
330 }
331
332 public boolean isUnlockHintRunning() {
333 return mUnlockHintRunning;
334 }
Selim Cinek5cf1d052017-06-01 17:36:46 -0700335
336 public boolean isQsCustomizerShowing() {
337 return mQsCustomizerShowing;
338 }
339
340 public void setQsCustomizerShowing(boolean qsCustomizerShowing) {
341 mQsCustomizerShowing = qsCustomizerShowing;
342 }
Selim Cinek1f624952017-06-08 19:11:50 -0700343
344 public void setIntrinsicPadding(int intrinsicPadding) {
345 mIntrinsicPadding = intrinsicPadding;
346 }
347
348 public int getIntrinsicPadding() {
349 return mIntrinsicPadding;
350 }
Selim Cinekebf42342017-07-13 15:46:10 +0200351
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 Jaggid552d9d2014-05-07 19:41:13 +0200381}