blob: c22b8c2109062741e663e62b35902cf4b6ca4632 [file] [log] [blame]
Selim Cinek67b22602014-03-10 15:40:16 +01001/*
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
17package com.android.systemui.statusbar.stack;
18
19import android.content.Context;
Christoph Studer6e3eceb2014-04-01 18:40:27 +020020import android.util.Log;
Selim Cinek67b22602014-03-10 15:40:16 +010021import android.view.View;
22import android.view.ViewGroup;
Selim Cinek343e6e22014-04-11 21:23:30 +020023
Selim Cinek67b22602014-03-10 15:40:16 +010024import com.android.systemui.R;
Selim Cinek1685e632014-04-08 02:27:49 +020025import com.android.systemui.statusbar.ExpandableNotificationRow;
Jorim Jaggibe565df2014-04-28 17:51:23 +020026import com.android.systemui.statusbar.ExpandableView;
Selim Cinek67b22602014-03-10 15:40:16 +010027
Jorim Jaggid4a57442014-04-10 02:45:55 +020028import java.util.ArrayList;
29
Selim Cinek67b22602014-03-10 15:40:16 +010030/**
31 * The Algorithm of the {@link com.android.systemui.statusbar.stack
32 * .NotificationStackScrollLayout} which can be queried for {@link com.android.systemui.statusbar
33 * .stack.StackScrollState}
34 */
35public class StackScrollAlgorithm {
36
Christoph Studer6e3eceb2014-04-01 18:40:27 +020037 private static final String LOG_TAG = "StackScrollAlgorithm";
38
Selim Cinek67b22602014-03-10 15:40:16 +010039 private static final int MAX_ITEMS_IN_BOTTOM_STACK = 3;
40 private static final int MAX_ITEMS_IN_TOP_STACK = 3;
41
Jorim Jaggid552d9d2014-05-07 19:41:13 +020042 /** When a child is activated, the other cards' alpha fade to this value. */
43 private static final float ACTIVATED_INVERSE_ALPHA = 0.9f;
44 private static final float DIMMED_SCALE = 0.95f;
45
Selim Cinek67b22602014-03-10 15:40:16 +010046 private int mPaddingBetweenElements;
47 private int mCollapsedSize;
48 private int mTopStackPeekSize;
49 private int mBottomStackPeekSize;
50 private int mZDistanceBetweenElements;
51 private int mZBasicHeight;
Selim Cinek708a6c12014-05-28 14:16:02 +020052 private int mRoundedRectCornerRadius;
Selim Cinek67b22602014-03-10 15:40:16 +010053
54 private StackIndentationFunctor mTopStackIndentationFunctor;
55 private StackIndentationFunctor mBottomStackIndentationFunctor;
56
Selim Cinek343e6e22014-04-11 21:23:30 +020057 private int mLayoutHeight;
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +020058
59 /** mLayoutHeight - mTopPadding */
60 private int mInnerHeight;
61 private int mTopPadding;
Selim Cinek67b22602014-03-10 15:40:16 +010062 private StackScrollAlgorithmState mTempAlgorithmState = new StackScrollAlgorithmState();
Selim Cinek1685e632014-04-08 02:27:49 +020063 private boolean mIsExpansionChanging;
64 private int mFirstChildMaxHeight;
65 private boolean mIsExpanded;
Jorim Jaggibe565df2014-04-28 17:51:23 +020066 private ExpandableView mFirstChildWhileExpanding;
Selim Cinek1685e632014-04-08 02:27:49 +020067 private boolean mExpandedOnStart;
Selim Cinek343e6e22014-04-11 21:23:30 +020068 private int mTopStackTotalSize;
Selim Cinek34c0a8d2014-05-12 00:01:43 +020069 private int mPaddingBetweenElementsDimmed;
70 private int mPaddingBetweenElementsNormal;
71 private int mBottomStackSlowDownLength;
Selim Cinekad3e5af2014-07-04 12:24:11 +020072 private int mTopStackSlowDownLength;
Selim Cinekd83771e2014-07-04 16:45:31 +020073 private int mCollapseSecondCardPadding;
Selim Cinek67b22602014-03-10 15:40:16 +010074
75 public StackScrollAlgorithm(Context context) {
76 initConstants(context);
Selim Cinek34c0a8d2014-05-12 00:01:43 +020077 updatePadding(false);
78 }
79
80 private void updatePadding(boolean dimmed) {
81 mPaddingBetweenElements = dimmed
82 ? mPaddingBetweenElementsDimmed
83 : mPaddingBetweenElementsNormal;
Selim Cinekad3e5af2014-07-04 12:24:11 +020084 mTopStackTotalSize = mTopStackSlowDownLength + mPaddingBetweenElements
85 + mTopStackPeekSize;
Selim Cinek34c0a8d2014-05-12 00:01:43 +020086 mTopStackIndentationFunctor = new PiecewiseLinearIndentationFunctor(
87 MAX_ITEMS_IN_TOP_STACK,
88 mTopStackPeekSize,
Selim Cinekb96924d2014-05-12 15:11:25 +020089 mTopStackTotalSize - mTopStackPeekSize,
Selim Cinek34c0a8d2014-05-12 00:01:43 +020090 0.5f);
91 mBottomStackIndentationFunctor = new PiecewiseLinearIndentationFunctor(
92 MAX_ITEMS_IN_BOTTOM_STACK,
93 mBottomStackPeekSize,
94 getBottomStackSlowDownLength(),
95 0.5f);
96 }
97
98 public int getBottomStackSlowDownLength() {
99 return mBottomStackSlowDownLength + mPaddingBetweenElements;
Selim Cinek67b22602014-03-10 15:40:16 +0100100 }
101
102 private void initConstants(Context context) {
Selim Cinek34c0a8d2014-05-12 00:01:43 +0200103 mPaddingBetweenElementsDimmed = context.getResources()
104 .getDimensionPixelSize(R.dimen.notification_padding_dimmed);
105 mPaddingBetweenElementsNormal = context.getResources()
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200106 .getDimensionPixelSize(R.dimen.notification_padding);
Selim Cinek67b22602014-03-10 15:40:16 +0100107 mCollapsedSize = context.getResources()
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200108 .getDimensionPixelSize(R.dimen.notification_min_height);
Selim Cinek67b22602014-03-10 15:40:16 +0100109 mTopStackPeekSize = context.getResources()
110 .getDimensionPixelSize(R.dimen.top_stack_peek_amount);
111 mBottomStackPeekSize = context.getResources()
112 .getDimensionPixelSize(R.dimen.bottom_stack_peek_amount);
113 mZDistanceBetweenElements = context.getResources()
114 .getDimensionPixelSize(R.dimen.z_distance_between_notifications);
115 mZBasicHeight = (MAX_ITEMS_IN_BOTTOM_STACK + 1) * mZDistanceBetweenElements;
Selim Cinek34c0a8d2014-05-12 00:01:43 +0200116 mBottomStackSlowDownLength = context.getResources()
117 .getDimensionPixelSize(R.dimen.bottom_stack_slow_down_length);
Selim Cinekad3e5af2014-07-04 12:24:11 +0200118 mTopStackSlowDownLength = context.getResources()
119 .getDimensionPixelSize(R.dimen.top_stack_slow_down_length);
Selim Cinek708a6c12014-05-28 14:16:02 +0200120 mRoundedRectCornerRadius = context.getResources().getDimensionPixelSize(
Selim Cinek697178b2014-07-02 19:40:30 +0200121 R.dimen.notification_material_rounded_rect_radius);
Selim Cinekd83771e2014-07-04 16:45:31 +0200122 mCollapseSecondCardPadding = context.getResources().getDimensionPixelSize(
123 R.dimen.notification_collapse_second_card_padding);
Selim Cinek67b22602014-03-10 15:40:16 +0100124 }
125
126
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200127 public void getStackScrollState(AmbientState ambientState, StackScrollState resultState) {
Selim Cinek67b22602014-03-10 15:40:16 +0100128 // The state of the local variables are saved in an algorithmState to easily subdivide it
129 // into multiple phases.
130 StackScrollAlgorithmState algorithmState = mTempAlgorithmState;
131
132 // First we reset the view states to their default values.
133 resultState.resetViewStates();
134
Selim Cinek343e6e22014-04-11 21:23:30 +0200135 algorithmState.itemsInTopStack = 0.0f;
Selim Cinek67b22602014-03-10 15:40:16 +0100136 algorithmState.partialInTop = 0.0f;
137 algorithmState.lastTopStackIndex = 0;
Selim Cinek343e6e22014-04-11 21:23:30 +0200138 algorithmState.scrolledPixelsTop = 0;
Selim Cinek67b22602014-03-10 15:40:16 +0100139 algorithmState.itemsInBottomStack = 0.0f;
Selim Cinek343e6e22014-04-11 21:23:30 +0200140 algorithmState.partialInBottom = 0.0f;
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200141 float bottomOverScroll = ambientState.getOverScrollAmount(false /* onTop */);
Selim Cinek1408eb52014-06-02 14:45:38 +0200142
143 int scrollY = ambientState.getScrollY();
144
145 // Due to the overScroller, the stackscroller can have negative scroll state. This is
146 // already accounted for by the top padding and doesn't need an additional adaption
147 scrollY = Math.max(0, scrollY);
148 algorithmState.scrollY = (int) (scrollY + mCollapsedSize + bottomOverScroll);
Selim Cinek343e6e22014-04-11 21:23:30 +0200149
Jorim Jaggid4a57442014-04-10 02:45:55 +0200150 updateVisibleChildren(resultState, algorithmState);
Selim Cinek67b22602014-03-10 15:40:16 +0100151
152 // Phase 1:
153 findNumberOfItemsInTopStackAndUpdateState(resultState, algorithmState);
154
155 // Phase 2:
156 updatePositionsForState(resultState, algorithmState);
157
158 // Phase 3:
159 updateZValuesForState(resultState, algorithmState);
Selim Cinekeb973562014-05-02 17:07:49 +0200160
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200161 handleDraggedViews(ambientState, resultState, algorithmState);
162 updateDimmedActivated(ambientState, resultState, algorithmState);
Selim Cinek708a6c12014-05-28 14:16:02 +0200163 updateClipping(resultState, algorithmState);
Selim Cinekf54090e2014-06-17 17:24:51 -0700164 updateScrimAmount(resultState, algorithmState, ambientState.getScrimAmount());
Selim Cinek3d2b94bf2014-07-02 22:12:47 +0200165 updateSpeedBumpState(resultState, algorithmState, ambientState.getSpeedBumpIndex());
166 }
167
168 private void updateSpeedBumpState(StackScrollState resultState,
169 StackScrollAlgorithmState algorithmState, int speedBumpIndex) {
170 int childCount = algorithmState.visibleChildren.size();
171 for (int i = 0; i < childCount; i++) {
172 View child = algorithmState.visibleChildren.get(i);
173 StackScrollState.ViewState childViewState = resultState.getViewStateForView(child);
174 childViewState.belowSpeedBump = speedBumpIndex != -1 && i > speedBumpIndex;
175 }
Selim Cinekf54090e2014-06-17 17:24:51 -0700176 }
177
178 private void updateScrimAmount(StackScrollState resultState,
179 StackScrollAlgorithmState algorithmState, float scrimAmount) {
180 int childCount = algorithmState.visibleChildren.size();
181 for (int i = 0; i < childCount; i++) {
182 View child = algorithmState.visibleChildren.get(i);
183 StackScrollState.ViewState childViewState = resultState.getViewStateForView(child);
184 childViewState.scrimAmount = scrimAmount;
185 }
Selim Cinek708a6c12014-05-28 14:16:02 +0200186 }
187
188 private void updateClipping(StackScrollState resultState,
189 StackScrollAlgorithmState algorithmState) {
190 float previousNotificationEnd = 0;
191 float previousNotificationStart = 0;
192 boolean previousNotificationIsSwiped = false;
193 int childCount = algorithmState.visibleChildren.size();
194 for (int i = 0; i < childCount; i++) {
195 ExpandableView child = algorithmState.visibleChildren.get(i);
196 StackScrollState.ViewState state = resultState.getViewStateForView(child);
Jorim Jaggi2e34ec32014-07-01 03:17:05 +0200197 float newYTranslation = state.yTranslation + state.height * (1f - state.scale) / 2f;
198 float newHeight = state.height * state.scale;
Selim Cinek708a6c12014-05-28 14:16:02 +0200199 // apply clipping and shadow
200 float newNotificationEnd = newYTranslation + newHeight;
201
202 // In the unlocked shade we have to clip a little bit higher because of the rounded
203 // corners of the notifications.
Jorim Jaggi2e34ec32014-07-01 03:17:05 +0200204 float clippingCorrection = state.dimmed ? 0 : mRoundedRectCornerRadius * state.scale;
Selim Cinek708a6c12014-05-28 14:16:02 +0200205
206 // When the previous notification is swiped, we don't clip the content to the
207 // bottom of it.
208 float clipHeight = previousNotificationIsSwiped
209 ? newHeight
210 : newNotificationEnd - (previousNotificationEnd - clippingCorrection);
211
212 updateChildClippingAndBackground(state, newHeight, clipHeight,
Jorim Jaggi2e34ec32014-07-01 03:17:05 +0200213 newHeight - (previousNotificationStart - newYTranslation));
Selim Cinek708a6c12014-05-28 14:16:02 +0200214
215 if (!child.isTransparent()) {
216 // Only update the previous values if we are not transparent,
217 // otherwise we would clip to a transparent view.
Jorim Jaggi2e34ec32014-07-01 03:17:05 +0200218 previousNotificationStart = newYTranslation + state.clipTopAmount * state.scale;
Selim Cinek708a6c12014-05-28 14:16:02 +0200219 previousNotificationEnd = newNotificationEnd;
220 previousNotificationIsSwiped = child.getTranslationX() != 0;
221 }
222 }
223 }
224
225 /**
226 * Updates the shadow outline and the clipping for a view.
227 *
228 * @param state the viewState to update
229 * @param realHeight the currently applied height of the view
230 * @param clipHeight the desired clip height, the rest of the view will be clipped from the top
231 * @param backgroundHeight the desired background height. The shadows of the view will be
232 * based on this height and the content will be clipped from the top
233 */
Jorim Jaggi2e34ec32014-07-01 03:17:05 +0200234 private void updateChildClippingAndBackground(StackScrollState.ViewState state,
235 float realHeight, float clipHeight, float backgroundHeight) {
Selim Cinek708a6c12014-05-28 14:16:02 +0200236 if (realHeight > clipHeight) {
Jorim Jaggi2e34ec32014-07-01 03:17:05 +0200237 // Rather overlap than create a hole.
238 state.topOverLap = (int) Math.floor((realHeight - clipHeight) / state.scale);
Selim Cinek708a6c12014-05-28 14:16:02 +0200239 } else {
240 state.topOverLap = 0;
241 }
242 if (realHeight > backgroundHeight) {
Jorim Jaggi2e34ec32014-07-01 03:17:05 +0200243 // Rather overlap than create a hole.
244 state.clipTopAmount = (int) Math.floor((realHeight - backgroundHeight) / state.scale);
Selim Cinek708a6c12014-05-28 14:16:02 +0200245 } else {
246 state.clipTopAmount = 0;
247 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200248 }
249
250 /**
251 * Updates the dimmed and activated states of the children.
252 */
253 private void updateDimmedActivated(AmbientState ambientState, StackScrollState resultState,
254 StackScrollAlgorithmState algorithmState) {
255 boolean dimmed = ambientState.isDimmed();
John Spurlockbf370992014-06-17 13:58:31 -0400256 boolean dark = ambientState.isDark();
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200257 View activatedChild = ambientState.getActivatedChild();
258 int childCount = algorithmState.visibleChildren.size();
259 for (int i = 0; i < childCount; i++) {
260 View child = algorithmState.visibleChildren.get(i);
261 StackScrollState.ViewState childViewState = resultState.getViewStateForView(child);
262 childViewState.dimmed = dimmed;
John Spurlockbf370992014-06-17 13:58:31 -0400263 childViewState.dark = dark;
Selim Cinekb89de4e2014-06-10 10:47:05 +0200264 boolean isActivatedChild = activatedChild == child;
265 childViewState.scale = !dimmed || isActivatedChild
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200266 ? 1.0f
267 : DIMMED_SCALE;
Selim Cinekb89de4e2014-06-10 10:47:05 +0200268 if (dimmed && activatedChild != null) {
269 if (!isActivatedChild) {
270 childViewState.alpha *= ACTIVATED_INVERSE_ALPHA;
271 } else {
272 childViewState.zTranslation += 2.0f * mZDistanceBetweenElements;
273 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200274 }
275 }
Selim Cinekeb973562014-05-02 17:07:49 +0200276 }
277
278 /**
279 * Handle the special state when views are being dragged
280 */
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200281 private void handleDraggedViews(AmbientState ambientState, StackScrollState resultState,
Selim Cinekeb973562014-05-02 17:07:49 +0200282 StackScrollAlgorithmState algorithmState) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200283 ArrayList<View> draggedViews = ambientState.getDraggedViews();
284 for (View draggedView : draggedViews) {
Selim Cinekeb973562014-05-02 17:07:49 +0200285 int childIndex = algorithmState.visibleChildren.indexOf(draggedView);
286 if (childIndex >= 0 && childIndex < algorithmState.visibleChildren.size() - 1) {
287 View nextChild = algorithmState.visibleChildren.get(childIndex + 1);
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200288 if (!draggedViews.contains(nextChild)) {
Selim Cinekeb973562014-05-02 17:07:49 +0200289 // only if the view is not dragged itself we modify its state to be fully
290 // visible
291 StackScrollState.ViewState viewState = resultState.getViewStateForView(
292 nextChild);
293 // The child below the dragged one must be fully visible
294 viewState.alpha = 1;
295 }
296
297 // Lets set the alpha to the one it currently has, as its currently being dragged
298 StackScrollState.ViewState viewState = resultState.getViewStateForView(draggedView);
299 // The dragged child should keep the set alpha
300 viewState.alpha = draggedView.getAlpha();
301 }
302 }
Selim Cinek343e6e22014-04-11 21:23:30 +0200303 }
Selim Cinek67b22602014-03-10 15:40:16 +0100304
Selim Cinek343e6e22014-04-11 21:23:30 +0200305 /**
Jorim Jaggid4a57442014-04-10 02:45:55 +0200306 * Update the visible children on the state.
307 */
308 private void updateVisibleChildren(StackScrollState resultState,
309 StackScrollAlgorithmState state) {
310 ViewGroup hostView = resultState.getHostView();
311 int childCount = hostView.getChildCount();
312 state.visibleChildren.clear();
313 state.visibleChildren.ensureCapacity(childCount);
314 for (int i = 0; i < childCount; i++) {
Jorim Jaggibe565df2014-04-28 17:51:23 +0200315 ExpandableView v = (ExpandableView) hostView.getChildAt(i);
Jorim Jaggid4a57442014-04-10 02:45:55 +0200316 if (v.getVisibility() != View.GONE) {
Selim Cinek8efa6dd2014-05-19 16:27:37 +0200317 StackScrollState.ViewState viewState = resultState.getViewStateForView(v);
318 viewState.notGoneIndex = state.visibleChildren.size();
Jorim Jaggid4a57442014-04-10 02:45:55 +0200319 state.visibleChildren.add(v);
320 }
321 }
322 }
323
324 /**
Selim Cinek67b22602014-03-10 15:40:16 +0100325 * Determine the positions for the views. This is the main part of the algorithm.
326 *
327 * @param resultState The result state to update if a change to the properties of a child occurs
328 * @param algorithmState The state in which the current pass of the algorithm is currently in
Selim Cinek67b22602014-03-10 15:40:16 +0100329 */
330 private void updatePositionsForState(StackScrollState resultState,
331 StackScrollAlgorithmState algorithmState) {
Selim Cinek67b22602014-03-10 15:40:16 +0100332
Selim Cinek1685e632014-04-08 02:27:49 +0200333 // The starting position of the bottom stack peek
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200334 float bottomPeekStart = mInnerHeight - mBottomStackPeekSize;
Selim Cinek1685e632014-04-08 02:27:49 +0200335
Selim Cinek67b22602014-03-10 15:40:16 +0100336 // The position where the bottom stack starts.
Selim Cinek34c0a8d2014-05-12 00:01:43 +0200337 float bottomStackStart = bottomPeekStart - mBottomStackSlowDownLength;
Selim Cinek67b22602014-03-10 15:40:16 +0100338
339 // The y coordinate of the current child.
340 float currentYPosition = 0.0f;
341
342 // How far in is the element currently transitioning into the bottom stack.
343 float yPositionInScrollView = 0.0f;
344
Jorim Jaggid4a57442014-04-10 02:45:55 +0200345 int childCount = algorithmState.visibleChildren.size();
Selim Cinek67b22602014-03-10 15:40:16 +0100346 int numberOfElementsCompletelyIn = (int) algorithmState.itemsInTopStack;
347 for (int i = 0; i < childCount; i++) {
Jorim Jaggibe565df2014-04-28 17:51:23 +0200348 ExpandableView child = algorithmState.visibleChildren.get(i);
Selim Cinek67b22602014-03-10 15:40:16 +0100349 StackScrollState.ViewState childViewState = resultState.getViewStateForView(child);
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200350 childViewState.location = StackScrollState.ViewState.LOCATION_UNKNOWN;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200351 int childHeight = getMaxAllowedChildHeight(child);
Selim Cinek67b22602014-03-10 15:40:16 +0100352 float yPositionInScrollViewAfterElement = yPositionInScrollView
353 + childHeight
354 + mPaddingBetweenElements;
Selim Cinek343e6e22014-04-11 21:23:30 +0200355 float scrollOffset = yPositionInScrollView - algorithmState.scrollY + mCollapsedSize;
356
357 if (i == algorithmState.lastTopStackIndex + 1) {
358 // Normally the position of this child is the position in the regular scrollview,
359 // but if the two stacks are very close to each other,
360 // then have have to push it even more upwards to the position of the bottom
361 // stack start.
362 currentYPosition = Math.min(scrollOffset, bottomStackStart);
363 }
364 childViewState.yTranslation = currentYPosition;
365
366 // The y position after this element
367 float nextYPosition = currentYPosition + childHeight +
368 mPaddingBetweenElements;
369
370 if (i <= algorithmState.lastTopStackIndex) {
Selim Cinek67b22602014-03-10 15:40:16 +0100371 // Case 1:
372 // We are in the top Stack
Selim Cinek343e6e22014-04-11 21:23:30 +0200373 updateStateForTopStackChild(algorithmState,
374 numberOfElementsCompletelyIn, i, childHeight, childViewState, scrollOffset);
375 clampYTranslation(childViewState, childHeight);
376 // check if we are overlapping with the bottom stack
377 if (childViewState.yTranslation + childHeight + mPaddingBetweenElements
Selim Cinek4a1ac842014-05-01 15:51:58 +0200378 >= bottomStackStart && !mIsExpansionChanging && i != 0) {
Selim Cinek343e6e22014-04-11 21:23:30 +0200379 // TODO: handle overlapping sizes with end stack better
380 // we just collapse this element
381 childViewState.height = mCollapsedSize;
382 }
383 } else if (nextYPosition >= bottomStackStart) {
Selim Cinek67b22602014-03-10 15:40:16 +0100384 // Case 2:
Selim Cinek343e6e22014-04-11 21:23:30 +0200385 // We are in the bottom stack.
386 if (currentYPosition >= bottomStackStart) {
Selim Cinek67b22602014-03-10 15:40:16 +0100387 // According to the regular scroll view we are fully translated out of the
388 // bottom of the screen so we are fully in the bottom stack
Selim Cinek343e6e22014-04-11 21:23:30 +0200389 updateStateForChildFullyInBottomStack(algorithmState,
390 bottomStackStart, childViewState, childHeight);
Selim Cinek67b22602014-03-10 15:40:16 +0100391 } else {
Selim Cinek67b22602014-03-10 15:40:16 +0100392 // According to the regular scroll view we are currently translating out of /
393 // into the bottom of the screen
Selim Cinek343e6e22014-04-11 21:23:30 +0200394 updateStateForChildTransitioningInBottom(algorithmState,
395 bottomStackStart, bottomPeekStart, currentYPosition,
396 childViewState, childHeight);
Selim Cinek67b22602014-03-10 15:40:16 +0100397 }
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200398 } else {
Selim Cinek343e6e22014-04-11 21:23:30 +0200399 // Case 3:
400 // We are in the regular scroll area.
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200401 childViewState.location = StackScrollState.ViewState.LOCATION_MAIN_AREA;
Selim Cinek343e6e22014-04-11 21:23:30 +0200402 clampYTranslation(childViewState, childHeight);
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200403 }
Selim Cinek343e6e22014-04-11 21:23:30 +0200404
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200405 // The first card is always rendered.
406 if (i == 0) {
407 childViewState.alpha = 1.0f;
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200408 childViewState.yTranslation = Math.max(mCollapsedSize - algorithmState.scrollY, 0);
Selim Cinekd83771e2014-07-04 16:45:31 +0200409 if (childViewState.yTranslation + childViewState.height
410 > bottomPeekStart - mCollapseSecondCardPadding) {
Selim Cinek4fe3e472014-07-03 16:32:54 +0200411 childViewState.height = (int) Math.max(
Selim Cinekd83771e2014-07-04 16:45:31 +0200412 bottomPeekStart - mCollapseSecondCardPadding
413 - childViewState.yTranslation, mCollapsedSize);
Selim Cinek4fe3e472014-07-03 16:32:54 +0200414 }
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200415 childViewState.location = StackScrollState.ViewState.LOCATION_FIRST_CARD;
416 }
417 if (childViewState.location == StackScrollState.ViewState.LOCATION_UNKNOWN) {
418 Log.wtf(LOG_TAG, "Failed to assign location for child " + i);
Selim Cinek67b22602014-03-10 15:40:16 +0100419 }
Selim Cinek343e6e22014-04-11 21:23:30 +0200420 currentYPosition = childViewState.yTranslation + childHeight + mPaddingBetweenElements;
Selim Cinek67b22602014-03-10 15:40:16 +0100421 yPositionInScrollView = yPositionInScrollViewAfterElement;
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200422
423 childViewState.yTranslation += mTopPadding;
Selim Cinek67b22602014-03-10 15:40:16 +0100424 }
425 }
426
Selim Cinek1685e632014-04-08 02:27:49 +0200427 /**
Selim Cinek343e6e22014-04-11 21:23:30 +0200428 * Clamp the yTranslation both up and down to valid positions.
Selim Cinek1685e632014-04-08 02:27:49 +0200429 *
Selim Cinek1685e632014-04-08 02:27:49 +0200430 * @param childViewState the view state of the child
Selim Cinek343e6e22014-04-11 21:23:30 +0200431 * @param childHeight the height of this child
Selim Cinek1685e632014-04-08 02:27:49 +0200432 */
Selim Cinek343e6e22014-04-11 21:23:30 +0200433 private void clampYTranslation(StackScrollState.ViewState childViewState, int childHeight) {
434 clampPositionToBottomStackStart(childViewState, childHeight);
435 clampPositionToTopStackEnd(childViewState, childHeight);
436 }
437
438 /**
439 * Clamp the yTranslation of the child down such that its end is at most on the beginning of
440 * the bottom stack.
441 *
442 * @param childViewState the view state of the child
443 * @param childHeight the height of this child
444 */
445 private void clampPositionToBottomStackStart(StackScrollState.ViewState childViewState,
446 int childHeight) {
447 childViewState.yTranslation = Math.min(childViewState.yTranslation,
Selim Cinekd83771e2014-07-04 16:45:31 +0200448 mInnerHeight - mBottomStackPeekSize - mCollapseSecondCardPadding - childHeight);
Selim Cinek343e6e22014-04-11 21:23:30 +0200449 }
450
451 /**
452 * Clamp the yTranslation of the child up such that its end is at lest on the end of the top
Jorim Jaggibe565df2014-04-28 17:51:23 +0200453 * stack.get
Selim Cinek343e6e22014-04-11 21:23:30 +0200454 *
455 * @param childViewState the view state of the child
456 * @param childHeight the height of this child
457 */
458 private void clampPositionToTopStackEnd(StackScrollState.ViewState childViewState,
459 int childHeight) {
460 childViewState.yTranslation = Math.max(childViewState.yTranslation,
461 mCollapsedSize - childHeight);
Selim Cinek1685e632014-04-08 02:27:49 +0200462 }
463
464 private int getMaxAllowedChildHeight(View child) {
465 if (child instanceof ExpandableNotificationRow) {
466 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
Jorim Jaggi9cbadd32014-05-01 20:18:31 +0200467 return row.getIntrinsicHeight();
Jorim Jaggibe565df2014-04-28 17:51:23 +0200468 } else if (child instanceof ExpandableView) {
469 ExpandableView expandableView = (ExpandableView) child;
470 return expandableView.getActualHeight();
Selim Cinek1685e632014-04-08 02:27:49 +0200471 }
Jorim Jaggibe565df2014-04-28 17:51:23 +0200472 return child == null? mCollapsedSize : child.getHeight();
Selim Cinek1685e632014-04-08 02:27:49 +0200473 }
474
Selim Cinek343e6e22014-04-11 21:23:30 +0200475 private void updateStateForChildTransitioningInBottom(StackScrollAlgorithmState algorithmState,
476 float transitioningPositionStart, float bottomPeakStart, float currentYPosition,
477 StackScrollState.ViewState childViewState, int childHeight) {
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200478
Selim Cinek343e6e22014-04-11 21:23:30 +0200479 // This is the transitioning element on top of bottom stack, calculate how far we are in.
480 algorithmState.partialInBottom = 1.0f - (
481 (transitioningPositionStart - currentYPosition) / (childHeight +
482 mPaddingBetweenElements));
483
484 // the offset starting at the transitionPosition of the bottom stack
485 float offset = mBottomStackIndentationFunctor.getValue(algorithmState.partialInBottom);
486 algorithmState.itemsInBottomStack += algorithmState.partialInBottom;
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200487 childViewState.yTranslation = transitioningPositionStart + offset - childHeight
488 - mPaddingBetweenElements;
Selim Cinek34c0a8d2014-05-12 00:01:43 +0200489
Selim Cinek343e6e22014-04-11 21:23:30 +0200490 // We want at least to be at the end of the top stack when collapsing
491 clampPositionToTopStackEnd(childViewState, childHeight);
492 childViewState.location = StackScrollState.ViewState.LOCATION_MAIN_AREA;
Selim Cinek67b22602014-03-10 15:40:16 +0100493 }
494
Selim Cinek343e6e22014-04-11 21:23:30 +0200495 private void updateStateForChildFullyInBottomStack(StackScrollAlgorithmState algorithmState,
Selim Cinek67b22602014-03-10 15:40:16 +0100496 float transitioningPositionStart, StackScrollState.ViewState childViewState,
497 int childHeight) {
498
Selim Cinek343e6e22014-04-11 21:23:30 +0200499 float currentYPosition;
Selim Cinek67b22602014-03-10 15:40:16 +0100500 algorithmState.itemsInBottomStack += 1.0f;
501 if (algorithmState.itemsInBottomStack < MAX_ITEMS_IN_BOTTOM_STACK) {
502 // We are visually entering the bottom stack
Selim Cinek343e6e22014-04-11 21:23:30 +0200503 currentYPosition = transitioningPositionStart
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200504 + mBottomStackIndentationFunctor.getValue(algorithmState.itemsInBottomStack)
505 - mPaddingBetweenElements;
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200506 childViewState.location = StackScrollState.ViewState.LOCATION_BOTTOM_STACK_PEEKING;
Selim Cinek67b22602014-03-10 15:40:16 +0100507 } else {
508 // we are fully inside the stack
509 if (algorithmState.itemsInBottomStack > MAX_ITEMS_IN_BOTTOM_STACK + 2) {
510 childViewState.alpha = 0.0f;
511 } else if (algorithmState.itemsInBottomStack
512 > MAX_ITEMS_IN_BOTTOM_STACK + 1) {
513 childViewState.alpha = 1.0f - algorithmState.partialInBottom;
514 }
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200515 childViewState.location = StackScrollState.ViewState.LOCATION_BOTTOM_STACK_HIDDEN;
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200516 currentYPosition = mInnerHeight;
Selim Cinek67b22602014-03-10 15:40:16 +0100517 }
Selim Cinek343e6e22014-04-11 21:23:30 +0200518 childViewState.yTranslation = currentYPosition - childHeight;
519 clampPositionToTopStackEnd(childViewState, childHeight);
Selim Cinek67b22602014-03-10 15:40:16 +0100520 }
521
Selim Cinek343e6e22014-04-11 21:23:30 +0200522 private void updateStateForTopStackChild(StackScrollAlgorithmState algorithmState,
523 int numberOfElementsCompletelyIn, int i, int childHeight,
524 StackScrollState.ViewState childViewState, float scrollOffset) {
Selim Cinek67b22602014-03-10 15:40:16 +0100525
Selim Cinek67b22602014-03-10 15:40:16 +0100526
527 // First we calculate the index relative to the current stack window of size at most
528 // {@link #MAX_ITEMS_IN_TOP_STACK}
Selim Cinek343e6e22014-04-11 21:23:30 +0200529 int paddedIndex = i - 1
Selim Cinek67b22602014-03-10 15:40:16 +0100530 - Math.max(numberOfElementsCompletelyIn - MAX_ITEMS_IN_TOP_STACK, 0);
531 if (paddedIndex >= 0) {
Selim Cinek343e6e22014-04-11 21:23:30 +0200532
Selim Cinek67b22602014-03-10 15:40:16 +0100533 // We are currently visually entering the top stack
Selim Cinekad3e5af2014-07-04 12:24:11 +0200534 float distanceToStack = (childHeight + mPaddingBetweenElements)
535 - algorithmState.scrolledPixelsTop;
536 if (i == algorithmState.lastTopStackIndex
537 && distanceToStack > (mTopStackTotalSize + mPaddingBetweenElements)) {
Selim Cinek343e6e22014-04-11 21:23:30 +0200538
539 // Child is currently translating into stack but not yet inside slow down zone.
540 // Handle it like the regular scrollview.
541 childViewState.yTranslation = scrollOffset;
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200542 } else {
Selim Cinek343e6e22014-04-11 21:23:30 +0200543 // Apply stacking logic.
544 float numItemsBefore;
545 if (i == algorithmState.lastTopStackIndex) {
Selim Cinekad3e5af2014-07-04 12:24:11 +0200546 numItemsBefore = 1.0f
547 - (distanceToStack / (mTopStackTotalSize + mPaddingBetweenElements));
Selim Cinek343e6e22014-04-11 21:23:30 +0200548 } else {
549 numItemsBefore = algorithmState.itemsInTopStack - i;
550 }
551 // The end position of the current child
Selim Cinekad3e5af2014-07-04 12:24:11 +0200552 float currentChildEndY = mCollapsedSize + mTopStackTotalSize
553 - mTopStackIndentationFunctor.getValue(numItemsBefore);
Selim Cinek343e6e22014-04-11 21:23:30 +0200554 childViewState.yTranslation = currentChildEndY - childHeight;
Selim Cinek67b22602014-03-10 15:40:16 +0100555 }
Selim Cinek343e6e22014-04-11 21:23:30 +0200556 childViewState.location = StackScrollState.ViewState.LOCATION_TOP_STACK_PEEKING;
Selim Cinek67b22602014-03-10 15:40:16 +0100557 } else {
Selim Cinek343e6e22014-04-11 21:23:30 +0200558 if (paddedIndex == -1) {
559 childViewState.alpha = 1.0f - algorithmState.partialInTop;
560 } else {
561 // We are hidden behind the top card and faded out, so we can hide ourselves.
562 childViewState.alpha = 0.0f;
563 }
564 childViewState.yTranslation = mCollapsedSize - childHeight;
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200565 childViewState.location = StackScrollState.ViewState.LOCATION_TOP_STACK_HIDDEN;
Selim Cinek67b22602014-03-10 15:40:16 +0100566 }
Selim Cinek343e6e22014-04-11 21:23:30 +0200567
568
Selim Cinek67b22602014-03-10 15:40:16 +0100569 }
570
571 /**
572 * Find the number of items in the top stack and update the result state if needed.
573 *
574 * @param resultState The result state to update if a height change of an child occurs
575 * @param algorithmState The state in which the current pass of the algorithm is currently in
Selim Cinek67b22602014-03-10 15:40:16 +0100576 */
577 private void findNumberOfItemsInTopStackAndUpdateState(StackScrollState resultState,
578 StackScrollAlgorithmState algorithmState) {
579
580 // The y Position if the element would be in a regular scrollView
581 float yPositionInScrollView = 0.0f;
Jorim Jaggid4a57442014-04-10 02:45:55 +0200582 int childCount = algorithmState.visibleChildren.size();
Selim Cinek67b22602014-03-10 15:40:16 +0100583
584 // find the number of elements in the top stack.
585 for (int i = 0; i < childCount; i++) {
Jorim Jaggibe565df2014-04-28 17:51:23 +0200586 ExpandableView child = algorithmState.visibleChildren.get(i);
Selim Cinek67b22602014-03-10 15:40:16 +0100587 StackScrollState.ViewState childViewState = resultState.getViewStateForView(child);
Jorim Jaggibe565df2014-04-28 17:51:23 +0200588 int childHeight = getMaxAllowedChildHeight(child);
Selim Cinek67b22602014-03-10 15:40:16 +0100589 float yPositionInScrollViewAfterElement = yPositionInScrollView
590 + childHeight
591 + mPaddingBetweenElements;
592 if (yPositionInScrollView < algorithmState.scrollY) {
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200593 if (i == 0 && algorithmState.scrollY <= mCollapsedSize) {
Selim Cinek343e6e22014-04-11 21:23:30 +0200594
595 // The starting position of the bottom stack peek
Selim Cinekd83771e2014-07-04 16:45:31 +0200596 int bottomPeekStart = mInnerHeight - mBottomStackPeekSize -
597 mCollapseSecondCardPadding;
Selim Cinek343e6e22014-04-11 21:23:30 +0200598 // Collapse and expand the first child while the shade is being expanded
599 float maxHeight = mIsExpansionChanging && child == mFirstChildWhileExpanding
600 ? mFirstChildMaxHeight
601 : childHeight;
602 childViewState.height = (int) Math.max(Math.min(bottomPeekStart, maxHeight),
603 mCollapsedSize);
604 algorithmState.itemsInTopStack = 1.0f;
605
606 } else if (yPositionInScrollViewAfterElement < algorithmState.scrollY) {
Selim Cinek67b22602014-03-10 15:40:16 +0100607 // According to the regular scroll view we are fully off screen
608 algorithmState.itemsInTopStack += 1.0f;
Selim Cinek343e6e22014-04-11 21:23:30 +0200609 if (i == 0) {
Selim Cinek67b22602014-03-10 15:40:16 +0100610 childViewState.height = mCollapsedSize;
611 }
612 } else {
613 // According to the regular scroll view we are partially off screen
Selim Cinek343e6e22014-04-11 21:23:30 +0200614
Selim Cinek67b22602014-03-10 15:40:16 +0100615 // How much did we scroll into this child
Selim Cinekad3e5af2014-07-04 12:24:11 +0200616 algorithmState.scrolledPixelsTop = algorithmState.scrollY
617 - yPositionInScrollView;
Selim Cinek343e6e22014-04-11 21:23:30 +0200618 algorithmState.partialInTop = (algorithmState.scrolledPixelsTop) / (childHeight
Selim Cinek67b22602014-03-10 15:40:16 +0100619 + mPaddingBetweenElements);
620
621 // Our element can be expanded, so this can get negative
622 algorithmState.partialInTop = Math.max(0.0f, algorithmState.partialInTop);
623 algorithmState.itemsInTopStack += algorithmState.partialInTop;
Selim Cinekad3e5af2014-07-04 12:24:11 +0200624
Selim Cinek343e6e22014-04-11 21:23:30 +0200625 if (i == 0) {
Selim Cinekad3e5af2014-07-04 12:24:11 +0200626 // If it is expanded we have to collapse it to a new size
627 float newSize = yPositionInScrollViewAfterElement
628 - mPaddingBetweenElements
629 - algorithmState.scrollY + mCollapsedSize;
630 newSize = Math.max(mCollapsedSize, newSize);
Selim Cinek4e456be2014-06-12 18:09:43 +0200631 algorithmState.itemsInTopStack = 1.0f;
Selim Cinek67b22602014-03-10 15:40:16 +0100632 childViewState.height = (int) newSize;
Selim Cinek67b22602014-03-10 15:40:16 +0100633 }
Selim Cinek343e6e22014-04-11 21:23:30 +0200634 algorithmState.lastTopStackIndex = i;
635 break;
Selim Cinek67b22602014-03-10 15:40:16 +0100636 }
637 } else {
Selim Cinek343e6e22014-04-11 21:23:30 +0200638 algorithmState.lastTopStackIndex = i - 1;
Selim Cinek67b22602014-03-10 15:40:16 +0100639 // We are already past the stack so we can end the loop
640 break;
641 }
642 yPositionInScrollView = yPositionInScrollViewAfterElement;
643 }
644 }
645
646 /**
647 * Calculate the Z positions for all children based on the number of items in both stacks and
648 * save it in the resultState
649 *
650 * @param resultState The result state to update the zTranslation values
651 * @param algorithmState The state in which the current pass of the algorithm is currently in
652 */
653 private void updateZValuesForState(StackScrollState resultState,
654 StackScrollAlgorithmState algorithmState) {
Jorim Jaggid4a57442014-04-10 02:45:55 +0200655 int childCount = algorithmState.visibleChildren.size();
Selim Cinek67b22602014-03-10 15:40:16 +0100656 for (int i = 0; i < childCount; i++) {
Jorim Jaggid4a57442014-04-10 02:45:55 +0200657 View child = algorithmState.visibleChildren.get(i);
Selim Cinek67b22602014-03-10 15:40:16 +0100658 StackScrollState.ViewState childViewState = resultState.getViewStateForView(child);
659 if (i < algorithmState.itemsInTopStack) {
660 float stackIndex = algorithmState.itemsInTopStack - i;
661 stackIndex = Math.min(stackIndex, MAX_ITEMS_IN_TOP_STACK + 2);
Selim Cinek4e456be2014-06-12 18:09:43 +0200662 if (i == 0 && algorithmState.itemsInTopStack < 2.0f) {
663
664 // We only have the top item and an additional item in the top stack,
665 // Interpolate the index from 0 to 2 while the second item is
666 // translating in.
667 stackIndex -= 1.0f;
668 if (algorithmState.scrollY > mCollapsedSize) {
669
670 // Since there is a shadow treshhold, we cant just interpolate from 0 to
671 // 2 but we interpolate from 0.1f to 2.0f when scrolled in. The jump in
672 // height will not be noticable since we have padding in between.
673 stackIndex = 0.1f + stackIndex * 1.9f;
674 }
675 }
Selim Cinek67b22602014-03-10 15:40:16 +0100676 childViewState.zTranslation = mZBasicHeight
677 + stackIndex * mZDistanceBetweenElements;
678 } else if (i > (childCount - 1 - algorithmState.itemsInBottomStack)) {
679 float numItemsAbove = i - (childCount - 1 - algorithmState.itemsInBottomStack);
680 float translationZ = mZBasicHeight
681 - numItemsAbove * mZDistanceBetweenElements;
682 childViewState.zTranslation = translationZ;
683 } else {
684 childViewState.zTranslation = mZBasicHeight;
685 }
686 }
687 }
688
Selim Cinek343e6e22014-04-11 21:23:30 +0200689 public void setLayoutHeight(int layoutHeight) {
Selim Cinek67b22602014-03-10 15:40:16 +0100690 this.mLayoutHeight = layoutHeight;
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200691 updateInnerHeight();
692 }
693
694 public void setTopPadding(int topPadding) {
695 mTopPadding = topPadding;
696 updateInnerHeight();
697 }
698
699 private void updateInnerHeight() {
700 mInnerHeight = mLayoutHeight - mTopPadding;
Selim Cinek67b22602014-03-10 15:40:16 +0100701 }
702
Selim Cinek1685e632014-04-08 02:27:49 +0200703 public void onExpansionStarted(StackScrollState currentState) {
704 mIsExpansionChanging = true;
705 mExpandedOnStart = mIsExpanded;
706 ViewGroup hostView = currentState.getHostView();
707 updateFirstChildHeightWhileExpanding(hostView);
708 }
709
710 private void updateFirstChildHeightWhileExpanding(ViewGroup hostView) {
Jorim Jaggibe565df2014-04-28 17:51:23 +0200711 mFirstChildWhileExpanding = (ExpandableView) findFirstVisibleChild(hostView);
Jorim Jaggi9f347ae2014-04-11 00:47:18 +0200712 if (mFirstChildWhileExpanding != null) {
Selim Cinek1685e632014-04-08 02:27:49 +0200713 if (mExpandedOnStart) {
714
715 // We are collapsing the shade, so the first child can get as most as high as the
716 // current height.
Jorim Jaggibe565df2014-04-28 17:51:23 +0200717 mFirstChildMaxHeight = mFirstChildWhileExpanding.getActualHeight();
Selim Cinek1685e632014-04-08 02:27:49 +0200718 } else {
719
720 // We are expanding the shade, expand it to its full height.
Selim Cinek7d447722014-06-10 15:51:59 +0200721 if (!isMaxSizeInitialized(mFirstChildWhileExpanding)) {
Selim Cinekb6e0e122014-04-23 17:24:37 +0200722
723 // This child was not layouted yet, wait for a layout pass
724 mFirstChildWhileExpanding
725 .addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
726 @Override
727 public void onLayoutChange(View v, int left, int top, int right,
728 int bottom, int oldLeft, int oldTop, int oldRight,
729 int oldBottom) {
Selim Cinek2ba5f1f2014-04-28 20:23:30 +0200730 if (mFirstChildWhileExpanding != null) {
731 mFirstChildMaxHeight = getMaxAllowedChildHeight(
732 mFirstChildWhileExpanding);
733 } else {
734 mFirstChildMaxHeight = 0;
735 }
736 v.removeOnLayoutChangeListener(this);
Selim Cinekb6e0e122014-04-23 17:24:37 +0200737 }
738 });
739 } else {
740 mFirstChildMaxHeight = getMaxAllowedChildHeight(mFirstChildWhileExpanding);
741 }
Selim Cinek1685e632014-04-08 02:27:49 +0200742 }
743 } else {
Selim Cinek1685e632014-04-08 02:27:49 +0200744 mFirstChildMaxHeight = 0;
745 }
746 }
747
Selim Cinek7d447722014-06-10 15:51:59 +0200748 private boolean isMaxSizeInitialized(ExpandableView child) {
749 if (child instanceof ExpandableNotificationRow) {
750 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
751 return row.isShowingLayoutLayouted();
752 }
753 return child == null || child.getWidth() != 0;
754 }
755
Jorim Jaggi9f347ae2014-04-11 00:47:18 +0200756 private View findFirstVisibleChild(ViewGroup container) {
757 int childCount = container.getChildCount();
758 for (int i = 0; i < childCount; i++) {
759 View child = container.getChildAt(i);
760 if (child.getVisibility() != View.GONE) {
761 return child;
762 }
763 }
764 return null;
765 }
766
Selim Cinek1685e632014-04-08 02:27:49 +0200767 public void onExpansionStopped() {
768 mIsExpansionChanging = false;
769 mFirstChildWhileExpanding = null;
770 }
771
772 public void setIsExpanded(boolean isExpanded) {
773 this.mIsExpanded = isExpanded;
774 }
775
776 public void notifyChildrenChanged(ViewGroup hostView) {
777 if (mIsExpansionChanging) {
778 updateFirstChildHeightWhileExpanding(hostView);
779 }
780 }
781
Selim Cinek34c0a8d2014-05-12 00:01:43 +0200782 public void setDimmed(boolean dimmed) {
783 updatePadding(dimmed);
784 }
785
Selim Cinek67b22602014-03-10 15:40:16 +0100786 class StackScrollAlgorithmState {
787
788 /**
789 * The scroll position of the algorithm
790 */
791 public int scrollY;
792
793 /**
794 * The quantity of items which are in the top stack.
795 */
796 public float itemsInTopStack;
797
798 /**
799 * how far in is the element currently transitioning into the top stack
800 */
801 public float partialInTop;
802
803 /**
Selim Cinek343e6e22014-04-11 21:23:30 +0200804 * The number of pixels the last child in the top stack has scrolled in to the stack
805 */
806 public float scrolledPixelsTop;
807
808 /**
Selim Cinek67b22602014-03-10 15:40:16 +0100809 * The last item index which is in the top stack.
Selim Cinek67b22602014-03-10 15:40:16 +0100810 */
811 public int lastTopStackIndex;
812
813 /**
814 * The quantity of items which are in the bottom stack.
815 */
816 public float itemsInBottomStack;
817
818 /**
819 * how far in is the element currently transitioning into the bottom stack
820 */
821 public float partialInBottom;
Jorim Jaggid4a57442014-04-10 02:45:55 +0200822
823 /**
824 * The children from the host view which are not gone.
825 */
Jorim Jaggibe565df2014-04-28 17:51:23 +0200826 public final ArrayList<ExpandableView> visibleChildren = new ArrayList<ExpandableView>();
Selim Cinek67b22602014-03-10 15:40:16 +0100827 }
828
829}