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

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

Introduction

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

Prototype

public ViewPropertyAnimatorCompat translationY(float f) 

Source Link

Usage

From source file:net.nym.napply.library.behavior.BottomScrollShowHideBehavior.java

private void show(final View child) {
    if (child == null) {
        return;//from   www.  j  av  a2  s .c om
    }
    final float translationY = child.getTranslationY();
    //hide -> show
    if (translationY <= 0 || isAnimate) {
        return;
    }
    ViewPropertyAnimatorCompat animator = ViewCompat.animate(child);
    animator.translationY(0).setDuration(500).setInterpolator(new DecelerateInterpolator())
            .setListener(new ViewPropertyAnimatorListener() {
                @Override
                public void onAnimationStart(View view) {
                    child.setVisibility(View.VISIBLE);
                    isAnimate = true;
                }

                @Override
                public void onAnimationEnd(View view) {
                    isAnimate = false;
                }

                @Override
                public void onAnimationCancel(View view) {
                    hide(child);
                }
            }).start();
}

From source file:net.nym.napply.library.behavior.BottomScrollShowHideBehavior.java

private void hide(final View child) {
    if (child == null) {
        return;//w ww  . j  a  v  a2s.c  om
    }
    final float translationY = child.getTranslationY();
    //show -> hide
    if (translationY < 0 || isAnimate) {
        return;
    }
    ViewPropertyAnimatorCompat animator = ViewCompat.animate(child);
    animator.translationY(child.getHeight()).setDuration(500).setInterpolator(new DecelerateInterpolator())
            .setListener(new ViewPropertyAnimatorListener() {
                @Override
                public void onAnimationStart(View view) {
                    isAnimate = true;
                }

                @Override
                public void onAnimationEnd(View view) {
                    child.setVisibility(View.GONE);
                    isAnimate = false;
                }

                @Override
                public void onAnimationCancel(View view) {
                    show(child);
                }
            }).start();
}

From source file:net.nym.napply.library.behavior.HeadScrollShowHideBehavior.java

private void show(final View child) {
    if (child == null) {
        return;/*from   w  w w .j  a  v  a2 s .  co m*/
    }
    final float translationY = child.getTranslationY();
    //hide -> show
    if (translationY >= 0 || isAnimate) {
        return;
    }
    ViewPropertyAnimatorCompat animator = ViewCompat.animate(child);
    animator.translationY(0).setDuration(500).setInterpolator(new DecelerateInterpolator())
            .setListener(new ViewPropertyAnimatorListener() {
                @Override
                public void onAnimationStart(View view) {
                    child.setVisibility(View.VISIBLE);
                    isAnimate = true;
                }

                @Override
                public void onAnimationEnd(View view) {
                    isAnimate = false;
                }

                @Override
                public void onAnimationCancel(View view) {
                    hide(child);
                }
            }).start();
}

From source file:net.nym.napply.library.behavior.HeadScrollShowHideBehavior.java

private void hide(final View child) {
    if (child == null) {
        return;//  ww w.j  a v  a 2s  .c om
    }
    final float translationY = child.getTranslationY();
    //show -> hide
    if (translationY < 0 || isAnimate) {
        return;
    }
    ViewPropertyAnimatorCompat animator = ViewCompat.animate(child);
    animator.translationY(-child.getHeight()).setDuration(500).setInterpolator(new DecelerateInterpolator())
            .setListener(new ViewPropertyAnimatorListener() {
                @Override
                public void onAnimationStart(View view) {
                    isAnimate = true;
                }

                @Override
                public void onAnimationEnd(View view) {
                    child.setVisibility(View.GONE);
                    isAnimate = false;
                }

                @Override
                public void onAnimationCancel(View view) {
                    show(child);
                }
            }).start();
}

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

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

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

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

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

protected void animateAddImpl(final RecyclerView.ViewHolder holder) {
    final View view = holder.itemView;

    final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);
    mAddAnimations.add(holder);/*from  ww  w  .ja v a2  s .c o  m*/
    animation.translationY(0).alpha(1).setDuration(getAddDuration()).setListener(new VpaListenerAdapter() {
        @Override
        public void onAnimationStart(View view) {
            dispatchAddStarting(holder);
        }

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

        @Override
        public void onAnimationEnd(View view) {
            animation.setListener(null);
            ViewCompat.setAlpha(view, 1);
            ViewCompat.setTranslationY(view, 0);
            dispatchAddFinished(holder);
            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/*from  w w  w.  ja va 2s .  c om*/
            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 w  w w. ja v a2 s  .com
            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//  w w  w.  j  av a  2s.c  o m
        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: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 w w .  jav  a2  s. com
    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);
    }
}