blob: d7a810eca02ed55da1083b14864dedd03d6fe781 [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 Cinek2627d722018-01-19 12:16:49 -0800223 return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding
224 - mExpandAnimationTopChange, mLayoutMinHeight);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700225 }
226
227 public boolean isShadeExpanded() {
228 return mShadeExpanded;
229 }
230
231 public void setShadeExpanded(boolean shadeExpanded) {
232 mShadeExpanded = shadeExpanded;
233 }
234
235 public void setMaxHeadsUpTranslation(float maxHeadsUpTranslation) {
236 mMaxHeadsUpTranslation = maxHeadsUpTranslation;
237 }
238
239 public float getMaxHeadsUpTranslation() {
240 return mMaxHeadsUpTranslation;
241 }
Selim Cineka59ecc32015-04-07 10:51:49 -0700242
Selim Cinek9c17b772015-07-07 20:37:09 -0700243 public void setDismissAllInProgress(boolean dismissAllInProgress) {
244 mDismissAllInProgress = dismissAllInProgress;
245 }
246
247 public boolean isDismissAllInProgress() {
248 return mDismissAllInProgress;
249 }
Selim Cinekbc243a92016-09-27 16:35:13 -0700250
251 public void setLayoutMinHeight(int layoutMinHeight) {
252 mLayoutMinHeight = layoutMinHeight;
253 }
Selim Cinek281c2022016-10-13 19:14:43 -0700254
255 public void setShelf(NotificationShelf shelf) {
256 mShelf = shelf;
257 }
258
Eliot Courtney5d3d2d02018-01-18 15:59:03 +0900259 @Nullable
Selim Cinek281c2022016-10-13 19:14:43 -0700260 public NotificationShelf getShelf() {
261 return mShelf;
262 }
Selim Cinek91d4cba2016-11-10 19:59:48 -0800263
264 public void setLayoutMaxHeight(int maxLayoutHeight) {
265 mMaxLayoutHeight = maxLayoutHeight;
266 }
Selim Cinekdb167372016-11-17 15:41:17 -0800267
268 /**
269 * Sets the last visible view of the host layout, that has a background, i.e the very last
270 * view in the shade, without the clear all button.
271 */
272 public void setLastVisibleBackgroundChild(
273 ActivatableNotificationView lastVisibleBackgroundChild) {
274 mLastVisibleBackgroundChild = lastVisibleBackgroundChild;
275 }
276
277 public ActivatableNotificationView getLastVisibleBackgroundChild() {
278 return mLastVisibleBackgroundChild;
279 }
Selim Cinek727903c2016-12-06 17:28:10 -0800280
281 public void setCurrentScrollVelocity(float currentScrollVelocity) {
282 mCurrentScrollVelocity = currentScrollVelocity;
283 }
284
285 public float getCurrentScrollVelocity() {
286 return mCurrentScrollVelocity;
287 }
Selim Cinek355652a2016-12-07 13:32:12 -0800288
289 public boolean isOnKeyguard() {
290 return mStatusBarState == StatusBarState.KEYGUARD;
291 }
292
293 public void setStatusBarState(int statusBarState) {
294 mStatusBarState = statusBarState;
295 }
Selim Cinekd5ab6452016-12-08 16:34:00 -0800296
297 public void setExpandingVelocity(float expandingVelocity) {
298 mExpandingVelocity = expandingVelocity;
299 }
300
301 public void setExpansionChanging(boolean expansionChanging) {
302 mExpansionChanging = expansionChanging;
303 }
304
305 public boolean isExpansionChanging() {
306 return mExpansionChanging;
307 }
308
309 public float getExpandingVelocity() {
310 return mExpandingVelocity;
311 }
312
313 public void setPanelTracking(boolean panelTracking) {
314 mPanelTracking = panelTracking;
315 }
316
Selim Cinekbe2c4432017-05-30 12:11:09 -0700317 public boolean hasPulsingNotifications() {
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900318 return mPulsing;
Adrian Roosd83e9992017-03-16 15:17:57 -0700319 }
320
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900321 public void setPulsing(boolean hasPulsing) {
Selim Cinekebf42342017-07-13 15:46:10 +0200322 mPulsing = hasPulsing;
323 }
324
325 public boolean isPulsing(NotificationData.Entry entry) {
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900326 if (!mPulsing || mHeadsUpManager == null) {
Selim Cinekebf42342017-07-13 15:46:10 +0200327 return false;
328 }
yoshiki iguchi4e30e762018-02-06 12:09:23 +0900329 return mHeadsUpManager.getAllEntries().anyMatch(e -> (e == entry));
Adrian Roosd83e9992017-03-16 15:17:57 -0700330 }
331
Selim Cinekd5ab6452016-12-08 16:34:00 -0800332 public boolean isPanelTracking() {
333 return mPanelTracking;
334 }
Selim Cinekfcff4c62016-12-27 14:26:06 +0100335
336 public boolean isPanelFullWidth() {
337 return mPanelFullWidth;
338 }
339
340 public void setPanelFullWidth(boolean panelFullWidth) {
341 mPanelFullWidth = panelFullWidth;
342 }
Selim Cinekec29d342017-05-05 18:31:49 -0700343
344 public void setUnlockHintRunning(boolean unlockHintRunning) {
345 mUnlockHintRunning = unlockHintRunning;
346 }
347
348 public boolean isUnlockHintRunning() {
349 return mUnlockHintRunning;
350 }
Selim Cinek5cf1d052017-06-01 17:36:46 -0700351
352 public boolean isQsCustomizerShowing() {
353 return mQsCustomizerShowing;
354 }
355
356 public void setQsCustomizerShowing(boolean qsCustomizerShowing) {
357 mQsCustomizerShowing = qsCustomizerShowing;
358 }
Selim Cinek1f624952017-06-08 19:11:50 -0700359
360 public void setIntrinsicPadding(int intrinsicPadding) {
361 mIntrinsicPadding = intrinsicPadding;
362 }
363
364 public int getIntrinsicPadding() {
365 return mIntrinsicPadding;
366 }
Selim Cinekebf42342017-07-13 15:46:10 +0200367
368 /**
369 * Similar to the normal is above shelf logic but doesn't allow it to be above in AOD1.
370 *
371 * @param expandableView the view to check
372 */
373 public boolean isAboveShelf(ExpandableView expandableView) {
374 if (!(expandableView instanceof ExpandableNotificationRow)) {
375 return expandableView.isAboveShelf();
376 }
377 ExpandableNotificationRow row = (ExpandableNotificationRow) expandableView;
378 return row.isAboveShelf() && !isDozingAndNotPulsing(row);
379 }
380
381 /**
382 * @return whether a view is dozing and not pulsing right now
383 */
384 public boolean isDozingAndNotPulsing(ExpandableView view) {
385 if (view instanceof ExpandableNotificationRow) {
386 return isDozingAndNotPulsing((ExpandableNotificationRow) view);
387 }
388 return false;
389 }
390
391 /**
392 * @return whether a row is dozing and not pulsing right now
393 */
394 public boolean isDozingAndNotPulsing(ExpandableNotificationRow row) {
395 return isDark() && !isPulsing(row.getEntry());
396 }
Selim Cinek2627d722018-01-19 12:16:49 -0800397
398 public void setExpandAnimationTopChange(int expandAnimationTopChange) {
399 mExpandAnimationTopChange = expandAnimationTopChange;
400 }
401
402 public void setExpandingNotification(ExpandableNotificationRow row) {
403 mExpandingNotification = row;
404 }
405
406 public ExpandableNotificationRow getExpandingNotification() {
407 return mExpandingNotification;
408 }
409
410 public int getExpandAnimationTopChange() {
411 return mExpandAnimationTopChange;
412 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200413}