Example usage for android.animation ValueAnimator setCurrentFraction

List of usage examples for android.animation ValueAnimator setCurrentFraction

Introduction

In this page you can find the example usage for android.animation ValueAnimator setCurrentFraction.

Prototype

public void setCurrentFraction(float fraction) 

Source Link

Document

Sets the position of the animation to the specified fraction.

Usage

From source file:com.android.deskclock.AnimatorUtils.java

public static void setAnimatedFraction(ValueAnimator animator, float fraction) {
    if (Utils.isLMR1OrLater()) {
        animator.setCurrentFraction(fraction);
        return;/*  w  ww. j  a  v a2s . c  om*/
    }

    if (sTryAnimateValue) {
        // try to set the animated fraction directly so that it isn't affected by the
        // internal animator scale or time (b/17938711)
        try {
            if (sAnimateValue == null) {
                sAnimateValue = ValueAnimator.class.getDeclaredMethod("animateValue", float.class);
                sAnimateValue.setAccessible(true);
            }

            sAnimateValue.invoke(animator, fraction);
            return;
        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
            // something went wrong, don't try that again
            LogUtils.e("Unable to use animateValue directly", e);
            sTryAnimateValue = false;
        }
    }

    // if that doesn't work then just fall back to setting the current play time
    animator.setCurrentPlayTime(Math.round(fraction * animator.getDuration()));
}

From source file:com.android.clear.reminder.AnimatorUtils.java

public static void setAnimatedFraction(ValueAnimator animator, float fraction) {
    if (Utils.isLMR1OrLater()) {
        animator.setCurrentFraction(fraction);
        return;//  www.  j a  v a2  s.  co  m
    }

    if (sTryAnimateValue) {
        // try to set the animated fraction directly so that it isn't affected by the
        // internal animator scale or time (b/17938711)
        try {
            if (sAnimateValue == null) {
                sAnimateValue = ValueAnimator.class.getDeclaredMethod("animateValue", float.class);
                sAnimateValue.setAccessible(true);
            }

            sAnimateValue.invoke(animator, fraction);
            return;
        } catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
            // something went wrong, don't try that again
            L.e("Unable to use animateValue directly", e);
            sTryAnimateValue = false;
        }
    }

    // if that doesn't work then just fall back to setting the current play time
    animator.setCurrentPlayTime(Math.round(fraction * animator.getDuration()));
}