@Override public boolean dispatchFinishedWhenDone() { if (mDebug && !isRunning()) { Log.d(TAG, "dispatchFinishedWhenDone()"); } return super.dispatchFinishedWhenDone(); }
@Override public void run() { result[0] = mAnimator.animateAdd(vh); } });
@Override public void run() { result[0] = mAnimator.animateChange(oldHolder, newHolder, fromX, fromY, toX, toY); } });
animator.setSupportsChangeAnimations(false); mRecyclerView.hasFixedSize(); mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
@Override public void endAnimations() { // end all pending animations mMoveAnimationsManager.endAllPendingAnimations(); mRemoveAnimationManager.endAllPendingAnimations(); mAddAnimationsManager.endAllPendingAnimations(); mChangeAnimationsManager.endAllPendingAnimations(); if (!isRunning()) { return; } // end all deferred animations mMoveAnimationsManager.endAllDeferredReadyAnimations(); mAddAnimationsManager.endAllDeferredReadyAnimations(); mChangeAnimationsManager.endAllDeferredReadyAnimations(); // cancel all started animations mRemoveAnimationManager.cancelAllStartedAnimations(); mMoveAnimationsManager.cancelAllStartedAnimations(); mAddAnimationsManager.cancelAllStartedAnimations(); mChangeAnimationsManager.cancelAllStartedAnimations(); dispatchAnimationsFinished(); }
@Override public void endAnimation(@NonNull RecyclerView.ViewHolder item) { // this will trigger end callback which should set properties to their target values. cancelAnimations(item); mMoveAnimationsManager.endPendingAnimations(item); mChangeAnimationsManager.endPendingAnimations(item); mRemoveAnimationManager.endPendingAnimations(item); mAddAnimationsManager.endPendingAnimations(item); mMoveAnimationsManager.endDeferredReadyAnimations(item); mChangeAnimationsManager.endDeferredReadyAnimations(item); mRemoveAnimationManager.endDeferredReadyAnimations(item); mAddAnimationsManager.endDeferredReadyAnimations(item); // animations should be ended by the cancel above. if (mRemoveAnimationManager.removeFromActive(item) && mDebug) { throw new IllegalStateException("after animation is cancelled, item should not be in the active animation list [remove]"); } if (mAddAnimationsManager.removeFromActive(item) && mDebug) { throw new IllegalStateException("after animation is cancelled, item should not be in the active animation list [add]"); } if (mChangeAnimationsManager.removeFromActive(item) && mDebug) { throw new IllegalStateException("after animation is cancelled, item should not be in the active animation list [change]"); } if (mMoveAnimationsManager.removeFromActive(item) && mDebug) { throw new IllegalStateException("after animation is cancelled, item should not be in the active animation list [move]"); } dispatchFinishedWhenDone(); }
@Override public void run() { result[0] = mAnimator.animateRemove(vh); } });
@Override public void run() { result[0] = mAnimator.animateMove(vh, fromX, fromY, toX, toY); } });
/** * {@inheritDoc} * <p> * If the payload list is not empty, RefactoredDefaultItemAnimator returns <code>true</code>. * When this is the case: * <ul> * <li>If you override {@link #animateChange(RecyclerView.ViewHolder, RecyclerView.ViewHolder, int, int, int, int)}, both * ViewHolder arguments will be the same instance. * </li> * <li> * If you are not overriding {@link #animateChange(RecyclerView.ViewHolder, RecyclerView.ViewHolder, int, int, int, int)}, * then RefactoredDefaultItemAnimator will call {@link #animateMove(RecyclerView.ViewHolder, int, int, int, int)} and * run a move animation instead. * </li> * </ul> */ @Override public boolean canReuseUpdatedViewHolder(@NonNull RecyclerView.ViewHolder viewHolder, @NonNull List<Object> payloads) { return !payloads.isEmpty() || super.canReuseUpdatedViewHolder(viewHolder, payloads); }
animator.setSupportsChangeAnimations(false); mRecyclerView.hasFixedSize(); mRecyclerView.setLayoutManager(new LinearLayoutManager(context));
@Test public void testAnimateAdd() throws Throwable { ViewHolder vh = createViewHolder(1); expectItems(1); assertTrue(animateAdd(vh)); assertTrue(mAnimator.isRunning()); runAndWait(1); }
mRecyclerView.setAdapter(mAdapter); final GeneralItemAnimator animator = new SwipeDismissItemAnimator(); animator.setSupportsChangeAnimations(false); mRecyclerView.setItemAnimator(animator); AutoStaggeredGridLayoutManager layoutManager = new AutoStaggeredGridLayoutManager(
@Test public void testAnimateRemove() throws Throwable { ViewHolder vh = createViewHolder(1); expectItems(1); assertTrue(animateRemove(vh)); assertTrue(mAnimator.isRunning()); runAndWait(1); }
animator.setSupportsChangeAnimations(false);
@Test public void testAnimateMove() throws Throwable { ViewHolder vh = createViewHolder(1); expectItems(1); assertTrue(animateMove(vh, 0, 0, 100, 100)); assertTrue(mAnimator.isRunning()); runAndWait(1); }
@Test public void testAnimateChange() throws Throwable { ViewHolder vh = createViewHolder(1); ViewHolder vh2 = createViewHolder(2); expectItems(2); assertTrue(animateChange(vh, vh2, 0, 0, 100, 100)); assertTrue(mAnimator.isRunning()); runAndWait(1); }