/* * ****************************************************************************** * Copyright (c) 2014 Gabriele Mariotti. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * ***************************************************************************** */ package com.marshalchen.common.ui.recyclerviewitemanimator; import android.support.v4.view.ViewCompat; import android.support.v7.widget.RecyclerView; import android.view.View; /** * * @see android.support.v7.widget.RecyclerView#setItemAnimator(android.support.v7.widget.RecyclerView.ItemAnimator) */ public class SlideInOutRightItemAnimator extends BaseItemAnimator { public SlideInOutRightItemAnimator(RecyclerView recyclerView){ super(recyclerView); } protected void animateRemoveImpl(final RecyclerView.ViewHolder holder) { final View view = holder.itemView; ViewCompat.animate(view).cancel(); ViewCompat.animate(view).setDuration(getRemoveDuration()). translationX(+mRecyclerView.getWidth()).setListener(new VpaListenerAdapter() { @Override public void onAnimationEnd(View view) { ViewCompat.setTranslationX(view, +mRecyclerView.getWidth()); dispatchRemoveFinished(holder); mRemoveAnimations.remove(holder); dispatchFinishedWhenDone(); } }).start(); mRemoveAnimations.add(holder); } @Override protected void prepareAnimateAdd(RecyclerView.ViewHolder holder) { ViewCompat.setTranslationX(holder.itemView, +mRecyclerView.getWidth()); } protected void animateAddImpl(final RecyclerView.ViewHolder holder) { final View view = holder.itemView; ViewCompat.animate(view).cancel(); ViewCompat.animate(view).translationX(0) .setDuration(getAddDuration()). setListener(new VpaListenerAdapter() { @Override public void onAnimationCancel(View view) { ViewCompat.setTranslationX(view, 0); } @Override public void onAnimationEnd(View view) { dispatchAddFinished(holder); mAddAnimations.remove(holder); dispatchFinishedWhenDone(); } }).start(); mAddAnimations.add(holder); } @Override public boolean animateChange(RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder viewHolder2, int i, int i2, int i3, int i4) { return false; } }