blob: f97a7e6531049e24ddb88b67b02a0cca0c9b54fb [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
Dave Mankoffa4d195d2018-11-16 13:33:27 -050061 public StackScrollAlgorithm(Context context, ViewGroup hostView) {
62 mHostView = hostView;
Selim Cinekaf0dc312015-12-15 17:01:44 -080063 initView(context);
Selim Cinek34c0a8d2014-05-12 00:01:43 +020064 }
65
Selim Cinekaf0dc312015-12-15 17:01:44 -080066 public void initView(Context context) {
67 initConstants(context);
Selim Cinek34c0a8d2014-05-12 00:01:43 +020068 }
69
Selim Cinek67b22602014-03-10 15:40:16 +010070 private void initConstants(Context context) {
Anthony Chen9fe1ee72017-04-07 13:53:37 -070071 Resources res = context.getResources();
72 mPaddingBetweenElements = res.getDimensionPixelSize(
Selim Cinekdb167372016-11-17 15:41:17 -080073 R.dimen.notification_divider_height);
Anthony Chen9fe1ee72017-04-07 13:53:37 -070074 mIncreasedPaddingBetweenElements =
75 res.getDimensionPixelSize(R.dimen.notification_divider_height_increased);
76 mCollapsedSize = res.getDimensionPixelSize(R.dimen.notification_min_height);
77 mStatusBarHeight = res.getDimensionPixelSize(R.dimen.status_bar_height);
78 mClipNotificationScrollToTop = res.getBoolean(R.bool.config_clipNotificationScrollToTop);
Selim Cinekaa9db1f2018-02-27 17:35:47 -080079 mHeadsUpInset = mStatusBarHeight + res.getDimensionPixelSize(
80 R.dimen.heads_up_status_bar_padding);
Selim Cinek99e9adf2018-03-15 09:17:47 -070081 mPinnedZTranslationExtra = res.getDimensionPixelSize(
82 R.dimen.heads_up_pinned_elevation);
Gus Prevase2d6f042018-10-17 15:25:30 -040083 mGapHeight = res.getDimensionPixelSize(R.dimen.notification_section_divider_height);
Jorim Jaggid7c1fae2014-08-13 18:27:47 +020084 }
Selim Cinek67b22602014-03-10 15:40:16 +010085
Dave Mankoffa4d195d2018-11-16 13:33:27 -050086 /**
87 * Updates the state of all children in the hostview based on this algorithm.
88 */
89 public void resetViewStates(AmbientState ambientState) {
Selim Cinek67b22602014-03-10 15:40:16 +010090 // The state of the local variables are saved in an algorithmState to easily subdivide it
91 // into multiple phases.
92 StackScrollAlgorithmState algorithmState = mTempAlgorithmState;
93
94 // First we reset the view states to their default values.
Dave Mankoffa4d195d2018-11-16 13:33:27 -050095 resetChildViewStates();
Selim Cinek67b22602014-03-10 15:40:16 +010096
Dave Mankoffa4d195d2018-11-16 13:33:27 -050097 initAlgorithmState(mHostView, algorithmState, ambientState);
Selim Cinek1408eb52014-06-02 14:45:38 +020098
Dave Mankoffa4d195d2018-11-16 13:33:27 -050099 updatePositionsForState(algorithmState, ambientState);
Selim Cinek67b22602014-03-10 15:40:16 +0100100
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500101 updateZValuesForState(algorithmState, ambientState);
Selim Cinek3776fe02016-02-04 13:32:43 -0800102
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500103 updateHeadsUpStates(algorithmState, ambientState);
Selim Cinek5040f2e2019-02-14 18:22:42 -0800104 updatePulsingStates(algorithmState, ambientState);
Selim Cinekeb973562014-05-02 17:07:49 +0200105
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500106 updateDimmedActivatedHideSensitive(ambientState, algorithmState);
107 updateClipping(algorithmState, ambientState);
108 updateSpeedBumpState(algorithmState, ambientState);
109 updateShelfState(ambientState);
110 getNotificationChildrenStates(algorithmState, ambientState);
Selim Cinekb5605e52015-02-20 18:21:41 +0100111 }
112
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500113 private void resetChildViewStates() {
114 int numChildren = mHostView.getChildCount();
115 for (int i = 0; i < numChildren; i++) {
116 ExpandableView child = (ExpandableView) mHostView.getChildAt(i);
117 child.resetViewState();
118 }
119 }
120
121 private void getNotificationChildrenStates(StackScrollAlgorithmState algorithmState,
Selim Cinekc25989e2018-02-16 16:42:14 -0800122 AmbientState ambientState) {
Selim Cinekb5605e52015-02-20 18:21:41 +0100123 int childCount = algorithmState.visibleChildren.size();
124 for (int i = 0; i < childCount; i++) {
125 ExpandableView v = algorithmState.visibleChildren.get(i);
126 if (v instanceof ExpandableNotificationRow) {
127 ExpandableNotificationRow row = (ExpandableNotificationRow) v;
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500128 row.updateChildrenStates(ambientState);
Selim Cinekb5605e52015-02-20 18:21:41 +0100129 }
130 }
Selim Cinek3d2b94bf2014-07-02 22:12:47 +0200131 }
132
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500133 private void updateSpeedBumpState(StackScrollAlgorithmState algorithmState,
134 AmbientState ambientState) {
Selim Cinek3d2b94bf2014-07-02 22:12:47 +0200135 int childCount = algorithmState.visibleChildren.size();
Selim Cinekdb167372016-11-17 15:41:17 -0800136 int belowSpeedBump = ambientState.getSpeedBumpIndex();
Selim Cinek3d2b94bf2014-07-02 22:12:47 +0200137 for (int i = 0; i < childCount; i++) {
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500138 ExpandableView child = algorithmState.visibleChildren.get(i);
139 ExpandableViewState childViewState = child.getViewState();
Selim Cinek3107cfa2014-07-22 15:24:29 +0200140
141 // The speed bump can also be gone, so equality needs to be taken when comparing
142 // indices.
Selim Cinekdb167372016-11-17 15:41:17 -0800143 childViewState.belowSpeedBump = i >= belowSpeedBump;
Selim Cinek3d2b94bf2014-07-02 22:12:47 +0200144 }
Selim Cinekdb167372016-11-17 15:41:17 -0800145
146 }
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500147
148 private void updateShelfState(AmbientState ambientState) {
Selim Cinek281c2022016-10-13 19:14:43 -0700149 NotificationShelf shelf = ambientState.getShelf();
Eliot Courtney5d3d2d02018-01-18 15:59:03 +0900150 if (shelf != null) {
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500151 shelf.updateState(ambientState);
Eliot Courtney5d3d2d02018-01-18 15:59:03 +0900152 }
Selim Cinekf54090e2014-06-17 17:24:51 -0700153 }
154
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500155 private void updateClipping(StackScrollAlgorithmState algorithmState,
156 AmbientState ambientState) {
Selim Cinek355652a2016-12-07 13:32:12 -0800157 float drawStart = !ambientState.isOnKeyguard() ? ambientState.getTopPadding()
Selim Cinek2627d722018-01-19 12:16:49 -0800158 + ambientState.getStackTranslation() + ambientState.getExpandAnimationTopChange()
159 : 0;
Selim Cinek708a6c12014-05-28 14:16:02 +0200160 float previousNotificationEnd = 0;
161 float previousNotificationStart = 0;
Selim Cinek708a6c12014-05-28 14:16:02 +0200162 int childCount = algorithmState.visibleChildren.size();
163 for (int i = 0; i < childCount; i++) {
164 ExpandableView child = algorithmState.visibleChildren.get(i);
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500165 ExpandableViewState state = child.getViewState();
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100166 if (!child.mustStayOnScreen() || state.headsUpIsVisible) {
Selim Cinek3776fe02016-02-04 13:32:43 -0800167 previousNotificationEnd = Math.max(drawStart, previousNotificationEnd);
168 previousNotificationStart = Math.max(drawStart, previousNotificationStart);
169 }
Selim Cinek587cbf32016-01-19 11:36:18 -0800170 float newYTranslation = state.yTranslation;
171 float newHeight = state.height;
Selim Cinek708a6c12014-05-28 14:16:02 +0200172 float newNotificationEnd = newYTranslation + newHeight;
Mady Mellor53ac1ef2016-06-20 13:11:38 -0700173 boolean isHeadsUp = (child instanceof ExpandableNotificationRow)
174 && ((ExpandableNotificationRow) child).isPinned();
Anthony Chen9fe1ee72017-04-07 13:53:37 -0700175 if (mClipNotificationScrollToTop
176 && !state.inShelf && newYTranslation < previousNotificationEnd
Jorim Jaggi0fdf5742016-06-27 11:50:58 -0700177 && (!isHeadsUp || ambientState.isShadeExpanded())) {
Mady Mellorc128f222016-04-26 11:42:46 -0700178 // The previous view is overlapping on top, clip!
179 float overlapAmount = previousNotificationEnd - newYTranslation;
180 state.clipTopAmount = (int) overlapAmount;
Selim Cinekc5baa3e2014-10-29 19:04:19 +0100181 } else {
Mady Mellorc128f222016-04-26 11:42:46 -0700182 state.clipTopAmount = 0;
Selim Cinek9c17b772015-07-07 20:37:09 -0700183 }
184
Selim Cinek708a6c12014-05-28 14:16:02 +0200185 if (!child.isTransparent()) {
186 // Only update the previous values if we are not transparent,
187 // otherwise we would clip to a transparent view.
Mady Mellorc128f222016-04-26 11:42:46 -0700188 previousNotificationEnd = newNotificationEnd;
189 previousNotificationStart = newYTranslation;
Selim Cinek708a6c12014-05-28 14:16:02 +0200190 }
191 }
192 }
193
Selim Cinek9c17b772015-07-07 20:37:09 -0700194 public static boolean canChildBeDismissed(View v) {
Selim Cinek9e624e72016-07-20 13:46:49 -0700195 if (!(v instanceof ExpandableNotificationRow)) {
196 return false;
Selim Cinek38d429f2016-06-03 11:46:56 -0700197 }
Selim Cinek9e624e72016-07-20 13:46:49 -0700198 ExpandableNotificationRow row = (ExpandableNotificationRow) v;
Nadia Benbernou7a18c812019-02-08 16:23:10 -0500199 if (row.isBlockingHelperShowingAndTranslationFinished()) {
200 return true;
201 }
Aaron Heuckroth1dd67cb2018-06-14 14:28:08 -0400202 if (row.areGutsExposed() || !row.getEntry().hasFinishedInitialization()) {
Selim Cinek9e624e72016-07-20 13:46:49 -0700203 return false;
204 }
205 return row.canViewBeDismissed();
Selim Cinek9c17b772015-07-07 20:37:09 -0700206 }
207
Selim Cinek708a6c12014-05-28 14:16:02 +0200208 /**
Jorim Jaggiae441282014-08-01 02:45:18 +0200209 * Updates the dimmed, activated and hiding sensitive states of the children.
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200210 */
Jorim Jaggiae441282014-08-01 02:45:18 +0200211 private void updateDimmedActivatedHideSensitive(AmbientState ambientState,
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500212 StackScrollAlgorithmState algorithmState) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200213 boolean dimmed = ambientState.isDimmed();
Lucas Dupin16cfe452018-02-08 13:14:50 -0800214 boolean dark = ambientState.isFullyDark();
Jorim Jaggiae441282014-08-01 02:45:18 +0200215 boolean hideSensitive = ambientState.isHideSensitive();
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200216 View activatedChild = ambientState.getActivatedChild();
217 int childCount = algorithmState.visibleChildren.size();
218 for (int i = 0; i < childCount; i++) {
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500219 ExpandableView child = algorithmState.visibleChildren.get(i);
220 ExpandableViewState childViewState = child.getViewState();
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200221 childViewState.dimmed = dimmed;
John Spurlockbf370992014-06-17 13:58:31 -0400222 childViewState.dark = dark;
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 Cinekd96ed402017-07-28 18:19:03 -0700256 int firstHiddenIndex = ambientState.isDark()
257 ? (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) {
Selim Cinek67b22602014-03-10 15:40:16 +0100367
Gus Prevas0fa58d62019-01-11 13:58:40 -0500368 if (ANCHOR_SCROLLING) {
369 float currentYPosition = algorithmState.anchorViewY;
370 int childCount = algorithmState.visibleChildren.size();
371 for (int i = algorithmState.anchorViewIndex; i < childCount; i++) {
372 if (i > algorithmState.anchorViewIndex && ambientState.beginsNewSection(i)) {
373 currentYPosition += mGapHeight;
374 }
375 currentYPosition = updateChild(i, algorithmState, ambientState, currentYPosition,
376 false /* reverse */);
377 }
378 currentYPosition = algorithmState.anchorViewY;
379 for (int i = algorithmState.anchorViewIndex - 1; i >= 0; i--) {
380 if (ambientState.beginsNewSection(i + 1)) {
381 currentYPosition -= mGapHeight;
382 }
383 currentYPosition = updateChild(i, algorithmState, ambientState, currentYPosition,
384 true /* reverse */);
385 }
386 } else {
387 // The y coordinate of the current child.
388 float currentYPosition = -algorithmState.scrollY;
389 int childCount = algorithmState.visibleChildren.size();
390 for (int i = 0; i < childCount; i++) {
391 if (ambientState.beginsNewSection(i)) {
392 currentYPosition += mGapHeight;
393 }
394 currentYPosition = updateChild(i, algorithmState, ambientState, currentYPosition,
395 false /* reverse */);
396 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700397 }
398 }
399
Gus Prevas0fa58d62019-01-11 13:58:40 -0500400 /**
401 * Populates the {@link ExpandableViewState} for a single child.
402 *
403 * @param i The index of the child in
404 * {@link StackScrollAlgorithmState#visibleChildren}.
405 * @param algorithmState The overall output state of the algorithm.
406 * @param ambientState The input state provided to the algorithm.
407 * @param currentYPosition The Y position of the current pass of the algorithm. For a forward
408 * pass, this should be the top of the child; for a reverse pass, the
409 * bottom of the child.
410 * @param reverse Whether we're laying out children in the reverse direction (Y
411 * positions
412 * decreasing) instead of the forward direction (Y positions
413 * increasing).
414 * @return The Y position after laying out the child. This will be the {@code currentYPosition}
415 * for the next call to this method, after adjusting for any gaps between children.
416 */
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500417 protected float updateChild(
418 int i,
419 StackScrollAlgorithmState algorithmState,
420 AmbientState ambientState,
Gus Prevas0fa58d62019-01-11 13:58:40 -0500421 float currentYPosition,
422 boolean reverse) {
Muyuan Li87798022016-04-07 17:51:25 -0700423 ExpandableView child = algorithmState.visibleChildren.get(i);
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500424 ExpandableViewState childViewState = child.getViewState();
Selim Cinekbbcebde2016-11-09 18:28:20 -0800425 childViewState.location = ExpandableViewState.LOCATION_UNKNOWN;
Muyuan Li87798022016-04-07 17:51:25 -0700426 int paddingAfterChild = getPaddingAfterChild(algorithmState, child);
427 int childHeight = getMaxAllowedChildHeight(child);
Gus Prevas0fa58d62019-01-11 13:58:40 -0500428 if (reverse) {
429 childViewState.yTranslation = currentYPosition - (childHeight + paddingAfterChild);
430 if (currentYPosition <= 0) {
431 childViewState.location = ExpandableViewState.LOCATION_HIDDEN_TOP;
432 }
433 } else {
434 childViewState.yTranslation = currentYPosition;
Gus Prevase2d6f042018-10-17 15:25:30 -0400435 }
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400436 boolean isFooterView = child instanceof FooterView;
Selim Cinekcde90e52016-12-22 21:01:49 +0100437 boolean isEmptyShadeView = child instanceof EmptyShadeView;
Muyuan Li87798022016-04-07 17:51:25 -0700438
Selim Cinekdb167372016-11-17 15:41:17 -0800439 childViewState.location = ExpandableViewState.LOCATION_MAIN_AREA;
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100440 float inset = ambientState.getTopPadding() + ambientState.getStackTranslation();
Selim Cinekc25989e2018-02-16 16:42:14 -0800441 if (i <= algorithmState.getIndexOfExpandingNotification()) {
Selim Cinek2627d722018-01-19 12:16:49 -0800442 inset += ambientState.getExpandAnimationTopChange();
443 }
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100444 if (child.mustStayOnScreen() && childViewState.yTranslation >= 0) {
445 // Even if we're not scrolled away we're in view and we're also not in the
446 // shelf. We can relax the constraints and let us scroll off the top!
447 float end = childViewState.yTranslation + childViewState.height + inset;
448 childViewState.headsUpIsVisible = end < ambientState.getMaxHeadsUpTranslation();
449 }
Julia Reynoldsed1c9af2018-03-21 15:21:09 -0400450 if (isFooterView) {
Selim Cinekdb167372016-11-17 15:41:17 -0800451 childViewState.yTranslation = Math.min(childViewState.yTranslation,
452 ambientState.getInnerHeight() - childHeight);
Selim Cinekcde90e52016-12-22 21:01:49 +0100453 } else if (isEmptyShadeView) {
454 childViewState.yTranslation = ambientState.getInnerHeight() - childHeight
455 + ambientState.getStackTranslation() * 0.25f;
Muyuan Li87798022016-04-07 17:51:25 -0700456 } else {
Selim Cinek2627d722018-01-19 12:16:49 -0800457 clampPositionToShelf(child, childViewState, ambientState);
Muyuan Li87798022016-04-07 17:51:25 -0700458 }
459
Gus Prevas0fa58d62019-01-11 13:58:40 -0500460 if (reverse) {
461 currentYPosition = childViewState.yTranslation;
462 } 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
476 protected int getPaddingAfterChild(StackScrollAlgorithmState algorithmState,
Selim Cinek61633a82016-01-25 15:54:10 -0800477 ExpandableView child) {
Selim Cinek281c2022016-10-13 19:14:43 -0700478 return algorithmState.getPaddingAfterChild(child);
Selim Cinek61633a82016-01-25 15:54:10 -0800479 }
480
Selim Cinek5040f2e2019-02-14 18:22:42 -0800481 private void updatePulsingStates(StackScrollAlgorithmState algorithmState,
482 AmbientState ambientState) {
483 int childCount = algorithmState.visibleChildren.size();
484 for (int i = 0; i < childCount; i++) {
485 View child = algorithmState.visibleChildren.get(i);
486 if (!(child instanceof ExpandableNotificationRow)) {
487 continue;
488 }
489 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
Selim Cinek459aee32019-02-20 11:18:56 -0800490 if (!row.showingAmbientPulsing() || (i == 0 && ambientState.isPulseExpanding())) {
Selim Cinek5040f2e2019-02-14 18:22:42 -0800491 continue;
492 }
493 ExpandableViewState viewState = row.getViewState();
494 viewState.hidden = false;
495 }
496 }
497
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500498 private void updateHeadsUpStates(StackScrollAlgorithmState algorithmState,
499 AmbientState ambientState) {
Selim Cineka4baaa32015-04-20 14:27:54 -0700500 int childCount = algorithmState.visibleChildren.size();
501 ExpandableNotificationRow topHeadsUpEntry = null;
502 for (int i = 0; i < childCount; i++) {
503 View child = algorithmState.visibleChildren.get(i);
504 if (!(child instanceof ExpandableNotificationRow)) {
505 break;
506 }
507 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
508 if (!row.isHeadsUp()) {
509 break;
Selim Cineka4baaa32015-04-20 14:27:54 -0700510 }
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500511 ExpandableViewState childState = row.getViewState();
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100512 if (topHeadsUpEntry == null && row.mustStayOnScreen() && !childState.headsUpIsVisible) {
Selim Cinek3776fe02016-02-04 13:32:43 -0800513 topHeadsUpEntry = row;
Selim Cinekbbcebde2016-11-09 18:28:20 -0800514 childState.location = ExpandableViewState.LOCATION_FIRST_HUN;
Selim Cinek3776fe02016-02-04 13:32:43 -0800515 }
Selim Cinek1f3f5442015-04-10 17:54:46 -0700516 boolean isTopEntry = topHeadsUpEntry == row;
Selim Cinek3776fe02016-02-04 13:32:43 -0800517 float unmodifiedEndLocation = childState.yTranslation + childState.height;
Selim Cinek131c1e22015-05-11 19:04:49 -0700518 if (mIsExpanded) {
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100519 if (row.mustStayOnScreen() && !childState.headsUpIsVisible) {
520 // Ensure that the heads up is always visible even when scrolled off
521 clampHunToTop(ambientState, row, childState);
Selim Cinek459aee32019-02-20 11:18:56 -0800522 if (i == 0 && row.isAboveShelf()) {
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100523 // the first hun can't get off screen.
524 clampHunToMaxTranslation(ambientState, row, childState);
525 childState.hidden = false;
526 }
Selim Cinekd127d792016-11-01 19:11:41 -0700527 }
Selim Cinek131c1e22015-05-11 19:04:49 -0700528 }
Selim Cinek684a4422015-04-15 16:18:39 -0700529 if (row.isPinned()) {
Selim Cinekaa9db1f2018-02-27 17:35:47 -0800530 childState.yTranslation = Math.max(childState.yTranslation, mHeadsUpInset);
Selim Cinek31aada42015-12-18 17:51:15 -0800531 childState.height = Math.max(row.getIntrinsicHeight(), childState.height);
Selim Cinekcafa87f2016-10-26 17:00:17 -0700532 childState.hidden = false;
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500533 ExpandableViewState topState =
534 topHeadsUpEntry == null ? null : topHeadsUpEntry.getViewState();
Selim Cinek61cfd4b2017-12-08 12:42:36 -0800535 if (topState != null && !isTopEntry && (!mIsExpanded
Selim Cinek3776fe02016-02-04 13:32:43 -0800536 || unmodifiedEndLocation < topState.yTranslation + topState.height)) {
Selim Cinek684a4422015-04-15 16:18:39 -0700537 // Ensure that a headsUp doesn't vertically extend further than the heads-up at
538 // the top most z-position
Selim Cinek31aada42015-12-18 17:51:15 -0800539 childState.height = row.getIntrinsicHeight();
Selim Cineke53e6bb2015-04-13 16:14:26 -0700540 childState.yTranslation = topState.yTranslation + topState.height
541 - childState.height;
Selim Cinek1f3f5442015-04-10 17:54:46 -0700542 }
felkachang529bfe62018-07-04 12:51:44 +0800543
544 // heads up notification show and this row is the top entry of heads up
545 // notifications. i.e. this row should be the only one row that has input field
546 // To check if the row need to do translation according to scroll Y
547 // heads up show full of row's content and any scroll y indicate that the
548 // translationY need to move up the HUN.
Gus Prevas0fa58d62019-01-11 13:58:40 -0500549 // TODO: fix this check for anchor scrolling.
felkachang529bfe62018-07-04 12:51:44 +0800550 if (!mIsExpanded && isTopEntry && ambientState.getScrollY() > 0) {
551 childState.yTranslation -= ambientState.getScrollY();
552 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700553 }
Selim Cinekcafa87f2016-10-26 17:00:17 -0700554 if (row.isHeadsUpAnimatingAway()) {
555 childState.hidden = false;
556 }
Selim Cinekb8f09cf2015-03-16 17:09:28 -0700557 }
Selim Cinek67b22602014-03-10 15:40:16 +0100558 }
559
Selim Cinek3776fe02016-02-04 13:32:43 -0800560 private void clampHunToTop(AmbientState ambientState, ExpandableNotificationRow row,
Selim Cinekbbcebde2016-11-09 18:28:20 -0800561 ExpandableViewState childState) {
Selim Cinek3776fe02016-02-04 13:32:43 -0800562 float newTranslation = Math.max(ambientState.getTopPadding()
563 + ambientState.getStackTranslation(), childState.yTranslation);
564 childState.height = (int) Math.max(childState.height - (newTranslation
Selim Cinek567e8452016-03-24 10:54:56 -0700565 - childState.yTranslation), row.getCollapsedHeight());
Selim Cinek3776fe02016-02-04 13:32:43 -0800566 childState.yTranslation = newTranslation;
567 }
568
569 private void clampHunToMaxTranslation(AmbientState ambientState, ExpandableNotificationRow row,
Selim Cinekbbcebde2016-11-09 18:28:20 -0800570 ExpandableViewState childState) {
Selim Cinek3776fe02016-02-04 13:32:43 -0800571 float newTranslation;
Selim Cinek7e0f9482017-05-22 20:00:56 -0700572 float maxHeadsUpTranslation = ambientState.getMaxHeadsUpTranslation();
573 float maxShelfPosition = ambientState.getInnerHeight() + ambientState.getTopPadding()
574 + ambientState.getStackTranslation();
575 maxHeadsUpTranslation = Math.min(maxHeadsUpTranslation, maxShelfPosition);
576 float bottomPosition = maxHeadsUpTranslation - row.getCollapsedHeight();
Selim Cinek3776fe02016-02-04 13:32:43 -0800577 newTranslation = Math.min(childState.yTranslation, bottomPosition);
Selim Cinek7e0f9482017-05-22 20:00:56 -0700578 childState.height = (int) Math.min(childState.height, maxHeadsUpTranslation
579 - newTranslation);
Selim Cinek3776fe02016-02-04 13:32:43 -0800580 childState.yTranslation = newTranslation;
Selim Cinek343e6e22014-04-11 21:23:30 +0200581 }
582
583 /**
Selim Cinek281c2022016-10-13 19:14:43 -0700584 * Clamp the height of the child down such that its end is at most on the beginning of
585 * the shelf.
586 *
Selim Cinek281c2022016-10-13 19:14:43 -0700587 * @param childViewState the view state of the child
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500588 * @param ambientState the ambient state
Selim Cinek281c2022016-10-13 19:14:43 -0700589 */
Selim Cinek2627d722018-01-19 12:16:49 -0800590 private void clampPositionToShelf(ExpandableView child,
591 ExpandableViewState childViewState,
Selim Cinek281c2022016-10-13 19:14:43 -0700592 AmbientState ambientState) {
Eliot Courtney5d3d2d02018-01-18 15:59:03 +0900593 if (ambientState.getShelf() == null) {
594 return;
595 }
596
Selim Cineka686b2c2016-10-26 13:58:27 -0700597 int shelfStart = ambientState.getInnerHeight()
598 - ambientState.getShelf().getIntrinsicHeight();
shawnlin5be1f7c2018-05-21 20:50:54 +0800599 if (ambientState.isAppearing() && !child.isAboveShelf()) {
600 // Don't show none heads-up notifications while in appearing phase.
601 childViewState.yTranslation = Math.max(childViewState.yTranslation, shelfStart);
602 }
Selim Cinek281c2022016-10-13 19:14:43 -0700603 childViewState.yTranslation = Math.min(childViewState.yTranslation, shelfStart);
Selim Cinekc383fd02016-10-21 15:31:26 -0700604 if (childViewState.yTranslation >= shelfStart) {
Selim Cinekc25989e2018-02-16 16:42:14 -0800605 childViewState.hidden = !child.isExpandAnimationRunning() && !child.hasExpandingChild();
Selim Cinekeccb5de2016-10-28 15:04:05 -0700606 childViewState.inShelf = true;
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100607 childViewState.headsUpIsVisible = false;
Selim Cinekc383fd02016-10-21 15:31:26 -0700608 }
Selim Cinek281c2022016-10-13 19:14:43 -0700609 }
610
Muyuan Li87798022016-04-07 17:51:25 -0700611 protected int getMaxAllowedChildHeight(View child) {
Selim Cinek31aada42015-12-18 17:51:15 -0800612 if (child instanceof ExpandableView) {
Jorim Jaggibe565df2014-04-28 17:51:23 +0200613 ExpandableView expandableView = (ExpandableView) child;
Selim Cinek8d5727f2015-04-28 19:17:32 -0700614 return expandableView.getIntrinsicHeight();
Selim Cinek1685e632014-04-08 02:27:49 +0200615 }
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500616 return child == null ? mCollapsedSize : child.getHeight();
Selim Cinek1685e632014-04-08 02:27:49 +0200617 }
618
Selim Cinek67b22602014-03-10 15:40:16 +0100619 /**
Selim Cinek67b22602014-03-10 15:40:16 +0100620 * Calculate the Z positions for all children based on the number of items in both stacks and
621 * save it in the resultState
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500622 *
Selim Cinek67b22602014-03-10 15:40:16 +0100623 * @param algorithmState The state in which the current pass of the algorithm is currently in
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500624 * @param ambientState The ambient state of the algorithm
Selim Cinek67b22602014-03-10 15:40:16 +0100625 */
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500626 private void updateZValuesForState(StackScrollAlgorithmState algorithmState,
627 AmbientState ambientState) {
Jorim Jaggid4a57442014-04-10 02:45:55 +0200628 int childCount = algorithmState.visibleChildren.size();
Selim Cinek33223572016-02-19 19:32:22 -0800629 float childrenOnTop = 0.0f;
Selim Cinek3776fe02016-02-04 13:32:43 -0800630 for (int i = childCount - 1; i >= 0; i--) {
Selim Cinekdaab6f52017-04-06 16:46:34 -0700631 childrenOnTop = updateChildZValue(i, childrenOnTop,
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500632 algorithmState, ambientState);
Muyuan Li87798022016-04-07 17:51:25 -0700633 }
634 }
635
Selim Cinekdaab6f52017-04-06 16:46:34 -0700636 protected float updateChildZValue(int i, float childrenOnTop,
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500637 StackScrollAlgorithmState algorithmState,
Muyuan Li87798022016-04-07 17:51:25 -0700638 AmbientState ambientState) {
639 ExpandableView child = algorithmState.visibleChildren.get(i);
Dave Mankoffa4d195d2018-11-16 13:33:27 -0500640 ExpandableViewState childViewState = child.getViewState();
Selim Cinek281c2022016-10-13 19:14:43 -0700641 int zDistanceBetweenElements = ambientState.getZDistanceBetweenElements();
642 float baseZ = ambientState.getBaseZHeight();
Selim Cinek9b9d6e12017-11-30 12:29:47 +0100643 if (child.mustStayOnScreen() && !childViewState.headsUpIsVisible
644 && !ambientState.isDozingAndNotPulsing(child)
Muyuan Li87798022016-04-07 17:51:25 -0700645 && childViewState.yTranslation < ambientState.getTopPadding()
646 + ambientState.getStackTranslation()) {
647 if (childrenOnTop != 0.0f) {
648 childrenOnTop++;
649 } else {
650 float overlap = ambientState.getTopPadding()
651 + ambientState.getStackTranslation() - childViewState.yTranslation;
652 childrenOnTop += Math.min(1.0f, overlap / childViewState.height);
653 }
Selim Cinek281c2022016-10-13 19:14:43 -0700654 childViewState.zTranslation = baseZ
655 + childrenOnTop * zDistanceBetweenElements;
Selim Cinek459aee32019-02-20 11:18:56 -0800656 } else if (i == 0 && child.isAboveShelf()) {
Selim Cinekd127d792016-11-01 19:11:41 -0700657 // In case this is a new view that has never been measured before, we don't want to
658 // elevate if we are currently expanded more then the notification
Eliot Courtney5d3d2d02018-01-18 15:59:03 +0900659 int shelfHeight = ambientState.getShelf() == null ? 0 :
660 ambientState.getShelf().getIntrinsicHeight();
Selim Cinekd127d792016-11-01 19:11:41 -0700661 float shelfStart = ambientState.getInnerHeight()
662 - shelfHeight + ambientState.getTopPadding()
663 + ambientState.getStackTranslation();
664 float notificationEnd = childViewState.yTranslation + child.getPinnedHeadsUpHeight()
665 + mPaddingBetweenElements;
666 if (shelfStart > notificationEnd) {
667 childViewState.zTranslation = baseZ;
668 } else {
669 float factor = (notificationEnd - shelfStart) / shelfHeight;
670 factor = Math.min(factor, 1.0f);
671 childViewState.zTranslation = baseZ + factor * zDistanceBetweenElements;
672 }
Muyuan Li87798022016-04-07 17:51:25 -0700673 } else {
Selim Cinek281c2022016-10-13 19:14:43 -0700674 childViewState.zTranslation = baseZ;
Selim Cinek67b22602014-03-10 15:40:16 +0100675 }
Selim Cinek99e9adf2018-03-15 09:17:47 -0700676
677 // We need to scrim the notification more from its surrounding content when we are pinned,
678 // and we therefore elevate it higher.
679 // We can use the headerVisibleAmount for this, since the value nicely goes from 0 to 1 when
680 // expanding after which we have a normal elevation again.
681 childViewState.zTranslation += (1.0f - child.getHeaderVisibleAmount())
682 * mPinnedZTranslationExtra;
Selim Cinekdaab6f52017-04-06 16:46:34 -0700683 return childrenOnTop;
Selim Cinek67b22602014-03-10 15:40:16 +0100684 }
685
Selim Cinek1685e632014-04-08 02:27:49 +0200686 public void setIsExpanded(boolean isExpanded) {
687 this.mIsExpanded = isExpanded;
688 }
689
Selim Cinek281c2022016-10-13 19:14:43 -0700690 public class StackScrollAlgorithmState {
Selim Cinek67b22602014-03-10 15:40:16 +0100691
692 /**
Gus Prevas0fa58d62019-01-11 13:58:40 -0500693 * The scroll position of the algorithm (absolute scrolling).
Selim Cinek67b22602014-03-10 15:40:16 +0100694 */
695 public int scrollY;
696
Gus Prevas0fa58d62019-01-11 13:58:40 -0500697 /** The index of the anchor view (anchor scrolling). */
698 public int anchorViewIndex;
699
700 /**
701 * The Y position, relative to the top of the screen, of the anchor view (anchor scrolling).
702 */
703 public int anchorViewY;
704
Selim Cinek67b22602014-03-10 15:40:16 +0100705 /**
Jorim Jaggid4a57442014-04-10 02:45:55 +0200706 * The children from the host view which are not gone.
707 */
Jorim Jaggibe565df2014-04-28 17:51:23 +0200708 public final ArrayList<ExpandableView> visibleChildren = new ArrayList<ExpandableView>();
Selim Cinek61633a82016-01-25 15:54:10 -0800709
710 /**
Selim Cineka7ed2c12017-01-23 20:47:24 -0800711 * The padding after each child measured in pixels.
Selim Cinek61633a82016-01-25 15:54:10 -0800712 */
Selim Cineka7ed2c12017-01-23 20:47:24 -0800713 public final HashMap<ExpandableView, Float> paddingMap = new HashMap<>();
Selim Cinek2627d722018-01-19 12:16:49 -0800714 private int indexOfExpandingNotification;
Selim Cinek281c2022016-10-13 19:14:43 -0700715
716 public int getPaddingAfterChild(ExpandableView child) {
Selim Cineka7ed2c12017-01-23 20:47:24 -0800717 Float padding = paddingMap.get(child);
718 if (padding == null) {
719 // Should only happen for the last view
720 return mPaddingBetweenElements;
721 }
722 return (int) padding.floatValue();
Selim Cinek281c2022016-10-13 19:14:43 -0700723 }
Selim Cinek2627d722018-01-19 12:16:49 -0800724
725 public int getIndexOfExpandingNotification() {
726 return indexOfExpandingNotification;
727 }
Selim Cinek67b22602014-03-10 15:40:16 +0100728 }
729
730}