Java Code Examples for androidx.core.view.ViewCompat#postOnAnimationDelayed()

The following examples show how to use androidx.core.view.ViewCompat#postOnAnimationDelayed() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ExpandableItemAnimator.java    From OmegaRecyclerView with MIT License 6 votes vote down vote up
private void runMoveActions(boolean hasRemovals) {
    final ArrayList<AnimationHelper.MoveInfo> moves = new ArrayList<>(mPendingChanges.moves);
    mMovesList.add(moves);
    Runnable mover = new Runnable() {
        @Override
        public void run() {
            for (AnimationHelper.MoveInfo moveInfo : moves) {
                runMoveAnimation(moveInfo.holder, moveInfo.fromX, moveInfo.fromY, moveInfo.toX, moveInfo.toY);
            }
            moves.clear();
            mMovesList.remove(moves);
        }
    };
    if (hasRemovals) {
        View view = moves.get(0).holder.itemView;
        ViewCompat.postOnAnimationDelayed(view, mover, getRemoveDuration());
    } else {
        mover.run();
    }
}
 
Example 2
Source File: ExpandableItemAnimator.java    From OmegaRecyclerView with MIT License 6 votes vote down vote up
private void runChangesActions(boolean hasRemovals) {
    final ArrayList<AnimationHelper.ChangeInfo> changes = new ArrayList<>(mPendingChanges.changes);
    mChangesList.add(changes);
    Runnable changer = new Runnable() {
        @Override
        public void run() {
            for (AnimationHelper.ChangeInfo change : changes) {
                runChangeAnimation(change);
            }
            changes.clear();
            mChangesList.remove(changes);
        }
    };
    if (hasRemovals) {
        ViewHolder holder = changes.get(0).oldHolder;
        ViewCompat.postOnAnimationDelayed(holder.itemView, changer, getRemoveDuration());
    } else {
        changer.run();
    }
}
 
Example 3
Source File: ExpandableItemAnimator.java    From OmegaRecyclerView with MIT License 6 votes vote down vote up
private void scheduleAddAnimation(final ArrayList<ViewHolder> additions, boolean forceDelay, boolean hasRemovals, boolean hasMoves, boolean hasChanges) {
    if (!additions.isEmpty()) {
        mAdditionsList.add(additions);
        Runnable adder = new Runnable() {
            public void run() {
                proceedWithAnimationHelper(additions, new UnVoidFunction<ViewHolder>() {
                    @Override
                    public void apply(ViewHolder param) {
                        runAddAnimation(param);
                    }
                }, true);
                mAdditionsList.remove(additions);
            }
        };
        if (hasRemovals || hasMoves || hasChanges) {
            View view = additions.get(0).itemView;
            long totalDelay = getTotalDelay(hasRemovals, hasMoves, hasChanges);
            ViewCompat.postOnAnimationDelayed(view, adder, forceDelay || isNeedAddingDelay() ? totalDelay : 0L);
        } else {
            adder.run();
        }
    }
}
 
Example 4
Source File: FlexibleItemAnimator.java    From FlexibleAdapter with Apache License 2.0 6 votes vote down vote up
private void runMoveAnimation(boolean removalsPending, boolean movesPending) {
    if (movesPending) {
        final ArrayList<MoveInfo> moves = new ArrayList<>();
        moves.addAll(mPendingMoves);
        mMovesList.add(moves);
        mPendingMoves.clear();
        Runnable mover = new Runnable() {
            @Override
            public void run() {
                for (MoveInfo moveInfo : moves) {
                    animateMoveImpl(moveInfo.holder, moveInfo.fromX, moveInfo.fromY,
                            moveInfo.toX, moveInfo.toY);
                }
                moves.clear();
                mMovesList.remove(moves);
            }
        };
        if (removalsPending) {
            View view = moves.get(0).holder.itemView;
            ViewCompat.postOnAnimationDelayed(view, mover, getRemoveDuration());
        } else {
            mover.run();
        }
    }
}
 
Example 5
Source File: FlexibleItemAnimator.java    From FlexibleAdapter with Apache License 2.0 6 votes vote down vote up
private void runChangeAnimation(boolean removalsPending, boolean changesPending) {
    // Change animation to run in parallel with move animations
    if (changesPending) {
        final ArrayList<ChangeInfo> changes = new ArrayList<>();
        changes.addAll(mPendingChanges);
        mChangesList.add(changes);
        mPendingChanges.clear();
        Runnable changer = new Runnable() {
            @Override
            public void run() {
                for (ChangeInfo change : changes) {
                    animateChangeImpl(change);
                }
                changes.clear();
                mChangesList.remove(changes);
            }
        };
        if (removalsPending) {
            ViewHolder holder = changes.get(0).oldHolder;
            ViewCompat.postOnAnimationDelayed(holder.itemView, changer, getRemoveDuration());
        } else {
            changer.run();
        }
    }
}
 
Example 6
Source File: ExpandableItemAnimator.java    From OmegaRecyclerView with MIT License 5 votes vote down vote up
@Override
public void runPendingAnimations() {
    boolean removalsPending = !mPendingChanges.removals.isEmpty();
    boolean movesPending = !mPendingChanges.moves.isEmpty();
    boolean changesPending = !mPendingChanges.changes.isEmpty();
    boolean additionsPending = !mPendingChanges.additions.isEmpty();

    if (removalsPending) runRemoveActions();
    if (movesPending) runMoveActions(removalsPending);
    if (changesPending) runChangesActions(removalsPending);
    if (additionsPending) runAddActions(removalsPending, movesPending, changesPending);

    View someView = null;
    if (removalsPending) {
        someView = mPendingChanges.removals.get(0).itemView;
    }
    if (someView == null && movesPending) {
        someView = mPendingChanges.moves.get(0).holder.itemView;
    }
    if (someView == null && changesPending) {
        someView = mPendingChanges.changes.get(0).oldHolder.itemView;
    }
    if (someView == null && additionsPending) {
        someView = mPendingChanges.additions.get(0).itemView;
    }
    if (someView != null) {
        ViewCompat.postOnAnimationDelayed(someView, mPendingCleaner, getTotalDelay(removalsPending, movesPending, changesPending));
    }
}
 
Example 7
Source File: FlexibleItemAnimator.java    From FlexibleAdapter with Apache License 2.0 5 votes vote down vote up
private void runAddAnimation(boolean removalsPending, boolean changesPending,
                             boolean movesPending, boolean additionsPending) {
    if (additionsPending) {
        final ArrayList<ViewHolder> additions = new ArrayList<>();
        // Sorting addition animations based on it's original layout position
        Collections.sort(mPendingAdditions, new Comparator<ViewHolder>() {
            @Override
            public int compare(ViewHolder vh1, ViewHolder vh2) {
                return vh1.getLayoutPosition() - vh2.getLayoutPosition();
            }
        });
        additions.addAll(mPendingAdditions);
        mAdditionsList.add(additions);
        mPendingAdditions.clear();
        Runnable adder = new Runnable() {
            public void run() {
                int index = 0;
                for (ViewHolder holder : additions) {
                    doAnimateAdd(holder, index++);
                }
                additions.clear();
                mAdditionsList.remove(additions);
            }
        };
        if (removalsPending || movesPending || changesPending) {
            long removeDuration = removalsPending ? getRemoveDuration() : 0;
            long moveDuration = movesPending ? getMoveDuration() : 0;
            long changeDuration = changesPending ? getChangeDuration() : 0;
            long totalDelay = removeDuration + Math.max(moveDuration, changeDuration);
            View view = additions.get(0).itemView;
            ViewCompat.postOnAnimationDelayed(view, adder, totalDelay);
        } else {
            adder.run();
        }
    }
}
 
Example 8
Source File: ViewAnimation.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
private void postOnAnimationDelayed(long delayMillis) {
    if (mEatRunOnAnimationRequest) {
        mReSchedulePostAnimationCallback = true;
    } else {
        mView.removeCallbacks(this);
        ViewCompat.postOnAnimationDelayed(mView, this, delayMillis);
    }
}