@Override
 public boolean animateChange(
     RecyclerView.ViewHolder oldHolder,
     RecyclerView.ViewHolder newHolder,
     int fromX,
     int fromY,
     int toX,
     int toY) {
   if (oldHolder == newHolder) {
     // Don't know how to run change animations when the same view holder is re-used.
     // run a move animation to handle position changes.
     return animateMove(oldHolder, fromX, fromY, toX, toY);
   }
   final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
   final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
   final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
   resetAnimation(oldHolder);
   int deltaX = (int) (toX - fromX - prevTranslationX);
   int deltaY = (int) (toY - fromY - prevTranslationY);
   // recover prev translation state after ending animation
   ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
   ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
   ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
   if (newHolder != null) {
     // carry over translation values
     resetAnimation(newHolder);
     ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
     ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
     ViewCompat.setAlpha(newHolder.itemView, 0);
   }
   mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
   return true;
 }
  @Override
  protected Rect getDividerBound(int position, RecyclerView parent, View child) {
    Rect bounds = new Rect(0, 0, 0, 0);
    int transitionX = (int) ViewCompat.getTranslationX(child);
    int transitionY = (int) ViewCompat.getTranslationY(child);
    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
    bounds.top =
        parent.getPaddingTop() + mMarginProvider.dividerTopMargin(position, parent) + transitionY;
    bounds.bottom =
        parent.getHeight()
            - parent.getPaddingBottom()
            - mMarginProvider.dividerBottomMargin(position, parent)
            + transitionY;

    int dividerSize = getDividerSize(position, parent);
    if (mDividerType == DividerType.DRAWABLE) {
      bounds.left = child.getRight() + params.leftMargin + transitionX;
      bounds.right = bounds.left + dividerSize;
    } else {
      bounds.left = child.getRight() + params.leftMargin + dividerSize / 2 + transitionX;
      bounds.right = bounds.left;
    }

    return bounds;
  }
  private boolean animateSlideInternal(
      RecyclerView.ViewHolder holder,
      boolean horizontal,
      int translationX,
      int translationY,
      long duration,
      Interpolator interpolator,
      SwipeFinishInfo swipeFinish) {
    if (!(holder instanceof SwipeableItemViewHolder)) {
      return false;
    }

    final View containerView = ((SwipeableItemViewHolder) holder).getSwipeableContainerView();

    final int prevTranslationX = (int) (ViewCompat.getTranslationX(containerView) + 0.5f);
    final int prevTranslationY = (int) (ViewCompat.getTranslationY(containerView) + 0.5f);

    endAnimation(holder);

    final int curTranslationX = (int) (ViewCompat.getTranslationX(containerView) + 0.5f);
    final int curTranslationY = (int) (ViewCompat.getTranslationY(containerView) + 0.5f);
    //noinspection UnnecessaryLocalVariable
    final int toX = translationX;
    //noinspection UnnecessaryLocalVariable
    final int toY = translationY;

    if ((duration == 0)
        || (curTranslationX == toX && curTranslationY == toY)
        || (Math.max(Math.abs(toX - prevTranslationX), Math.abs(toY - prevTranslationY))
            <= mImmediatelySetTranslationThreshold)) {
      ViewCompat.setTranslationX(containerView, toX);
      ViewCompat.setTranslationY(containerView, toY);

      return false;
    }

    ViewCompat.setTranslationX(containerView, prevTranslationX);
    ViewCompat.setTranslationY(containerView, prevTranslationY);

    SlidingAnimatorListenerObject listener =
        new SlidingAnimatorListenerObject(
            mAdapter, mActive, holder, toX, toY, duration, horizontal, interpolator, swipeFinish);

    listener.start();

    return true;
  }
 public int getSwipeContainerViewTranslationY(RecyclerView.ViewHolder holder) {
   if (supportsViewPropertyAnimator()) {
     final View containerView = ((SwipeableItemViewHolder) holder).getSwipeableContainerView();
     return (int) (ViewCompat.getTranslationY(containerView) + 0.5f);
   } else {
     return getTranslationYPreHoneycomb(holder);
   }
 }
    @Override
    public void onAnimationUpdate(View view) {
      float translation =
          mHorizontal ? ViewCompat.getTranslationX(view) : ViewCompat.getTranslationY(view);
      float amount = translation * mInvSize;

      mAdapter.onUpdateSlideAmount(
          mViewHolder, mViewHolder.getLayoutPosition(), amount, true, mHorizontal, false);
    }
  @Override
  public boolean onCheckCanStartDrag(MyViewHolder holder, int position, int x, int y) {
    // x, y --- relative from the itemView's top-left
    final View containerView = holder.mContainer;
    final View dragHandleView = holder.mDragHandle;

    final int offsetX =
        containerView.getLeft() + (int) (ViewCompat.getTranslationX(containerView) + 0.5f);
    final int offsetY =
        containerView.getTop() + (int) (ViewCompat.getTranslationY(containerView) + 0.5f);

    return ViewUtils.hitTest(dragHandleView, x - offsetX, y - offsetY);
  }
Exemplo n.º 7
0
 @Override
 public boolean animateMove(final ViewHolder holder, int fromX, int fromY, int toX, int toY) {
   final View view = holder.itemView;
   fromX += ViewCompat.getTranslationX(holder.itemView);
   fromY += ViewCompat.getTranslationY(holder.itemView);
   endAnimation(holder);
   int deltaX = toX - fromX;
   int deltaY = toY - fromY;
   if (deltaX == 0 && deltaY == 0) {
     dispatchMoveFinished(holder);
     return false;
   }
   if (deltaX != 0) {
     ViewCompat.setTranslationX(view, -deltaX);
   }
   if (deltaY != 0) {
     ViewCompat.setTranslationY(view, -deltaY);
   }
   mPendingMoves.add(new MoveInfo(holder, fromX, fromY, toX, toY));
   return true;
 }
 public boolean animateChange(RecyclerView.ViewHolder paramViewHolder1, RecyclerView.ViewHolder paramViewHolder2, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
 {
   float f1 = ViewCompat.getTranslationX(itemView);
   float f2 = ViewCompat.getTranslationY(itemView);
   float f3 = ViewCompat.getAlpha(itemView);
   endAnimation(paramViewHolder1);
   int i = (int)(paramInt3 - paramInt1 - f1);
   int j = (int)(paramInt4 - paramInt2 - f2);
   ViewCompat.setTranslationX(itemView, f1);
   ViewCompat.setTranslationY(itemView, f2);
   ViewCompat.setAlpha(itemView, f3);
   if ((paramViewHolder2 != null) && (itemView != null))
   {
     endAnimation(paramViewHolder2);
     ViewCompat.setTranslationX(itemView, -i);
     ViewCompat.setTranslationY(itemView, -j);
     ViewCompat.setAlpha(itemView, 0.0F);
   }
   mPendingChanges.add(new DefaultItemAnimator.ChangeInfo(paramViewHolder1, paramViewHolder2, paramInt1, paramInt2, paramInt3, paramInt4, null));
   return true;
 }
 public boolean animateMove(RecyclerView.ViewHolder paramViewHolder, int paramInt1, int paramInt2, int paramInt3, int paramInt4)
 {
   View localView = itemView;
   paramInt1 = (int)(paramInt1 + ViewCompat.getTranslationX(itemView));
   paramInt2 = (int)(paramInt2 + ViewCompat.getTranslationY(itemView));
   endAnimation(paramViewHolder);
   int i = paramInt3 - paramInt1;
   int j = paramInt4 - paramInt2;
   if ((i == 0) && (j == 0))
   {
     dispatchMoveFinished(paramViewHolder);
     return false;
   }
   if (i != 0) {
     ViewCompat.setTranslationX(localView, -i);
   }
   if (j != 0) {
     ViewCompat.setTranslationY(localView, -j);
   }
   mPendingMoves.add(new DefaultItemAnimator.MoveInfo(paramViewHolder, paramInt1, paramInt2, paramInt3, paramInt4, null));
   return true;
 }
  private void drawHeaders(Canvas c, RecyclerView parent, RecyclerView.State state) {
    final int childCount = parent.getChildCount();
    final RecyclerView.LayoutManager lm = parent.getLayoutManager();
    Float lastY = null;

    for (int i = childCount - 1; i >= 0; i--) {
      View child = parent.getChildAt(i);
      RecyclerView.LayoutParams lp = (RecyclerView.LayoutParams) child.getLayoutParams();
      RecyclerView.ViewHolder holder = parent.getChildViewHolder(child);

      if (!lp.isItemRemoved() && !lp.isViewInvalid()) {

        float translationY = ViewCompat.getTranslationY(child);

        if ((i == 0 && headerStore.isSticky()) || headerStore.isHeader(holder)) {

          View header = headerStore.getHeaderViewByItem(holder);

          if (header.getVisibility() == View.VISIBLE) {

            int headerHeight = headerStore.getHeaderHeight(holder);
            float y = getHeaderY(child, lm) + translationY;

            if (headerStore.isSticky() && lastY != null && lastY < y + headerHeight) {
              y = lastY - headerHeight;
            }

            c.save();
            c.translate(0, y);
            header.draw(c);
            c.restore();

            lastY = y;
          }
        }
      }
    }
  }
Exemplo n.º 11
0
 @Override
 public boolean animateChange(
     ViewHolder oldHolder, ViewHolder newHolder, int fromX, int fromY, int toX, int toY) {
   final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
   final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
   final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
   endAnimation(oldHolder);
   int deltaX = (int) (toX - fromX - prevTranslationX);
   int deltaY = (int) (toY - fromY - prevTranslationY);
   // recover prev translation state after ending animation
   ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
   ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
   ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
   if (newHolder != null && newHolder.itemView != null) {
     // carry over translation values
     endAnimation(newHolder);
     ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
     ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
     ViewCompat.setAlpha(newHolder.itemView, 0);
   }
   mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
   return true;
 }