Example usage for android.animation ValueAnimator setCurrentPlayTime

List of usage examples for android.animation ValueAnimator setCurrentPlayTime

Introduction

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

Prototype

public void setCurrentPlayTime(long playTime) 

Source Link

Document

Sets the position of the animation to the specified point in time.

Usage

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

public static void setAnimatedFraction(ValueAnimator animator, float fraction) {
    if (Utils.isLMR1OrLater()) {
        animator.setCurrentFraction(fraction);
        return;//from  w  w w.  j  av  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;//from ww  w .  j  av  a2s .c o  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()));
}