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:com.hippo.nimingban.itemanimator.FloatItemAnimator.java

private void animateAddImpl(final RecyclerView.ViewHolder holder, float translationY) {
    final View view = holder.itemView;
    final ViewPropertyAnimatorCompat animation = ViewCompat.animate(view);

    view.setVisibility(View.VISIBLE);
    mAddAnimations.add(holder);/*from w  ww. j  av  a2 s. co m*/
    view.setTranslationY(translationY);
    animation.translationY(0.0f).setDuration((long) (translationY / SPEED))
            .setInterpolator(AnimationUtils2.FAST_SLOW_INTERPOLATOR).setListener(new VpaListenerAdapter() {
                @Override
                public void onAnimationStart(View view) {
                    dispatchAddStarting(holder);
                }

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

                @Override
                public void onAnimationEnd(View view) {
                    animation.setListener(null);
                    dispatchAddFinished(holder);
                    mAddAnimations.remove(holder);
                    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;// w  w w .j  av  a2  s  .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:com.kozhevin.example.carousel.CarouselItemAnimator.java

private void animateRemoveImpl(final ViewHolder pHolder) {
    final View view = pHolder.itemView;
    ViewCompat.animate(view).cancel();//from  www  . ja  v  a  2 s .  co m
    if (getTranslationValueY() != 0 && mIsUseTranslationAnimation) {
        ViewPropertyAnimatorCompat lViewPropertyAnimatorCompat = ViewCompat.animate(view);
        lViewPropertyAnimatorCompat.setDuration(350);
        lViewPropertyAnimatorCompat.translationY(getTranslationValueY());
        lViewPropertyAnimatorCompat.setListener(new ViewPropertyAnimatorListener() {

            @Override
            public void onAnimationStart(View arg0) {
            }

            @Override
            public void onAnimationEnd(View arg0) {
                animateAlhaRemove(view, pHolder);
            }

            @Override
            public void onAnimationCancel(View arg0) {
            }
        });
        ViewCompat.animate(view).start();
    } else {
        if (mIsUseTranslationAnimation) {
            view.setAlpha(0f);
            mIsUseTranslationAnimation = true;
        }
        animateAlhaRemove(view, pHolder);

    }
    mRemoveAnimations.add(pHolder);
}

From source file:cn.zhangls.android.weibo.ui.weibo.RecyclerItemAnimator.java

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

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

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

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);//from w  w  w.  ja  va2s .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:net.simonvt.cathode.widget.ScalingItemAnimator.java

private void animateChangeImpl(final ChangeInfo changeInfo) {
    final ViewHolder holder = changeInfo.oldHolder;
    final View view = holder.itemView;
    final ViewHolder newHolder = changeInfo.newHolder;
    final View newView = newHolder != null ? newHolder.itemView : null;
    changeAnimations.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 www.  j a v a2  s  .co 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);
            changeAnimations.remove(changeInfo.oldHolder);
            dispatchFinishedWhenDone();
        }
    }).start();
    if (newView != null) {
        changeAnimations.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);
                        changeAnimations.remove(changeInfo.newHolder);
                        dispatchFinishedWhenDone();
                    }
                }).start();
    }
}

From source file:com.example.administrator.demorecyler.MyItemAnimator.java

private void animateChangeImpl(final ChangeInfo changeInfo) {
    final ViewHolder holder = changeInfo.oldHolder;
    final View view = holder.itemView;
    final 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  w w  .j  a v  a2s .  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:com.example.recycleviewexample.ScaleInItemAnimator.java

private void animateChangeImpl(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) {
        mChangeAnimations.add(changeInfo.oldHolder);
        final ViewPropertyAnimatorCompat oldViewAnim = ViewCompat.animate(view)
                .setDuration(getChangeDuration());
        oldViewAnim.translationX(changeInfo.toX - changeInfo.fromX);
        oldViewAnim.translationY(changeInfo.toY - changeInfo.fromY);
        ViewCompat.setPivotX(view, view.getWidth());
        oldViewAnim.scaleX(0).setListener(new VpaListenerAdapter() {
            @Override/* www  .j  a  v  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);
                ViewCompat.setPivotX(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);

        Log.d(Common.Tag, " Pivot : " + ViewCompat.getPivotX(view));

        ViewCompat.setPivotX(newView, 0.0f);
        ViewCompat.setScaleX(newView, 0.0f);
        newViewAnimation.translationX(0).translationY(0).scaleX(1.0f).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.oginotihiro.snackbar.Snackbar.java

private void animateViewOut(final int event) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        ViewPropertyAnimatorCompat vpac = ViewCompat.animate(mView);

        if (mDirection == LEFT_RIGHT) {
            vpac.translationX(-mView.getWidth());
        } else if (mDirection == TOP_BOTTOM) {
            vpac.translationY(-mView.getHeight());
        } else if (mDirection == RIGHT_LEFT) {
            vpac.translationX(mView.getWidth());
        } else if (mDirection == BOTTOM_TOP) {
            vpac.translationY(mView.getHeight());
        }//from w w w .ja v a2s . c  o m

        vpac.setInterpolator(new FastOutSlowInInterpolator()).setDuration(mAnimDuration)
                .setListener(new ViewPropertyAnimatorListenerAdapter() {
                    @Override
                    public void onAnimationStart(View view) {
                        mView.animateChildrenOut(0, mAnimFadeDuration);
                    }

                    @Override
                    public void onAnimationEnd(View view) {
                        onViewHidden(event);
                    }
                }).start();
    } else {
        Animation anim = null;

        if (mDirection == LEFT_RIGHT) {
            anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.oginotihiro_snackbar_left_out);
        } else if (mDirection == TOP_BOTTOM) {
            anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.oginotihiro_snackbar_top_out);
        } else if (mDirection == RIGHT_LEFT) {
            anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.oginotihiro_snackbar_right_out);
        } else if (mDirection == BOTTOM_TOP) {
            anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.oginotihiro_snackbar_bottom_out);
        }

        if (anim == null)
            return;

        anim.setInterpolator(new FastOutSlowInInterpolator());
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                onViewHidden(event);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        mView.startAnimation(anim);
    }
}

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

private 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 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/* ww  w  .  j  a  v  a2  s  .  com*/
            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();
    }
}