예제 #1
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();
        }
      }
    }
  }