blob: b7b991e36710da6058806ca8a9c9633d62c85d50 [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 Cinek281c2022016-10-13 19:14:43 -070065
66 public AmbientState(Context context) {
67 reload(context);
68 }
69
70 /**
71 * Reload the dimens e.g. if the density changed.
72 */
73 public void reload(Context context) {
74 mZDistanceBetweenElements = Math.max(1, context.getResources()
75 .getDimensionPixelSize(R.dimen.z_distance_between_notifications));
Selim Cinekdb167372016-11-17 15:41:17 -080076 mBaseZHeight = 4 * mZDistanceBetweenElements;
Selim Cinek281c2022016-10-13 19:14:43 -070077 }
78
79 /**
80 * @return the basic Z height on which notifications remain.
81 */
82 public int getBaseZHeight() {
83 return mBaseZHeight;
84 }
85
86 /**
87 * @return the distance in Z between two overlaying notifications.
88 */
89 public int getZDistanceBetweenElements() {
90 return mZDistanceBetweenElements;
91 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +020092
93 public int getScrollY() {
94 return mScrollY;
95 }
96
97 public void setScrollY(int scrollY) {
98 this.mScrollY = scrollY;
99 }
100
101 public void onBeginDrag(View view) {
102 mDraggedViews.add(view);
103 }
104
105 public void onDragFinished(View view) {
106 mDraggedViews.remove(view);
107 }
108
109 public ArrayList<View> getDraggedViews() {
110 return mDraggedViews;
111 }
112
113 /**
114 * @param dimmed Whether we are in a dimmed state (on the lockscreen), where the backgrounds are
115 * translucent and everything is scaled back a bit.
116 */
117 public void setDimmed(boolean dimmed) {
118 mDimmed = dimmed;
119 }
120
John Spurlockbf370992014-06-17 13:58:31 -0400121 /** In dark mode, we draw as little as possible, assuming a black background */
122 public void setDark(boolean dark) {
123 mDark = dark;
124 }
125
Jorim Jaggiae441282014-08-01 02:45:18 +0200126 public void setHideSensitive(boolean hideSensitive) {
127 mHideSensitive = hideSensitive;
128 }
129
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200130 /**
131 * In dimmed mode, a child can be activated, which happens on the first tap of the double-tap
132 * interaction. This child is then scaled normally and its background is fully opaque.
133 */
Selim Cineka32ab602014-06-11 15:06:01 +0200134 public void setActivatedChild(ActivatableNotificationView activatedChild) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200135 mActivatedChild = activatedChild;
136 }
137
138 public boolean isDimmed() {
139 return mDimmed;
140 }
141
John Spurlockbf370992014-06-17 13:58:31 -0400142 public boolean isDark() {
143 return mDark;
144 }
145
Jorim Jaggiae441282014-08-01 02:45:18 +0200146 public boolean isHideSensitive() {
147 return mHideSensitive;
148 }
149
Selim Cineka32ab602014-06-11 15:06:01 +0200150 public ActivatableNotificationView getActivatedChild() {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200151 return mActivatedChild;
152 }
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200153
154 public void setOverScrollAmount(float amount, boolean onTop) {
155 if (onTop) {
156 mOverScrollTopAmount = amount;
157 } else {
158 mOverScrollBottomAmount = amount;
159 }
160 }
161
162 public float getOverScrollAmount(boolean top) {
163 return top ? mOverScrollTopAmount : mOverScrollBottomAmount;
164 }
Selim Cinekc27437b2014-05-14 10:23:33 +0200165
Selim Cinekdb167372016-11-17 15:41:17 -0800166 public int getSpeedBumpIndex() {
167 return mSpeedBumpIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200168 }
169
Selim Cinekdb167372016-11-17 15:41:17 -0800170 public void setSpeedBumpIndex(int shelfIndex) {
171 mSpeedBumpIndex = shelfIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200172 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700173
174 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
175 mHeadsUpManager = headsUpManager;
176 }
177
Selim Cineka59ecc32015-04-07 10:51:49 -0700178 public float getStackTranslation() {
179 return mStackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700180 }
181
Selim Cineka59ecc32015-04-07 10:51:49 -0700182 public void setStackTranslation(float stackTranslation) {
183 mStackTranslation = stackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700184 }
185
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700186 public void setLayoutHeight(int layoutHeight) {
187 mLayoutHeight = layoutHeight;
188 }
189
Selim Cineka59ecc32015-04-07 10:51:49 -0700190 public float getTopPadding() {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700191 return mTopPadding;
192 }
193
194 public void setTopPadding(int topPadding) {
195 mTopPadding = topPadding;
196 }
197
198 public int getInnerHeight() {
Selim Cinek91d4cba2016-11-10 19:59:48 -0800199 return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding, mLayoutMinHeight);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700200 }
201
202 public boolean isShadeExpanded() {
203 return mShadeExpanded;
204 }
205
206 public void setShadeExpanded(boolean shadeExpanded) {
207 mShadeExpanded = shadeExpanded;
208 }
209
210 public void setMaxHeadsUpTranslation(float maxHeadsUpTranslation) {
211 mMaxHeadsUpTranslation = maxHeadsUpTranslation;
212 }
213
214 public float getMaxHeadsUpTranslation() {
215 return mMaxHeadsUpTranslation;
216 }
Selim Cineka59ecc32015-04-07 10:51:49 -0700217
Selim Cinek9c17b772015-07-07 20:37:09 -0700218 public void setDismissAllInProgress(boolean dismissAllInProgress) {
219 mDismissAllInProgress = dismissAllInProgress;
220 }
221
222 public boolean isDismissAllInProgress() {
223 return mDismissAllInProgress;
224 }
Selim Cinekbc243a92016-09-27 16:35:13 -0700225
226 public void setLayoutMinHeight(int layoutMinHeight) {
227 mLayoutMinHeight = layoutMinHeight;
228 }
Selim Cinek281c2022016-10-13 19:14:43 -0700229
230 public void setShelf(NotificationShelf shelf) {
231 mShelf = shelf;
232 }
233
234 public NotificationShelf getShelf() {
235 return mShelf;
236 }
Selim Cinek91d4cba2016-11-10 19:59:48 -0800237
238 public void setLayoutMaxHeight(int maxLayoutHeight) {
239 mMaxLayoutHeight = maxLayoutHeight;
240 }
Selim Cinekdb167372016-11-17 15:41:17 -0800241
242 /**
243 * Sets the last visible view of the host layout, that has a background, i.e the very last
244 * view in the shade, without the clear all button.
245 */
246 public void setLastVisibleBackgroundChild(
247 ActivatableNotificationView lastVisibleBackgroundChild) {
248 mLastVisibleBackgroundChild = lastVisibleBackgroundChild;
249 }
250
251 public ActivatableNotificationView getLastVisibleBackgroundChild() {
252 return mLastVisibleBackgroundChild;
253 }
Selim Cinek727903c2016-12-06 17:28:10 -0800254
255 public void setCurrentScrollVelocity(float currentScrollVelocity) {
256 mCurrentScrollVelocity = currentScrollVelocity;
257 }
258
259 public float getCurrentScrollVelocity() {
260 return mCurrentScrollVelocity;
261 }
Selim Cinek355652a2016-12-07 13:32:12 -0800262
263 public boolean isOnKeyguard() {
264 return mStatusBarState == StatusBarState.KEYGUARD;
265 }
266
267 public void setStatusBarState(int statusBarState) {
268 mStatusBarState = statusBarState;
269 }
Selim Cinekd5ab6452016-12-08 16:34:00 -0800270
271 public void setExpandingVelocity(float expandingVelocity) {
272 mExpandingVelocity = expandingVelocity;
273 }
274
275 public void setExpansionChanging(boolean expansionChanging) {
276 mExpansionChanging = expansionChanging;
277 }
278
279 public boolean isExpansionChanging() {
280 return mExpansionChanging;
281 }
282
283 public float getExpandingVelocity() {
284 return mExpandingVelocity;
285 }
286
287 public void setPanelTracking(boolean panelTracking) {
288 mPanelTracking = panelTracking;
289 }
290
Selim Cinekbe2c4432017-05-30 12:11:09 -0700291 public boolean hasPulsingNotifications() {
292 return mHasPulsingNotifications;
Adrian Roosd83e9992017-03-16 15:17:57 -0700293 }
294
Selim Cinekbe2c4432017-05-30 12:11:09 -0700295 public void setHasPulsingNotifications(boolean hasPulsing) {
296 mHasPulsingNotifications = hasPulsing;
Adrian Roosd83e9992017-03-16 15:17:57 -0700297 }
298
Selim Cinekd5ab6452016-12-08 16:34:00 -0800299 public boolean isPanelTracking() {
300 return mPanelTracking;
301 }
Selim Cinekfcff4c62016-12-27 14:26:06 +0100302
303 public boolean isPanelFullWidth() {
304 return mPanelFullWidth;
305 }
306
307 public void setPanelFullWidth(boolean panelFullWidth) {
308 mPanelFullWidth = panelFullWidth;
309 }
Selim Cinekec29d342017-05-05 18:31:49 -0700310
311 public void setUnlockHintRunning(boolean unlockHintRunning) {
312 mUnlockHintRunning = unlockHintRunning;
313 }
314
315 public boolean isUnlockHintRunning() {
316 return mUnlockHintRunning;
317 }
Selim Cinek5cf1d052017-06-01 17:36:46 -0700318
319 public boolean isQsCustomizerShowing() {
320 return mQsCustomizerShowing;
321 }
322
323 public void setQsCustomizerShowing(boolean qsCustomizerShowing) {
324 mQsCustomizerShowing = qsCustomizerShowing;
325 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200326}