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