Ejemplo n.º 1
0
 private void updateStateForChildFullyInBottomStack(
     StackScrollAlgorithmState algorithmState,
     float transitioningPositionStart,
     StackViewState childViewState,
     int childHeight,
     AmbientState ambientState) {
   Log.d(TAG, "updateStateForChildFullyInBottomStack: ");
   float currentYPosition;
   algorithmState.itemsInBottomStack += 1.0f;
   if (algorithmState.itemsInBottomStack < MAX_ITEMS_IN_BOTTOM_STACK) {
     // We are visually entering the bottom stack
     currentYPosition =
         transitioningPositionStart
             + mBottomStackIndentationFunctor.getValue(algorithmState.itemsInBottomStack)
             - mPaddingBetweenElements;
     childViewState.location = StackViewState.LOCATION_BOTTOM_STACK_PEEKING;
   } else {
     // we are fully inside the stack
     if (algorithmState.itemsInBottomStack > MAX_ITEMS_IN_BOTTOM_STACK + 2) {
       childViewState.alpha = 0.0f;
     } else if (algorithmState.itemsInBottomStack > MAX_ITEMS_IN_BOTTOM_STACK + 1) {
       childViewState.alpha = 1.0f - algorithmState.partialInBottom;
     }
     childViewState.location = StackViewState.LOCATION_BOTTOM_STACK_HIDDEN;
     currentYPosition = ambientState.getInnerHeight();
   }
   childViewState.yTranslation = currentYPosition - childHeight;
   clampPositionToTopStackEnd(childViewState, childHeight);
 }
Ejemplo n.º 2
0
  private void updateStateForTopStackChild(
      StackScrollAlgorithmState algorithmState,
      int numberOfElementsCompletelyIn,
      int i,
      int childHeight,
      StackViewState childViewState,
      float scrollOffset) {

    Log.d(TAG, "updateStateForTopStackChild: ");
    // First we calculate the index relative to the current stack window of size at most
    // {@link #MAX_ITEMS_IN_TOP_STACK}
    int paddedIndex = i - 1 - Math.max(numberOfElementsCompletelyIn - MAX_ITEMS_IN_TOP_STACK, 0);
    if (paddedIndex >= 0) {

      // We are currently visually entering the top stack
      float distanceToStack =
          (childHeight + mPaddingBetweenElements) - algorithmState.scrolledPixelsTop;
      if (i == algorithmState.lastTopStackIndex
          && distanceToStack > (mTopStackTotalSize + mPaddingBetweenElements)) {

        // Child is currently translating into stack but not yet inside slow down zone.
        // Handle it like the regular scrollview.
        childViewState.yTranslation = scrollOffset;
      } else {
        // Apply stacking logic.
        float numItemsBefore;
        if (i == algorithmState.lastTopStackIndex) {
          numItemsBefore =
              1.0f - (distanceToStack / (mTopStackTotalSize + mPaddingBetweenElements));
        } else {
          numItemsBefore = algorithmState.itemsInTopStack - i;
        }
        // The end position of the current child
        float currentChildEndY =
            mCollapsedSize
                + mTopStackTotalSize
                - mTopStackIndentationFunctor.getValue(numItemsBefore);
        childViewState.yTranslation = currentChildEndY - childHeight;
      }
      childViewState.location = StackViewState.LOCATION_TOP_STACK_PEEKING;
    } else {
      if (paddedIndex == -1) {
        childViewState.alpha = 1.0f - algorithmState.partialInTop;
      } else {
        // We are hidden behind the top card and faded out, so we can hide ourselves.
        childViewState.alpha = 0.0f;
      }
      childViewState.yTranslation = mCollapsedSize - childHeight;
      childViewState.location = StackViewState.LOCATION_TOP_STACK_HIDDEN;
    }
  }
Ejemplo n.º 3
0
  private void updateStateForChildTransitioningInBottom(
      StackScrollAlgorithmState algorithmState,
      float transitioningPositionStart,
      float bottomPeakStart,
      float currentYPosition,
      StackViewState childViewState,
      int childHeight) {
    Log.d(TAG, "updateStateForChildTransitioningInBottom: ");
    // This is the transitioning element on top of bottom stack, calculate how far we are in.
    algorithmState.partialInBottom =
        1.0f
            - ((transitioningPositionStart - currentYPosition)
                / (childHeight + mPaddingBetweenElements));

    // the offset starting at the transitionPosition of the bottom stack
    float offset = mBottomStackIndentationFunctor.getValue(algorithmState.partialInBottom);
    algorithmState.itemsInBottomStack += algorithmState.partialInBottom;
    int newHeight = childHeight;
    if (childHeight > mCollapsedSize && mIsSmallScreen) {
      newHeight =
          (int)
              Math.max(
                  Math.min(
                      transitioningPositionStart
                          + offset
                          - mPaddingBetweenElements
                          - currentYPosition,
                      childHeight),
                  mCollapsedSize);
      childViewState.height = newHeight;
    }
    childViewState.yTranslation =
        transitioningPositionStart + offset - newHeight - mPaddingBetweenElements;

    // We want at least to be at the end of the top stack when collapsing
    clampPositionToTopStackEnd(childViewState, newHeight);
    childViewState.location = StackViewState.LOCATION_MAIN_AREA;
  }