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

public static void bindView(ObjectAnimator animator, final View view) {

    animator.addListener(new Animator.AnimatorListener() {
        @Override//  www .  j a v  a  2 s .  c o  m
        public void onAnimationStart(Animator animation) {

        }

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

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
}

From source file:Main.java

public static void animHide(final View v, int duration, float from, float to, final boolean gone) {
    v.clearAnimation();//w w  w.  j a v  a2 s.  c o  m
    ObjectAnimator anim = ObjectAnimator.ofFloat(v, "alpha", from, to).setDuration(duration);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            if (gone) {
                v.setVisibility(View.GONE);
            }
        }
    });
    anim.start();
}

From source file:Main.java

public static void animateTextViewMaxLinesChange(final TextView textView, final int maxLines,
        final int duration) {
    final int startHeight = textView.getMeasuredHeight();
    textView.setMaxLines(maxLines);//from ww  w . java2  s  .c  o  m
    textView.measure(View.MeasureSpec.makeMeasureSpec(textView.getWidth(), View.MeasureSpec.EXACTLY),
            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
    final int endHeight = textView.getMeasuredHeight();
    ObjectAnimator animation = ObjectAnimator.ofInt(textView, MAX_HEIGHT_ATTR, startHeight, endHeight);
    animation.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (textView.getMaxHeight() == endHeight) {
                textView.setMaxLines(maxLines);
            }
        }
    }

    );
    animation.setDuration(duration).start();
}

From source file:Main.java

public static ObjectAnimator fadeIn(final View v) {
    ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(v, "alpha", 0f, 1f);
    alphaAnim.setDuration(ANIM_DURATION_FADEIN);
    alphaAnim.addListener(new AnimatorListenerAdapter() {
        @Override//from   w  ww .ja  v  a2 s. c  om
        public void onAnimationStart(Animator animation) {
            v.setVisibility(View.VISIBLE);
        }
    });

    return alphaAnim;
}

From source file:Main.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static void fadeOutHoneyComb(final View view) {
    view.setAlpha(1.0F);/*from  www  .  j a  va  2s.c o  m*/
    ObjectAnimator animator = ObjectAnimator.ofFloat(view, "alpha", 1.0F, 0.0F).setDuration(ANIMATION_DURATION);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(android.animation.Animator animation) {
            view.setVisibility(View.GONE);
            view.setAlpha(1.0F);
        }
    });
    animator.start();
}

From source file:Main.java

public static ObjectAnimator inflate(final View v) {
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0f, 1f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0f, 1f);
    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(v, scaleX, scaleY);
    animator.setDuration(ANIM_DURATION_INFLATE);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override/*from   ww  w  .j a va  2 s .  c  om*/
        public void onAnimationStart(Animator animation) {
            v.setVisibility(View.VISIBLE);
        }
    });

    return animator;
}

From source file:Main.java

public static ObjectAnimator inflateFadeIn(final View v) {
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0f, 1f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0f, 1f);
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0f, 1f);
    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(v, scaleX, scaleY, alpha);
    animator.setDuration(ANIM_DURATION_INFLATE);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override//from  w  ww.j ava 2s.  c  o  m
        public void onAnimationStart(Animator animation) {
            v.setVisibility(View.VISIBLE);
        }
    });

    return animator;
}

From source file:Main.java

public static void alphaHide(@NonNull final View view, final Runnable rWhenDone) {
    if (view.getWindowToken() == null) {
        if (rWhenDone != null)
            rWhenDone.run();/*from w  w  w .j av a2 s.co  m*/
        return;
    }
    ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f);
    alpha.setDuration(DURATION_MID);
    alpha.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            view.setVisibility(View.INVISIBLE);
            if (rWhenDone != null)
                rWhenDone.run();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            view.setVisibility(View.INVISIBLE);
            if (rWhenDone != null)
                rWhenDone.run();
        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
    alpha.start();
}

From source file:Main.java

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

From source file:Main.java

/**
 * scale x/*from   ww  w  .ja v  a2  s .  c o m*/
 *
 * @param v
 * @param fromX
 * @param toX
 * @param duration
 * @param animatorListener
 */
public static void scaleX(View v, float fromX, float toX, int duration,
        Animator.AnimatorListener animatorListener) {
    ObjectAnimator animator = ObjectAnimator.ofFloat(v, View.SCALE_X, fromX, toX);
    animator.setDuration(duration);
    if (animatorListener != null) {
        animator.addListener(animatorListener);
    }
    animator.start();
}