blob: c0ce795f16f406e272bc8aa6080339d3e43981b7 [file] [log] [blame]
Chet Haase17fb4b02010-06-28 17:55:07 -07001/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package android.animation;
18
George Mountc96c7b22013-08-23 13:31:31 -070019import android.graphics.Path;
20import android.graphics.PointF;
Chet Haase17fb4b02010-06-28 17:55:07 -070021import android.util.Log;
Chet Haaseb39f0512011-05-24 14:36:40 -070022import android.util.Property;
Chet Haase17fb4b02010-06-28 17:55:07 -070023
Chet Haasee2ab7cc2010-12-06 16:10:07 -080024import java.util.ArrayList;
Chet Haase17fb4b02010-06-28 17:55:07 -070025
26/**
Chet Haasea18a86b2010-09-07 13:20:00 -070027 * This subclass of {@link ValueAnimator} provides support for animating properties on target objects.
Chet Haase17fb4b02010-06-28 17:55:07 -070028 * The constructors of this class take parameters to define the target object that will be animated
29 * as well as the name of the property that will be animated. Appropriate set/get functions
30 * are then determined internally and the animation will call these functions as necessary to
31 * animate the property.
Chet Haase6e0ecb42010-11-03 19:41:18 -070032 *
Joe Fernandez3aef8e1d2011-12-20 10:38:34 -080033 * <div class="special reference">
34 * <h3>Developer Guides</h3>
35 * <p>For more information about animating with {@code ObjectAnimator}, read the
36 * <a href="{@docRoot}guide/topics/graphics/prop-animation.html#object-animator">Property
37 * Animation</a> developer guide.</p>
38 * </div>
39 *
Chet Haase6e0ecb42010-11-03 19:41:18 -070040 * @see #setPropertyName(String)
41 *
Chet Haase17fb4b02010-06-28 17:55:07 -070042 */
Chet Haase2794eb32010-10-12 16:29:28 -070043public final class ObjectAnimator extends ValueAnimator {
Chet Haasee2ab7cc2010-12-06 16:10:07 -080044 private static final boolean DBG = false;
Chet Haase17fb4b02010-06-28 17:55:07 -070045
46 // The target object on which the property exists, set in the constructor
Patrick Dubroy51ae5fc2011-01-16 14:23:15 -080047 private Object mTarget;
Chet Haase17fb4b02010-06-28 17:55:07 -070048
49 private String mPropertyName;
50
Chet Haaseb39f0512011-05-24 14:36:40 -070051 private Property mProperty;
52
Chet Haasebe19e032013-03-15 17:08:55 -070053 private boolean mAutoCancel = false;
54
Chet Haase17fb4b02010-06-28 17:55:07 -070055 /**
56 * Sets the name of the property that will be animated. This name is used to derive
57 * a setter function that will be called to set animated values.
58 * For example, a property name of <code>foo</code> will result
59 * in a call to the function <code>setFoo()</code> on the target object. If either
60 * <code>valueFrom</code> or <code>valueTo</code> is null, then a getter function will
61 * also be derived and called.
62 *
Chet Haase6e0ecb42010-11-03 19:41:18 -070063 * <p>For best performance of the mechanism that calls the setter function determined by the
64 * name of the property being animated, use <code>float</code> or <code>int</code> typed values,
65 * and make the setter function for those properties have a <code>void</code> return value. This
66 * will cause the code to take an optimized path for these constrained circumstances. Other
67 * property types and return types will work, but will have more overhead in processing
68 * the requests due to normal reflection mechanisms.</p>
69 *
Chet Haase17fb4b02010-06-28 17:55:07 -070070 * <p>Note that the setter function derived from this property name
71 * must take the same parameter type as the
72 * <code>valueFrom</code> and <code>valueTo</code> properties, otherwise the call to
73 * the setter function will fail.</p>
74 *
Chet Haasea18a86b2010-09-07 13:20:00 -070075 * <p>If this ObjectAnimator has been set up to animate several properties together,
Chet Haased953d082010-08-16 17:44:28 -070076 * using more than one PropertyValuesHolder objects, then setting the propertyName simply
77 * sets the propertyName in the first of those PropertyValuesHolder objects.</p>
78 *
Chet Haaseb39f0512011-05-24 14:36:40 -070079 * @param propertyName The name of the property being animated. Should not be null.
Chet Haase17fb4b02010-06-28 17:55:07 -070080 */
81 public void setPropertyName(String propertyName) {
Chet Haase0e0590b2010-09-26 11:57:28 -070082 // mValues could be null if this is being constructed piecemeal. Just record the
83 // propertyName to be used later when setValues() is called if so.
Chet Haased953d082010-08-16 17:44:28 -070084 if (mValues != null) {
Chet Haase602e4d32010-08-16 08:57:23 -070085 PropertyValuesHolder valuesHolder = mValues[0];
86 String oldName = valuesHolder.getPropertyName();
Chet Haased953d082010-08-16 17:44:28 -070087 valuesHolder.setPropertyName(propertyName);
Chet Haase602e4d32010-08-16 08:57:23 -070088 mValuesMap.remove(oldName);
89 mValuesMap.put(propertyName, valuesHolder);
Chet Haased953d082010-08-16 17:44:28 -070090 }
Chet Haase17fb4b02010-06-28 17:55:07 -070091 mPropertyName = propertyName;
Chet Haase0e0590b2010-09-26 11:57:28 -070092 // New property/values/target should cause re-initialization prior to starting
93 mInitialized = false;
Chet Haase17fb4b02010-06-28 17:55:07 -070094 }
95
96 /**
Chet Haaseb39f0512011-05-24 14:36:40 -070097 * Sets the property that will be animated. Property objects will take precedence over
98 * properties specified by the {@link #setPropertyName(String)} method. Animations should
99 * be set up to use one or the other, not both.
100 *
101 * @param property The property being animated. Should not be null.
102 */
103 public void setProperty(Property property) {
104 // mValues could be null if this is being constructed piecemeal. Just record the
105 // propertyName to be used later when setValues() is called if so.
106 if (mValues != null) {
107 PropertyValuesHolder valuesHolder = mValues[0];
108 String oldName = valuesHolder.getPropertyName();
109 valuesHolder.setProperty(property);
110 mValuesMap.remove(oldName);
111 mValuesMap.put(mPropertyName, valuesHolder);
112 }
113 if (mProperty != null) {
114 mPropertyName = property.getName();
115 }
116 mProperty = property;
117 // New property/values/target should cause re-initialization prior to starting
118 mInitialized = false;
119 }
120
121 /**
Chet Haase17fb4b02010-06-28 17:55:07 -0700122 * Gets the name of the property that will be animated. This name will be used to derive
123 * a setter function that will be called to set animated values.
124 * For example, a property name of <code>foo</code> will result
125 * in a call to the function <code>setFoo()</code> on the target object. If either
126 * <code>valueFrom</code> or <code>valueTo</code> is null, then a getter function will
127 * also be derived and called.
Chet Haasefdd3ad72013-04-24 16:38:20 -0700128 *
129 * <p>If this animator was created with a {@link Property} object instead of the
130 * string name of a property, then this method will return the {@link
131 * Property#getName() name} of that Property object instead. If this animator was
132 * created with one or more {@link PropertyValuesHolder} objects, then this method
133 * will return the {@link PropertyValuesHolder#getPropertyName() name} of that
134 * object (if there was just one) or a comma-separated list of all of the
135 * names (if there are more than one).</p>
Chet Haase17fb4b02010-06-28 17:55:07 -0700136 */
137 public String getPropertyName() {
Chet Haasefdd3ad72013-04-24 16:38:20 -0700138 String propertyName = null;
139 if (mPropertyName != null) {
140 propertyName = mPropertyName;
141 } else if (mProperty != null) {
142 propertyName = mProperty.getName();
143 } else if (mValues != null && mValues.length > 0) {
144 for (int i = 0; i < mValues.length; ++i) {
145 if (i == 0) {
146 propertyName = "";
147 } else {
148 propertyName += ",";
149 }
150 propertyName += mValues[i].getPropertyName();
151 }
152 }
153 return propertyName;
154 }
155
156 @Override
157 String getNameForTrace() {
158 return "animator:" + getPropertyName();
Chet Haase17fb4b02010-06-28 17:55:07 -0700159 }
160
161 /**
Chet Haasea18a86b2010-09-07 13:20:00 -0700162 * Creates a new ObjectAnimator object. This default constructor is primarily for
Chet Haased51d3682010-08-11 19:46:48 -0700163 * use internally; the other constructors which take parameters are more generally
164 * useful.
165 */
Chet Haasea18a86b2010-09-07 13:20:00 -0700166 public ObjectAnimator() {
Chet Haased51d3682010-08-11 19:46:48 -0700167 }
168
169 /**
Chet Haaseb39f0512011-05-24 14:36:40 -0700170 * Private utility constructor that initializes the target object and name of the
171 * property being animated.
Chet Haase17fb4b02010-06-28 17:55:07 -0700172 *
Patrick Dubroy51ae5fc2011-01-16 14:23:15 -0800173 * @param target The object whose property is to be animated. This object should
174 * have a public method on it called <code>setName()</code>, where <code>name</code> is
175 * the value of the <code>propertyName</code> parameter.
Chet Haased953d082010-08-16 17:44:28 -0700176 * @param propertyName The name of the property being animated.
Chet Haase17fb4b02010-06-28 17:55:07 -0700177 */
Chet Haase2794eb32010-10-12 16:29:28 -0700178 private ObjectAnimator(Object target, String propertyName) {
Patrick Dubroy51ae5fc2011-01-16 14:23:15 -0800179 mTarget = target;
Chet Haased953d082010-08-16 17:44:28 -0700180 setPropertyName(propertyName);
Chet Haase17fb4b02010-06-28 17:55:07 -0700181 }
182
183 /**
Chet Haaseb39f0512011-05-24 14:36:40 -0700184 * Private utility constructor that initializes the target object and property being animated.
185 *
186 * @param target The object whose property is to be animated.
187 * @param property The property being animated.
188 */
189 private <T> ObjectAnimator(T target, Property<T, ?> property) {
190 mTarget = target;
191 setProperty(property);
192 }
193
194 /**
Chet Haase2794eb32010-10-12 16:29:28 -0700195 * Constructs and returns an ObjectAnimator that animates between int values. A single
George Mount16d2c9c2013-09-17 09:07:48 -0700196 * value implies that that value is the one being animated to. Two values imply starting
Chet Haaseb39f0512011-05-24 14:36:40 -0700197 * and ending values. More than two values imply a starting value, values to animate through
198 * along the way, and an ending value (these values will be distributed evenly across
199 * the duration of the animation).
Chet Haase2794eb32010-10-12 16:29:28 -0700200 *
Patrick Dubroy51ae5fc2011-01-16 14:23:15 -0800201 * @param target The object whose property is to be animated. This object should
202 * have a public method on it called <code>setName()</code>, where <code>name</code> is
203 * the value of the <code>propertyName</code> parameter.
Chet Haase2794eb32010-10-12 16:29:28 -0700204 * @param propertyName The name of the property being animated.
205 * @param values A set of values that the animation will animate between over time.
Chet Haaseb39f0512011-05-24 14:36:40 -0700206 * @return An ObjectAnimator object that is set up to animate between the given values.
Chet Haase2794eb32010-10-12 16:29:28 -0700207 */
208 public static ObjectAnimator ofInt(Object target, String propertyName, int... values) {
209 ObjectAnimator anim = new ObjectAnimator(target, propertyName);
210 anim.setIntValues(values);
211 return anim;
212 }
213
214 /**
George Mountc96c7b22013-08-23 13:31:31 -0700215 * Constructs and returns an ObjectAnimator that animates coordinates along a <code>Path</code>
216 * using two properties. A <code>Path</code></> animation moves in two dimensions, animating
217 * coordinates <code>(x, y)</code> together to follow the line. In this variation, the
218 * coordinates are integers that are set to separate properties designated by
219 * <code>xPropertyName</code> and <code>yPropertyName</code>.
220 *
221 * @param target The object whose properties are to be animated. This object should
222 * have public methods on it called <code>setNameX()</code> and
223 * <code>setNameY</code>, where <code>nameX</code> and <code>nameY</code>
224 * are the value of <code>xPropertyName</code> and <code>yPropertyName</code>
225 * parameters, respectively.
226 * @param xPropertyName The name of the property for the x coordinate being animated.
227 * @param yPropertyName The name of the property for the y coordinate being animated.
228 * @param path The <code>Path</code> to animate values along.
229 * @return An ObjectAnimator object that is set up to animate along <code>path</code>.
230 */
231 public static ObjectAnimator ofInt(Object target, String xPropertyName, String yPropertyName,
232 Path path) {
233 Keyframe[][] keyframes = PropertyValuesHolder.createKeyframes(path, true);
234 PropertyValuesHolder x = PropertyValuesHolder.ofKeyframe(xPropertyName, keyframes[0]);
235 PropertyValuesHolder y = PropertyValuesHolder.ofKeyframe(yPropertyName, keyframes[1]);
236 return ofPropertyValuesHolder(target, x, y);
237 }
238
239 /**
Chet Haaseb39f0512011-05-24 14:36:40 -0700240 * Constructs and returns an ObjectAnimator that animates between int values. A single
George Mount16d2c9c2013-09-17 09:07:48 -0700241 * value implies that that value is the one being animated to. Two values imply starting
Chet Haaseb39f0512011-05-24 14:36:40 -0700242 * and ending values. More than two values imply a starting value, values to animate through
243 * along the way, and an ending value (these values will be distributed evenly across
244 * the duration of the animation).
245 *
246 * @param target The object whose property is to be animated.
247 * @param property The property being animated.
248 * @param values A set of values that the animation will animate between over time.
249 * @return An ObjectAnimator object that is set up to animate between the given values.
250 */
251 public static <T> ObjectAnimator ofInt(T target, Property<T, Integer> property, int... values) {
252 ObjectAnimator anim = new ObjectAnimator(target, property);
253 anim.setIntValues(values);
254 return anim;
255 }
256
257 /**
George Mountc96c7b22013-08-23 13:31:31 -0700258 * Constructs and returns an ObjectAnimator that animates coordinates along a <code>Path</code>
259 * using two properties. A <code>Path</code></> animation moves in two dimensions, animating
260 * coordinates <code>(x, y)</code> together to follow the line. In this variation, the
261 * coordinates are integers that are set to separate properties, <code>xProperty</code> and
262 * <code>yProperty</code>.
263 *
264 * @param target The object whose properties are to be animated.
265 * @param xProperty The property for the x coordinate being animated.
266 * @param yProperty The property for the y coordinate being animated.
267 * @param path The <code>Path</code> to animate values along.
268 * @return An ObjectAnimator object that is set up to animate along <code>path</code>.
269 */
270 public static <T> ObjectAnimator ofInt(T target, Property<T, Integer> xProperty,
271 Property<T, Integer> yProperty, Path path) {
272 Keyframe[][] keyframes = PropertyValuesHolder.createKeyframes(path, true);
273 PropertyValuesHolder x = PropertyValuesHolder.ofKeyframe(xProperty, keyframes[0]);
274 PropertyValuesHolder y = PropertyValuesHolder.ofKeyframe(yProperty, keyframes[1]);
275 return ofPropertyValuesHolder(target, x, y);
276 }
277
278 /**
George Mount4eed5292013-08-30 13:56:01 -0700279 * Constructs and returns an ObjectAnimator that animates over int values for a multiple
280 * parameters setter. Only public methods that take only int parameters are supported.
281 * Each <code>int[]</code> contains a complete set of parameters to the setter method.
282 * At least two <code>int[]</code> values must be provided, a start and end. More than two
283 * values imply a starting value, values to animate through along the way, and an ending
284 * value (these values will be distributed evenly across the duration of the animation).
285 *
286 * @param target The object whose property is to be animated. This object may
287 * have a public method on it called <code>setName()</code>, where <code>name</code> is
288 * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also
289 * be the case-sensitive complete name of the public setter method.
290 * @param propertyName The name of the property being animated or the name of the setter method.
291 * @param values A set of values that the animation will animate between over time.
292 * @return An ObjectAnimator object that is set up to animate between the given values.
293 */
294 public static ObjectAnimator ofMultiInt(Object target, String propertyName, int[][] values) {
295 PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiInt(propertyName, values);
296 return ofPropertyValuesHolder(target, pvh);
297 }
298
299 /**
George Mountc96c7b22013-08-23 13:31:31 -0700300 * Constructs and returns an ObjectAnimator that animates the target using a multi-int setter
301 * along the given <code>Path</code>. A <code>Path</code></> animation moves in two dimensions,
302 * animating coordinates <code>(x, y)</code> together to follow the line. In this variation, the
303 * coordinates are integer x and y coordinates used in the first and second parameter of the
304 * setter, respectively.
305 *
306 * @param target The object whose property is to be animated. This object may
307 * have a public method on it called <code>setName()</code>, where <code>name</code> is
308 * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also
309 * be the case-sensitive complete name of the public setter method.
310 * @param propertyName The name of the property being animated or the name of the setter method.
311 * @param path The <code>Path</code> to animate values along.
312 * @return An ObjectAnimator object that is set up to animate along <code>path</code>.
313 */
314 public static ObjectAnimator ofMultiInt(Object target, String propertyName, Path path) {
315 PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiInt(propertyName, path);
316 return ofPropertyValuesHolder(target, pvh);
317 }
318
319 /**
George Mount4eed5292013-08-30 13:56:01 -0700320 * Constructs and returns an ObjectAnimator that animates over values for a multiple int
321 * parameters setter. Only public methods that take only int parameters are supported.
322 * <p>At least two values must be provided, a start and end. More than two
323 * values imply a starting value, values to animate through along the way, and an ending
324 * value (these values will be distributed evenly across the duration of the animation).</p>
325 *
326 * @param target The object whose property is to be animated. This object may
327 * have a public method on it called <code>setName()</code>, where <code>name</code> is
328 * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also
George Mountc96c7b22013-08-23 13:31:31 -0700329 * be the case-sensitive complete name of the public setter method.
George Mount4eed5292013-08-30 13:56:01 -0700330 * @param propertyName The name of the property being animated or the name of the setter method.
331 * @param converter Converts T objects into int parameters for the multi-value setter.
332 * @param evaluator A TypeEvaluator that will be called on each animation frame to
333 * provide the necessary interpolation between the Object values to derive the animated
334 * value.
335 * @param values A set of values that the animation will animate between over time.
336 * @return An ObjectAnimator object that is set up to animate between the given values.
337 */
338 public static <T> ObjectAnimator ofMultiInt(Object target, String propertyName,
339 TypeConverter<T, int[]> converter, TypeEvaluator<T> evaluator, T... values) {
340 PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiInt(propertyName, converter,
341 evaluator, values);
342 return ObjectAnimator.ofPropertyValuesHolder(target, pvh);
343 }
344
345 /**
George Mount1ffb2802013-10-09 16:13:54 -0700346 * Constructs and returns an ObjectAnimator that animates between color values. A single
347 * value implies that that value is the one being animated to. Two values imply starting
348 * and ending values. More than two values imply a starting value, values to animate through
349 * along the way, and an ending value (these values will be distributed evenly across
350 * the duration of the animation).
351 *
352 * @param target The object whose property is to be animated. This object should
353 * have a public method on it called <code>setName()</code>, where <code>name</code> is
354 * the value of the <code>propertyName</code> parameter.
355 * @param propertyName The name of the property being animated.
356 * @param values A set of values that the animation will animate between over time.
357 * @return An ObjectAnimator object that is set up to animate between the given values.
358 */
359 public static ObjectAnimator ofArgb(Object target, String propertyName, int... values) {
360 ObjectAnimator animator = ofInt(target, propertyName, values);
361 animator.setEvaluator(ArgbEvaluator.getInstance());
362 return animator;
363 }
364
365 /**
366 * Constructs and returns an ObjectAnimator that animates between color values. A single
367 * value implies that that value is the one being animated to. Two values imply starting
368 * and ending values. More than two values imply a starting value, values to animate through
369 * along the way, and an ending value (these values will be distributed evenly across
370 * the duration of the animation).
371 *
372 * @param target The object whose property is to be animated.
373 * @param property The property being animated.
374 * @param values A set of values that the animation will animate between over time.
375 * @return An ObjectAnimator object that is set up to animate between the given values.
376 */
377 public static <T> ObjectAnimator ofArgb(T target, Property<T, Integer> property,
378 int... values) {
379 ObjectAnimator animator = ofInt(target, property, values);
380 animator.setEvaluator(ArgbEvaluator.getInstance());
381 return animator;
382 }
383
384 /**
Chet Haase2794eb32010-10-12 16:29:28 -0700385 * Constructs and returns an ObjectAnimator that animates between float values. A single
George Mount16d2c9c2013-09-17 09:07:48 -0700386 * value implies that that value is the one being animated to. Two values imply starting
Chet Haaseb39f0512011-05-24 14:36:40 -0700387 * and ending values. More than two values imply a starting value, values to animate through
388 * along the way, and an ending value (these values will be distributed evenly across
389 * the duration of the animation).
Chet Haase2794eb32010-10-12 16:29:28 -0700390 *
Patrick Dubroy51ae5fc2011-01-16 14:23:15 -0800391 * @param target The object whose property is to be animated. This object should
392 * have a public method on it called <code>setName()</code>, where <code>name</code> is
393 * the value of the <code>propertyName</code> parameter.
Chet Haase2794eb32010-10-12 16:29:28 -0700394 * @param propertyName The name of the property being animated.
395 * @param values A set of values that the animation will animate between over time.
Chet Haaseb39f0512011-05-24 14:36:40 -0700396 * @return An ObjectAnimator object that is set up to animate between the given values.
Chet Haase2794eb32010-10-12 16:29:28 -0700397 */
398 public static ObjectAnimator ofFloat(Object target, String propertyName, float... values) {
399 ObjectAnimator anim = new ObjectAnimator(target, propertyName);
400 anim.setFloatValues(values);
401 return anim;
402 }
403
404 /**
George Mountc96c7b22013-08-23 13:31:31 -0700405 * Constructs and returns an ObjectAnimator that animates coordinates along a <code>Path</code>
406 * using two properties. A <code>Path</code></> animation moves in two dimensions, animating
407 * coordinates <code>(x, y)</code> together to follow the line. In this variation, the
408 * coordinates are floats that are set to separate properties designated by
409 * <code>xPropertyName</code> and <code>yPropertyName</code>.
410 *
411 * @param target The object whose properties are to be animated. This object should
412 * have public methods on it called <code>setNameX()</code> and
413 * <code>setNameY</code>, where <code>nameX</code> and <code>nameY</code>
414 * are the value of the <code>xPropertyName</code> and <code>yPropertyName</code>
415 * parameters, respectively.
416 * @param xPropertyName The name of the property for the x coordinate being animated.
417 * @param yPropertyName The name of the property for the y coordinate being animated.
418 * @param path The <code>Path</code> to animate values along.
419 * @return An ObjectAnimator object that is set up to animate along <code>path</code>.
420 */
421 public static ObjectAnimator ofFloat(Object target, String xPropertyName, String yPropertyName,
422 Path path) {
423 Keyframe[][] keyframes = PropertyValuesHolder.createKeyframes(path, false);
424 PropertyValuesHolder x = PropertyValuesHolder.ofKeyframe(xPropertyName, keyframes[0]);
425 PropertyValuesHolder y = PropertyValuesHolder.ofKeyframe(yPropertyName, keyframes[1]);
426 return ofPropertyValuesHolder(target, x, y);
427 }
428
429 /**
Chet Haaseb39f0512011-05-24 14:36:40 -0700430 * Constructs and returns an ObjectAnimator that animates between float values. A single
George Mount16d2c9c2013-09-17 09:07:48 -0700431 * value implies that that value is the one being animated to. Two values imply starting
Chet Haaseb39f0512011-05-24 14:36:40 -0700432 * and ending values. More than two values imply a starting value, values to animate through
433 * along the way, and an ending value (these values will be distributed evenly across
434 * the duration of the animation).
435 *
436 * @param target The object whose property is to be animated.
437 * @param property The property being animated.
438 * @param values A set of values that the animation will animate between over time.
439 * @return An ObjectAnimator object that is set up to animate between the given values.
440 */
441 public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> property,
442 float... values) {
443 ObjectAnimator anim = new ObjectAnimator(target, property);
444 anim.setFloatValues(values);
445 return anim;
446 }
447
448 /**
George Mountc96c7b22013-08-23 13:31:31 -0700449 * Constructs and returns an ObjectAnimator that animates coordinates along a <code>Path</code>
450 * using two properties. A <code>Path</code></> animation moves in two dimensions, animating
451 * coordinates <code>(x, y)</code> together to follow the line. In this variation, the
452 * coordinates are floats that are set to separate properties, <code>xProperty</code> and
453 * <code>yProperty</code>.
454 *
455 * @param target The object whose properties are to be animated.
456 * @param xProperty The property for the x coordinate being animated.
457 * @param yProperty The property for the y coordinate being animated.
458 * @param path The <code>Path</code> to animate values along.
459 * @return An ObjectAnimator object that is set up to animate along <code>path</code>.
460 */
461 public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> xProperty,
462 Property<T, Float> yProperty, Path path) {
463 return ofFloat(target, xProperty.getName(), yProperty.getName(), path);
464 }
465
466 /**
George Mount4eed5292013-08-30 13:56:01 -0700467 * Constructs and returns an ObjectAnimator that animates over float values for a multiple
468 * parameters setter. Only public methods that take only float parameters are supported.
469 * Each <code>float[]</code> contains a complete set of parameters to the setter method.
470 * At least two <code>float[]</code> values must be provided, a start and end. More than two
471 * values imply a starting value, values to animate through along the way, and an ending
472 * value (these values will be distributed evenly across the duration of the animation).
473 *
474 * @param target The object whose property is to be animated. This object may
475 * have a public method on it called <code>setName()</code>, where <code>name</code> is
476 * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also
George Mountc96c7b22013-08-23 13:31:31 -0700477 * be the case-sensitive complete name of the public setter method.
George Mount4eed5292013-08-30 13:56:01 -0700478 * @param propertyName The name of the property being animated or the name of the setter method.
479 * @param values A set of values that the animation will animate between over time.
480 * @return An ObjectAnimator object that is set up to animate between the given values.
481 */
482 public static ObjectAnimator ofMultiFloat(Object target, String propertyName,
483 float[][] values) {
484 PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiFloat(propertyName, values);
485 return ofPropertyValuesHolder(target, pvh);
486 }
487
488 /**
George Mountc96c7b22013-08-23 13:31:31 -0700489 * Constructs and returns an ObjectAnimator that animates the target using a multi-float setter
490 * along the given <code>Path</code>. A <code>Path</code></> animation moves in two dimensions,
491 * animating coordinates <code>(x, y)</code> together to follow the line. In this variation, the
492 * coordinates are float x and y coordinates used in the first and second parameter of the
493 * setter, respectively.
494 *
495 * @param target The object whose property is to be animated. This object may
496 * have a public method on it called <code>setName()</code>, where <code>name</code> is
497 * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also
498 * be the case-sensitive complete name of the public setter method.
499 * @param propertyName The name of the property being animated or the name of the setter method.
500 * @param path The <code>Path</code> to animate values along.
501 * @return An ObjectAnimator object that is set up to animate along <code>path</code>.
502 */
503 public static ObjectAnimator ofMultiFloat(Object target, String propertyName, Path path) {
504 PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiFloat(propertyName, path);
505 return ofPropertyValuesHolder(target, pvh);
506 }
507
508 /**
George Mount4eed5292013-08-30 13:56:01 -0700509 * Constructs and returns an ObjectAnimator that animates over values for a multiple float
510 * parameters setter. Only public methods that take only float parameters are supported.
511 * <p>At least two values must be provided, a start and end. More than two
512 * values imply a starting value, values to animate through along the way, and an ending
513 * value (these values will be distributed evenly across the duration of the animation).</p>
514 *
515 * @param target The object whose property is to be animated. This object may
516 * have a public method on it called <code>setName()</code>, where <code>name</code> is
517 * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also
518 * be the case-sensitive complete name of the public setter method.
519 * @param propertyName The name of the property being animated or the name of the setter method.
520 * @param converter Converts T objects into float parameters for the multi-value setter.
521 * @param evaluator A TypeEvaluator that will be called on each animation frame to
522 * provide the necessary interpolation between the Object values to derive the animated
523 * value.
524 * @param values A set of values that the animation will animate between over time.
525 * @return An ObjectAnimator object that is set up to animate between the given values.
526 */
527 public static <T> ObjectAnimator ofMultiFloat(Object target, String propertyName,
528 TypeConverter<T, float[]> converter, TypeEvaluator<T> evaluator, T... values) {
529 PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiFloat(propertyName, converter,
530 evaluator, values);
531 return ObjectAnimator.ofPropertyValuesHolder(target, pvh);
532 }
533
534 /**
Chet Haaseb39f0512011-05-24 14:36:40 -0700535 * Constructs and returns an ObjectAnimator that animates between Object values. A single
George Mount16d2c9c2013-09-17 09:07:48 -0700536 * value implies that that value is the one being animated to. Two values imply starting
Chet Haaseb39f0512011-05-24 14:36:40 -0700537 * and ending values. More than two values imply a starting value, values to animate through
538 * along the way, and an ending value (these values will be distributed evenly across
539 * the duration of the animation).
Chet Haasefe591562010-07-27 11:15:37 -0700540 *
Patrick Dubroy51ae5fc2011-01-16 14:23:15 -0800541 * @param target The object whose property is to be animated. This object should
Chet Haaseb39f0512011-05-24 14:36:40 -0700542 * have a public method on it called <code>setName()</code>, where <code>name</code> is
543 * the value of the <code>propertyName</code> parameter.
Chet Haase2794eb32010-10-12 16:29:28 -0700544 * @param propertyName The name of the property being animated.
545 * @param evaluator A TypeEvaluator that will be called on each animation frame to
Chet Haaseb39f0512011-05-24 14:36:40 -0700546 * provide the necessary interpolation between the Object values to derive the animated
Chet Haase2794eb32010-10-12 16:29:28 -0700547 * value.
Chet Haaseb39f0512011-05-24 14:36:40 -0700548 * @param values A set of values that the animation will animate between over time.
549 * @return An ObjectAnimator object that is set up to animate between the given values.
Chet Haasefe591562010-07-27 11:15:37 -0700550 */
Chet Haase2794eb32010-10-12 16:29:28 -0700551 public static ObjectAnimator ofObject(Object target, String propertyName,
552 TypeEvaluator evaluator, Object... values) {
553 ObjectAnimator anim = new ObjectAnimator(target, propertyName);
554 anim.setObjectValues(values);
555 anim.setEvaluator(evaluator);
556 return anim;
557 }
558
559 /**
George Mountc96c7b22013-08-23 13:31:31 -0700560 * Constructs and returns an ObjectAnimator that animates a property along a <code>Path</code>.
561 * A <code>Path</code></> animation moves in two dimensions, animating coordinates
562 * <code>(x, y)</code> together to follow the line. This variant animates the coordinates
563 * in a <code>PointF</code> to follow the <code>Path</code>. If the <code>Property</code>
564 * associated with <code>propertyName</code> uses a type other than <code>PointF</code>,
565 * <code>converter</code> can be used to change from <code>PointF</code> to the type
566 * associated with the <code>Property</code>.
567 *
568 * @param target The object whose property is to be animated. This object should
569 * have a public method on it called <code>setName()</code>, where <code>name</code> is
570 * the value of the <code>propertyName</code> parameter.
571 * @param propertyName The name of the property being animated.
572 * @param converter Converts a PointF to the type associated with the setter. May be
573 * null if conversion is unnecessary.
574 * @param path The <code>Path</code> to animate values along.
575 * @return An ObjectAnimator object that is set up to animate along <code>path</code>.
576 */
577 public static ObjectAnimator ofObject(Object target, String propertyName,
578 TypeConverter<PointF, ?> converter, Path path) {
579 PropertyValuesHolder pvh = PropertyValuesHolder.ofObject(propertyName, converter, path);
580 return ofPropertyValuesHolder(target, pvh);
581 }
582
583 /**
Chet Haaseb39f0512011-05-24 14:36:40 -0700584 * Constructs and returns an ObjectAnimator that animates between Object values. A single
George Mount16d2c9c2013-09-17 09:07:48 -0700585 * value implies that that value is the one being animated to. Two values imply starting
Chet Haaseb39f0512011-05-24 14:36:40 -0700586 * and ending values. More than two values imply a starting value, values to animate through
587 * along the way, and an ending value (these values will be distributed evenly across
588 * the duration of the animation).
Chet Haase2794eb32010-10-12 16:29:28 -0700589 *
Chet Haaseb39f0512011-05-24 14:36:40 -0700590 * @param target The object whose property is to be animated.
591 * @param property The property being animated.
592 * @param evaluator A TypeEvaluator that will be called on each animation frame to
593 * provide the necessary interpolation between the Object values to derive the animated
594 * value.
595 * @param values A set of values that the animation will animate between over time.
596 * @return An ObjectAnimator object that is set up to animate between the given values.
597 */
598 public static <T, V> ObjectAnimator ofObject(T target, Property<T, V> property,
599 TypeEvaluator<V> evaluator, V... values) {
600 ObjectAnimator anim = new ObjectAnimator(target, property);
601 anim.setObjectValues(values);
602 anim.setEvaluator(evaluator);
603 return anim;
604 }
605
606 /**
George Mount16d2c9c2013-09-17 09:07:48 -0700607 * Constructs and returns an ObjectAnimator that animates between Object values. A single
608 * value implies that that value is the one being animated to. Two values imply starting
609 * and ending values. More than two values imply a starting value, values to animate through
610 * along the way, and an ending value (these values will be distributed evenly across
611 * the duration of the animation). This variant supplies a <code>TypeConverter</code> to
612 * convert from the animated values to the type of the property. If only one value is
613 * supplied, the <code>TypeConverter</code> must implement
614 * {@link TypeConverter#convertBack(Object)} to retrieve the current value.
615 *
616 * @param target The object whose property is to be animated.
617 * @param property The property being animated.
618 * @param converter Converts the animated object to the Property type.
619 * @param evaluator A TypeEvaluator that will be called on each animation frame to
620 * provide the necessary interpolation between the Object values to derive the animated
621 * value.
622 * @param values A set of values that the animation will animate between over time.
623 * @return An ObjectAnimator object that is set up to animate between the given values.
624 */
625 public static <T, V, P> ObjectAnimator ofObject(T target, Property<T, P> property,
626 TypeConverter<V, P> converter, TypeEvaluator<V> evaluator, V... values) {
627 PropertyValuesHolder pvh = PropertyValuesHolder.ofObject(property, converter, evaluator,
628 values);
629 return ofPropertyValuesHolder(target, pvh);
630 }
631
632 /**
George Mountc96c7b22013-08-23 13:31:31 -0700633 * Constructs and returns an ObjectAnimator that animates a property along a <code>Path</code>.
634 * A <code>Path</code></> animation moves in two dimensions, animating coordinates
635 * <code>(x, y)</code> together to follow the line. This variant animates the coordinates
636 * in a <code>PointF</code> to follow the <code>Path</code>. If <code>property</code>
637 * uses a type other than <code>PointF</code>, <code>converter</code> can be used to change
638 * from <code>PointF</code> to the type associated with the <code>Property</code>.
639 *
640 * @param target The object whose property is to be animated.
641 * @param property The property being animated. Should not be null.
642 * @param converter Converts a PointF to the type associated with the setter. May be
643 * null if conversion is unnecessary.
644 * @param path The <code>Path</code> to animate values along.
645 * @return An ObjectAnimator object that is set up to animate along <code>path</code>.
646 */
647 public static <T, V> ObjectAnimator ofObject(T target, Property<T, V> property,
648 TypeConverter<PointF, V> converter, Path path) {
649 PropertyValuesHolder pvh = PropertyValuesHolder.ofObject(property, converter, path);
650 return ofPropertyValuesHolder(target, pvh);
651 }
652
653 /**
Chet Haaseb39f0512011-05-24 14:36:40 -0700654 * Constructs and returns an ObjectAnimator that animates between the sets of values specified
655 * in <code>PropertyValueHolder</code> objects. This variant should be used when animating
656 * several properties at once with the same ObjectAnimator, since PropertyValuesHolder allows
657 * you to associate a set of animation values with a property name.
658 *
659 * @param target The object whose property is to be animated. Depending on how the
660 * PropertyValuesObjects were constructed, the target object should either have the {@link
661 * android.util.Property} objects used to construct the PropertyValuesHolder objects or (if the
662 * PropertyValuesHOlder objects were created with property names) the target object should have
663 * public methods on it called <code>setName()</code>, where <code>name</code> is the name of
664 * the property passed in as the <code>propertyName</code> parameter for each of the
665 * PropertyValuesHolder objects.
666 * @param values A set of PropertyValuesHolder objects whose values will be animated between
667 * over time.
668 * @return An ObjectAnimator object that is set up to animate between the given values.
Chet Haase2794eb32010-10-12 16:29:28 -0700669 */
670 public static ObjectAnimator ofPropertyValuesHolder(Object target,
671 PropertyValuesHolder... values) {
672 ObjectAnimator anim = new ObjectAnimator();
Patrick Dubroy51ae5fc2011-01-16 14:23:15 -0800673 anim.mTarget = target;
Chet Haase2794eb32010-10-12 16:29:28 -0700674 anim.setValues(values);
675 return anim;
Chet Haase3dd207a2010-07-20 14:00:01 -0700676 }
677
Romain Guy83d6e822010-10-14 10:13:53 -0700678 @Override
Chet Haase2794eb32010-10-12 16:29:28 -0700679 public void setIntValues(int... values) {
Romain Guy83d6e822010-10-14 10:13:53 -0700680 if (mValues == null || mValues.length == 0) {
681 // No values yet - this animator is being constructed piecemeal. Init the values with
682 // whatever the current propertyName is
Chet Haaseb39f0512011-05-24 14:36:40 -0700683 if (mProperty != null) {
684 setValues(PropertyValuesHolder.ofInt(mProperty, values));
685 } else {
686 setValues(PropertyValuesHolder.ofInt(mPropertyName, values));
687 }
Romain Guy83d6e822010-10-14 10:13:53 -0700688 } else {
Chet Haase2794eb32010-10-12 16:29:28 -0700689 super.setIntValues(values);
690 }
691 }
692
693 @Override
694 public void setFloatValues(float... values) {
695 if (mValues == null || mValues.length == 0) {
696 // No values yet - this animator is being constructed piecemeal. Init the values with
697 // whatever the current propertyName is
Chet Haaseb39f0512011-05-24 14:36:40 -0700698 if (mProperty != null) {
699 setValues(PropertyValuesHolder.ofFloat(mProperty, values));
700 } else {
701 setValues(PropertyValuesHolder.ofFloat(mPropertyName, values));
702 }
Chet Haase2794eb32010-10-12 16:29:28 -0700703 } else {
704 super.setFloatValues(values);
705 }
706 }
707
708 @Override
Chet Haase2794eb32010-10-12 16:29:28 -0700709 public void setObjectValues(Object... values) {
710 if (mValues == null || mValues.length == 0) {
711 // No values yet - this animator is being constructed piecemeal. Init the values with
712 // whatever the current propertyName is
Chet Haaseb39f0512011-05-24 14:36:40 -0700713 if (mProperty != null) {
Chet Haasebe19e032013-03-15 17:08:55 -0700714 setValues(PropertyValuesHolder.ofObject(mProperty, (TypeEvaluator) null, values));
Chet Haaseb39f0512011-05-24 14:36:40 -0700715 } else {
Chet Haasebe19e032013-03-15 17:08:55 -0700716 setValues(PropertyValuesHolder.ofObject(mPropertyName,
717 (TypeEvaluator) null, values));
Chet Haaseb39f0512011-05-24 14:36:40 -0700718 }
Chet Haase2794eb32010-10-12 16:29:28 -0700719 } else {
720 super.setObjectValues(values);
Romain Guy83d6e822010-10-14 10:13:53 -0700721 }
Chet Haase0e0590b2010-09-26 11:57:28 -0700722 }
Romain Guy83d6e822010-10-14 10:13:53 -0700723
Chet Haasebe19e032013-03-15 17:08:55 -0700724 /**
725 * autoCancel controls whether an ObjectAnimator will be canceled automatically
726 * when any other ObjectAnimator with the same target and properties is started.
727 * Setting this flag may make it easier to run different animators on the same target
728 * object without having to keep track of whether there are conflicting animators that
729 * need to be manually canceled. Canceling animators must have the same exact set of
730 * target properties, in the same order.
731 *
732 * @param cancel Whether future ObjectAnimators with the same target and properties
733 * as this ObjectAnimator will cause this ObjectAnimator to be canceled.
734 */
735 public void setAutoCancel(boolean cancel) {
736 mAutoCancel = cancel;
737 }
738
739 private boolean hasSameTargetAndProperties(Animator anim) {
740 if (anim instanceof ObjectAnimator) {
741 PropertyValuesHolder[] theirValues = ((ObjectAnimator) anim).getValues();
742 if (((ObjectAnimator) anim).getTarget() == mTarget &&
743 mValues.length == theirValues.length) {
744 for (int i = 0; i < mValues.length; ++i) {
745 PropertyValuesHolder pvhMine = mValues[i];
746 PropertyValuesHolder pvhTheirs = theirValues[i];
747 if (pvhMine.getPropertyName() == null ||
748 !pvhMine.getPropertyName().equals(pvhTheirs.getPropertyName())) {
749 return false;
750 }
751 }
752 return true;
753 }
754 }
755 return false;
756 }
757
Chet Haasee2ab7cc2010-12-06 16:10:07 -0800758 @Override
759 public void start() {
Chet Haasebe19e032013-03-15 17:08:55 -0700760 // See if any of the current active/pending animators need to be canceled
761 AnimationHandler handler = sAnimationHandler.get();
762 if (handler != null) {
763 int numAnims = handler.mAnimations.size();
764 for (int i = numAnims - 1; i >= 0; i--) {
765 if (handler.mAnimations.get(i) instanceof ObjectAnimator) {
766 ObjectAnimator anim = (ObjectAnimator) handler.mAnimations.get(i);
767 if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) {
768 anim.cancel();
769 }
770 }
771 }
772 numAnims = handler.mPendingAnimations.size();
773 for (int i = numAnims - 1; i >= 0; i--) {
774 if (handler.mPendingAnimations.get(i) instanceof ObjectAnimator) {
775 ObjectAnimator anim = (ObjectAnimator) handler.mPendingAnimations.get(i);
776 if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) {
777 anim.cancel();
778 }
779 }
780 }
781 numAnims = handler.mDelayedAnims.size();
782 for (int i = numAnims - 1; i >= 0; i--) {
783 if (handler.mDelayedAnims.get(i) instanceof ObjectAnimator) {
784 ObjectAnimator anim = (ObjectAnimator) handler.mDelayedAnims.get(i);
785 if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) {
786 anim.cancel();
787 }
788 }
789 }
790 }
Chet Haasee2ab7cc2010-12-06 16:10:07 -0800791 if (DBG) {
Chet Haase3c4ce722011-09-02 15:37:25 -0700792 Log.d("ObjectAnimator", "Anim target, duration: " + mTarget + ", " + getDuration());
Chet Haasee2ab7cc2010-12-06 16:10:07 -0800793 for (int i = 0; i < mValues.length; ++i) {
794 PropertyValuesHolder pvh = mValues[i];
795 ArrayList<Keyframe> keyframes = pvh.mKeyframeSet.mKeyframes;
796 Log.d("ObjectAnimator", " Values[" + i + "]: " +
797 pvh.getPropertyName() + ", " + keyframes.get(0).getValue() + ", " +
798 keyframes.get(pvh.mKeyframeSet.mNumKeyframes - 1).getValue());
799 }
800 }
801 super.start();
802 }
803
Chet Haase3dd207a2010-07-20 14:00:01 -0700804 /**
Chet Haase17fb4b02010-06-28 17:55:07 -0700805 * This function is called immediately before processing the first animation
806 * frame of an animation. If there is a nonzero <code>startDelay</code>, the
807 * function is called after that delay ends.
808 * It takes care of the final initialization steps for the
809 * animation. This includes setting mEvaluator, if the user has not yet
810 * set it up, and the setter/getter methods, if the user did not supply
811 * them.
812 *
813 * <p>Overriders of this method should call the superclass method to cause
814 * internal mechanisms to be set up correctly.</p>
815 */
816 @Override
817 void initAnimation() {
Chet Haase21cd1382010-09-01 17:42:29 -0700818 if (!mInitialized) {
819 // mValueType may change due to setter/getter setup; do this before calling super.init(),
820 // which uses mValueType to set up the default type evaluator.
821 int numValues = mValues.length;
822 for (int i = 0; i < numValues; ++i) {
Patrick Dubroy51ae5fc2011-01-16 14:23:15 -0800823 mValues[i].setupSetterAndGetter(mTarget);
Chet Haase21cd1382010-09-01 17:42:29 -0700824 }
825 super.initAnimation();
Chet Haase17fb4b02010-06-28 17:55:07 -0700826 }
827 }
828
Chet Haase2794eb32010-10-12 16:29:28 -0700829 /**
830 * Sets the length of the animation. The default duration is 300 milliseconds.
831 *
832 * @param duration The length of the animation, in milliseconds.
833 * @return ObjectAnimator The object called with setDuration(). This return
834 * value makes it easier to compose statements together that construct and then set the
835 * duration, as in
836 * <code>ObjectAnimator.ofInt(target, propertyName, 0, 10).setDuration(500).start()</code>.
837 */
838 @Override
839 public ObjectAnimator setDuration(long duration) {
840 super.setDuration(duration);
841 return this;
842 }
843
Chet Haase17fb4b02010-06-28 17:55:07 -0700844
845 /**
846 * The target object whose property will be animated by this animation
847 *
Patrick Dubroy51ae5fc2011-01-16 14:23:15 -0800848 * @return The object being animated
Chet Haase17fb4b02010-06-28 17:55:07 -0700849 */
850 public Object getTarget() {
Patrick Dubroy51ae5fc2011-01-16 14:23:15 -0800851 return mTarget;
Chet Haase17fb4b02010-06-28 17:55:07 -0700852 }
853
854 /**
Patrick Dubroy51ae5fc2011-01-16 14:23:15 -0800855 * Sets the target object whose property will be animated by this animation
Chet Haasef54a8d72010-07-22 14:44:59 -0700856 *
857 * @param target The object being animated
858 */
Chet Haase21cd1382010-09-01 17:42:29 -0700859 @Override
Chet Haasef54a8d72010-07-22 14:44:59 -0700860 public void setTarget(Object target) {
Patrick Dubroy51ae5fc2011-01-16 14:23:15 -0800861 if (mTarget != target) {
Patrick Dubroy7beecfa2011-01-16 14:42:39 -0800862 final Object oldTarget = mTarget;
Patrick Dubroy51ae5fc2011-01-16 14:23:15 -0800863 mTarget = target;
Patrick Dubroy7beecfa2011-01-16 14:42:39 -0800864 if (oldTarget != null && target != null && oldTarget.getClass() == target.getClass()) {
Chet Haase70d4ba12010-10-06 09:46:45 -0700865 return;
866 }
867 // New target type should cause re-initialization prior to starting
868 mInitialized = false;
869 }
Chet Haasef54a8d72010-07-22 14:44:59 -0700870 }
871
Chet Haase21cd1382010-09-01 17:42:29 -0700872 @Override
873 public void setupStartValues() {
874 initAnimation();
875 int numValues = mValues.length;
876 for (int i = 0; i < numValues; ++i) {
Patrick Dubroy51ae5fc2011-01-16 14:23:15 -0800877 mValues[i].setupStartValue(mTarget);
Chet Haase21cd1382010-09-01 17:42:29 -0700878 }
879 }
880
881 @Override
882 public void setupEndValues() {
883 initAnimation();
884 int numValues = mValues.length;
885 for (int i = 0; i < numValues; ++i) {
Patrick Dubroy51ae5fc2011-01-16 14:23:15 -0800886 mValues[i].setupEndValue(mTarget);
Chet Haase21cd1382010-09-01 17:42:29 -0700887 }
888 }
889
Chet Haasef54a8d72010-07-22 14:44:59 -0700890 /**
Chet Haase17fb4b02010-06-28 17:55:07 -0700891 * This method is called with the elapsed fraction of the animation during every
892 * animation frame. This function turns the elapsed fraction into an interpolated fraction
893 * and then into an animated value (from the evaluator. The function is called mostly during
894 * animation updates, but it is also called when the <code>end()</code>
895 * function is called, to set the final value on the property.
896 *
897 * <p>Overrides of this method must call the superclass to perform the calculation
898 * of the animated value.</p>
899 *
900 * @param fraction The elapsed fraction of the animation.
901 */
902 @Override
903 void animateValue(float fraction) {
904 super.animateValue(fraction);
Chet Haase602e4d32010-08-16 08:57:23 -0700905 int numValues = mValues.length;
906 for (int i = 0; i < numValues; ++i) {
Patrick Dubroy51ae5fc2011-01-16 14:23:15 -0800907 mValues[i].setAnimatedValue(mTarget);
Chet Haase17fb4b02010-06-28 17:55:07 -0700908 }
909 }
Chet Haase49afa5b2010-08-23 11:39:53 -0700910
911 @Override
Chet Haasea18a86b2010-09-07 13:20:00 -0700912 public ObjectAnimator clone() {
913 final ObjectAnimator anim = (ObjectAnimator) super.clone();
Chet Haase49afa5b2010-08-23 11:39:53 -0700914 return anim;
915 }
Chet Haasee9140a72011-02-16 16:23:29 -0800916
917 @Override
918 public String toString() {
919 String returnVal = "ObjectAnimator@" + Integer.toHexString(hashCode()) + ", target " +
920 mTarget;
921 if (mValues != null) {
922 for (int i = 0; i < mValues.length; ++i) {
923 returnVal += "\n " + mValues[i].toString();
924 }
925 }
926 return returnVal;
927 }
Chet Haase17fb4b02010-06-28 17:55:07 -0700928}