blob: f468b5c7e11dfa35cf26cf40a100b3fcd87359c3 [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 Cinek727903c2016-12-06 17:28:10 -080055 private float mCurrentScrollVelocity;
Selim Cinek281c2022016-10-13 19:14:43 -070056
57 public AmbientState(Context context) {
58 reload(context);
59 }
60
61 /**
62 * Reload the dimens e.g. if the density changed.
63 */
64 public void reload(Context context) {
65 mZDistanceBetweenElements = Math.max(1, context.getResources()
66 .getDimensionPixelSize(R.dimen.z_distance_between_notifications));
Selim Cinekdb167372016-11-17 15:41:17 -080067 mBaseZHeight = 4 * mZDistanceBetweenElements;
Selim Cinek281c2022016-10-13 19:14:43 -070068 }
69
70 /**
71 * @return the basic Z height on which notifications remain.
72 */
73 public int getBaseZHeight() {
74 return mBaseZHeight;
75 }
76
77 /**
78 * @return the distance in Z between two overlaying notifications.
79 */
80 public int getZDistanceBetweenElements() {
81 return mZDistanceBetweenElements;
82 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +020083
84 public int getScrollY() {
85 return mScrollY;
86 }
87
88 public void setScrollY(int scrollY) {
89 this.mScrollY = scrollY;
90 }
91
92 public void onBeginDrag(View view) {
93 mDraggedViews.add(view);
94 }
95
96 public void onDragFinished(View view) {
97 mDraggedViews.remove(view);
98 }
99
100 public ArrayList<View> getDraggedViews() {
101 return mDraggedViews;
102 }
103
104 /**
105 * @param dimmed Whether we are in a dimmed state (on the lockscreen), where the backgrounds are
106 * translucent and everything is scaled back a bit.
107 */
108 public void setDimmed(boolean dimmed) {
109 mDimmed = dimmed;
110 }
111
John Spurlockbf370992014-06-17 13:58:31 -0400112 /** In dark mode, we draw as little as possible, assuming a black background */
113 public void setDark(boolean dark) {
114 mDark = dark;
115 }
116
Jorim Jaggiae441282014-08-01 02:45:18 +0200117 public void setHideSensitive(boolean hideSensitive) {
118 mHideSensitive = hideSensitive;
119 }
120
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200121 /**
122 * In dimmed mode, a child can be activated, which happens on the first tap of the double-tap
123 * interaction. This child is then scaled normally and its background is fully opaque.
124 */
Selim Cineka32ab602014-06-11 15:06:01 +0200125 public void setActivatedChild(ActivatableNotificationView activatedChild) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200126 mActivatedChild = activatedChild;
127 }
128
129 public boolean isDimmed() {
130 return mDimmed;
131 }
132
John Spurlockbf370992014-06-17 13:58:31 -0400133 public boolean isDark() {
134 return mDark;
135 }
136
Jorim Jaggiae441282014-08-01 02:45:18 +0200137 public boolean isHideSensitive() {
138 return mHideSensitive;
139 }
140
Selim Cineka32ab602014-06-11 15:06:01 +0200141 public ActivatableNotificationView getActivatedChild() {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200142 return mActivatedChild;
143 }
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200144
145 public void setOverScrollAmount(float amount, boolean onTop) {
146 if (onTop) {
147 mOverScrollTopAmount = amount;
148 } else {
149 mOverScrollBottomAmount = amount;
150 }
151 }
152
153 public float getOverScrollAmount(boolean top) {
154 return top ? mOverScrollTopAmount : mOverScrollBottomAmount;
155 }
Selim Cinekc27437b2014-05-14 10:23:33 +0200156
Selim Cinekdb167372016-11-17 15:41:17 -0800157 public int getSpeedBumpIndex() {
158 return mSpeedBumpIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200159 }
160
Selim Cinekdb167372016-11-17 15:41:17 -0800161 public void setSpeedBumpIndex(int shelfIndex) {
162 mSpeedBumpIndex = shelfIndex;
Selim Cinekc27437b2014-05-14 10:23:33 +0200163 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700164
165 public void setHeadsUpManager(HeadsUpManager headsUpManager) {
166 mHeadsUpManager = headsUpManager;
167 }
168
Selim Cineka59ecc32015-04-07 10:51:49 -0700169 public float getStackTranslation() {
170 return mStackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700171 }
172
Selim Cineka59ecc32015-04-07 10:51:49 -0700173 public void setStackTranslation(float stackTranslation) {
174 mStackTranslation = stackTranslation;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700175 }
176
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700177 public void setLayoutHeight(int layoutHeight) {
178 mLayoutHeight = layoutHeight;
179 }
180
Selim Cineka59ecc32015-04-07 10:51:49 -0700181 public float getTopPadding() {
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700182 return mTopPadding;
183 }
184
185 public void setTopPadding(int topPadding) {
186 mTopPadding = topPadding;
187 }
188
189 public int getInnerHeight() {
Selim Cinek91d4cba2016-11-10 19:59:48 -0800190 return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding, mLayoutMinHeight);
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700191 }
192
193 public boolean isShadeExpanded() {
194 return mShadeExpanded;
195 }
196
197 public void setShadeExpanded(boolean shadeExpanded) {
198 mShadeExpanded = shadeExpanded;
199 }
200
201 public void setMaxHeadsUpTranslation(float maxHeadsUpTranslation) {
202 mMaxHeadsUpTranslation = maxHeadsUpTranslation;
203 }
204
205 public float getMaxHeadsUpTranslation() {
206 return mMaxHeadsUpTranslation;
207 }
Selim Cineka59ecc32015-04-07 10:51:49 -0700208
Selim Cinek9c17b772015-07-07 20:37:09 -0700209 public void setDismissAllInProgress(boolean dismissAllInProgress) {
210 mDismissAllInProgress = dismissAllInProgress;
211 }
212
213 public boolean isDismissAllInProgress() {
214 return mDismissAllInProgress;
215 }
Selim Cinekbc243a92016-09-27 16:35:13 -0700216
217 public void setLayoutMinHeight(int layoutMinHeight) {
218 mLayoutMinHeight = layoutMinHeight;
219 }
Selim Cinek281c2022016-10-13 19:14:43 -0700220
221 public void setShelf(NotificationShelf shelf) {
222 mShelf = shelf;
223 }
224
225 public NotificationShelf getShelf() {
226 return mShelf;
227 }
Selim Cinek91d4cba2016-11-10 19:59:48 -0800228
229 public void setLayoutMaxHeight(int maxLayoutHeight) {
230 mMaxLayoutHeight = maxLayoutHeight;
231 }
Selim Cinekdb167372016-11-17 15:41:17 -0800232
233 /**
234 * Sets the last visible view of the host layout, that has a background, i.e the very last
235 * view in the shade, without the clear all button.
236 */
237 public void setLastVisibleBackgroundChild(
238 ActivatableNotificationView lastVisibleBackgroundChild) {
239 mLastVisibleBackgroundChild = lastVisibleBackgroundChild;
240 }
241
242 public ActivatableNotificationView getLastVisibleBackgroundChild() {
243 return mLastVisibleBackgroundChild;
244 }
Selim Cinek727903c2016-12-06 17:28:10 -0800245
246 public void setCurrentScrollVelocity(float currentScrollVelocity) {
247 mCurrentScrollVelocity = currentScrollVelocity;
248 }
249
250 public float getCurrentScrollVelocity() {
251 return mCurrentScrollVelocity;
252 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200253}