blob: e1ff29703da78662005a90d153d7024e74aba89e [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 Cinek281c2022016-10-13 19:14:43 -070061
62 public AmbientState(Context context) {
63 reload(context);
64 }
65
66 /**
67 * Reload the dimens e.g. if the density changed.
68 */
69 public void reload(Context context) {
70 mZDistanceBetweenElements = Math.max(1, context.getResources()
71 .getDimensionPixelSize(R.dimen.z_distance_between_notifications));
Selim Cinekdb167372016-11-17 15:41:17 -080072 mBaseZHeight = 4 * mZDistanceBetweenElements;
Selim Cinek281c2022016-10-13 19:14:43 -070073 }
74
75 /**
76 * @return the basic Z height on which notifications remain.
77 */
78 public int getBaseZHeight() {
79 return mBaseZHeight;
80 }
81
82 /**
83 * @return the distance in Z between two overlaying notifications.
84 */
85 public int getZDistanceBetweenElements() {
86 return mZDistanceBetweenElements;
87 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +020088
89 public int getScrollY() {
90 return mScrollY;
91 }
92
93 public void setScrollY(int scrollY) {
94 this.mScrollY = scrollY;
95 }
96
97 public void onBeginDrag(View view) {
98 mDraggedViews.add(view);
99 }
100
101 public void onDragFinished(View view) {
102 mDraggedViews.remove(view);
103 }
104
105 public ArrayList<View> getDraggedViews() {
106 return mDraggedViews;
107 }
108
109 /**
110 * @param dimmed Whether we are in a dimmed state (on the lockscreen), where the backgrounds are
111 * translucent and everything is scaled back a bit.
112 */
113 public void setDimmed(boolean dimmed) {
114 mDimmed = dimmed;
115 }
116
John Spurlockbf370992014-06-17 13:58:31 -0400117 /** In dark mode, we draw as little as possible, assuming a black background */
118 public void setDark(boolean dark) {
119 mDark = dark;
120 }
121
Jorim Jaggiae441282014-08-01 02:45:18 +0200122 public void setHideSensitive(boolean hideSensitive) {
123 mHideSensitive = hideSensitive;
124 }
125
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200126 /**
127 * In dimmed mode, a child can be activated, which happens on the first tap of the double-tap
128 * interaction. This child is then scaled normally and its background is fully opaque.
129 */
Selim Cineka32ab602014-06-11 15:06:01 +0200130 public void setActivatedChild(ActivatableNotificationView activatedChild) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200131 mActivatedChild = activatedChild;
132 }
133
134 public boolean isDimmed() {
135 return mDimmed;
136 }
137
John Spurlockbf370992014-06-17 13:58:31 -0400138 public boolean isDark() {
139 return mDark;
140 }
141
Jorim Jaggiae441282014-08-01 02:45:18 +0200142 public boolean isHideSensitive() {
143 return mHideSensitive;
144 }
145
Selim Cineka32ab602014-06-11 15:06:01 +0200146 public ActivatableNotificationView getActivatedChild() {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200147 return mActivatedChild;
148 }
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200149
150 public void setOverScrollAmount(float amount, boolean onTop) {
151 if (onTop) {
152 mOverScrollTopAmount = amount;
153 } else {
154 mOverScrollBottomAmount = amount;
155 }
156 }
157
158 public float getOverScrollAmount(boolean top) {
159 return top ? mOverScrollTopAmount : mOverScrollBottomAmount;
160 }
Selim Cinekc27437b2014-05-14 10:23:33 +0200161
Selim Cinekdb167372016-11-17 15:41:17 -0800162 public int getSpeedBumpIndex() {
163 return mSpeedBumpIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200164 }
165
Selim Cinekdb167372016-11-17 15:41:17 -0800166 public void setSpeedBumpIndex(int shelfIndex) {
167 mSpeedBumpIndex = shelfIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200168 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700169
170 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
171 mHeadsUpManager = headsUpManager;
172 }
173
Selim Cineka59ecc32015-04-07 10:51:49 -0700174 public float getStackTranslation() {
175 return mStackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700176 }
177
Selim Cineka59ecc32015-04-07 10:51:49 -0700178 public void setStackTranslation(float stackTranslation) {
179 mStackTranslation = stackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700180 }
181
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700182 public void setLayoutHeight(int layoutHeight) {
183 mLayoutHeight = layoutHeight;
184 }
185
Selim Cineka59ecc32015-04-07 10:51:49 -0700186 public float getTopPadding() {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700187 return mTopPadding;
188 }
189
190 public void setTopPadding(int topPadding) {
191 mTopPadding = topPadding;
192 }
193
194 public int getInnerHeight() {
Selim Cinek91d4cba2016-11-10 19:59:48 -0800195 return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding, mLayoutMinHeight);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700196 }
197
198 public boolean isShadeExpanded() {
199 return mShadeExpanded;
200 }
201
202 public void setShadeExpanded(boolean shadeExpanded) {
203 mShadeExpanded = shadeExpanded;
204 }
205
206 public void setMaxHeadsUpTranslation(float maxHeadsUpTranslation) {
207 mMaxHeadsUpTranslation = maxHeadsUpTranslation;
208 }
209
210 public float getMaxHeadsUpTranslation() {
211 return mMaxHeadsUpTranslation;
212 }
Selim Cineka59ecc32015-04-07 10:51:49 -0700213
Selim Cinek9c17b772015-07-07 20:37:09 -0700214 public void setDismissAllInProgress(boolean dismissAllInProgress) {
215 mDismissAllInProgress = dismissAllInProgress;
216 }
217
218 public boolean isDismissAllInProgress() {
219 return mDismissAllInProgress;
220 }
Selim Cinekbc243a92016-09-27 16:35:13 -0700221
222 public void setLayoutMinHeight(int layoutMinHeight) {
223 mLayoutMinHeight = layoutMinHeight;
224 }
Selim Cinek281c2022016-10-13 19:14:43 -0700225
226 public void setShelf(NotificationShelf shelf) {
227 mShelf = shelf;
228 }
229
230 public NotificationShelf getShelf() {
231 return mShelf;
232 }
Selim Cinek91d4cba2016-11-10 19:59:48 -0800233
234 public void setLayoutMaxHeight(int maxLayoutHeight) {
235 mMaxLayoutHeight = maxLayoutHeight;
236 }
Selim Cinekdb167372016-11-17 15:41:17 -0800237
238 /**
239 * Sets the last visible view of the host layout, that has a background, i.e the very last
240 * view in the shade, without the clear all button.
241 */
242 public void setLastVisibleBackgroundChild(
243 ActivatableNotificationView lastVisibleBackgroundChild) {
244 mLastVisibleBackgroundChild = lastVisibleBackgroundChild;
245 }
246
247 public ActivatableNotificationView getLastVisibleBackgroundChild() {
248 return mLastVisibleBackgroundChild;
249 }
Selim Cinek727903c2016-12-06 17:28:10 -0800250
251 public void setCurrentScrollVelocity(float currentScrollVelocity) {
252 mCurrentScrollVelocity = currentScrollVelocity;
253 }
254
255 public float getCurrentScrollVelocity() {
256 return mCurrentScrollVelocity;
257 }
Selim Cinek355652a2016-12-07 13:32:12 -0800258
259 public boolean isOnKeyguard() {
260 return mStatusBarState == StatusBarState.KEYGUARD;
261 }
262
263 public void setStatusBarState(int statusBarState) {
264 mStatusBarState = statusBarState;
265 }
Selim Cinekd5ab6452016-12-08 16:34:00 -0800266
267 public void setExpandingVelocity(float expandingVelocity) {
268 mExpandingVelocity = expandingVelocity;
269 }
270
271 public void setExpansionChanging(boolean expansionChanging) {
272 mExpansionChanging = expansionChanging;
273 }
274
275 public boolean isExpansionChanging() {
276 return mExpansionChanging;
277 }
278
279 public float getExpandingVelocity() {
280 return mExpandingVelocity;
281 }
282
283 public void setPanelTracking(boolean panelTracking) {
284 mPanelTracking = panelTracking;
285 }
286
287 public boolean isPanelTracking() {
288 return mPanelTracking;
289 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200290}