11f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar/*
21f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar * Copyright (C) 2015 The Android Open Source Project
31f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar * Licensed under the Apache License, Version 2.0 (the "License");
41f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar * you may not use this file except in compliance with the License.
51f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar * You may obtain a copy of the License at
61f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar *      http://www.apache.org/licenses/LICENSE-2.0
71f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar * Unless required by applicable law or agreed to in writing, software
81f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar * distributed under the License is distributed on an "AS IS" BASIS,
91f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
101f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar * See the License for the specific language governing permissions and
111f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar * limitations under the License.
121f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar */
131f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar
141f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyarpackage android.support.v7.widget;
151f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar
161f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyarimport java.util.ArrayList;
171f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyarimport java.util.concurrent.CountDownLatch;
181f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyarimport java.util.concurrent.TimeUnit;
191f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar
201f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyarpublic class LoggingItemAnimator extends DefaultItemAnimator {
211f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar
221f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    final ArrayList<RecyclerView.ViewHolder> mAddVHs = new ArrayList<RecyclerView.ViewHolder>();
231f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar
241f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    final ArrayList<RecyclerView.ViewHolder> mRemoveVHs = new ArrayList<RecyclerView.ViewHolder>();
251f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar
261f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    final ArrayList<RecyclerView.ViewHolder> mMoveVHs = new ArrayList<RecyclerView.ViewHolder>();
271f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar
281f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    final ArrayList<RecyclerView.ViewHolder> mChangeOldVHs = new ArrayList<RecyclerView.ViewHolder>();
291f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar
301f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    final ArrayList<RecyclerView.ViewHolder> mChangeNewVHs = new ArrayList<RecyclerView.ViewHolder>();
311f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar
321f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    CountDownLatch mWaitForPendingAnimations;
331f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar
341f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    @Override
351f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    public void runPendingAnimations() {
361f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        if (mWaitForPendingAnimations != null) {
371f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar            mWaitForPendingAnimations.countDown();
381f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        }
391f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        super.runPendingAnimations();
401f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    }
411f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar
421f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    public void expectRunPendingAnimationsCall(int count) {
431f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        mWaitForPendingAnimations = new CountDownLatch(count);
441f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    }
451f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar
461f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    public void waitForPendingAnimationsCall(int seconds) throws InterruptedException {
471f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        mWaitForPendingAnimations.await(seconds, TimeUnit.SECONDS);
481f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    }
491f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar
501f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    @Override
511f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    public boolean animateAdd(RecyclerView.ViewHolder holder) {
521f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        mAddVHs.add(holder);
531f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        return super.animateAdd(holder);
541f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    }
551f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar
561f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    @Override
571f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    public boolean animateRemove(RecyclerView.ViewHolder holder) {
581f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        mRemoveVHs.add(holder);
591f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        return super.animateRemove(holder);
601f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    }
611f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar
621f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    @Override
631f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    public boolean animateMove(RecyclerView.ViewHolder holder, int fromX, int fromY,
641f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar            int toX, int toY) {
651f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        mMoveVHs.add(holder);
661f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        return super.animateMove(holder, fromX, fromY, toX, toY);
671f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    }
681f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar
691f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    @Override
701f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    public boolean animateChange(RecyclerView.ViewHolder oldHolder,
711f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar            RecyclerView.ViewHolder newHolder, int fromX, int fromY, int toX, int toY) {
721f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        if (oldHolder != null) {
731f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar            mChangeOldVHs.add(oldHolder);
741f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        }
751f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        if (newHolder != null) {
761f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar            mChangeNewVHs.add(newHolder);
771f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        }
781f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        return super.animateChange(oldHolder, newHolder, fromX, fromY, toX, toY);
791f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    }
801f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar
811f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    public void reset() {
821f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        mAddVHs.clear();
831f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        mRemoveVHs.clear();
841f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        mMoveVHs.clear();
851f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        mChangeOldVHs.clear();
861f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar        mChangeNewVHs.clear();
871f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar    }
881f5c7b76bfc3da85513e6d2c6aa1058339f0c625Yigit Boyar}