blob: e409b9c4454f05e0f54c32d973da7014611e8119 [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;
Adrian Roosd83e9992017-03-16 15:17:57 -070062 private boolean mPulsing;
Selim Cinekec29d342017-05-05 18:31:49 -070063 private boolean mUnlockHintRunning;
Selim Cinek281c2022016-10-13 19:14:43 -070064
65 public AmbientState(Context context) {
66 reload(context);
67 }
68
69 /**
70 * Reload the dimens e.g. if the density changed.
71 */
72 public void reload(Context context) {
73 mZDistanceBetweenElements = Math.max(1, context.getResources()
74 .getDimensionPixelSize(R.dimen.z_distance_between_notifications));
Selim Cinekdb167372016-11-17 15:41:17 -080075 mBaseZHeight = 4 * mZDistanceBetweenElements;
Selim Cinek281c2022016-10-13 19:14:43 -070076 }
77
78 /**
79 * @return the basic Z height on which notifications remain.
80 */
81 public int getBaseZHeight() {
82 return mBaseZHeight;
83 }
84
85 /**
86 * @return the distance in Z between two overlaying notifications.
87 */
88 public int getZDistanceBetweenElements() {
89 return mZDistanceBetweenElements;
90 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +020091
92 public int getScrollY() {
93 return mScrollY;
94 }
95
96 public void setScrollY(int scrollY) {
97 this.mScrollY = scrollY;
98 }
99
100 public void onBeginDrag(View view) {
101 mDraggedViews.add(view);
102 }
103
104 public void onDragFinished(View view) {
105 mDraggedViews.remove(view);
106 }
107
108 public ArrayList<View> getDraggedViews() {
109 return mDraggedViews;
110 }
111
112 /**
113 * @param dimmed Whether we are in a dimmed state (on the lockscreen), where the backgrounds are
114 * translucent and everything is scaled back a bit.
115 */
116 public void setDimmed(boolean dimmed) {
117 mDimmed = dimmed;
118 }
119
John Spurlockbf370992014-06-17 13:58:31 -0400120 /** In dark mode, we draw as little as possible, assuming a black background */
121 public void setDark(boolean dark) {
122 mDark = dark;
123 }
124
Jorim Jaggiae441282014-08-01 02:45:18 +0200125 public void setHideSensitive(boolean hideSensitive) {
126 mHideSensitive = hideSensitive;
127 }
128
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200129 /**
130 * In dimmed mode, a child can be activated, which happens on the first tap of the double-tap
131 * interaction. This child is then scaled normally and its background is fully opaque.
132 */
Selim Cineka32ab602014-06-11 15:06:01 +0200133 public void setActivatedChild(ActivatableNotificationView activatedChild) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200134 mActivatedChild = activatedChild;
135 }
136
137 public boolean isDimmed() {
138 return mDimmed;
139 }
140
John Spurlockbf370992014-06-17 13:58:31 -0400141 public boolean isDark() {
142 return mDark;
143 }
144
Jorim Jaggiae441282014-08-01 02:45:18 +0200145 public boolean isHideSensitive() {
146 return mHideSensitive;
147 }
148
Selim Cineka32ab602014-06-11 15:06:01 +0200149 public ActivatableNotificationView getActivatedChild() {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200150 return mActivatedChild;
151 }
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200152
153 public void setOverScrollAmount(float amount, boolean onTop) {
154 if (onTop) {
155 mOverScrollTopAmount = amount;
156 } else {
157 mOverScrollBottomAmount = amount;
158 }
159 }
160
161 public float getOverScrollAmount(boolean top) {
162 return top ? mOverScrollTopAmount : mOverScrollBottomAmount;
163 }
Selim Cinekc27437b2014-05-14 10:23:33 +0200164
Selim Cinekdb167372016-11-17 15:41:17 -0800165 public int getSpeedBumpIndex() {
166 return mSpeedBumpIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200167 }
168
Selim Cinekdb167372016-11-17 15:41:17 -0800169 public void setSpeedBumpIndex(int shelfIndex) {
170 mSpeedBumpIndex = shelfIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200171 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700172
173 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
174 mHeadsUpManager = headsUpManager;
175 }
176
Selim Cineka59ecc32015-04-07 10:51:49 -0700177 public float getStackTranslation() {
178 return mStackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700179 }
180
Selim Cineka59ecc32015-04-07 10:51:49 -0700181 public void setStackTranslation(float stackTranslation) {
182 mStackTranslation = stackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700183 }
184
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700185 public void setLayoutHeight(int layoutHeight) {
186 mLayoutHeight = layoutHeight;
187 }
188
Selim Cineka59ecc32015-04-07 10:51:49 -0700189 public float getTopPadding() {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700190 return mTopPadding;
191 }
192
193 public void setTopPadding(int topPadding) {
194 mTopPadding = topPadding;
195 }
196
197 public int getInnerHeight() {
Selim Cinek91d4cba2016-11-10 19:59:48 -0800198 return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding, mLayoutMinHeight);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700199 }
200
201 public boolean isShadeExpanded() {
202 return mShadeExpanded;
203 }
204
205 public void setShadeExpanded(boolean shadeExpanded) {
206 mShadeExpanded = shadeExpanded;
207 }
208
209 public void setMaxHeadsUpTranslation(float maxHeadsUpTranslation) {
210 mMaxHeadsUpTranslation = maxHeadsUpTranslation;
211 }
212
213 public float getMaxHeadsUpTranslation() {
214 return mMaxHeadsUpTranslation;
215 }
Selim Cineka59ecc32015-04-07 10:51:49 -0700216
Selim Cinek9c17b772015-07-07 20:37:09 -0700217 public void setDismissAllInProgress(boolean dismissAllInProgress) {
218 mDismissAllInProgress = dismissAllInProgress;
219 }
220
221 public boolean isDismissAllInProgress() {
222 return mDismissAllInProgress;
223 }
Selim Cinekbc243a92016-09-27 16:35:13 -0700224
225 public void setLayoutMinHeight(int layoutMinHeight) {
226 mLayoutMinHeight = layoutMinHeight;
227 }
Selim Cinek281c2022016-10-13 19:14:43 -0700228
229 public void setShelf(NotificationShelf shelf) {
230 mShelf = shelf;
231 }
232
233 public NotificationShelf getShelf() {
234 return mShelf;
235 }
Selim Cinek91d4cba2016-11-10 19:59:48 -0800236
237 public void setLayoutMaxHeight(int maxLayoutHeight) {
238 mMaxLayoutHeight = maxLayoutHeight;
239 }
Selim Cinekdb167372016-11-17 15:41:17 -0800240
241 /**
242 * Sets the last visible view of the host layout, that has a background, i.e the very last
243 * view in the shade, without the clear all button.
244 */
245 public void setLastVisibleBackgroundChild(
246 ActivatableNotificationView lastVisibleBackgroundChild) {
247 mLastVisibleBackgroundChild = lastVisibleBackgroundChild;
248 }
249
250 public ActivatableNotificationView getLastVisibleBackgroundChild() {
251 return mLastVisibleBackgroundChild;
252 }
Selim Cinek727903c2016-12-06 17:28:10 -0800253
254 public void setCurrentScrollVelocity(float currentScrollVelocity) {
255 mCurrentScrollVelocity = currentScrollVelocity;
256 }
257
258 public float getCurrentScrollVelocity() {
259 return mCurrentScrollVelocity;
260 }
Selim Cinek355652a2016-12-07 13:32:12 -0800261
262 public boolean isOnKeyguard() {
263 return mStatusBarState == StatusBarState.KEYGUARD;
264 }
265
266 public void setStatusBarState(int statusBarState) {
267 mStatusBarState = statusBarState;
268 }
Selim Cinekd5ab6452016-12-08 16:34:00 -0800269
270 public void setExpandingVelocity(float expandingVelocity) {
271 mExpandingVelocity = expandingVelocity;
272 }
273
274 public void setExpansionChanging(boolean expansionChanging) {
275 mExpansionChanging = expansionChanging;
276 }
277
278 public boolean isExpansionChanging() {
279 return mExpansionChanging;
280 }
281
282 public float getExpandingVelocity() {
283 return mExpandingVelocity;
284 }
285
286 public void setPanelTracking(boolean panelTracking) {
287 mPanelTracking = panelTracking;
288 }
289
Adrian Roosd83e9992017-03-16 15:17:57 -0700290 public boolean isPulsing() {
291 return mPulsing;
292 }
293
294 public void setPulsing(boolean pulsing) {
295 mPulsing = pulsing;
296 }
297
Selim Cinekd5ab6452016-12-08 16:34:00 -0800298 public boolean isPanelTracking() {
299 return mPanelTracking;
300 }
Selim Cinekfcff4c62016-12-27 14:26:06 +0100301
302 public boolean isPanelFullWidth() {
303 return mPanelFullWidth;
304 }
305
306 public void setPanelFullWidth(boolean panelFullWidth) {
307 mPanelFullWidth = panelFullWidth;
308 }
Selim Cinekec29d342017-05-05 18:31:49 -0700309
310 public void setUnlockHintRunning(boolean unlockHintRunning) {
311 mUnlockHintRunning = unlockHintRunning;
312 }
313
314 public boolean isUnlockHintRunning() {
315 return mUnlockHintRunning;
316 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200317}