예제 #1
0
  /** Synchronizes the views with the model */
  boolean synchronizeStackViewsWithModel() {
    if (mStackViewsDirty) {
      // Get all the task transforms
      ArrayList<T> data = mCallback.getData();
      float stackScroll = mStackScroller.getStackScroll();
      int[] visibleRange = mTmpVisibleRange;
      boolean isValidVisibleRange =
          updateStackTransforms(mCurrentTaskTransforms, data, stackScroll, visibleRange, false);

      // Return all the invisible children to the pool
      mTmpTaskViewMap.clear();
      int childCount = getChildCount();
      for (int i = childCount - 1; i >= 0; i--) {
        DeckChildView<T> tv = (DeckChildView) getChildAt(i);
        T key = tv.getAttachedKey();
        int taskIndex = data.indexOf(key);

        if (visibleRange[1] <= taskIndex && taskIndex <= visibleRange[0]) {
          mTmpTaskViewMap.put(key, tv);
        } else {
          mViewPool.returnViewToPool(tv);
        }
      }

      for (int i = visibleRange[0]; isValidVisibleRange && i >= visibleRange[1]; i--) {
        T key = data.get(i);
        DeckChildViewTransform transform = mCurrentTaskTransforms.get(i);
        DeckChildView tv = mTmpTaskViewMap.get(key);

        if (tv == null) {
          // TODO Check
          tv = mViewPool.pickUpViewFromPool(key, key);

          if (mStackViewsAnimationDuration > 0) {
            // For items in the list, put them in start animating them from the
            // approriate ends of the list where they are expected to appear
            if (Float.compare(transform.p, 0f) <= 0) {
              mLayoutAlgorithm.getStackTransform(0f, 0f, mTmpTransform, null);
            } else {
              mLayoutAlgorithm.getStackTransform(1f, 0f, mTmpTransform, null);
            }
            tv.updateViewPropertiesToTaskTransform(mTmpTransform, 0);
          }
        }

        // Animate the task into place
        tv.updateViewPropertiesToTaskTransform(
            mCurrentTaskTransforms.get(i),
            mStackViewsAnimationDuration,
            mRequestUpdateClippingListener);
      }

      // Reset the request-synchronize params
      mStackViewsAnimationDuration = 0;
      mStackViewsDirty = false;
      mStackViewsClipDirty = true;
      return true;
    }
    return false;
  }
예제 #2
0
  /** Gets the stack transforms of a list of tasks, and returns the visible range of tasks. */
  private boolean updateStackTransforms(
      ArrayList<DeckChildViewTransform> taskTransforms,
      ArrayList<T> data,
      float stackScroll,
      int[] visibleRangeOut,
      boolean boundTranslationsToRect) {
    int taskTransformCount = taskTransforms.size();
    int taskCount = data.size();
    int frontMostVisibleIndex = -1;
    int backMostVisibleIndex = -1;

    // We can reuse the task transforms where possible to reduce object allocation
    if (taskTransformCount < taskCount) {
      // If there are less transforms than tasks, then add as many transforms as necessary
      for (int i = taskTransformCount; i < taskCount; i++) {
        taskTransforms.add(new DeckChildViewTransform());
      }
    } else if (taskTransformCount > taskCount) {
      // If there are more transforms than tasks, then just subset the transform list
      taskTransforms.subList(0, taskCount);
    }

    // Update the stack transforms
    DeckChildViewTransform prevTransform = null;
    for (int i = taskCount - 1; i >= 0; i--) {
      DeckChildViewTransform transform =
          mLayoutAlgorithm.getStackTransform(
              data.get(i), stackScroll, taskTransforms.get(i), prevTransform);
      if (transform.visible) {
        if (frontMostVisibleIndex < 0) {
          frontMostVisibleIndex = i;
        }
        backMostVisibleIndex = i;
      } else {
        if (backMostVisibleIndex != -1) {
          // We've reached the end of the visible range, so going down the rest of the
          // stack, we can just reset the transforms accordingly
          while (i >= 0) {
            taskTransforms.get(i).reset();
            i--;
          }
          break;
        }
      }

      if (boundTranslationsToRect) {
        transform.translationY =
            Math.min(transform.translationY, mLayoutAlgorithm.mViewRect.bottom);
      }
      prevTransform = transform;
    }
    if (visibleRangeOut != null) {
      visibleRangeOut[0] = frontMostVisibleIndex;
      visibleRangeOut[1] = backMostVisibleIndex;
    }
    return frontMostVisibleIndex != -1 && backMostVisibleIndex != -1;
  }
예제 #3
0
  /** Updates the min and max virtual scroll bounds */
  void updateMinMaxScroll(
      boolean boundScrollToNewMinMax, boolean launchedWithAltTab, boolean launchedFromHome) {
    // Compute the min and max scroll values
    mLayoutAlgorithm.computeMinMaxScroll(mCallback.getData(), launchedWithAltTab, launchedFromHome);

    // Debug logging
    if (true) {
      mStackScroller.boundScroll();
    }
  }
예제 #4
0
  public void notifyDataSetChanged() {
    // Get the stack scroll of the task to anchor to (since we are removing something, the front
    // most task will be our anchor task)
    T anchorTask = null;
    float prevAnchorTaskScroll = 0;
    boolean pullStackForward = mCallback.getData().size() > 0;
    if (pullStackForward) {
      anchorTask = mCallback.getData().get(mCallback.getData().size() - 1);
      prevAnchorTaskScroll = mLayoutAlgorithm.getStackScrollForTask(anchorTask);
    }

    // Update the min/max scroll and animate other task views into their new positions
    updateMinMaxScroll(true, mConfig.launchedWithAltTab, mConfig.launchedFromHome);

    // Offset the stack by as much as the anchor task would otherwise move back
    if (pullStackForward) {
      float anchorTaskScroll = mLayoutAlgorithm.getStackScrollForTask(anchorTask);
      mStackScroller.setStackScroll(
          mStackScroller.getStackScroll() + (anchorTaskScroll - prevAnchorTaskScroll));
      mStackScroller.boundScroll();
    }

    // Animate all the tasks into place
    requestSynchronizeStackViewsWithModel(200);

    T newFrontMostTask =
        mCallback.getData().size() > 0
            ? mCallback.getData().get(mCallback.getData().size() - 1)
            : null;
    // Update the new front most task
    if (newFrontMostTask != null) {
      DeckChildView<T> frontTv = getChildViewForTask(newFrontMostTask);
      if (frontTv != null) {
        frontTv.onTaskBound(newFrontMostTask);
      }
    }

    // If there are no remaining tasks
    if (mCallback.getData().size() == 0) {
      mCallback.onNoViewsToDeck();
    }
  }
예제 #5
0
  /** Computes the stack and task rects */
  public void computeRects(
      int windowWidth,
      int windowHeight,
      Rect taskStackBounds,
      boolean launchedWithAltTab,
      boolean launchedFromHome) {
    // Compute the rects in the stack algorithm
    mLayoutAlgorithm.computeRects(windowWidth, windowHeight, taskStackBounds);

    // Update the scroll bounds
    updateMinMaxScroll(false, launchedWithAltTab, launchedFromHome);
  }
예제 #6
0
  /** Focuses the task at the specified index in the stack */
  public void scrollToChild(int childIndex) {
    if (getCurrentChildIndex() == childIndex) return;

    if (0 <= childIndex && childIndex < mCallback.getData().size()) {
      // Scroll the view into position (just center it in the curve)
      float newScroll =
          mLayoutAlgorithm.getStackScrollForTask(mCallback.getData().get(childIndex)) - 0.5f;
      newScroll = mStackScroller.getBoundedStackScroll(newScroll);
      mStackScroller.setStackScroll(newScroll);
      // Alternate (animated) way
      // mStackScroller.animateScroll(mStackScroller.getStackScroll(), newScroll, null);
    }
  }
예제 #7
0
  /** Focuses the task at the specified index in the stack */
  void focusTask(int childIndex, boolean scrollToNewPosition, final boolean animateFocusedState) {
    // Return early if the task is already focused
    if (childIndex == mFocusedTaskIndex) return;

    ArrayList<T> data = mCallback.getData();

    if (0 <= childIndex && childIndex < data.size()) {
      mFocusedTaskIndex = childIndex;

      // Focus the view if possible, otherwise, focus the view after we scroll into position
      T key = data.get(childIndex);
      DeckChildView tv = getChildViewForTask(key);
      Runnable postScrollRunnable = null;
      if (tv != null) {
        tv.setFocusedTask(animateFocusedState);
      } else {
        postScrollRunnable =
            new Runnable() {
              @Override
              public void run() {

                DeckChildView tv = getChildViewForTask(mCallback.getData().get(mFocusedTaskIndex));
                if (tv != null) {
                  tv.setFocusedTask(animateFocusedState);
                }
              }
            };
      }

      // Scroll the view into position (just center it in the curve)
      if (scrollToNewPosition) {
        float newScroll = mLayoutAlgorithm.getStackScrollForTask(key) - 0.5f;
        newScroll = mStackScroller.getBoundedStackScroll(newScroll);
        mStackScroller.animateScroll(
            mStackScroller.getStackScroll(), newScroll, postScrollRunnable);
      } else {
        if (postScrollRunnable != null) {
          postScrollRunnable.run();
        }
      }
    }
  }
예제 #8
0
  /** Requests this task stacks to start it's enter-recents animation */
  public void startEnterRecentsAnimation(ViewAnimation.TaskViewEnterContext ctx) {
    // If we are still waiting to layout, then just defer until then
    if (mAwaitingFirstLayout) {
      mStartEnterAnimationRequestedAfterLayout = true;
      mStartEnterAnimationContext = ctx;
      return;
    }

    if (mCallback.getData().size() > 0) {
      int childCount = getChildCount();

      // Animate all the task views into view
      for (int i = childCount - 1; i >= 0; i--) {
        DeckChildView<T> tv = (DeckChildView) getChildAt(i);
        T key = tv.getAttachedKey();
        ctx.currentTaskTransform = new DeckChildViewTransform();
        ctx.currentStackViewIndex = i;
        ctx.currentStackViewCount = childCount;
        ctx.currentTaskRect = mLayoutAlgorithm.mTaskRect;
        // TODO: this needs to go
        ctx.currentTaskOccludesLaunchTarget = false;
        ctx.updateListener = mRequestUpdateClippingListener;
        mLayoutAlgorithm.getStackTransform(
            key, mStackScroller.getStackScroll(), ctx.currentTaskTransform, null);
        tv.startEnterRecentsAnimation(ctx);
      }

      // Add a runnable to the post animation ref counter to clear all the views
      ctx.postAnimationTrigger.addLastDecrementRunnable(
          new Runnable() {
            @Override
            public void run() {
              mStartEnterAnimationCompleted = true;
              // Poke the dozer to restart the trigger after the animation completes
              mUIDozeTrigger.poke();
            }
          });
    }
  }
예제 #9
0
 /**
  * Computes the maximum number of visible tasks and thumbnails. Requires that
  * updateMinMaxScrollForStack() is called first.
  */
 public DeckViewLayoutAlgorithm.VisibilityReport computeStackVisibilityReport() {
   return mLayoutAlgorithm.computeStackVisibilityReport(mCallback.getData());
 }