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 | |
| 17 | package com.android.systemui.statusbar.stack; |
| 18 | |
| 19 | import android.content.Context; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 20 | import android.util.Log; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 21 | import android.view.View; |
| 22 | import android.view.ViewGroup; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 23 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 24 | import com.android.systemui.R; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 25 | import com.android.systemui.statusbar.ExpandableNotificationRow; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 26 | import com.android.systemui.statusbar.ExpandableView; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 27 | |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 28 | import java.util.ArrayList; |
| 29 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 30 | /** |
| 31 | * The Algorithm of the {@link com.android.systemui.statusbar.stack |
| 32 | * .NotificationStackScrollLayout} which can be queried for {@link com.android.systemui.statusbar |
| 33 | * .stack.StackScrollState} |
| 34 | */ |
| 35 | public class StackScrollAlgorithm { |
| 36 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 37 | private static final String LOG_TAG = "StackScrollAlgorithm"; |
| 38 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 39 | private static final int MAX_ITEMS_IN_BOTTOM_STACK = 3; |
| 40 | private static final int MAX_ITEMS_IN_TOP_STACK = 3; |
| 41 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame^] | 42 | /** When a child is activated, the other cards' alpha fade to this value. */ |
| 43 | private static final float ACTIVATED_INVERSE_ALPHA = 0.9f; |
| 44 | private static final float DIMMED_SCALE = 0.95f; |
| 45 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 46 | private int mPaddingBetweenElements; |
| 47 | private int mCollapsedSize; |
| 48 | private int mTopStackPeekSize; |
| 49 | private int mBottomStackPeekSize; |
| 50 | private int mZDistanceBetweenElements; |
| 51 | private int mZBasicHeight; |
| 52 | |
| 53 | private StackIndentationFunctor mTopStackIndentationFunctor; |
| 54 | private StackIndentationFunctor mBottomStackIndentationFunctor; |
| 55 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 56 | private int mLayoutHeight; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 57 | |
| 58 | /** mLayoutHeight - mTopPadding */ |
| 59 | private int mInnerHeight; |
| 60 | private int mTopPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 61 | private StackScrollAlgorithmState mTempAlgorithmState = new StackScrollAlgorithmState(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 62 | private boolean mIsExpansionChanging; |
| 63 | private int mFirstChildMaxHeight; |
| 64 | private boolean mIsExpanded; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 65 | private ExpandableView mFirstChildWhileExpanding; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 66 | private boolean mExpandedOnStart; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 67 | private int mTopStackTotalSize; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 68 | |
| 69 | public StackScrollAlgorithm(Context context) { |
| 70 | initConstants(context); |
| 71 | } |
| 72 | |
| 73 | private void initConstants(Context context) { |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 74 | mPaddingBetweenElements = context.getResources() |
| 75 | .getDimensionPixelSize(R.dimen.notification_padding); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 76 | mCollapsedSize = context.getResources() |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 77 | .getDimensionPixelSize(R.dimen.notification_min_height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 78 | mTopStackPeekSize = context.getResources() |
| 79 | .getDimensionPixelSize(R.dimen.top_stack_peek_amount); |
| 80 | mBottomStackPeekSize = context.getResources() |
| 81 | .getDimensionPixelSize(R.dimen.bottom_stack_peek_amount); |
| 82 | mZDistanceBetweenElements = context.getResources() |
| 83 | .getDimensionPixelSize(R.dimen.z_distance_between_notifications); |
| 84 | mZBasicHeight = (MAX_ITEMS_IN_BOTTOM_STACK + 1) * mZDistanceBetweenElements; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 85 | mTopStackTotalSize = mCollapsedSize + mPaddingBetweenElements; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 86 | mTopStackIndentationFunctor = new PiecewiseLinearIndentationFunctor( |
| 87 | MAX_ITEMS_IN_TOP_STACK, |
| 88 | mTopStackPeekSize, |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 89 | mTopStackTotalSize, |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 90 | 0.5f); |
| 91 | mBottomStackIndentationFunctor = new PiecewiseLinearIndentationFunctor( |
| 92 | MAX_ITEMS_IN_BOTTOM_STACK, |
| 93 | mBottomStackPeekSize, |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 94 | mCollapsedSize + mBottomStackPeekSize + mPaddingBetweenElements, |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 95 | 0.5f); |
| 96 | } |
| 97 | |
| 98 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame^] | 99 | public void getStackScrollState(AmbientState ambientState, StackScrollState resultState) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 100 | // The state of the local variables are saved in an algorithmState to easily subdivide it |
| 101 | // into multiple phases. |
| 102 | StackScrollAlgorithmState algorithmState = mTempAlgorithmState; |
| 103 | |
| 104 | // First we reset the view states to their default values. |
| 105 | resultState.resetViewStates(); |
| 106 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 107 | algorithmState.itemsInTopStack = 0.0f; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 108 | algorithmState.partialInTop = 0.0f; |
| 109 | algorithmState.lastTopStackIndex = 0; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 110 | algorithmState.scrolledPixelsTop = 0; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 111 | algorithmState.itemsInBottomStack = 0.0f; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 112 | algorithmState.partialInBottom = 0.0f; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame^] | 113 | algorithmState.scrollY = ambientState.getScrollY() + mCollapsedSize; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 114 | |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 115 | updateVisibleChildren(resultState, algorithmState); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 116 | |
| 117 | // Phase 1: |
| 118 | findNumberOfItemsInTopStackAndUpdateState(resultState, algorithmState); |
| 119 | |
| 120 | // Phase 2: |
| 121 | updatePositionsForState(resultState, algorithmState); |
| 122 | |
| 123 | // Phase 3: |
| 124 | updateZValuesForState(resultState, algorithmState); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 125 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame^] | 126 | handleDraggedViews(ambientState, resultState, algorithmState); |
| 127 | updateDimmedActivated(ambientState, resultState, algorithmState); |
| 128 | } |
| 129 | |
| 130 | /** |
| 131 | * Updates the dimmed and activated states of the children. |
| 132 | */ |
| 133 | private void updateDimmedActivated(AmbientState ambientState, StackScrollState resultState, |
| 134 | StackScrollAlgorithmState algorithmState) { |
| 135 | boolean dimmed = ambientState.isDimmed(); |
| 136 | View activatedChild = ambientState.getActivatedChild(); |
| 137 | int childCount = algorithmState.visibleChildren.size(); |
| 138 | for (int i = 0; i < childCount; i++) { |
| 139 | View child = algorithmState.visibleChildren.get(i); |
| 140 | StackScrollState.ViewState childViewState = resultState.getViewStateForView(child); |
| 141 | childViewState.dimmed = dimmed; |
| 142 | childViewState.scale = !dimmed || activatedChild == child |
| 143 | ? 1.0f |
| 144 | : DIMMED_SCALE; |
| 145 | if (dimmed && activatedChild != null && child != activatedChild) { |
| 146 | childViewState.alpha *= ACTIVATED_INVERSE_ALPHA; |
| 147 | } |
| 148 | } |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Handle the special state when views are being dragged |
| 153 | */ |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame^] | 154 | private void handleDraggedViews(AmbientState ambientState, StackScrollState resultState, |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 155 | StackScrollAlgorithmState algorithmState) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame^] | 156 | ArrayList<View> draggedViews = ambientState.getDraggedViews(); |
| 157 | for (View draggedView : draggedViews) { |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 158 | int childIndex = algorithmState.visibleChildren.indexOf(draggedView); |
| 159 | if (childIndex >= 0 && childIndex < algorithmState.visibleChildren.size() - 1) { |
| 160 | View nextChild = algorithmState.visibleChildren.get(childIndex + 1); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame^] | 161 | if (!draggedViews.contains(nextChild)) { |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 162 | // only if the view is not dragged itself we modify its state to be fully |
| 163 | // visible |
| 164 | StackScrollState.ViewState viewState = resultState.getViewStateForView( |
| 165 | nextChild); |
| 166 | // The child below the dragged one must be fully visible |
| 167 | viewState.alpha = 1; |
| 168 | } |
| 169 | |
| 170 | // Lets set the alpha to the one it currently has, as its currently being dragged |
| 171 | StackScrollState.ViewState viewState = resultState.getViewStateForView(draggedView); |
| 172 | // The dragged child should keep the set alpha |
| 173 | viewState.alpha = draggedView.getAlpha(); |
| 174 | } |
| 175 | } |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 176 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 177 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 178 | /** |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 179 | * Update the visible children on the state. |
| 180 | */ |
| 181 | private void updateVisibleChildren(StackScrollState resultState, |
| 182 | StackScrollAlgorithmState state) { |
| 183 | ViewGroup hostView = resultState.getHostView(); |
| 184 | int childCount = hostView.getChildCount(); |
| 185 | state.visibleChildren.clear(); |
| 186 | state.visibleChildren.ensureCapacity(childCount); |
| 187 | for (int i = 0; i < childCount; i++) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 188 | ExpandableView v = (ExpandableView) hostView.getChildAt(i); |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 189 | if (v.getVisibility() != View.GONE) { |
| 190 | state.visibleChildren.add(v); |
| 191 | } |
| 192 | } |
| 193 | } |
| 194 | |
| 195 | /** |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 196 | * Determine the positions for the views. This is the main part of the algorithm. |
| 197 | * |
| 198 | * @param resultState The result state to update if a change to the properties of a child occurs |
| 199 | * @param algorithmState The state in which the current pass of the algorithm is currently in |
| 200 | * and which will be updated |
| 201 | */ |
| 202 | private void updatePositionsForState(StackScrollState resultState, |
| 203 | StackScrollAlgorithmState algorithmState) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 204 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 205 | // The starting position of the bottom stack peek |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 206 | float bottomPeekStart = mInnerHeight - mBottomStackPeekSize; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 207 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 208 | // The position where the bottom stack starts. |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 209 | float bottomStackStart = bottomPeekStart - mCollapsedSize; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 210 | |
| 211 | // The y coordinate of the current child. |
| 212 | float currentYPosition = 0.0f; |
| 213 | |
| 214 | // How far in is the element currently transitioning into the bottom stack. |
| 215 | float yPositionInScrollView = 0.0f; |
| 216 | |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 217 | int childCount = algorithmState.visibleChildren.size(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 218 | int numberOfElementsCompletelyIn = (int) algorithmState.itemsInTopStack; |
| 219 | for (int i = 0; i < childCount; i++) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 220 | ExpandableView child = algorithmState.visibleChildren.get(i); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 221 | StackScrollState.ViewState childViewState = resultState.getViewStateForView(child); |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 222 | childViewState.location = StackScrollState.ViewState.LOCATION_UNKNOWN; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 223 | int childHeight = getMaxAllowedChildHeight(child); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 224 | float yPositionInScrollViewAfterElement = yPositionInScrollView |
| 225 | + childHeight |
| 226 | + mPaddingBetweenElements; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 227 | float scrollOffset = yPositionInScrollView - algorithmState.scrollY + mCollapsedSize; |
| 228 | |
| 229 | if (i == algorithmState.lastTopStackIndex + 1) { |
| 230 | // Normally the position of this child is the position in the regular scrollview, |
| 231 | // but if the two stacks are very close to each other, |
| 232 | // then have have to push it even more upwards to the position of the bottom |
| 233 | // stack start. |
| 234 | currentYPosition = Math.min(scrollOffset, bottomStackStart); |
| 235 | } |
| 236 | childViewState.yTranslation = currentYPosition; |
| 237 | |
| 238 | // The y position after this element |
| 239 | float nextYPosition = currentYPosition + childHeight + |
| 240 | mPaddingBetweenElements; |
| 241 | |
| 242 | if (i <= algorithmState.lastTopStackIndex) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 243 | // Case 1: |
| 244 | // We are in the top Stack |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 245 | updateStateForTopStackChild(algorithmState, |
| 246 | numberOfElementsCompletelyIn, i, childHeight, childViewState, scrollOffset); |
| 247 | clampYTranslation(childViewState, childHeight); |
| 248 | // check if we are overlapping with the bottom stack |
| 249 | if (childViewState.yTranslation + childHeight + mPaddingBetweenElements |
Selim Cinek | 4a1ac84 | 2014-05-01 15:51:58 +0200 | [diff] [blame] | 250 | >= bottomStackStart && !mIsExpansionChanging && i != 0) { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 251 | // TODO: handle overlapping sizes with end stack better |
| 252 | // we just collapse this element |
| 253 | childViewState.height = mCollapsedSize; |
| 254 | } |
| 255 | } else if (nextYPosition >= bottomStackStart) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 256 | // Case 2: |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 257 | // We are in the bottom stack. |
| 258 | if (currentYPosition >= bottomStackStart) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 259 | // According to the regular scroll view we are fully translated out of the |
| 260 | // bottom of the screen so we are fully in the bottom stack |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 261 | updateStateForChildFullyInBottomStack(algorithmState, |
| 262 | bottomStackStart, childViewState, childHeight); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 263 | } else { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 264 | // According to the regular scroll view we are currently translating out of / |
| 265 | // into the bottom of the screen |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 266 | updateStateForChildTransitioningInBottom(algorithmState, |
| 267 | bottomStackStart, bottomPeekStart, currentYPosition, |
| 268 | childViewState, childHeight); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 269 | } |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 270 | } else { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 271 | // Case 3: |
| 272 | // We are in the regular scroll area. |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 273 | childViewState.location = StackScrollState.ViewState.LOCATION_MAIN_AREA; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 274 | clampYTranslation(childViewState, childHeight); |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 275 | } |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 276 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 277 | // The first card is always rendered. |
| 278 | if (i == 0) { |
| 279 | childViewState.alpha = 1.0f; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 280 | childViewState.yTranslation = 0; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 281 | childViewState.location = StackScrollState.ViewState.LOCATION_FIRST_CARD; |
| 282 | } |
| 283 | if (childViewState.location == StackScrollState.ViewState.LOCATION_UNKNOWN) { |
| 284 | Log.wtf(LOG_TAG, "Failed to assign location for child " + i); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 285 | } |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 286 | currentYPosition = childViewState.yTranslation + childHeight + mPaddingBetweenElements; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 287 | yPositionInScrollView = yPositionInScrollViewAfterElement; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 288 | |
| 289 | childViewState.yTranslation += mTopPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 290 | } |
| 291 | } |
| 292 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 293 | /** |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 294 | * Clamp the yTranslation both up and down to valid positions. |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 295 | * |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 296 | * @param childViewState the view state of the child |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 297 | * @param childHeight the height of this child |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 298 | */ |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 299 | private void clampYTranslation(StackScrollState.ViewState childViewState, int childHeight) { |
| 300 | clampPositionToBottomStackStart(childViewState, childHeight); |
| 301 | clampPositionToTopStackEnd(childViewState, childHeight); |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * Clamp the yTranslation of the child down such that its end is at most on the beginning of |
| 306 | * the bottom stack. |
| 307 | * |
| 308 | * @param childViewState the view state of the child |
| 309 | * @param childHeight the height of this child |
| 310 | */ |
| 311 | private void clampPositionToBottomStackStart(StackScrollState.ViewState childViewState, |
| 312 | int childHeight) { |
| 313 | childViewState.yTranslation = Math.min(childViewState.yTranslation, |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 314 | mInnerHeight - mBottomStackPeekSize - childHeight); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | /** |
| 318 | * Clamp the yTranslation of the child up such that its end is at lest on the end of the top |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 319 | * stack.get |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 320 | * |
| 321 | * @param childViewState the view state of the child |
| 322 | * @param childHeight the height of this child |
| 323 | */ |
| 324 | private void clampPositionToTopStackEnd(StackScrollState.ViewState childViewState, |
| 325 | int childHeight) { |
| 326 | childViewState.yTranslation = Math.max(childViewState.yTranslation, |
| 327 | mCollapsedSize - childHeight); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | private int getMaxAllowedChildHeight(View child) { |
| 331 | if (child instanceof ExpandableNotificationRow) { |
| 332 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 333 | return row.getIntrinsicHeight(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 334 | } else if (child instanceof ExpandableView) { |
| 335 | ExpandableView expandableView = (ExpandableView) child; |
| 336 | return expandableView.getActualHeight(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 337 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 338 | return child == null? mCollapsedSize : child.getHeight(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 339 | } |
| 340 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 341 | private void updateStateForChildTransitioningInBottom(StackScrollAlgorithmState algorithmState, |
| 342 | float transitioningPositionStart, float bottomPeakStart, float currentYPosition, |
| 343 | StackScrollState.ViewState childViewState, int childHeight) { |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 344 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 345 | // This is the transitioning element on top of bottom stack, calculate how far we are in. |
| 346 | algorithmState.partialInBottom = 1.0f - ( |
| 347 | (transitioningPositionStart - currentYPosition) / (childHeight + |
| 348 | mPaddingBetweenElements)); |
| 349 | |
| 350 | // the offset starting at the transitionPosition of the bottom stack |
| 351 | float offset = mBottomStackIndentationFunctor.getValue(algorithmState.partialInBottom); |
| 352 | algorithmState.itemsInBottomStack += algorithmState.partialInBottom; |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 353 | childViewState.yTranslation = transitioningPositionStart + offset - childHeight |
| 354 | - mPaddingBetweenElements; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 355 | |
| 356 | // We want at least to be at the end of the top stack when collapsing |
| 357 | clampPositionToTopStackEnd(childViewState, childHeight); |
| 358 | childViewState.location = StackScrollState.ViewState.LOCATION_MAIN_AREA; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 359 | } |
| 360 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 361 | private void updateStateForChildFullyInBottomStack(StackScrollAlgorithmState algorithmState, |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 362 | float transitioningPositionStart, StackScrollState.ViewState childViewState, |
| 363 | int childHeight) { |
| 364 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 365 | float currentYPosition; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 366 | algorithmState.itemsInBottomStack += 1.0f; |
| 367 | if (algorithmState.itemsInBottomStack < MAX_ITEMS_IN_BOTTOM_STACK) { |
| 368 | // We are visually entering the bottom stack |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 369 | currentYPosition = transitioningPositionStart |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 370 | + mBottomStackIndentationFunctor.getValue(algorithmState.itemsInBottomStack) |
| 371 | - mPaddingBetweenElements; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 372 | childViewState.location = StackScrollState.ViewState.LOCATION_BOTTOM_STACK_PEEKING; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 373 | } else { |
| 374 | // we are fully inside the stack |
| 375 | if (algorithmState.itemsInBottomStack > MAX_ITEMS_IN_BOTTOM_STACK + 2) { |
| 376 | childViewState.alpha = 0.0f; |
| 377 | } else if (algorithmState.itemsInBottomStack |
| 378 | > MAX_ITEMS_IN_BOTTOM_STACK + 1) { |
| 379 | childViewState.alpha = 1.0f - algorithmState.partialInBottom; |
| 380 | } |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 381 | childViewState.location = StackScrollState.ViewState.LOCATION_BOTTOM_STACK_HIDDEN; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 382 | currentYPosition = mInnerHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 383 | } |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 384 | childViewState.yTranslation = currentYPosition - childHeight; |
| 385 | clampPositionToTopStackEnd(childViewState, childHeight); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 386 | } |
| 387 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 388 | private void updateStateForTopStackChild(StackScrollAlgorithmState algorithmState, |
| 389 | int numberOfElementsCompletelyIn, int i, int childHeight, |
| 390 | StackScrollState.ViewState childViewState, float scrollOffset) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 391 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 392 | |
| 393 | // First we calculate the index relative to the current stack window of size at most |
| 394 | // {@link #MAX_ITEMS_IN_TOP_STACK} |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 395 | int paddedIndex = i - 1 |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 396 | - Math.max(numberOfElementsCompletelyIn - MAX_ITEMS_IN_TOP_STACK, 0); |
| 397 | if (paddedIndex >= 0) { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 398 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 399 | // We are currently visually entering the top stack |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 400 | float distanceToStack = childHeight - algorithmState.scrolledPixelsTop; |
| 401 | if (i == algorithmState.lastTopStackIndex && distanceToStack > mTopStackTotalSize) { |
| 402 | |
| 403 | // Child is currently translating into stack but not yet inside slow down zone. |
| 404 | // Handle it like the regular scrollview. |
| 405 | childViewState.yTranslation = scrollOffset; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 406 | } else { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 407 | // Apply stacking logic. |
| 408 | float numItemsBefore; |
| 409 | if (i == algorithmState.lastTopStackIndex) { |
| 410 | numItemsBefore = 1.0f - (distanceToStack / mTopStackTotalSize); |
| 411 | } else { |
| 412 | numItemsBefore = algorithmState.itemsInTopStack - i; |
| 413 | } |
| 414 | // The end position of the current child |
| 415 | float currentChildEndY = mCollapsedSize + mTopStackTotalSize - |
| 416 | mTopStackIndentationFunctor.getValue(numItemsBefore); |
| 417 | childViewState.yTranslation = currentChildEndY - childHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 418 | } |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 419 | childViewState.location = StackScrollState.ViewState.LOCATION_TOP_STACK_PEEKING; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 420 | } else { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 421 | if (paddedIndex == -1) { |
| 422 | childViewState.alpha = 1.0f - algorithmState.partialInTop; |
| 423 | } else { |
| 424 | // We are hidden behind the top card and faded out, so we can hide ourselves. |
| 425 | childViewState.alpha = 0.0f; |
| 426 | } |
| 427 | childViewState.yTranslation = mCollapsedSize - childHeight; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 428 | childViewState.location = StackScrollState.ViewState.LOCATION_TOP_STACK_HIDDEN; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 429 | } |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 430 | |
| 431 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /** |
| 435 | * Find the number of items in the top stack and update the result state if needed. |
| 436 | * |
| 437 | * @param resultState The result state to update if a height change of an child occurs |
| 438 | * @param algorithmState The state in which the current pass of the algorithm is currently in |
| 439 | * and which will be updated |
| 440 | */ |
| 441 | private void findNumberOfItemsInTopStackAndUpdateState(StackScrollState resultState, |
| 442 | StackScrollAlgorithmState algorithmState) { |
| 443 | |
| 444 | // The y Position if the element would be in a regular scrollView |
| 445 | float yPositionInScrollView = 0.0f; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 446 | int childCount = algorithmState.visibleChildren.size(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 447 | |
| 448 | // find the number of elements in the top stack. |
| 449 | for (int i = 0; i < childCount; i++) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 450 | ExpandableView child = algorithmState.visibleChildren.get(i); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 451 | StackScrollState.ViewState childViewState = resultState.getViewStateForView(child); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 452 | int childHeight = getMaxAllowedChildHeight(child); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 453 | float yPositionInScrollViewAfterElement = yPositionInScrollView |
| 454 | + childHeight |
| 455 | + mPaddingBetweenElements; |
| 456 | if (yPositionInScrollView < algorithmState.scrollY) { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 457 | if (i == 0 && algorithmState.scrollY == mCollapsedSize) { |
| 458 | |
| 459 | // The starting position of the bottom stack peek |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 460 | int bottomPeekStart = mInnerHeight - mBottomStackPeekSize; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 461 | // Collapse and expand the first child while the shade is being expanded |
| 462 | float maxHeight = mIsExpansionChanging && child == mFirstChildWhileExpanding |
| 463 | ? mFirstChildMaxHeight |
| 464 | : childHeight; |
| 465 | childViewState.height = (int) Math.max(Math.min(bottomPeekStart, maxHeight), |
| 466 | mCollapsedSize); |
| 467 | algorithmState.itemsInTopStack = 1.0f; |
| 468 | |
| 469 | } else if (yPositionInScrollViewAfterElement < algorithmState.scrollY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 470 | // According to the regular scroll view we are fully off screen |
| 471 | algorithmState.itemsInTopStack += 1.0f; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 472 | if (i == 0) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 473 | childViewState.height = mCollapsedSize; |
| 474 | } |
| 475 | } else { |
| 476 | // According to the regular scroll view we are partially off screen |
| 477 | // If it is expanded we have to collapse it to a new size |
| 478 | float newSize = yPositionInScrollViewAfterElement |
| 479 | - mPaddingBetweenElements |
| 480 | - algorithmState.scrollY; |
| 481 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 482 | if (i == 0) { |
| 483 | newSize += mCollapsedSize; |
| 484 | } |
| 485 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 486 | // How much did we scroll into this child |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 487 | algorithmState.scrolledPixelsTop = childHeight - newSize; |
| 488 | algorithmState.partialInTop = (algorithmState.scrolledPixelsTop) / (childHeight |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 489 | + mPaddingBetweenElements); |
| 490 | |
| 491 | // Our element can be expanded, so this can get negative |
| 492 | algorithmState.partialInTop = Math.max(0.0f, algorithmState.partialInTop); |
| 493 | algorithmState.itemsInTopStack += algorithmState.partialInTop; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 494 | newSize = Math.max(mCollapsedSize, newSize); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 495 | if (i == 0) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 496 | childViewState.height = (int) newSize; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 497 | } |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 498 | algorithmState.lastTopStackIndex = i; |
| 499 | break; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 500 | } |
| 501 | } else { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 502 | algorithmState.lastTopStackIndex = i - 1; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 503 | // We are already past the stack so we can end the loop |
| 504 | break; |
| 505 | } |
| 506 | yPositionInScrollView = yPositionInScrollViewAfterElement; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | /** |
| 511 | * Calculate the Z positions for all children based on the number of items in both stacks and |
| 512 | * save it in the resultState |
| 513 | * |
| 514 | * @param resultState The result state to update the zTranslation values |
| 515 | * @param algorithmState The state in which the current pass of the algorithm is currently in |
| 516 | */ |
| 517 | private void updateZValuesForState(StackScrollState resultState, |
| 518 | StackScrollAlgorithmState algorithmState) { |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 519 | int childCount = algorithmState.visibleChildren.size(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 520 | for (int i = 0; i < childCount; i++) { |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 521 | View child = algorithmState.visibleChildren.get(i); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 522 | StackScrollState.ViewState childViewState = resultState.getViewStateForView(child); |
| 523 | if (i < algorithmState.itemsInTopStack) { |
| 524 | float stackIndex = algorithmState.itemsInTopStack - i; |
| 525 | stackIndex = Math.min(stackIndex, MAX_ITEMS_IN_TOP_STACK + 2); |
| 526 | childViewState.zTranslation = mZBasicHeight |
| 527 | + stackIndex * mZDistanceBetweenElements; |
| 528 | } else if (i > (childCount - 1 - algorithmState.itemsInBottomStack)) { |
| 529 | float numItemsAbove = i - (childCount - 1 - algorithmState.itemsInBottomStack); |
| 530 | float translationZ = mZBasicHeight |
| 531 | - numItemsAbove * mZDistanceBetweenElements; |
| 532 | childViewState.zTranslation = translationZ; |
| 533 | } else { |
| 534 | childViewState.zTranslation = mZBasicHeight; |
| 535 | } |
| 536 | } |
| 537 | } |
| 538 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 539 | public void setLayoutHeight(int layoutHeight) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 540 | this.mLayoutHeight = layoutHeight; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 541 | updateInnerHeight(); |
| 542 | } |
| 543 | |
| 544 | public void setTopPadding(int topPadding) { |
| 545 | mTopPadding = topPadding; |
| 546 | updateInnerHeight(); |
| 547 | } |
| 548 | |
| 549 | private void updateInnerHeight() { |
| 550 | mInnerHeight = mLayoutHeight - mTopPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 551 | } |
| 552 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 553 | public void onExpansionStarted(StackScrollState currentState) { |
| 554 | mIsExpansionChanging = true; |
| 555 | mExpandedOnStart = mIsExpanded; |
| 556 | ViewGroup hostView = currentState.getHostView(); |
| 557 | updateFirstChildHeightWhileExpanding(hostView); |
| 558 | } |
| 559 | |
| 560 | private void updateFirstChildHeightWhileExpanding(ViewGroup hostView) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 561 | mFirstChildWhileExpanding = (ExpandableView) findFirstVisibleChild(hostView); |
Jorim Jaggi | 9f347ae | 2014-04-11 00:47:18 +0200 | [diff] [blame] | 562 | if (mFirstChildWhileExpanding != null) { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 563 | if (mExpandedOnStart) { |
| 564 | |
| 565 | // We are collapsing the shade, so the first child can get as most as high as the |
| 566 | // current height. |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 567 | mFirstChildMaxHeight = mFirstChildWhileExpanding.getActualHeight(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 568 | } else { |
| 569 | |
| 570 | // We are expanding the shade, expand it to its full height. |
Selim Cinek | b6e0e12 | 2014-04-23 17:24:37 +0200 | [diff] [blame] | 571 | if (mFirstChildWhileExpanding.getWidth() == 0) { |
| 572 | |
| 573 | // This child was not layouted yet, wait for a layout pass |
| 574 | mFirstChildWhileExpanding |
| 575 | .addOnLayoutChangeListener(new View.OnLayoutChangeListener() { |
| 576 | @Override |
| 577 | public void onLayoutChange(View v, int left, int top, int right, |
| 578 | int bottom, int oldLeft, int oldTop, int oldRight, |
| 579 | int oldBottom) { |
Selim Cinek | 2ba5f1f | 2014-04-28 20:23:30 +0200 | [diff] [blame] | 580 | if (mFirstChildWhileExpanding != null) { |
| 581 | mFirstChildMaxHeight = getMaxAllowedChildHeight( |
| 582 | mFirstChildWhileExpanding); |
| 583 | } else { |
| 584 | mFirstChildMaxHeight = 0; |
| 585 | } |
| 586 | v.removeOnLayoutChangeListener(this); |
Selim Cinek | b6e0e12 | 2014-04-23 17:24:37 +0200 | [diff] [blame] | 587 | } |
| 588 | }); |
| 589 | } else { |
| 590 | mFirstChildMaxHeight = getMaxAllowedChildHeight(mFirstChildWhileExpanding); |
| 591 | } |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 592 | } |
| 593 | } else { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 594 | mFirstChildMaxHeight = 0; |
| 595 | } |
| 596 | } |
| 597 | |
Jorim Jaggi | 9f347ae | 2014-04-11 00:47:18 +0200 | [diff] [blame] | 598 | private View findFirstVisibleChild(ViewGroup container) { |
| 599 | int childCount = container.getChildCount(); |
| 600 | for (int i = 0; i < childCount; i++) { |
| 601 | View child = container.getChildAt(i); |
| 602 | if (child.getVisibility() != View.GONE) { |
| 603 | return child; |
| 604 | } |
| 605 | } |
| 606 | return null; |
| 607 | } |
| 608 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 609 | public void onExpansionStopped() { |
| 610 | mIsExpansionChanging = false; |
| 611 | mFirstChildWhileExpanding = null; |
| 612 | } |
| 613 | |
| 614 | public void setIsExpanded(boolean isExpanded) { |
| 615 | this.mIsExpanded = isExpanded; |
| 616 | } |
| 617 | |
| 618 | public void notifyChildrenChanged(ViewGroup hostView) { |
| 619 | if (mIsExpansionChanging) { |
| 620 | updateFirstChildHeightWhileExpanding(hostView); |
| 621 | } |
| 622 | } |
| 623 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 624 | class StackScrollAlgorithmState { |
| 625 | |
| 626 | /** |
| 627 | * The scroll position of the algorithm |
| 628 | */ |
| 629 | public int scrollY; |
| 630 | |
| 631 | /** |
| 632 | * The quantity of items which are in the top stack. |
| 633 | */ |
| 634 | public float itemsInTopStack; |
| 635 | |
| 636 | /** |
| 637 | * how far in is the element currently transitioning into the top stack |
| 638 | */ |
| 639 | public float partialInTop; |
| 640 | |
| 641 | /** |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 642 | * The number of pixels the last child in the top stack has scrolled in to the stack |
| 643 | */ |
| 644 | public float scrolledPixelsTop; |
| 645 | |
| 646 | /** |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 647 | * The last item index which is in the top stack. |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 648 | */ |
| 649 | public int lastTopStackIndex; |
| 650 | |
| 651 | /** |
| 652 | * The quantity of items which are in the bottom stack. |
| 653 | */ |
| 654 | public float itemsInBottomStack; |
| 655 | |
| 656 | /** |
| 657 | * how far in is the element currently transitioning into the bottom stack |
| 658 | */ |
| 659 | public float partialInBottom; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 660 | |
| 661 | /** |
| 662 | * The children from the host view which are not gone. |
| 663 | */ |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 664 | public final ArrayList<ExpandableView> visibleChildren = new ArrayList<ExpandableView>(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | } |