blob: ba1e7c2d86c522ed4d95b40a3cdd989b06b4f7a5 [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 Cinek281c2022016-10-13 19:14:43 -070024import com.android.systemui.statusbar.NotificationShelf;
Selim Cinek355652a2016-12-07 13:32:12 -080025import com.android.systemui.statusbar.StatusBarState;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070026import com.android.systemui.statusbar.policy.HeadsUpManager;
Jorim Jaggid552d9d2014-05-07 19:41:13 +020027
28import java.util.ArrayList;
29
30/**
31 * A global state to track all input states for the algorithm.
32 */
33public class AmbientState {
34 private ArrayList<View> mDraggedViews = new ArrayList<View>();
35 private int mScrollY;
36 private boolean mDimmed;
Selim Cineka32ab602014-06-11 15:06:01 +020037 private ActivatableNotificationView mActivatedChild;
Selim Cinek8d9ff9c2014-05-12 15:13:04 +020038 private float mOverScrollTopAmount;
39 private float mOverScrollBottomAmount;
Selim Cinekdb167372016-11-17 15:41:17 -080040 private int mSpeedBumpIndex = -1;
John Spurlockbf370992014-06-17 13:58:31 -040041 private boolean mDark;
Jorim Jaggiae441282014-08-01 02:45:18 +020042 private boolean mHideSensitive;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070043 private HeadsUpManager mHeadsUpManager;
Selim Cineka59ecc32015-04-07 10:51:49 -070044 private float mStackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070045 private int mLayoutHeight;
46 private int mTopPadding;
47 private boolean mShadeExpanded;
48 private float mMaxHeadsUpTranslation;
Selim Cinek9c17b772015-07-07 20:37:09 -070049 private boolean mDismissAllInProgress;
Selim Cinekbc243a92016-09-27 16:35:13 -070050 private int mLayoutMinHeight;
Selim Cinek281c2022016-10-13 19:14:43 -070051 private NotificationShelf mShelf;
52 private int mZDistanceBetweenElements;
53 private int mBaseZHeight;
Selim Cinek91d4cba2016-11-10 19:59:48 -080054 private int mMaxLayoutHeight;
Selim Cinekdb167372016-11-17 15:41:17 -080055 private ActivatableNotificationView mLastVisibleBackgroundChild;
Selim Cinek727903c2016-12-06 17:28:10 -080056 private float mCurrentScrollVelocity;
Selim Cinek355652a2016-12-07 13:32:12 -080057 private int mStatusBarState;
Selim Cinekd5ab6452016-12-08 16:34:00 -080058 private float mExpandingVelocity;
59 private boolean mPanelTracking;
60 private boolean mExpansionChanging;
Selim Cinekfcff4c62016-12-27 14:26:06 +010061 private boolean mPanelFullWidth;
Selim Cinekbe2c4432017-05-30 12:11:09 -070062 private boolean mHasPulsingNotifications;
Selim Cinekec29d342017-05-05 18:31:49 -070063 private boolean mUnlockHintRunning;
Selim Cinek5cf1d052017-06-01 17:36:46 -070064 private boolean mQsCustomizerShowing;
Selim Cinek1f624952017-06-08 19:11:50 -070065 private int mIntrinsicPadding;
Selim Cinek281c2022016-10-13 19:14:43 -070066
67 public AmbientState(Context context) {
68 reload(context);
69 }
70
71 /**
72 * Reload the dimens e.g. if the density changed.
73 */
74 public void reload(Context context) {
75 mZDistanceBetweenElements = Math.max(1, context.getResources()
76 .getDimensionPixelSize(R.dimen.z_distance_between_notifications));
Selim Cinekdb167372016-11-17 15:41:17 -080077 mBaseZHeight = 4 * mZDistanceBetweenElements;
Selim Cinek281c2022016-10-13 19:14:43 -070078 }
79
80 /**
81 * @return the basic Z height on which notifications remain.
82 */
83 public int getBaseZHeight() {
84 return mBaseZHeight;
85 }
86
87 /**
88 * @return the distance in Z between two overlaying notifications.
89 */
90 public int getZDistanceBetweenElements() {
91 return mZDistanceBetweenElements;
92 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +020093
94 public int getScrollY() {
95 return mScrollY;
96 }
97
98 public void setScrollY(int scrollY) {
99 this.mScrollY = scrollY;
100 }
101
102 public void onBeginDrag(View view) {
103 mDraggedViews.add(view);
104 }
105
106 public void onDragFinished(View view) {
107 mDraggedViews.remove(view);
108 }
109
110 public ArrayList<View> getDraggedViews() {
111 return mDraggedViews;
112 }
113
114 /**
115 * @param dimmed Whether we are in a dimmed state (on the lockscreen), where the backgrounds are
116 * translucent and everything is scaled back a bit.
117 */
118 public void setDimmed(boolean dimmed) {
119 mDimmed = dimmed;
120 }
121
John Spurlockbf370992014-06-17 13:58:31 -0400122 /** In dark mode, we draw as little as possible, assuming a black background */
123 public void setDark(boolean dark) {
124 mDark = dark;
125 }
126
Jorim Jaggiae441282014-08-01 02:45:18 +0200127 public void setHideSensitive(boolean hideSensitive) {
128 mHideSensitive = hideSensitive;
129 }
130
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200131 /**
132 * In dimmed mode, a child can be activated, which happens on the first tap of the double-tap
133 * interaction. This child is then scaled normally and its background is fully opaque.
134 */
Selim Cineka32ab602014-06-11 15:06:01 +0200135 public void setActivatedChild(ActivatableNotificationView activatedChild) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200136 mActivatedChild = activatedChild;
137 }
138
139 public boolean isDimmed() {
140 return mDimmed;
141 }
142
John Spurlockbf370992014-06-17 13:58:31 -0400143 public boolean isDark() {
144 return mDark;
145 }
146
Jorim Jaggiae441282014-08-01 02:45:18 +0200147 public boolean isHideSensitive() {
148 return mHideSensitive;
149 }
150
Selim Cineka32ab602014-06-11 15:06:01 +0200151 public ActivatableNotificationView getActivatedChild() {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200152 return mActivatedChild;
153 }
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200154
155 public void setOverScrollAmount(float amount, boolean onTop) {
156 if (onTop) {
157 mOverScrollTopAmount = amount;
158 } else {
159 mOverScrollBottomAmount = amount;
160 }
161 }
162
163 public float getOverScrollAmount(boolean top) {
164 return top ? mOverScrollTopAmount : mOverScrollBottomAmount;
165 }
Selim Cinekc27437b2014-05-14 10:23:33 +0200166
Selim Cinekdb167372016-11-17 15:41:17 -0800167 public int getSpeedBumpIndex() {
168 return mSpeedBumpIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200169 }
170
Selim Cinekdb167372016-11-17 15:41:17 -0800171 public void setSpeedBumpIndex(int shelfIndex) {
172 mSpeedBumpIndex = shelfIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200173 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700174
175 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
176 mHeadsUpManager = headsUpManager;
177 }
178
Selim Cineka59ecc32015-04-07 10:51:49 -0700179 public float getStackTranslation() {
180 return mStackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700181 }
182
Selim Cineka59ecc32015-04-07 10:51:49 -0700183 public void setStackTranslation(float stackTranslation) {
184 mStackTranslation = stackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700185 }
186
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700187 public void setLayoutHeight(int layoutHeight) {
188 mLayoutHeight = layoutHeight;
189 }
190
Selim Cineka59ecc32015-04-07 10:51:49 -0700191 public float getTopPadding() {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700192 return mTopPadding;
193 }
194
195 public void setTopPadding(int topPadding) {
196 mTopPadding = topPadding;
197 }
198
199 public int getInnerHeight() {
Selim Cinek91d4cba2016-11-10 19:59:48 -0800200 return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding, mLayoutMinHeight);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700201 }
202
203 public boolean isShadeExpanded() {
204 return mShadeExpanded;
205 }
206
207 public void setShadeExpanded(boolean shadeExpanded) {
208 mShadeExpanded = shadeExpanded;
209 }
210
211 public void setMaxHeadsUpTranslation(float maxHeadsUpTranslation) {
212 mMaxHeadsUpTranslation = maxHeadsUpTranslation;
213 }
214
215 public float getMaxHeadsUpTranslation() {
216 return mMaxHeadsUpTranslation;
217 }
Selim Cineka59ecc32015-04-07 10:51:49 -0700218
Selim Cinek9c17b772015-07-07 20:37:09 -0700219 public void setDismissAllInProgress(boolean dismissAllInProgress) {
220 mDismissAllInProgress = dismissAllInProgress;
221 }
222
223 public boolean isDismissAllInProgress() {
224 return mDismissAllInProgress;
225 }
Selim Cinekbc243a92016-09-27 16:35:13 -0700226
227 public void setLayoutMinHeight(int layoutMinHeight) {
228 mLayoutMinHeight = layoutMinHeight;
229 }
Selim Cinek281c2022016-10-13 19:14:43 -0700230
231 public void setShelf(NotificationShelf shelf) {
232 mShelf = shelf;
233 }
234
235 public NotificationShelf getShelf() {
236 return mShelf;
237 }
Selim Cinek91d4cba2016-11-10 19:59:48 -0800238
239 public void setLayoutMaxHeight(int maxLayoutHeight) {
240 mMaxLayoutHeight = maxLayoutHeight;
241 }
Selim Cinekdb167372016-11-17 15:41:17 -0800242
243 /**
244 * Sets the last visible view of the host layout, that has a background, i.e the very last
245 * view in the shade, without the clear all button.
246 */
247 public void setLastVisibleBackgroundChild(
248 ActivatableNotificationView lastVisibleBackgroundChild) {
249 mLastVisibleBackgroundChild = lastVisibleBackgroundChild;
250 }
251
252 public ActivatableNotificationView getLastVisibleBackgroundChild() {
253 return mLastVisibleBackgroundChild;
254 }
Selim Cinek727903c2016-12-06 17:28:10 -0800255
256 public void setCurrentScrollVelocity(float currentScrollVelocity) {
257 mCurrentScrollVelocity = currentScrollVelocity;
258 }
259
260 public float getCurrentScrollVelocity() {
261 return mCurrentScrollVelocity;
262 }
Selim Cinek355652a2016-12-07 13:32:12 -0800263
264 public boolean isOnKeyguard() {
265 return mStatusBarState == StatusBarState.KEYGUARD;
266 }
267
268 public void setStatusBarState(int statusBarState) {
269 mStatusBarState = statusBarState;
270 }
Selim Cinekd5ab6452016-12-08 16:34:00 -0800271
272 public void setExpandingVelocity(float expandingVelocity) {
273 mExpandingVelocity = expandingVelocity;
274 }
275
276 public void setExpansionChanging(boolean expansionChanging) {
277 mExpansionChanging = expansionChanging;
278 }
279
280 public boolean isExpansionChanging() {
281 return mExpansionChanging;
282 }
283
284 public float getExpandingVelocity() {
285 return mExpandingVelocity;
286 }
287
288 public void setPanelTracking(boolean panelTracking) {
289 mPanelTracking = panelTracking;
290 }
291
Selim Cinekbe2c4432017-05-30 12:11:09 -0700292 public boolean hasPulsingNotifications() {
293 return mHasPulsingNotifications;
Adrian Roosd83e9992017-03-16 15:17:57 -0700294 }
295
Selim Cinekbe2c4432017-05-30 12:11:09 -0700296 public void setHasPulsingNotifications(boolean hasPulsing) {
297 mHasPulsingNotifications = hasPulsing;
Adrian Roosd83e9992017-03-16 15:17:57 -0700298 }
299
Selim Cinekd5ab6452016-12-08 16:34:00 -0800300 public boolean isPanelTracking() {
301 return mPanelTracking;
302 }
Selim Cinekfcff4c62016-12-27 14:26:06 +0100303
304 public boolean isPanelFullWidth() {
305 return mPanelFullWidth;
306 }
307
308 public void setPanelFullWidth(boolean panelFullWidth) {
309 mPanelFullWidth = panelFullWidth;
310 }
Selim Cinekec29d342017-05-05 18:31:49 -0700311
312 public void setUnlockHintRunning(boolean unlockHintRunning) {
313 mUnlockHintRunning = unlockHintRunning;
314 }
315
316 public boolean isUnlockHintRunning() {
317 return mUnlockHintRunning;
318 }
Selim Cinek5cf1d052017-06-01 17:36:46 -0700319
320 public boolean isQsCustomizerShowing() {
321 return mQsCustomizerShowing;
322 }
323
324 public void setQsCustomizerShowing(boolean qsCustomizerShowing) {
325 mQsCustomizerShowing = qsCustomizerShowing;
326 }
Selim Cinek1f624952017-06-08 19:11:50 -0700327
328 public void setIntrinsicPadding(int intrinsicPadding) {
329 mIntrinsicPadding = intrinsicPadding;
330 }
331
332 public int getIntrinsicPadding() {
333 return mIntrinsicPadding;
334 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200335}