Example usage for android.animation ObjectAnimator setInterpolator

List of usage examples for android.animation ObjectAnimator setInterpolator

Introduction

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

Prototype

@Override
public void setInterpolator(TimeInterpolator value) 

Source Link

Document

The time interpolator used in calculating the elapsed fraction of this animation.

Usage

From source file:Main.java

public static void animateHeart(View view) {
    AnimatorSet animatorSet = new AnimatorSet();
    ObjectAnimator imgScaleUpYAnim = ObjectAnimator.ofFloat(view, "scaleY", 1.0f, 1.2f);
    imgScaleUpYAnim.setDuration(300);//from   w ww.j  a v  a  2 s  . co m
    ObjectAnimator imgScaleUpXAnim = ObjectAnimator.ofFloat(view, "scaleX", 1.0f, 1.2f);
    imgScaleUpXAnim.setDuration(300);
    ObjectAnimator imgScaleDownYAnim = ObjectAnimator.ofFloat(view, "scaleY", 1.2f, 1.0f);
    imgScaleDownYAnim.setDuration(300);
    imgScaleDownYAnim.setInterpolator(ACCELERATE_INTERPOLATOR);
    ObjectAnimator imgScaleDownXAnim = ObjectAnimator.ofFloat(view, "scaleX", 1.2f, 1.0f);
    imgScaleDownXAnim.setDuration(300);
    animatorSet.playTogether(imgScaleUpXAnim, imgScaleUpYAnim);
    animatorSet.play(imgScaleDownYAnim).with(imgScaleDownXAnim).after(imgScaleUpXAnim);
    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            view.clearAnimation();
            animatorSet.start();
        }
    });
    animatorSet.start();
}

From source file:Main.java

public static void shake(View v) {
    final float distance = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 4.0f,
            v.getResources().getDisplayMetrics());
    final ObjectAnimator animator = ObjectAnimator.ofFloat(v, "translationX", 0, distance, 0, -distance, 0);
    animator.setRepeatMode(ObjectAnimator.RESTART);
    animator.setInterpolator(new LinearInterpolator());
    animator.setRepeatCount(4);/*from  w  w  w .j av a  2s.  co  m*/
    animator.setDuration(150);
    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);//from   w  ww.j ava2s. c o  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

public static void animatePhotoLike(final ImageView likeBg, final ImageView likeIcon) {
    likeBg.setVisibility(View.VISIBLE);
    likeIcon.setVisibility(View.VISIBLE);

    likeBg.setScaleY(0.1f);//from   ww w  .  j  av  a2  s .c  o m
    likeBg.setScaleX(0.1f);
    likeBg.setAlpha(1f);
    likeIcon.setScaleY(0.1f);
    likeIcon.setScaleX(0.1f);

    AnimatorSet animatorSet = new AnimatorSet();

    ObjectAnimator bgScaleYAnim = ObjectAnimator.ofFloat(likeBg, "scaleY", 0.1f, 1f);
    bgScaleYAnim.setDuration(200);
    bgScaleYAnim.setInterpolator(DECCELERATE_INTERPOLATOR);
    ObjectAnimator bgScaleXAnim = ObjectAnimator.ofFloat(likeBg, "scaleX", 0.1f, 1f);
    bgScaleXAnim.setDuration(200);
    bgScaleXAnim.setInterpolator(DECCELERATE_INTERPOLATOR);
    ObjectAnimator bgAlphaAnim = ObjectAnimator.ofFloat(likeBg, "alpha", 1f, 0f);
    bgAlphaAnim.setDuration(200);
    bgAlphaAnim.setStartDelay(150);
    bgAlphaAnim.setInterpolator(DECCELERATE_INTERPOLATOR);

    ObjectAnimator imgScaleUpYAnim = ObjectAnimator.ofFloat(likeIcon, "scaleY", 0.1f, 1f);
    imgScaleUpYAnim.setDuration(300);
    imgScaleUpYAnim.setInterpolator(DECCELERATE_INTERPOLATOR);
    ObjectAnimator imgScaleUpXAnim = ObjectAnimator.ofFloat(likeIcon, "scaleX", 0.1f, 1f);
    imgScaleUpXAnim.setDuration(300);
    imgScaleUpXAnim.setInterpolator(DECCELERATE_INTERPOLATOR);

    ObjectAnimator imgScaleDownYAnim = ObjectAnimator.ofFloat(likeIcon, "scaleY", 1f, 0f);
    imgScaleDownYAnim.setDuration(300);
    imgScaleDownYAnim.setInterpolator(ACCELERATE_INTERPOLATOR);
    ObjectAnimator imgScaleDownXAnim = ObjectAnimator.ofFloat(likeIcon, "scaleX", 1f, 0f);
    imgScaleDownXAnim.setDuration(300);
    imgScaleDownXAnim.setInterpolator(ACCELERATE_INTERPOLATOR);

    animatorSet.playTogether(bgScaleYAnim, bgScaleXAnim, bgAlphaAnim, imgScaleUpYAnim, imgScaleUpXAnim);
    animatorSet.play(imgScaleDownYAnim).with(imgScaleDownXAnim).after(imgScaleUpYAnim);

    animatorSet.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            resetLikeAnimationState(likeBg, likeIcon);
        }
    });
    animatorSet.start();
}

From source file:by.gdgminsk.animationguide.util.AnimUtils.java

public static void scaleOut(final View view, int delay) {
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 0.0f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 0.0f);
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0.4f);
    ObjectAnimator scaleOutAnimation = ObjectAnimator.ofPropertyValuesHolder(view, alpha, scaleX, scaleY);
    scaleOutAnimation.setInterpolator(EASE_OUT_INTERPOLATOR);
    scaleOutAnimation.addListener(new AnimatorListenerAdapter() {
        @Override/*from w  w w. jav a  2  s.  c o m*/
        public void onAnimationEnd(Animator animation) {
            view.setVisibility(View.GONE);
        }

        @Override
        public void onAnimationStart(Animator animation) {
            view.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            view.setScaleX(0.0f);
            view.setScaleY(0.0f);
            view.setVisibility(View.GONE);
        }
    });
    scaleOutAnimation.setDuration(view.getResources().getInteger(R.integer.duration_fab_scale_out));
    scaleOutAnimation.setStartDelay(delay);

    scaleOutAnimation.start();
}

From source file:Main.java

public static void breath(View v, float fromRange, float toRange, long duration) {
    ObjectAnimator animator = ObjectAnimator.ofFloat(v, View.ALPHA, fromRange, toRange);
    animator.setDuration(duration);/*ww w .  ja v  a 2s . c o  m*/
    animator.setRepeatMode(ValueAnimator.REVERSE);
    animator.setRepeatCount(ValueAnimator.INFINITE);
    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    animator.start();
}

From source file:Main.java

public static void animatePhotoLike(final View vBgLike, final View ivLike) {
    vBgLike.setVisibility(View.VISIBLE);
    ivLike.setVisibility(View.VISIBLE);

    vBgLike.setScaleY(0.1f);/*w ww.ja  v a 2  s. c  o  m*/
    vBgLike.setScaleX(0.1f);
    vBgLike.setAlpha(1f);
    ivLike.setScaleY(0.1f);
    ivLike.setScaleX(0.1f);

    android.animation.AnimatorSet animatorSet = new android.animation.AnimatorSet();

    android.animation.ObjectAnimator bgScaleYAnim = android.animation.ObjectAnimator.ofFloat(vBgLike, "scaleY",
            0.1f, 1f);
    bgScaleYAnim.setDuration(200);
    bgScaleYAnim.setInterpolator(DECELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator bgScaleXAnim = android.animation.ObjectAnimator.ofFloat(vBgLike, "scaleX",
            0.1f, 1f);
    bgScaleXAnim.setDuration(200);
    bgScaleXAnim.setInterpolator(DECELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator bgAlphaAnim = android.animation.ObjectAnimator.ofFloat(vBgLike, "alpha",
            1f, 0f);
    bgAlphaAnim.setDuration(200);
    bgAlphaAnim.setStartDelay(150);
    bgAlphaAnim.setInterpolator(DECELERATE_INTERPOLATOR);

    android.animation.ObjectAnimator imgScaleUpYAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleY", 0.1f, 1f);
    imgScaleUpYAnim.setDuration(300);
    imgScaleUpYAnim.setInterpolator(DECELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator imgScaleUpXAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleX", 0.1f, 1f);
    imgScaleUpXAnim.setDuration(300);
    imgScaleUpXAnim.setInterpolator(DECELERATE_INTERPOLATOR);

    android.animation.ObjectAnimator imgScaleDownYAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleY", 1f, 0f);
    imgScaleDownYAnim.setDuration(300);
    imgScaleDownYAnim.setInterpolator(ACCELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator imgScaleDownXAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleX", 1f, 0f);
    imgScaleDownXAnim.setDuration(300);
    imgScaleDownXAnim.setInterpolator(ACCELERATE_INTERPOLATOR);

    animatorSet.playTogether(bgScaleYAnim, bgScaleXAnim, bgAlphaAnim, imgScaleUpYAnim, imgScaleUpXAnim);
    animatorSet.play(imgScaleDownYAnim).with(imgScaleDownXAnim).after(imgScaleUpYAnim);

    animatorSet.addListener(new android.animation.AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(android.animation.Animator animation) {
            vBgLike.setVisibility(View.INVISIBLE);
            ivLike.setVisibility(View.INVISIBLE);
        }
    });
    animatorSet.start();
}

From source file:Main.java

public static void animatePhotoLike(final View vBgLike, final View ivLike) {
    vBgLike.setVisibility(View.VISIBLE);
    ivLike.setVisibility(View.VISIBLE);

    vBgLike.setScaleY(0.1f);// www  . j a  va  2s .c  o  m
    vBgLike.setScaleX(0.1f);
    vBgLike.setAlpha(1f);
    ivLike.setScaleY(0.1f);
    ivLike.setScaleX(0.1f);

    android.animation.AnimatorSet animatorSet = new android.animation.AnimatorSet();

    android.animation.ObjectAnimator bgScaleYAnim = android.animation.ObjectAnimator.ofFloat(vBgLike, "scaleY",
            0.1f, 1f);
    bgScaleYAnim.setDuration(200);
    bgScaleYAnim.setInterpolator(DECCELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator bgScaleXAnim = android.animation.ObjectAnimator.ofFloat(vBgLike, "scaleX",
            0.1f, 1f);
    bgScaleXAnim.setDuration(200);
    bgScaleXAnim.setInterpolator(DECCELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator bgAlphaAnim = android.animation.ObjectAnimator.ofFloat(vBgLike, "alpha",
            1f, 0f);
    bgAlphaAnim.setDuration(200);
    bgAlphaAnim.setStartDelay(150);
    bgAlphaAnim.setInterpolator(DECCELERATE_INTERPOLATOR);

    android.animation.ObjectAnimator imgScaleUpYAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleY", 0.1f, 1f);
    imgScaleUpYAnim.setDuration(300);
    imgScaleUpYAnim.setInterpolator(DECCELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator imgScaleUpXAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleX", 0.1f, 1f);
    imgScaleUpXAnim.setDuration(300);
    imgScaleUpXAnim.setInterpolator(DECCELERATE_INTERPOLATOR);

    android.animation.ObjectAnimator imgScaleDownYAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleY", 1f, 0f);
    imgScaleDownYAnim.setDuration(300);
    imgScaleDownYAnim.setInterpolator(ACCELERATE_INTERPOLATOR);
    android.animation.ObjectAnimator imgScaleDownXAnim = android.animation.ObjectAnimator.ofFloat(ivLike,
            "scaleX", 1f, 0f);
    imgScaleDownXAnim.setDuration(300);
    imgScaleDownXAnim.setInterpolator(ACCELERATE_INTERPOLATOR);

    animatorSet.playTogether(bgScaleYAnim, bgScaleXAnim, bgAlphaAnim, imgScaleUpYAnim, imgScaleUpXAnim);
    animatorSet.play(imgScaleDownYAnim).with(imgScaleDownXAnim).after(imgScaleUpYAnim);

    animatorSet.addListener(new android.animation.AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(android.animation.Animator animation) {
            vBgLike.setVisibility(View.INVISIBLE);
            ivLike.setVisibility(View.INVISIBLE);
        }
    });
    animatorSet.start();
}

From source file:Main.java

public static void animateTextChange(final TextView view, final String toText) {
    ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f);
    final ObjectAnimator restore = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f);
    alpha.setDuration(DURATION_SHORT);//from  w  w  w .ja v a 2 s  . c  o  m
    alpha.setInterpolator(new AccelerateDecelerateInterpolator());
    restore.setDuration(DURATION_SHORT);
    restore.setInterpolator(new AccelerateDecelerateInterpolator());
    alpha.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
            // Do nothing.
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            view.setText(toText);
            restore.start();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            view.setText(toText);
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
            // Do nothing.
        }
    });
    alpha.start();
}

From source file:Main.java

public static void animateTextChange(final TextView view, @IdRes final int toText, final Runnable rWhenEnd) {
    ObjectAnimator alpha = ObjectAnimator.ofFloat(view, "alpha", 1f, 0f);
    final ObjectAnimator restore = ObjectAnimator.ofFloat(view, "alpha", 0f, 1f);
    alpha.setDuration(DURATION_SHORT);//from   www.ja va 2 s . co  m
    alpha.setInterpolator(new AccelerateDecelerateInterpolator());
    restore.setDuration(DURATION_SHORT);
    restore.setInterpolator(new AccelerateDecelerateInterpolator());
    alpha.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
            // Do nothing.
        }

        @SuppressWarnings("ResourceType")
        @Override
        public void onAnimationEnd(Animator animation) {
            view.setText(toText);
            restore.start();
        }

        @SuppressWarnings("ResourceType")
        @Override
        public void onAnimationCancel(Animator animation) {
            view.setText(toText);
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
            // Do nothing.
        }
    });
    if (rWhenEnd != null)
        restore.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

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

            @Override
            public void onAnimationCancel(Animator animation) {
                rWhenEnd.run();
            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });
    alpha.start();
}