Example usage for android.animation ObjectAnimator ofFloat

List of usage examples for android.animation ObjectAnimator ofFloat

Introduction

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

Prototype

public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> xProperty, Property<T, Float> yProperty,
        Path path) 

Source Link

Document

Constructs and returns an ObjectAnimator that animates coordinates along a Path using two properties.

Usage

From source file:Main.java

public static void doSimpleRefresh(Object view, int repeat) {
    LinearInterpolator interpolator = new LinearInterpolator();
    ObjectAnimator refreshAnimator = ObjectAnimator.ofFloat(view, "rotation", 0f, 360f);
    refreshAnimator.setInterpolator(interpolator);
    refreshAnimator.setDuration(300);/*  ww  w .j  av a 2  s .  c o  m*/
    refreshAnimator.setRepeatCount(repeat);
    refreshAnimator.start();
}

From source file:Main.java

public static void scaleHide(final View view, final Runnable rWhenEnd) {
    if (view.getWindowToken() == null) {
        view.setVisibility(View.INVISIBLE);
        if (rWhenEnd != null) {
            rWhenEnd.run();//  ww  w  . j  ava  2  s .  co m
        }
        return;
    }
    ObjectAnimator scaleX = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0f);
    ObjectAnimator scaleY = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0f);
    AnimatorSet set = new AnimatorSet();
    set.playTogether(scaleX, scaleY);
    set.setDuration(DURATION_SHORT);
    set.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

        }

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

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

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
    set.start();
}

From source file:Main.java

/**
 * Animator to animate X scale of the view. Y scale is constant
 *
 * @param view View to be animated//w  ww  . j a  v a  2 s  . c  om
 * @param pivotX x coordinate of the pivot
 * @param pivotY y coordinate of the pivot
 * @param fromScale initial scale
 * @param toScale final scale
 * @param duration animation duration in milliseconds
 * @return Animator Object
 */
@NonNull
public static Animator scaleX(@NonNull View view, int pivotX, int pivotY, float fromScale, float toScale,
        int duration) {
    view.setPivotX(pivotX);
    view.setPivotY(pivotY);
    Animator animator = ObjectAnimator.ofFloat(view, "scaleX", fromScale, toScale);
    animator.setDuration(duration);
    return animator;
}

From source file:Main.java

/**
 * Animator to animate Y scale of the view. X scale is constant
 *
 * @param view View to be animated/*ww  w  .j  a  va2  s  .c o m*/
 * @param pivotX x coordinate of the pivot
 * @param pivotY y coordinate of the pivot
 * @param fromScale initial scale
 * @param toScale final scale
 * @param duration animation duration in milliseconds
 * @return Animator Object
 */
@NonNull
public static Animator scaleY(@NonNull View view, int pivotX, int pivotY, float fromScale, float toScale,
        int duration) {
    view.setPivotX(pivotX);
    view.setPivotY(pivotY);
    Animator animator = ObjectAnimator.ofFloat(view, "scaleY", fromScale, toScale);
    animator.setDuration(duration);
    return animator;
}

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);//ww w .j  av a2 s. 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

/**
 * This method creates an Object Animator based on the targeted view, the property to be
 * animated and the initial value and final value
 *
 * @param view/*from  ww w  .  j a  v a  2 s  .co  m*/
 *         Target view
 * @param property
 *         Property to be animated
 * @param init
 *         Initial value
 * @param end
 *         Final value
 * @param duration
 *         Animation duration
 *
 * @return ObjectAnimator with the given animated property
 */
@NonNull
public static ObjectAnimator createObjectAnimator(View view, String property, float init, float end,
        long duration) {
    ObjectAnimator scaleXAnimation = ObjectAnimator.ofFloat(view, property, init, end);
    scaleXAnimation.setInterpolator(new AccelerateDecelerateInterpolator());
    scaleXAnimation.setDuration(duration);
    return scaleXAnimation;
}

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);/*from  w  ww  .j  a  va  2  s .  c  om*/
    animator.setRepeatMode(ValueAnimator.REVERSE);
    animator.setRepeatCount(ValueAnimator.INFINITE);
    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    animator.start();
}

From source file:Main.java

public static ObjectAnimator to_alpha(View target) {

    ObjectAnimator objectAnimator = null;
    if (null != target && target.getVisibility() != View.VISIBLE) {
        target.setVisibility(View.VISIBLE);

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

        objectAnimator.start();// w  w w.j a va 2s . c  o  m
    }

    return objectAnimator;
}

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 w w  .  ja va  2  s  .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: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 a  v  a 2s.co 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();
}