From d40acfb89e3222e8da516254341a9489de7fd07b Mon Sep 17 00:00:00 2001 From: Cyril Mottier Date: Thu, 25 Jul 2013 10:08:29 +0200 Subject: Return the actual interpolator of the ViewPropertyAnimator The implementation of getInterpolator() was always returning null (probably a quick copy-paste from the default Animator implementation). This patch fixes the problem by returning the interpolator set by setInterpolator(TimeInterpolator) or the default one if none has been set yet. This patch also avoid creating multiple instances of ValueAnimator in order to retrieve some default values. Change-Id: I8880f419f021a8b980fb32bebe927915fde19bf7 --- core/java/android/view/ViewPropertyAnimator.java | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/core/java/android/view/ViewPropertyAnimator.java b/core/java/android/view/ViewPropertyAnimator.java index 71a85bc7a2f5..e6bf420acccc 100644 --- a/core/java/android/view/ViewPropertyAnimator.java +++ b/core/java/android/view/ViewPropertyAnimator.java @@ -97,6 +97,12 @@ public class ViewPropertyAnimator { */ private Animator.AnimatorListener mListener = null; + /** + * A lazily-created ValueAnimator used in order to get some default animator properties + * (duration, start delay, interpolator, etc.). + */ + private ValueAnimator mTempValueAnimator; + /** * This listener is the mechanism by which the underlying Animator causes changes to the * properties currently being animated, as well as the cleanup after an animation is @@ -268,7 +274,10 @@ public class ViewPropertyAnimator { } else { // Just return the default from ValueAnimator, since that's what we'd get if // the value has not been set otherwise - return new ValueAnimator().getDuration(); + if (mTempValueAnimator == null) { + mTempValueAnimator = new ValueAnimator(); + } + return mTempValueAnimator.getDuration(); } } @@ -328,7 +337,16 @@ public class ViewPropertyAnimator { * @return The timing interpolator for this animation. */ public TimeInterpolator getInterpolator() { - return null; + if (mInterpolatorSet) { + return mInterpolator; + } else { + // Just return the default from ValueAnimator, since that's what we'd get if + // the value has not been set otherwise + if (mTempValueAnimator == null) { + mTempValueAnimator = new ValueAnimator(); + } + return mTempValueAnimator.getInterpolator(); + } } /** -- cgit v1.2.3-59-g8ed1b