Exemplo n.º 1
0
  @Override
  public void prepareViewToLeavePool(DeckChildView<T> dcv, T key, boolean isNewView) {
    // It is possible for a view to be returned to the view pool before it is laid out,
    // which means that we will need to relayout the view when it is first used next.
    boolean requiresRelayout = dcv.getWidth() <= 0 && !isNewView;

    // Rebind the task and request that this task's data be filled into the TaskView
    dcv.onTaskBound(key);

    // Load the task data
    mCallback.loadViewData(new WeakReference<DeckChildView<T>>(dcv), key);

    // If the doze trigger has already fired, then update the state for this task view
    if (mUIDozeTrigger.hasTriggered()) {
      dcv.setNoUserInteractionState();
    }

    // If we've finished the start animation, then ensure we always enable the focus animations
    if (mStartEnterAnimationCompleted) {
      dcv.enableFocusAnimations();
    }

    // Find the index where this task should be placed in the stack
    int insertIndex = -1;
    int position = mCallback.getData().indexOf(key);
    if (position != -1) {
      int childCount = getChildCount();
      for (int i = 0; i < childCount; i++) {
        T otherKey = ((DeckChildView<T>) getChildAt(i)).getAttachedKey();
        int pos = mCallback.getData().indexOf(otherKey);
        if (position < pos) {
          insertIndex = i;
          break;
        }
      }
    }

    // Add/attach the view to the hierarchy
    if (isNewView) {
      addView(dcv, insertIndex);
    } else {
      attachViewToParent(dcv, insertIndex, dcv.getLayoutParams());
      if (requiresRelayout) {
        dcv.requestLayout();
      }
    }

    // Set the new state for this view, including the callbacks and view clipping
    dcv.setCallbacks(this);
    dcv.setTouchEnabled(true);
    dcv.setClipViewInStack(true);
  }