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