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; |
Jorim Jaggi | d7c1fae | 2014-08-13 18:27:47 +0200 | [diff] [blame] | 20 | import android.util.DisplayMetrics; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 21 | import android.util.Log; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 22 | import android.view.View; |
| 23 | import android.view.ViewGroup; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 24 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 25 | import com.android.systemui.R; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 26 | import com.android.systemui.statusbar.ExpandableNotificationRow; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 27 | import com.android.systemui.statusbar.ExpandableView; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 28 | |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 29 | import java.util.ArrayList; |
| 30 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 31 | /** |
| 32 | * The Algorithm of the {@link com.android.systemui.statusbar.stack |
| 33 | * .NotificationStackScrollLayout} which can be queried for {@link com.android.systemui.statusbar |
| 34 | * .stack.StackScrollState} |
| 35 | */ |
| 36 | public class StackScrollAlgorithm { |
| 37 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 38 | private static final String LOG_TAG = "StackScrollAlgorithm"; |
| 39 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 40 | private static final int MAX_ITEMS_IN_BOTTOM_STACK = 3; |
| 41 | private static final int MAX_ITEMS_IN_TOP_STACK = 3; |
| 42 | |
Jorim Jaggi | 362dd6d | 2014-07-09 19:04:07 +0200 | [diff] [blame] | 43 | public static final float DIMMED_SCALE = 0.95f; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 44 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 45 | private int mPaddingBetweenElements; |
| 46 | private int mCollapsedSize; |
| 47 | private int mTopStackPeekSize; |
| 48 | private int mBottomStackPeekSize; |
| 49 | private int mZDistanceBetweenElements; |
| 50 | private int mZBasicHeight; |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 51 | private int mRoundedRectCornerRadius; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 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 | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 68 | private int mPaddingBetweenElementsDimmed; |
| 69 | private int mPaddingBetweenElementsNormal; |
| 70 | private int mBottomStackSlowDownLength; |
Selim Cinek | ad3e5af | 2014-07-04 12:24:11 +0200 | [diff] [blame] | 71 | private int mTopStackSlowDownLength; |
Selim Cinek | d83771e | 2014-07-04 16:45:31 +0200 | [diff] [blame] | 72 | private int mCollapseSecondCardPadding; |
Selim Cinek | 3afd00e | 2014-08-11 22:32:57 +0200 | [diff] [blame] | 73 | private boolean mIsSmallScreen; |
| 74 | private int mMaxNotificationHeight; |
Jorim Jaggi | d7c1fae | 2014-08-13 18:27:47 +0200 | [diff] [blame] | 75 | private boolean mScaleDimmed; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 76 | |
| 77 | public StackScrollAlgorithm(Context context) { |
| 78 | initConstants(context); |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 79 | updatePadding(false); |
| 80 | } |
| 81 | |
| 82 | private void updatePadding(boolean dimmed) { |
Jorim Jaggi | d7c1fae | 2014-08-13 18:27:47 +0200 | [diff] [blame] | 83 | mPaddingBetweenElements = dimmed && mScaleDimmed |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 84 | ? mPaddingBetweenElementsDimmed |
| 85 | : mPaddingBetweenElementsNormal; |
Selim Cinek | ad3e5af | 2014-07-04 12:24:11 +0200 | [diff] [blame] | 86 | mTopStackTotalSize = mTopStackSlowDownLength + mPaddingBetweenElements |
| 87 | + mTopStackPeekSize; |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 88 | mTopStackIndentationFunctor = new PiecewiseLinearIndentationFunctor( |
| 89 | MAX_ITEMS_IN_TOP_STACK, |
| 90 | mTopStackPeekSize, |
Selim Cinek | b96924d | 2014-05-12 15:11:25 +0200 | [diff] [blame] | 91 | mTopStackTotalSize - mTopStackPeekSize, |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 92 | 0.5f); |
| 93 | mBottomStackIndentationFunctor = new PiecewiseLinearIndentationFunctor( |
| 94 | MAX_ITEMS_IN_BOTTOM_STACK, |
| 95 | mBottomStackPeekSize, |
| 96 | getBottomStackSlowDownLength(), |
| 97 | 0.5f); |
| 98 | } |
| 99 | |
| 100 | public int getBottomStackSlowDownLength() { |
| 101 | return mBottomStackSlowDownLength + mPaddingBetweenElements; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | private void initConstants(Context context) { |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 105 | mPaddingBetweenElementsDimmed = context.getResources() |
| 106 | .getDimensionPixelSize(R.dimen.notification_padding_dimmed); |
| 107 | mPaddingBetweenElementsNormal = context.getResources() |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 108 | .getDimensionPixelSize(R.dimen.notification_padding); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 109 | mCollapsedSize = context.getResources() |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 110 | .getDimensionPixelSize(R.dimen.notification_min_height); |
Selim Cinek | 3afd00e | 2014-08-11 22:32:57 +0200 | [diff] [blame] | 111 | mMaxNotificationHeight = context.getResources() |
| 112 | .getDimensionPixelSize(R.dimen.notification_max_height); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 113 | mTopStackPeekSize = context.getResources() |
| 114 | .getDimensionPixelSize(R.dimen.top_stack_peek_amount); |
| 115 | mBottomStackPeekSize = context.getResources() |
| 116 | .getDimensionPixelSize(R.dimen.bottom_stack_peek_amount); |
| 117 | mZDistanceBetweenElements = context.getResources() |
| 118 | .getDimensionPixelSize(R.dimen.z_distance_between_notifications); |
| 119 | mZBasicHeight = (MAX_ITEMS_IN_BOTTOM_STACK + 1) * mZDistanceBetweenElements; |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 120 | mBottomStackSlowDownLength = context.getResources() |
| 121 | .getDimensionPixelSize(R.dimen.bottom_stack_slow_down_length); |
Selim Cinek | ad3e5af | 2014-07-04 12:24:11 +0200 | [diff] [blame] | 122 | mTopStackSlowDownLength = context.getResources() |
| 123 | .getDimensionPixelSize(R.dimen.top_stack_slow_down_length); |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 124 | mRoundedRectCornerRadius = context.getResources().getDimensionPixelSize( |
Selim Cinek | 697178b | 2014-07-02 19:40:30 +0200 | [diff] [blame] | 125 | R.dimen.notification_material_rounded_rect_radius); |
Selim Cinek | d83771e | 2014-07-04 16:45:31 +0200 | [diff] [blame] | 126 | mCollapseSecondCardPadding = context.getResources().getDimensionPixelSize( |
| 127 | R.dimen.notification_collapse_second_card_padding); |
Jorim Jaggi | d7c1fae | 2014-08-13 18:27:47 +0200 | [diff] [blame] | 128 | mScaleDimmed = context.getResources().getDisplayMetrics().densityDpi |
| 129 | >= DisplayMetrics.DENSITY_XXHIGH; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 130 | } |
| 131 | |
Jorim Jaggi | d7c1fae | 2014-08-13 18:27:47 +0200 | [diff] [blame] | 132 | public boolean shouldScaleDimmed() { |
| 133 | return mScaleDimmed; |
| 134 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 135 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 136 | public void getStackScrollState(AmbientState ambientState, StackScrollState resultState) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 137 | // The state of the local variables are saved in an algorithmState to easily subdivide it |
| 138 | // into multiple phases. |
| 139 | StackScrollAlgorithmState algorithmState = mTempAlgorithmState; |
| 140 | |
| 141 | // First we reset the view states to their default values. |
| 142 | resultState.resetViewStates(); |
| 143 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 144 | algorithmState.itemsInTopStack = 0.0f; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 145 | algorithmState.partialInTop = 0.0f; |
| 146 | algorithmState.lastTopStackIndex = 0; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 147 | algorithmState.scrolledPixelsTop = 0; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 148 | algorithmState.itemsInBottomStack = 0.0f; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 149 | algorithmState.partialInBottom = 0.0f; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 150 | float bottomOverScroll = ambientState.getOverScrollAmount(false /* onTop */); |
Selim Cinek | 1408eb5 | 2014-06-02 14:45:38 +0200 | [diff] [blame] | 151 | |
| 152 | int scrollY = ambientState.getScrollY(); |
| 153 | |
| 154 | // Due to the overScroller, the stackscroller can have negative scroll state. This is |
| 155 | // already accounted for by the top padding and doesn't need an additional adaption |
| 156 | scrollY = Math.max(0, scrollY); |
| 157 | algorithmState.scrollY = (int) (scrollY + mCollapsedSize + bottomOverScroll); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 158 | |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 159 | updateVisibleChildren(resultState, algorithmState); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 160 | |
| 161 | // Phase 1: |
| 162 | findNumberOfItemsInTopStackAndUpdateState(resultState, algorithmState); |
| 163 | |
| 164 | // Phase 2: |
| 165 | updatePositionsForState(resultState, algorithmState); |
| 166 | |
| 167 | // Phase 3: |
| 168 | updateZValuesForState(resultState, algorithmState); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 169 | |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 170 | handleDraggedViews(ambientState, resultState, algorithmState); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 171 | updateDimmedActivatedHideSensitive(ambientState, resultState, algorithmState); |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 172 | updateClipping(resultState, algorithmState); |
Selim Cinek | 3d2b94bf | 2014-07-02 22:12:47 +0200 | [diff] [blame] | 173 | updateSpeedBumpState(resultState, algorithmState, ambientState.getSpeedBumpIndex()); |
| 174 | } |
| 175 | |
| 176 | private void updateSpeedBumpState(StackScrollState resultState, |
| 177 | StackScrollAlgorithmState algorithmState, int speedBumpIndex) { |
| 178 | int childCount = algorithmState.visibleChildren.size(); |
| 179 | for (int i = 0; i < childCount; i++) { |
| 180 | View child = algorithmState.visibleChildren.get(i); |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 181 | StackViewState childViewState = resultState.getViewStateForView(child); |
Selim Cinek | 3107cfa | 2014-07-22 15:24:29 +0200 | [diff] [blame] | 182 | |
| 183 | // The speed bump can also be gone, so equality needs to be taken when comparing |
| 184 | // indices. |
| 185 | childViewState.belowSpeedBump = speedBumpIndex != -1 && i >= speedBumpIndex; |
Selim Cinek | 3d2b94bf | 2014-07-02 22:12:47 +0200 | [diff] [blame] | 186 | } |
Selim Cinek | f54090e | 2014-06-17 17:24:51 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 189 | private void updateClipping(StackScrollState resultState, |
| 190 | StackScrollAlgorithmState algorithmState) { |
| 191 | float previousNotificationEnd = 0; |
| 192 | float previousNotificationStart = 0; |
| 193 | boolean previousNotificationIsSwiped = false; |
| 194 | int childCount = algorithmState.visibleChildren.size(); |
| 195 | for (int i = 0; i < childCount; i++) { |
| 196 | ExpandableView child = algorithmState.visibleChildren.get(i); |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 197 | StackViewState state = resultState.getViewStateForView(child); |
Jorim Jaggi | 2e34ec3 | 2014-07-01 03:17:05 +0200 | [diff] [blame] | 198 | float newYTranslation = state.yTranslation + state.height * (1f - state.scale) / 2f; |
| 199 | float newHeight = state.height * state.scale; |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 200 | // apply clipping and shadow |
| 201 | float newNotificationEnd = newYTranslation + newHeight; |
| 202 | |
Selim Cinek | c5baa3e | 2014-10-29 19:04:19 +0100 | [diff] [blame] | 203 | float clipHeight; |
| 204 | if (previousNotificationIsSwiped) { |
| 205 | // When the previous notification is swiped, we don't clip the content to the |
| 206 | // bottom of it. |
| 207 | clipHeight = newHeight; |
| 208 | } else { |
| 209 | clipHeight = newNotificationEnd - previousNotificationEnd; |
| 210 | clipHeight = Math.max(0.0f, clipHeight); |
| 211 | if (clipHeight != 0.0f) { |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 212 | |
Selim Cinek | c5baa3e | 2014-10-29 19:04:19 +0100 | [diff] [blame] | 213 | // In the unlocked shade we have to clip a little bit higher because of the rounded |
| 214 | // corners of the notifications, but only if we are not fully overlapped by |
| 215 | // the top card. |
| 216 | float clippingCorrection = state.dimmed |
| 217 | ? 0 |
| 218 | : mRoundedRectCornerRadius * state.scale; |
| 219 | clipHeight += clippingCorrection; |
| 220 | } |
| 221 | } |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 222 | |
| 223 | updateChildClippingAndBackground(state, newHeight, clipHeight, |
Jorim Jaggi | 2e34ec3 | 2014-07-01 03:17:05 +0200 | [diff] [blame] | 224 | newHeight - (previousNotificationStart - newYTranslation)); |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 225 | |
| 226 | if (!child.isTransparent()) { |
| 227 | // Only update the previous values if we are not transparent, |
| 228 | // otherwise we would clip to a transparent view. |
Jorim Jaggi | 2e34ec3 | 2014-07-01 03:17:05 +0200 | [diff] [blame] | 229 | previousNotificationStart = newYTranslation + state.clipTopAmount * state.scale; |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 230 | previousNotificationEnd = newNotificationEnd; |
| 231 | previousNotificationIsSwiped = child.getTranslationX() != 0; |
| 232 | } |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Updates the shadow outline and the clipping for a view. |
| 238 | * |
| 239 | * @param state the viewState to update |
| 240 | * @param realHeight the currently applied height of the view |
| 241 | * @param clipHeight the desired clip height, the rest of the view will be clipped from the top |
| 242 | * @param backgroundHeight the desired background height. The shadows of the view will be |
| 243 | * based on this height and the content will be clipped from the top |
| 244 | */ |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 245 | private void updateChildClippingAndBackground(StackViewState state, float realHeight, |
| 246 | float clipHeight, float backgroundHeight) { |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 247 | if (realHeight > clipHeight) { |
Jorim Jaggi | 2e34ec3 | 2014-07-01 03:17:05 +0200 | [diff] [blame] | 248 | // Rather overlap than create a hole. |
| 249 | state.topOverLap = (int) Math.floor((realHeight - clipHeight) / state.scale); |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 250 | } else { |
| 251 | state.topOverLap = 0; |
| 252 | } |
| 253 | if (realHeight > backgroundHeight) { |
Jorim Jaggi | 2e34ec3 | 2014-07-01 03:17:05 +0200 | [diff] [blame] | 254 | // Rather overlap than create a hole. |
| 255 | state.clipTopAmount = (int) Math.floor((realHeight - backgroundHeight) / state.scale); |
Selim Cinek | 708a6c1 | 2014-05-28 14:16:02 +0200 | [diff] [blame] | 256 | } else { |
| 257 | state.clipTopAmount = 0; |
| 258 | } |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 259 | } |
| 260 | |
| 261 | /** |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 262 | * Updates the dimmed, activated and hiding sensitive states of the children. |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 263 | */ |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 264 | private void updateDimmedActivatedHideSensitive(AmbientState ambientState, |
| 265 | StackScrollState resultState, StackScrollAlgorithmState algorithmState) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 266 | boolean dimmed = ambientState.isDimmed(); |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 267 | boolean dark = ambientState.isDark(); |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 268 | boolean hideSensitive = ambientState.isHideSensitive(); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 269 | View activatedChild = ambientState.getActivatedChild(); |
| 270 | int childCount = algorithmState.visibleChildren.size(); |
| 271 | for (int i = 0; i < childCount; i++) { |
| 272 | View child = algorithmState.visibleChildren.get(i); |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 273 | StackViewState childViewState = resultState.getViewStateForView(child); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 274 | childViewState.dimmed = dimmed; |
John Spurlock | bf37099 | 2014-06-17 13:58:31 -0400 | [diff] [blame] | 275 | childViewState.dark = dark; |
Jorim Jaggi | ae44128 | 2014-08-01 02:45:18 +0200 | [diff] [blame] | 276 | childViewState.hideSensitive = hideSensitive; |
Selim Cinek | b89de4e | 2014-06-10 10:47:05 +0200 | [diff] [blame] | 277 | boolean isActivatedChild = activatedChild == child; |
Jorim Jaggi | d7c1fae | 2014-08-13 18:27:47 +0200 | [diff] [blame] | 278 | childViewState.scale = !mScaleDimmed || !dimmed || isActivatedChild |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 279 | ? 1.0f |
| 280 | : DIMMED_SCALE; |
Jorim Jaggi | 4538cee | 2014-09-09 15:21:38 +0200 | [diff] [blame] | 281 | if (dimmed && isActivatedChild) { |
| 282 | childViewState.zTranslation += 2.0f * mZDistanceBetweenElements; |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 283 | } |
| 284 | } |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Handle the special state when views are being dragged |
| 289 | */ |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 290 | private void handleDraggedViews(AmbientState ambientState, StackScrollState resultState, |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 291 | StackScrollAlgorithmState algorithmState) { |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 292 | ArrayList<View> draggedViews = ambientState.getDraggedViews(); |
| 293 | for (View draggedView : draggedViews) { |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 294 | int childIndex = algorithmState.visibleChildren.indexOf(draggedView); |
| 295 | if (childIndex >= 0 && childIndex < algorithmState.visibleChildren.size() - 1) { |
| 296 | View nextChild = algorithmState.visibleChildren.get(childIndex + 1); |
Jorim Jaggi | d552d9d | 2014-05-07 19:41:13 +0200 | [diff] [blame] | 297 | if (!draggedViews.contains(nextChild)) { |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 298 | // only if the view is not dragged itself we modify its state to be fully |
| 299 | // visible |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 300 | StackViewState viewState = resultState.getViewStateForView( |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 301 | nextChild); |
| 302 | // The child below the dragged one must be fully visible |
| 303 | viewState.alpha = 1; |
| 304 | } |
| 305 | |
| 306 | // Lets set the alpha to the one it currently has, as its currently being dragged |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 307 | StackViewState viewState = resultState.getViewStateForView(draggedView); |
Selim Cinek | eb97356 | 2014-05-02 17:07:49 +0200 | [diff] [blame] | 308 | // The dragged child should keep the set alpha |
| 309 | viewState.alpha = draggedView.getAlpha(); |
| 310 | } |
| 311 | } |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 312 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 313 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 314 | /** |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 315 | * Update the visible children on the state. |
| 316 | */ |
| 317 | private void updateVisibleChildren(StackScrollState resultState, |
| 318 | StackScrollAlgorithmState state) { |
| 319 | ViewGroup hostView = resultState.getHostView(); |
| 320 | int childCount = hostView.getChildCount(); |
| 321 | state.visibleChildren.clear(); |
| 322 | state.visibleChildren.ensureCapacity(childCount); |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 323 | int notGoneIndex = 0; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 324 | for (int i = 0; i < childCount; i++) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 325 | ExpandableView v = (ExpandableView) hostView.getChildAt(i); |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 326 | if (v.getVisibility() != View.GONE) { |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 327 | StackViewState viewState = resultState.getViewStateForView(v); |
| 328 | viewState.notGoneIndex = notGoneIndex; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 329 | state.visibleChildren.add(v); |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 330 | notGoneIndex++; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 331 | } |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | /** |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 336 | * Determine the positions for the views. This is the main part of the algorithm. |
| 337 | * |
| 338 | * @param resultState The result state to update if a change to the properties of a child occurs |
| 339 | * @param algorithmState The state in which the current pass of the algorithm is currently in |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 340 | */ |
| 341 | private void updatePositionsForState(StackScrollState resultState, |
| 342 | StackScrollAlgorithmState algorithmState) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 343 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 344 | // The starting position of the bottom stack peek |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 345 | float bottomPeekStart = mInnerHeight - mBottomStackPeekSize; |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 346 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 347 | // The position where the bottom stack starts. |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 348 | float bottomStackStart = bottomPeekStart - mBottomStackSlowDownLength; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 349 | |
| 350 | // The y coordinate of the current child. |
| 351 | float currentYPosition = 0.0f; |
| 352 | |
| 353 | // How far in is the element currently transitioning into the bottom stack. |
| 354 | float yPositionInScrollView = 0.0f; |
| 355 | |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 356 | int childCount = algorithmState.visibleChildren.size(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 357 | int numberOfElementsCompletelyIn = (int) algorithmState.itemsInTopStack; |
| 358 | for (int i = 0; i < childCount; i++) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 359 | ExpandableView child = algorithmState.visibleChildren.get(i); |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 360 | StackViewState childViewState = resultState.getViewStateForView(child); |
| 361 | childViewState.location = StackViewState.LOCATION_UNKNOWN; |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 362 | int childHeight = getMaxAllowedChildHeight(child); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 363 | float yPositionInScrollViewAfterElement = yPositionInScrollView |
| 364 | + childHeight |
| 365 | + mPaddingBetweenElements; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 366 | float scrollOffset = yPositionInScrollView - algorithmState.scrollY + mCollapsedSize; |
| 367 | |
| 368 | if (i == algorithmState.lastTopStackIndex + 1) { |
| 369 | // Normally the position of this child is the position in the regular scrollview, |
| 370 | // but if the two stacks are very close to each other, |
| 371 | // then have have to push it even more upwards to the position of the bottom |
| 372 | // stack start. |
| 373 | currentYPosition = Math.min(scrollOffset, bottomStackStart); |
| 374 | } |
| 375 | childViewState.yTranslation = currentYPosition; |
| 376 | |
| 377 | // The y position after this element |
| 378 | float nextYPosition = currentYPosition + childHeight + |
| 379 | mPaddingBetweenElements; |
| 380 | |
| 381 | if (i <= algorithmState.lastTopStackIndex) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 382 | // Case 1: |
| 383 | // We are in the top Stack |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 384 | updateStateForTopStackChild(algorithmState, |
| 385 | numberOfElementsCompletelyIn, i, childHeight, childViewState, scrollOffset); |
Selim Cinek | 3afd00e | 2014-08-11 22:32:57 +0200 | [diff] [blame] | 386 | clampPositionToTopStackEnd(childViewState, childHeight); |
| 387 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 388 | // check if we are overlapping with the bottom stack |
| 389 | if (childViewState.yTranslation + childHeight + mPaddingBetweenElements |
Selim Cinek | 4581cf8 | 2014-08-12 12:40:32 +0200 | [diff] [blame] | 390 | >= bottomStackStart && !mIsExpansionChanging && i != 0 && mIsSmallScreen) { |
Selim Cinek | 3afd00e | 2014-08-11 22:32:57 +0200 | [diff] [blame] | 391 | // we just collapse this element slightly |
| 392 | int newSize = (int) Math.max(bottomStackStart - mPaddingBetweenElements - |
| 393 | childViewState.yTranslation, mCollapsedSize); |
| 394 | childViewState.height = newSize; |
Selim Cinek | 4581cf8 | 2014-08-12 12:40:32 +0200 | [diff] [blame] | 395 | updateStateForChildTransitioningInBottom(algorithmState, bottomStackStart, |
| 396 | bottomPeekStart, childViewState.yTranslation, childViewState, |
| 397 | childHeight); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 398 | } |
Selim Cinek | 3afd00e | 2014-08-11 22:32:57 +0200 | [diff] [blame] | 399 | clampPositionToBottomStackStart(childViewState, childViewState.height); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 400 | } else if (nextYPosition >= bottomStackStart) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 401 | // Case 2: |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 402 | // We are in the bottom stack. |
| 403 | if (currentYPosition >= bottomStackStart) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 404 | // According to the regular scroll view we are fully translated out of the |
| 405 | // bottom of the screen so we are fully in the bottom stack |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 406 | updateStateForChildFullyInBottomStack(algorithmState, |
| 407 | bottomStackStart, childViewState, childHeight); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 408 | } else { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 409 | // According to the regular scroll view we are currently translating out of / |
| 410 | // into the bottom of the screen |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 411 | updateStateForChildTransitioningInBottom(algorithmState, |
| 412 | bottomStackStart, bottomPeekStart, currentYPosition, |
| 413 | childViewState, childHeight); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 414 | } |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 415 | } else { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 416 | // Case 3: |
| 417 | // We are in the regular scroll area. |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 418 | childViewState.location = StackViewState.LOCATION_MAIN_AREA; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 419 | clampYTranslation(childViewState, childHeight); |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 420 | } |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 421 | |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 422 | // The first card is always rendered. |
| 423 | if (i == 0) { |
| 424 | childViewState.alpha = 1.0f; |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 425 | childViewState.yTranslation = Math.max(mCollapsedSize - algorithmState.scrollY, 0); |
Selim Cinek | d83771e | 2014-07-04 16:45:31 +0200 | [diff] [blame] | 426 | if (childViewState.yTranslation + childViewState.height |
| 427 | > bottomPeekStart - mCollapseSecondCardPadding) { |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 428 | childViewState.height = (int) Math.max( |
Selim Cinek | d83771e | 2014-07-04 16:45:31 +0200 | [diff] [blame] | 429 | bottomPeekStart - mCollapseSecondCardPadding |
| 430 | - childViewState.yTranslation, mCollapsedSize); |
Selim Cinek | 4fe3e47 | 2014-07-03 16:32:54 +0200 | [diff] [blame] | 431 | } |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 432 | childViewState.location = StackViewState.LOCATION_FIRST_CARD; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 433 | } |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 434 | if (childViewState.location == StackViewState.LOCATION_UNKNOWN) { |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 435 | Log.wtf(LOG_TAG, "Failed to assign location for child " + i); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 436 | } |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 437 | currentYPosition = childViewState.yTranslation + childHeight + mPaddingBetweenElements; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 438 | yPositionInScrollView = yPositionInScrollViewAfterElement; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 439 | |
| 440 | childViewState.yTranslation += mTopPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 441 | } |
| 442 | } |
| 443 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 444 | /** |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 445 | * Clamp the yTranslation both up and down to valid positions. |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 446 | * |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 447 | * @param childViewState the view state of the child |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 448 | * @param childHeight the height of this child |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 449 | */ |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 450 | private void clampYTranslation(StackViewState childViewState, int childHeight) { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 451 | clampPositionToBottomStackStart(childViewState, childHeight); |
| 452 | clampPositionToTopStackEnd(childViewState, childHeight); |
| 453 | } |
| 454 | |
| 455 | /** |
| 456 | * Clamp the yTranslation of the child down such that its end is at most on the beginning of |
| 457 | * the bottom stack. |
| 458 | * |
| 459 | * @param childViewState the view state of the child |
| 460 | * @param childHeight the height of this child |
| 461 | */ |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 462 | private void clampPositionToBottomStackStart(StackViewState childViewState, |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 463 | int childHeight) { |
| 464 | childViewState.yTranslation = Math.min(childViewState.yTranslation, |
Selim Cinek | d83771e | 2014-07-04 16:45:31 +0200 | [diff] [blame] | 465 | mInnerHeight - mBottomStackPeekSize - mCollapseSecondCardPadding - childHeight); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 466 | } |
| 467 | |
| 468 | /** |
| 469 | * 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] | 470 | * stack.get |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 471 | * |
| 472 | * @param childViewState the view state of the child |
| 473 | * @param childHeight the height of this child |
| 474 | */ |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 475 | private void clampPositionToTopStackEnd(StackViewState childViewState, |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 476 | int childHeight) { |
| 477 | childViewState.yTranslation = Math.max(childViewState.yTranslation, |
| 478 | mCollapsedSize - childHeight); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 479 | } |
| 480 | |
| 481 | private int getMaxAllowedChildHeight(View child) { |
| 482 | if (child instanceof ExpandableNotificationRow) { |
| 483 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Jorim Jaggi | 9cbadd3 | 2014-05-01 20:18:31 +0200 | [diff] [blame] | 484 | return row.getIntrinsicHeight(); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 485 | } else if (child instanceof ExpandableView) { |
| 486 | ExpandableView expandableView = (ExpandableView) child; |
| 487 | return expandableView.getActualHeight(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 488 | } |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 489 | return child == null? mCollapsedSize : child.getHeight(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 490 | } |
| 491 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 492 | private void updateStateForChildTransitioningInBottom(StackScrollAlgorithmState algorithmState, |
| 493 | float transitioningPositionStart, float bottomPeakStart, float currentYPosition, |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 494 | StackViewState childViewState, int childHeight) { |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 495 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 496 | // This is the transitioning element on top of bottom stack, calculate how far we are in. |
| 497 | algorithmState.partialInBottom = 1.0f - ( |
| 498 | (transitioningPositionStart - currentYPosition) / (childHeight + |
| 499 | mPaddingBetweenElements)); |
| 500 | |
| 501 | // the offset starting at the transitionPosition of the bottom stack |
| 502 | float offset = mBottomStackIndentationFunctor.getValue(algorithmState.partialInBottom); |
| 503 | algorithmState.itemsInBottomStack += algorithmState.partialInBottom; |
Selim Cinek | 3afd00e | 2014-08-11 22:32:57 +0200 | [diff] [blame] | 504 | int newHeight = childHeight; |
| 505 | if (childHeight > mCollapsedSize && mIsSmallScreen) { |
| 506 | newHeight = (int) Math.max(Math.min(transitioningPositionStart + offset - |
| 507 | mPaddingBetweenElements - currentYPosition, childHeight), mCollapsedSize); |
| 508 | childViewState.height = newHeight; |
| 509 | } |
| 510 | childViewState.yTranslation = transitioningPositionStart + offset - newHeight |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 511 | - mPaddingBetweenElements; |
Selim Cinek | 3afd00e | 2014-08-11 22:32:57 +0200 | [diff] [blame] | 512 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 513 | // We want at least to be at the end of the top stack when collapsing |
Selim Cinek | 3afd00e | 2014-08-11 22:32:57 +0200 | [diff] [blame] | 514 | clampPositionToTopStackEnd(childViewState, newHeight); |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 515 | childViewState.location = StackViewState.LOCATION_MAIN_AREA; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 516 | } |
| 517 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 518 | private void updateStateForChildFullyInBottomStack(StackScrollAlgorithmState algorithmState, |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 519 | float transitioningPositionStart, StackViewState childViewState, |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 520 | int childHeight) { |
| 521 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 522 | float currentYPosition; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 523 | algorithmState.itemsInBottomStack += 1.0f; |
| 524 | if (algorithmState.itemsInBottomStack < MAX_ITEMS_IN_BOTTOM_STACK) { |
| 525 | // We are visually entering the bottom stack |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 526 | currentYPosition = transitioningPositionStart |
Jorim Jaggi | fe40f7d | 2014-04-28 15:20:04 +0200 | [diff] [blame] | 527 | + mBottomStackIndentationFunctor.getValue(algorithmState.itemsInBottomStack) |
| 528 | - mPaddingBetweenElements; |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 529 | childViewState.location = StackViewState.LOCATION_BOTTOM_STACK_PEEKING; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 530 | } else { |
| 531 | // we are fully inside the stack |
| 532 | if (algorithmState.itemsInBottomStack > MAX_ITEMS_IN_BOTTOM_STACK + 2) { |
| 533 | childViewState.alpha = 0.0f; |
| 534 | } else if (algorithmState.itemsInBottomStack |
| 535 | > MAX_ITEMS_IN_BOTTOM_STACK + 1) { |
| 536 | childViewState.alpha = 1.0f - algorithmState.partialInBottom; |
| 537 | } |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 538 | childViewState.location = StackViewState.LOCATION_BOTTOM_STACK_HIDDEN; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 539 | currentYPosition = mInnerHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 540 | } |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 541 | childViewState.yTranslation = currentYPosition - childHeight; |
| 542 | clampPositionToTopStackEnd(childViewState, childHeight); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 543 | } |
| 544 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 545 | private void updateStateForTopStackChild(StackScrollAlgorithmState algorithmState, |
| 546 | int numberOfElementsCompletelyIn, int i, int childHeight, |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 547 | StackViewState childViewState, float scrollOffset) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 548 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 549 | |
| 550 | // First we calculate the index relative to the current stack window of size at most |
| 551 | // {@link #MAX_ITEMS_IN_TOP_STACK} |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 552 | int paddedIndex = i - 1 |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 553 | - Math.max(numberOfElementsCompletelyIn - MAX_ITEMS_IN_TOP_STACK, 0); |
| 554 | if (paddedIndex >= 0) { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 555 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 556 | // We are currently visually entering the top stack |
Selim Cinek | ad3e5af | 2014-07-04 12:24:11 +0200 | [diff] [blame] | 557 | float distanceToStack = (childHeight + mPaddingBetweenElements) |
| 558 | - algorithmState.scrolledPixelsTop; |
| 559 | if (i == algorithmState.lastTopStackIndex |
| 560 | && distanceToStack > (mTopStackTotalSize + mPaddingBetweenElements)) { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 561 | |
| 562 | // Child is currently translating into stack but not yet inside slow down zone. |
| 563 | // Handle it like the regular scrollview. |
| 564 | childViewState.yTranslation = scrollOffset; |
Christoph Studer | 6e3eceb | 2014-04-01 18:40:27 +0200 | [diff] [blame] | 565 | } else { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 566 | // Apply stacking logic. |
| 567 | float numItemsBefore; |
| 568 | if (i == algorithmState.lastTopStackIndex) { |
Selim Cinek | ad3e5af | 2014-07-04 12:24:11 +0200 | [diff] [blame] | 569 | numItemsBefore = 1.0f |
| 570 | - (distanceToStack / (mTopStackTotalSize + mPaddingBetweenElements)); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 571 | } else { |
| 572 | numItemsBefore = algorithmState.itemsInTopStack - i; |
| 573 | } |
| 574 | // The end position of the current child |
Selim Cinek | ad3e5af | 2014-07-04 12:24:11 +0200 | [diff] [blame] | 575 | float currentChildEndY = mCollapsedSize + mTopStackTotalSize |
| 576 | - mTopStackIndentationFunctor.getValue(numItemsBefore); |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 577 | childViewState.yTranslation = currentChildEndY - childHeight; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 578 | } |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 579 | childViewState.location = StackViewState.LOCATION_TOP_STACK_PEEKING; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 580 | } else { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 581 | if (paddedIndex == -1) { |
| 582 | childViewState.alpha = 1.0f - algorithmState.partialInTop; |
| 583 | } else { |
| 584 | // We are hidden behind the top card and faded out, so we can hide ourselves. |
| 585 | childViewState.alpha = 0.0f; |
| 586 | } |
| 587 | childViewState.yTranslation = mCollapsedSize - childHeight; |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 588 | childViewState.location = StackViewState.LOCATION_TOP_STACK_HIDDEN; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 589 | } |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 590 | |
| 591 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | /** |
| 595 | * Find the number of items in the top stack and update the result state if needed. |
| 596 | * |
| 597 | * @param resultState The result state to update if a height change of an child occurs |
| 598 | * @param algorithmState The state in which the current pass of the algorithm is currently in |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 599 | */ |
| 600 | private void findNumberOfItemsInTopStackAndUpdateState(StackScrollState resultState, |
| 601 | StackScrollAlgorithmState algorithmState) { |
| 602 | |
| 603 | // The y Position if the element would be in a regular scrollView |
| 604 | float yPositionInScrollView = 0.0f; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 605 | int childCount = algorithmState.visibleChildren.size(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 606 | |
| 607 | // find the number of elements in the top stack. |
| 608 | for (int i = 0; i < childCount; i++) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 609 | ExpandableView child = algorithmState.visibleChildren.get(i); |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 610 | StackViewState childViewState = resultState.getViewStateForView(child); |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 611 | int childHeight = getMaxAllowedChildHeight(child); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 612 | float yPositionInScrollViewAfterElement = yPositionInScrollView |
| 613 | + childHeight |
| 614 | + mPaddingBetweenElements; |
| 615 | if (yPositionInScrollView < algorithmState.scrollY) { |
Selim Cinek | 8d9ff9c | 2014-05-12 15:13:04 +0200 | [diff] [blame] | 616 | if (i == 0 && algorithmState.scrollY <= mCollapsedSize) { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 617 | |
| 618 | // The starting position of the bottom stack peek |
Selim Cinek | d83771e | 2014-07-04 16:45:31 +0200 | [diff] [blame] | 619 | int bottomPeekStart = mInnerHeight - mBottomStackPeekSize - |
| 620 | mCollapseSecondCardPadding; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 621 | // Collapse and expand the first child while the shade is being expanded |
| 622 | float maxHeight = mIsExpansionChanging && child == mFirstChildWhileExpanding |
| 623 | ? mFirstChildMaxHeight |
| 624 | : childHeight; |
| 625 | childViewState.height = (int) Math.max(Math.min(bottomPeekStart, maxHeight), |
| 626 | mCollapsedSize); |
| 627 | algorithmState.itemsInTopStack = 1.0f; |
| 628 | |
| 629 | } else if (yPositionInScrollViewAfterElement < algorithmState.scrollY) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 630 | // According to the regular scroll view we are fully off screen |
| 631 | algorithmState.itemsInTopStack += 1.0f; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 632 | if (i == 0) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 633 | childViewState.height = mCollapsedSize; |
| 634 | } |
| 635 | } else { |
| 636 | // According to the regular scroll view we are partially off screen |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 637 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 638 | // How much did we scroll into this child |
Selim Cinek | ad3e5af | 2014-07-04 12:24:11 +0200 | [diff] [blame] | 639 | algorithmState.scrolledPixelsTop = algorithmState.scrollY |
| 640 | - yPositionInScrollView; |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 641 | algorithmState.partialInTop = (algorithmState.scrolledPixelsTop) / (childHeight |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 642 | + mPaddingBetweenElements); |
| 643 | |
| 644 | // Our element can be expanded, so this can get negative |
| 645 | algorithmState.partialInTop = Math.max(0.0f, algorithmState.partialInTop); |
| 646 | algorithmState.itemsInTopStack += algorithmState.partialInTop; |
Selim Cinek | ad3e5af | 2014-07-04 12:24:11 +0200 | [diff] [blame] | 647 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 648 | if (i == 0) { |
Selim Cinek | ad3e5af | 2014-07-04 12:24:11 +0200 | [diff] [blame] | 649 | // If it is expanded we have to collapse it to a new size |
| 650 | float newSize = yPositionInScrollViewAfterElement |
| 651 | - mPaddingBetweenElements |
| 652 | - algorithmState.scrollY + mCollapsedSize; |
| 653 | newSize = Math.max(mCollapsedSize, newSize); |
Selim Cinek | 4e456be | 2014-06-12 18:09:43 +0200 | [diff] [blame] | 654 | algorithmState.itemsInTopStack = 1.0f; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 655 | childViewState.height = (int) newSize; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 656 | } |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 657 | algorithmState.lastTopStackIndex = i; |
| 658 | break; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 659 | } |
| 660 | } else { |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 661 | algorithmState.lastTopStackIndex = i - 1; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 662 | // We are already past the stack so we can end the loop |
| 663 | break; |
| 664 | } |
| 665 | yPositionInScrollView = yPositionInScrollViewAfterElement; |
| 666 | } |
| 667 | } |
| 668 | |
| 669 | /** |
| 670 | * Calculate the Z positions for all children based on the number of items in both stacks and |
| 671 | * save it in the resultState |
| 672 | * |
| 673 | * @param resultState The result state to update the zTranslation values |
| 674 | * @param algorithmState The state in which the current pass of the algorithm is currently in |
| 675 | */ |
| 676 | private void updateZValuesForState(StackScrollState resultState, |
| 677 | StackScrollAlgorithmState algorithmState) { |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 678 | int childCount = algorithmState.visibleChildren.size(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 679 | for (int i = 0; i < childCount; i++) { |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 680 | View child = algorithmState.visibleChildren.get(i); |
Selim Cinek | b036ca4 | 2015-02-20 15:56:28 +0100 | [diff] [blame^] | 681 | StackViewState childViewState = resultState.getViewStateForView(child); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 682 | if (i < algorithmState.itemsInTopStack) { |
| 683 | float stackIndex = algorithmState.itemsInTopStack - i; |
Selim Cinek | c5baa3e | 2014-10-29 19:04:19 +0100 | [diff] [blame] | 684 | |
| 685 | // Ensure that the topmost item is a little bit higher than the rest when fully |
| 686 | // scrolled, to avoid drawing errors when swiping it out |
| 687 | float max = MAX_ITEMS_IN_TOP_STACK + (i == 0 ? 2.5f : 2); |
| 688 | stackIndex = Math.min(stackIndex, max); |
Selim Cinek | 4e456be | 2014-06-12 18:09:43 +0200 | [diff] [blame] | 689 | if (i == 0 && algorithmState.itemsInTopStack < 2.0f) { |
| 690 | |
| 691 | // We only have the top item and an additional item in the top stack, |
| 692 | // Interpolate the index from 0 to 2 while the second item is |
| 693 | // translating in. |
| 694 | stackIndex -= 1.0f; |
| 695 | if (algorithmState.scrollY > mCollapsedSize) { |
| 696 | |
| 697 | // Since there is a shadow treshhold, we cant just interpolate from 0 to |
| 698 | // 2 but we interpolate from 0.1f to 2.0f when scrolled in. The jump in |
| 699 | // height will not be noticable since we have padding in between. |
| 700 | stackIndex = 0.1f + stackIndex * 1.9f; |
| 701 | } |
| 702 | } |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 703 | childViewState.zTranslation = mZBasicHeight |
| 704 | + stackIndex * mZDistanceBetweenElements; |
| 705 | } else if (i > (childCount - 1 - algorithmState.itemsInBottomStack)) { |
| 706 | float numItemsAbove = i - (childCount - 1 - algorithmState.itemsInBottomStack); |
| 707 | float translationZ = mZBasicHeight |
| 708 | - numItemsAbove * mZDistanceBetweenElements; |
| 709 | childViewState.zTranslation = translationZ; |
| 710 | } else { |
| 711 | childViewState.zTranslation = mZBasicHeight; |
| 712 | } |
| 713 | } |
| 714 | } |
| 715 | |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 716 | public void setLayoutHeight(int layoutHeight) { |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 717 | this.mLayoutHeight = layoutHeight; |
Jorim Jaggi | 8c1a44b | 2014-04-29 19:04:02 +0200 | [diff] [blame] | 718 | updateInnerHeight(); |
| 719 | } |
| 720 | |
| 721 | public void setTopPadding(int topPadding) { |
| 722 | mTopPadding = topPadding; |
| 723 | updateInnerHeight(); |
| 724 | } |
| 725 | |
| 726 | private void updateInnerHeight() { |
| 727 | mInnerHeight = mLayoutHeight - mTopPadding; |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 728 | } |
| 729 | |
Selim Cinek | 3afd00e | 2014-08-11 22:32:57 +0200 | [diff] [blame] | 730 | |
| 731 | /** |
| 732 | * Update whether the device is very small, i.e. Notifications can be in both the top and the |
| 733 | * bottom stack at the same time |
| 734 | * |
| 735 | * @param panelHeight The normal height of the panel when it's open |
| 736 | */ |
| 737 | public void updateIsSmallScreen(int panelHeight) { |
| 738 | mIsSmallScreen = panelHeight < |
| 739 | mCollapsedSize /* top stack */ |
| 740 | + mBottomStackSlowDownLength + mBottomStackPeekSize /* bottom stack */ |
| 741 | + mMaxNotificationHeight; /* max notification height */ |
| 742 | } |
| 743 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 744 | public void onExpansionStarted(StackScrollState currentState) { |
| 745 | mIsExpansionChanging = true; |
| 746 | mExpandedOnStart = mIsExpanded; |
| 747 | ViewGroup hostView = currentState.getHostView(); |
| 748 | updateFirstChildHeightWhileExpanding(hostView); |
| 749 | } |
| 750 | |
| 751 | private void updateFirstChildHeightWhileExpanding(ViewGroup hostView) { |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 752 | mFirstChildWhileExpanding = (ExpandableView) findFirstVisibleChild(hostView); |
Jorim Jaggi | 9f347ae | 2014-04-11 00:47:18 +0200 | [diff] [blame] | 753 | if (mFirstChildWhileExpanding != null) { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 754 | if (mExpandedOnStart) { |
| 755 | |
| 756 | // We are collapsing the shade, so the first child can get as most as high as the |
Selim Cinek | 02af41e | 2014-10-14 15:46:43 +0200 | [diff] [blame] | 757 | // current height or the end value of the animation. |
| 758 | mFirstChildMaxHeight = StackStateAnimator.getFinalActualHeight( |
| 759 | mFirstChildWhileExpanding); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 760 | } else { |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 761 | updateFirstChildMaxSizeToMaxHeight(); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 762 | } |
| 763 | } else { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 764 | mFirstChildMaxHeight = 0; |
| 765 | } |
| 766 | } |
| 767 | |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 768 | private void updateFirstChildMaxSizeToMaxHeight() { |
| 769 | // We are expanding the shade, expand it to its full height. |
| 770 | if (!isMaxSizeInitialized(mFirstChildWhileExpanding)) { |
| 771 | |
| 772 | // This child was not layouted yet, wait for a layout pass |
| 773 | mFirstChildWhileExpanding |
| 774 | .addOnLayoutChangeListener(new View.OnLayoutChangeListener() { |
| 775 | @Override |
| 776 | public void onLayoutChange(View v, int left, int top, int right, |
| 777 | int bottom, int oldLeft, int oldTop, int oldRight, |
| 778 | int oldBottom) { |
| 779 | if (mFirstChildWhileExpanding != null) { |
| 780 | mFirstChildMaxHeight = getMaxAllowedChildHeight( |
| 781 | mFirstChildWhileExpanding); |
| 782 | } else { |
| 783 | mFirstChildMaxHeight = 0; |
| 784 | } |
| 785 | v.removeOnLayoutChangeListener(this); |
| 786 | } |
| 787 | }); |
| 788 | } else { |
| 789 | mFirstChildMaxHeight = getMaxAllowedChildHeight(mFirstChildWhileExpanding); |
| 790 | } |
| 791 | } |
| 792 | |
Selim Cinek | 7d44772 | 2014-06-10 15:51:59 +0200 | [diff] [blame] | 793 | private boolean isMaxSizeInitialized(ExpandableView child) { |
| 794 | if (child instanceof ExpandableNotificationRow) { |
| 795 | ExpandableNotificationRow row = (ExpandableNotificationRow) child; |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 796 | return row.isMaxExpandHeightInitialized(); |
Selim Cinek | 7d44772 | 2014-06-10 15:51:59 +0200 | [diff] [blame] | 797 | } |
| 798 | return child == null || child.getWidth() != 0; |
| 799 | } |
| 800 | |
Jorim Jaggi | 9f347ae | 2014-04-11 00:47:18 +0200 | [diff] [blame] | 801 | private View findFirstVisibleChild(ViewGroup container) { |
| 802 | int childCount = container.getChildCount(); |
| 803 | for (int i = 0; i < childCount; i++) { |
| 804 | View child = container.getChildAt(i); |
| 805 | if (child.getVisibility() != View.GONE) { |
| 806 | return child; |
| 807 | } |
| 808 | } |
| 809 | return null; |
| 810 | } |
| 811 | |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 812 | public void onExpansionStopped() { |
| 813 | mIsExpansionChanging = false; |
| 814 | mFirstChildWhileExpanding = null; |
| 815 | } |
| 816 | |
| 817 | public void setIsExpanded(boolean isExpanded) { |
| 818 | this.mIsExpanded = isExpanded; |
| 819 | } |
| 820 | |
Selim Cinek | 02af41e | 2014-10-14 15:46:43 +0200 | [diff] [blame] | 821 | public void notifyChildrenChanged(final ViewGroup hostView) { |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 822 | if (mIsExpansionChanging) { |
Selim Cinek | 02af41e | 2014-10-14 15:46:43 +0200 | [diff] [blame] | 823 | hostView.post(new Runnable() { |
| 824 | @Override |
| 825 | public void run() { |
| 826 | updateFirstChildHeightWhileExpanding(hostView); |
| 827 | } |
| 828 | }); |
Selim Cinek | 1685e63 | 2014-04-08 02:27:49 +0200 | [diff] [blame] | 829 | } |
| 830 | } |
| 831 | |
Selim Cinek | 34c0a8d | 2014-05-12 00:01:43 +0200 | [diff] [blame] | 832 | public void setDimmed(boolean dimmed) { |
| 833 | updatePadding(dimmed); |
| 834 | } |
| 835 | |
Selim Cinek | 31094df | 2014-08-14 19:28:15 +0200 | [diff] [blame] | 836 | public void onReset(ExpandableView view) { |
| 837 | if (view.equals(mFirstChildWhileExpanding)) { |
| 838 | updateFirstChildMaxSizeToMaxHeight(); |
| 839 | } |
| 840 | } |
| 841 | |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 842 | class StackScrollAlgorithmState { |
| 843 | |
| 844 | /** |
| 845 | * The scroll position of the algorithm |
| 846 | */ |
| 847 | public int scrollY; |
| 848 | |
| 849 | /** |
| 850 | * The quantity of items which are in the top stack. |
| 851 | */ |
| 852 | public float itemsInTopStack; |
| 853 | |
| 854 | /** |
| 855 | * how far in is the element currently transitioning into the top stack |
| 856 | */ |
| 857 | public float partialInTop; |
| 858 | |
| 859 | /** |
Selim Cinek | 343e6e2 | 2014-04-11 21:23:30 +0200 | [diff] [blame] | 860 | * The number of pixels the last child in the top stack has scrolled in to the stack |
| 861 | */ |
| 862 | public float scrolledPixelsTop; |
| 863 | |
| 864 | /** |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 865 | * The last item index which is in the top stack. |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 866 | */ |
| 867 | public int lastTopStackIndex; |
| 868 | |
| 869 | /** |
| 870 | * The quantity of items which are in the bottom stack. |
| 871 | */ |
| 872 | public float itemsInBottomStack; |
| 873 | |
| 874 | /** |
| 875 | * how far in is the element currently transitioning into the bottom stack |
| 876 | */ |
| 877 | public float partialInBottom; |
Jorim Jaggi | d4a5744 | 2014-04-10 02:45:55 +0200 | [diff] [blame] | 878 | |
| 879 | /** |
| 880 | * The children from the host view which are not gone. |
| 881 | */ |
Jorim Jaggi | be565df | 2014-04-28 17:51:23 +0200 | [diff] [blame] | 882 | public final ArrayList<ExpandableView> visibleChildren = new ArrayList<ExpandableView>(); |
Selim Cinek | 67b2260 | 2014-03-10 15:40:16 +0100 | [diff] [blame] | 883 | } |
| 884 | |
| 885 | } |