blob: 09c6968867b8033ac0fad11b6d9ba27389245088 [file] [log] [blame]
Selim Cinek67b22602014-03-10 15:40:16 +01001/*
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
Rohan Shah20790b82018-07-02 17:21:04 -070017package com.android.systemui.statusbar.notification.stack;
Selim Cinek67b22602014-03-10 15:40:16 +010018
19import android.content.Context;
Anthony Chen9fe1ee72017-04-07 13:53:37 -070020import android.content.res.Resources;
Christoph Studer6e3eceb2014-04-01 18:40:27 +020021import android.util.Log;
Selim Cinek67b22602014-03-10 15:40:16 +010022import android.view.View;
23import android.view.ViewGroup;
Gus Prevase2d6f042018-10-17 15:25:30 -040024
Selim Cinek67b22602014-03-10 15:40:16 +010025import com.android.systemui.R;
Selim Cinekcde90e52016-12-22 21:01:49 +010026import com.android.systemui.statusbar.EmptyShadeView;
Gus Prevase2d6f042018-10-17 15:25:30 -040027import com.android.systemui.statusbar.NotificationShelf;
28import com.android.systemui.statusbar.notification.NotificationUtils;
Rohan Shah20790b82018-07-02 17:21:04 -070029import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow;
30import com.android.systemui.statusbar.notification.row.ExpandableView;
31import com.android.systemui.statusbar.notification.row.FooterView;
Selim Cinek67b22602014-03-10 15:40:16 +010032
Jorim Jaggid4a57442014-04-10 02:45:55 +020033import java.util.ArrayList;
Selim Cinek42357e02016-02-24 18:48:01 -080034import java.util.HashMap;
Selim Cinekb5605e52015-02-20 18:21:41 +010035import java.util.List;
Jorim Jaggid4a57442014-04-10 02:45:55 +020036
Selim Cinek67b22602014-03-10 15:40:16 +010037/**
Rohan Shah20790b82018-07-02 17:21:04 -070038 * The Algorithm of the {@link com.android.systemui.statusbar.notification.stack
Selim Cinek67b22602014-03-10 15:40:16 +010039 * .NotificationStackScrollLayout} which can be queried for {@link com.android.systemui.statusbar
40 * .stack.StackScrollState}
41 */
42public class StackScrollAlgorithm {
43
Gus Prevas0fa58d62019-01-11 13:58:40 -050044 static final boolean ANCHOR_SCROLLING = false;
45
Christoph Studer6e3eceb2014-04-01 18:40:27 +020046 private static final String LOG_TAG = "StackScrollAlgorithm";
Dave Mankoffa4d195d2018-11-16 13:33:27 -050047 private final ViewGroup mHostView;
Christoph Studer6e3eceb2014-04-01 18:40:27 +020048
Selim Cinek67b22602014-03-10 15:40:16 +010049 private int mPaddingBetweenElements;
Selim Cinek61633a82016-01-25 15:54:10 -080050 private int mIncreasedPaddingBetweenElements;
Gus Prevase2d6f042018-10-17 15:25:30 -040051 private int mGapHeight;
Selim Cinek67b22602014-03-10 15:40:16 +010052 private int mCollapsedSize;
Selim Cinek67b22602014-03-10 15:40:16 +010053
Selim Cinek67b22602014-03-10 15:40:16 +010054 private StackScrollAlgorithmState mTempAlgorithmState = new StackScrollAlgorithmState();
Selim Cinek1685e632014-04-08 02:27:49 +020055 private boolean mIsExpanded;
Anthony Chen9fe1ee72017-04-07 13:53:37 -070056 private boolean mClipNotificationScrollToTop;
Selim Cinekcafa87f2016-10-26 17:00:17 -070057 private int mStatusBarHeight;
Selim Cinekaa9db1f2018-02-27 17:35:47 -080058 private float mHeadsUpInset;
Selim Cinek99e9adf2018-03-15 09:17:47 -070059 private int mPinnedZTranslationExtra;
Selim Cinek67b22602014-03-10 15:40:16 +010060
Ned Burns9eb06332019-04-23 16:02:12 -040061 public StackScrollAlgorithm(
62 Context context,
63 ViewGroup hostView) {
Dave Mankoffa4d195d2018-11-16 13:33:27 -050064 mHostView = hostView;
Selim Cinekaf0dc312015-12-15 17:01:44 -080065 initView(context);
Selim Cinek34c0a8d2014-05-12 00:01:43 +020066 }
67
Selim Cinekaf0dc312015-12-15 17:01:44 -080068 public void initView(Context context) {
69 initConstants(context);
Selim Cinek34c0a8d2014-05-12 00:01:43 +020070 }
71
Selim Cinek67b22602014-03-10 15:40:16 +010072 private void initConstants(Context context) {
Anthony Chen9fe1ee72017-04-07 13:53:37 -070073 Resources res = context.getResources();
74 mPaddingBetweenElements = res.getDimensionPixelSize(
Selim Cinekdb167372016-11-17 15:41:17 -080075 R.dimen.notification_divider_height);
Anthony Chen9fe1ee72017-04-07 13:53:37 -070076 mIncreasedPaddingBetweenElements =
77 res.getDimensionPixelSize(R.dimen.notification_divider_height_increased);
78 mCollapsedSize = res.getDimensionPixelSize(R.dimen.notification_min_height);
79 mStatusBarHeight = res.getDimensionPixelSize(R.dimen.status_bar_height);
80 mClipNotificationScrollToTop = res.getBoolean(R.bool.config_clipNotificationScrollToTop);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080081 mHeadsUpInset = mStatusBarHeight + res.getDimensionPixelSize(
82 R.dimen.heads_up_status_bar_padding);
Selim Cinek99e9adf2018-03-15 09:17:47 -070083 mPinnedZTranslationExtra = res.getDimensionPixelSize(
84 R.dimen.heads_up_pinned_elevation);
Gus Prevase2d6f042018-10-17 15:25:30 -040085 mGapHeight = res.getDimensionPixelSize(R.dimen.notification_section_divider_height);
Jorim Jaggid7c1fae2014-08-13 18:27:47 +020086 }
Selim Cinek67b22602014-03-10 15:40:16 +010087
Dave Mankoffa4d195d2018-11-16 13:33:27 -050088 /**
89 * Updates the state of all children in the hostview based on this algorithm.
90 */
91 public void resetViewStates(AmbientState ambientState) {
Selim Cinek67b22602014-03-10 15:40:16 +010092 // The state of the local variables are saved in an algorithmState to easily subdivide it
93 // into multiple phases.
94 StackScrollAlgorithmState algorithmState = mTempAlgorithmState;
95
96 // First we reset the view states to their default values.
Dave Mankoffa4d195d2018-11-16 13:33:27 -050097 resetChildViewStates();
Selim Cinek67b22602014-03-10 15:40:16 +010098
Dave Mankoffa4d195d2018-11-16 13:33:27 -050099 initAlgorithmState(mHostView, algorithmState, ambientState);
Selim Cinek1408eb52014-06-02 14:45:38 +0200100
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500101 updatePositionsForState(algorithmState, ambientState);
Selim Cinek67b22602014-03-10 15:40:16 +0100102
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500103 updateZValuesForState(algorithmState, ambientState);
Selim Cinek3776fe02016-02-04 13:32:43 -0800104
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500105 updateHeadsUpStates(algorithmState, ambientState);
Selim Cinek5040f2e2019-02-14 18:22:42 -0800106 updatePulsingStates(algorithmState, ambientState);
Selim Cinekeb973562014-05-02 17:07:49 +0200107
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500108 updateDimmedActivatedHideSensitive(ambientState, algorithmState);
109 updateClipping(algorithmState, ambientState);
110 updateSpeedBumpState(algorithmState, ambientState);
111 updateShelfState(ambientState);
112 getNotificationChildrenStates(algorithmState, ambientState);
Selim Cinekb5605e52015-02-20 18:21:41 +0100113 }
114
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500115 private void resetChildViewStates() {
116 int numChildren = mHostView.getChildCount();
117 for (int i = 0; i < numChildren; i++) {
118 ExpandableView child = (ExpandableView) mHostView.getChildAt(i);
119 child.resetViewState();
120 }
121 }
122
123 private void getNotificationChildrenStates(StackScrollAlgorithmState algorithmState,
Selim Cinekc25989e2018-02-16 16:42:14 -0800124 AmbientState ambientState) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100125 int childCount = algorithmState.visibleChildren.size();
126 for (int i = 0; i < childCount; i++) {
127 ExpandableView v = algorithmState.visibleChildren.get(i);
128 if (v instanceof ExpandableNotificationRow) {
129 ExpandableNotificationRow row = (ExpandableNotificationRow) v;
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500130 row.updateChildrenStates(ambientState);
Selim Cinekb5605e52015-02-20 18:21:41 +0100131 }
132 }
Selim Cinek3d2b94bf2014-07-02 22:12:47 +0200133 }
134
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500135 private void updateSpeedBumpState(StackScrollAlgorithmState algorithmState,
136 AmbientState ambientState) {
Selim Cinek3d2b94bf2014-07-02 22:12:47 +0200137 int childCount = algorithmState.visibleChildren.size();
Selim Cinekdb167372016-11-17 15:41:17 -0800138 int belowSpeedBump = ambientState.getSpeedBumpIndex();
Selim Cinek3d2b94bf2014-07-02 22:12:47 +0200139 for (int i = 0; i < childCount; i++) {
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500140 ExpandableView child = algorithmState.visibleChildren.get(i);
141 ExpandableViewState childViewState = child.getViewState();
Selim Cinek3107cfa2014-07-22 15:24:29 +0200142
143 // The speed bump can also be gone, so equality needs to be taken when comparing
144 // indices.
Selim Cinekdb167372016-11-17 15:41:17 -0800145 childViewState.belowSpeedBump = i >= belowSpeedBump;
Selim Cinek3d2b94bf2014-07-02 22:12:47 +0200146 }
Selim Cinekdb167372016-11-17 15:41:17 -0800147
148 }
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500149
150 private void updateShelfState(AmbientState ambientState) {
Selim Cinek281c2022016-10-13 19:14:43 -0700151 NotificationShelf shelf = ambientState.getShelf();
Eliot Courtney5d3d2d02018-01-18 15:59:03 +0900152 if (shelf != null) {
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500153 shelf.updateState(ambientState);
Eliot Courtney5d3d2d02018-01-18 15:59:03 +0900154 }
Selim Cinekf54090e2014-06-17 17:24:51 -0700155 }
156
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500157 private void updateClipping(StackScrollAlgorithmState algorithmState,
158 AmbientState ambientState) {
Selim Cinek355652a2016-12-07 13:32:12 -0800159 float drawStart = !ambientState.isOnKeyguard() ? ambientState.getTopPadding()
Selim Cinek2627d722018-01-19 12:16:49 -0800160 + ambientState.getStackTranslation() + ambientState.getExpandAnimationTopChange()
161 : 0;
Selim Cinek708a6c12014-05-28 14:16:02 +0200162 float previousNotificationEnd = 0;
163 float previousNotificationStart = 0;
Selim Cinek708a6c12014-05-28 14:16:02 +0200164 int childCount = algorithmState.visibleChildren.size();
165 for (int i = 0; i < childCount; i++) {
166 ExpandableView child = algorithmState.visibleChildren.get(i);
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500167 ExpandableViewState state = child.getViewState();
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100168 if (!child.mustStayOnScreen() || state.headsUpIsVisible) {
Selim Cinek3776fe02016-02-04 13:32:43 -0800169 previousNotificationEnd = Math.max(drawStart, previousNotificationEnd);
170 previousNotificationStart = Math.max(drawStart, previousNotificationStart);
171 }
Selim Cinek587cbf32016-01-19 11:36:18 -0800172 float newYTranslation = state.yTranslation;
173 float newHeight = state.height;
Selim Cinek708a6c12014-05-28 14:16:02 +0200174 float newNotificationEnd = newYTranslation + newHeight;
Mady Mellor53ac1ef2016-06-20 13:11:38 -0700175 boolean isHeadsUp = (child instanceof ExpandableNotificationRow)
176 && ((ExpandableNotificationRow) child).isPinned();
Anthony Chen9fe1ee72017-04-07 13:53:37 -0700177 if (mClipNotificationScrollToTop
178 && !state.inShelf && newYTranslation < previousNotificationEnd
Jorim Jaggi0fdf5742016-06-27 11:50:58 -0700179 && (!isHeadsUp || ambientState.isShadeExpanded())) {
Mady Mellorc128f222016-04-26 11:42:46 -0700180 // The previous view is overlapping on top, clip!
181 float overlapAmount = previousNotificationEnd - newYTranslation;
182 state.clipTopAmount = (int) overlapAmount;
Selim Cinekc5baa3e2014-10-29 19:04:19 +0100183 } else {
Mady Mellorc128f222016-04-26 11:42:46 -0700184 state.clipTopAmount = 0;
Selim Cinek9c17b772015-07-07 20:37:09 -0700185 }
186
Selim Cinek708a6c12014-05-28 14:16:02 +0200187 if (!child.isTransparent()) {
188 // Only update the previous values if we are not transparent,
189 // otherwise we would clip to a transparent view.
Mady Mellorc128f222016-04-26 11:42:46 -0700190 previousNotificationEnd = newNotificationEnd;
191 previousNotificationStart = newYTranslation;
Selim Cinek708a6c12014-05-28 14:16:02 +0200192 }
193 }
194 }
195
Selim Cinek9c17b772015-07-07 20:37:09 -0700196 public static boolean canChildBeDismissed(View v) {
Selim Cinek9e624e72016-07-20 13:46:49 -0700197 if (!(v instanceof ExpandableNotificationRow)) {
198 return false;
Selim Cinek38d429f2016-06-03 11:46:56 -0700199 }
Selim Cinek9e624e72016-07-20 13:46:49 -0700200 ExpandableNotificationRow row = (ExpandableNotificationRow) v;
Nadia Benbernou7a18c812019-02-08 16:23:10 -0500201 if (row.isBlockingHelperShowingAndTranslationFinished()) {
202 return true;
203 }
Aaron Heuckroth1dd67cb2018-06-14 14:28:08 -0400204 if (row.areGutsExposed() || !row.getEntry().hasFinishedInitialization()) {
Selim Cinek9e624e72016-07-20 13:46:49 -0700205 return false;
206 }
207 return row.canViewBeDismissed();
Selim Cinek9c17b772015-07-07 20:37:09 -0700208 }
209
Selim Cinek708a6c12014-05-28 14:16:02 +0200210 /**
Jorim Jaggiae441282014-08-01 02:45:18 +0200211 * Updates the dimmed, activated and hiding sensitive states of the children.
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200212 */
Jorim Jaggiae441282014-08-01 02:45:18 +0200213 private void updateDimmedActivatedHideSensitive(AmbientState ambientState,
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500214 StackScrollAlgorithmState algorithmState) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200215 boolean dimmed = ambientState.isDimmed();
Jorim Jaggiae441282014-08-01 02:45:18 +0200216 boolean hideSensitive = ambientState.isHideSensitive();
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200217 View activatedChild = ambientState.getActivatedChild();
218 int childCount = algorithmState.visibleChildren.size();
219 for (int i = 0; i < childCount; i++) {
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500220 ExpandableView child = algorithmState.visibleChildren.get(i);
221 ExpandableViewState childViewState = child.getViewState();
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200222 childViewState.dimmed = dimmed;
Jorim Jaggiae441282014-08-01 02:45:18 +0200223 childViewState.hideSensitive = hideSensitive;
Selim Cinekb89de4e2014-06-10 10:47:05 +0200224 boolean isActivatedChild = activatedChild == child;
Jorim Jaggi4538cee2014-09-09 15:21:38 +0200225 if (dimmed && isActivatedChild) {
Selim Cinek281c2022016-10-13 19:14:43 -0700226 childViewState.zTranslation += 2.0f * ambientState.getZDistanceBetweenElements();
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200227 }
228 }
Selim Cinekeb973562014-05-02 17:07:49 +0200229 }
230
231 /**
Selim Cinek61633a82016-01-25 15:54:10 -0800232 * Initialize the algorithm state like updating the visible children.
Jorim Jaggid4a57442014-04-10 02:45:55 +0200233 */
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500234 private void initAlgorithmState(ViewGroup hostView, StackScrollAlgorithmState state,
Selim Cinek3776fe02016-02-04 13:32:43 -0800235 AmbientState ambientState) {
Selim Cinek3776fe02016-02-04 13:32:43 -0800236 float bottomOverScroll = ambientState.getOverScrollAmount(false /* onTop */);
237
238 int scrollY = ambientState.getScrollY();
239
240 // Due to the overScroller, the stackscroller can have negative scroll state. This is
241 // already accounted for by the top padding and doesn't need an additional adaption
242 scrollY = Math.max(0, scrollY);
243 state.scrollY = (int) (scrollY + bottomOverScroll);
244
Gus Prevas0fa58d62019-01-11 13:58:40 -0500245 if (ANCHOR_SCROLLING) {
246 state.anchorViewY = (int) (ambientState.getAnchorViewY() - bottomOverScroll);
247 }
248
Selim Cinek3776fe02016-02-04 13:32:43 -0800249 //now init the visible children and update paddings
Jorim Jaggid4a57442014-04-10 02:45:55 +0200250 int childCount = hostView.getChildCount();
251 state.visibleChildren.clear();
252 state.visibleChildren.ensureCapacity(childCount);
Selim Cineka7ed2c12017-01-23 20:47:24 -0800253 state.paddingMap.clear();
Selim Cinekb036ca42015-02-20 15:56:28 +0100254 int notGoneIndex = 0;
Selim Cinek61633a82016-01-25 15:54:10 -0800255 ExpandableView lastView = null;
Selim Cinekc1d9ab22019-05-21 18:08:30 -0700256 int firstHiddenIndex = ambientState.isDozing()
Selim Cinekd96ed402017-07-28 18:19:03 -0700257 ? (ambientState.hasPulsingNotifications() ? 1 : 0)
258 : childCount;
259
260 // The goal here is to fill the padding map, by iterating over how much padding each child
261 // needs. The map is thereby reused, by first filling it with the padding amount and when
262 // iterating over it again, it's filled with the actual resolved value.
263
Jorim Jaggid4a57442014-04-10 02:45:55 +0200264 for (int i = 0; i < childCount; i++) {
Gus Prevas0fa58d62019-01-11 13:58:40 -0500265 if (ANCHOR_SCROLLING) {
266 if (i == ambientState.getAnchorViewIndex()) {
267 state.anchorViewIndex = state.visibleChildren.size();
268 }
269 }
Jorim Jaggibe565df2014-04-28 17:51:23 +0200270 ExpandableView v = (ExpandableView) hostView.getChildAt(i);
Jorim Jaggid4a57442014-04-10 02:45:55 +0200271 if (v.getVisibility() != View.GONE) {
Selim Cinek281c2022016-10-13 19:14:43 -0700272 if (v == ambientState.getShelf()) {
273 continue;
274 }
Selim Cinekd96ed402017-07-28 18:19:03 -0700275 if (i >= firstHiddenIndex) {
276 // we need normal padding now, to be in sync with what the stack calculates
277 lastView = null;
Selim Cinekd96ed402017-07-28 18:19:03 -0700278 }
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500279 notGoneIndex = updateNotGoneIndex(state, notGoneIndex, v);
Selim Cinekd96ed402017-07-28 18:19:03 -0700280 float increasedPadding = v.getIncreasedPaddingAmount();
Selim Cinek42357e02016-02-24 18:48:01 -0800281 if (increasedPadding != 0.0f) {
Selim Cineka7ed2c12017-01-23 20:47:24 -0800282 state.paddingMap.put(v, increasedPadding);
Selim Cinek61633a82016-01-25 15:54:10 -0800283 if (lastView != null) {
Selim Cineka7ed2c12017-01-23 20:47:24 -0800284 Float prevValue = state.paddingMap.get(lastView);
285 float newValue = getPaddingForValue(increasedPadding);
286 if (prevValue != null) {
287 float prevPadding = getPaddingForValue(prevValue);
288 if (increasedPadding > 0) {
289 newValue = NotificationUtils.interpolate(
290 prevPadding,
291 newValue,
292 increasedPadding);
293 } else if (prevValue > 0) {
294 newValue = NotificationUtils.interpolate(
295 newValue,
296 prevPadding,
297 prevValue);
298 }
299 }
300 state.paddingMap.put(lastView, newValue);
Selim Cinek61633a82016-01-25 15:54:10 -0800301 }
Selim Cineka7ed2c12017-01-23 20:47:24 -0800302 } else if (lastView != null) {
Selim Cinekd96ed402017-07-28 18:19:03 -0700303
304 // Let's now resolve the value to an actual padding
Selim Cineka7ed2c12017-01-23 20:47:24 -0800305 float newValue = getPaddingForValue(state.paddingMap.get(lastView));
306 state.paddingMap.put(lastView, newValue);
Selim Cinek61633a82016-01-25 15:54:10 -0800307 }
Selim Cinekb5605e52015-02-20 18:21:41 +0100308 if (v instanceof ExpandableNotificationRow) {
309 ExpandableNotificationRow row = (ExpandableNotificationRow) v;
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700310
311 // handle the notgoneIndex for the children as well
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500312 List<ExpandableNotificationRow> children = row.getNotificationChildren();
Selim Cinek83bc7832015-10-22 13:26:54 -0700313 if (row.isSummaryWithChildren() && children != null) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100314 for (ExpandableNotificationRow childRow : children) {
315 if (childRow.getVisibility() != View.GONE) {
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500316 ExpandableViewState childState = childRow.getViewState();
Selim Cinekb5605e52015-02-20 18:21:41 +0100317 childState.notGoneIndex = notGoneIndex;
318 notGoneIndex++;
319 }
320 }
321 }
322 }
Selim Cinek61633a82016-01-25 15:54:10 -0800323 lastView = v;
Jorim Jaggid4a57442014-04-10 02:45:55 +0200324 }
325 }
Selim Cinek2627d722018-01-19 12:16:49 -0800326 ExpandableNotificationRow expandingNotification = ambientState.getExpandingNotification();
327 state.indexOfExpandingNotification = expandingNotification != null
Selim Cinekc25989e2018-02-16 16:42:14 -0800328 ? expandingNotification.isChildInGroup()
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500329 ? state.visibleChildren.indexOf(expandingNotification.getNotificationParent())
330 : state.visibleChildren.indexOf(expandingNotification)
Selim Cinek2627d722018-01-19 12:16:49 -0800331 : -1;
Jorim Jaggid4a57442014-04-10 02:45:55 +0200332 }
333
Selim Cineka7ed2c12017-01-23 20:47:24 -0800334 private float getPaddingForValue(Float increasedPadding) {
335 if (increasedPadding == null) {
336 return mPaddingBetweenElements;
337 } else if (increasedPadding >= 0.0f) {
338 return NotificationUtils.interpolate(
339 mPaddingBetweenElements,
340 mIncreasedPaddingBetweenElements,
341 increasedPadding);
342 } else {
343 return NotificationUtils.interpolate(
344 0,
345 mPaddingBetweenElements,
346 1.0f + increasedPadding);
347 }
348 }
349
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500350 private int updateNotGoneIndex(StackScrollAlgorithmState state, int notGoneIndex,
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700351 ExpandableView v) {
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500352 ExpandableViewState viewState = v.getViewState();
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700353 viewState.notGoneIndex = notGoneIndex;
354 state.visibleChildren.add(v);
355 notGoneIndex++;
356 return notGoneIndex;
357 }
358
Jorim Jaggid4a57442014-04-10 02:45:55 +0200359 /**
Selim Cinek67b22602014-03-10 15:40:16 +0100360 * Determine the positions for the views. This is the main part of the algorithm.
361 *
Selim Cinek67b22602014-03-10 15:40:16 +0100362 * @param algorithmState The state in which the current pass of the algorithm is currently in
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500363 * @param ambientState The current ambient state
Selim Cinek67b22602014-03-10 15:40:16 +0100364 */
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500365 private void updatePositionsForState(StackScrollAlgorithmState algorithmState,
366 AmbientState ambientState) {
Gus Prevas0fa58d62019-01-11 13:58:40 -0500367 if (ANCHOR_SCROLLING) {
368 float currentYPosition = algorithmState.anchorViewY;
369 int childCount = algorithmState.visibleChildren.size();
370 for (int i = algorithmState.anchorViewIndex; i < childCount; i++) {
Gus Prevas0fa58d62019-01-11 13:58:40 -0500371 currentYPosition = updateChild(i, algorithmState, ambientState, currentYPosition,
372 false /* reverse */);
373 }
374 currentYPosition = algorithmState.anchorViewY;
375 for (int i = algorithmState.anchorViewIndex - 1; i >= 0; i--) {
Gus Prevas0fa58d62019-01-11 13:58:40 -0500376 currentYPosition = updateChild(i, algorithmState, ambientState, currentYPosition,
377 true /* reverse */);
378 }
379 } else {
380 // The y coordinate of the current child.
381 float currentYPosition = -algorithmState.scrollY;
382 int childCount = algorithmState.visibleChildren.size();
383 for (int i = 0; i < childCount; i++) {
Gus Prevas0fa58d62019-01-11 13:58:40 -0500384 currentYPosition = updateChild(i, algorithmState, ambientState, currentYPosition,
385 false /* reverse */);
386 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700387 }
388 }
389
Gus Prevas0fa58d62019-01-11 13:58:40 -0500390 /**
391 * Populates the {@link ExpandableViewState} for a single child.
392 *
393 * @param i The index of the child in
394 * {@link StackScrollAlgorithmState#visibleChildren}.
395 * @param algorithmState The overall output state of the algorithm.
396 * @param ambientState The input state provided to the algorithm.
397 * @param currentYPosition The Y position of the current pass of the algorithm. For a forward
398 * pass, this should be the top of the child; for a reverse pass, the
399 * bottom of the child.
400 * @param reverse Whether we're laying out children in the reverse direction (Y
401 * positions
402 * decreasing) instead of the forward direction (Y positions
403 * increasing).
404 * @return The Y position after laying out the child. This will be the {@code currentYPosition}
405 * for the next call to this method, after adjusting for any gaps between children.
406 */
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500407 protected float updateChild(
408 int i,
409 StackScrollAlgorithmState algorithmState,
410 AmbientState ambientState,
Gus Prevas0fa58d62019-01-11 13:58:40 -0500411 float currentYPosition,
412 boolean reverse) {
Muyuan Li87798022016-04-07 17:51:25 -0700413 ExpandableView child = algorithmState.visibleChildren.get(i);
Ned Burns9eb06332019-04-23 16:02:12 -0400414 final boolean applyGapHeight =
415 childNeedsGapHeight(ambientState.getSectionProvider(), algorithmState, i, child);
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500416 ExpandableViewState childViewState = child.getViewState();
Selim Cinekbbcebde2016-11-09 18:28:20 -0800417 childViewState.location = ExpandableViewState.LOCATION_UNKNOWN;
Ned Burns9eb06332019-04-23 16:02:12 -0400418
419 if (applyGapHeight && !reverse) {
420 currentYPosition += mGapHeight;
421 }
422
Muyuan Li87798022016-04-07 17:51:25 -0700423 int paddingAfterChild = getPaddingAfterChild(algorithmState, child);
424 int childHeight = getMaxAllowedChildHeight(child);
Gus Prevas0fa58d62019-01-11 13:58:40 -0500425 if (reverse) {
426 childViewState.yTranslation = currentYPosition - (childHeight + paddingAfterChild);
427 if (currentYPosition <= 0) {
428 childViewState.location = ExpandableViewState.LOCATION_HIDDEN_TOP;
429 }
430 } else {
431 childViewState.yTranslation = currentYPosition;
Gus Prevase2d6f042018-10-17 15:25:30 -0400432 }
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400433 boolean isFooterView = child instanceof FooterView;
Selim Cinekcde90e52016-12-22 21:01:49 +0100434 boolean isEmptyShadeView = child instanceof EmptyShadeView;
Muyuan Li87798022016-04-07 17:51:25 -0700435
Selim Cinekdb167372016-11-17 15:41:17 -0800436 childViewState.location = ExpandableViewState.LOCATION_MAIN_AREA;
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100437 float inset = ambientState.getTopPadding() + ambientState.getStackTranslation();
Selim Cinekc25989e2018-02-16 16:42:14 -0800438 if (i <= algorithmState.getIndexOfExpandingNotification()) {
Selim Cinek2627d722018-01-19 12:16:49 -0800439 inset += ambientState.getExpandAnimationTopChange();
440 }
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100441 if (child.mustStayOnScreen() && childViewState.yTranslation >= 0) {
442 // Even if we're not scrolled away we're in view and we're also not in the
443 // shelf. We can relax the constraints and let us scroll off the top!
444 float end = childViewState.yTranslation + childViewState.height + inset;
445 childViewState.headsUpIsVisible = end < ambientState.getMaxHeadsUpTranslation();
446 }
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400447 if (isFooterView) {
Selim Cinekdb167372016-11-17 15:41:17 -0800448 childViewState.yTranslation = Math.min(childViewState.yTranslation,
449 ambientState.getInnerHeight() - childHeight);
Selim Cinekcde90e52016-12-22 21:01:49 +0100450 } else if (isEmptyShadeView) {
451 childViewState.yTranslation = ambientState.getInnerHeight() - childHeight
452 + ambientState.getStackTranslation() * 0.25f;
Muyuan Li87798022016-04-07 17:51:25 -0700453 } else {
Selim Cinek2627d722018-01-19 12:16:49 -0800454 clampPositionToShelf(child, childViewState, ambientState);
Muyuan Li87798022016-04-07 17:51:25 -0700455 }
456
Gus Prevas0fa58d62019-01-11 13:58:40 -0500457 if (reverse) {
458 currentYPosition = childViewState.yTranslation;
Ned Burns9eb06332019-04-23 16:02:12 -0400459 if (applyGapHeight) {
460 currentYPosition -= mGapHeight;
461 }
Gus Prevas0fa58d62019-01-11 13:58:40 -0500462 } else {
463 currentYPosition = childViewState.yTranslation + childHeight + paddingAfterChild;
464 if (currentYPosition <= 0) {
465 childViewState.location = ExpandableViewState.LOCATION_HIDDEN_TOP;
466 }
Muyuan Li87798022016-04-07 17:51:25 -0700467 }
Selim Cinekbbcebde2016-11-09 18:28:20 -0800468 if (childViewState.location == ExpandableViewState.LOCATION_UNKNOWN) {
Muyuan Li87798022016-04-07 17:51:25 -0700469 Log.wtf(LOG_TAG, "Failed to assign location for child " + i);
470 }
471
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100472 childViewState.yTranslation += inset;
Muyuan Li87798022016-04-07 17:51:25 -0700473 return currentYPosition;
474 }
475
Ned Burns9eb06332019-04-23 16:02:12 -0400476 private boolean childNeedsGapHeight(
477 SectionProvider sectionProvider,
478 StackScrollAlgorithmState algorithmState,
479 int visibleIndex,
480 View child) {
481 boolean needsGapHeight = sectionProvider.beginsSection(child) && visibleIndex > 0;
482 if (ANCHOR_SCROLLING) {
483 needsGapHeight &= visibleIndex != algorithmState.anchorViewIndex;
484 }
485 return needsGapHeight;
486 }
487
Muyuan Li87798022016-04-07 17:51:25 -0700488 protected int getPaddingAfterChild(StackScrollAlgorithmState algorithmState,
Selim Cinek61633a82016-01-25 15:54:10 -0800489 ExpandableView child) {
Selim Cinek281c2022016-10-13 19:14:43 -0700490 return algorithmState.getPaddingAfterChild(child);
Selim Cinek61633a82016-01-25 15:54:10 -0800491 }
492
Selim Cinek5040f2e2019-02-14 18:22:42 -0800493 private void updatePulsingStates(StackScrollAlgorithmState algorithmState,
494 AmbientState ambientState) {
495 int childCount = algorithmState.visibleChildren.size();
496 for (int i = 0; i < childCount; i++) {
497 View child = algorithmState.visibleChildren.get(i);
498 if (!(child instanceof ExpandableNotificationRow)) {
499 continue;
500 }
501 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
Selim Cinekc3fec682019-06-06 18:11:07 -0700502 if (!row.showingPulsing() || (i == 0 && ambientState.isPulseExpanding())) {
Selim Cinek5040f2e2019-02-14 18:22:42 -0800503 continue;
504 }
505 ExpandableViewState viewState = row.getViewState();
506 viewState.hidden = false;
507 }
508 }
509
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500510 private void updateHeadsUpStates(StackScrollAlgorithmState algorithmState,
511 AmbientState ambientState) {
Selim Cineka4baaa32015-04-20 14:27:54 -0700512 int childCount = algorithmState.visibleChildren.size();
513 ExpandableNotificationRow topHeadsUpEntry = null;
514 for (int i = 0; i < childCount; i++) {
515 View child = algorithmState.visibleChildren.get(i);
516 if (!(child instanceof ExpandableNotificationRow)) {
517 break;
518 }
519 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
520 if (!row.isHeadsUp()) {
521 break;
Selim Cineka4baaa32015-04-20 14:27:54 -0700522 }
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500523 ExpandableViewState childState = row.getViewState();
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100524 if (topHeadsUpEntry == null && row.mustStayOnScreen() && !childState.headsUpIsVisible) {
Selim Cinek3776fe02016-02-04 13:32:43 -0800525 topHeadsUpEntry = row;
Selim Cinekbbcebde2016-11-09 18:28:20 -0800526 childState.location = ExpandableViewState.LOCATION_FIRST_HUN;
Selim Cinek3776fe02016-02-04 13:32:43 -0800527 }
Selim Cinek1f3f5442015-04-10 17:54:46 -0700528 boolean isTopEntry = topHeadsUpEntry == row;
Selim Cinek3776fe02016-02-04 13:32:43 -0800529 float unmodifiedEndLocation = childState.yTranslation + childState.height;
Selim Cinek131c1e22015-05-11 19:04:49 -0700530 if (mIsExpanded) {
Selim Cinekc3fec682019-06-06 18:11:07 -0700531 if (row.mustStayOnScreen() && !childState.headsUpIsVisible
532 && !row.showingPulsing()) {
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100533 // Ensure that the heads up is always visible even when scrolled off
534 clampHunToTop(ambientState, row, childState);
Selim Cinek459aee32019-02-20 11:18:56 -0800535 if (i == 0 && row.isAboveShelf()) {
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100536 // the first hun can't get off screen.
537 clampHunToMaxTranslation(ambientState, row, childState);
538 childState.hidden = false;
539 }
Selim Cinekd127d792016-11-01 19:11:41 -0700540 }
Selim Cinek131c1e22015-05-11 19:04:49 -0700541 }
Selim Cinek684a4422015-04-15 16:18:39 -0700542 if (row.isPinned()) {
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800543 childState.yTranslation = Math.max(childState.yTranslation, mHeadsUpInset);
Selim Cinek31aada42015-12-18 17:51:15 -0800544 childState.height = Math.max(row.getIntrinsicHeight(), childState.height);
Selim Cinekcafa87f2016-10-26 17:00:17 -0700545 childState.hidden = false;
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500546 ExpandableViewState topState =
547 topHeadsUpEntry == null ? null : topHeadsUpEntry.getViewState();
Selim Cinek61cfd4b2017-12-08 12:42:36 -0800548 if (topState != null && !isTopEntry && (!mIsExpanded
Selim Cinek3776fe02016-02-04 13:32:43 -0800549 || unmodifiedEndLocation < topState.yTranslation + topState.height)) {
Selim Cinek684a4422015-04-15 16:18:39 -0700550 // Ensure that a headsUp doesn't vertically extend further than the heads-up at
551 // the top most z-position
Selim Cinek31aada42015-12-18 17:51:15 -0800552 childState.height = row.getIntrinsicHeight();
Selim Cineke53e6bb2015-04-13 16:14:26 -0700553 childState.yTranslation = topState.yTranslation + topState.height
554 - childState.height;
Selim Cinek1f3f5442015-04-10 17:54:46 -0700555 }
felkachang529bfe62018-07-04 12:51:44 +0800556
557 // heads up notification show and this row is the top entry of heads up
558 // notifications. i.e. this row should be the only one row that has input field
559 // To check if the row need to do translation according to scroll Y
560 // heads up show full of row's content and any scroll y indicate that the
561 // translationY need to move up the HUN.
Gus Prevas0fa58d62019-01-11 13:58:40 -0500562 // TODO: fix this check for anchor scrolling.
felkachang529bfe62018-07-04 12:51:44 +0800563 if (!mIsExpanded && isTopEntry && ambientState.getScrollY() > 0) {
564 childState.yTranslation -= ambientState.getScrollY();
565 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700566 }
Selim Cinekcafa87f2016-10-26 17:00:17 -0700567 if (row.isHeadsUpAnimatingAway()) {
568 childState.hidden = false;
569 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700570 }
Selim Cinek67b22602014-03-10 15:40:16 +0100571 }
572
Selim Cinek3776fe02016-02-04 13:32:43 -0800573 private void clampHunToTop(AmbientState ambientState, ExpandableNotificationRow row,
Selim Cinekbbcebde2016-11-09 18:28:20 -0800574 ExpandableViewState childState) {
Selim Cinek3776fe02016-02-04 13:32:43 -0800575 float newTranslation = Math.max(ambientState.getTopPadding()
576 + ambientState.getStackTranslation(), childState.yTranslation);
577 childState.height = (int) Math.max(childState.height - (newTranslation
Selim Cinek567e8452016-03-24 10:54:56 -0700578 - childState.yTranslation), row.getCollapsedHeight());
Selim Cinek3776fe02016-02-04 13:32:43 -0800579 childState.yTranslation = newTranslation;
580 }
581
582 private void clampHunToMaxTranslation(AmbientState ambientState, ExpandableNotificationRow row,
Selim Cinekbbcebde2016-11-09 18:28:20 -0800583 ExpandableViewState childState) {
Selim Cinek3776fe02016-02-04 13:32:43 -0800584 float newTranslation;
Selim Cinek7e0f9482017-05-22 20:00:56 -0700585 float maxHeadsUpTranslation = ambientState.getMaxHeadsUpTranslation();
586 float maxShelfPosition = ambientState.getInnerHeight() + ambientState.getTopPadding()
587 + ambientState.getStackTranslation();
588 maxHeadsUpTranslation = Math.min(maxHeadsUpTranslation, maxShelfPosition);
589 float bottomPosition = maxHeadsUpTranslation - row.getCollapsedHeight();
Selim Cinek3776fe02016-02-04 13:32:43 -0800590 newTranslation = Math.min(childState.yTranslation, bottomPosition);
Selim Cinek7e0f9482017-05-22 20:00:56 -0700591 childState.height = (int) Math.min(childState.height, maxHeadsUpTranslation
592 - newTranslation);
Selim Cinek3776fe02016-02-04 13:32:43 -0800593 childState.yTranslation = newTranslation;
Selim Cinek343e6e22014-04-11 21:23:30 +0200594 }
595
596 /**
Selim Cinek281c2022016-10-13 19:14:43 -0700597 * Clamp the height of the child down such that its end is at most on the beginning of
598 * the shelf.
599 *
Selim Cinek281c2022016-10-13 19:14:43 -0700600 * @param childViewState the view state of the child
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500601 * @param ambientState the ambient state
Selim Cinek281c2022016-10-13 19:14:43 -0700602 */
Selim Cinek2627d722018-01-19 12:16:49 -0800603 private void clampPositionToShelf(ExpandableView child,
604 ExpandableViewState childViewState,
Selim Cinek281c2022016-10-13 19:14:43 -0700605 AmbientState ambientState) {
Eliot Courtney5d3d2d02018-01-18 15:59:03 +0900606 if (ambientState.getShelf() == null) {
607 return;
608 }
609
Selim Cineka686b2c2016-10-26 13:58:27 -0700610 int shelfStart = ambientState.getInnerHeight()
611 - ambientState.getShelf().getIntrinsicHeight();
shawnlin5be1f7c2018-05-21 20:50:54 +0800612 if (ambientState.isAppearing() && !child.isAboveShelf()) {
613 // Don't show none heads-up notifications while in appearing phase.
614 childViewState.yTranslation = Math.max(childViewState.yTranslation, shelfStart);
615 }
Selim Cinek281c2022016-10-13 19:14:43 -0700616 childViewState.yTranslation = Math.min(childViewState.yTranslation, shelfStart);
Selim Cinekc383fd02016-10-21 15:31:26 -0700617 if (childViewState.yTranslation >= shelfStart) {
Selim Cinekc25989e2018-02-16 16:42:14 -0800618 childViewState.hidden = !child.isExpandAnimationRunning() && !child.hasExpandingChild();
Selim Cinekeccb5de2016-10-28 15:04:05 -0700619 childViewState.inShelf = true;
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100620 childViewState.headsUpIsVisible = false;
Selim Cinekc383fd02016-10-21 15:31:26 -0700621 }
Selim Cinek281c2022016-10-13 19:14:43 -0700622 }
623
Muyuan Li87798022016-04-07 17:51:25 -0700624 protected int getMaxAllowedChildHeight(View child) {
Selim Cinek31aada42015-12-18 17:51:15 -0800625 if (child instanceof ExpandableView) {
Jorim Jaggibe565df2014-04-28 17:51:23 +0200626 ExpandableView expandableView = (ExpandableView) child;
Selim Cinek8d5727f2015-04-28 19:17:32 -0700627 return expandableView.getIntrinsicHeight();
Selim Cinek1685e632014-04-08 02:27:49 +0200628 }
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500629 return child == null ? mCollapsedSize : child.getHeight();
Selim Cinek1685e632014-04-08 02:27:49 +0200630 }
631
Selim Cinek67b22602014-03-10 15:40:16 +0100632 /**
Selim Cinek67b22602014-03-10 15:40:16 +0100633 * Calculate the Z positions for all children based on the number of items in both stacks and
634 * save it in the resultState
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500635 *
Selim Cinek67b22602014-03-10 15:40:16 +0100636 * @param algorithmState The state in which the current pass of the algorithm is currently in
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500637 * @param ambientState The ambient state of the algorithm
Selim Cinek67b22602014-03-10 15:40:16 +0100638 */
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500639 private void updateZValuesForState(StackScrollAlgorithmState algorithmState,
640 AmbientState ambientState) {
Jorim Jaggid4a57442014-04-10 02:45:55 +0200641 int childCount = algorithmState.visibleChildren.size();
Selim Cinek33223572016-02-19 19:32:22 -0800642 float childrenOnTop = 0.0f;
Selim Cinek3776fe02016-02-04 13:32:43 -0800643 for (int i = childCount - 1; i >= 0; i--) {
Selim Cinekdaab6f52017-04-06 16:46:34 -0700644 childrenOnTop = updateChildZValue(i, childrenOnTop,
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500645 algorithmState, ambientState);
Muyuan Li87798022016-04-07 17:51:25 -0700646 }
647 }
648
Selim Cinekdaab6f52017-04-06 16:46:34 -0700649 protected float updateChildZValue(int i, float childrenOnTop,
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500650 StackScrollAlgorithmState algorithmState,
Muyuan Li87798022016-04-07 17:51:25 -0700651 AmbientState ambientState) {
652 ExpandableView child = algorithmState.visibleChildren.get(i);
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500653 ExpandableViewState childViewState = child.getViewState();
Selim Cinek281c2022016-10-13 19:14:43 -0700654 int zDistanceBetweenElements = ambientState.getZDistanceBetweenElements();
655 float baseZ = ambientState.getBaseZHeight();
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100656 if (child.mustStayOnScreen() && !childViewState.headsUpIsVisible
657 && !ambientState.isDozingAndNotPulsing(child)
Muyuan Li87798022016-04-07 17:51:25 -0700658 && childViewState.yTranslation < ambientState.getTopPadding()
659 + ambientState.getStackTranslation()) {
660 if (childrenOnTop != 0.0f) {
661 childrenOnTop++;
662 } else {
663 float overlap = ambientState.getTopPadding()
664 + ambientState.getStackTranslation() - childViewState.yTranslation;
665 childrenOnTop += Math.min(1.0f, overlap / childViewState.height);
666 }
Selim Cinek281c2022016-10-13 19:14:43 -0700667 childViewState.zTranslation = baseZ
668 + childrenOnTop * zDistanceBetweenElements;
Selim Cinekc3fec682019-06-06 18:11:07 -0700669 } else if (i == 0 && (child.isAboveShelf() || child.showingPulsing())) {
Selim Cinekd127d792016-11-01 19:11:41 -0700670 // In case this is a new view that has never been measured before, we don't want to
671 // elevate if we are currently expanded more then the notification
Eliot Courtney5d3d2d02018-01-18 15:59:03 +0900672 int shelfHeight = ambientState.getShelf() == null ? 0 :
673 ambientState.getShelf().getIntrinsicHeight();
Selim Cinekd127d792016-11-01 19:11:41 -0700674 float shelfStart = ambientState.getInnerHeight()
675 - shelfHeight + ambientState.getTopPadding()
676 + ambientState.getStackTranslation();
677 float notificationEnd = childViewState.yTranslation + child.getPinnedHeadsUpHeight()
678 + mPaddingBetweenElements;
679 if (shelfStart > notificationEnd) {
680 childViewState.zTranslation = baseZ;
681 } else {
682 float factor = (notificationEnd - shelfStart) / shelfHeight;
683 factor = Math.min(factor, 1.0f);
684 childViewState.zTranslation = baseZ + factor * zDistanceBetweenElements;
685 }
Muyuan Li87798022016-04-07 17:51:25 -0700686 } else {
Selim Cinek281c2022016-10-13 19:14:43 -0700687 childViewState.zTranslation = baseZ;
Selim Cinek67b22602014-03-10 15:40:16 +0100688 }
Selim Cinek99e9adf2018-03-15 09:17:47 -0700689
690 // We need to scrim the notification more from its surrounding content when we are pinned,
691 // and we therefore elevate it higher.
692 // We can use the headerVisibleAmount for this, since the value nicely goes from 0 to 1 when
693 // expanding after which we have a normal elevation again.
694 childViewState.zTranslation += (1.0f - child.getHeaderVisibleAmount())
695 * mPinnedZTranslationExtra;
Selim Cinekdaab6f52017-04-06 16:46:34 -0700696 return childrenOnTop;
Selim Cinek67b22602014-03-10 15:40:16 +0100697 }
698
Selim Cinek1685e632014-04-08 02:27:49 +0200699 public void setIsExpanded(boolean isExpanded) {
700 this.mIsExpanded = isExpanded;
701 }
702
Selim Cinek281c2022016-10-13 19:14:43 -0700703 public class StackScrollAlgorithmState {
Selim Cinek67b22602014-03-10 15:40:16 +0100704
705 /**
Gus Prevas0fa58d62019-01-11 13:58:40 -0500706 * The scroll position of the algorithm (absolute scrolling).
Selim Cinek67b22602014-03-10 15:40:16 +0100707 */
708 public int scrollY;
709
Gus Prevas0fa58d62019-01-11 13:58:40 -0500710 /** The index of the anchor view (anchor scrolling). */
711 public int anchorViewIndex;
712
713 /**
714 * The Y position, relative to the top of the screen, of the anchor view (anchor scrolling).
715 */
716 public int anchorViewY;
717
Selim Cinek67b22602014-03-10 15:40:16 +0100718 /**
Jorim Jaggid4a57442014-04-10 02:45:55 +0200719 * The children from the host view which are not gone.
720 */
Jorim Jaggibe565df2014-04-28 17:51:23 +0200721 public final ArrayList<ExpandableView> visibleChildren = new ArrayList<ExpandableView>();
Selim Cinek61633a82016-01-25 15:54:10 -0800722
723 /**
Selim Cineka7ed2c12017-01-23 20:47:24 -0800724 * The padding after each child measured in pixels.
Selim Cinek61633a82016-01-25 15:54:10 -0800725 */
Selim Cineka7ed2c12017-01-23 20:47:24 -0800726 public final HashMap<ExpandableView, Float> paddingMap = new HashMap<>();
Selim Cinek2627d722018-01-19 12:16:49 -0800727 private int indexOfExpandingNotification;
Selim Cinek281c2022016-10-13 19:14:43 -0700728
729 public int getPaddingAfterChild(ExpandableView child) {
Selim Cineka7ed2c12017-01-23 20:47:24 -0800730 Float padding = paddingMap.get(child);
731 if (padding == null) {
732 // Should only happen for the last view
733 return mPaddingBetweenElements;
734 }
735 return (int) padding.floatValue();
Selim Cinek281c2022016-10-13 19:14:43 -0700736 }
Selim Cinek2627d722018-01-19 12:16:49 -0800737
738 public int getIndexOfExpandingNotification() {
739 return indexOfExpandingNotification;
740 }
Selim Cinek67b22602014-03-10 15:40:16 +0100741 }
742
Ned Burns9eb06332019-04-23 16:02:12 -0400743 /**
744 * Interface for telling the SSA when a new notification section begins (so it can add in
745 * appropriate margins).
746 */
747 public interface SectionProvider {
748 /**
749 * True if this view starts a new "section" of notifications, such as the gentle
750 * notifications section. False if sections are not enabled.
751 */
752 boolean beginsSection(View view);
753 }
Selim Cinek67b22602014-03-10 15:40:16 +0100754}