blob: 94fc17a8b1d832b82262c35f3d6aad3e18152409 [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 Cinek281c2022016-10-13 19:14:43 -070058
59 public AmbientState(Context context) {
60 reload(context);
61 }
62
63 /**
64 * Reload the dimens e.g. if the density changed.
65 */
66 public void reload(Context context) {
67 mZDistanceBetweenElements = Math.max(1, context.getResources()
68 .getDimensionPixelSize(R.dimen.z_distance_between_notifications));
Selim Cinekdb167372016-11-17 15:41:17 -080069 mBaseZHeight = 4 * mZDistanceBetweenElements;
Selim Cinek281c2022016-10-13 19:14:43 -070070 }
71
72 /**
73 * @return the basic Z height on which notifications remain.
74 */
75 public int getBaseZHeight() {
76 return mBaseZHeight;
77 }
78
79 /**
80 * @return the distance in Z between two overlaying notifications.
81 */
82 public int getZDistanceBetweenElements() {
83 return mZDistanceBetweenElements;
84 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +020085
86 public int getScrollY() {
87 return mScrollY;
88 }
89
90 public void setScrollY(int scrollY) {
91 this.mScrollY = scrollY;
92 }
93
94 public void onBeginDrag(View view) {
95 mDraggedViews.add(view);
96 }
97
98 public void onDragFinished(View view) {
99 mDraggedViews.remove(view);
100 }
101
102 public ArrayList<View> getDraggedViews() {
103 return mDraggedViews;
104 }
105
106 /**
107 * @param dimmed Whether we are in a dimmed state (on the lockscreen), where the backgrounds are
108 * translucent and everything is scaled back a bit.
109 */
110 public void setDimmed(boolean dimmed) {
111 mDimmed = dimmed;
112 }
113
John Spurlockbf370992014-06-17 13:58:31 -0400114 /** In dark mode, we draw as little as possible, assuming a black background */
115 public void setDark(boolean dark) {
116 mDark = dark;
117 }
118
Jorim Jaggiae441282014-08-01 02:45:18 +0200119 public void setHideSensitive(boolean hideSensitive) {
120 mHideSensitive = hideSensitive;
121 }
122
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200123 /**
124 * In dimmed mode, a child can be activated, which happens on the first tap of the double-tap
125 * interaction. This child is then scaled normally and its background is fully opaque.
126 */
Selim Cineka32ab602014-06-11 15:06:01 +0200127 public void setActivatedChild(ActivatableNotificationView activatedChild) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200128 mActivatedChild = activatedChild;
129 }
130
131 public boolean isDimmed() {
132 return mDimmed;
133 }
134
John Spurlockbf370992014-06-17 13:58:31 -0400135 public boolean isDark() {
136 return mDark;
137 }
138
Jorim Jaggiae441282014-08-01 02:45:18 +0200139 public boolean isHideSensitive() {
140 return mHideSensitive;
141 }
142
Selim Cineka32ab602014-06-11 15:06:01 +0200143 public ActivatableNotificationView getActivatedChild() {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200144 return mActivatedChild;
145 }
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200146
147 public void setOverScrollAmount(float amount, boolean onTop) {
148 if (onTop) {
149 mOverScrollTopAmount = amount;
150 } else {
151 mOverScrollBottomAmount = amount;
152 }
153 }
154
155 public float getOverScrollAmount(boolean top) {
156 return top ? mOverScrollTopAmount : mOverScrollBottomAmount;
157 }
Selim Cinekc27437b2014-05-14 10:23:33 +0200158
Selim Cinekdb167372016-11-17 15:41:17 -0800159 public int getSpeedBumpIndex() {
160 return mSpeedBumpIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200161 }
162
Selim Cinekdb167372016-11-17 15:41:17 -0800163 public void setSpeedBumpIndex(int shelfIndex) {
164 mSpeedBumpIndex = shelfIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200165 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700166
167 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
168 mHeadsUpManager = headsUpManager;
169 }
170
Selim Cineka59ecc32015-04-07 10:51:49 -0700171 public float getStackTranslation() {
172 return mStackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700173 }
174
Selim Cineka59ecc32015-04-07 10:51:49 -0700175 public void setStackTranslation(float stackTranslation) {
176 mStackTranslation = stackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700177 }
178
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700179 public void setLayoutHeight(int layoutHeight) {
180 mLayoutHeight = layoutHeight;
181 }
182
Selim Cineka59ecc32015-04-07 10:51:49 -0700183 public float getTopPadding() {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700184 return mTopPadding;
185 }
186
187 public void setTopPadding(int topPadding) {
188 mTopPadding = topPadding;
189 }
190
191 public int getInnerHeight() {
Selim Cinek91d4cba2016-11-10 19:59:48 -0800192 return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding, mLayoutMinHeight);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700193 }
194
195 public boolean isShadeExpanded() {
196 return mShadeExpanded;
197 }
198
199 public void setShadeExpanded(boolean shadeExpanded) {
200 mShadeExpanded = shadeExpanded;
201 }
202
203 public void setMaxHeadsUpTranslation(float maxHeadsUpTranslation) {
204 mMaxHeadsUpTranslation = maxHeadsUpTranslation;
205 }
206
207 public float getMaxHeadsUpTranslation() {
208 return mMaxHeadsUpTranslation;
209 }
Selim Cineka59ecc32015-04-07 10:51:49 -0700210
Selim Cinek9c17b772015-07-07 20:37:09 -0700211 public void setDismissAllInProgress(boolean dismissAllInProgress) {
212 mDismissAllInProgress = dismissAllInProgress;
213 }
214
215 public boolean isDismissAllInProgress() {
216 return mDismissAllInProgress;
217 }
Selim Cinekbc243a92016-09-27 16:35:13 -0700218
219 public void setLayoutMinHeight(int layoutMinHeight) {
220 mLayoutMinHeight = layoutMinHeight;
221 }
Selim Cinek281c2022016-10-13 19:14:43 -0700222
223 public void setShelf(NotificationShelf shelf) {
224 mShelf = shelf;
225 }
226
227 public NotificationShelf getShelf() {
228 return mShelf;
229 }
Selim Cinek91d4cba2016-11-10 19:59:48 -0800230
231 public void setLayoutMaxHeight(int maxLayoutHeight) {
232 mMaxLayoutHeight = maxLayoutHeight;
233 }
Selim Cinekdb167372016-11-17 15:41:17 -0800234
235 /**
236 * Sets the last visible view of the host layout, that has a background, i.e the very last
237 * view in the shade, without the clear all button.
238 */
239 public void setLastVisibleBackgroundChild(
240 ActivatableNotificationView lastVisibleBackgroundChild) {
241 mLastVisibleBackgroundChild = lastVisibleBackgroundChild;
242 }
243
244 public ActivatableNotificationView getLastVisibleBackgroundChild() {
245 return mLastVisibleBackgroundChild;
246 }
Selim Cinek727903c2016-12-06 17:28:10 -0800247
248 public void setCurrentScrollVelocity(float currentScrollVelocity) {
249 mCurrentScrollVelocity = currentScrollVelocity;
250 }
251
252 public float getCurrentScrollVelocity() {
253 return mCurrentScrollVelocity;
254 }
Selim Cinek355652a2016-12-07 13:32:12 -0800255
256 public boolean isOnKeyguard() {
257 return mStatusBarState == StatusBarState.KEYGUARD;
258 }
259
260 public void setStatusBarState(int statusBarState) {
261 mStatusBarState = statusBarState;
262 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200263}