StackScrollAlgorithm.java revision 38d429f4395b3bac933ad8a77ab224659f9bb2e5
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 17package com.android.systemui.statusbar.stack; 18 19import android.content.Context; 20import android.util.Log; 21import android.view.View; 22import android.view.ViewGroup; 23 24import com.android.systemui.R; 25import com.android.systemui.statusbar.ExpandableNotificationRow; 26import com.android.systemui.statusbar.ExpandableView; 27import com.android.systemui.statusbar.notification.FakeShadowView; 28import com.android.systemui.statusbar.notification.NotificationUtils; 29 30import java.util.ArrayList; 31import java.util.HashMap; 32import java.util.List; 33 34/** 35 * The Algorithm of the {@link com.android.systemui.statusbar.stack 36 * .NotificationStackScrollLayout} which can be queried for {@link com.android.systemui.statusbar 37 * .stack.StackScrollState} 38 */ 39public class StackScrollAlgorithm { 40 41 private static final String LOG_TAG = "StackScrollAlgorithm"; 42 43 private static final int MAX_ITEMS_IN_BOTTOM_STACK = 3; 44 45 private int mPaddingBetweenElements; 46 private int mIncreasedPaddingBetweenElements; 47 private int mCollapsedSize; 48 private int mBottomStackPeekSize; 49 private int mZDistanceBetweenElements; 50 private int mZBasicHeight; 51 52 private StackIndentationFunctor mBottomStackIndentationFunctor; 53 54 private StackScrollAlgorithmState mTempAlgorithmState = new StackScrollAlgorithmState(); 55 private boolean mIsExpanded; 56 private int mBottomStackSlowDownLength; 57 58 public StackScrollAlgorithm(Context context) { 59 initView(context); 60 } 61 62 public void initView(Context context) { 63 initConstants(context); 64 } 65 66 public int getBottomStackSlowDownLength() { 67 return mBottomStackSlowDownLength + mPaddingBetweenElements; 68 } 69 70 private void initConstants(Context context) { 71 mPaddingBetweenElements = Math.max(1, context.getResources() 72 .getDimensionPixelSize(R.dimen.notification_divider_height)); 73 mIncreasedPaddingBetweenElements = context.getResources() 74 .getDimensionPixelSize(R.dimen.notification_divider_height_increased); 75 mCollapsedSize = context.getResources() 76 .getDimensionPixelSize(R.dimen.notification_min_height); 77 mBottomStackPeekSize = context.getResources() 78 .getDimensionPixelSize(R.dimen.bottom_stack_peek_amount); 79 mZDistanceBetweenElements = Math.max(1, context.getResources() 80 .getDimensionPixelSize(R.dimen.z_distance_between_notifications)); 81 mZBasicHeight = (MAX_ITEMS_IN_BOTTOM_STACK + 1) * mZDistanceBetweenElements; 82 mBottomStackSlowDownLength = context.getResources() 83 .getDimensionPixelSize(R.dimen.bottom_stack_slow_down_length); 84 mBottomStackIndentationFunctor = new PiecewiseLinearIndentationFunctor( 85 MAX_ITEMS_IN_BOTTOM_STACK, 86 mBottomStackPeekSize, 87 getBottomStackSlowDownLength(), 88 0.5f); 89 } 90 91 public void getStackScrollState(AmbientState ambientState, StackScrollState resultState) { 92 // The state of the local variables are saved in an algorithmState to easily subdivide it 93 // into multiple phases. 94 StackScrollAlgorithmState algorithmState = mTempAlgorithmState; 95 96 // First we reset the view states to their default values. 97 resultState.resetViewStates(); 98 99 initAlgorithmState(resultState, algorithmState, ambientState); 100 101 updatePositionsForState(resultState, algorithmState, ambientState); 102 103 updateZValuesForState(resultState, algorithmState, ambientState); 104 105 updateHeadsUpStates(resultState, algorithmState, ambientState); 106 107 handleDraggedViews(ambientState, resultState, algorithmState); 108 updateDimmedActivatedHideSensitive(ambientState, resultState, algorithmState); 109 updateClipping(resultState, algorithmState, ambientState); 110 updateSpeedBumpState(resultState, algorithmState, ambientState.getSpeedBumpIndex()); 111 getNotificationChildrenStates(resultState, algorithmState); 112 } 113 114 private void getNotificationChildrenStates(StackScrollState resultState, 115 StackScrollAlgorithmState algorithmState) { 116 int childCount = algorithmState.visibleChildren.size(); 117 for (int i = 0; i < childCount; i++) { 118 ExpandableView v = algorithmState.visibleChildren.get(i); 119 if (v instanceof ExpandableNotificationRow) { 120 ExpandableNotificationRow row = (ExpandableNotificationRow) v; 121 row.getChildrenStates(resultState); 122 } 123 } 124 } 125 126 private void updateSpeedBumpState(StackScrollState resultState, 127 StackScrollAlgorithmState algorithmState, int speedBumpIndex) { 128 int childCount = algorithmState.visibleChildren.size(); 129 for (int i = 0; i < childCount; i++) { 130 View child = algorithmState.visibleChildren.get(i); 131 StackViewState childViewState = resultState.getViewStateForView(child); 132 133 // The speed bump can also be gone, so equality needs to be taken when comparing 134 // indices. 135 childViewState.belowSpeedBump = speedBumpIndex != -1 && i >= speedBumpIndex; 136 } 137 } 138 139 private void updateClipping(StackScrollState resultState, 140 StackScrollAlgorithmState algorithmState, AmbientState ambientState) { 141 float drawStart = ambientState.getTopPadding() + ambientState.getStackTranslation(); 142 float previousNotificationEnd = 0; 143 float previousNotificationStart = 0; 144 int childCount = algorithmState.visibleChildren.size(); 145 for (int i = 0; i < childCount; i++) { 146 ExpandableView child = algorithmState.visibleChildren.get(i); 147 StackViewState state = resultState.getViewStateForView(child); 148 if (!child.mustStayOnScreen()) { 149 previousNotificationEnd = Math.max(drawStart, previousNotificationEnd); 150 previousNotificationStart = Math.max(drawStart, previousNotificationStart); 151 } 152 float newYTranslation = state.yTranslation; 153 float newHeight = state.height; 154 float newNotificationEnd = newYTranslation + newHeight; 155 156 if (newYTranslation < previousNotificationEnd) { 157 // The previous view is overlapping on top, clip! 158 float overlapAmount = previousNotificationEnd - newYTranslation; 159 state.clipTopAmount = (int) overlapAmount; 160 } else { 161 state.clipTopAmount = 0; 162 } 163 164 if (!child.isTransparent()) { 165 // Only update the previous values if we are not transparent, 166 // otherwise we would clip to a transparent view. 167 previousNotificationEnd = newNotificationEnd; 168 previousNotificationStart = newYTranslation; 169 } 170 } 171 } 172 173 public static boolean canChildBeDismissed(View v) { 174 if (v instanceof ExpandableNotificationRow) { 175 ExpandableNotificationRow row = (ExpandableNotificationRow) v; 176 if (row.areGutsExposed()) { 177 return false; 178 } 179 } 180 final View veto = v.findViewById(R.id.veto); 181 return (veto != null && veto.getVisibility() != View.GONE); 182 } 183 184 /** 185 * Updates the dimmed, activated and hiding sensitive states of the children. 186 */ 187 private void updateDimmedActivatedHideSensitive(AmbientState ambientState, 188 StackScrollState resultState, StackScrollAlgorithmState algorithmState) { 189 boolean dimmed = ambientState.isDimmed(); 190 boolean dark = ambientState.isDark(); 191 boolean hideSensitive = ambientState.isHideSensitive(); 192 View activatedChild = ambientState.getActivatedChild(); 193 int childCount = algorithmState.visibleChildren.size(); 194 for (int i = 0; i < childCount; i++) { 195 View child = algorithmState.visibleChildren.get(i); 196 StackViewState childViewState = resultState.getViewStateForView(child); 197 childViewState.dimmed = dimmed; 198 childViewState.dark = dark; 199 childViewState.hideSensitive = hideSensitive; 200 boolean isActivatedChild = activatedChild == child; 201 if (dimmed && isActivatedChild) { 202 childViewState.zTranslation += 2.0f * mZDistanceBetweenElements; 203 } 204 } 205 } 206 207 /** 208 * Handle the special state when views are being dragged 209 */ 210 private void handleDraggedViews(AmbientState ambientState, StackScrollState resultState, 211 StackScrollAlgorithmState algorithmState) { 212 ArrayList<View> draggedViews = ambientState.getDraggedViews(); 213 for (View draggedView : draggedViews) { 214 int childIndex = algorithmState.visibleChildren.indexOf(draggedView); 215 if (childIndex >= 0 && childIndex < algorithmState.visibleChildren.size() - 1) { 216 View nextChild = algorithmState.visibleChildren.get(childIndex + 1); 217 if (!draggedViews.contains(nextChild)) { 218 // only if the view is not dragged itself we modify its state to be fully 219 // visible 220 StackViewState viewState = resultState.getViewStateForView( 221 nextChild); 222 // The child below the dragged one must be fully visible 223 if (ambientState.isShadeExpanded()) { 224 viewState.shadowAlpha = 1; 225 viewState.hidden = false; 226 } 227 } 228 229 // Lets set the alpha to the one it currently has, as its currently being dragged 230 StackViewState viewState = resultState.getViewStateForView(draggedView); 231 // The dragged child should keep the set alpha 232 viewState.alpha = draggedView.getAlpha(); 233 } 234 } 235 } 236 237 /** 238 * Initialize the algorithm state like updating the visible children. 239 */ 240 private void initAlgorithmState(StackScrollState resultState, StackScrollAlgorithmState state, 241 AmbientState ambientState) { 242 state.itemsInBottomStack = 0.0f; 243 state.partialInBottom = 0.0f; 244 float bottomOverScroll = ambientState.getOverScrollAmount(false /* onTop */); 245 246 int scrollY = ambientState.getScrollY(); 247 248 // Due to the overScroller, the stackscroller can have negative scroll state. This is 249 // already accounted for by the top padding and doesn't need an additional adaption 250 scrollY = Math.max(0, scrollY); 251 state.scrollY = (int) (scrollY + bottomOverScroll); 252 253 //now init the visible children and update paddings 254 ViewGroup hostView = resultState.getHostView(); 255 int childCount = hostView.getChildCount(); 256 state.visibleChildren.clear(); 257 state.visibleChildren.ensureCapacity(childCount); 258 state.increasedPaddingMap.clear(); 259 int notGoneIndex = 0; 260 ExpandableView lastView = null; 261 for (int i = 0; i < childCount; i++) { 262 ExpandableView v = (ExpandableView) hostView.getChildAt(i); 263 if (v.getVisibility() != View.GONE) { 264 notGoneIndex = updateNotGoneIndex(resultState, state, notGoneIndex, v); 265 float increasedPadding = v.getIncreasedPaddingAmount(); 266 if (increasedPadding != 0.0f) { 267 state.increasedPaddingMap.put(v, increasedPadding); 268 if (lastView != null) { 269 Float prevValue = state.increasedPaddingMap.get(lastView); 270 float newValue = prevValue != null 271 ? Math.max(prevValue, increasedPadding) 272 : increasedPadding; 273 state.increasedPaddingMap.put(lastView, newValue); 274 } 275 } 276 if (v instanceof ExpandableNotificationRow) { 277 ExpandableNotificationRow row = (ExpandableNotificationRow) v; 278 279 // handle the notgoneIndex for the children as well 280 List<ExpandableNotificationRow> children = 281 row.getNotificationChildren(); 282 if (row.isSummaryWithChildren() && children != null) { 283 for (ExpandableNotificationRow childRow : children) { 284 if (childRow.getVisibility() != View.GONE) { 285 StackViewState childState 286 = resultState.getViewStateForView(childRow); 287 childState.notGoneIndex = notGoneIndex; 288 notGoneIndex++; 289 } 290 } 291 } 292 } 293 lastView = v; 294 } 295 } 296 } 297 298 private int updateNotGoneIndex(StackScrollState resultState, 299 StackScrollAlgorithmState state, int notGoneIndex, 300 ExpandableView v) { 301 StackViewState viewState = resultState.getViewStateForView(v); 302 viewState.notGoneIndex = notGoneIndex; 303 state.visibleChildren.add(v); 304 notGoneIndex++; 305 return notGoneIndex; 306 } 307 308 /** 309 * Determine the positions for the views. This is the main part of the algorithm. 310 * 311 * @param resultState The result state to update if a change to the properties of a child occurs 312 * @param algorithmState The state in which the current pass of the algorithm is currently in 313 * @param ambientState The current ambient state 314 */ 315 private void updatePositionsForState(StackScrollState resultState, 316 StackScrollAlgorithmState algorithmState, AmbientState ambientState) { 317 318 // The starting position of the bottom stack peek 319 float bottomPeekStart = ambientState.getInnerHeight() - mBottomStackPeekSize; 320 321 // The position where the bottom stack starts. 322 float bottomStackStart = bottomPeekStart - mBottomStackSlowDownLength; 323 324 // The y coordinate of the current child. 325 float currentYPosition = -algorithmState.scrollY; 326 327 int childCount = algorithmState.visibleChildren.size(); 328 int paddingAfterChild; 329 for (int i = 0; i < childCount; i++) { 330 ExpandableView child = algorithmState.visibleChildren.get(i); 331 StackViewState childViewState = resultState.getViewStateForView(child); 332 childViewState.location = StackViewState.LOCATION_UNKNOWN; 333 paddingAfterChild = getPaddingAfterChild(algorithmState, child); 334 int childHeight = getMaxAllowedChildHeight(child); 335 int collapsedHeight = child.getCollapsedHeight(); 336 childViewState.yTranslation = currentYPosition; 337 if (i == 0) { 338 updateFirstChildHeight(child, childViewState, childHeight, ambientState); 339 } 340 341 // The y position after this element 342 float nextYPosition = currentYPosition + childHeight + 343 paddingAfterChild; 344 if (nextYPosition >= bottomStackStart) { 345 // Case 1: 346 // We are in the bottom stack. 347 if (currentYPosition >= bottomStackStart) { 348 // According to the regular scroll view we are fully translated out of the 349 // bottom of the screen so we are fully in the bottom stack 350 updateStateForChildFullyInBottomStack(algorithmState, 351 bottomStackStart, childViewState, collapsedHeight, ambientState, child); 352 } else { 353 // According to the regular scroll view we are currently translating out of / 354 // into the bottom of the screen 355 updateStateForChildTransitioningInBottom(algorithmState, 356 bottomStackStart, child, currentYPosition, 357 childViewState, childHeight); 358 } 359 } else { 360 // Case 2: 361 // We are in the regular scroll area. 362 childViewState.location = StackViewState.LOCATION_MAIN_AREA; 363 clampPositionToBottomStackStart(childViewState, childViewState.height, childHeight, 364 ambientState); 365 } 366 367 if (i == 0 && ambientState.getScrollY() <= 0) { 368 // The first card can get into the bottom stack if it's the only one 369 // on the lockscreen which pushes it up. Let's make sure that doesn't happen and 370 // it stays at the top 371 childViewState.yTranslation = Math.max(0, childViewState.yTranslation); 372 } 373 currentYPosition = childViewState.yTranslation + childHeight + paddingAfterChild; 374 if (currentYPosition <= 0) { 375 childViewState.location = StackViewState.LOCATION_HIDDEN_TOP; 376 } 377 if (childViewState.location == StackViewState.LOCATION_UNKNOWN) { 378 Log.wtf(LOG_TAG, "Failed to assign location for child " + i); 379 } 380 381 childViewState.yTranslation += ambientState.getTopPadding() 382 + ambientState.getStackTranslation(); 383 } 384 } 385 386 private int getPaddingAfterChild(StackScrollAlgorithmState algorithmState, 387 ExpandableView child) { 388 Float paddingValue = algorithmState.increasedPaddingMap.get(child); 389 return paddingValue == null 390 ? mPaddingBetweenElements 391 : (int) NotificationUtils.interpolate(mPaddingBetweenElements, 392 mIncreasedPaddingBetweenElements, 393 paddingValue); 394 } 395 396 private void updateHeadsUpStates(StackScrollState resultState, 397 StackScrollAlgorithmState algorithmState, AmbientState ambientState) { 398 int childCount = algorithmState.visibleChildren.size(); 399 ExpandableNotificationRow topHeadsUpEntry = null; 400 for (int i = 0; i < childCount; i++) { 401 View child = algorithmState.visibleChildren.get(i); 402 if (!(child instanceof ExpandableNotificationRow)) { 403 break; 404 } 405 ExpandableNotificationRow row = (ExpandableNotificationRow) child; 406 if (!row.isHeadsUp()) { 407 break; 408 } 409 StackViewState childState = resultState.getViewStateForView(row); 410 if (topHeadsUpEntry == null) { 411 topHeadsUpEntry = row; 412 childState.location = StackViewState.LOCATION_FIRST_HUN; 413 } 414 boolean isTopEntry = topHeadsUpEntry == row; 415 float unmodifiedEndLocation = childState.yTranslation + childState.height; 416 if (mIsExpanded) { 417 // Ensure that the heads up is always visible even when scrolled off 418 clampHunToTop(ambientState, row, childState); 419 clampHunToMaxTranslation(ambientState, row, childState); 420 } 421 if (row.isPinned()) { 422 childState.yTranslation = Math.max(childState.yTranslation, 0); 423 childState.height = Math.max(row.getIntrinsicHeight(), childState.height); 424 StackViewState topState = resultState.getViewStateForView(topHeadsUpEntry); 425 if (!isTopEntry && (!mIsExpanded 426 || unmodifiedEndLocation < topState.yTranslation + topState.height)) { 427 // Ensure that a headsUp doesn't vertically extend further than the heads-up at 428 // the top most z-position 429 childState.height = row.getIntrinsicHeight(); 430 childState.yTranslation = topState.yTranslation + topState.height 431 - childState.height; 432 } 433 } 434 } 435 } 436 437 private void clampHunToTop(AmbientState ambientState, ExpandableNotificationRow row, 438 StackViewState childState) { 439 float newTranslation = Math.max(ambientState.getTopPadding() 440 + ambientState.getStackTranslation(), childState.yTranslation); 441 childState.height = (int) Math.max(childState.height - (newTranslation 442 - childState.yTranslation), row.getCollapsedHeight()); 443 childState.yTranslation = newTranslation; 444 } 445 446 private void clampHunToMaxTranslation(AmbientState ambientState, ExpandableNotificationRow row, 447 StackViewState childState) { 448 float newTranslation; 449 float bottomPosition = ambientState.getMaxHeadsUpTranslation() - row.getCollapsedHeight(); 450 newTranslation = Math.min(childState.yTranslation, bottomPosition); 451 childState.height = (int) Math.max(childState.height 452 - (childState.yTranslation - newTranslation), row.getCollapsedHeight()); 453 childState.yTranslation = newTranslation; 454 } 455 456 /** 457 * Clamp the yTranslation of the child down such that its end is at most on the beginning of 458 * the bottom stack. 459 * 460 * @param childViewState the view state of the child 461 * @param childHeight the height of this child 462 * @param minHeight the minumum Height of the View 463 */ 464 private void clampPositionToBottomStackStart(StackViewState childViewState, 465 int childHeight, int minHeight, AmbientState ambientState) { 466 467 int bottomStackStart = ambientState.getInnerHeight() 468 - mBottomStackPeekSize - mBottomStackSlowDownLength; 469 int childStart = bottomStackStart - childHeight; 470 if (childStart < childViewState.yTranslation) { 471 float newHeight = bottomStackStart - childViewState.yTranslation; 472 if (newHeight < minHeight) { 473 newHeight = minHeight; 474 childViewState.yTranslation = bottomStackStart - minHeight; 475 } 476 childViewState.height = (int) newHeight; 477 } 478 } 479 480 private int getMaxAllowedChildHeight(View child) { 481 if (child instanceof ExpandableView) { 482 ExpandableView expandableView = (ExpandableView) child; 483 return expandableView.getIntrinsicHeight(); 484 } 485 return child == null? mCollapsedSize : child.getHeight(); 486 } 487 488 private void updateStateForChildTransitioningInBottom(StackScrollAlgorithmState algorithmState, 489 float transitioningPositionStart, ExpandableView child, float currentYPosition, 490 StackViewState childViewState, int childHeight) { 491 492 // This is the transitioning element on top of bottom stack, calculate how far we are in. 493 algorithmState.partialInBottom = 1.0f - ( 494 (transitioningPositionStart - currentYPosition) / (childHeight + 495 getPaddingAfterChild(algorithmState, child))); 496 497 // the offset starting at the transitionPosition of the bottom stack 498 float offset = mBottomStackIndentationFunctor.getValue(algorithmState.partialInBottom); 499 algorithmState.itemsInBottomStack += algorithmState.partialInBottom; 500 int newHeight = childHeight; 501 if (childHeight > child.getCollapsedHeight()) { 502 newHeight = (int) Math.max(Math.min(transitioningPositionStart + offset - 503 getPaddingAfterChild(algorithmState, child) - currentYPosition, childHeight), 504 child.getCollapsedHeight()); 505 childViewState.height = newHeight; 506 } 507 childViewState.yTranslation = transitioningPositionStart + offset - newHeight 508 - getPaddingAfterChild(algorithmState, child); 509 childViewState.location = StackViewState.LOCATION_MAIN_AREA; 510 } 511 512 private void updateStateForChildFullyInBottomStack(StackScrollAlgorithmState algorithmState, 513 float transitioningPositionStart, StackViewState childViewState, 514 int collapsedHeight, AmbientState ambientState, ExpandableView child) { 515 float currentYPosition; 516 algorithmState.itemsInBottomStack += 1.0f; 517 if (algorithmState.itemsInBottomStack < MAX_ITEMS_IN_BOTTOM_STACK) { 518 // We are visually entering the bottom stack 519 currentYPosition = transitioningPositionStart 520 + mBottomStackIndentationFunctor.getValue(algorithmState.itemsInBottomStack) 521 - getPaddingAfterChild(algorithmState, child); 522 childViewState.location = StackViewState.LOCATION_BOTTOM_STACK_PEEKING; 523 } else { 524 // we are fully inside the stack 525 if (algorithmState.itemsInBottomStack > MAX_ITEMS_IN_BOTTOM_STACK + 2) { 526 childViewState.hidden = true; 527 childViewState.shadowAlpha = 0.0f; 528 } else if (algorithmState.itemsInBottomStack 529 > MAX_ITEMS_IN_BOTTOM_STACK + 1) { 530 childViewState.shadowAlpha = 1.0f - algorithmState.partialInBottom; 531 } 532 childViewState.location = StackViewState.LOCATION_BOTTOM_STACK_HIDDEN; 533 currentYPosition = ambientState.getInnerHeight(); 534 } 535 childViewState.height = collapsedHeight; 536 childViewState.yTranslation = currentYPosition - collapsedHeight; 537 } 538 539 540 /** 541 * Update the height of the first child i.e clamp it to the bottom stack 542 * 543 * @param child the child to update 544 * @param childViewState the viewstate of the child 545 * @param childHeight the height of the child 546 * @param ambientState The ambient state of the algorithm 547 */ 548 private void updateFirstChildHeight(ExpandableView child, StackViewState childViewState, 549 int childHeight, AmbientState ambientState) { 550 551 // The starting position of the bottom stack peek 552 int bottomPeekStart = ambientState.getInnerHeight() - mBottomStackPeekSize - 553 mBottomStackSlowDownLength + ambientState.getScrollY(); 554 // Collapse and expand the first child while the shade is being expanded 555 childViewState.height = (int) Math.max(Math.min(bottomPeekStart, (float) childHeight), 556 child.getCollapsedHeight()); 557 } 558 559 /** 560 * Calculate the Z positions for all children based on the number of items in both stacks and 561 * save it in the resultState 562 * @param resultState The result state to update the zTranslation values 563 * @param algorithmState The state in which the current pass of the algorithm is currently in 564 * @param ambientState The ambient state of the algorithm 565 */ 566 private void updateZValuesForState(StackScrollState resultState, 567 StackScrollAlgorithmState algorithmState, AmbientState ambientState) { 568 int childCount = algorithmState.visibleChildren.size(); 569 float childrenOnTop = 0.0f; 570 for (int i = childCount - 1; i >= 0; i--) { 571 ExpandableView child = algorithmState.visibleChildren.get(i); 572 StackViewState childViewState = resultState.getViewStateForView(child); 573 if (i > (childCount - 1 - algorithmState.itemsInBottomStack)) { 574 // We are in the bottom stack 575 float numItemsAbove = i - (childCount - 1 - algorithmState.itemsInBottomStack); 576 float zSubtraction; 577 if (numItemsAbove <= 1.0f) { 578 float factor = 0.2f; 579 // Lets fade in slower to the threshold to make the shadow fade in look nicer 580 if (numItemsAbove <= factor) { 581 zSubtraction = FakeShadowView.SHADOW_SIBLING_TRESHOLD 582 * numItemsAbove * (1.0f / factor); 583 } else { 584 zSubtraction = FakeShadowView.SHADOW_SIBLING_TRESHOLD 585 + (numItemsAbove - factor) * (1.0f / (1.0f - factor)) 586 * (mZDistanceBetweenElements 587 - FakeShadowView.SHADOW_SIBLING_TRESHOLD); 588 } 589 } else { 590 zSubtraction = numItemsAbove * mZDistanceBetweenElements; 591 } 592 childViewState.zTranslation = mZBasicHeight - zSubtraction; 593 } else if (child.mustStayOnScreen() 594 && childViewState.yTranslation < ambientState.getTopPadding() 595 + ambientState.getStackTranslation()) { 596 if (childrenOnTop != 0.0f) { 597 childrenOnTop++; 598 } else { 599 float overlap = ambientState.getTopPadding() 600 + ambientState.getStackTranslation() - childViewState.yTranslation; 601 childrenOnTop += Math.min(1.0f, overlap / childViewState.height); 602 } 603 childViewState.zTranslation = mZBasicHeight 604 + childrenOnTop * mZDistanceBetweenElements; 605 } else { 606 childViewState.zTranslation = mZBasicHeight; 607 } 608 } 609 } 610 611 private boolean isMaxSizeInitialized(ExpandableView child) { 612 if (child instanceof ExpandableNotificationRow) { 613 ExpandableNotificationRow row = (ExpandableNotificationRow) child; 614 return row.isMaxExpandHeightInitialized(); 615 } 616 return child == null || child.getWidth() != 0; 617 } 618 619 private View findFirstVisibleChild(ViewGroup container) { 620 int childCount = container.getChildCount(); 621 for (int i = 0; i < childCount; i++) { 622 View child = container.getChildAt(i); 623 if (child.getVisibility() != View.GONE) { 624 return child; 625 } 626 } 627 return null; 628 } 629 630 public void setIsExpanded(boolean isExpanded) { 631 this.mIsExpanded = isExpanded; 632 } 633 634 class StackScrollAlgorithmState { 635 636 /** 637 * The scroll position of the algorithm 638 */ 639 public int scrollY; 640 641 /** 642 * The quantity of items which are in the bottom stack. 643 */ 644 public float itemsInBottomStack; 645 646 /** 647 * how far in is the element currently transitioning into the bottom stack 648 */ 649 public float partialInBottom; 650 651 /** 652 * The children from the host view which are not gone. 653 */ 654 public final ArrayList<ExpandableView> visibleChildren = new ArrayList<ExpandableView>(); 655 656 /** 657 * The children from the host that need an increased padding after them. A value of 0 means 658 * no increased padding, a value of 1 means full padding. 659 */ 660 public final HashMap<ExpandableView, Float> increasedPaddingMap = new HashMap<>(); 661 } 662 663} 664