1 /*
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 
17 package com.android.systemui.statusbar.stack;
18 
19 import android.content.Context;
20 import android.view.View;
21 
22 import com.android.systemui.R;
23 import com.android.systemui.statusbar.ActivatableNotificationView;
24 import com.android.systemui.statusbar.NotificationShelf;
25 import com.android.systemui.statusbar.StatusBarState;
26 import com.android.systemui.statusbar.policy.HeadsUpManager;
27 
28 import java.util.ArrayList;
29 
30 /**
31  * A global state to track all input states for the algorithm.
32  */
33 public class AmbientState {
34     private ArrayList<View> mDraggedViews = new ArrayList<View>();
35     private int mScrollY;
36     private boolean mDimmed;
37     private ActivatableNotificationView mActivatedChild;
38     private float mOverScrollTopAmount;
39     private float mOverScrollBottomAmount;
40     private int mSpeedBumpIndex = -1;
41     private boolean mDark;
42     private boolean mHideSensitive;
43     private HeadsUpManager mHeadsUpManager;
44     private float mStackTranslation;
45     private int mLayoutHeight;
46     private int mTopPadding;
47     private boolean mShadeExpanded;
48     private float mMaxHeadsUpTranslation;
49     private boolean mDismissAllInProgress;
50     private int mLayoutMinHeight;
51     private NotificationShelf mShelf;
52     private int mZDistanceBetweenElements;
53     private int mBaseZHeight;
54     private int mMaxLayoutHeight;
55     private ActivatableNotificationView mLastVisibleBackgroundChild;
56     private float mCurrentScrollVelocity;
57     private int mStatusBarState;
58     private float mExpandingVelocity;
59     private boolean mPanelTracking;
60     private boolean mExpansionChanging;
61     private boolean mPanelFullWidth;
62     private boolean mHasPulsingNotifications;
63     private boolean mUnlockHintRunning;
64 
AmbientState(Context context)65     public AmbientState(Context context) {
66         reload(context);
67     }
68 
69     /**
70      * Reload the dimens e.g. if the density changed.
71      */
reload(Context context)72     public void reload(Context context) {
73         mZDistanceBetweenElements = Math.max(1, context.getResources()
74                 .getDimensionPixelSize(R.dimen.z_distance_between_notifications));
75         mBaseZHeight = 4 * mZDistanceBetweenElements;
76     }
77 
78     /**
79      * @return the basic Z height on which notifications remain.
80      */
getBaseZHeight()81     public int getBaseZHeight() {
82         return mBaseZHeight;
83     }
84 
85     /**
86      * @return the distance in Z between two overlaying notifications.
87      */
getZDistanceBetweenElements()88     public int getZDistanceBetweenElements() {
89         return mZDistanceBetweenElements;
90     }
91 
getScrollY()92     public int getScrollY() {
93         return mScrollY;
94     }
95 
setScrollY(int scrollY)96     public void setScrollY(int scrollY) {
97         this.mScrollY = scrollY;
98     }
99 
onBeginDrag(View view)100     public void onBeginDrag(View view) {
101         mDraggedViews.add(view);
102     }
103 
onDragFinished(View view)104     public void onDragFinished(View view) {
105         mDraggedViews.remove(view);
106     }
107 
getDraggedViews()108     public ArrayList<View> getDraggedViews() {
109         return mDraggedViews;
110     }
111 
112     /**
113      * @param dimmed Whether we are in a dimmed state (on the lockscreen), where the backgrounds are
114      *               translucent and everything is scaled back a bit.
115      */
setDimmed(boolean dimmed)116     public void setDimmed(boolean dimmed) {
117         mDimmed = dimmed;
118     }
119 
120     /** In dark mode, we draw as little as possible, assuming a black background */
setDark(boolean dark)121     public void setDark(boolean dark) {
122         mDark = dark;
123     }
124 
setHideSensitive(boolean hideSensitive)125     public void setHideSensitive(boolean hideSensitive) {
126         mHideSensitive = hideSensitive;
127     }
128 
129     /**
130      * In dimmed mode, a child can be activated, which happens on the first tap of the double-tap
131      * interaction. This child is then scaled normally and its background is fully opaque.
132      */
setActivatedChild(ActivatableNotificationView activatedChild)133     public void setActivatedChild(ActivatableNotificationView activatedChild) {
134         mActivatedChild = activatedChild;
135     }
136 
isDimmed()137     public boolean isDimmed() {
138         return mDimmed;
139     }
140 
isDark()141     public boolean isDark() {
142         return mDark;
143     }
144 
isHideSensitive()145     public boolean isHideSensitive() {
146         return mHideSensitive;
147     }
148 
getActivatedChild()149     public ActivatableNotificationView getActivatedChild() {
150         return mActivatedChild;
151     }
152 
setOverScrollAmount(float amount, boolean onTop)153     public void setOverScrollAmount(float amount, boolean onTop) {
154         if (onTop) {
155             mOverScrollTopAmount = amount;
156         } else {
157             mOverScrollBottomAmount = amount;
158         }
159     }
160 
getOverScrollAmount(boolean top)161     public float getOverScrollAmount(boolean top) {
162         return top ? mOverScrollTopAmount : mOverScrollBottomAmount;
163     }
164 
getSpeedBumpIndex()165     public int getSpeedBumpIndex() {
166         return mSpeedBumpIndex;
167     }
168 
setSpeedBumpIndex(int shelfIndex)169     public void setSpeedBumpIndex(int shelfIndex) {
170         mSpeedBumpIndex = shelfIndex;
171     }
172 
setHeadsUpManager(HeadsUpManager headsUpManager)173     public void setHeadsUpManager(HeadsUpManager headsUpManager) {
174         mHeadsUpManager = headsUpManager;
175     }
176 
getStackTranslation()177     public float getStackTranslation() {
178         return mStackTranslation;
179     }
180 
setStackTranslation(float stackTranslation)181     public void setStackTranslation(float stackTranslation) {
182         mStackTranslation = stackTranslation;
183     }
184 
setLayoutHeight(int layoutHeight)185     public void setLayoutHeight(int layoutHeight) {
186         mLayoutHeight = layoutHeight;
187     }
188 
getTopPadding()189     public float getTopPadding() {
190         return mTopPadding;
191     }
192 
setTopPadding(int topPadding)193     public void setTopPadding(int topPadding) {
194         mTopPadding = topPadding;
195     }
196 
getInnerHeight()197     public int getInnerHeight() {
198         return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding, mLayoutMinHeight);
199     }
200 
isShadeExpanded()201     public boolean isShadeExpanded() {
202         return mShadeExpanded;
203     }
204 
setShadeExpanded(boolean shadeExpanded)205     public void setShadeExpanded(boolean shadeExpanded) {
206         mShadeExpanded = shadeExpanded;
207     }
208 
setMaxHeadsUpTranslation(float maxHeadsUpTranslation)209     public void setMaxHeadsUpTranslation(float maxHeadsUpTranslation) {
210         mMaxHeadsUpTranslation = maxHeadsUpTranslation;
211     }
212 
getMaxHeadsUpTranslation()213     public float getMaxHeadsUpTranslation() {
214         return mMaxHeadsUpTranslation;
215     }
216 
setDismissAllInProgress(boolean dismissAllInProgress)217     public void setDismissAllInProgress(boolean dismissAllInProgress) {
218         mDismissAllInProgress = dismissAllInProgress;
219     }
220 
isDismissAllInProgress()221     public boolean isDismissAllInProgress() {
222         return mDismissAllInProgress;
223     }
224 
setLayoutMinHeight(int layoutMinHeight)225     public void setLayoutMinHeight(int layoutMinHeight) {
226         mLayoutMinHeight = layoutMinHeight;
227     }
228 
setShelf(NotificationShelf shelf)229     public void setShelf(NotificationShelf shelf) {
230         mShelf = shelf;
231     }
232 
getShelf()233     public NotificationShelf getShelf() {
234         return mShelf;
235     }
236 
setLayoutMaxHeight(int maxLayoutHeight)237     public void setLayoutMaxHeight(int maxLayoutHeight) {
238         mMaxLayoutHeight = maxLayoutHeight;
239     }
240 
241     /**
242      * Sets the last visible view of the host layout, that has a background, i.e the very last
243      * view in the shade, without the clear all button.
244      */
setLastVisibleBackgroundChild( ActivatableNotificationView lastVisibleBackgroundChild)245     public void setLastVisibleBackgroundChild(
246             ActivatableNotificationView lastVisibleBackgroundChild) {
247         mLastVisibleBackgroundChild = lastVisibleBackgroundChild;
248     }
249 
getLastVisibleBackgroundChild()250     public ActivatableNotificationView getLastVisibleBackgroundChild() {
251         return mLastVisibleBackgroundChild;
252     }
253 
setCurrentScrollVelocity(float currentScrollVelocity)254     public void setCurrentScrollVelocity(float currentScrollVelocity) {
255         mCurrentScrollVelocity = currentScrollVelocity;
256     }
257 
getCurrentScrollVelocity()258     public float getCurrentScrollVelocity() {
259         return mCurrentScrollVelocity;
260     }
261 
isOnKeyguard()262     public boolean isOnKeyguard() {
263         return mStatusBarState == StatusBarState.KEYGUARD;
264     }
265 
setStatusBarState(int statusBarState)266     public void setStatusBarState(int statusBarState) {
267         mStatusBarState = statusBarState;
268     }
269 
setExpandingVelocity(float expandingVelocity)270     public void setExpandingVelocity(float expandingVelocity) {
271         mExpandingVelocity = expandingVelocity;
272     }
273 
setExpansionChanging(boolean expansionChanging)274     public void setExpansionChanging(boolean expansionChanging) {
275         mExpansionChanging = expansionChanging;
276     }
277 
isExpansionChanging()278     public boolean isExpansionChanging() {
279         return mExpansionChanging;
280     }
281 
getExpandingVelocity()282     public float getExpandingVelocity() {
283         return mExpandingVelocity;
284     }
285 
setPanelTracking(boolean panelTracking)286     public void setPanelTracking(boolean panelTracking) {
287         mPanelTracking = panelTracking;
288     }
289 
hasPulsingNotifications()290     public boolean hasPulsingNotifications() {
291         return mHasPulsingNotifications;
292     }
293 
setHasPulsingNotifications(boolean hasPulsing)294     public void setHasPulsingNotifications(boolean hasPulsing) {
295         mHasPulsingNotifications = hasPulsing;
296     }
297 
isPanelTracking()298     public boolean isPanelTracking() {
299         return mPanelTracking;
300     }
301 
isPanelFullWidth()302     public boolean isPanelFullWidth() {
303         return mPanelFullWidth;
304     }
305 
setPanelFullWidth(boolean panelFullWidth)306     public void setPanelFullWidth(boolean panelFullWidth) {
307         mPanelFullWidth = panelFullWidth;
308     }
309 
setUnlockHintRunning(boolean unlockHintRunning)310     public void setUnlockHintRunning(boolean unlockHintRunning) {
311         mUnlockHintRunning = unlockHintRunning;
312     }
313 
isUnlockHintRunning()314     public boolean isUnlockHintRunning() {
315         return mUnlockHintRunning;
316     }
317 }
318