blob: 0f637fb5a40a3886c437b9bceec56d98b4e31df1 [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;
Selim Cinek281c2022016-10-13 19:14:43 -070073
74 public AmbientState(Context context) {
75 reload(context);
76 }
77
78 /**
79 * Reload the dimens e.g. if the density changed.
80 */
81 public void reload(Context context) {
Selim Cinek2627d722018-01-19 12:16:49 -080082 mZDistanceBetweenElements = getZDistanceBetweenElements(context);
83 mBaseZHeight = getBaseHeight(mZDistanceBetweenElements);
84 }
85
86 private static int getZDistanceBetweenElements(Context context) {
87 return Math.max(1, context.getResources()
Selim Cinek281c2022016-10-13 19:14:43 -070088 .getDimensionPixelSize(R.dimen.z_distance_between_notifications));
Selim Cinek2627d722018-01-19 12:16:49 -080089 }
90
91 private static int getBaseHeight(int zdistanceBetweenElements) {
92 return 4 * zdistanceBetweenElements;
93 }
94
95 /**
96 * @return the launch height for notifications that are launched
97 */
98 public static int getNotificationLaunchHeight(Context context) {
99 int zDistance = getZDistanceBetweenElements(context);
100 return getBaseHeight(zDistance) * 2;
Selim Cinek281c2022016-10-13 19:14:43 -0700101 }
102
103 /**
104 * @return the basic Z height on which notifications remain.
105 */
106 public int getBaseZHeight() {
107 return mBaseZHeight;
108 }
109
110 /**
111 * @return the distance in Z between two overlaying notifications.
112 */
113 public int getZDistanceBetweenElements() {
114 return mZDistanceBetweenElements;
115 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200116
117 public int getScrollY() {
118 return mScrollY;
119 }
120
121 public void setScrollY(int scrollY) {
122 this.mScrollY = scrollY;
123 }
124
125 public void onBeginDrag(View view) {
126 mDraggedViews.add(view);
127 }
128
129 public void onDragFinished(View view) {
130 mDraggedViews.remove(view);
131 }
132
133 public ArrayList<View> getDraggedViews() {
134 return mDraggedViews;
135 }
136
137 /**
138 * @param dimmed Whether we are in a dimmed state (on the lockscreen), where the backgrounds are
139 * translucent and everything is scaled back a bit.
140 */
141 public void setDimmed(boolean dimmed) {
142 mDimmed = dimmed;
143 }
144
John Spurlockbf370992014-06-17 13:58:31 -0400145 /** In dark mode, we draw as little as possible, assuming a black background */
146 public void setDark(boolean dark) {
147 mDark = dark;
148 }
149
Jorim Jaggiae441282014-08-01 02:45:18 +0200150 public void setHideSensitive(boolean hideSensitive) {
151 mHideSensitive = hideSensitive;
152 }
153
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200154 /**
155 * In dimmed mode, a child can be activated, which happens on the first tap of the double-tap
156 * interaction. This child is then scaled normally and its background is fully opaque.
157 */
Selim Cineka32ab602014-06-11 15:06:01 +0200158 public void setActivatedChild(ActivatableNotificationView activatedChild) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200159 mActivatedChild = activatedChild;
160 }
161
162 public boolean isDimmed() {
163 return mDimmed;
164 }
165
John Spurlockbf370992014-06-17 13:58:31 -0400166 public boolean isDark() {
167 return mDark;
168 }
169
Jorim Jaggiae441282014-08-01 02:45:18 +0200170 public boolean isHideSensitive() {
171 return mHideSensitive;
172 }
173
Selim Cineka32ab602014-06-11 15:06:01 +0200174 public ActivatableNotificationView getActivatedChild() {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200175 return mActivatedChild;
176 }
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200177
178 public void setOverScrollAmount(float amount, boolean onTop) {
179 if (onTop) {
180 mOverScrollTopAmount = amount;
181 } else {
182 mOverScrollBottomAmount = amount;
183 }
184 }
185
186 public float getOverScrollAmount(boolean top) {
187 return top ? mOverScrollTopAmount : mOverScrollBottomAmount;
188 }
Selim Cinekc27437b2014-05-14 10:23:33 +0200189
Selim Cinekdb167372016-11-17 15:41:17 -0800190 public int getSpeedBumpIndex() {
191 return mSpeedBumpIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200192 }
193
Selim Cinekdb167372016-11-17 15:41:17 -0800194 public void setSpeedBumpIndex(int shelfIndex) {
195 mSpeedBumpIndex = shelfIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200196 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700197
198 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
199 mHeadsUpManager = headsUpManager;
200 }
201
Selim Cineka59ecc32015-04-07 10:51:49 -0700202 public float getStackTranslation() {
203 return mStackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700204 }
205
Selim Cineka59ecc32015-04-07 10:51:49 -0700206 public void setStackTranslation(float stackTranslation) {
207 mStackTranslation = stackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700208 }
209
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700210 public void setLayoutHeight(int layoutHeight) {
211 mLayoutHeight = layoutHeight;
212 }
213
Selim Cineka59ecc32015-04-07 10:51:49 -0700214 public float getTopPadding() {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700215 return mTopPadding;
216 }
217
218 public void setTopPadding(int topPadding) {
219 mTopPadding = topPadding;
220 }
221
222 public int getInnerHeight() {
Selim Cinekc25989e2018-02-16 16:42:14 -0800223 return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding, mLayoutMinHeight);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700224 }
225
226 public boolean isShadeExpanded() {
227 return mShadeExpanded;
228 }
229
230 public void setShadeExpanded(boolean shadeExpanded) {
231 mShadeExpanded = shadeExpanded;
232 }
233
234 public void setMaxHeadsUpTranslation(float maxHeadsUpTranslation) {
235 mMaxHeadsUpTranslation = maxHeadsUpTranslation;
236 }
237
238 public float getMaxHeadsUpTranslation() {
239 return mMaxHeadsUpTranslation;
240 }
Selim Cineka59ecc32015-04-07 10:51:49 -0700241
Selim Cinek9c17b772015-07-07 20:37:09 -0700242 public void setDismissAllInProgress(boolean dismissAllInProgress) {
243 mDismissAllInProgress = dismissAllInProgress;
244 }
245
246 public boolean isDismissAllInProgress() {
247 return mDismissAllInProgress;
248 }
Selim Cinekbc243a92016-09-27 16:35:13 -0700249
250 public void setLayoutMinHeight(int layoutMinHeight) {
251 mLayoutMinHeight = layoutMinHeight;
252 }
Selim Cinek281c2022016-10-13 19:14:43 -0700253
254 public void setShelf(NotificationShelf shelf) {
255 mShelf = shelf;
256 }
257
Eliot Courtney5d3d2d02018-01-18 15:59:03 +0900258 @Nullable
Selim Cinek281c2022016-10-13 19:14:43 -0700259 public NotificationShelf getShelf() {
260 return mShelf;
261 }
Selim Cinek91d4cba2016-11-10 19:59:48 -0800262
263 public void setLayoutMaxHeight(int maxLayoutHeight) {
264 mMaxLayoutHeight = maxLayoutHeight;
265 }
Selim Cinekdb167372016-11-17 15:41:17 -0800266
267 /**
268 * Sets the last visible view of the host layout, that has a background, i.e the very last
269 * view in the shade, without the clear all button.
270 */
271 public void setLastVisibleBackgroundChild(
272 ActivatableNotificationView lastVisibleBackgroundChild) {
273 mLastVisibleBackgroundChild = lastVisibleBackgroundChild;
274 }
275
276 public ActivatableNotificationView getLastVisibleBackgroundChild() {
277 return mLastVisibleBackgroundChild;
278 }
Selim Cinek727903c2016-12-06 17:28:10 -0800279
280 public void setCurrentScrollVelocity(float currentScrollVelocity) {
281 mCurrentScrollVelocity = currentScrollVelocity;
282 }
283
284 public float getCurrentScrollVelocity() {
285 return mCurrentScrollVelocity;
286 }
Selim Cinek355652a2016-12-07 13:32:12 -0800287
288 public boolean isOnKeyguard() {
289 return mStatusBarState == StatusBarState.KEYGUARD;
290 }
291
292 public void setStatusBarState(int statusBarState) {
293 mStatusBarState = statusBarState;
294 }
Selim Cinekd5ab6452016-12-08 16:34:00 -0800295
296 public void setExpandingVelocity(float expandingVelocity) {
297 mExpandingVelocity = expandingVelocity;
298 }
299
300 public void setExpansionChanging(boolean expansionChanging) {
301 mExpansionChanging = expansionChanging;
302 }
303
304 public boolean isExpansionChanging() {
305 return mExpansionChanging;
306 }
307
308 public float getExpandingVelocity() {
309 return mExpandingVelocity;
310 }
311
312 public void setPanelTracking(boolean panelTracking) {
313 mPanelTracking = panelTracking;
314 }
315
Selim Cinekbe2c4432017-05-30 12:11:09 -0700316 public boolean hasPulsingNotifications() {
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900317 return mPulsing;
Adrian Roosd83e9992017-03-16 15:17:57 -0700318 }
319
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900320 public void setPulsing(boolean hasPulsing) {
Selim Cinekebf42342017-07-13 15:46:10 +0200321 mPulsing = hasPulsing;
322 }
323
324 public boolean isPulsing(NotificationData.Entry entry) {
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900325 if (!mPulsing || mHeadsUpManager == null) {
Selim Cinekebf42342017-07-13 15:46:10 +0200326 return false;
327 }
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900328 return mHeadsUpManager.getAllEntries().anyMatch(e -> (e == entry));
Adrian Roosd83e9992017-03-16 15:17:57 -0700329 }
330
Selim Cinekd5ab6452016-12-08 16:34:00 -0800331 public boolean isPanelTracking() {
332 return mPanelTracking;
333 }
Selim Cinekfcff4c62016-12-27 14:26:06 +0100334
335 public boolean isPanelFullWidth() {
336 return mPanelFullWidth;
337 }
338
339 public void setPanelFullWidth(boolean panelFullWidth) {
340 mPanelFullWidth = panelFullWidth;
341 }
Selim Cinekec29d342017-05-05 18:31:49 -0700342
343 public void setUnlockHintRunning(boolean unlockHintRunning) {
344 mUnlockHintRunning = unlockHintRunning;
345 }
346
347 public boolean isUnlockHintRunning() {
348 return mUnlockHintRunning;
349 }
Selim Cinek5cf1d052017-06-01 17:36:46 -0700350
351 public boolean isQsCustomizerShowing() {
352 return mQsCustomizerShowing;
353 }
354
355 public void setQsCustomizerShowing(boolean qsCustomizerShowing) {
356 mQsCustomizerShowing = qsCustomizerShowing;
357 }
Selim Cinek1f624952017-06-08 19:11:50 -0700358
359 public void setIntrinsicPadding(int intrinsicPadding) {
360 mIntrinsicPadding = intrinsicPadding;
361 }
362
363 public int getIntrinsicPadding() {
364 return mIntrinsicPadding;
365 }
Selim Cinekebf42342017-07-13 15:46:10 +0200366
367 /**
368 * Similar to the normal is above shelf logic but doesn't allow it to be above in AOD1.
369 *
370 * @param expandableView the view to check
371 */
372 public boolean isAboveShelf(ExpandableView expandableView) {
373 if (!(expandableView instanceof ExpandableNotificationRow)) {
374 return expandableView.isAboveShelf();
375 }
376 ExpandableNotificationRow row = (ExpandableNotificationRow) expandableView;
377 return row.isAboveShelf() && !isDozingAndNotPulsing(row);
378 }
379
380 /**
381 * @return whether a view is dozing and not pulsing right now
382 */
383 public boolean isDozingAndNotPulsing(ExpandableView view) {
384 if (view instanceof ExpandableNotificationRow) {
385 return isDozingAndNotPulsing((ExpandableNotificationRow) view);
386 }
387 return false;
388 }
389
390 /**
391 * @return whether a row is dozing and not pulsing right now
392 */
393 public boolean isDozingAndNotPulsing(ExpandableNotificationRow row) {
394 return isDark() && !isPulsing(row.getEntry());
395 }
Selim Cinek2627d722018-01-19 12:16:49 -0800396
397 public void setExpandAnimationTopChange(int expandAnimationTopChange) {
398 mExpandAnimationTopChange = expandAnimationTopChange;
399 }
400
401 public void setExpandingNotification(ExpandableNotificationRow row) {
402 mExpandingNotification = row;
403 }
404
405 public ExpandableNotificationRow getExpandingNotification() {
406 return mExpandingNotification;
407 }
408
409 public int getExpandAnimationTopChange() {
410 return mExpandAnimationTopChange;
411 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200412}