Search in sources :

Example 11 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 12 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 13 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 14 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project Onboarding by eoinfogarty.

the class ImageAdapter method onCreateViewHolder.

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

Example 15 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project MovieGuide by esoxjem.

the class MoviesListingAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    holder.itemView.setOnClickListener(holder);
    holder.movie = movies.get(position);
    holder.name.setText(holder.movie.getTitle());
    Glide.with(context).load(holder.movie.getPosterPath()).asBitmap().diskCacheStrategy(DiskCacheStrategy.RESULT).into(new BitmapImageViewTarget(holder.poster) {

        @Override
        public void onResourceReady(Bitmap bitmap, GlideAnimation anim) {
            super.onResourceReady(bitmap, anim);
            Palette.from(bitmap).generate(new Palette.PaletteAsyncListener() {

                @Override
                public void onGenerated(Palette palette) {
                    holder.titleBackground.setBackgroundColor(palette.getVibrantColor(context.getResources().getColor(R.color.black_translucent_60)));
                }
            });
        }
    });
}
Also used : Palette(android.support.v7.graphics.Palette) Bitmap(android.graphics.Bitmap) BitmapImageViewTarget(com.bumptech.glide.request.target.BitmapImageViewTarget) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation)

Aggregations

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