Search in sources :

Example 6 with ViewPropertyAnimatorCompat

use of androidx.core.view.ViewPropertyAnimatorCompat in project BottomNavigation by Ashok-Varma.

the class BadgeItem method hide.

/**
 * @param animate whether to animate the change
 * @return this, to allow builder pattern
 */
public T hide(boolean animate) {
    mIsHidden = true;
    if (isWeakReferenceValid()) {
        TextView textView = mTextViewRef.get();
        if (animate) {
            ViewPropertyAnimatorCompat animatorCompat = ViewCompat.animate(textView);
            animatorCompat.cancel();
            animatorCompat.setDuration(mAnimationDuration);
            animatorCompat.scaleX(0).scaleY(0);
            animatorCompat.setListener(new ViewPropertyAnimatorListener() {

                @Override
                public void onAnimationStart(View view) {
                // Empty body
                }

                @Override
                public void onAnimationEnd(View view) {
                    view.setVisibility(View.GONE);
                }

                @Override
                public void onAnimationCancel(View view) {
                    view.setVisibility(View.GONE);
                }
            });
            animatorCompat.start();
        } else {
            textView.setVisibility(View.GONE);
        }
    }
    return getSubInstance();
}
Also used : ViewPropertyAnimatorListener(androidx.core.view.ViewPropertyAnimatorListener) TextView(android.widget.TextView) ViewPropertyAnimatorCompat(androidx.core.view.ViewPropertyAnimatorCompat) TextView(android.widget.TextView) View(android.view.View)

Example 7 with ViewPropertyAnimatorCompat

use of androidx.core.view.ViewPropertyAnimatorCompat in project Lightning-Browser by anthonycr.

the class HorizontalItemAnimator method animateRemoveImpl.

private void animateRemoveImpl(@NonNull final ViewHolder holder) {
    final View view = holder.itemView;
    final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
    mRemoveAnimations.add(holder);
    animation.setDuration(getRemoveDuration()).alpha(0).translationY(holder.itemView.getHeight()).setInterpolator(new AccelerateInterpolator()).setListener(new VpaListenerAdapter() {

        @Override
        public void onAnimationStart(View view) {
            dispatchRemoveStarting(holder);
        }

        @Override
        public void onAnimationEnd(View view) {
            animation.setListener(null);
            ViewCompat.setAlpha(view, 1);
            ViewCompat.setTranslationY(view, 0);
            dispatchRemoveFinished(holder);
            mRemoveAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
}
Also used : AccelerateInterpolator(android.view.animation.AccelerateInterpolator) ViewPropertyAnimatorCompat(androidx.core.view.ViewPropertyAnimatorCompat) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 8 with ViewPropertyAnimatorCompat

use of androidx.core.view.ViewPropertyAnimatorCompat in project Lightning-Browser by anthonycr.

the class HorizontalItemAnimator method animateAddImpl.

private void animateAddImpl(@NonNull final ViewHolder holder) {
    final View view = holder.itemView;
    final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
    mAddAnimations.add(holder);
    animation.alpha(1).translationY(0).setInterpolator(new BezierDecelerateInterpolator()).setDuration(getAddDuration()).setListener(new VpaListenerAdapter() {

        @Override
        public void onAnimationStart(View view) {
            dispatchAddStarting(holder);
        }

        @Override
        public void onAnimationCancel(View view) {
            ViewCompat.setTranslationY(view, 0);
            ViewCompat.setAlpha(view, 1);
        }

        @Override
        public void onAnimationEnd(View view) {
            animation.setListener(null);
            dispatchAddFinished(holder);
            mAddAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
}
Also used : BezierDecelerateInterpolator(acr.browser.lightning.interpolator.BezierDecelerateInterpolator) ViewPropertyAnimatorCompat(androidx.core.view.ViewPropertyAnimatorCompat) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 9 with ViewPropertyAnimatorCompat

use of androidx.core.view.ViewPropertyAnimatorCompat in project Lightning-Browser by anthonycr.

the class HorizontalItemAnimator method animateMoveImpl.

private void animateMoveImpl(@NonNull final ViewHolder holder, 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) {
        ViewCompat.animate(view).translationX(0);
    }
    if (deltaY != 0) {
        ViewCompat.animate(view).translationY(0);
    }
    // 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 ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
    mMoveAnimations.add(holder);
    animation.setDuration(getMoveDuration()).setListener(new VpaListenerAdapter() {

        @Override
        public void onAnimationStart(View view) {
            dispatchMoveStarting(holder);
        }

        @Override
        public void onAnimationCancel(View view) {
            if (deltaX != 0) {
                ViewCompat.setTranslationX(view, 0);
            }
            if (deltaY != 0) {
                ViewCompat.setTranslationY(view, 0);
            }
        }

        @Override
        public void onAnimationEnd(View view) {
            animation.setListener(null);
            dispatchMoveFinished(holder);
            mMoveAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
}
Also used : ViewPropertyAnimatorCompat(androidx.core.view.ViewPropertyAnimatorCompat) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 10 with ViewPropertyAnimatorCompat

use of androidx.core.view.ViewPropertyAnimatorCompat in project Lightning-Browser by anthonycr.

the class VerticalItemAnimator method animateChangeImpl.

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

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

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

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

            @Override
            public void onAnimationEnd(View view) {
                newViewAnimation.setListener(null);
                ViewCompat.setAlpha(newView, 1);
                ViewCompat.setTranslationX(newView, 0);
                ViewCompat.setTranslationY(newView, 0);
                dispatchChangeFinished(changeInfo.newHolder, false);
                mChangeAnimations.remove(changeInfo.newHolder);
                dispatchFinishedWhenDone();
            }
        }).start();
    }
}
Also used : ViewHolder(androidx.recyclerview.widget.RecyclerView.ViewHolder) ViewPropertyAnimatorCompat(androidx.core.view.ViewPropertyAnimatorCompat) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Aggregations

ViewPropertyAnimatorCompat (androidx.core.view.ViewPropertyAnimatorCompat)12 View (android.view.View)11 RecyclerView (androidx.recyclerview.widget.RecyclerView)10 ViewHolder (androidx.recyclerview.widget.RecyclerView.ViewHolder)3 BezierDecelerateInterpolator (acr.browser.lightning.interpolator.BezierDecelerateInterpolator)2 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)2 TextView (android.widget.TextView)2 ViewPropertyAnimatorListener (androidx.core.view.ViewPropertyAnimatorListener)1 AnimatedViewHolder (eu.davidea.viewholders.AnimatedViewHolder)1