Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 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 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 19 | import android.content.Context; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 20 | import android.view.View; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 21 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 22 | import com.android.systemui.R; |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 23 | import com.android.systemui.statusbar.ActivatableNotificationView; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 24 | import com.android.systemui.statusbar.NotificationShelf; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 25 | import com.android.systemui.statusbar.policy.HeadsUpManager; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 26 | |
| 27 | import java.util.ArrayList; |
| 28 | |
| 29 | /** |
| 30 | * A global state to track all input states for the algorithm. |
| 31 | */ |
| 32 | public class AmbientState { |
| 33 | private ArrayList<View> mDraggedViews = new ArrayList<View>(); |
| 34 | private int mScrollY; |
| 35 | private boolean mDimmed; |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 36 | private ActivatableNotificationView mActivatedChild; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 37 | private float mOverScrollTopAmount; |
| 38 | private float mOverScrollBottomAmount; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 39 | private int mSpeedBumpIndex = -1; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 40 | private boolean mDark; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 41 | private boolean mHideSensitive; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 42 | private HeadsUpManager mHeadsUpManager; |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 43 | private float mStackTranslation; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 44 | private int mLayoutHeight; |
| 45 | private int mTopPadding; |
| 46 | private boolean mShadeExpanded; |
| 47 | private float mMaxHeadsUpTranslation; |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 48 | private boolean mDismissAllInProgress; |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 49 | private int mLayoutMinHeight; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 50 | private NotificationShelf mShelf; |
| 51 | private int mZDistanceBetweenElements; |
| 52 | private int mBaseZHeight; |
Selim Cinek | 91d4cba | 2016-11-10 19:59:48 -0800 | [diff] [blame] | 53 | private int mMaxLayoutHeight; |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 54 | private ActivatableNotificationView mLastVisibleBackgroundChild; |
Selim Cinek | 727903c | 2016-12-06 17:28:10 -0800 | [diff] [blame^] | 55 | private float mCurrentScrollVelocity; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 56 | |
| 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 Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 67 | mBaseZHeight = 4 * mZDistanceBetweenElements; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 68 | } |
| 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 Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 83 | |
| 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 Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 112 | /** 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 Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 117 | public void setHideSensitive(boolean hideSensitive) { |
| 118 | mHideSensitive = hideSensitive; |
| 119 | } |
| 120 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 121 | /** |
| 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 Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 125 | public void setActivatedChild(ActivatableNotificationView activatedChild) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 126 | mActivatedChild = activatedChild; |
| 127 | } |
| 128 | |
| 129 | public boolean isDimmed() { |
| 130 | return mDimmed; |
| 131 | } |
| 132 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 133 | public boolean isDark() { |
| 134 | return mDark; |
| 135 | } |
| 136 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 137 | public boolean isHideSensitive() { |
| 138 | return mHideSensitive; |
| 139 | } |
| 140 | |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 141 | public ActivatableNotificationView getActivatedChild() { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 142 | return mActivatedChild; |
| 143 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 144 | |
| 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 Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 156 | |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 157 | public int getSpeedBumpIndex() { |
| 158 | return mSpeedBumpIndex; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 159 | } |
| 160 | |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 161 | public void setSpeedBumpIndex(int shelfIndex) { |
| 162 | mSpeedBumpIndex = shelfIndex; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 163 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 164 | |
| 165 | public void setHeadsUpManager(HeadsUpManager headsUpManager) { |
| 166 | mHeadsUpManager = headsUpManager; |
| 167 | } |
| 168 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 169 | public float getStackTranslation() { |
| 170 | return mStackTranslation; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 173 | public void setStackTranslation(float stackTranslation) { |
| 174 | mStackTranslation = stackTranslation; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 177 | public void setLayoutHeight(int layoutHeight) { |
| 178 | mLayoutHeight = layoutHeight; |
| 179 | } |
| 180 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 181 | public float getTopPadding() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 182 | return mTopPadding; |
| 183 | } |
| 184 | |
| 185 | public void setTopPadding(int topPadding) { |
| 186 | mTopPadding = topPadding; |
| 187 | } |
| 188 | |
| 189 | public int getInnerHeight() { |
Selim Cinek | 91d4cba | 2016-11-10 19:59:48 -0800 | [diff] [blame] | 190 | return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding, mLayoutMinHeight); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 191 | } |
| 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 Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 208 | |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 209 | public void setDismissAllInProgress(boolean dismissAllInProgress) { |
| 210 | mDismissAllInProgress = dismissAllInProgress; |
| 211 | } |
| 212 | |
| 213 | public boolean isDismissAllInProgress() { |
| 214 | return mDismissAllInProgress; |
| 215 | } |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 216 | |
| 217 | public void setLayoutMinHeight(int layoutMinHeight) { |
| 218 | mLayoutMinHeight = layoutMinHeight; |
| 219 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 220 | |
| 221 | public void setShelf(NotificationShelf shelf) { |
| 222 | mShelf = shelf; |
| 223 | } |
| 224 | |
| 225 | public NotificationShelf getShelf() { |
| 226 | return mShelf; |
| 227 | } |
Selim Cinek | 91d4cba | 2016-11-10 19:59:48 -0800 | [diff] [blame] | 228 | |
| 229 | public void setLayoutMaxHeight(int maxLayoutHeight) { |
| 230 | mMaxLayoutHeight = maxLayoutHeight; |
| 231 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 232 | |
| 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 Cinek | 727903c | 2016-12-06 17:28:10 -0800 | [diff] [blame^] | 245 | |
| 246 | public void setCurrentScrollVelocity(float currentScrollVelocity) { |
| 247 | mCurrentScrollVelocity = currentScrollVelocity; |
| 248 | } |
| 249 | |
| 250 | public float getCurrentScrollVelocity() { |
| 251 | return mCurrentScrollVelocity; |
| 252 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 253 | } |