Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [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 | |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 17 | package com.android.systemui.statusbar.notification.stack; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 18 | |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 19 | import android.annotation.NonNull; |
| 20 | import android.annotation.Nullable; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 21 | import android.content.Context; |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 22 | import android.content.res.Resources; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 23 | import android.util.Log; |
Steve Elliott | 0c904c3 | 2020-06-22 11:50:35 -0400 | [diff] [blame] | 24 | import android.util.MathUtils; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 25 | import android.view.View; |
| 26 | import android.view.ViewGroup; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 27 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 28 | import com.android.systemui.R; |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 29 | import com.android.systemui.statusbar.EmptyShadeView; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 30 | import com.android.systemui.statusbar.NotificationShelf; |
| 31 | import com.android.systemui.statusbar.notification.NotificationUtils; |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 32 | import com.android.systemui.statusbar.notification.row.ExpandableNotificationRow; |
| 33 | import com.android.systemui.statusbar.notification.row.ExpandableView; |
| 34 | import com.android.systemui.statusbar.notification.row.FooterView; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 35 | |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 36 | import java.util.ArrayList; |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 37 | import java.util.HashMap; |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 38 | import java.util.List; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 39 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 40 | /** |
Rohan Shah | 20790b8 | 2018-07-02 17:21:04 -0700 | [diff] [blame] | 41 | * The Algorithm of the {@link com.android.systemui.statusbar.notification.stack |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 42 | * .NotificationStackScrollLayout} which can be queried for {@link com.android.systemui.statusbar |
| 43 | * .stack.StackScrollState} |
| 44 | */ |
| 45 | public class StackScrollAlgorithm { |
| 46 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 47 | static final boolean ANCHOR_SCROLLING = false; |
| 48 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 49 | private static final String LOG_TAG = "StackScrollAlgorithm"; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 50 | private final ViewGroup mHostView; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 51 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 52 | private int mPaddingBetweenElements; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 53 | private int mIncreasedPaddingBetweenElements; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 54 | private int mGapHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 55 | private int mCollapsedSize; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 56 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 57 | private StackScrollAlgorithmState mTempAlgorithmState = new StackScrollAlgorithmState(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 58 | private boolean mIsExpanded; |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 59 | private boolean mClipNotificationScrollToTop; |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 60 | private int mStatusBarHeight; |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 61 | private float mHeadsUpInset; |
Selim Cinek | 99e9adf | 2018-03-15 09:17:47 -0700 | [diff] [blame] | 62 | private int mPinnedZTranslationExtra; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 63 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 64 | public StackScrollAlgorithm( |
| 65 | Context context, |
| 66 | ViewGroup hostView) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 67 | mHostView = hostView; |
Selim Cinek | af0dc31 | 2015-12-15 17:01:44 -0800 | [diff] [blame] | 68 | initView(context); |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 69 | } |
| 70 | |
Selim Cinek | af0dc31 | 2015-12-15 17:01:44 -0800 | [diff] [blame] | 71 | public void initView(Context context) { |
| 72 | initConstants(context); |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 73 | } |
| 74 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 75 | private void initConstants(Context context) { |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 76 | Resources res = context.getResources(); |
| 77 | mPaddingBetweenElements = res.getDimensionPixelSize( |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 78 | R.dimen.notification_divider_height); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 79 | mIncreasedPaddingBetweenElements = |
| 80 | res.getDimensionPixelSize(R.dimen.notification_divider_height_increased); |
| 81 | mCollapsedSize = res.getDimensionPixelSize(R.dimen.notification_min_height); |
| 82 | mStatusBarHeight = res.getDimensionPixelSize(R.dimen.status_bar_height); |
| 83 | mClipNotificationScrollToTop = res.getBoolean(R.bool.config_clipNotificationScrollToTop); |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 84 | mHeadsUpInset = mStatusBarHeight + res.getDimensionPixelSize( |
| 85 | R.dimen.heads_up_status_bar_padding); |
Selim Cinek | 99e9adf | 2018-03-15 09:17:47 -0700 | [diff] [blame] | 86 | mPinnedZTranslationExtra = res.getDimensionPixelSize( |
| 87 | R.dimen.heads_up_pinned_elevation); |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 88 | mGapHeight = res.getDimensionPixelSize(R.dimen.notification_section_divider_height); |
Jorim Jaggi | d7c1fae | 2014-08-13 18:27:47 +0200 | [diff] [blame] | 89 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 90 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 91 | /** |
| 92 | * Updates the state of all children in the hostview based on this algorithm. |
| 93 | */ |
| 94 | public void resetViewStates(AmbientState ambientState) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 95 | // The state of the local variables are saved in an algorithmState to easily subdivide it |
| 96 | // into multiple phases. |
| 97 | StackScrollAlgorithmState algorithmState = mTempAlgorithmState; |
| 98 | |
| 99 | // First we reset the view states to their default values. |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 100 | resetChildViewStates(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 101 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 102 | initAlgorithmState(mHostView, algorithmState, ambientState); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 103 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 104 | updatePositionsForState(algorithmState, ambientState); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 105 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 106 | updateZValuesForState(algorithmState, ambientState); |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 107 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 108 | updateHeadsUpStates(algorithmState, ambientState); |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 109 | updatePulsingStates(algorithmState, ambientState); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 110 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 111 | updateDimmedActivatedHideSensitive(ambientState, algorithmState); |
| 112 | updateClipping(algorithmState, ambientState); |
| 113 | updateSpeedBumpState(algorithmState, ambientState); |
| 114 | updateShelfState(ambientState); |
| 115 | getNotificationChildrenStates(algorithmState, ambientState); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 116 | } |
| 117 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 118 | private void resetChildViewStates() { |
| 119 | int numChildren = mHostView.getChildCount(); |
| 120 | for (int i = 0; i < numChildren; i++) { |
| 121 | ExpandableView child = (ExpandableView) mHostView.getChildAt(i); |
| 122 | child.resetViewState(); |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | private void getNotificationChildrenStates(StackScrollAlgorithmState algorithmState, |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 127 | AmbientState ambientState) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 128 | int childCount = algorithmState.visibleChildren.size(); |
| 129 | for (int i = 0; i < childCount; i++) { |
| 130 | ExpandableView v = algorithmState.visibleChildren.get(i); |
| 131 | if (v instanceof ExpandableNotificationRow) { |
| 132 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 133 | row.updateChildrenStates(ambientState); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 134 | } |
| 135 | } |
Selim Cinek | 3d2b94bf | 2014-07-02 22:12:47 +0200 | [diff] [blame] | 136 | } |
| 137 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 138 | private void updateSpeedBumpState(StackScrollAlgorithmState algorithmState, |
| 139 | AmbientState ambientState) { |
Selim Cinek | 3d2b94bf | 2014-07-02 22:12:47 +0200 | [diff] [blame] | 140 | int childCount = algorithmState.visibleChildren.size(); |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 141 | int belowSpeedBump = ambientState.getSpeedBumpIndex(); |
Selim Cinek | 3d2b94bf | 2014-07-02 22:12:47 +0200 | [diff] [blame] | 142 | for (int i = 0; i < childCount; i++) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 143 | ExpandableView child = algorithmState.visibleChildren.get(i); |
| 144 | ExpandableViewState childViewState = child.getViewState(); |
Selim Cinek | 3107cfa | 2014-07-22 15:24:29 +0200 | [diff] [blame] | 145 | |
| 146 | // The speed bump can also be gone, so equality needs to be taken when comparing |
| 147 | // indices. |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 148 | childViewState.belowSpeedBump = i >= belowSpeedBump; |
Selim Cinek | 3d2b94bf | 2014-07-02 22:12:47 +0200 | [diff] [blame] | 149 | } |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 150 | |
| 151 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 152 | |
| 153 | private void updateShelfState(AmbientState ambientState) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 154 | NotificationShelf shelf = ambientState.getShelf(); |
Eliot Courtney | 5d3d2d0 | 2018-01-18 15:59:03 +0900 | [diff] [blame] | 155 | if (shelf != null) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 156 | shelf.updateState(ambientState); |
Eliot Courtney | 5d3d2d0 | 2018-01-18 15:59:03 +0900 | [diff] [blame] | 157 | } |
Selim Cinek | f54090e | 2014-06-17 17:24:51 -0700 | [diff] [blame] | 158 | } |
| 159 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 160 | private void updateClipping(StackScrollAlgorithmState algorithmState, |
| 161 | AmbientState ambientState) { |
Selim Cinek | 355652a | 2016-12-07 13:32:12 -0800 | [diff] [blame] | 162 | float drawStart = !ambientState.isOnKeyguard() ? ambientState.getTopPadding() |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 163 | + ambientState.getStackTranslation() + ambientState.getExpandAnimationTopChange() |
| 164 | : 0; |
Selim Cinek | 8f3f03f | 2019-07-18 14:19:54 -0700 | [diff] [blame] | 165 | float clipStart = 0; |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 166 | int childCount = algorithmState.visibleChildren.size(); |
Selim Cinek | 3ff6f50 | 2019-07-29 16:33:48 -0700 | [diff] [blame] | 167 | boolean firstHeadsUp = true; |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 168 | for (int i = 0; i < childCount; i++) { |
| 169 | ExpandableView child = algorithmState.visibleChildren.get(i); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 170 | ExpandableViewState state = child.getViewState(); |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 171 | if (!child.mustStayOnScreen() || state.headsUpIsVisible) { |
Selim Cinek | 8f3f03f | 2019-07-18 14:19:54 -0700 | [diff] [blame] | 172 | clipStart = Math.max(drawStart, clipStart); |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 173 | } |
Selim Cinek | 587cbf3 | 2016-01-19 11:36:18 -0800 | [diff] [blame] | 174 | float newYTranslation = state.yTranslation; |
| 175 | float newHeight = state.height; |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 176 | float newNotificationEnd = newYTranslation + newHeight; |
Mady Mellor | 53ac1ef | 2016-06-20 13:11:38 -0700 | [diff] [blame] | 177 | boolean isHeadsUp = (child instanceof ExpandableNotificationRow) |
| 178 | && ((ExpandableNotificationRow) child).isPinned(); |
Anthony Chen | 9fe1ee7 | 2017-04-07 13:53:37 -0700 | [diff] [blame] | 179 | if (mClipNotificationScrollToTop |
Selim Cinek | 3ff6f50 | 2019-07-29 16:33:48 -0700 | [diff] [blame] | 180 | && (!state.inShelf || (isHeadsUp && !firstHeadsUp)) |
Selim Cinek | 8f3f03f | 2019-07-18 14:19:54 -0700 | [diff] [blame] | 181 | && newYTranslation < clipStart) { |
Mady Mellor | c128f22 | 2016-04-26 11:42:46 -0700 | [diff] [blame] | 182 | // The previous view is overlapping on top, clip! |
Selim Cinek | 8f3f03f | 2019-07-18 14:19:54 -0700 | [diff] [blame] | 183 | float overlapAmount = clipStart - newYTranslation; |
Mady Mellor | c128f22 | 2016-04-26 11:42:46 -0700 | [diff] [blame] | 184 | state.clipTopAmount = (int) overlapAmount; |
Selim Cinek | c5baa3e | 2014-10-29 19:04:19 +0100 | [diff] [blame] | 185 | } else { |
Mady Mellor | c128f22 | 2016-04-26 11:42:46 -0700 | [diff] [blame] | 186 | state.clipTopAmount = 0; |
Selim Cinek | 9c17b77 | 2015-07-07 20:37:09 -0700 | [diff] [blame] | 187 | } |
Selim Cinek | 3ff6f50 | 2019-07-29 16:33:48 -0700 | [diff] [blame] | 188 | if (isHeadsUp) { |
| 189 | firstHeadsUp = false; |
| 190 | } |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 191 | if (!child.isTransparent()) { |
| 192 | // Only update the previous values if we are not transparent, |
| 193 | // otherwise we would clip to a transparent view. |
Selim Cinek | 8f3f03f | 2019-07-18 14:19:54 -0700 | [diff] [blame] | 194 | clipStart = Math.max(clipStart, isHeadsUp ? newYTranslation : newNotificationEnd); |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | } |
| 198 | |
| 199 | /** |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 200 | * Updates the dimmed, activated and hiding sensitive states of the children. |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 201 | */ |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 202 | private void updateDimmedActivatedHideSensitive(AmbientState ambientState, |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 203 | StackScrollAlgorithmState algorithmState) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 204 | boolean dimmed = ambientState.isDimmed(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 205 | boolean hideSensitive = ambientState.isHideSensitive(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 206 | View activatedChild = ambientState.getActivatedChild(); |
| 207 | int childCount = algorithmState.visibleChildren.size(); |
| 208 | for (int i = 0; i < childCount; i++) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 209 | ExpandableView child = algorithmState.visibleChildren.get(i); |
| 210 | ExpandableViewState childViewState = child.getViewState(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 211 | childViewState.dimmed = dimmed; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 212 | childViewState.hideSensitive = hideSensitive; |
Selim Cinek | b89de4e | 2014-06-10 10:47:05 +0200 | [diff] [blame] | 213 | boolean isActivatedChild = activatedChild == child; |
Jorim Jaggi | 4538cee | 2014-09-09 15:21:38 +0200 | [diff] [blame] | 214 | if (dimmed && isActivatedChild) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 215 | childViewState.zTranslation += 2.0f * ambientState.getZDistanceBetweenElements(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 216 | } |
| 217 | } |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | /** |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 221 | * Initialize the algorithm state like updating the visible children. |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 222 | */ |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 223 | private void initAlgorithmState(ViewGroup hostView, StackScrollAlgorithmState state, |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 224 | AmbientState ambientState) { |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 225 | float bottomOverScroll = ambientState.getOverScrollAmount(false /* onTop */); |
| 226 | |
| 227 | int scrollY = ambientState.getScrollY(); |
| 228 | |
| 229 | // Due to the overScroller, the stackscroller can have negative scroll state. This is |
| 230 | // already accounted for by the top padding and doesn't need an additional adaption |
| 231 | scrollY = Math.max(0, scrollY); |
| 232 | state.scrollY = (int) (scrollY + bottomOverScroll); |
| 233 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 234 | if (ANCHOR_SCROLLING) { |
| 235 | state.anchorViewY = (int) (ambientState.getAnchorViewY() - bottomOverScroll); |
| 236 | } |
| 237 | |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 238 | //now init the visible children and update paddings |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 239 | int childCount = hostView.getChildCount(); |
| 240 | state.visibleChildren.clear(); |
| 241 | state.visibleChildren.ensureCapacity(childCount); |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 242 | state.paddingMap.clear(); |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame] | 243 | int notGoneIndex = 0; |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 244 | ExpandableView lastView = null; |
Selim Cinek | c1d9ab2 | 2019-05-21 18:08:30 -0700 | [diff] [blame] | 245 | int firstHiddenIndex = ambientState.isDozing() |
Selim Cinek | d96ed40 | 2017-07-28 18:19:03 -0700 | [diff] [blame] | 246 | ? (ambientState.hasPulsingNotifications() ? 1 : 0) |
| 247 | : childCount; |
| 248 | |
| 249 | // The goal here is to fill the padding map, by iterating over how much padding each child |
| 250 | // needs. The map is thereby reused, by first filling it with the padding amount and when |
| 251 | // iterating over it again, it's filled with the actual resolved value. |
| 252 | |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 253 | for (int i = 0; i < childCount; i++) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 254 | if (ANCHOR_SCROLLING) { |
| 255 | if (i == ambientState.getAnchorViewIndex()) { |
| 256 | state.anchorViewIndex = state.visibleChildren.size(); |
| 257 | } |
| 258 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 259 | ExpandableView v = (ExpandableView) hostView.getChildAt(i); |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 260 | if (v.getVisibility() != View.GONE) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 261 | if (v == ambientState.getShelf()) { |
| 262 | continue; |
| 263 | } |
Selim Cinek | d96ed40 | 2017-07-28 18:19:03 -0700 | [diff] [blame] | 264 | if (i >= firstHiddenIndex) { |
| 265 | // we need normal padding now, to be in sync with what the stack calculates |
| 266 | lastView = null; |
Selim Cinek | d96ed40 | 2017-07-28 18:19:03 -0700 | [diff] [blame] | 267 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 268 | notGoneIndex = updateNotGoneIndex(state, notGoneIndex, v); |
Selim Cinek | d96ed40 | 2017-07-28 18:19:03 -0700 | [diff] [blame] | 269 | float increasedPadding = v.getIncreasedPaddingAmount(); |
Selim Cinek | 42357e0 | 2016-02-24 18:48:01 -0800 | [diff] [blame] | 270 | if (increasedPadding != 0.0f) { |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 271 | state.paddingMap.put(v, increasedPadding); |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 272 | if (lastView != null) { |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 273 | Float prevValue = state.paddingMap.get(lastView); |
| 274 | float newValue = getPaddingForValue(increasedPadding); |
| 275 | if (prevValue != null) { |
| 276 | float prevPadding = getPaddingForValue(prevValue); |
| 277 | if (increasedPadding > 0) { |
| 278 | newValue = NotificationUtils.interpolate( |
| 279 | prevPadding, |
| 280 | newValue, |
| 281 | increasedPadding); |
| 282 | } else if (prevValue > 0) { |
| 283 | newValue = NotificationUtils.interpolate( |
| 284 | newValue, |
| 285 | prevPadding, |
| 286 | prevValue); |
| 287 | } |
| 288 | } |
| 289 | state.paddingMap.put(lastView, newValue); |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 290 | } |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 291 | } else if (lastView != null) { |
Selim Cinek | d96ed40 | 2017-07-28 18:19:03 -0700 | [diff] [blame] | 292 | |
| 293 | // Let's now resolve the value to an actual padding |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 294 | float newValue = getPaddingForValue(state.paddingMap.get(lastView)); |
| 295 | state.paddingMap.put(lastView, newValue); |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 296 | } |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 297 | if (v instanceof ExpandableNotificationRow) { |
| 298 | ExpandableNotificationRow row = (ExpandableNotificationRow) v; |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 299 | |
| 300 | // handle the notgoneIndex for the children as well |
Kevin Han | 43077f9 | 2020-02-28 12:51:53 -0800 | [diff] [blame] | 301 | List<ExpandableNotificationRow> children = row.getAttachedChildren(); |
Selim Cinek | 83bc783 | 2015-10-22 13:26:54 -0700 | [diff] [blame] | 302 | if (row.isSummaryWithChildren() && children != null) { |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 303 | for (ExpandableNotificationRow childRow : children) { |
| 304 | if (childRow.getVisibility() != View.GONE) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 305 | ExpandableViewState childState = childRow.getViewState(); |
Selim Cinek | b5605e5 | 2015-02-20 18:21:41 +0100 | [diff] [blame] | 306 | childState.notGoneIndex = notGoneIndex; |
| 307 | notGoneIndex++; |
| 308 | } |
| 309 | } |
| 310 | } |
| 311 | } |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 312 | lastView = v; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 313 | } |
| 314 | } |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 315 | ExpandableNotificationRow expandingNotification = ambientState.getExpandingNotification(); |
| 316 | state.indexOfExpandingNotification = expandingNotification != null |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 317 | ? expandingNotification.isChildInGroup() |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 318 | ? state.visibleChildren.indexOf(expandingNotification.getNotificationParent()) |
| 319 | : state.visibleChildren.indexOf(expandingNotification) |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 320 | : -1; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 321 | } |
| 322 | |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 323 | private float getPaddingForValue(Float increasedPadding) { |
| 324 | if (increasedPadding == null) { |
| 325 | return mPaddingBetweenElements; |
| 326 | } else if (increasedPadding >= 0.0f) { |
| 327 | return NotificationUtils.interpolate( |
| 328 | mPaddingBetweenElements, |
| 329 | mIncreasedPaddingBetweenElements, |
| 330 | increasedPadding); |
| 331 | } else { |
| 332 | return NotificationUtils.interpolate( |
| 333 | 0, |
| 334 | mPaddingBetweenElements, |
| 335 | 1.0f + increasedPadding); |
| 336 | } |
| 337 | } |
| 338 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 339 | private int updateNotGoneIndex(StackScrollAlgorithmState state, int notGoneIndex, |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 340 | ExpandableView v) { |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 341 | ExpandableViewState viewState = v.getViewState(); |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 342 | viewState.notGoneIndex = notGoneIndex; |
| 343 | state.visibleChildren.add(v); |
| 344 | notGoneIndex++; |
| 345 | return notGoneIndex; |
| 346 | } |
| 347 | |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 348 | /** |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 349 | * Determine the positions for the views. This is the main part of the algorithm. |
| 350 | * |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 351 | * @param algorithmState The state in which the current pass of the algorithm is currently in |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 352 | * @param ambientState The current ambient state |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 353 | */ |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 354 | private void updatePositionsForState(StackScrollAlgorithmState algorithmState, |
| 355 | AmbientState ambientState) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 356 | if (ANCHOR_SCROLLING) { |
| 357 | float currentYPosition = algorithmState.anchorViewY; |
| 358 | int childCount = algorithmState.visibleChildren.size(); |
| 359 | for (int i = algorithmState.anchorViewIndex; i < childCount; i++) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 360 | currentYPosition = updateChild(i, algorithmState, ambientState, currentYPosition, |
| 361 | false /* reverse */); |
| 362 | } |
| 363 | currentYPosition = algorithmState.anchorViewY; |
| 364 | for (int i = algorithmState.anchorViewIndex - 1; i >= 0; i--) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 365 | currentYPosition = updateChild(i, algorithmState, ambientState, currentYPosition, |
| 366 | true /* reverse */); |
| 367 | } |
| 368 | } else { |
| 369 | // The y coordinate of the current child. |
| 370 | float currentYPosition = -algorithmState.scrollY; |
| 371 | int childCount = algorithmState.visibleChildren.size(); |
| 372 | for (int i = 0; i < childCount; i++) { |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 373 | currentYPosition = updateChild(i, algorithmState, ambientState, currentYPosition, |
| 374 | false /* reverse */); |
| 375 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 376 | } |
| 377 | } |
| 378 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 379 | /** |
| 380 | * Populates the {@link ExpandableViewState} for a single child. |
| 381 | * |
| 382 | * @param i The index of the child in |
| 383 | * {@link StackScrollAlgorithmState#visibleChildren}. |
| 384 | * @param algorithmState The overall output state of the algorithm. |
| 385 | * @param ambientState The input state provided to the algorithm. |
| 386 | * @param currentYPosition The Y position of the current pass of the algorithm. For a forward |
| 387 | * pass, this should be the top of the child; for a reverse pass, the |
| 388 | * bottom of the child. |
| 389 | * @param reverse Whether we're laying out children in the reverse direction (Y |
| 390 | * positions |
| 391 | * decreasing) instead of the forward direction (Y positions |
| 392 | * increasing). |
| 393 | * @return The Y position after laying out the child. This will be the {@code currentYPosition} |
| 394 | * for the next call to this method, after adjusting for any gaps between children. |
| 395 | */ |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 396 | protected float updateChild( |
| 397 | int i, |
| 398 | StackScrollAlgorithmState algorithmState, |
| 399 | AmbientState ambientState, |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 400 | float currentYPosition, |
| 401 | boolean reverse) { |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 402 | ExpandableView child = algorithmState.visibleChildren.get(i); |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 403 | ExpandableView previousChild = i > 0 ? algorithmState.visibleChildren.get(i - 1) : null; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 404 | final boolean applyGapHeight = |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 405 | childNeedsGapHeight( |
Selim Cinek | 54ef7be | 2020-05-27 19:09:21 -0700 | [diff] [blame] | 406 | ambientState.getSectionProvider(), algorithmState.anchorViewIndex, i, |
| 407 | child, previousChild); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 408 | ExpandableViewState childViewState = child.getViewState(); |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 409 | childViewState.location = ExpandableViewState.LOCATION_UNKNOWN; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 410 | |
| 411 | if (applyGapHeight && !reverse) { |
| 412 | currentYPosition += mGapHeight; |
| 413 | } |
| 414 | |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 415 | int paddingAfterChild = getPaddingAfterChild(algorithmState, child); |
| 416 | int childHeight = getMaxAllowedChildHeight(child); |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 417 | if (reverse) { |
| 418 | childViewState.yTranslation = currentYPosition - (childHeight + paddingAfterChild); |
| 419 | if (currentYPosition <= 0) { |
| 420 | childViewState.location = ExpandableViewState.LOCATION_HIDDEN_TOP; |
| 421 | } |
| 422 | } else { |
| 423 | childViewState.yTranslation = currentYPosition; |
Gus Prevas | e2d6f04 | 2018-10-17 15:25:30 -0400 | [diff] [blame] | 424 | } |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 425 | boolean isFooterView = child instanceof FooterView; |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 426 | boolean isEmptyShadeView = child instanceof EmptyShadeView; |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 427 | |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 428 | childViewState.location = ExpandableViewState.LOCATION_MAIN_AREA; |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 429 | float inset = ambientState.getTopPadding() + ambientState.getStackTranslation(); |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 430 | if (i <= algorithmState.getIndexOfExpandingNotification()) { |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 431 | inset += ambientState.getExpandAnimationTopChange(); |
| 432 | } |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 433 | if (child.mustStayOnScreen() && childViewState.yTranslation >= 0) { |
| 434 | // Even if we're not scrolled away we're in view and we're also not in the |
| 435 | // shelf. We can relax the constraints and let us scroll off the top! |
| 436 | float end = childViewState.yTranslation + childViewState.height + inset; |
| 437 | childViewState.headsUpIsVisible = end < ambientState.getMaxHeadsUpTranslation(); |
| 438 | } |
Julia Reynolds | ed1c9af | 2018-03-21 15:21:09 -0400 | [diff] [blame] | 439 | if (isFooterView) { |
Selim Cinek | db16737 | 2016-11-17 15:41:17 -0800 | [diff] [blame] | 440 | childViewState.yTranslation = Math.min(childViewState.yTranslation, |
| 441 | ambientState.getInnerHeight() - childHeight); |
Selim Cinek | cde90e5 | 2016-12-22 21:01:49 +0100 | [diff] [blame] | 442 | } else if (isEmptyShadeView) { |
| 443 | childViewState.yTranslation = ambientState.getInnerHeight() - childHeight |
| 444 | + ambientState.getStackTranslation() * 0.25f; |
Steve Elliott | 0c904c3 | 2020-06-22 11:50:35 -0400 | [diff] [blame] | 445 | } else if (child != ambientState.getTrackedHeadsUpRow()) { |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 446 | clampPositionToShelf(child, childViewState, ambientState); |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 449 | if (reverse) { |
| 450 | currentYPosition = childViewState.yTranslation; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 451 | if (applyGapHeight) { |
| 452 | currentYPosition -= mGapHeight; |
| 453 | } |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 454 | } else { |
| 455 | currentYPosition = childViewState.yTranslation + childHeight + paddingAfterChild; |
| 456 | if (currentYPosition <= 0) { |
| 457 | childViewState.location = ExpandableViewState.LOCATION_HIDDEN_TOP; |
| 458 | } |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 459 | } |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 460 | if (childViewState.location == ExpandableViewState.LOCATION_UNKNOWN) { |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 461 | Log.wtf(LOG_TAG, "Failed to assign location for child " + i); |
| 462 | } |
| 463 | |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 464 | childViewState.yTranslation += inset; |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 465 | return currentYPosition; |
| 466 | } |
| 467 | |
Selim Cinek | 54ef7be | 2020-05-27 19:09:21 -0700 | [diff] [blame] | 468 | /** |
| 469 | * Get the gap height needed for before a view |
| 470 | * |
| 471 | * @param sectionProvider the sectionProvider used to understand the sections |
| 472 | * @param anchorViewIndex the anchorView index when anchor scrolling, can be 0 if not |
| 473 | * @param visibleIndex the visible index of this view in the list |
| 474 | * @param child the child asked about |
| 475 | * @param previousChild the child right before it or null if none |
| 476 | * @return the size of the gap needed or 0 if none is needed |
| 477 | */ |
| 478 | public float getGapHeightForChild( |
| 479 | SectionProvider sectionProvider, |
| 480 | int anchorViewIndex, |
| 481 | int visibleIndex, |
| 482 | View child, |
| 483 | View previousChild) { |
| 484 | |
| 485 | if (childNeedsGapHeight(sectionProvider, anchorViewIndex, visibleIndex, child, |
| 486 | previousChild)) { |
| 487 | return mGapHeight; |
| 488 | } else { |
| 489 | return 0; |
| 490 | } |
| 491 | } |
| 492 | |
| 493 | /** |
| 494 | * Does a given child need a gap, i.e spacing before a view? |
| 495 | * |
| 496 | * @param sectionProvider the sectionProvider used to understand the sections |
| 497 | * @param anchorViewIndex the anchorView index when anchor scrolling, can be 0 if not |
| 498 | * @param visibleIndex the visible index of this view in the list |
| 499 | * @param child the child asked about |
| 500 | * @param previousChild the child right before it or null if none |
| 501 | * @return if the child needs a gap height |
| 502 | */ |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 503 | private boolean childNeedsGapHeight( |
| 504 | SectionProvider sectionProvider, |
Selim Cinek | 54ef7be | 2020-05-27 19:09:21 -0700 | [diff] [blame] | 505 | int anchorViewIndex, |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 506 | int visibleIndex, |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 507 | View child, |
| 508 | View previousChild) { |
| 509 | |
| 510 | boolean needsGapHeight = sectionProvider.beginsSection(child, previousChild) |
| 511 | && visibleIndex > 0; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 512 | if (ANCHOR_SCROLLING) { |
Selim Cinek | 54ef7be | 2020-05-27 19:09:21 -0700 | [diff] [blame] | 513 | needsGapHeight &= visibleIndex != anchorViewIndex; |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 514 | } |
| 515 | return needsGapHeight; |
| 516 | } |
| 517 | |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 518 | protected int getPaddingAfterChild(StackScrollAlgorithmState algorithmState, |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 519 | ExpandableView child) { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 520 | return algorithmState.getPaddingAfterChild(child); |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 521 | } |
| 522 | |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 523 | private void updatePulsingStates(StackScrollAlgorithmState algorithmState, |
| 524 | AmbientState ambientState) { |
| 525 | int childCount = algorithmState.visibleChildren.size(); |
| 526 | for (int i = 0; i < childCount; i++) { |
| 527 | View child = algorithmState.visibleChildren.get(i); |
| 528 | if (!(child instanceof ExpandableNotificationRow)) { |
| 529 | continue; |
| 530 | } |
| 531 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 532 | if (!row.showingPulsing() || (i == 0 && ambientState.isPulseExpanding())) { |
Selim Cinek | 5040f2e | 2019-02-14 18:22:42 -0800 | [diff] [blame] | 533 | continue; |
| 534 | } |
| 535 | ExpandableViewState viewState = row.getViewState(); |
| 536 | viewState.hidden = false; |
| 537 | } |
| 538 | } |
| 539 | |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 540 | private void updateHeadsUpStates(StackScrollAlgorithmState algorithmState, |
| 541 | AmbientState ambientState) { |
Selim Cinek | a4baaa3 | 2015-04-20 14:27:54 -0700 | [diff] [blame] | 542 | int childCount = algorithmState.visibleChildren.size(); |
Steve Elliott | 0c904c3 | 2020-06-22 11:50:35 -0400 | [diff] [blame] | 543 | |
| 544 | // Move the tracked heads up into position during the appear animation, by interpolating |
| 545 | // between the HUN inset (where it will appear as a HUN) and the end position in the shade |
| 546 | ExpandableNotificationRow trackedHeadsUpRow = ambientState.getTrackedHeadsUpRow(); |
| 547 | if (trackedHeadsUpRow != null) { |
| 548 | ExpandableViewState childState = trackedHeadsUpRow.getViewState(); |
| 549 | if (childState != null) { |
| 550 | float endPosition = childState.yTranslation - ambientState.getStackTranslation(); |
| 551 | childState.yTranslation = MathUtils.lerp( |
| 552 | mHeadsUpInset, endPosition, ambientState.getAppearFraction()); |
| 553 | } |
| 554 | } |
| 555 | |
Selim Cinek | a4baaa3 | 2015-04-20 14:27:54 -0700 | [diff] [blame] | 556 | ExpandableNotificationRow topHeadsUpEntry = null; |
| 557 | for (int i = 0; i < childCount; i++) { |
| 558 | View child = algorithmState.visibleChildren.get(i); |
| 559 | if (!(child instanceof ExpandableNotificationRow)) { |
Selim Cinek | a3f6f88 | 2019-07-04 19:20:32 -0700 | [diff] [blame] | 560 | continue; |
Selim Cinek | a4baaa3 | 2015-04-20 14:27:54 -0700 | [diff] [blame] | 561 | } |
| 562 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
| 563 | if (!row.isHeadsUp()) { |
Selim Cinek | a3f6f88 | 2019-07-04 19:20:32 -0700 | [diff] [blame] | 564 | continue; |
Selim Cinek | a4baaa3 | 2015-04-20 14:27:54 -0700 | [diff] [blame] | 565 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 566 | ExpandableViewState childState = row.getViewState(); |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 567 | if (topHeadsUpEntry == null && row.mustStayOnScreen() && !childState.headsUpIsVisible) { |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 568 | topHeadsUpEntry = row; |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 569 | childState.location = ExpandableViewState.LOCATION_FIRST_HUN; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 570 | } |
Selim Cinek | 1f3f544 | 2015-04-10 17:54:46 -0700 | [diff] [blame] | 571 | boolean isTopEntry = topHeadsUpEntry == row; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 572 | float unmodifiedEndLocation = childState.yTranslation + childState.height; |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 573 | if (mIsExpanded) { |
Selim Cinek | c3fec68 | 2019-06-06 18:11:07 -0700 | [diff] [blame] | 574 | if (row.mustStayOnScreen() && !childState.headsUpIsVisible |
| 575 | && !row.showingPulsing()) { |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 576 | // Ensure that the heads up is always visible even when scrolled off |
| 577 | clampHunToTop(ambientState, row, childState); |
Steve Elliott | 0c904c3 | 2020-06-22 11:50:35 -0400 | [diff] [blame] | 578 | if (isTopEntry && row.isAboveShelf()) { |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 579 | // the first hun can't get off screen. |
| 580 | clampHunToMaxTranslation(ambientState, row, childState); |
| 581 | childState.hidden = false; |
| 582 | } |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 583 | } |
Selim Cinek | 131c1e2 | 2015-05-11 19:04:49 -0700 | [diff] [blame] | 584 | } |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 585 | if (row.isPinned()) { |
Selim Cinek | aa9db1f | 2018-02-27 17:35:47 -0800 | [diff] [blame] | 586 | childState.yTranslation = Math.max(childState.yTranslation, mHeadsUpInset); |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 587 | childState.height = Math.max(row.getIntrinsicHeight(), childState.height); |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 588 | childState.hidden = false; |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 589 | ExpandableViewState topState = |
| 590 | topHeadsUpEntry == null ? null : topHeadsUpEntry.getViewState(); |
Selim Cinek | 61cfd4b | 2017-12-08 12:42:36 -0800 | [diff] [blame] | 591 | if (topState != null && !isTopEntry && (!mIsExpanded |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 592 | || unmodifiedEndLocation > topState.yTranslation + topState.height)) { |
Selim Cinek | 684a442 | 2015-04-15 16:18:39 -0700 | [diff] [blame] | 593 | // Ensure that a headsUp doesn't vertically extend further than the heads-up at |
| 594 | // the top most z-position |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 595 | childState.height = row.getIntrinsicHeight(); |
Selim Cinek | e3c6e46 | 2019-06-24 19:37:06 -0700 | [diff] [blame] | 596 | childState.yTranslation = Math.min(topState.yTranslation + topState.height |
| 597 | - childState.height, childState.yTranslation); |
Selim Cinek | 1f3f544 | 2015-04-10 17:54:46 -0700 | [diff] [blame] | 598 | } |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 599 | |
| 600 | // heads up notification show and this row is the top entry of heads up |
| 601 | // notifications. i.e. this row should be the only one row that has input field |
| 602 | // To check if the row need to do translation according to scroll Y |
| 603 | // heads up show full of row's content and any scroll y indicate that the |
| 604 | // translationY need to move up the HUN. |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 605 | // TODO: fix this check for anchor scrolling. |
felkachang | 529bfe6 | 2018-07-04 12:51:44 +0800 | [diff] [blame] | 606 | if (!mIsExpanded && isTopEntry && ambientState.getScrollY() > 0) { |
| 607 | childState.yTranslation -= ambientState.getScrollY(); |
| 608 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 609 | } |
Selim Cinek | cafa87f | 2016-10-26 17:00:17 -0700 | [diff] [blame] | 610 | if (row.isHeadsUpAnimatingAway()) { |
| 611 | childState.hidden = false; |
| 612 | } |
Selim Cinek | b8f09cf | 2015-03-16 17:09:28 -0700 | [diff] [blame] | 613 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 614 | } |
| 615 | |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 616 | private void clampHunToTop(AmbientState ambientState, ExpandableNotificationRow row, |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 617 | ExpandableViewState childState) { |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 618 | float newTranslation = Math.max(ambientState.getTopPadding() |
| 619 | + ambientState.getStackTranslation(), childState.yTranslation); |
| 620 | childState.height = (int) Math.max(childState.height - (newTranslation |
Selim Cinek | 567e845 | 2016-03-24 10:54:56 -0700 | [diff] [blame] | 621 | - childState.yTranslation), row.getCollapsedHeight()); |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 622 | childState.yTranslation = newTranslation; |
| 623 | } |
| 624 | |
| 625 | private void clampHunToMaxTranslation(AmbientState ambientState, ExpandableNotificationRow row, |
Selim Cinek | bbcebde | 2016-11-09 18:28:20 -0800 | [diff] [blame] | 626 | ExpandableViewState childState) { |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 627 | float newTranslation; |
Selim Cinek | 7e0f948 | 2017-05-22 20:00:56 -0700 | [diff] [blame] | 628 | float maxHeadsUpTranslation = ambientState.getMaxHeadsUpTranslation(); |
| 629 | float maxShelfPosition = ambientState.getInnerHeight() + ambientState.getTopPadding() |
| 630 | + ambientState.getStackTranslation(); |
| 631 | maxHeadsUpTranslation = Math.min(maxHeadsUpTranslation, maxShelfPosition); |
| 632 | float bottomPosition = maxHeadsUpTranslation - row.getCollapsedHeight(); |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 633 | newTranslation = Math.min(childState.yTranslation, bottomPosition); |
Selim Cinek | 7e0f948 | 2017-05-22 20:00:56 -0700 | [diff] [blame] | 634 | childState.height = (int) Math.min(childState.height, maxHeadsUpTranslation |
| 635 | - newTranslation); |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 636 | childState.yTranslation = newTranslation; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | /** |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 640 | * Clamp the height of the child down such that its end is at most on the beginning of |
| 641 | * the shelf. |
| 642 | * |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 643 | * @param childViewState the view state of the child |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 644 | * @param ambientState the ambient state |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 645 | */ |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 646 | private void clampPositionToShelf(ExpandableView child, |
| 647 | ExpandableViewState childViewState, |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 648 | AmbientState ambientState) { |
Eliot Courtney | 5d3d2d0 | 2018-01-18 15:59:03 +0900 | [diff] [blame] | 649 | if (ambientState.getShelf() == null) { |
| 650 | return; |
| 651 | } |
| 652 | |
Steve Elliott | 0c904c3 | 2020-06-22 11:50:35 -0400 | [diff] [blame] | 653 | ExpandableNotificationRow trackedHeadsUpRow = ambientState.getTrackedHeadsUpRow(); |
| 654 | boolean isBeforeTrackedHeadsUp = trackedHeadsUpRow != null |
| 655 | && mHostView.indexOfChild(child) < mHostView.indexOfChild(trackedHeadsUpRow); |
| 656 | |
Selim Cinek | a686b2c | 2016-10-26 13:58:27 -0700 | [diff] [blame] | 657 | int shelfStart = ambientState.getInnerHeight() |
| 658 | - ambientState.getShelf().getIntrinsicHeight(); |
Steve Elliott | 0c904c3 | 2020-06-22 11:50:35 -0400 | [diff] [blame] | 659 | if (ambientState.isAppearing() && !child.isAboveShelf() && !isBeforeTrackedHeadsUp) { |
shawnlin | 5be1f7c | 2018-05-21 20:50:54 +0800 | [diff] [blame] | 660 | // Don't show none heads-up notifications while in appearing phase. |
| 661 | childViewState.yTranslation = Math.max(childViewState.yTranslation, shelfStart); |
| 662 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 663 | childViewState.yTranslation = Math.min(childViewState.yTranslation, shelfStart); |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 664 | if (childViewState.yTranslation >= shelfStart) { |
Selim Cinek | c25989e | 2018-02-16 16:42:14 -0800 | [diff] [blame] | 665 | childViewState.hidden = !child.isExpandAnimationRunning() && !child.hasExpandingChild(); |
Selim Cinek | eccb5de | 2016-10-28 15:04:05 -0700 | [diff] [blame] | 666 | childViewState.inShelf = true; |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 667 | childViewState.headsUpIsVisible = false; |
Selim Cinek | c383fd0 | 2016-10-21 15:31:26 -0700 | [diff] [blame] | 668 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 669 | } |
| 670 | |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 671 | protected int getMaxAllowedChildHeight(View child) { |
Selim Cinek | 31aada4 | 2015-12-18 17:51:15 -0800 | [diff] [blame] | 672 | if (child instanceof ExpandableView) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 673 | ExpandableView expandableView = (ExpandableView) child; |
Selim Cinek | 8d5727f | 2015-04-28 19:17:32 -0700 | [diff] [blame] | 674 | return expandableView.getIntrinsicHeight(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 675 | } |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 676 | return child == null ? mCollapsedSize : child.getHeight(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 677 | } |
| 678 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 679 | /** |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 680 | * Calculate the Z positions for all children based on the number of items in both stacks and |
| 681 | * save it in the resultState |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 682 | * |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 683 | * @param algorithmState The state in which the current pass of the algorithm is currently in |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 684 | * @param ambientState The ambient state of the algorithm |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 685 | */ |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 686 | private void updateZValuesForState(StackScrollAlgorithmState algorithmState, |
| 687 | AmbientState ambientState) { |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 688 | int childCount = algorithmState.visibleChildren.size(); |
Selim Cinek | 3322357 | 2016-02-19 19:32:22 -0800 | [diff] [blame] | 689 | float childrenOnTop = 0.0f; |
Selim Cinek | 3776fe0 | 2016-02-04 13:32:43 -0800 | [diff] [blame] | 690 | for (int i = childCount - 1; i >= 0; i--) { |
Selim Cinek | daab6f5 | 2017-04-06 16:46:34 -0700 | [diff] [blame] | 691 | childrenOnTop = updateChildZValue(i, childrenOnTop, |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 692 | algorithmState, ambientState); |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 693 | } |
| 694 | } |
| 695 | |
Selim Cinek | daab6f5 | 2017-04-06 16:46:34 -0700 | [diff] [blame] | 696 | protected float updateChildZValue(int i, float childrenOnTop, |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 697 | StackScrollAlgorithmState algorithmState, |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 698 | AmbientState ambientState) { |
| 699 | ExpandableView child = algorithmState.visibleChildren.get(i); |
Dave Mankoff | a4d195d | 2018-11-16 13:33:27 -0500 | [diff] [blame] | 700 | ExpandableViewState childViewState = child.getViewState(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 701 | int zDistanceBetweenElements = ambientState.getZDistanceBetweenElements(); |
| 702 | float baseZ = ambientState.getBaseZHeight(); |
Selim Cinek | 9b9d6e1 | 2017-11-30 12:29:47 +0100 | [diff] [blame] | 703 | if (child.mustStayOnScreen() && !childViewState.headsUpIsVisible |
| 704 | && !ambientState.isDozingAndNotPulsing(child) |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 705 | && childViewState.yTranslation < ambientState.getTopPadding() |
| 706 | + ambientState.getStackTranslation()) { |
| 707 | if (childrenOnTop != 0.0f) { |
| 708 | childrenOnTop++; |
| 709 | } else { |
| 710 | float overlap = ambientState.getTopPadding() |
| 711 | + ambientState.getStackTranslation() - childViewState.yTranslation; |
| 712 | childrenOnTop += Math.min(1.0f, overlap / childViewState.height); |
| 713 | } |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 714 | childViewState.zTranslation = baseZ |
| 715 | + childrenOnTop * zDistanceBetweenElements; |
Steve Elliott | 0c904c3 | 2020-06-22 11:50:35 -0400 | [diff] [blame] | 716 | } else if (child == ambientState.getTrackedHeadsUpRow() |
| 717 | || (i == 0 && (child.isAboveShelf() || child.showingPulsing()))) { |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 718 | // In case this is a new view that has never been measured before, we don't want to |
| 719 | // elevate if we are currently expanded more then the notification |
Eliot Courtney | 5d3d2d0 | 2018-01-18 15:59:03 +0900 | [diff] [blame] | 720 | int shelfHeight = ambientState.getShelf() == null ? 0 : |
| 721 | ambientState.getShelf().getIntrinsicHeight(); |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 722 | float shelfStart = ambientState.getInnerHeight() |
| 723 | - shelfHeight + ambientState.getTopPadding() |
| 724 | + ambientState.getStackTranslation(); |
Steve Elliott | 0c904c3 | 2020-06-22 11:50:35 -0400 | [diff] [blame] | 725 | float notificationEnd = childViewState.yTranslation + child.getIntrinsicHeight() |
Selim Cinek | d127d79 | 2016-11-01 19:11:41 -0700 | [diff] [blame] | 726 | + mPaddingBetweenElements; |
| 727 | if (shelfStart > notificationEnd) { |
| 728 | childViewState.zTranslation = baseZ; |
| 729 | } else { |
| 730 | float factor = (notificationEnd - shelfStart) / shelfHeight; |
| 731 | factor = Math.min(factor, 1.0f); |
| 732 | childViewState.zTranslation = baseZ + factor * zDistanceBetweenElements; |
| 733 | } |
Muyuan Li | 8779802 | 2016-04-07 17:51:25 -0700 | [diff] [blame] | 734 | } else { |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 735 | childViewState.zTranslation = baseZ; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 736 | } |
Selim Cinek | 99e9adf | 2018-03-15 09:17:47 -0700 | [diff] [blame] | 737 | |
| 738 | // We need to scrim the notification more from its surrounding content when we are pinned, |
| 739 | // and we therefore elevate it higher. |
| 740 | // We can use the headerVisibleAmount for this, since the value nicely goes from 0 to 1 when |
| 741 | // expanding after which we have a normal elevation again. |
| 742 | childViewState.zTranslation += (1.0f - child.getHeaderVisibleAmount()) |
| 743 | * mPinnedZTranslationExtra; |
Selim Cinek | daab6f5 | 2017-04-06 16:46:34 -0700 | [diff] [blame] | 744 | return childrenOnTop; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 745 | } |
| 746 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 747 | public void setIsExpanded(boolean isExpanded) { |
| 748 | this.mIsExpanded = isExpanded; |
| 749 | } |
| 750 | |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 751 | public class StackScrollAlgorithmState { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 752 | |
| 753 | /** |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 754 | * The scroll position of the algorithm (absolute scrolling). |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 755 | */ |
| 756 | public int scrollY; |
| 757 | |
Gus Prevas | 0fa58d6 | 2019-01-11 13:58:40 -0500 | [diff] [blame] | 758 | /** The index of the anchor view (anchor scrolling). */ |
| 759 | public int anchorViewIndex; |
| 760 | |
| 761 | /** |
| 762 | * The Y position, relative to the top of the screen, of the anchor view (anchor scrolling). |
| 763 | */ |
| 764 | public int anchorViewY; |
| 765 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 766 | /** |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 767 | * The children from the host view which are not gone. |
| 768 | */ |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 769 | public final ArrayList<ExpandableView> visibleChildren = new ArrayList<ExpandableView>(); |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 770 | |
| 771 | /** |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 772 | * The padding after each child measured in pixels. |
Selim Cinek | 61633a8 | 2016-01-25 15:54:10 -0800 | [diff] [blame] | 773 | */ |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 774 | public final HashMap<ExpandableView, Float> paddingMap = new HashMap<>(); |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 775 | private int indexOfExpandingNotification; |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 776 | |
| 777 | public int getPaddingAfterChild(ExpandableView child) { |
Selim Cinek | a7ed2c1 | 2017-01-23 20:47:24 -0800 | [diff] [blame] | 778 | Float padding = paddingMap.get(child); |
| 779 | if (padding == null) { |
| 780 | // Should only happen for the last view |
| 781 | return mPaddingBetweenElements; |
| 782 | } |
| 783 | return (int) padding.floatValue(); |
Selim Cinek | 281c202 | 2016-10-13 19:14:43 -0700 | [diff] [blame] | 784 | } |
Selim Cinek | 2627d72 | 2018-01-19 12:16:49 -0800 | [diff] [blame] | 785 | |
| 786 | public int getIndexOfExpandingNotification() { |
| 787 | return indexOfExpandingNotification; |
| 788 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 789 | } |
| 790 | |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 791 | /** |
| 792 | * Interface for telling the SSA when a new notification section begins (so it can add in |
| 793 | * appropriate margins). |
| 794 | */ |
| 795 | public interface SectionProvider { |
| 796 | /** |
| 797 | * True if this view starts a new "section" of notifications, such as the gentle |
| 798 | * notifications section. False if sections are not enabled. |
| 799 | */ |
Evan Laird | 25f0275 | 2019-08-14 19:25:06 -0400 | [diff] [blame] | 800 | boolean beginsSection(@NonNull View view, @Nullable View previous); |
Ned Burns | 9eb0633 | 2019-04-23 16:02:12 -0400 | [diff] [blame] | 801 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 802 | } |