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

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

Introduction

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

Prototype

public ViewPropertyAnimatorCompat translationX(float f) 

Source Link

Usage

From source file:com.twotoasters.jazzylistview.effects.WaveEffect.java

@Override
public void setupAnimation(View item, int position, int scrollDirection, ViewPropertyAnimatorCompat animator) {
    animator.translationX(0);
}

From source file:aloha.shiningstarbase.util.itemanimator.SlideInOutLeftItemAnimator.java

protected void animateAddImpl(final RecyclerView.ViewHolder holder) {
    final View view = holder.itemView;
    final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
    mAddAnimations.add(holder);/*  ww w  .  ja  v  a  2 s.c o m*/
    animation.translationX(0).alpha(1).setDuration(getAddDuration()).setListener(new VpaListenerAdapter() {
        @Override
        public void onAnimationStart(View view) {
            dispatchAddStarting(holder);
        }

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

        @Override
        public void onAnimationEnd(View view) {
            animation.setListener(null);
            ViewCompat.setTranslationX(view, 0);
            ViewCompat.setAlpha(view, 1);
            dispatchAddFinished(holder);
            mAddAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
}

From source file:aloha.shiningstarbase.util.itemanimator.SlideInOutRightItemAnimator.java

protected void animateAddImpl(final RecyclerView.ViewHolder holder) {
    final View view = holder.itemView;
    final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
    mAddAnimations.add(holder);//  w  w w.  j a v a 2 s  .c o m
    animation.translationX(0).alpha(1).setDuration(getAddDuration()).setListener(new VpaListenerAdapter() {
        @Override
        public void onAnimationStart(View view) {
            dispatchAddStarting(holder);
        }

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

        @Override
        public void onAnimationEnd(View view) {
            animation.setListener(null);
            dispatchAddFinished(holder);
            ViewCompat.setTranslationX(view, 0);
            ViewCompat.setAlpha(view, 1);
            mAddAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
}

From source file:jp.wasabeef.recyclerview.animators.AnimateChange.java

public void animateChange(final RecyclerView.ViewHolder oldHolder, final RecyclerView.ViewHolder newHolder,
        int fromX, int fromY, int toX, int toY) {
    final View view = oldHolder.itemView;
    final View newView = newHolder.itemView;
    long oldAnimDuration = (long) (0.5f * mDispatcher.getChangeDuration());
    long newAnimDuration = mDispatcher.getChangeDuration();

    if (view != null) {
        final ViewPropertyAnimatorCompat oldViewAnim = ViewCompat.animate(view);
        oldViewAnim.translationX(toX - fromX);
        oldViewAnim.translationY(toY - fromY);

        oldViewAnim.setDuration(oldAnimDuration);
        oldViewAnim.alpha(0).setListener(new ViewPropertyAnimatorListener() {
            @Override// ww w  . ja va  2 s . c  o m
            public void onAnimationStart(View view) {
                mDispatcher.dispatchChangeStarting(oldHolder, true);
            }

            @Override
            public void onAnimationEnd(View view) {
                oldViewAnim.setListener(null);
                ViewCompat.setAlpha(view, 1);
                ViewCompat.setTranslationX(view, 0);
                ViewCompat.setTranslationY(view, 0);
                mDispatcher.dispatchChangeFinished(oldHolder, true);
            }

            @Override
            public void onAnimationCancel(View view) {
                ViewHelper.clear(view);
            }
        }).start();
    }

    if (newView != null) {
        final ViewPropertyAnimatorCompat newViewAnimation = ViewCompat.animate(newView);
        newViewAnimation.translationX(0).translationY(0);

        newViewAnimation.setDuration(newAnimDuration);
        newViewAnimation.alpha(1).setListener(new ViewPropertyAnimatorListener() {
            @Override
            public void onAnimationStart(View view) {
                mDispatcher.dispatchChangeStarting(newHolder, false);
            }

            @Override
            public void onAnimationEnd(View view) {
                newViewAnimation.setListener(null);
                ViewCompat.setAlpha(newView, 1);
                ViewCompat.setTranslationX(newView, 0);
                ViewCompat.setTranslationY(newView, 0);
                mDispatcher.dispatchChangeFinished(newHolder, false);
            }

            @Override
            public void onAnimationCancel(View view) {
                ViewHelper.clear(view);
            }
        }).start();
    }
}

From source file:jp.wasabeef.recyclerview.animators.change.TinyScaleAnimate.java

public void animateChange(final RecyclerView.ViewHolder oldHolder, final RecyclerView.ViewHolder newHolder,
        int fromX, int fromY, int toX, int toY) {
    final long duration = (long) (0.5f * mDispatcher.getChangeDuration());

    if (oldHolder.itemView != null) {
        final ViewPropertyAnimatorCompat oldViewAnim = ViewCompat.animate(oldHolder.itemView);
        oldViewAnim.translationX(toX - fromX);
        oldViewAnim.translationY(toY - fromY);

        oldViewAnim.setDuration(duration);
        oldViewAnim.scaleX(SCALE_VALUE).scaleY(SCALE_VALUE);
        oldViewAnim.setListener(new ViewPropertyAnimatorListener() {
            @Override/*from   ww  w  . ja v a2 s  .co  m*/
            public void onAnimationStart(View view) {
                mDispatcher.dispatchChangeStarting(oldHolder, true);
            }

            @Override
            public void onAnimationEnd(View view) {
                oldViewAnim.setListener(null);
                ViewCompat.setAlpha(view, 1);
                ViewCompat.setTranslationX(view, 0);
                ViewCompat.setTranslationY(view, 0);
                mDispatcher.dispatchChangeFinished(oldHolder, true);

                if (newHolder.itemView != null) {
                    ViewCompat.setScaleX(newHolder.itemView, SCALE_VALUE);
                    ViewCompat.setScaleY(newHolder.itemView, SCALE_VALUE);
                    ViewCompat.setAlpha(newHolder.itemView, 1.f);
                    final ViewPropertyAnimatorCompat newViewAnimation = ViewCompat.animate(newHolder.itemView);
                    newViewAnimation.translationX(0).translationY(0);
                    newViewAnimation.scaleX(1.f).scaleY(1.f);
                    newViewAnimation.setDuration(duration);
                    newViewAnimation.setListener(new ViewPropertyAnimatorListener() {
                        @Override
                        public void onAnimationStart(View view) {
                            mDispatcher.dispatchChangeStarting(newHolder, false);
                        }

                        @Override
                        public void onAnimationEnd(View view) {
                            newViewAnimation.setListener(null);
                            ViewCompat.setAlpha(view, 1);
                            ViewCompat.setTranslationX(view, 0);
                            ViewCompat.setTranslationY(view, 0);
                            mDispatcher.dispatchChangeFinished(newHolder, false);
                        }

                        @Override
                        public void onAnimationCancel(View view) {
                            ViewHelper.clear(view);
                        }
                    }).start();
                }
            }

            @Override
            public void onAnimationCancel(View view) {
                ViewHelper.clear(view);
            }
        }).start();
    }

}

From source file:com.vicmns.demoinboxlikefab.SlideInOutLeftItemAnimator.java

@Override
protected void animateChangeImpl(final BaseItemAnimator.ChangeInfo changeInfo) {
    final RecyclerView.ViewHolder holder = changeInfo.oldHolder;
    final View view = holder.itemView;
    final RecyclerView.ViewHolder newHolder = changeInfo.newHolder;
    final View newView = newHolder != null ? newHolder.itemView : null;
    mChangeAnimations.add(changeInfo.oldHolder);

    final ViewPropertyAnimatorCompat oldViewAnim = ViewCompat.animate(view).setDuration(getChangeDuration());
    oldViewAnim.translationX(changeInfo.toX - changeInfo.fromX);
    oldViewAnim.translationY(changeInfo.toY - changeInfo.fromY);
    oldViewAnim.alpha(0).setListener(new VpaListenerAdapter() {
        @Override/*from w ww  .ja va  2s  . c  om*/
        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) {
        mChangeAnimations.add(changeInfo.newHolder);
        final ViewPropertyAnimatorCompat newViewAnimation = ViewCompat.animate(newView);
        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();
    }
}

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  w  w  w  .  j av  a2 s . co 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:vc908.stickerfactory.ui.advancedrecyclerview.swipeable.ItemSlidingAnimator.java

private boolean animateSlideInternal(final RecyclerView.ViewHolder holder, int translationX, long duration,
        Interpolator interpolator) {/*from  w ww . j  a va2 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;
}

From source file:com.freshdigitable.udonroad.TimelineAnimator.java

private void animateMoveImpl(final Move move) {
    //    Log.d(TAG, "animateMoveImpl: " + debugString(move.holder));
    moveAnimations.add(move.holder);/*w  ww .ja  v a  2  s  .  c o  m*/
    final ViewPropertyAnimatorCompat animate = ViewCompat.animate(move.holder.itemView);
    if (move.deltaX() != 0) {
        animate.translationX(0);
    }
    if (move.deltaY() != 0) {
        animate.translationY(0);
    }
    animate.setDuration(getMoveDuration()).setListener(new ViewPropertyAnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(View view) {
            dispatchMoveStarting(move.holder);
        }

        @Override
        public void onAnimationEnd(View view) {
            animate.setListener(null);
            dispatchMoveFinished(move.holder);
            moveAnimations.remove(move.holder);
            dispatchFinishedWhenDone();
        }

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

From source file:com.lebron.imagebrowse.anim.MyItemAnimator.java

/**
 * //w  w  w. j av a  2  s .c  o  m
 * @param holder
 */
private void animateAddImpl(final ViewHolder holder) {
    final View view = holder.itemView;
    final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
    mAddAnimations.add(holder);
    animation.translationX(0).setDuration(getAddDuration()).setListener(new VpaListenerAdapter() {
        @Override
        public void onAnimationStart(View view) {
            dispatchAddStarting(holder);
        }

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

        @Override
        public void onAnimationEnd(View view) {
            animation.setListener(null);
            dispatchAddFinished(holder);
            mAddAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    }).start();
}