Example usage for android.animation ObjectAnimator addListener

List of usage examples for android.animation ObjectAnimator addListener

Introduction

In this page you can find the example usage for android.animation ObjectAnimator addListener.

Prototype

public void addListener(AnimatorListener listener) 

Source Link

Document

Adds a listener to the set of listeners that are sent events through the life of an animation, such as start, repeat, and end.

Usage

From source file:Main.java

/**
 * rotation y/*from  www  .  ja v  a2  s  .c  o  m*/
 *
 * @param v
 * @param fromY
 * @param toY
 * @param duration
 * @param animatorListener
 */
public static void rotationY(View v, float fromY, float toY, int duration,
        Animator.AnimatorListener animatorListener) {
    ObjectAnimator animator = ObjectAnimator.ofFloat(v, View.ROTATION_Y, fromY, toY);
    animator.setDuration(duration);
    if (animatorListener != null) {
        animator.addListener(animatorListener);
    }
    animator.start();
}

From source file:Main.java

/**
 * rotation x/*from  ww  w.j  a va2 s .com*/
 *
 * @param v
 * @param fromX
 * @param toX
 * @param duration
 * @param animatorListener
 */
public static void rotationX(View v, float fromX, float toX, int duration,
        Animator.AnimatorListener animatorListener) {
    ObjectAnimator animator = ObjectAnimator.ofFloat(v, View.ROTATION_X, fromX, toX);
    animator.setDuration(duration);
    if (animatorListener != null) {
        animator.addListener(animatorListener);
    }
    animator.start();
}

From source file:Main.java

/**
 * alpha/*from  ww w  . j av a  2  s .co m*/
 *
 * @param v
 * @param fromAlpha
 * @param toAlpha
 * @param duration
 * @param animatorListener
 */
public static void alpha(View v, float fromAlpha, float toAlpha, int duration,
        Animator.AnimatorListener animatorListener) {
    ObjectAnimator animator = ObjectAnimator.ofFloat(v, View.ALPHA, fromAlpha, toAlpha);
    animator.setDuration(duration);
    if (animatorListener != null) {
        animator.addListener(animatorListener);
    }
    animator.start();
}

From source file:Main.java

/**
 * translation y// w  ww .  j a  v a2 s .  c om
 *
 * @param v
 * @param fromY
 * @param toY
 * @param duration
 * @param animatorListener
 */
public static void translationY(View v, float fromY, float toY, int duration,
        Animator.AnimatorListener animatorListener) {
    ObjectAnimator animator = ObjectAnimator.ofFloat(v, View.TRANSLATION_Y, fromY, toY);
    animator.setDuration(duration);
    if (animatorListener != null) {
        animator.addListener(animatorListener);
    }
    animator.start();
}

From source file:Main.java

/**
 * translation x//  www .  j av a2  s. c om
 *
 * @param v
 * @param fromX
 * @param toX
 * @param duration
 * @param animatorListener
 */
public static void translationX(View v, float fromX, float toX, int duration,
        Animator.AnimatorListener animatorListener) {
    ObjectAnimator animator = ObjectAnimator.ofFloat(v, View.TRANSLATION_X, fromX, toX);
    animator.setDuration(duration);
    if (animatorListener != null) {
        animator.addListener(animatorListener);
    }
    animator.start();
}

From source file:Main.java

public static void animateHeartButton(final View v) {
    AnimatorSet animatorSet = new AnimatorSet();

    ObjectAnimator rotationAnim = ObjectAnimator.ofFloat(v, "rotation", 0f, 360f);
    rotationAnim.setDuration(300);/*  w  ww.  j  a  v a2 s .  co m*/
    rotationAnim.setInterpolator(ACCELERATE_INTERPOLATOR);

    ObjectAnimator bounceAnimX = ObjectAnimator.ofFloat(v, "scaleX", 0.2f, 1f);
    bounceAnimX.setDuration(300);
    bounceAnimX.setInterpolator(OVERSHOOT_INTERPOLATOR);

    ObjectAnimator bounceAnimY = ObjectAnimator.ofFloat(v, "scaleY", 0.2f, 1f);
    bounceAnimY.setDuration(300);
    bounceAnimY.setInterpolator(OVERSHOOT_INTERPOLATOR);
    bounceAnimY.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
        }

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

    animatorSet.play(bounceAnimX).with(bounceAnimY).after(rotationAnim);
    animatorSet.start();
}

From source file:Main.java

/**
 * Create fade in animation for appearing effect
 *
 * @param target          target view for animating
 * @param durationInMilis animation duration
 * @param delayInMilis    start animation in delay
 * @param listener listener of animation behaviour
 *//*from  w w  w  .j a v a 2s  .  co m*/
public static void setFadeAppearEffect(View target, int durationInMilis, int delayInMilis,
        Animator.AnimatorListener listener) {
    ObjectAnimator alphaAnimation6 = ObjectAnimator.ofFloat(target, "alpha", 0.0F, 1.0F);
    alphaAnimation6.setStartDelay(delayInMilis);
    alphaAnimation6.setDuration(durationInMilis);
    if (listener != null) {
        alphaAnimation6.addListener(listener);
    }
    alphaAnimation6.start();
}

From source file:Main.java

/**
 * Create fade out animation for disappearing effect
 *
 * @param target          target view for animating
 * @param durationInMilis animation duration
 * @param delayInMilis    start animation in delay
 * @param listener listener of animation behaviour
 *///from w w w.  j  av  a  2  s  . c om
public static void setFadeDisappearEffect(View target, int durationInMilis, int delayInMilis,
        Animator.AnimatorListener listener) {
    ObjectAnimator alphaAnimation6 = ObjectAnimator.ofFloat(target, "alpha", 1.0F, 0.0F);
    alphaAnimation6.setStartDelay(delayInMilis);
    alphaAnimation6.setDuration(durationInMilis);
    if (listener != null) {
        alphaAnimation6.addListener(listener);
    }
    alphaAnimation6.start();
}

From source file:Main.java

public static ObjectAnimator alpha_to(final View target) {

    ObjectAnimator objectAnimator = null;

    if (null != target) {
        objectAnimator = ObjectAnimator.ofFloat(target, View.ALPHA, 1f, 0f)
                .setDuration(BUBBLE_ANIMATION_DURATION);

        objectAnimator.addListener(new AnimatorListenerAdapter() {
            @Override/*from  w ww. ja v  a2s  .  c o m*/
            public void onAnimationCancel(Animator animation) {
                super.onAnimationCancel(animation);
                target.setVisibility(View.GONE);
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                super.onAnimationEnd(animation);
                target.setVisibility(View.GONE);
            }
        });

        objectAnimator.start();
    }

    return objectAnimator;
}

From source file:com.grottworkshop.gwscirclereveal.animation.ViewAnimationUtils.java

/**
 * Returns an Animator which can animate a clipping circle.
 * <p>// w  ww .  ja v  a2 s . c om
 * Any shadow cast by the View will respect the circular clip from this animator.
 * <p>
 * Only a single non-rectangular clip can be applied on a View at any time.
 * Views clipped by a circular reveal animation take priority over
 * {@link android.view.View#setClipToOutline(boolean) View Outline clipping}.
 * <p>
 * Note that the animation returned here is a one-shot animation. It cannot
 * be re-used, and once started it cannot be paused or resumed.
 *
 * @param view The View will be clipped to the animating circle.
 * @param centerX The x coordinate of the center of the animating circle.
 * @param centerY The y coordinate of the center of the animating circle.
 * @param startRadius The starting radius of the animating circle.
 * @param endRadius The ending radius of the animating circle.
 */
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static SupportAnimator createCircularReveal(View view, int centerX, int centerY, float startRadius,
        float endRadius) {

    if (!(view.getParent() instanceof RevealAnimator)) {
        throw new IllegalArgumentException("View must be inside RevealFrameLayout or RevealLinearLayout.");
    }

    RevealAnimator revealLayout = (RevealAnimator) view.getParent();
    revealLayout.attachRevealInfo(
            new RevealAnimator.RevealInfo(centerX, centerY, startRadius, endRadius, new WeakReference<>(view)));

    if (LOLLIPOP_PLUS) {
        return new SupportAnimatorLollipop(android.view.ViewAnimationUtils.createCircularReveal(view, centerX,
                centerY, startRadius, endRadius), revealLayout);
    }

    ObjectAnimator reveal = ObjectAnimator.ofFloat(revealLayout, CLIP_RADIUS, startRadius, endRadius);
    reveal.addListener(getRevealFinishListener(revealLayout));

    return new SupportAnimatorPreL(reveal, revealLayout);
}