Search in sources :

Example 41 with ViewPropertyAnimator

use of android.view.ViewPropertyAnimator in project Telegram-FOSS by Telegram-FOSS-Team.

the class DialogsItemAnimator method animateMoveImpl.

void animateMoveImpl(final ViewHolder holder, ItemHolderInfo info, int fromX, int fromY, int toX, int toY) {
    final View view = holder.itemView;
    final int deltaX = toX - fromX;
    final int deltaY = toY - fromY;
    if (deltaX != 0) {
        view.animate().translationX(0);
    }
    if (deltaY != 0) {
        view.animate().translationY(0);
    }
    if (fromY > toY) {
        bottomClip = fromY - toY;
    } else {
        topClip = toY - fromY;
    }
    if (removingDialog != null) {
        if (topClip != Integer.MAX_VALUE) {
            bottomClip = removingDialog.getMeasuredHeight() - topClip;
            removingDialog.setTopClip(topClip);
            removingDialog.setBottomClip(bottomClip);
        } else if (bottomClip != Integer.MAX_VALUE) {
            topClip = removingDialog.getMeasuredHeight() - bottomClip;
            removingDialog.setTopClip(topClip);
            removingDialog.setBottomClip(bottomClip);
        }
    }
    // TODO: make EndActions end listeners instead, since end actions aren't called when
    // vpas are canceled (and can't end them. why?)
    // need listener functionality in VPACompat for this. Ick.
    final ViewPropertyAnimator animation = view.animate();
    mMoveAnimations.add(holder);
    animation.setDuration(deleteDuration).setListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animator) {
            dispatchMoveStarting(holder);
        }

        @Override
        public void onAnimationCancel(Animator animator) {
            if (deltaX != 0) {
                view.setTranslationX(0);
            }
            if (deltaY != 0) {
                view.setTranslationY(0);
            }
            if (holder.itemView instanceof DialogCell) {
                ((DialogCell) holder.itemView).setMoving(false);
            } else if (holder.itemView instanceof DialogsAdapter.LastEmptyView) {
                ((DialogsAdapter.LastEmptyView) holder.itemView).moving = false;
            }
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            animation.setListener(null);
            dispatchMoveFinished(holder);
            mMoveAnimations.remove(holder);
            dispatchFinishedWhenDone();
            if (holder.itemView instanceof DialogCell) {
                ((DialogCell) holder.itemView).setMoving(false);
            } else if (holder.itemView instanceof DialogsAdapter.LastEmptyView) {
                ((DialogsAdapter.LastEmptyView) holder.itemView).moving = false;
            }
            view.setTranslationX(0);
            view.setTranslationY(0);
        }
    }).start();
}
Also used : DialogCell(org.telegram.ui.Cells.DialogCell) ObjectAnimator(android.animation.ObjectAnimator) SimpleItemAnimator(androidx.recyclerview.widget.SimpleItemAnimator) Animator(android.animation.Animator) ViewPropertyAnimator(android.view.ViewPropertyAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) DialogsAdapter(org.telegram.ui.Adapters.DialogsAdapter) View(android.view.View) ViewPropertyAnimator(android.view.ViewPropertyAnimator)

Example 42 with ViewPropertyAnimator

use of android.view.ViewPropertyAnimator in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatListItemAnimator method animateAddImpl.

public void animateAddImpl(final RecyclerView.ViewHolder holder, int addedItemsHeight) {
    final View view = holder.itemView;
    final ViewPropertyAnimator animation = view.animate();
    mAddAnimations.add(holder);
    view.setTranslationY(addedItemsHeight);
    holder.itemView.setScaleX(1);
    holder.itemView.setScaleY(1);
    ChatMessageCell chatMessageCell = holder.itemView instanceof ChatMessageCell ? (ChatMessageCell) holder.itemView : null;
    if (!(chatMessageCell != null && chatMessageCell.getTransitionParams().ignoreAlpha)) {
        holder.itemView.setAlpha(1);
    }
    if (chatMessageCell != null && activity.animatingMessageObjects.contains(chatMessageCell.getMessageObject())) {
        activity.animatingMessageObjects.remove(chatMessageCell.getMessageObject());
        if (activity.getChatActivityEnterView().canShowMessageTransition()) {
            if (chatMessageCell.getMessageObject().isVoice()) {
                if (Math.abs(view.getTranslationY()) < view.getMeasuredHeight() * 3f) {
                    VoiceMessageEnterTransition transition = new VoiceMessageEnterTransition(chatMessageCell, activity.getChatActivityEnterView(), recyclerListView, activity.messageEnterTransitionContainer, resourcesProvider);
                    transition.start();
                }
            } else {
                if (SharedConfig.getDevicePerformanceClass() != SharedConfig.PERFORMANCE_CLASS_LOW && Math.abs(view.getTranslationY()) < recyclerListView.getMeasuredHeight()) {
                    TextMessageEnterTransition transition = new TextMessageEnterTransition(chatMessageCell, activity, recyclerListView, activity.messageEnterTransitionContainer, resourcesProvider);
                    transition.start();
                }
            }
            activity.getChatActivityEnterView().startMessageTransition();
        }
    }
    animation.translationY(0).setDuration(getMoveDuration()).setInterpolator(translationInterpolator).setListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animator) {
            dispatchAddStarting(holder);
        }

        @Override
        public void onAnimationCancel(Animator animator) {
            view.setTranslationY(0);
            if (view instanceof ChatMessageCell) {
                ((ChatMessageCell) view).getTransitionParams().messageEntering = false;
            }
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            if (view instanceof ChatMessageCell) {
                ((ChatMessageCell) view).getTransitionParams().messageEntering = false;
            }
            animation.setListener(null);
            if (mAddAnimations.remove(holder)) {
                dispatchAddFinished(holder);
                dispatchFinishedWhenDone();
            }
        }
    }).start();
}
Also used : ChatMessageCell(org.telegram.ui.Cells.ChatMessageCell) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ViewPropertyAnimator(android.view.ViewPropertyAnimator) ValueAnimator(android.animation.ValueAnimator) TextMessageEnterTransition(org.telegram.ui.TextMessageEnterTransition) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ChatGreetingsView(org.telegram.ui.Components.ChatGreetingsView) View(android.view.View) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ViewPropertyAnimator(android.view.ViewPropertyAnimator) VoiceMessageEnterTransition(org.telegram.ui.VoiceMessageEnterTransition)

Example 43 with ViewPropertyAnimator

use of android.view.ViewPropertyAnimator in project Telegram-FOSS by Telegram-FOSS-Team.

the class DefaultItemAnimator method animateRemoveImpl.

protected void animateRemoveImpl(final RecyclerView.ViewHolder holder) {
    final View view = holder.itemView;
    final ViewPropertyAnimator animation = view.animate();
    mRemoveAnimations.add(holder);
    animation.setDuration(getRemoveDuration()).alpha(0).setListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animator) {
            dispatchRemoveStarting(holder);
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            animation.setListener(null);
            view.setAlpha(1);
            view.setTranslationX(0);
            view.setTranslationY(0);
            dispatchRemoveFinished(holder);
            mRemoveAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
}
Also used : Animator(android.animation.Animator) ViewPropertyAnimator(android.view.ViewPropertyAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) View(android.view.View) ViewPropertyAnimator(android.view.ViewPropertyAnimator)

Example 44 with ViewPropertyAnimator

use of android.view.ViewPropertyAnimator in project Telegram-FOSS by Telegram-FOSS-Team.

the class DefaultItemAnimator method animateChangeImpl.

void animateChangeImpl(final ChangeInfo changeInfo) {
    final RecyclerView.ViewHolder holder = changeInfo.oldHolder;
    final View view = holder == null ? null : holder.itemView;
    final RecyclerView.ViewHolder newHolder = changeInfo.newHolder;
    final View newView = newHolder != null ? newHolder.itemView : null;
    if (view != null) {
        final ViewPropertyAnimator oldViewAnim = view.animate().setDuration(getChangeDuration());
        mChangeAnimations.add(changeInfo.oldHolder);
        oldViewAnim.translationX(changeInfo.toX - changeInfo.fromX);
        oldViewAnim.translationY(changeInfo.toY - changeInfo.fromY);
        oldViewAnim.alpha(0).setListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationStart(Animator animator) {
                dispatchChangeStarting(changeInfo.oldHolder, true);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                oldViewAnim.setListener(null);
                view.setAlpha(1);
                view.setTranslationX(0);
                view.setTranslationY(0);
                dispatchChangeFinished(changeInfo.oldHolder, true);
                mChangeAnimations.remove(changeInfo.oldHolder);
                dispatchFinishedWhenDone();
            }
        }).start();
    }
    if (newView != null) {
        final ViewPropertyAnimator newViewAnimation = newView.animate();
        mChangeAnimations.add(changeInfo.newHolder);
        newViewAnimation.translationX(0).translationY(0).setDuration(getChangeDuration()).alpha(1).setListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationStart(Animator animator) {
                dispatchChangeStarting(changeInfo.newHolder, false);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                newViewAnimation.setListener(null);
                newView.setAlpha(1);
                newView.setTranslationX(0);
                newView.setTranslationY(0);
                dispatchChangeFinished(changeInfo.newHolder, false);
                mChangeAnimations.remove(changeInfo.newHolder);
                dispatchFinishedWhenDone();
            }
        }).start();
    }
}
Also used : Animator(android.animation.Animator) ViewPropertyAnimator(android.view.ViewPropertyAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) View(android.view.View) ViewPropertyAnimator(android.view.ViewPropertyAnimator)

Example 45 with ViewPropertyAnimator

use of android.view.ViewPropertyAnimator in project Telegram-FOSS by Telegram-FOSS-Team.

the class RecyclerListView method checkIfEmpty.

private void checkIfEmpty(boolean animated) {
    if (isHidden) {
        return;
    }
    if (getAdapter() == null || emptyView == null) {
        if (hiddenByEmptyView && getVisibility() != VISIBLE) {
            setVisibility(VISIBLE);
            hiddenByEmptyView = false;
        }
        return;
    }
    boolean emptyViewVisible = emptyViewIsVisible();
    int newVisibility = emptyViewVisible ? VISIBLE : GONE;
    if (!animateEmptyView) {
        animated = false;
    }
    if (animated) {
        if (emptyViewAnimateToVisibility != newVisibility) {
            emptyViewAnimateToVisibility = newVisibility;
            if (newVisibility == VISIBLE) {
                emptyView.animate().setListener(null).cancel();
                if (emptyView.getVisibility() == GONE) {
                    emptyView.setVisibility(VISIBLE);
                    emptyView.setAlpha(0);
                    if (emptyViewAnimationType == 1) {
                        emptyView.setScaleX(0.7f);
                        emptyView.setScaleY(0.7f);
                    }
                }
                emptyView.animate().alpha(1f).scaleX(1).scaleY(1).setDuration(150).start();
            } else {
                if (emptyView.getVisibility() != GONE) {
                    ViewPropertyAnimator animator = emptyView.animate().alpha(0);
                    if (emptyViewAnimationType == 1) {
                        animator.scaleY(0.7f).scaleX(0.7f);
                    }
                    animator.setDuration(150).setListener(new AnimatorListenerAdapter() {

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            if (emptyView != null) {
                                emptyView.setVisibility(GONE);
                            }
                        }
                    }).start();
                }
            }
        }
    } else {
        emptyViewAnimateToVisibility = newVisibility;
        emptyView.setVisibility(newVisibility);
        emptyView.setAlpha(1f);
    }
    if (hideIfEmpty) {
        newVisibility = emptyViewVisible ? INVISIBLE : VISIBLE;
        if (getVisibility() != newVisibility) {
            setVisibility(newVisibility);
        }
        hiddenByEmptyView = true;
    }
}
Also used : Animator(android.animation.Animator) ViewPropertyAnimator(android.view.ViewPropertyAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) SuppressLint(android.annotation.SuppressLint) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) ViewPropertyAnimator(android.view.ViewPropertyAnimator)

Aggregations

ViewPropertyAnimator (android.view.ViewPropertyAnimator)104 Animator (android.animation.Animator)59 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)36 View (android.view.View)30 ValueAnimator (android.animation.ValueAnimator)23 ObjectAnimator (android.animation.ObjectAnimator)11 RecyclerView (androidx.recyclerview.widget.RecyclerView)9 AnimatorListener (android.animation.Animator.AnimatorListener)8 SimpleItemAnimator (androidx.recyclerview.widget.SimpleItemAnimator)7 SimpleItemAnimator (android.support.v7.widget.SimpleItemAnimator)4 ViewGroup (android.view.ViewGroup)4 ImageView (android.widget.ImageView)4 FastOutSlowInInterpolator (androidx.interpolator.view.animation.FastOutSlowInInterpolator)4 ProgressCardView (org.wikipedia.feed.progress.ProgressCardView)4 Paint (android.graphics.Paint)3 ViewTreeObserver (android.view.ViewTreeObserver)3 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)3 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)3 DialogCell (org.telegram.ui.Cells.DialogCell)3 Point (android.graphics.Point)2