Example usage for android.animation ObjectAnimator start

List of usage examples for android.animation ObjectAnimator start

Introduction

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

Prototype

@Override
    public void start() 

Source Link

Usage

From source file:com.ae.apps.messagecounter.fragments.SentCountFragment.java

/**
 * Sets the progress value to a progressbar, with animation if the OS supports it
 * // w w w  .  j av  a  2s  .c o m
 * @param progressBar
 * @param progress
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static void setProgressWithAnimation(ProgressBar progressBar, int progress, long animDelay) {
    // We try to add animation for newer APIs here
    if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.HONEYCOMB) {
        android.animation.ObjectAnimator animation = android.animation.ObjectAnimator.ofInt(progressBar,
                PROGRESS_VALUE, 0, progress);
        animation.setDuration(100);
        animation.setStartDelay(animDelay);
        animation.setInterpolator(new AccelerateDecelerateInterpolator());
        animation.start();
    } else {
        progressBar.setProgress(progress);
    }
}

From source file:com.miz.utils.ViewUtils.java

/**
 * Animates the transition when changing the maxLines
 * attribute of a TextView.// w  ww  . j  a  v a 2  s. c  o  m
 * @param text
 * @param maxLines
 */
public static void animateTextViewMaxLines(TextView text, int maxLines) {
    try {
        ObjectAnimator animation = ObjectAnimator.ofInt(text, "maxLines", maxLines);
        animation.setInterpolator(new AccelerateInterpolator());
        animation.setDuration(200);
        animation.start();
    } catch (Exception e) {
        // Some devices crash at runtime when using the ObjectAnimator
        text.setMaxLines(maxLines);
    }
}

From source file:me.calebjones.spacelaunchnow.utils.Utils.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static void animateViewColor(View v, int startColor, int endColor) {

    ObjectAnimator animator = ObjectAnimator.ofObject(v, "backgroundColor", new ArgbEvaluator(), startColor,
            endColor);//  ww w.  j av  a2 s.  c  o m

    animator.setInterpolator(new PathInterpolator(0.4f, 0f, 1f, 1f));
    animator.setDuration(COLOR_ANIMATION_DURATION);
    animator.start();
}

From source file:com.miz.utils.ViewUtils.java

public static void animateFabJump(View fab, Animator.AnimatorListener listener) {
    try {// w w w .  ja v a  2  s  . c  om
        ObjectAnimator animation = ObjectAnimator.ofFloat(fab, "translationY", -10f, -5f, 0f, 5f, 10f, 5f, 0f,
                -5f, -10f, -5f, 0f);
        animation.setDuration(350);
        animation.addListener(listener);
        animation.start();
    } catch (Exception e) {
        // Some devices crash at runtime when using the ObjectAnimator
    }
}

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);//ww w. j  av a2 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 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.j a  va2 s.c  om*/
            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 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  ww w  . ja v  a2  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();
}

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();// w w w. j a  v a  2  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:by.gdgminsk.animationguide.util.AnimUtils.java

public static void scaleIn(final View view, int delay) {
    view.setAlpha(0.0f);/*  w ww  .  j  ava  2s . co m*/
    view.setScaleX(0.0f);
    view.setScaleY(0.0f);
    PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f);
    PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f);
    PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f);
    ObjectAnimator scaleInAnimation = ObjectAnimator.ofPropertyValuesHolder(view, alpha, scaleX, scaleY);
    scaleInAnimation.setDuration(view.getResources().getInteger(R.integer.duration_fab_scale_in));
    scaleInAnimation.setStartDelay(delay);
    scaleInAnimation.setInterpolator(EASE_IN_INTERPOLATOR);
    scaleInAnimation.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            view.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            view.setAlpha(1.0f);
            view.setScaleX(1.0f);
            view.setScaleY(1.0f);
        }
    });
    scaleInAnimation.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 .j a v a2s  .  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();
}