Example usage for android.support.v4.view ViewPropertyAnimatorCompat setInterpolator

List of usage examples for android.support.v4.view ViewPropertyAnimatorCompat setInterpolator

Introduction

In this page you can find the example usage for android.support.v4.view ViewPropertyAnimatorCompat setInterpolator.

Prototype

public ViewPropertyAnimatorCompat setInterpolator(Interpolator interpolator) 

Source Link

Usage

From source file:vc908.stickerfactory.ui.advancedrecyclerview.draggable.BaseDraggableItemDecorator.java

protected void moveToDefaultPosition(View targetView, boolean animate) {
    final int curTranslationY = (int) (ViewCompat.getTranslationY(targetView));
    final int halfItemHeight = targetView.getHeight() / 2;
    final float translationProportion = (halfItemHeight > 0)
            ? Math.abs((float) curTranslationY / halfItemHeight)
            : 0;/*from   w ww.ja  v  a2  s. co  m*/
    final float t = 1.0f - Math.min(translationProportion, 1.0f);
    final int animDuration = (int) (mReturnToDefaultPositionDuration * (1.0f - (t * t)) + 0.5f);

    if (supportsViewPropertyAnimation() && animate
            && (animDuration > RETURN_TO_DEFAULT_POS_ANIMATE_THRESHOLD_MSEC)
            && (Math.abs(curTranslationY) > mReturnToDefaultPositionAnimateThreshold)) {
        final ViewPropertyAnimatorCompat animator = ViewCompat.animate(targetView);
        animator.cancel();
        animator.setDuration(animDuration);
        animator.setInterpolator(mReturnToDefaultPositionInterpolator);
        animator.translationY(0.0f);
        animator.setListener(new ViewPropertyAnimatorListener() {
            @Override
            public void onAnimationStart(View view) {
            }

            @Override
            public void onAnimationEnd(View view) {
                animator.setListener(null);
                ViewCompat.setTranslationY(view, 0);

                // invalidate explicitly to refresh other decorations
                if (view.getParent() instanceof RecyclerView) {
                    ViewCompat.postInvalidateOnAnimation((RecyclerView) view.getParent());
                }
            }

            @Override
            public void onAnimationCancel(View view) {
            }
        });
        animator.start();
    } else {
        ViewCompat.setTranslationY(targetView, 0);
    }
}

From source file:com.github.shareme.gwsmaterialuikit.library.advancerv.draggable.BaseDraggableItemDecorator.java

protected void moveToDefaultPosition(View targetView, boolean animate) {
    final int curTranslationX = (int) (ViewCompat.getTranslationX(targetView));
    final int curTranslationY = (int) (ViewCompat.getTranslationY(targetView));
    final int halfItemWidth = targetView.getWidth() / 2;
    final int halfItemHeight = targetView.getHeight() / 2;
    final float translationProportionX = (halfItemWidth > 0) ? Math.abs((float) curTranslationX / halfItemWidth)
            : 0;/*from   www  .ja  v a  2s .  c  o  m*/
    final float translationProportionY = (halfItemHeight > 0)
            ? Math.abs((float) curTranslationY / halfItemHeight)
            : 0;
    final float tx = 1.0f - Math.min(translationProportionX, 1.0f);
    final float ty = 1.0f - Math.min(translationProportionY, 1.0f);
    final int animDurationX = (int) (mReturnToDefaultPositionDuration * (1.0f - (tx * tx)) + 0.5f);
    final int animDurationY = (int) (mReturnToDefaultPositionDuration * (1.0f - (ty * ty)) + 0.5f);
    final int animDuration = Math.max(animDurationX, animDurationY);
    final int maxAbsTranslation = Math.max(Math.abs(curTranslationX), Math.abs(curTranslationY));

    if (supportsViewPropertyAnimation() && animate
            && (animDuration > RETURN_TO_DEFAULT_POS_ANIMATE_THRESHOLD_MSEC)
            && (maxAbsTranslation > mReturnToDefaultPositionAnimateThreshold)) {
        final ViewPropertyAnimatorCompat animator = ViewCompat.animate(targetView);
        animator.cancel();
        animator.setDuration(animDuration);
        animator.setInterpolator(mReturnToDefaultPositionInterpolator);
        animator.translationX(0.0f);
        animator.translationY(0.0f);
        animator.setListener(new ViewPropertyAnimatorListener() {
            @Override
            public void onAnimationStart(View view) {
            }

            @Override
            public void onAnimationEnd(View view) {
                animator.setListener(null);
                ViewCompat.setTranslationX(view, 0);
                ViewCompat.setTranslationY(view, 0);

                // invalidate explicitly to refresh other decorations
                if (view.getParent() instanceof RecyclerView) {
                    ViewCompat.postInvalidateOnAnimation((RecyclerView) view.getParent());
                }
            }

            @Override
            public void onAnimationCancel(View view) {
            }
        });
        animator.start();
    } else {
        ViewCompat.setTranslationX(targetView, 0);
        ViewCompat.setTranslationY(targetView, 0);
    }
}

From source file:android.support.v7.internal.view.ViewPropertyAnimatorCompatSet.java

public void start() {
    if (mIsStarted)
        return;/*ww  w  .  j  av a 2  s  . c  o  m*/
    for (ViewPropertyAnimatorCompat animator : mAnimators) {
        if (mDuration >= 0) {
            animator.setDuration(mDuration);
        }
        if (mInterpolator != null) {
            animator.setInterpolator(mInterpolator);
        }
        if (mListener != null) {
            animator.setListener(mProxyListener);
        }
        animator.start();
    }

    mIsStarted = true;
}

From source file:android.support.v7.internal.widget.AbsActionBarView.java

public void animateToVisibility(int visibility) {
    if (mVisibilityAnim != null) {
        mVisibilityAnim.cancel();/*  www  .  ja va2  s  . co  m*/
    }
    if (visibility == VISIBLE) {
        if (getVisibility() != VISIBLE) {
            ViewCompat.setAlpha(this, 0f);
            if (mSplitView != null && mMenuView != null) {
                ViewCompat.setAlpha(mMenuView, 0f);
            }
        }
        ViewPropertyAnimatorCompat anim = ViewCompat.animate(this).alpha(1f);
        anim.setDuration(FADE_DURATION);
        anim.setInterpolator(sAlphaInterpolator);
        if (mSplitView != null && mMenuView != null) {
            ViewPropertyAnimatorCompatSet set = new ViewPropertyAnimatorCompatSet();
            ViewPropertyAnimatorCompat splitAnim = ViewCompat.animate(mMenuView).alpha(1f);
            splitAnim.setDuration(FADE_DURATION);
            set.setListener(mVisAnimListener.withFinalVisibility(anim, visibility));
            set.play(anim).play(splitAnim);
            set.start();
        } else {
            anim.setListener(mVisAnimListener.withFinalVisibility(anim, visibility));
            anim.start();
        }
    } else {
        ViewPropertyAnimatorCompat anim = ViewCompat.animate(this).alpha(0f);
        anim.setDuration(FADE_DURATION);
        anim.setInterpolator(sAlphaInterpolator);
        if (mSplitView != null && mMenuView != null) {
            ViewPropertyAnimatorCompatSet set = new ViewPropertyAnimatorCompatSet();
            ViewPropertyAnimatorCompat splitAnim = ViewCompat.animate(mMenuView).alpha(0f);
            splitAnim.setDuration(FADE_DURATION);
            set.setListener(mVisAnimListener.withFinalVisibility(anim, visibility));
            set.play(anim).play(splitAnim);
            set.start();
        } else {
            anim.setListener(mVisAnimListener.withFinalVisibility(anim, visibility));
            anim.start();
        }
    }
}

From source file:io.apptik.multiview.animators.FlexiItemAnimator.java

@Override
protected void animateAddImpl(final RecyclerView.ViewHolder holder) {
    if (vpaAdd == null) {
        resetView(holder.itemView);// w  ww.j  av a 2 s.c o m
        dispatchAddFinished(holder);
        dispatchFinishedWhenDone();
        return;
    }
    mAddAnimations.add(holder);

    Runnable beforeAction = vpaAdd.getBeforeAction(holder);
    if (beforeAction != null) {
        beforeAction.run();
    }
    final ViewPropertyAnimatorCompat animation = vpaAdd.getAnim(holder);
    if (ipAdd != null) {
        animation.setInterpolator(ipAdd);
    }
    animation.setDuration(getAddDuration()).setListener(new VoidVpaListener() {
        @Override
        public void onAnimationStart(View view) {
            Log.v("start add anim: " + view);
            dispatchAddStarting(holder);
        }

        @Override
        public void onAnimationCancel(View view) {
            Log.v("cancel add anim: " + view);
            resetView(view);
        }

        @Override
        public void onAnimationEnd(View view) {
            Log.v("end add anim: " + view);
            animation.setListener(null);
            resetView(view);
            dispatchAddFinished(holder);
            mAddAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
}

From source file:io.apptik.multiview.animators.FlexiItemAnimator.java

protected void animateRemoveImpl(final RecyclerView.ViewHolder holder) {
    if (vpaRemove == null) {
        dispatchRemoveFinished(holder);/*w ww .ja v  a2s.c  om*/
        dispatchFinishedWhenDone();
        return;
    }
    Runnable beforeAction = vpaRemove.getBeforeAction(holder);
    if (beforeAction != null) {
        beforeAction.run();
    }
    final ViewPropertyAnimatorCompat animation = vpaRemove.getAnim(holder);
    if (ipRemove != null) {
        animation.setInterpolator(ipRemove);
    }
    animation.setDuration(getRemoveDuration()).setListener(new VoidVpaListener() {
        @Override
        public void onAnimationStart(View view) {
            Log.v("start remove anim: " + view);
            dispatchRemoveStarting(holder);
        }

        @Override
        public void onAnimationCancel(View view) {
            Log.v("cancel remove anim: " + view);
            resetView(view);
        }

        @Override
        public void onAnimationEnd(View view) {
            Log.v("end remove anim: " + view);
            animation.setListener(null);
            resetView(view);
            dispatchRemoveFinished(holder);
            mRemoveAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
    mRemoveAnimations.add(holder);
}

From source file:io.apptik.multiview.animators.FlexiItemAnimator.java

@Override
protected void animateMoveImpl(final RecyclerView.ViewHolder holder, final MoveInfo moveInfo) {
    if (vpaMove == null) {
        dispatchMoveFinished(holder);//from   w w w .  ja v a2s .  c  o  m
        dispatchFinishedWhenDone();
        return;
    }
    final int deltaX = moveInfo.toX - moveInfo.fromX;
    final int deltaY = moveInfo.toY - moveInfo.fromY;

    mMoveAnimations.add(holder);
    Runnable beforeAction = vpaMove.getBeforeAction(holder, moveInfo);
    if (beforeAction != null) {
        beforeAction.run();
    }
    final ViewPropertyAnimatorCompat animation = vpaMove.getAnim(holder, moveInfo);
    if (ipMove != null) {
        animation.setInterpolator(ipMove);
    }
    animation.setDuration(getMoveDuration()).setListener(new VoidVpaListener() {
        @Override
        public void onAnimationStart(View view) {
            Log.v("start move anim: " + view);
            dispatchMoveStarting(holder);
        }

        @Override
        public void onAnimationCancel(View view) {
            Log.v("cancel move anim: " + view);
            resetView(view);
        }

        @Override
        public void onAnimationEnd(View view) {
            Log.v("end move anim: " + view);
            animation.setListener(null);
            resetView(view);
            dispatchMoveFinished(holder);
            mMoveAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
}

From source file:com.github.vase4kin.teamcityapp.login.view.LoginViewImpl.java

/**
 * {@inheritDoc}//www.ja  v a  2  s .  c o  m
 */
@Override
public void animate() {
    ViewCompat.animate(mLogoImageView).translationY(mActivity.getResources().getInteger(R.integer.logo_move))
            .setStartDelay(STARTUP_DELAY).setDuration(ANIM_ITEM_DURATION)
            .setInterpolator(new DecelerateInterpolator(1.2f)).start();

    for (int i = 0; i < mContainer.getChildCount(); i++) {
        View v = mContainer.getChildAt(i);
        ViewPropertyAnimatorCompat viewAnimator = ViewCompat.animate(v).translationY(0).alpha(1)
                .setStartDelay((ITEM_DELAY * i) + 500).setDuration(1000);

        viewAnimator.setInterpolator(new DecelerateInterpolator()).start();
    }
}

From source file:io.apptik.multiview.animators.FlexiItemAnimator.java

@Override
protected void animateChangeImpl(final BaseItemAnimator.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 && vpaChnageOld != null) {
        mChangeAnimations.add(changeInfo.oldHolder);
        Runnable beforeAction = vpaChnageOld.getBeforeAction(holder, changeInfo);
        if (beforeAction != null) {
            beforeAction.run();/*from w  w w.  j  av a  2  s  .co m*/
        }
        final ViewPropertyAnimatorCompat oldViewAnim = vpaChnageOld.getAnim(changeInfo.oldHolder, changeInfo)
                .setDuration(getChangeDuration());
        if (ipChangeOld != null) {
            oldViewAnim.setInterpolator(ipChangeOld);
        }
        oldViewAnim.setListener(new VoidVpaListener() {
            @Override
            public void onAnimationStart(View view) {
                Log.v("start change old anim: " + view);
                dispatchChangeStarting(changeInfo.oldHolder, true);
            }

            @Override
            public void onAnimationCancel(View view) {
                Log.v("cancel change old anim: " + view);
                resetView(view);
            }

            @Override
            public void onAnimationEnd(View view) {
                Log.v("end change old anim: " + view);
                oldViewAnim.setListener(null);
                Log.v("end change old anim before: " + view);
                resetView(view);
                Log.v("end change old anim after: " + view);
                dispatchChangeFinished(changeInfo.oldHolder, true);
                mChangeAnimations.remove(changeInfo.oldHolder);
                dispatchFinishedWhenDone();
            }
        }).start();
    } else {
        dispatchChangeFinished(changeInfo.oldHolder, true);
        dispatchFinishedWhenDone();
    }
    if (newView != null && vpaChangeNew != null) {
        mChangeAnimations.add(changeInfo.newHolder);
        Runnable beforeAction = vpaChangeNew.getBeforeAction(holder, changeInfo);
        if (beforeAction != null) {
            beforeAction.run();
        }
        final ViewPropertyAnimatorCompat newViewAnimation = vpaChangeNew.getAnim(changeInfo.newHolder,
                changeInfo);
        if (ipChangeNew != null) {
            newViewAnimation.setInterpolator(ipChangeNew);
        }
        newViewAnimation.setDuration(getChangeDuration()).setListener(new VoidVpaListener() {
            @Override
            public void onAnimationStart(View view) {
                Log.v("start change new anim: " + view);
                dispatchChangeStarting(changeInfo.newHolder, false);
            }

            @Override
            public void onAnimationCancel(View view) {
                Log.v("cancel change new anim: " + view);
                resetView(view);
            }

            @Override
            public void onAnimationEnd(View view) {
                Log.v("end change new anim: " + view);
                newViewAnimation.setListener(null);
                resetView(view);
                dispatchChangeFinished(changeInfo.newHolder, false);
                mChangeAnimations.remove(changeInfo.newHolder);
                dispatchFinishedWhenDone();
            }
        }).start();
    } else {
        //            dispatchChangeFinished(changeInfo.newHolder, false);
        dispatchFinishedWhenDone();
    }
}

From source file:vc908.stickerfactory.ui.advancedrecyclerview.swipeable.ItemSlidingAnimator.java

private boolean animateSlideInternal(final RecyclerView.ViewHolder holder, int translationX, long duration,
        Interpolator interpolator) {/*w  ww .j  a v  a  2 s. co m*/
    if (!(holder instanceof SwipeableItemViewHolder)) {
        return false;
    }

    final View containerView = ((SwipeableItemViewHolder) holder).getSwipeableContainerView();

    final int prevTranslationX = (int) (ViewCompat.getTranslationX(containerView) + 0.5f);

    endAnimation(holder);

    final int curTranslationX = (int) (ViewCompat.getTranslationX(containerView) + 0.5f);
    final int toX = translationX;

    if (curTranslationX == toX) {
        return false;
    }

    if (duration == 0 || Math.abs(toX - prevTranslationX) <= mImmediatelySetTranslationThreshold) {
        ViewCompat.setTranslationX(containerView, toX);
        return false;
    }

    ViewCompat.setTranslationX(containerView, prevTranslationX);

    final ViewPropertyAnimatorCompat animator = ViewCompat.animate(containerView);

    animator.setDuration(duration);
    if (interpolator != null) {
        animator.setInterpolator(interpolator);
    }
    animator.translationX(toX);
    animator.setListener(new ViewPropertyAnimatorListener() {
        @Override
        public void onAnimationStart(View view) {
            if (animatorListener != null) {
                animatorListener.onAnimationStart(view);
            }
        }

        @Override
        public void onAnimationEnd(View view) {
            animator.setListener(null);
            mActive.remove(holder);
            ViewCompat.setTranslationX(view, toX);
            if (animatorListener != null) {
                animatorListener.onAnimationEnd(view);
            }
        }

        @Override
        public void onAnimationCancel(View view) {
            if (animatorListener != null) {
                animatorListener.onAnimationCancel(view);
            }
        }
    });

    mActive.add(holder);

    animator.start();

    return true;
}