blob: 26f74eab7ba7d4b6ee02b97678cd0632c2a3dab2 [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 Cinekb8f09cf2015-03-16 17:09:28 -070025import com.android.systemui.statusbar.policy.HeadsUpManager;
Jorim Jaggid552d9d2014-05-07 19:41:13 +020026
27import java.util.ArrayList;
28
29/**
30 * A global state to track all input states for the algorithm.
31 */
32public class AmbientState {
33 private ArrayList<View> mDraggedViews = new ArrayList<View>();
34 private int mScrollY;
35 private boolean mDimmed;
Selim Cineka32ab602014-06-11 15:06:01 +020036 private ActivatableNotificationView mActivatedChild;
Selim Cinek8d9ff9c2014-05-12 15:13:04 +020037 private float mOverScrollTopAmount;
38 private float mOverScrollBottomAmount;
Selim Cinekdb167372016-11-17 15:41:17 -080039 private int mSpeedBumpIndex = -1;
John Spurlockbf370992014-06-17 13:58:31 -040040 private boolean mDark;
Jorim Jaggiae441282014-08-01 02:45:18 +020041 private boolean mHideSensitive;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070042 private HeadsUpManager mHeadsUpManager;
Selim Cineka59ecc32015-04-07 10:51:49 -070043 private float mStackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -070044 private int mLayoutHeight;
45 private int mTopPadding;
46 private boolean mShadeExpanded;
47 private float mMaxHeadsUpTranslation;
Selim Cinek9c17b772015-07-07 20:37:09 -070048 private boolean mDismissAllInProgress;
Selim Cinekbc243a92016-09-27 16:35:13 -070049 private int mLayoutMinHeight;
Selim Cinek281c2022016-10-13 19:14:43 -070050 private NotificationShelf mShelf;
51 private int mZDistanceBetweenElements;
52 private int mBaseZHeight;
Selim Cinek91d4cba2016-11-10 19:59:48 -080053 private int mMaxLayoutHeight;
Selim Cinekdb167372016-11-17 15:41:17 -080054 private ActivatableNotificationView mLastVisibleBackgroundChild;
Selim Cinek281c2022016-10-13 19:14:43 -070055
56 public AmbientState(Context context) {
57 reload(context);
58 }
59
60 /**
61 * Reload the dimens e.g. if the density changed.
62 */
63 public void reload(Context context) {
64 mZDistanceBetweenElements = Math.max(1, context.getResources()
65 .getDimensionPixelSize(R.dimen.z_distance_between_notifications));
Selim Cinekdb167372016-11-17 15:41:17 -080066 mBaseZHeight = 4 * mZDistanceBetweenElements;
Selim Cinek281c2022016-10-13 19:14:43 -070067 }
68
69 /**
70 * @return the basic Z height on which notifications remain.
71 */
72 public int getBaseZHeight() {
73 return mBaseZHeight;
74 }
75
76 /**
77 * @return the distance in Z between two overlaying notifications.
78 */
79 public int getZDistanceBetweenElements() {
80 return mZDistanceBetweenElements;
81 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +020082
83 public int getScrollY() {
84 return mScrollY;
85 }
86
87 public void setScrollY(int scrollY) {
88 this.mScrollY = scrollY;
89 }
90
91 public void onBeginDrag(View view) {
92 mDraggedViews.add(view);
93 }
94
95 public void onDragFinished(View view) {
96 mDraggedViews.remove(view);
97 }
98
99 public ArrayList<View> getDraggedViews() {
100 return mDraggedViews;
101 }
102
103 /**
104 * @param dimmed Whether we are in a dimmed state (on the lockscreen), where the backgrounds are
105 * translucent and everything is scaled back a bit.
106 */
107 public void setDimmed(boolean dimmed) {
108 mDimmed = dimmed;
109 }
110
John Spurlockbf370992014-06-17 13:58:31 -0400111 /** In dark mode, we draw as little as possible, assuming a black background */
112 public void setDark(boolean dark) {
113 mDark = dark;
114 }
115
Jorim Jaggiae441282014-08-01 02:45:18 +0200116 public void setHideSensitive(boolean hideSensitive) {
117 mHideSensitive = hideSensitive;
118 }
119
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200120 /**
121 * In dimmed mode, a child can be activated, which happens on the first tap of the double-tap
122 * interaction. This child is then scaled normally and its background is fully opaque.
123 */
Selim Cineka32ab602014-06-11 15:06:01 +0200124 public void setActivatedChild(ActivatableNotificationView activatedChild) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200125 mActivatedChild = activatedChild;
126 }
127
128 public boolean isDimmed() {
129 return mDimmed;
130 }
131
John Spurlockbf370992014-06-17 13:58:31 -0400132 public boolean isDark() {
133 return mDark;
134 }
135
Jorim Jaggiae441282014-08-01 02:45:18 +0200136 public boolean isHideSensitive() {
137 return mHideSensitive;
138 }
139
Selim Cineka32ab602014-06-11 15:06:01 +0200140 public ActivatableNotificationView getActivatedChild() {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200141 return mActivatedChild;
142 }
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200143
144 public void setOverScrollAmount(float amount, boolean onTop) {
145 if (onTop) {
146 mOverScrollTopAmount = amount;
147 } else {
148 mOverScrollBottomAmount = amount;
149 }
150 }
151
152 public float getOverScrollAmount(boolean top) {
153 return top ? mOverScrollTopAmount : mOverScrollBottomAmount;
154 }
Selim Cinekc27437b2014-05-14 10:23:33 +0200155
Selim Cinekdb167372016-11-17 15:41:17 -0800156 public int getSpeedBumpIndex() {
157 return mSpeedBumpIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200158 }
159
Selim Cinekdb167372016-11-17 15:41:17 -0800160 public void setSpeedBumpIndex(int shelfIndex) {
161 mSpeedBumpIndex = shelfIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200162 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700163
164 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
165 mHeadsUpManager = headsUpManager;
166 }
167
Selim Cineka59ecc32015-04-07 10:51:49 -0700168 public float getStackTranslation() {
169 return mStackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700170 }
171
Selim Cineka59ecc32015-04-07 10:51:49 -0700172 public void setStackTranslation(float stackTranslation) {
173 mStackTranslation = stackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700174 }
175
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700176 public void setLayoutHeight(int layoutHeight) {
177 mLayoutHeight = layoutHeight;
178 }
179
Selim Cineka59ecc32015-04-07 10:51:49 -0700180 public float getTopPadding() {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700181 return mTopPadding;
182 }
183
184 public void setTopPadding(int topPadding) {
185 mTopPadding = topPadding;
186 }
187
188 public int getInnerHeight() {
Selim Cinek91d4cba2016-11-10 19:59:48 -0800189 return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding, mLayoutMinHeight);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700190 }
191
192 public boolean isShadeExpanded() {
193 return mShadeExpanded;
194 }
195
196 public void setShadeExpanded(boolean shadeExpanded) {
197 mShadeExpanded = shadeExpanded;
198 }
199
200 public void setMaxHeadsUpTranslation(float maxHeadsUpTranslation) {
201 mMaxHeadsUpTranslation = maxHeadsUpTranslation;
202 }
203
204 public float getMaxHeadsUpTranslation() {
205 return mMaxHeadsUpTranslation;
206 }
Selim Cineka59ecc32015-04-07 10:51:49 -0700207
Selim Cinek9c17b772015-07-07 20:37:09 -0700208 public void setDismissAllInProgress(boolean dismissAllInProgress) {
209 mDismissAllInProgress = dismissAllInProgress;
210 }
211
212 public boolean isDismissAllInProgress() {
213 return mDismissAllInProgress;
214 }
Selim Cinekbc243a92016-09-27 16:35:13 -0700215
216 public void setLayoutMinHeight(int layoutMinHeight) {
217 mLayoutMinHeight = layoutMinHeight;
218 }
Selim Cinek281c2022016-10-13 19:14:43 -0700219
220 public void setShelf(NotificationShelf shelf) {
221 mShelf = shelf;
222 }
223
224 public NotificationShelf getShelf() {
225 return mShelf;
226 }
Selim Cinek91d4cba2016-11-10 19:59:48 -0800227
228 public void setLayoutMaxHeight(int maxLayoutHeight) {
229 mMaxLayoutHeight = maxLayoutHeight;
230 }
Selim Cinekdb167372016-11-17 15:41:17 -0800231
232 /**
233 * Sets the last visible view of the host layout, that has a background, i.e the very last
234 * view in the shade, without the clear all button.
235 */
236 public void setLastVisibleBackgroundChild(
237 ActivatableNotificationView lastVisibleBackgroundChild) {
238 mLastVisibleBackgroundChild = lastVisibleBackgroundChild;
239 }
240
241 public ActivatableNotificationView getLastVisibleBackgroundChild() {
242 return mLastVisibleBackgroundChild;
243 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200244}