@OverridepublicbooleananimateChange(@NonNullRecyclerView.ViewHolderoldHolder,@NonNullRecyclerView.ViewHoldernewHolder,@NonNullItemHolderInfopreInfo,@NonNullItemHolderInfopostInfo){if(DEBUG){Log.d(TAG,"CHANGED: "+oldHolder+" with view "+oldHolder.itemView);}finalintfromLeft=preInfo.left;finalintfromTop=preInfo.top;finalinttoLeft,toTop;if(newHolder.shouldIgnore()){toLeft=preInfo.left;toTop=preInfo.top;}else{toLeft=postInfo.left;toTop=postInfo.top;}returnanimateChange(oldHolder,newHolder,fromLeft,fromTop,toLeft,toTop);}
@OverridepublicbooleananimateChange(RecyclerView.ViewHolderoldHolder,RecyclerView.ViewHoldernewHolder,intfromX,intfromY,inttoX,inttoY){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.returnanimateMove(oldHolder,fromX,fromY,toX,toY);}finalfloatprevTranslationX=oldHolder.itemView.getTranslationX();finalfloatprevTranslationY=oldHolder.itemView.getTranslationY();finalfloatprevAlpha=oldHolder.itemView.getAlpha();resetAnimation(oldHolder);intdeltaX=(int)(toX-fromX-prevTranslationX);intdeltaY=(int)(toY-fromY-prevTranslationY);// recover prev translation state after ending animationoldHolder.itemView.setTranslationX(prevTranslationX);oldHolder.itemView.setTranslationY(prevTranslationY);oldHolder.itemView.setAlpha(prevAlpha);if(newHolder!=null){// carry over translation valuesresetAnimation(newHolder);newHolder.itemView.setTranslationX(-deltaX);newHolder.itemView.setTranslationY(-deltaY);newHolder.itemView.setAlpha(0);}mPendingChanges.add(newChangeInfo(oldHolder,newHolder,fromX,fromY,toX,toY));returntrue;}
voidprocess(ProcessCallbackcallback){for(intindex=mLayoutHolderMap.size()-1;index>=0;index--){finalRecyclerView.ViewHolderviewHolder=mLayoutHolderMap.keyAt(index);finalInfoRecordrecord=mLayoutHolderMap.removeAt(index);if((record.flags&FLAG_PRE_AND_POST)==FLAG_PRE_AND_POST){// Persistent in both passes. Animate persistencecallback.processPersistent(viewHolder,record.preInfo,record.postInfo);}elseif((record.flags&FLAG_APPEAR)!=0){// Scrap view. RecyclerView will handle removing/recycling this.}InfoRecord.recycle(record);}}
@OverridepublicvoidprocessPersistent(ViewHolderviewHolder,@NonNullItemHolderInfopreInfo,@NonNullItemHolderInfopostInfo){viewHolder.setIsRecyclable(false);if(mDataSetHasChangedAfterLayout){// since it was rebound, use change instead as we'll be mapping them from// stable ids. If stable ids were false, we would not be running any// animationsif(mItemAnimator.animateChange(viewHolder,viewHolder,preInfo,postInfo)){postAnimationRunner();}}elseif(mItemAnimator.animatePersistence(viewHolder,preInfo,postInfo)){postAnimationRunner();}}