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 | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 39 | private int mShelfIndex = -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 | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 54 | |
| 55 | public AmbientState(Context context) { |
| 56 | reload(context); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * Reload the dimens e.g. if the density changed. |
| 61 | */ |
| 62 | public void reload(Context context) { |
| 63 | mZDistanceBetweenElements = Math.max(1, context.getResources() |
| 64 | .getDimensionPixelSize(R.dimen.z_distance_between_notifications)); |
| 65 | mBaseZHeight = (StackScrollAlgorithm.MAX_ITEMS_IN_BOTTOM_STACK + 1) |
| 66 | * mZDistanceBetweenElements; |
| 67 | } |
| 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 Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 82 | |
| 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 Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 111 | /** 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 Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 116 | public void setHideSensitive(boolean hideSensitive) { |
| 117 | mHideSensitive = hideSensitive; |
| 118 | } |
| 119 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 120 | /** |
| 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 Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 124 | public void setActivatedChild(ActivatableNotificationView activatedChild) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 125 | mActivatedChild = activatedChild; |
| 126 | } |
| 127 | |
| 128 | public boolean isDimmed() { |
| 129 | return mDimmed; |
| 130 | } |
| 131 | |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 132 | public boolean isDark() { |
| 133 | return mDark; |
| 134 | } |
| 135 | |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 136 | public boolean isHideSensitive() { |
| 137 | return mHideSensitive; |
| 138 | } |
| 139 | |
Selim Cinek | a32ab60 | 2014-06-11 15:06:01 +0200 | [diff] [blame] | 140 | public ActivatableNotificationView getActivatedChild() { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 141 | return mActivatedChild; |
| 142 | } |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 143 | |
| 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 Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 155 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 156 | public int getShelfIndex() { |
| 157 | return mShelfIndex; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 158 | } |
| 159 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 160 | public void setShelfIndex(int shelfIndex) { |
| 161 | mShelfIndex = shelfIndex; |
Selim Cinek | c27437b | 2014-05-14 10:23:33 +0200 | [diff] [blame] | 162 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 163 | |
| 164 | public void setHeadsUpManager(HeadsUpManager headsUpManager) { |
| 165 | mHeadsUpManager = headsUpManager; |
| 166 | } |
| 167 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 168 | public float getStackTranslation() { |
| 169 | return mStackTranslation; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 172 | public void setStackTranslation(float stackTranslation) { |
| 173 | mStackTranslation = stackTranslation; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 174 | } |
| 175 | |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 176 | public void setLayoutHeight(int layoutHeight) { |
| 177 | mLayoutHeight = layoutHeight; |
| 178 | } |
| 179 | |
Selim Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 180 | public float getTopPadding() { |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 181 | return mTopPadding; |
| 182 | } |
| 183 | |
| 184 | public void setTopPadding(int topPadding) { |
| 185 | mTopPadding = topPadding; |
| 186 | } |
| 187 | |
| 188 | public int getInnerHeight() { |
Selim Cinek | 91d4cba | 2016-11-10 19:59:48 -0800 | [diff] [blame^] | 189 | return Math.max(Math.min(mLayoutHeight, mMaxLayoutHeight) - mTopPadding, mLayoutMinHeight); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 190 | } |
| 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 Cinek | a59ecc3 | 2015-04-07 10:51:49 -0700 | [diff] [blame] | 207 | |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 208 | public void setDismissAllInProgress(boolean dismissAllInProgress) { |
| 209 | mDismissAllInProgress = dismissAllInProgress; |
| 210 | } |
| 211 | |
| 212 | public boolean isDismissAllInProgress() { |
| 213 | return mDismissAllInProgress; |
| 214 | } |
Selim Cinek | bc243a9 | 2016-09-27 16:35:13 -0700 | [diff] [blame] | 215 | |
| 216 | public void setLayoutMinHeight(int layoutMinHeight) { |
| 217 | mLayoutMinHeight = layoutMinHeight; |
| 218 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 219 | |
| 220 | public void setShelf(NotificationShelf shelf) { |
| 221 | mShelf = shelf; |
| 222 | } |
| 223 | |
| 224 | public NotificationShelf getShelf() { |
| 225 | return mShelf; |
| 226 | } |
Selim Cinek | 91d4cba | 2016-11-10 19:59:48 -0800 | [diff] [blame^] | 227 | |
| 228 | public void setLayoutMaxHeight(int maxLayoutHeight) { |
| 229 | mMaxLayoutHeight = maxLayoutHeight; |
| 230 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 231 | } |