Search in sources :

Example 21 with ViewHolder

use of androidx.recyclerview.widget.RecyclerView.ViewHolder in project Lightning-Browser by anthonycr.

the class VerticalItemAnimator method animateChangeImpl.

private void animateChangeImpl(@NonNull 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 : ViewHolder(androidx.recyclerview.widget.RecyclerView.ViewHolder) ViewPropertyAnimatorCompat(androidx.core.view.ViewPropertyAnimatorCompat) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 22 with ViewHolder

use of androidx.recyclerview.widget.RecyclerView.ViewHolder in project Carbon by ZieIony.

the class ItemTouchHelper method onChildViewDetachedFromWindow.

@Override
public void onChildViewDetachedFromWindow(View view) {
    removeChildDrawingOrderCallbackIfNecessary(view);
    final ViewHolder holder = mRecyclerView.getChildViewHolder(view);
    if (holder == null) {
        return;
    }
    if (mSelected != null && holder == mSelected) {
        select(null, ACTION_STATE_IDLE);
    } else {
        // this may push it into pending cleanup list.
        endRecoverAnimation(holder, false);
        if (mPendingCleanup.remove(holder.itemView)) {
            mCallback.clearView(mRecyclerView, holder);
        }
    }
}
Also used : ViewHolder(androidx.recyclerview.widget.RecyclerView.ViewHolder)

Example 23 with ViewHolder

use of androidx.recyclerview.widget.RecyclerView.ViewHolder in project Carbon by ZieIony.

the class ItemTouchHelper method checkSelectForSwipe.

/**
 * Checks whether we should select a View for swiping.
 */
boolean checkSelectForSwipe(int action, MotionEvent motionEvent, int pointerIndex) {
    if (mSelected != null || action != MotionEvent.ACTION_MOVE || mActionState == ACTION_STATE_DRAG || !mCallback.isItemViewSwipeEnabled()) {
        return false;
    }
    if (mRecyclerView.getScrollState() == RecyclerView.SCROLL_STATE_DRAGGING) {
        return false;
    }
    final ViewHolder vh = findSwipedView(motionEvent);
    if (vh == null) {
        return false;
    }
    final int movementFlags = mCallback.getAbsoluteMovementFlags(mRecyclerView, vh);
    final int swipeFlags = (movementFlags & ACTION_MODE_SWIPE_MASK) >> (DIRECTION_FLAG_COUNT * ACTION_STATE_SWIPE);
    if (swipeFlags == 0) {
        return false;
    }
    // mDx and mDy are only set in allowed directions. We use custom x/y here instead of
    // updateDxDy to avoid swiping if user moves more in the other direction
    final float x = motionEvent.getX(pointerIndex);
    final float y = motionEvent.getY(pointerIndex);
    // Calculate the distance moved
    final float dx = x - mInitialTouchX;
    final float dy = y - mInitialTouchY;
    // swipe target is chose w/o applying flags so it does not really check if swiping in that
    // direction is allowed. This why here, we use mDx mDy to check slope value again.
    final float absDx = Math.abs(dx);
    final float absDy = Math.abs(dy);
    if (absDx < mSlop && absDy < mSlop) {
        return false;
    }
    if (absDx > absDy) {
        if (dx < 0 && (swipeFlags & LEFT) == 0) {
            return false;
        }
        if (dx > 0 && (swipeFlags & RIGHT) == 0) {
            return false;
        }
    } else {
        if (dy < 0 && (swipeFlags & UP) == 0) {
            return false;
        }
        if (dy > 0 && (swipeFlags & DOWN) == 0) {
            return false;
        }
    }
    mDx = mDy = 0f;
    mActivePointerId = motionEvent.getPointerId(0);
    select(vh, ACTION_STATE_SWIPE);
    return true;
}
Also used : ViewHolder(androidx.recyclerview.widget.RecyclerView.ViewHolder)

Aggregations

ViewHolder (androidx.recyclerview.widget.RecyclerView.ViewHolder)23 View (android.view.View)16 RecyclerView (androidx.recyclerview.widget.RecyclerView)16 AnimatedViewHolder (eu.davidea.viewholders.AnimatedViewHolder)6 ArrayList (java.util.ArrayList)4 ViewPropertyAnimatorCompat (androidx.core.view.ViewPropertyAnimatorCompat)3 NonNull (androidx.annotation.NonNull)2 Animator (android.animation.Animator)1 ValueAnimator (android.animation.ValueAnimator)1 ViewParent (android.view.ViewParent)1 Nullable (androidx.annotation.Nullable)1