Example usage for android.view ViewPropertyAnimator translationX

List of usage examples for android.view ViewPropertyAnimator translationX

Introduction

In this page you can find the example usage for android.view ViewPropertyAnimator translationX.

Prototype

public ViewPropertyAnimator translationX(float value) 

Source Link

Document

This method will cause the View's translationX property to be animated to the specified value.

Usage

From source file:org.sufficientlysecure.keychain.ui.ViewKeyAdvActivity.java

private void animateMenuItem(final MenuItem vEditSubkeys, final boolean animateShow) {

    View actionView = LayoutInflater.from(this).inflate(R.layout.edit_icon, null);
    vEditSubkeys.setActionView(actionView);
    actionView.setTranslationX(animateShow ? 150 : 0);

    ViewPropertyAnimator animator = actionView.animate();
    animator.translationX(animateShow ? 0 : 150);
    animator.setDuration(300);/*from  w  w  w.j av a  2  s  .c o m*/
    animator.setInterpolator(new OvershootInterpolator(1.5f));
    animator.setListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (!animateShow) {
                vEditSubkeys.setVisible(false);
            }
            vEditSubkeys.setActionView(null);
        }
    });
    animator.start();

}

From source file:edward.com.recyclerview.BaseItemAnimator.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 ViewPropertyAnimator oldViewAnim = view.animate().setDuration(getChangeDuration());
        oldViewAnim.translationX(changeInfo.toX - changeInfo.fromX);
        oldViewAnim.translationY(changeInfo.toY - changeInfo.fromY);
        oldViewAnim.alpha(0).setListener(new VpaListenerAdapter() {
            @Override/*from w ww .  j a  v a 2  s.co m*/
            public void onAnimationStart(Animator animation) {
                dispatchChangeStarting(changeInfo.oldHolder, true);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                View mView = view;
                if (animation instanceof ObjectAnimator) {
                    mView = (View) ((ObjectAnimator) animation).getTarget();
                }
                oldViewAnim.setListener(null);
                mView.setAlpha(1);
                mView.setTranslationX(0);
                mView.setTranslationY(0);
                dispatchChangeFinished(changeInfo.oldHolder, true);
                mChangeAnimations.remove(changeInfo.oldHolder);
                dispatchFinishedWhenDone();
            }
        }).start();
    }
    if (newView != null) {
        mChangeAnimations.add(changeInfo.newHolder);
        final ViewPropertyAnimator newViewAnimation = newView.animate();
        newViewAnimation.translationX(0).translationY(0).setDuration(getChangeDuration()).alpha(1)
                .setListener(new VpaListenerAdapter() {
                    @Override
                    public void onAnimationStart(Animator view) {
                        dispatchChangeStarting(changeInfo.newHolder, false);
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        newViewAnimation.setListener(null);
                        newView.setAlpha(1);
                        newView.setTranslationX(0);
                        newView.setTranslationY(0);
                        dispatchChangeFinished(changeInfo.newHolder, false);
                        mChangeAnimations.remove(changeInfo.newHolder);
                        dispatchFinishedWhenDone();
                    }
                }).start();
    }
}

From source file:com.android.incallui.CallCardFragment.java

/**
 * Sets the visibility of the primary call card.
 * Ensures that when the primary call card is hidden, the video surface slides over to fill the
 * entire screen.//from w w  w .  ja  va  2s .  c o  m
 *
 * @param visible {@code True} if the primary call card should be visible.
 */
@Override
public void setCallCardVisible(final boolean visible) {
    Log.v(this, "setCallCardVisible : isVisible = " + visible);
    // When animating the hide/show of the views in a landscape layout, we need to take into
    // account whether we are in a left-to-right locale or a right-to-left locale and adjust
    // the animations accordingly.
    final boolean isLayoutRtl = InCallPresenter.isRtl();

    // Retrieve here since at fragment creation time the incoming video view is not inflated.
    final View videoView = getView().findViewById(R.id.incomingVideo);
    if (videoView == null) {
        return;
    }

    // Determine how much space there is below or to the side of the call card.
    final float spaceBesideCallCard = getSpaceBesideCallCard();

    // We need to translate the video surface, but we need to know its position after the layout
    // has occurred so use a {@code ViewTreeObserver}.
    final ViewTreeObserver observer = getView().getViewTreeObserver();
    observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            // We don't want to continue getting called.
            getView().getViewTreeObserver().removeOnPreDrawListener(this);

            float videoViewTranslation = 0f;

            // Translate the call card to its pre-animation state.
            if (!mIsLandscape) {
                mPrimaryCallCardContainer.setTranslationY(visible ? -mPrimaryCallCardContainer.getHeight() : 0);

                ViewGroup.LayoutParams p = videoView.getLayoutParams();
                videoViewTranslation = p.height / 2 - spaceBesideCallCard / 2;
            }

            // Perform animation of video view.
            ViewPropertyAnimator videoViewAnimator = videoView.animate()
                    .setInterpolator(AnimUtils.EASE_OUT_EASE_IN).setDuration(mVideoAnimationDuration);
            if (mIsLandscape) {
                videoViewAnimator.translationX(visible ? videoViewTranslation : 0);
            } else {
                videoViewAnimator.translationY(visible ? videoViewTranslation : 0);
            }
            videoViewAnimator.start();

            // Animate the call card sliding.
            ViewPropertyAnimator callCardAnimator = mPrimaryCallCardContainer.animate()
                    .setInterpolator(AnimUtils.EASE_OUT_EASE_IN).setDuration(mVideoAnimationDuration)
                    .setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            super.onAnimationEnd(animation);
                            if (!visible) {
                                mPrimaryCallCardContainer.setVisibility(View.GONE);
                            }
                        }

                        @Override
                        public void onAnimationStart(Animator animation) {
                            super.onAnimationStart(animation);
                            if (visible) {
                                mPrimaryCallCardContainer.setVisibility(View.VISIBLE);
                            }
                        }
                    });

            if (mIsLandscape) {
                float translationX = mPrimaryCallCardContainer.getWidth();
                translationX *= isLayoutRtl ? 1 : -1;
                callCardAnimator.translationX(visible ? 0 : translationX).start();
            } else {
                callCardAnimator.translationY(visible ? 0 : -mPrimaryCallCardContainer.getHeight()).start();
            }

            return true;
        }
    });
}