Search in sources :

Example 76 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project FlexibleAdapter by davideas.

the class FlexibleItemAnimator method animateChangeImpl.

private void animateChangeImpl(final ChangeInfo changeInfo) {
    final ViewHolder holder = changeInfo.oldHolder;
    final View view = holder == null ? null : holder.itemView;
    final ViewHolder newHolder = changeInfo.newHolder;
    final View newView = newHolder != null ? newHolder.itemView : null;
    if (view != null) {
        final ViewPropertyAnimatorCompat oldViewAnim = ViewCompat.animate(view).setDuration(getChangeDuration());
        mChangeAnimations.add(changeInfo.oldHolder);
        oldViewAnim.translationX(changeInfo.toX - changeInfo.fromX);
        oldViewAnim.translationY(changeInfo.toY - changeInfo.fromY);
        oldViewAnim.alpha(0).setListener(new VpaListenerAdapter() {

            @Override
            public void onAnimationStart(View view) {
                dispatchChangeStarting(changeInfo.oldHolder, true);
            }

            @Override
            public void onAnimationEnd(View view) {
                oldViewAnim.setListener(null);
                ViewCompat.setAlpha(view, 1);
                ViewCompat.setTranslationX(view, 0);
                ViewCompat.setTranslationY(view, 0);
                dispatchChangeFinished(changeInfo.oldHolder, true);
                mChangeAnimations.remove(changeInfo.oldHolder);
                dispatchFinishedWhenDone();
            }
        }).start();
    }
    if (newView != null) {
        final ViewPropertyAnimatorCompat newViewAnimation = ViewCompat.animate(newView);
        mChangeAnimations.add(changeInfo.newHolder);
        newViewAnimation.translationX(0).translationY(0).setDuration(getChangeDuration()).alpha(1).setListener(new VpaListenerAdapter() {

            @Override
            public void onAnimationStart(View view) {
                dispatchChangeStarting(changeInfo.newHolder, false);
            }

            @Override
            public void onAnimationEnd(View view) {
                newViewAnimation.setListener(null);
                ViewCompat.setAlpha(newView, 1);
                ViewCompat.setTranslationX(newView, 0);
                ViewCompat.setTranslationY(newView, 0);
                dispatchChangeFinished(changeInfo.newHolder, false);
                mChangeAnimations.remove(changeInfo.newHolder);
                dispatchFinishedWhenDone();
            }
        }).start();
    }
}
Also used : AnimatedViewHolder(eu.davidea.viewholders.AnimatedViewHolder) ViewHolder(android.support.v7.widget.RecyclerView.ViewHolder) ViewPropertyAnimatorCompat(android.support.v4.view.ViewPropertyAnimatorCompat) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 77 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project FlexibleAdapter by davideas.

the class FlexibleItemAnimator method endAnimation.

@Override
public void endAnimation(ViewHolder item) {
    final View view = item.itemView;
    // This will trigger end callback which should set properties to their target values.
    ViewCompat.animate(view).cancel();
    // TODO: if some other animations are chained to end, how do we cancel them as well?
    for (int i = mPendingMoves.size() - 1; i >= 0; i--) {
        MoveInfo moveInfo = mPendingMoves.get(i);
        if (moveInfo.holder == item) {
            ViewCompat.setTranslationY(view, 0);
            ViewCompat.setTranslationX(view, 0);
            dispatchMoveFinished(item);
            mPendingMoves.remove(i);
        }
    }
    endChangeAnimation(mPendingChanges, item);
    if (mPendingRemovals.remove(item)) {
        clear(item.itemView);
        dispatchRemoveFinished(item);
    }
    if (mPendingAdditions.remove(item)) {
        clear(item.itemView);
        dispatchAddFinished(item);
    }
    for (int i = mChangesList.size() - 1; i >= 0; i--) {
        ArrayList<ChangeInfo> changes = mChangesList.get(i);
        endChangeAnimation(changes, item);
        if (changes.isEmpty()) {
            mChangesList.remove(i);
        }
    }
    for (int i = mMovesList.size() - 1; i >= 0; i--) {
        ArrayList<MoveInfo> moves = mMovesList.get(i);
        for (int j = moves.size() - 1; j >= 0; j--) {
            MoveInfo moveInfo = moves.get(j);
            if (moveInfo.holder == item) {
                ViewCompat.setTranslationY(view, 0);
                ViewCompat.setTranslationX(view, 0);
                dispatchMoveFinished(item);
                moves.remove(j);
                if (moves.isEmpty()) {
                    mMovesList.remove(i);
                }
                break;
            }
        }
    }
    for (int i = mAdditionsList.size() - 1; i >= 0; i--) {
        ArrayList<ViewHolder> additions = mAdditionsList.get(i);
        if (additions.remove(item)) {
            clear(item.itemView);
            dispatchAddFinished(item);
            if (additions.isEmpty()) {
                mAdditionsList.remove(i);
            }
        }
    }
    // Animations should be ended by the cancel above.
    // Used during DEBUGGING; Commented in final version.
    //		if (mRemoveAnimations.remove(item)) {
    //			throw new IllegalStateException(
    //					"After animation is cancelled, item should not be in mRemoveAnimations list");
    //		}
    //		if (mAddAnimations.remove(item)) {
    //			throw new IllegalStateException(
    //					"After animation is cancelled, item should not be in mAddAnimations list");
    //		}
    //		if (mChangeAnimations.remove(item)) {
    //			throw new IllegalStateException(
    //					"After animation is cancelled, item should not be in mChangeAnimations list");
    //		}
    //		if (mMoveAnimations.remove(item)) {
    //			throw new IllegalStateException(
    //					"After animation is cancelled, item should not be in mMoveAnimations list");
    //		}
    dispatchFinishedWhenDone();
}
Also used : AnimatedViewHolder(eu.davidea.viewholders.AnimatedViewHolder) ViewHolder(android.support.v7.widget.RecyclerView.ViewHolder) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 78 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project FlexibleAdapter by davideas.

the class FlexibleItemAnimator method animateMoveImpl.

private void animateMoveImpl(final ViewHolder holder, int fromX, int fromY, int toX, int toY) {
    final View view = holder.itemView;
    final int deltaX = toX - fromX;
    final int deltaY = toY - fromY;
    if (deltaX != 0) {
        ViewCompat.animate(view).translationX(0);
    }
    if (deltaY != 0) {
        ViewCompat.animate(view).translationY(0);
    }
    // TODO: make EndActions end listeners instead, since end actions aren't called when
    // VPAs are canceled (and can't end them. why?)
    // Need listener functionality in VPACompat for this. Ick.
    mMoveAnimations.add(holder);
    final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
    animation.setDuration(getMoveDuration()).setListener(new VpaListenerAdapter() {

        @Override
        public void onAnimationStart(View view) {
            dispatchMoveStarting(holder);
        }

        @Override
        public void onAnimationCancel(View view) {
            if (deltaX != 0) {
                ViewCompat.setTranslationX(view, 0);
            }
            if (deltaY != 0) {
                ViewCompat.setTranslationY(view, 0);
            }
        }

        @Override
        public void onAnimationEnd(View view) {
            animation.setListener(null);
            dispatchMoveFinished(holder);
            mMoveAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
}
Also used : ViewPropertyAnimatorCompat(android.support.v4.view.ViewPropertyAnimatorCompat) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 79 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project plaid by nickbutcher.

the class GridItemDividerDecoration method onDrawOver.

@Override
public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
    if (parent.isAnimating())
        return;
    final int childCount = parent.getChildCount();
    final RecyclerView.LayoutManager lm = parent.getLayoutManager();
    for (int i = 0; i < childCount; i++) {
        final View child = parent.getChildAt(i);
        RecyclerView.ViewHolder viewHolder = parent.getChildViewHolder(child);
        if (requiresDivider(viewHolder)) {
            final int right = lm.getDecoratedRight(child);
            final int bottom = lm.getDecoratedBottom(child);
            // draw the bottom divider
            canvas.drawRect(lm.getDecoratedLeft(child), bottom - dividerSize, right, bottom, paint);
            // draw the right edge divider
            canvas.drawRect(right - dividerSize, lm.getDecoratedTop(child), right, bottom - dividerSize, paint);
        }
    }
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Paint(android.graphics.Paint)

Example 80 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project Android by WilliamYi96.

the class FruitAdapter method onCreateViewHolder.

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.fruit_item, parent, false);
    ViewHolder holder = new ViewHolder(view);
    return holder;
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) ImageView(android.widget.ImageView) View(android.view.View)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)265 View (android.view.View)248 TextView (android.widget.TextView)129 ImageView (android.widget.ImageView)95 ViewHolder (android.support.v7.widget.RecyclerView.ViewHolder)47 LayoutInflater (android.view.LayoutInflater)34 ViewGroup (android.view.ViewGroup)32 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)28 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)27 Intent (android.content.Intent)26 ArrayList (java.util.ArrayList)25 Context (android.content.Context)21 ViewPropertyAnimatorCompat (android.support.v4.view.ViewPropertyAnimatorCompat)17 BindView (butterknife.BindView)17 CardView (android.support.v7.widget.CardView)15 Paint (android.graphics.Paint)11 ParallaxRecyclerAdapter (com.poliveira.parallaxrecycleradapter.ParallaxRecyclerAdapter)8 ExampleData (de.madcyph3r.example.data.ExampleData)8 Drawable (android.graphics.drawable.Drawable)7 Test (org.junit.Test)7