Example usage for android.view ViewPropertyAnimator start

List of usage examples for android.view ViewPropertyAnimator start

Introduction

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

Prototype

public void start() 

Source Link

Document

Starts the currently pending property animations immediately.

Usage

From source file:Main.java

private static void scaleInternal(final View view, int startScaleValue, int endScaleValue, int durationMs,
        int startDelay, AnimatorListenerAdapter listener, Interpolator interpolator) {
    view.setScaleX(startScaleValue);/*from  www.  ja v  a  2 s.co m*/
    view.setScaleY(startScaleValue);

    final ViewPropertyAnimator animator = view.animate();
    animator.cancel();

    animator.setInterpolator(interpolator).scaleX(endScaleValue).scaleY(endScaleValue).setListener(listener)
            .withLayer();

    if (durationMs != DEFAULT_DURATION) {
        animator.setDuration(durationMs);
    }
    animator.setStartDelay(startDelay);

    animator.start();
}

From source file:Main.java

private static void scaleInternal(final View view, int startScaleValue, int endScaleValue, int durationMs,
        int startDelay, AnimatorListenerAdapter listener, Interpolator interpolator) {
    view.setScaleX(startScaleValue);/*from   w  w  w .j a  v  a 2s.c  o m*/
    view.setScaleY(startScaleValue);

    final ViewPropertyAnimator animator = view.animate();
    animator.cancel();

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
        animator.setInterpolator(interpolator).scaleX(endScaleValue).scaleY(endScaleValue)
                .setListener(listener);
    } else {
        animator.setInterpolator(interpolator).scaleX(endScaleValue).scaleY(endScaleValue).setListener(listener)
                .withLayer();
    }
    if (durationMs != DEFAULT_DURATION) {
        animator.setDuration(durationMs);
    }
    animator.setStartDelay(startDelay);

    animator.start();
}

From source file:Main.java

public static void scale(final View view, float fromScale, float toScale, long duration,
        final Runnable whenDone) {
    if (Build.VERSION.SDK_INT >= 12) {
        if (duration == 0) {
            view.setScaleX(toScale);//from   w w w  . ja v a2 s  .c  o m
            view.setScaleY(toScale);
            if (whenDone != null)
                whenDone.run();
        } else {
            ViewPropertyAnimator animation = view.animate().scaleX(toScale).scaleY(toScale)
                    .setDuration(duration);
            if (whenDone != null) {
                animation.setListener(new AnimatorListener() {
                    @Override
                    public void onAnimationCancel(Animator animation) {
                        whenDone.run();
                    }

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        whenDone.run();
                    }

                    @Override
                    public void onAnimationRepeat(Animator animation) {
                    }

                    @Override
                    public void onAnimationStart(Animator animation) {
                    }

                });
            }
            animation.start();
        }
    } else {
        ScaleAnimation scale = new ScaleAnimation(fromScale, toScale, fromScale, toScale,
                Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
        scale.setDuration(duration);
        scale.setFillEnabled(true);
        scale.setFillBefore(true);
        scale.setFillAfter(true);

        if (whenDone != null) {
            scale.setAnimationListener(new AnimationListener() {
                @Override
                public void onAnimationEnd(Animation animation) {
                    whenDone.run();
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }

                @Override
                public void onAnimationStart(Animation animation) {
                }

            });
        }
        addAnimation(view, scale);
    }
}

From source file:com.grarak.kerneladiutor.views.recyclerview.overallstatistics.FrequencyButtonView.java

private void rotate(final View v, boolean reverse) {
    ViewPropertyAnimator animator = v.animate().rotation(reverse ? -360 : 360);
    animator.setListener(new AnimatorListenerAdapter() {
        @Override/*from   w w  w.ja  va  2  s  .c  o m*/
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            v.setRotation(0);
        }
    });
    animator.start();
}

From source file:ir.newway.jazzylistview.JazzyHelper.java

private void doJazzinessImpl(View item, int position, int scrollDirection) {
    try {/* w  ww.  j  a  va  2 s .  c  o m*/
        ViewPropertyAnimator animator = item.animate().setDuration(DURATION).setInterpolator(mInterpolator);

        scrollDirection = scrollDirection > 0 ? 1 : -1;
        mTransitionEffect.initView(item, position, scrollDirection);
        mTransitionEffect.setupAnimation(item, position, scrollDirection, animator);
        animator.start();

    } catch (Exception e) {
        //    e.printStackTrace();
    }
}

From source file:com.guodong.sun.guodong.behavior.MyFabBehavior.java

private void show(final View view) {
    ViewPropertyAnimator animator = view.animate().translationY(0).setInterpolator(INTERPOLATOR)
            .setDuration(200);/*from   ww w  . j a  v a2 s.  co  m*/
    animator.setListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animator) {
            view.setVisibility(View.VISIBLE);
            isAnimate = true;
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            isAnimate = false;
        }

        @Override
        public void onAnimationCancel(Animator animator) {
            hide(view);
        }

        @Override
        public void onAnimationRepeat(Animator animator) {
        }
    });
    animator.start();
}

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   ww  w  .  j a v  a 2s.  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:com.guodong.sun.guodong.behavior.MyFabBehavior.java

private void hide(final View view) {
    ViewPropertyAnimator animator = view.animate().translationY(viewY).setInterpolator(INTERPOLATOR)
            .setDuration(200);/*from  ww  w .ja v  a  2 s .  c o m*/

    animator.setListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animator) {
            isAnimate = true;
        }

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

        @Override
        public void onAnimationCancel(Animator animator) {
            show(view);
        }

        @Override
        public void onAnimationRepeat(Animator animator) {
        }
    });
    animator.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 ww .ja va 2s . com
 *
 * @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;
        }
    });
}

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

/**
 * Sets the visibility of the secondary caller info box.  Note, if the {@code visible} parameter
 * is passed in {@code true}, and there is no secondary caller info populated (as determined by
 * {@code mHasSecondaryCallInfo}, the secondary caller info box will not be shown.
 *
 * @param visible {@code true} if the secondary caller info should be shown, {@code false}
 *      otherwise./*  w  ww  .j  a  v a  2 s.com*/
 */
@Override
public void setSecondaryInfoVisible(final boolean visible) {
    boolean wasVisible = mSecondaryCallInfo.isShown();
    final boolean isVisible = visible && mHasSecondaryCallInfo;
    Log.v(this, "setSecondaryInfoVisible: wasVisible = " + wasVisible + " isVisible = " + isVisible);

    // If visibility didn't change, nothing to do.
    if (wasVisible == isVisible) {
        return;
    }

    // If we are showing the secondary info, we need to show it before animating so that its
    // height will be determined on layout.
    if (isVisible) {
        mSecondaryCallInfo.setVisibility(View.VISIBLE);
    } else {
        mSecondaryCallInfo.setVisibility(View.GONE);
    }

    updateFabPositionForSecondaryCallInfo();
    // We need to translate the secondary caller info, 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);

            // Get the height of the secondary call info now, and then re-hide the view prior
            // to doing the actual animation.
            int secondaryHeight = mSecondaryCallInfo.getHeight();
            if (isVisible) {
                mSecondaryCallInfo.setVisibility(View.GONE);
            } else {
                mSecondaryCallInfo.setVisibility(View.VISIBLE);
            }
            Log.v(this, "setSecondaryInfoVisible: secondaryHeight = " + secondaryHeight);

            // Set the position of the secondary call info card to its starting location.
            mSecondaryCallInfo.setTranslationY(visible ? secondaryHeight : 0);

            // Animate the secondary card info slide up/down as it appears and disappears.
            ViewPropertyAnimator secondaryInfoAnimator = mSecondaryCallInfo.animate()
                    .setInterpolator(AnimUtils.EASE_OUT_EASE_IN).setDuration(mVideoAnimationDuration)
                    .translationY(isVisible ? 0 : secondaryHeight).setListener(new AnimatorListenerAdapter() {
                        @Override
                        public void onAnimationEnd(Animator animation) {
                            if (!isVisible) {
                                mSecondaryCallInfo.setVisibility(View.GONE);
                            }
                        }

                        @Override
                        public void onAnimationStart(Animator animation) {
                            if (isVisible) {
                                mSecondaryCallInfo.setVisibility(View.VISIBLE);
                            }
                        }
                    });
            secondaryInfoAnimator.start();

            // Notify listeners of a change in the visibility of the secondary info. This is
            // important when in a video call so that the video call presenter can shift the
            // video preview up or down to accommodate the secondary caller info.
            InCallPresenter.getInstance().notifySecondaryCallerInfoVisibilityChanged(visible, secondaryHeight);

            return true;
        }
    });
}