blob: fe2733b9a437a122698620627b462d571378b9f7 [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;
Jorim Jaggi362dd6d2014-07-09 19:04:07 +020044 public static final float DIMMED_SCALE = 0.95f;
Jorim Jaggid552d9d2014-05-07 19:41:13 +020045
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);
Selim Cinek3107cfa2014-07-22 15:24:29 +0200174
175 // The speed bump can also be gone, so equality needs to be taken when comparing
176 // indices.
177 childViewState.belowSpeedBump = speedBumpIndex != -1 && i >= speedBumpIndex;
Selim Cinek3d2b94bf2014-07-02 22:12:47 +0200178 }
Selim Cinekf54090e2014-06-17 17:24:51 -0700179 }
180
181 private void updateScrimAmount(StackScrollState resultState,
182 StackScrollAlgorithmState algorithmState, float scrimAmount) {
183 int childCount = algorithmState.visibleChildren.size();
184 for (int i = 0; i < childCount; i++) {
185 View child = algorithmState.visibleChildren.get(i);
186 StackScrollState.ViewState childViewState = resultState.getViewStateForView(child);
187 childViewState.scrimAmount = scrimAmount;
188 }
Selim Cinek708a6c12014-05-28 14:16:02 +0200189 }
190
191 private void updateClipping(StackScrollState resultState,
192 StackScrollAlgorithmState algorithmState) {
193 float previousNotificationEnd = 0;
194 float previousNotificationStart = 0;
195 boolean previousNotificationIsSwiped = false;
196 int childCount = algorithmState.visibleChildren.size();
197 for (int i = 0; i < childCount; i++) {
198 ExpandableView child = algorithmState.visibleChildren.get(i);
199 StackScrollState.ViewState state = resultState.getViewStateForView(child);
Jorim Jaggi2e34ec32014-07-01 03:17:05 +0200200 float newYTranslation = state.yTranslation + state.height * (1f - state.scale) / 2f;
201 float newHeight = state.height * state.scale;
Selim Cinek708a6c12014-05-28 14:16:02 +0200202 // apply clipping and shadow
203 float newNotificationEnd = newYTranslation + newHeight;
204
205 // In the unlocked shade we have to clip a little bit higher because of the rounded
206 // corners of the notifications.
Jorim Jaggi2e34ec32014-07-01 03:17:05 +0200207 float clippingCorrection = state.dimmed ? 0 : mRoundedRectCornerRadius * state.scale;
Selim Cinek708a6c12014-05-28 14:16:02 +0200208
209 // When the previous notification is swiped, we don't clip the content to the
210 // bottom of it.
211 float clipHeight = previousNotificationIsSwiped
212 ? newHeight
213 : newNotificationEnd - (previousNotificationEnd - clippingCorrection);
214
215 updateChildClippingAndBackground(state, newHeight, clipHeight,
Jorim Jaggi2e34ec32014-07-01 03:17:05 +0200216 newHeight - (previousNotificationStart - newYTranslation));
Selim Cinek708a6c12014-05-28 14:16:02 +0200217
218 if (!child.isTransparent()) {
219 // Only update the previous values if we are not transparent,
220 // otherwise we would clip to a transparent view.
Jorim Jaggi2e34ec32014-07-01 03:17:05 +0200221 previousNotificationStart = newYTranslation + state.clipTopAmount * state.scale;
Selim Cinek708a6c12014-05-28 14:16:02 +0200222 previousNotificationEnd = newNotificationEnd;
223 previousNotificationIsSwiped = child.getTranslationX() != 0;
224 }
225 }
226 }
227
228 /**
229 * Updates the shadow outline and the clipping for a view.
230 *
231 * @param state the viewState to update
232 * @param realHeight the currently applied height of the view
233 * @param clipHeight the desired clip height, the rest of the view will be clipped from the top
234 * @param backgroundHeight the desired background height. The shadows of the view will be
235 * based on this height and the content will be clipped from the top
236 */
Jorim Jaggi2e34ec32014-07-01 03:17:05 +0200237 private void updateChildClippingAndBackground(StackScrollState.ViewState state,
238 float realHeight, float clipHeight, float backgroundHeight) {
Selim Cinek708a6c12014-05-28 14:16:02 +0200239 if (realHeight > clipHeight) {
Jorim Jaggi2e34ec32014-07-01 03:17:05 +0200240 // Rather overlap than create a hole.
241 state.topOverLap = (int) Math.floor((realHeight - clipHeight) / state.scale);
Selim Cinek708a6c12014-05-28 14:16:02 +0200242 } else {
243 state.topOverLap = 0;
244 }
245 if (realHeight > backgroundHeight) {
Jorim Jaggi2e34ec32014-07-01 03:17:05 +0200246 // Rather overlap than create a hole.
247 state.clipTopAmount = (int) Math.floor((realHeight - backgroundHeight) / state.scale);
Selim Cinek708a6c12014-05-28 14:16:02 +0200248 } else {
249 state.clipTopAmount = 0;
250 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200251 }
252
253 /**
254 * Updates the dimmed and activated states of the children.
255 */
256 private void updateDimmedActivated(AmbientState ambientState, StackScrollState resultState,
257 StackScrollAlgorithmState algorithmState) {
258 boolean dimmed = ambientState.isDimmed();
John Spurlockbf370992014-06-17 13:58:31 -0400259 boolean dark = ambientState.isDark();
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200260 View activatedChild = ambientState.getActivatedChild();
261 int childCount = algorithmState.visibleChildren.size();
262 for (int i = 0; i < childCount; i++) {
263 View child = algorithmState.visibleChildren.get(i);
264 StackScrollState.ViewState childViewState = resultState.getViewStateForView(child);
265 childViewState.dimmed = dimmed;
John Spurlockbf370992014-06-17 13:58:31 -0400266 childViewState.dark = dark;
Selim Cinekb89de4e2014-06-10 10:47:05 +0200267 boolean isActivatedChild = activatedChild == child;
268 childViewState.scale = !dimmed || isActivatedChild
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200269 ? 1.0f
270 : DIMMED_SCALE;
Selim Cinekb89de4e2014-06-10 10:47:05 +0200271 if (dimmed && activatedChild != null) {
272 if (!isActivatedChild) {
273 childViewState.alpha *= ACTIVATED_INVERSE_ALPHA;
274 } else {
275 childViewState.zTranslation += 2.0f * mZDistanceBetweenElements;
276 }
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200277 }
278 }
Selim Cinekeb973562014-05-02 17:07:49 +0200279 }
280
281 /**
282 * Handle the special state when views are being dragged
283 */
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200284 private void handleDraggedViews(AmbientState ambientState, StackScrollState resultState,
Selim Cinekeb973562014-05-02 17:07:49 +0200285 StackScrollAlgorithmState algorithmState) {
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200286 ArrayList<View> draggedViews = ambientState.getDraggedViews();
287 for (View draggedView : draggedViews) {
Selim Cinekeb973562014-05-02 17:07:49 +0200288 int childIndex = algorithmState.visibleChildren.indexOf(draggedView);
289 if (childIndex >= 0 && childIndex < algorithmState.visibleChildren.size() - 1) {
290 View nextChild = algorithmState.visibleChildren.get(childIndex + 1);
Jorim Jaggid552d9d2014-05-07 19:41:13 +0200291 if (!draggedViews.contains(nextChild)) {
Selim Cinekeb973562014-05-02 17:07:49 +0200292 // only if the view is not dragged itself we modify its state to be fully
293 // visible
294 StackScrollState.ViewState viewState = resultState.getViewStateForView(
295 nextChild);
296 // The child below the dragged one must be fully visible
297 viewState.alpha = 1;
298 }
299
300 // Lets set the alpha to the one it currently has, as its currently being dragged
301 StackScrollState.ViewState viewState = resultState.getViewStateForView(draggedView);
302 // The dragged child should keep the set alpha
303 viewState.alpha = draggedView.getAlpha();
304 }
305 }
Selim Cinek343e6e22014-04-11 21:23:30 +0200306 }
Selim Cinek67b22602014-03-10 15:40:16 +0100307
Selim Cinek343e6e22014-04-11 21:23:30 +0200308 /**
Jorim Jaggid4a57442014-04-10 02:45:55 +0200309 * Update the visible children on the state.
310 */
311 private void updateVisibleChildren(StackScrollState resultState,
312 StackScrollAlgorithmState state) {
313 ViewGroup hostView = resultState.getHostView();
314 int childCount = hostView.getChildCount();
315 state.visibleChildren.clear();
316 state.visibleChildren.ensureCapacity(childCount);
317 for (int i = 0; i < childCount; i++) {
Jorim Jaggibe565df2014-04-28 17:51:23 +0200318 ExpandableView v = (ExpandableView) hostView.getChildAt(i);
Jorim Jaggid4a57442014-04-10 02:45:55 +0200319 if (v.getVisibility() != View.GONE) {
Selim Cinek8efa6dd2014-05-19 16:27:37 +0200320 StackScrollState.ViewState viewState = resultState.getViewStateForView(v);
321 viewState.notGoneIndex = state.visibleChildren.size();
Jorim Jaggid4a57442014-04-10 02:45:55 +0200322 state.visibleChildren.add(v);
323 }
324 }
325 }
326
327 /**
Selim Cinek67b22602014-03-10 15:40:16 +0100328 * Determine the positions for the views. This is the main part of the algorithm.
329 *
330 * @param resultState The result state to update if a change to the properties of a child occurs
331 * @param algorithmState The state in which the current pass of the algorithm is currently in
Selim Cinek67b22602014-03-10 15:40:16 +0100332 */
333 private void updatePositionsForState(StackScrollState resultState,
334 StackScrollAlgorithmState algorithmState) {
Selim Cinek67b22602014-03-10 15:40:16 +0100335
Selim Cinek1685e632014-04-08 02:27:49 +0200336 // The starting position of the bottom stack peek
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200337 float bottomPeekStart = mInnerHeight - mBottomStackPeekSize;
Selim Cinek1685e632014-04-08 02:27:49 +0200338
Selim Cinek67b22602014-03-10 15:40:16 +0100339 // The position where the bottom stack starts.
Selim Cinek34c0a8d2014-05-12 00:01:43 +0200340 float bottomStackStart = bottomPeekStart - mBottomStackSlowDownLength;
Selim Cinek67b22602014-03-10 15:40:16 +0100341
342 // The y coordinate of the current child.
343 float currentYPosition = 0.0f;
344
345 // How far in is the element currently transitioning into the bottom stack.
346 float yPositionInScrollView = 0.0f;
347
Jorim Jaggid4a57442014-04-10 02:45:55 +0200348 int childCount = algorithmState.visibleChildren.size();
Selim Cinek67b22602014-03-10 15:40:16 +0100349 int numberOfElementsCompletelyIn = (int) algorithmState.itemsInTopStack;
350 for (int i = 0; i < childCount; i++) {
Jorim Jaggibe565df2014-04-28 17:51:23 +0200351 ExpandableView child = algorithmState.visibleChildren.get(i);
Selim Cinek67b22602014-03-10 15:40:16 +0100352 StackScrollState.ViewState childViewState = resultState.getViewStateForView(child);
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200353 childViewState.location = StackScrollState.ViewState.LOCATION_UNKNOWN;
Jorim Jaggibe565df2014-04-28 17:51:23 +0200354 int childHeight = getMaxAllowedChildHeight(child);
Selim Cinek67b22602014-03-10 15:40:16 +0100355 float yPositionInScrollViewAfterElement = yPositionInScrollView
356 + childHeight
357 + mPaddingBetweenElements;
Selim Cinek343e6e22014-04-11 21:23:30 +0200358 float scrollOffset = yPositionInScrollView - algorithmState.scrollY + mCollapsedSize;
359
360 if (i == algorithmState.lastTopStackIndex + 1) {
361 // Normally the position of this child is the position in the regular scrollview,
362 // but if the two stacks are very close to each other,
363 // then have have to push it even more upwards to the position of the bottom
364 // stack start.
365 currentYPosition = Math.min(scrollOffset, bottomStackStart);
366 }
367 childViewState.yTranslation = currentYPosition;
368
369 // The y position after this element
370 float nextYPosition = currentYPosition + childHeight +
371 mPaddingBetweenElements;
372
373 if (i <= algorithmState.lastTopStackIndex) {
Selim Cinek67b22602014-03-10 15:40:16 +0100374 // Case 1:
375 // We are in the top Stack
Selim Cinek343e6e22014-04-11 21:23:30 +0200376 updateStateForTopStackChild(algorithmState,
377 numberOfElementsCompletelyIn, i, childHeight, childViewState, scrollOffset);
378 clampYTranslation(childViewState, childHeight);
379 // check if we are overlapping with the bottom stack
380 if (childViewState.yTranslation + childHeight + mPaddingBetweenElements
Selim Cinek4a1ac842014-05-01 15:51:58 +0200381 >= bottomStackStart && !mIsExpansionChanging && i != 0) {
Selim Cinek343e6e22014-04-11 21:23:30 +0200382 // TODO: handle overlapping sizes with end stack better
383 // we just collapse this element
384 childViewState.height = mCollapsedSize;
385 }
386 } else if (nextYPosition >= bottomStackStart) {
Selim Cinek67b22602014-03-10 15:40:16 +0100387 // Case 2:
Selim Cinek343e6e22014-04-11 21:23:30 +0200388 // We are in the bottom stack.
389 if (currentYPosition >= bottomStackStart) {
Selim Cinek67b22602014-03-10 15:40:16 +0100390 // According to the regular scroll view we are fully translated out of the
391 // bottom of the screen so we are fully in the bottom stack
Selim Cinek343e6e22014-04-11 21:23:30 +0200392 updateStateForChildFullyInBottomStack(algorithmState,
393 bottomStackStart, childViewState, childHeight);
Selim Cinek67b22602014-03-10 15:40:16 +0100394 } else {
Selim Cinek67b22602014-03-10 15:40:16 +0100395 // According to the regular scroll view we are currently translating out of /
396 // into the bottom of the screen
Selim Cinek343e6e22014-04-11 21:23:30 +0200397 updateStateForChildTransitioningInBottom(algorithmState,
398 bottomStackStart, bottomPeekStart, currentYPosition,
399 childViewState, childHeight);
Selim Cinek67b22602014-03-10 15:40:16 +0100400 }
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200401 } else {
Selim Cinek343e6e22014-04-11 21:23:30 +0200402 // Case 3:
403 // We are in the regular scroll area.
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200404 childViewState.location = StackScrollState.ViewState.LOCATION_MAIN_AREA;
Selim Cinek343e6e22014-04-11 21:23:30 +0200405 clampYTranslation(childViewState, childHeight);
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200406 }
Selim Cinek343e6e22014-04-11 21:23:30 +0200407
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200408 // The first card is always rendered.
409 if (i == 0) {
410 childViewState.alpha = 1.0f;
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200411 childViewState.yTranslation = Math.max(mCollapsedSize - algorithmState.scrollY, 0);
Selim Cinekd83771e2014-07-04 16:45:31 +0200412 if (childViewState.yTranslation + childViewState.height
413 > bottomPeekStart - mCollapseSecondCardPadding) {
Selim Cinek4fe3e472014-07-03 16:32:54 +0200414 childViewState.height = (int) Math.max(
Selim Cinekd83771e2014-07-04 16:45:31 +0200415 bottomPeekStart - mCollapseSecondCardPadding
416 - childViewState.yTranslation, mCollapsedSize);
Selim Cinek4fe3e472014-07-03 16:32:54 +0200417 }
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200418 childViewState.location = StackScrollState.ViewState.LOCATION_FIRST_CARD;
419 }
420 if (childViewState.location == StackScrollState.ViewState.LOCATION_UNKNOWN) {
421 Log.wtf(LOG_TAG, "Failed to assign location for child " + i);
Selim Cinek67b22602014-03-10 15:40:16 +0100422 }
Selim Cinek343e6e22014-04-11 21:23:30 +0200423 currentYPosition = childViewState.yTranslation + childHeight + mPaddingBetweenElements;
Selim Cinek67b22602014-03-10 15:40:16 +0100424 yPositionInScrollView = yPositionInScrollViewAfterElement;
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200425
426 childViewState.yTranslation += mTopPadding;
Selim Cinek67b22602014-03-10 15:40:16 +0100427 }
428 }
429
Selim Cinek1685e632014-04-08 02:27:49 +0200430 /**
Selim Cinek343e6e22014-04-11 21:23:30 +0200431 * Clamp the yTranslation both up and down to valid positions.
Selim Cinek1685e632014-04-08 02:27:49 +0200432 *
Selim Cinek1685e632014-04-08 02:27:49 +0200433 * @param childViewState the view state of the child
Selim Cinek343e6e22014-04-11 21:23:30 +0200434 * @param childHeight the height of this child
Selim Cinek1685e632014-04-08 02:27:49 +0200435 */
Selim Cinek343e6e22014-04-11 21:23:30 +0200436 private void clampYTranslation(StackScrollState.ViewState childViewState, int childHeight) {
437 clampPositionToBottomStackStart(childViewState, childHeight);
438 clampPositionToTopStackEnd(childViewState, childHeight);
439 }
440
441 /**
442 * Clamp the yTranslation of the child down such that its end is at most on the beginning of
443 * the bottom stack.
444 *
445 * @param childViewState the view state of the child
446 * @param childHeight the height of this child
447 */
448 private void clampPositionToBottomStackStart(StackScrollState.ViewState childViewState,
449 int childHeight) {
450 childViewState.yTranslation = Math.min(childViewState.yTranslation,
Selim Cinekd83771e2014-07-04 16:45:31 +0200451 mInnerHeight - mBottomStackPeekSize - mCollapseSecondCardPadding - childHeight);
Selim Cinek343e6e22014-04-11 21:23:30 +0200452 }
453
454 /**
455 * 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 +0200456 * stack.get
Selim Cinek343e6e22014-04-11 21:23:30 +0200457 *
458 * @param childViewState the view state of the child
459 * @param childHeight the height of this child
460 */
461 private void clampPositionToTopStackEnd(StackScrollState.ViewState childViewState,
462 int childHeight) {
463 childViewState.yTranslation = Math.max(childViewState.yTranslation,
464 mCollapsedSize - childHeight);
Selim Cinek1685e632014-04-08 02:27:49 +0200465 }
466
467 private int getMaxAllowedChildHeight(View child) {
468 if (child instanceof ExpandableNotificationRow) {
469 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
Jorim Jaggi9cbadd32014-05-01 20:18:31 +0200470 return row.getIntrinsicHeight();
Jorim Jaggibe565df2014-04-28 17:51:23 +0200471 } else if (child instanceof ExpandableView) {
472 ExpandableView expandableView = (ExpandableView) child;
473 return expandableView.getActualHeight();
Selim Cinek1685e632014-04-08 02:27:49 +0200474 }
Jorim Jaggibe565df2014-04-28 17:51:23 +0200475 return child == null? mCollapsedSize : child.getHeight();
Selim Cinek1685e632014-04-08 02:27:49 +0200476 }
477
Selim Cinek343e6e22014-04-11 21:23:30 +0200478 private void updateStateForChildTransitioningInBottom(StackScrollAlgorithmState algorithmState,
479 float transitioningPositionStart, float bottomPeakStart, float currentYPosition,
480 StackScrollState.ViewState childViewState, int childHeight) {
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200481
Selim Cinek343e6e22014-04-11 21:23:30 +0200482 // This is the transitioning element on top of bottom stack, calculate how far we are in.
483 algorithmState.partialInBottom = 1.0f - (
484 (transitioningPositionStart - currentYPosition) / (childHeight +
485 mPaddingBetweenElements));
486
487 // the offset starting at the transitionPosition of the bottom stack
488 float offset = mBottomStackIndentationFunctor.getValue(algorithmState.partialInBottom);
489 algorithmState.itemsInBottomStack += algorithmState.partialInBottom;
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200490 childViewState.yTranslation = transitioningPositionStart + offset - childHeight
491 - mPaddingBetweenElements;
Selim Cinek34c0a8d2014-05-12 00:01:43 +0200492
Selim Cinek343e6e22014-04-11 21:23:30 +0200493 // We want at least to be at the end of the top stack when collapsing
494 clampPositionToTopStackEnd(childViewState, childHeight);
495 childViewState.location = StackScrollState.ViewState.LOCATION_MAIN_AREA;
Selim Cinek67b22602014-03-10 15:40:16 +0100496 }
497
Selim Cinek343e6e22014-04-11 21:23:30 +0200498 private void updateStateForChildFullyInBottomStack(StackScrollAlgorithmState algorithmState,
Selim Cinek67b22602014-03-10 15:40:16 +0100499 float transitioningPositionStart, StackScrollState.ViewState childViewState,
500 int childHeight) {
501
Selim Cinek343e6e22014-04-11 21:23:30 +0200502 float currentYPosition;
Selim Cinek67b22602014-03-10 15:40:16 +0100503 algorithmState.itemsInBottomStack += 1.0f;
504 if (algorithmState.itemsInBottomStack < MAX_ITEMS_IN_BOTTOM_STACK) {
505 // We are visually entering the bottom stack
Selim Cinek343e6e22014-04-11 21:23:30 +0200506 currentYPosition = transitioningPositionStart
Jorim Jaggife40f7d2014-04-28 15:20:04 +0200507 + mBottomStackIndentationFunctor.getValue(algorithmState.itemsInBottomStack)
508 - mPaddingBetweenElements;
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200509 childViewState.location = StackScrollState.ViewState.LOCATION_BOTTOM_STACK_PEEKING;
Selim Cinek67b22602014-03-10 15:40:16 +0100510 } else {
511 // we are fully inside the stack
512 if (algorithmState.itemsInBottomStack > MAX_ITEMS_IN_BOTTOM_STACK + 2) {
513 childViewState.alpha = 0.0f;
514 } else if (algorithmState.itemsInBottomStack
515 > MAX_ITEMS_IN_BOTTOM_STACK + 1) {
516 childViewState.alpha = 1.0f - algorithmState.partialInBottom;
517 }
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200518 childViewState.location = StackScrollState.ViewState.LOCATION_BOTTOM_STACK_HIDDEN;
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200519 currentYPosition = mInnerHeight;
Selim Cinek67b22602014-03-10 15:40:16 +0100520 }
Selim Cinek343e6e22014-04-11 21:23:30 +0200521 childViewState.yTranslation = currentYPosition - childHeight;
522 clampPositionToTopStackEnd(childViewState, childHeight);
Selim Cinek67b22602014-03-10 15:40:16 +0100523 }
524
Selim Cinek343e6e22014-04-11 21:23:30 +0200525 private void updateStateForTopStackChild(StackScrollAlgorithmState algorithmState,
526 int numberOfElementsCompletelyIn, int i, int childHeight,
527 StackScrollState.ViewState childViewState, float scrollOffset) {
Selim Cinek67b22602014-03-10 15:40:16 +0100528
Selim Cinek67b22602014-03-10 15:40:16 +0100529
530 // First we calculate the index relative to the current stack window of size at most
531 // {@link #MAX_ITEMS_IN_TOP_STACK}
Selim Cinek343e6e22014-04-11 21:23:30 +0200532 int paddedIndex = i - 1
Selim Cinek67b22602014-03-10 15:40:16 +0100533 - Math.max(numberOfElementsCompletelyIn - MAX_ITEMS_IN_TOP_STACK, 0);
534 if (paddedIndex >= 0) {
Selim Cinek343e6e22014-04-11 21:23:30 +0200535
Selim Cinek67b22602014-03-10 15:40:16 +0100536 // We are currently visually entering the top stack
Selim Cinekad3e5af2014-07-04 12:24:11 +0200537 float distanceToStack = (childHeight + mPaddingBetweenElements)
538 - algorithmState.scrolledPixelsTop;
539 if (i == algorithmState.lastTopStackIndex
540 && distanceToStack > (mTopStackTotalSize + mPaddingBetweenElements)) {
Selim Cinek343e6e22014-04-11 21:23:30 +0200541
542 // Child is currently translating into stack but not yet inside slow down zone.
543 // Handle it like the regular scrollview.
544 childViewState.yTranslation = scrollOffset;
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200545 } else {
Selim Cinek343e6e22014-04-11 21:23:30 +0200546 // Apply stacking logic.
547 float numItemsBefore;
548 if (i == algorithmState.lastTopStackIndex) {
Selim Cinekad3e5af2014-07-04 12:24:11 +0200549 numItemsBefore = 1.0f
550 - (distanceToStack / (mTopStackTotalSize + mPaddingBetweenElements));
Selim Cinek343e6e22014-04-11 21:23:30 +0200551 } else {
552 numItemsBefore = algorithmState.itemsInTopStack - i;
553 }
554 // The end position of the current child
Selim Cinekad3e5af2014-07-04 12:24:11 +0200555 float currentChildEndY = mCollapsedSize + mTopStackTotalSize
556 - mTopStackIndentationFunctor.getValue(numItemsBefore);
Selim Cinek343e6e22014-04-11 21:23:30 +0200557 childViewState.yTranslation = currentChildEndY - childHeight;
Selim Cinek67b22602014-03-10 15:40:16 +0100558 }
Selim Cinek343e6e22014-04-11 21:23:30 +0200559 childViewState.location = StackScrollState.ViewState.LOCATION_TOP_STACK_PEEKING;
Selim Cinek67b22602014-03-10 15:40:16 +0100560 } else {
Selim Cinek343e6e22014-04-11 21:23:30 +0200561 if (paddedIndex == -1) {
562 childViewState.alpha = 1.0f - algorithmState.partialInTop;
563 } else {
564 // We are hidden behind the top card and faded out, so we can hide ourselves.
565 childViewState.alpha = 0.0f;
566 }
567 childViewState.yTranslation = mCollapsedSize - childHeight;
Christoph Studer6e3eceb2014-04-01 18:40:27 +0200568 childViewState.location = StackScrollState.ViewState.LOCATION_TOP_STACK_HIDDEN;
Selim Cinek67b22602014-03-10 15:40:16 +0100569 }
Selim Cinek343e6e22014-04-11 21:23:30 +0200570
571
Selim Cinek67b22602014-03-10 15:40:16 +0100572 }
573
574 /**
575 * Find the number of items in the top stack and update the result state if needed.
576 *
577 * @param resultState The result state to update if a height change of an child occurs
578 * @param algorithmState The state in which the current pass of the algorithm is currently in
Selim Cinek67b22602014-03-10 15:40:16 +0100579 */
580 private void findNumberOfItemsInTopStackAndUpdateState(StackScrollState resultState,
581 StackScrollAlgorithmState algorithmState) {
582
583 // The y Position if the element would be in a regular scrollView
584 float yPositionInScrollView = 0.0f;
Jorim Jaggid4a57442014-04-10 02:45:55 +0200585 int childCount = algorithmState.visibleChildren.size();
Selim Cinek67b22602014-03-10 15:40:16 +0100586
587 // find the number of elements in the top stack.
588 for (int i = 0; i < childCount; i++) {
Jorim Jaggibe565df2014-04-28 17:51:23 +0200589 ExpandableView child = algorithmState.visibleChildren.get(i);
Selim Cinek67b22602014-03-10 15:40:16 +0100590 StackScrollState.ViewState childViewState = resultState.getViewStateForView(child);
Jorim Jaggibe565df2014-04-28 17:51:23 +0200591 int childHeight = getMaxAllowedChildHeight(child);
Selim Cinek67b22602014-03-10 15:40:16 +0100592 float yPositionInScrollViewAfterElement = yPositionInScrollView
593 + childHeight
594 + mPaddingBetweenElements;
595 if (yPositionInScrollView < algorithmState.scrollY) {
Selim Cinek8d9ff9c2014-05-12 15:13:04 +0200596 if (i == 0 && algorithmState.scrollY <= mCollapsedSize) {
Selim Cinek343e6e22014-04-11 21:23:30 +0200597
598 // The starting position of the bottom stack peek
Selim Cinekd83771e2014-07-04 16:45:31 +0200599 int bottomPeekStart = mInnerHeight - mBottomStackPeekSize -
600 mCollapseSecondCardPadding;
Selim Cinek343e6e22014-04-11 21:23:30 +0200601 // Collapse and expand the first child while the shade is being expanded
602 float maxHeight = mIsExpansionChanging && child == mFirstChildWhileExpanding
603 ? mFirstChildMaxHeight
604 : childHeight;
605 childViewState.height = (int) Math.max(Math.min(bottomPeekStart, maxHeight),
606 mCollapsedSize);
607 algorithmState.itemsInTopStack = 1.0f;
608
609 } else if (yPositionInScrollViewAfterElement < algorithmState.scrollY) {
Selim Cinek67b22602014-03-10 15:40:16 +0100610 // According to the regular scroll view we are fully off screen
611 algorithmState.itemsInTopStack += 1.0f;
Selim Cinek343e6e22014-04-11 21:23:30 +0200612 if (i == 0) {
Selim Cinek67b22602014-03-10 15:40:16 +0100613 childViewState.height = mCollapsedSize;
614 }
615 } else {
616 // According to the regular scroll view we are partially off screen
Selim Cinek343e6e22014-04-11 21:23:30 +0200617
Selim Cinek67b22602014-03-10 15:40:16 +0100618 // How much did we scroll into this child
Selim Cinekad3e5af2014-07-04 12:24:11 +0200619 algorithmState.scrolledPixelsTop = algorithmState.scrollY
620 - yPositionInScrollView;
Selim Cinek343e6e22014-04-11 21:23:30 +0200621 algorithmState.partialInTop = (algorithmState.scrolledPixelsTop) / (childHeight
Selim Cinek67b22602014-03-10 15:40:16 +0100622 + mPaddingBetweenElements);
623
624 // Our element can be expanded, so this can get negative
625 algorithmState.partialInTop = Math.max(0.0f, algorithmState.partialInTop);
626 algorithmState.itemsInTopStack += algorithmState.partialInTop;
Selim Cinekad3e5af2014-07-04 12:24:11 +0200627
Selim Cinek343e6e22014-04-11 21:23:30 +0200628 if (i == 0) {
Selim Cinekad3e5af2014-07-04 12:24:11 +0200629 // If it is expanded we have to collapse it to a new size
630 float newSize = yPositionInScrollViewAfterElement
631 - mPaddingBetweenElements
632 - algorithmState.scrollY + mCollapsedSize;
633 newSize = Math.max(mCollapsedSize, newSize);
Selim Cinek4e456be2014-06-12 18:09:43 +0200634 algorithmState.itemsInTopStack = 1.0f;
Selim Cinek67b22602014-03-10 15:40:16 +0100635 childViewState.height = (int) newSize;
Selim Cinek67b22602014-03-10 15:40:16 +0100636 }
Selim Cinek343e6e22014-04-11 21:23:30 +0200637 algorithmState.lastTopStackIndex = i;
638 break;
Selim Cinek67b22602014-03-10 15:40:16 +0100639 }
640 } else {
Selim Cinek343e6e22014-04-11 21:23:30 +0200641 algorithmState.lastTopStackIndex = i - 1;
Selim Cinek67b22602014-03-10 15:40:16 +0100642 // We are already past the stack so we can end the loop
643 break;
644 }
645 yPositionInScrollView = yPositionInScrollViewAfterElement;
646 }
647 }
648
649 /**
650 * Calculate the Z positions for all children based on the number of items in both stacks and
651 * save it in the resultState
652 *
653 * @param resultState The result state to update the zTranslation values
654 * @param algorithmState The state in which the current pass of the algorithm is currently in
655 */
656 private void updateZValuesForState(StackScrollState resultState,
657 StackScrollAlgorithmState algorithmState) {
Jorim Jaggid4a57442014-04-10 02:45:55 +0200658 int childCount = algorithmState.visibleChildren.size();
Selim Cinek67b22602014-03-10 15:40:16 +0100659 for (int i = 0; i < childCount; i++) {
Jorim Jaggid4a57442014-04-10 02:45:55 +0200660 View child = algorithmState.visibleChildren.get(i);
Selim Cinek67b22602014-03-10 15:40:16 +0100661 StackScrollState.ViewState childViewState = resultState.getViewStateForView(child);
662 if (i < algorithmState.itemsInTopStack) {
663 float stackIndex = algorithmState.itemsInTopStack - i;
664 stackIndex = Math.min(stackIndex, MAX_ITEMS_IN_TOP_STACK + 2);
Selim Cinek4e456be2014-06-12 18:09:43 +0200665 if (i == 0 && algorithmState.itemsInTopStack < 2.0f) {
666
667 // We only have the top item and an additional item in the top stack,
668 // Interpolate the index from 0 to 2 while the second item is
669 // translating in.
670 stackIndex -= 1.0f;
671 if (algorithmState.scrollY > mCollapsedSize) {
672
673 // Since there is a shadow treshhold, we cant just interpolate from 0 to
674 // 2 but we interpolate from 0.1f to 2.0f when scrolled in. The jump in
675 // height will not be noticable since we have padding in between.
676 stackIndex = 0.1f + stackIndex * 1.9f;
677 }
678 }
Selim Cinek67b22602014-03-10 15:40:16 +0100679 childViewState.zTranslation = mZBasicHeight
680 + stackIndex * mZDistanceBetweenElements;
681 } else if (i > (childCount - 1 - algorithmState.itemsInBottomStack)) {
682 float numItemsAbove = i - (childCount - 1 - algorithmState.itemsInBottomStack);
683 float translationZ = mZBasicHeight
684 - numItemsAbove * mZDistanceBetweenElements;
685 childViewState.zTranslation = translationZ;
686 } else {
687 childViewState.zTranslation = mZBasicHeight;
688 }
689 }
690 }
691
Selim Cinek343e6e22014-04-11 21:23:30 +0200692 public void setLayoutHeight(int layoutHeight) {
Selim Cinek67b22602014-03-10 15:40:16 +0100693 this.mLayoutHeight = layoutHeight;
Jorim Jaggi8c1a44b2014-04-29 19:04:02 +0200694 updateInnerHeight();
695 }
696
697 public void setTopPadding(int topPadding) {
698 mTopPadding = topPadding;
699 updateInnerHeight();
700 }
701
702 private void updateInnerHeight() {
703 mInnerHeight = mLayoutHeight - mTopPadding;
Selim Cinek67b22602014-03-10 15:40:16 +0100704 }
705
Selim Cinek1685e632014-04-08 02:27:49 +0200706 public void onExpansionStarted(StackScrollState currentState) {
707 mIsExpansionChanging = true;
708 mExpandedOnStart = mIsExpanded;
709 ViewGroup hostView = currentState.getHostView();
710 updateFirstChildHeightWhileExpanding(hostView);
711 }
712
713 private void updateFirstChildHeightWhileExpanding(ViewGroup hostView) {
Jorim Jaggibe565df2014-04-28 17:51:23 +0200714 mFirstChildWhileExpanding = (ExpandableView) findFirstVisibleChild(hostView);
Jorim Jaggi9f347ae2014-04-11 00:47:18 +0200715 if (mFirstChildWhileExpanding != null) {
Selim Cinek1685e632014-04-08 02:27:49 +0200716 if (mExpandedOnStart) {
717
718 // We are collapsing the shade, so the first child can get as most as high as the
719 // current height.
Jorim Jaggibe565df2014-04-28 17:51:23 +0200720 mFirstChildMaxHeight = mFirstChildWhileExpanding.getActualHeight();
Selim Cinek1685e632014-04-08 02:27:49 +0200721 } else {
722
723 // We are expanding the shade, expand it to its full height.
Selim Cinek7d447722014-06-10 15:51:59 +0200724 if (!isMaxSizeInitialized(mFirstChildWhileExpanding)) {
Selim Cinekb6e0e122014-04-23 17:24:37 +0200725
726 // This child was not layouted yet, wait for a layout pass
727 mFirstChildWhileExpanding
728 .addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
729 @Override
730 public void onLayoutChange(View v, int left, int top, int right,
731 int bottom, int oldLeft, int oldTop, int oldRight,
732 int oldBottom) {
Selim Cinek2ba5f1f2014-04-28 20:23:30 +0200733 if (mFirstChildWhileExpanding != null) {
734 mFirstChildMaxHeight = getMaxAllowedChildHeight(
735 mFirstChildWhileExpanding);
736 } else {
737 mFirstChildMaxHeight = 0;
738 }
739 v.removeOnLayoutChangeListener(this);
Selim Cinekb6e0e122014-04-23 17:24:37 +0200740 }
741 });
742 } else {
743 mFirstChildMaxHeight = getMaxAllowedChildHeight(mFirstChildWhileExpanding);
744 }
Selim Cinek1685e632014-04-08 02:27:49 +0200745 }
746 } else {
Selim Cinek1685e632014-04-08 02:27:49 +0200747 mFirstChildMaxHeight = 0;
748 }
749 }
750
Selim Cinek7d447722014-06-10 15:51:59 +0200751 private boolean isMaxSizeInitialized(ExpandableView child) {
752 if (child instanceof ExpandableNotificationRow) {
753 ExpandableNotificationRow row = (ExpandableNotificationRow) child;
754 return row.isShowingLayoutLayouted();
755 }
756 return child == null || child.getWidth() != 0;
757 }
758
Jorim Jaggi9f347ae2014-04-11 00:47:18 +0200759 private View findFirstVisibleChild(ViewGroup container) {
760 int childCount = container.getChildCount();
761 for (int i = 0; i < childCount; i++) {
762 View child = container.getChildAt(i);
763 if (child.getVisibility() != View.GONE) {
764 return child;
765 }
766 }
767 return null;
768 }
769
Selim Cinek1685e632014-04-08 02:27:49 +0200770 public void onExpansionStopped() {
771 mIsExpansionChanging = false;
772 mFirstChildWhileExpanding = null;
773 }
774
775 public void setIsExpanded(boolean isExpanded) {
776 this.mIsExpanded = isExpanded;
777 }
778
779 public void notifyChildrenChanged(ViewGroup hostView) {
780 if (mIsExpansionChanging) {
781 updateFirstChildHeightWhileExpanding(hostView);
782 }
783 }
784
Selim Cinek34c0a8d2014-05-12 00:01:43 +0200785 public void setDimmed(boolean dimmed) {
786 updatePadding(dimmed);
787 }
788
Selim Cinek67b22602014-03-10 15:40:16 +0100789 class StackScrollAlgorithmState {
790
791 /**
792 * The scroll position of the algorithm
793 */
794 public int scrollY;
795
796 /**
797 * The quantity of items which are in the top stack.
798 */
799 public float itemsInTopStack;
800
801 /**
802 * how far in is the element currently transitioning into the top stack
803 */
804 public float partialInTop;
805
806 /**
Selim Cinek343e6e22014-04-11 21:23:30 +0200807 * The number of pixels the last child in the top stack has scrolled in to the stack
808 */
809 public float scrolledPixelsTop;
810
811 /**
Selim Cinek67b22602014-03-10 15:40:16 +0100812 * The last item index which is in the top stack.
Selim Cinek67b22602014-03-10 15:40:16 +0100813 */
814 public int lastTopStackIndex;
815
816 /**
817 * The quantity of items which are in the bottom stack.
818 */
819 public float itemsInBottomStack;
820
821 /**
822 * how far in is the element currently transitioning into the bottom stack
823 */
824 public float partialInBottom;
Jorim Jaggid4a57442014-04-10 02:45:55 +0200825
826 /**
827 * The children from the host view which are not gone.
828 */
Jorim Jaggibe565df2014-04-28 17:51:23 +0200829 public final ArrayList<ExpandableView> visibleChildren = new ArrayList<ExpandableView>();
Selim Cinek67b22602014-03-10 15:40:16 +0100830 }
831
832}