blob: b2b23a55cd205ec536543b3115ed8c0f624c48b8 [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 Cinek281c2022016-10-13 19:14:43 -070063
64 public AmbientState(Context context) {
65 reload(context);
66 }
67
68 /**
69 * Reload the dimens e.g. if the density changed.
70 */
71 public void reload(Context context) {
72 mZDistanceBetweenElements = Math.max(1, context.getResources()
73 .getDimensionPixelSize(R.dimen.z_distance_between_notifications));
Selim Cinekdb167372016-11-17 15:41:17 -080074 mBaseZHeight = 4 * mZDistanceBetweenElements;
Selim Cinek281c2022016-10-13 19:14:43 -070075 }
76
77 /**
78 * @return the basic Z height on which notifications remain.
79 */
80 public int getBaseZHeight() {
81 return mBaseZHeight;
82 }
83
84 /**
85 * @return the distance in Z between two overlaying notifications.
86 */
87 public int getZDistanceBetweenElements() {
88 return mZDistanceBetweenElements;
89 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +020090
91 public int getScrollY() {
92 return mScrollY;
93 }
94
95 public void setScrollY(int scrollY) {
96 this.mScrollY = scrollY;
97 }
98
99 public void onBeginDrag(View view) {
100 mDraggedViews.add(view);
101 }
102
103 public void onDragFinished(View view) {
104 mDraggedViews.remove(view);
105 }
106
107 public ArrayList<View> getDraggedViews() {
108 return mDraggedViews;
109 }
110
111 /**
112 * @param dimmed Whether we are in a dimmed state (on the lockscreen), where the backgrounds are
113 * translucent and everything is scaled back a bit.
114 */
115 public void setDimmed(boolean dimmed) {
116 mDimmed = dimmed;
117 }
118
John Spurlockbf370992014-06-17 13:58:31 -0400119 /** In dark mode, we draw as little as possible, assuming a black background */
120 public void setDark(boolean dark) {
121 mDark = dark;
122 }
123
Jorim Jaggiae441282014-08-01 02:45:18 +0200124 public void setHideSensitive(boolean hideSensitive) {
125 mHideSensitive = hideSensitive;
126 }
127
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200128 /**
129 * In dimmed mode, a child can be activated, which happens on the first tap of the double-tap
130 * interaction. This child is then scaled normally and its background is fully opaque.
131 */
Selim Cineka32ab602014-06-11 15:06:01 +0200132 public void setActivatedChild(ActivatableNotificationView activatedChild) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200133 mActivatedChild = activatedChild;
134 }
135
136 public boolean isDimmed() {
137 return mDimmed;
138 }
139
John Spurlockbf370992014-06-17 13:58:31 -0400140 public boolean isDark() {
141 return mDark;
142 }
143
Jorim Jaggiae441282014-08-01 02:45:18 +0200144 public boolean isHideSensitive() {
145 return mHideSensitive;
146 }
147
Selim Cineka32ab602014-06-11 15:06:01 +0200148 public ActivatableNotificationView getActivatedChild() {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200149 return mActivatedChild;
150 }
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200151
152 public void setOverScrollAmount(float amount, boolean onTop) {
153 if (onTop) {
154 mOverScrollTopAmount = amount;
155 } else {
156 mOverScrollBottomAmount = amount;
157 }
158 }
159
160 public float getOverScrollAmount(boolean top) {
161 return top ? mOverScrollTopAmount : mOverScrollBottomAmount;
162 }
Selim Cinekc27437b2014-05-14 10:23:33 +0200163
Selim Cinekdb167372016-11-17 15:41:17 -0800164 public int getSpeedBumpIndex() {
165 return mSpeedBumpIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200166 }
167
Selim Cinekdb167372016-11-17 15:41:17 -0800168 public void setSpeedBumpIndex(int shelfIndex) {
169 mSpeedBumpIndex = shelfIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200170 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700171
172 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
173 mHeadsUpManager = headsUpManager;
174 }
175
Selim Cineka59ecc32015-04-07 10:51:49 -0700176 public float getStackTranslation() {
177 return mStackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700178 }
179
Selim Cineka59ecc32015-04-07 10:51:49 -0700180 public void setStackTranslation(float stackTranslation) {
181 mStackTranslation = stackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700182 }
183
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700184 public void setLayoutHeight(int layoutHeight) {
185 mLayoutHeight = layoutHeight;
186 }
187
Selim Cineka59ecc32015-04-07 10:51:49 -0700188 public float getTopPadding() {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700189 return mTopPadding;
190 }
191
192 public void setTopPadding(int topPadding) {
193 mTopPadding = topPadding;
194 }
195
196 public int getInnerHeight() {
Selim Cinek91d4cba2016-11-10 19:59:48 -0800197 return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding, mLayoutMinHeight);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700198 }
199
200 public boolean isShadeExpanded() {
201 return mShadeExpanded;
202 }
203
204 public void setShadeExpanded(boolean shadeExpanded) {
205 mShadeExpanded = shadeExpanded;
206 }
207
208 public void setMaxHeadsUpTranslation(float maxHeadsUpTranslation) {
209 mMaxHeadsUpTranslation = maxHeadsUpTranslation;
210 }
211
212 public float getMaxHeadsUpTranslation() {
213 return mMaxHeadsUpTranslation;
214 }
Selim Cineka59ecc32015-04-07 10:51:49 -0700215
Selim Cinek9c17b772015-07-07 20:37:09 -0700216 public void setDismissAllInProgress(boolean dismissAllInProgress) {
217 mDismissAllInProgress = dismissAllInProgress;
218 }
219
220 public boolean isDismissAllInProgress() {
221 return mDismissAllInProgress;
222 }
Selim Cinekbc243a92016-09-27 16:35:13 -0700223
224 public void setLayoutMinHeight(int layoutMinHeight) {
225 mLayoutMinHeight = layoutMinHeight;
226 }
Selim Cinek281c2022016-10-13 19:14:43 -0700227
228 public void setShelf(NotificationShelf shelf) {
229 mShelf = shelf;
230 }
231
232 public NotificationShelf getShelf() {
233 return mShelf;
234 }
Selim Cinek91d4cba2016-11-10 19:59:48 -0800235
236 public void setLayoutMaxHeight(int maxLayoutHeight) {
237 mMaxLayoutHeight = maxLayoutHeight;
238 }
Selim Cinekdb167372016-11-17 15:41:17 -0800239
240 /**
241 * Sets the last visible view of the host layout, that has a background, i.e the very last
242 * view in the shade, without the clear all button.
243 */
244 public void setLastVisibleBackgroundChild(
245 ActivatableNotificationView lastVisibleBackgroundChild) {
246 mLastVisibleBackgroundChild = lastVisibleBackgroundChild;
247 }
248
249 public ActivatableNotificationView getLastVisibleBackgroundChild() {
250 return mLastVisibleBackgroundChild;
251 }
Selim Cinek727903c2016-12-06 17:28:10 -0800252
253 public void setCurrentScrollVelocity(float currentScrollVelocity) {
254 mCurrentScrollVelocity = currentScrollVelocity;
255 }
256
257 public float getCurrentScrollVelocity() {
258 return mCurrentScrollVelocity;
259 }
Selim Cinek355652a2016-12-07 13:32:12 -0800260
261 public boolean isOnKeyguard() {
262 return mStatusBarState == StatusBarState.KEYGUARD;
263 }
264
265 public void setStatusBarState(int statusBarState) {
266 mStatusBarState = statusBarState;
267 }
Selim Cinekd5ab6452016-12-08 16:34:00 -0800268
269 public void setExpandingVelocity(float expandingVelocity) {
270 mExpandingVelocity = expandingVelocity;
271 }
272
273 public void setExpansionChanging(boolean expansionChanging) {
274 mExpansionChanging = expansionChanging;
275 }
276
277 public boolean isExpansionChanging() {
278 return mExpansionChanging;
279 }
280
281 public float getExpandingVelocity() {
282 return mExpandingVelocity;
283 }
284
285 public void setPanelTracking(boolean panelTracking) {
286 mPanelTracking = panelTracking;
287 }
288
Adrian Roosd83e9992017-03-16 15:17:57 -0700289 public boolean isPulsing() {
290 return mPulsing;
291 }
292
293 public void setPulsing(boolean pulsing) {
294 mPulsing = pulsing;
295 }
296
Selim Cinekd5ab6452016-12-08 16:34:00 -0800297 public boolean isPanelTracking() {
298 return mPanelTracking;
299 }
Selim Cinekfcff4c62016-12-27 14:26:06 +0100300
301 public boolean isPanelFullWidth() {
302 return mPanelFullWidth;
303 }
304
305 public void setPanelFullWidth(boolean panelFullWidth) {
306 mPanelFullWidth = panelFullWidth;
307 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200308}