ObjectAnimator.java revision 3aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45
117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase/* 217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * Copyright (C) 2010 The Android Open Source Project 317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * Licensed under the Apache License, Version 2.0 (the "License"); 517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * you may not use this file except in compliance with the License. 617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * You may obtain a copy of the License at 717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * http://www.apache.org/licenses/LICENSE-2.0 917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 1017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * Unless required by applicable law or agreed to in writing, software 1117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * distributed under the License is distributed on an "AS IS" BASIS, 1217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * See the License for the specific language governing permissions and 1417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * limitations under the License. 1517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 1617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 1717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haasepackage android.animation; 1817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 1917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haaseimport android.util.Log; 20b39f051631250c49936a475d0e64584afb7f1b93Chet Haaseimport android.util.Property; 2117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 2217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haaseimport java.lang.reflect.Method; 23e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haaseimport java.util.ArrayList; 2417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 2517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase/** 26a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * This subclass of {@link ValueAnimator} provides support for animating properties on target objects. 2717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * The constructors of this class take parameters to define the target object that will be animated 2817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * as well as the name of the property that will be animated. Appropriate set/get functions 2917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * are then determined internally and the animation will call these functions as necessary to 3017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * animate the property. 316e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * 323aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <div class="special reference"> 333aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <h3>Developer Guides</h3> 343aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <p>For more information about animating with {@code ObjectAnimator}, read the 353aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <a href="{@docRoot}guide/topics/graphics/prop-animation.html#object-animator">Property 363aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * Animation</a> developer guide.</p> 373aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * </div> 383aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * 396e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * @see #setPropertyName(String) 406e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * 4117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 422794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haasepublic final class ObjectAnimator extends ValueAnimator { 43e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase private static final boolean DBG = false; 4417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 4517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase // The target object on which the property exists, set in the constructor 4651ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy private Object mTarget; 4717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 4817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase private String mPropertyName; 4917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 50b39f051631250c49936a475d0e64584afb7f1b93Chet Haase private Property mProperty; 51b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 5217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 5317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * Sets the name of the property that will be animated. This name is used to derive 5417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * a setter function that will be called to set animated values. 5517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * For example, a property name of <code>foo</code> will result 5617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * in a call to the function <code>setFoo()</code> on the target object. If either 5717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <code>valueFrom</code> or <code>valueTo</code> is null, then a getter function will 5817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * also be derived and called. 5917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 606e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * <p>For best performance of the mechanism that calls the setter function determined by the 616e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * name of the property being animated, use <code>float</code> or <code>int</code> typed values, 626e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * and make the setter function for those properties have a <code>void</code> return value. This 636e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * will cause the code to take an optimized path for these constrained circumstances. Other 646e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * property types and return types will work, but will have more overhead in processing 656e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * the requests due to normal reflection mechanisms.</p> 666e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * 6717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <p>Note that the setter function derived from this property name 6817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * must take the same parameter type as the 6917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <code>valueFrom</code> and <code>valueTo</code> properties, otherwise the call to 7017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * the setter function will fail.</p> 7117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 72a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * <p>If this ObjectAnimator has been set up to animate several properties together, 73d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase * using more than one PropertyValuesHolder objects, then setting the propertyName simply 74d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase * sets the propertyName in the first of those PropertyValuesHolder objects.</p> 75d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase * 76b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param propertyName The name of the property being animated. Should not be null. 7717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 7817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase public void setPropertyName(String propertyName) { 790e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase // mValues could be null if this is being constructed piecemeal. Just record the 800e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase // propertyName to be used later when setValues() is called if so. 81d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase if (mValues != null) { 82602e4d3824bf8b9cb9f817375d195b969712176aChet Haase PropertyValuesHolder valuesHolder = mValues[0]; 83602e4d3824bf8b9cb9f817375d195b969712176aChet Haase String oldName = valuesHolder.getPropertyName(); 84d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase valuesHolder.setPropertyName(propertyName); 85602e4d3824bf8b9cb9f817375d195b969712176aChet Haase mValuesMap.remove(oldName); 86602e4d3824bf8b9cb9f817375d195b969712176aChet Haase mValuesMap.put(propertyName, valuesHolder); 87d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase } 8817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase mPropertyName = propertyName; 890e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase // New property/values/target should cause re-initialization prior to starting 900e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase mInitialized = false; 9117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 9217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 9317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 94b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Sets the property that will be animated. Property objects will take precedence over 95b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * properties specified by the {@link #setPropertyName(String)} method. Animations should 96b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * be set up to use one or the other, not both. 97b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * 98b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param property The property being animated. Should not be null. 99b39f051631250c49936a475d0e64584afb7f1b93Chet Haase */ 100b39f051631250c49936a475d0e64584afb7f1b93Chet Haase public void setProperty(Property property) { 101b39f051631250c49936a475d0e64584afb7f1b93Chet Haase // mValues could be null if this is being constructed piecemeal. Just record the 102b39f051631250c49936a475d0e64584afb7f1b93Chet Haase // propertyName to be used later when setValues() is called if so. 103b39f051631250c49936a475d0e64584afb7f1b93Chet Haase if (mValues != null) { 104b39f051631250c49936a475d0e64584afb7f1b93Chet Haase PropertyValuesHolder valuesHolder = mValues[0]; 105b39f051631250c49936a475d0e64584afb7f1b93Chet Haase String oldName = valuesHolder.getPropertyName(); 106b39f051631250c49936a475d0e64584afb7f1b93Chet Haase valuesHolder.setProperty(property); 107b39f051631250c49936a475d0e64584afb7f1b93Chet Haase mValuesMap.remove(oldName); 108b39f051631250c49936a475d0e64584afb7f1b93Chet Haase mValuesMap.put(mPropertyName, valuesHolder); 109b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 110b39f051631250c49936a475d0e64584afb7f1b93Chet Haase if (mProperty != null) { 111b39f051631250c49936a475d0e64584afb7f1b93Chet Haase mPropertyName = property.getName(); 112b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 113b39f051631250c49936a475d0e64584afb7f1b93Chet Haase mProperty = property; 114b39f051631250c49936a475d0e64584afb7f1b93Chet Haase // New property/values/target should cause re-initialization prior to starting 115b39f051631250c49936a475d0e64584afb7f1b93Chet Haase mInitialized = false; 116b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 117b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 118b39f051631250c49936a475d0e64584afb7f1b93Chet Haase /** 11917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * Gets the name of the property that will be animated. This name will be used to derive 12017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * a setter function that will be called to set animated values. 12117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * For example, a property name of <code>foo</code> will result 12217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * in a call to the function <code>setFoo()</code> on the target object. If either 12317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <code>valueFrom</code> or <code>valueTo</code> is null, then a getter function will 12417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * also be derived and called. 12517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 12617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase public String getPropertyName() { 12717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase return mPropertyName; 12817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 12917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 13017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 131a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Creates a new ObjectAnimator object. This default constructor is primarily for 132d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase * use internally; the other constructors which take parameters are more generally 133d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase * useful. 134d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase */ 135a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public ObjectAnimator() { 136d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase } 137d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase 138d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase /** 139b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Private utility constructor that initializes the target object and name of the 140b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * property being animated. 141fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase * 14251ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * @param target The object whose property is to be animated. This object should 14351ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * have a public method on it called <code>setName()</code>, where <code>name</code> is 14451ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * the value of the <code>propertyName</code> parameter. 145d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase * @param propertyName The name of the property being animated. 146fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase */ 1472794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase private ObjectAnimator(Object target, String propertyName) { 14851ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy mTarget = target; 149d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase setPropertyName(propertyName); 150fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase } 151fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase 152fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase /** 153b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Private utility constructor that initializes the target object and property being animated. 154b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * 155b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param target The object whose property is to be animated. 156b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param property The property being animated. 157b39f051631250c49936a475d0e64584afb7f1b93Chet Haase */ 158b39f051631250c49936a475d0e64584afb7f1b93Chet Haase private <T> ObjectAnimator(T target, Property<T, ?> property) { 159b39f051631250c49936a475d0e64584afb7f1b93Chet Haase mTarget = target; 160b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setProperty(property); 161b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 162b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 163b39f051631250c49936a475d0e64584afb7f1b93Chet Haase /** 1642794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * Constructs and returns an ObjectAnimator that animates between int values. A single 165b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * value implies that that value is the one being animated to. Two values imply a starting 166b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 167b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 168b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 1692794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * 17051ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * @param target The object whose property is to be animated. This object should 17151ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * have a public method on it called <code>setName()</code>, where <code>name</code> is 17251ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * the value of the <code>propertyName</code> parameter. 1732794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param propertyName The name of the property being animated. 1742794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param values A set of values that the animation will animate between over time. 175b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 1762794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase */ 1772794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public static ObjectAnimator ofInt(Object target, String propertyName, int... values) { 1782794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase ObjectAnimator anim = new ObjectAnimator(target, propertyName); 1792794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setIntValues(values); 1802794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return anim; 1812794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 1822794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 1832794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase /** 184b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between int values. A single 185b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * value implies that that value is the one being animated to. Two values imply a starting 186b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 187b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 188b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 189b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * 190b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param target The object whose property is to be animated. 191b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param property The property being animated. 192b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of values that the animation will animate between over time. 193b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 194b39f051631250c49936a475d0e64584afb7f1b93Chet Haase */ 195b39f051631250c49936a475d0e64584afb7f1b93Chet Haase public static <T> ObjectAnimator ofInt(T target, Property<T, Integer> property, int... values) { 196b39f051631250c49936a475d0e64584afb7f1b93Chet Haase ObjectAnimator anim = new ObjectAnimator(target, property); 197b39f051631250c49936a475d0e64584afb7f1b93Chet Haase anim.setIntValues(values); 198b39f051631250c49936a475d0e64584afb7f1b93Chet Haase return anim; 199b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 200b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 201b39f051631250c49936a475d0e64584afb7f1b93Chet Haase /** 2022794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * Constructs and returns an ObjectAnimator that animates between float values. A single 203b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * value implies that that value is the one being animated to. Two values imply a starting 204b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 205b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 206b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 2072794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * 20851ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * @param target The object whose property is to be animated. This object should 20951ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * have a public method on it called <code>setName()</code>, where <code>name</code> is 21051ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * the value of the <code>propertyName</code> parameter. 2112794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param propertyName The name of the property being animated. 2122794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param values A set of values that the animation will animate between over time. 213b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 2142794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase */ 2152794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public static ObjectAnimator ofFloat(Object target, String propertyName, float... values) { 2162794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase ObjectAnimator anim = new ObjectAnimator(target, propertyName); 2172794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setFloatValues(values); 2182794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return anim; 2192794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 2202794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 2212794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase /** 222b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between float values. A single 223b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * value implies that that value is the one being animated to. Two values imply a starting 224b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 225b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 226b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 227b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * 228b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param target The object whose property is to be animated. 229b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param property The property being animated. 230b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of values that the animation will animate between over time. 231b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 232b39f051631250c49936a475d0e64584afb7f1b93Chet Haase */ 233b39f051631250c49936a475d0e64584afb7f1b93Chet Haase public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> property, 234b39f051631250c49936a475d0e64584afb7f1b93Chet Haase float... values) { 235b39f051631250c49936a475d0e64584afb7f1b93Chet Haase ObjectAnimator anim = new ObjectAnimator(target, property); 236b39f051631250c49936a475d0e64584afb7f1b93Chet Haase anim.setFloatValues(values); 237b39f051631250c49936a475d0e64584afb7f1b93Chet Haase return anim; 238b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 239b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 240b39f051631250c49936a475d0e64584afb7f1b93Chet Haase /** 241b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between Object values. A single 242b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * value implies that that value is the one being animated to. Two values imply a starting 243b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 244b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 245b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 24617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 24751ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * @param target The object whose property is to be animated. This object should 248b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * have a public method on it called <code>setName()</code>, where <code>name</code> is 249b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the value of the <code>propertyName</code> parameter. 2502794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param propertyName The name of the property being animated. 2512794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param evaluator A TypeEvaluator that will be called on each animation frame to 252b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * provide the necessary interpolation between the Object values to derive the animated 2532794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * value. 254b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of values that the animation will animate between over time. 255b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 256d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase */ 2572794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public static ObjectAnimator ofObject(Object target, String propertyName, 2582794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase TypeEvaluator evaluator, Object... values) { 2592794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase ObjectAnimator anim = new ObjectAnimator(target, propertyName); 2602794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setObjectValues(values); 2612794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setEvaluator(evaluator); 2622794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return anim; 2632794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 2642794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 2652794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase /** 266b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between Object values. A single 267b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * value implies that that value is the one being animated to. Two values imply a starting 268b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 269b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 270b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 2712794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * 272b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param target The object whose property is to be animated. 273b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param property The property being animated. 274b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param evaluator A TypeEvaluator that will be called on each animation frame to 275b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * provide the necessary interpolation between the Object values to derive the animated 276b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * value. 277b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of values that the animation will animate between over time. 278b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 279b39f051631250c49936a475d0e64584afb7f1b93Chet Haase */ 280b39f051631250c49936a475d0e64584afb7f1b93Chet Haase public static <T, V> ObjectAnimator ofObject(T target, Property<T, V> property, 281b39f051631250c49936a475d0e64584afb7f1b93Chet Haase TypeEvaluator<V> evaluator, V... values) { 282b39f051631250c49936a475d0e64584afb7f1b93Chet Haase ObjectAnimator anim = new ObjectAnimator(target, property); 283b39f051631250c49936a475d0e64584afb7f1b93Chet Haase anim.setObjectValues(values); 284b39f051631250c49936a475d0e64584afb7f1b93Chet Haase anim.setEvaluator(evaluator); 285b39f051631250c49936a475d0e64584afb7f1b93Chet Haase return anim; 286b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 287b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 288b39f051631250c49936a475d0e64584afb7f1b93Chet Haase /** 289b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between the sets of values specified 290b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * in <code>PropertyValueHolder</code> objects. This variant should be used when animating 291b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * several properties at once with the same ObjectAnimator, since PropertyValuesHolder allows 292b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * you to associate a set of animation values with a property name. 293b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * 294b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param target The object whose property is to be animated. Depending on how the 295b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * PropertyValuesObjects were constructed, the target object should either have the {@link 296b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * android.util.Property} objects used to construct the PropertyValuesHolder objects or (if the 297b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * PropertyValuesHOlder objects were created with property names) the target object should have 298b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * public methods on it called <code>setName()</code>, where <code>name</code> is the name of 299b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the property passed in as the <code>propertyName</code> parameter for each of the 300b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * PropertyValuesHolder objects. 301b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of PropertyValuesHolder objects whose values will be animated between 302b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * over time. 303b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 3042794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase */ 3052794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public static ObjectAnimator ofPropertyValuesHolder(Object target, 3062794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase PropertyValuesHolder... values) { 3072794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase ObjectAnimator anim = new ObjectAnimator(); 30851ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy anim.mTarget = target; 3092794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setValues(values); 3102794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return anim; 3113dd207a6dbd5d9244dc7fe213d5caa3cddaff0dbChet Haase } 3123dd207a6dbd5d9244dc7fe213d5caa3cddaff0dbChet Haase 31383d6e8213230fb0805aa019d266842253baeb114Romain Guy @Override 3142794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public void setIntValues(int... values) { 31583d6e8213230fb0805aa019d266842253baeb114Romain Guy if (mValues == null || mValues.length == 0) { 31683d6e8213230fb0805aa019d266842253baeb114Romain Guy // No values yet - this animator is being constructed piecemeal. Init the values with 31783d6e8213230fb0805aa019d266842253baeb114Romain Guy // whatever the current propertyName is 318b39f051631250c49936a475d0e64584afb7f1b93Chet Haase if (mProperty != null) { 319b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setValues(PropertyValuesHolder.ofInt(mProperty, values)); 320b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } else { 321b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setValues(PropertyValuesHolder.ofInt(mPropertyName, values)); 322b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 32383d6e8213230fb0805aa019d266842253baeb114Romain Guy } else { 3242794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase super.setIntValues(values); 3252794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 3262794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 3272794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 3282794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase @Override 3292794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public void setFloatValues(float... values) { 3302794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase if (mValues == null || mValues.length == 0) { 3312794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase // No values yet - this animator is being constructed piecemeal. Init the values with 3322794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase // whatever the current propertyName is 333b39f051631250c49936a475d0e64584afb7f1b93Chet Haase if (mProperty != null) { 334b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setValues(PropertyValuesHolder.ofFloat(mProperty, values)); 335b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } else { 336b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setValues(PropertyValuesHolder.ofFloat(mPropertyName, values)); 337b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 3382794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } else { 3392794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase super.setFloatValues(values); 3402794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 3412794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 3422794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 3432794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase @Override 3442794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public void setObjectValues(Object... values) { 3452794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase if (mValues == null || mValues.length == 0) { 3462794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase // No values yet - this animator is being constructed piecemeal. Init the values with 3472794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase // whatever the current propertyName is 348b39f051631250c49936a475d0e64584afb7f1b93Chet Haase if (mProperty != null) { 349b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setValues(PropertyValuesHolder.ofObject(mProperty, (TypeEvaluator)null, values)); 350b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } else { 351b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setValues(PropertyValuesHolder.ofObject(mPropertyName, (TypeEvaluator)null, values)); 352b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 3532794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } else { 3542794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase super.setObjectValues(values); 35583d6e8213230fb0805aa019d266842253baeb114Romain Guy } 3560e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase } 35783d6e8213230fb0805aa019d266842253baeb114Romain Guy 358e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase @Override 359e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase public void start() { 360e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase if (DBG) { 3613c4ce72c4d66d9ee041924259f20381b658c1529Chet Haase Log.d("ObjectAnimator", "Anim target, duration: " + mTarget + ", " + getDuration()); 362e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase for (int i = 0; i < mValues.length; ++i) { 363e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase PropertyValuesHolder pvh = mValues[i]; 364e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase ArrayList<Keyframe> keyframes = pvh.mKeyframeSet.mKeyframes; 365e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase Log.d("ObjectAnimator", " Values[" + i + "]: " + 366e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase pvh.getPropertyName() + ", " + keyframes.get(0).getValue() + ", " + 367e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase keyframes.get(pvh.mKeyframeSet.mNumKeyframes - 1).getValue()); 368e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase } 369e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase } 370e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase super.start(); 371e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase } 372e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase 3733dd207a6dbd5d9244dc7fe213d5caa3cddaff0dbChet Haase /** 37417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * This function is called immediately before processing the first animation 37517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * frame of an animation. If there is a nonzero <code>startDelay</code>, the 37617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * function is called after that delay ends. 37717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * It takes care of the final initialization steps for the 37817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * animation. This includes setting mEvaluator, if the user has not yet 37917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * set it up, and the setter/getter methods, if the user did not supply 38017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * them. 38117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 38217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <p>Overriders of this method should call the superclass method to cause 38317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * internal mechanisms to be set up correctly.</p> 38417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 38517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase @Override 38617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase void initAnimation() { 38721cd1389d2ef218b20994b617c57af120841a57fChet Haase if (!mInitialized) { 38821cd1389d2ef218b20994b617c57af120841a57fChet Haase // mValueType may change due to setter/getter setup; do this before calling super.init(), 38921cd1389d2ef218b20994b617c57af120841a57fChet Haase // which uses mValueType to set up the default type evaluator. 39021cd1389d2ef218b20994b617c57af120841a57fChet Haase int numValues = mValues.length; 39121cd1389d2ef218b20994b617c57af120841a57fChet Haase for (int i = 0; i < numValues; ++i) { 39251ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy mValues[i].setupSetterAndGetter(mTarget); 39321cd1389d2ef218b20994b617c57af120841a57fChet Haase } 39421cd1389d2ef218b20994b617c57af120841a57fChet Haase super.initAnimation(); 39517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 39617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 39717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 3982794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase /** 3992794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * Sets the length of the animation. The default duration is 300 milliseconds. 4002794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * 4012794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param duration The length of the animation, in milliseconds. 4022794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @return ObjectAnimator The object called with setDuration(). This return 4032794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * value makes it easier to compose statements together that construct and then set the 4042794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * duration, as in 4052794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * <code>ObjectAnimator.ofInt(target, propertyName, 0, 10).setDuration(500).start()</code>. 4062794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase */ 4072794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase @Override 4082794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public ObjectAnimator setDuration(long duration) { 4092794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase super.setDuration(duration); 4102794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return this; 4112794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 4122794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 41317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 41417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 41517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * The target object whose property will be animated by this animation 41617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 41751ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * @return The object being animated 41817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 41917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase public Object getTarget() { 42051ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy return mTarget; 42117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 42217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 42317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 42451ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * Sets the target object whose property will be animated by this animation 425f54a8d7c479485174941c38f151ea7083c658da3Chet Haase * 426f54a8d7c479485174941c38f151ea7083c658da3Chet Haase * @param target The object being animated 427f54a8d7c479485174941c38f151ea7083c658da3Chet Haase */ 42821cd1389d2ef218b20994b617c57af120841a57fChet Haase @Override 429f54a8d7c479485174941c38f151ea7083c658da3Chet Haase public void setTarget(Object target) { 43051ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy if (mTarget != target) { 4317beecfaf3b65a1552a7a7cc78ca00bb04133b507Patrick Dubroy final Object oldTarget = mTarget; 43251ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy mTarget = target; 4337beecfaf3b65a1552a7a7cc78ca00bb04133b507Patrick Dubroy if (oldTarget != null && target != null && oldTarget.getClass() == target.getClass()) { 43470d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase return; 43570d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase } 43670d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase // New target type should cause re-initialization prior to starting 43770d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase mInitialized = false; 43870d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase } 439f54a8d7c479485174941c38f151ea7083c658da3Chet Haase } 440f54a8d7c479485174941c38f151ea7083c658da3Chet Haase 44121cd1389d2ef218b20994b617c57af120841a57fChet Haase @Override 44221cd1389d2ef218b20994b617c57af120841a57fChet Haase public void setupStartValues() { 44321cd1389d2ef218b20994b617c57af120841a57fChet Haase initAnimation(); 44421cd1389d2ef218b20994b617c57af120841a57fChet Haase int numValues = mValues.length; 44521cd1389d2ef218b20994b617c57af120841a57fChet Haase for (int i = 0; i < numValues; ++i) { 44651ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy mValues[i].setupStartValue(mTarget); 44721cd1389d2ef218b20994b617c57af120841a57fChet Haase } 44821cd1389d2ef218b20994b617c57af120841a57fChet Haase } 44921cd1389d2ef218b20994b617c57af120841a57fChet Haase 45021cd1389d2ef218b20994b617c57af120841a57fChet Haase @Override 45121cd1389d2ef218b20994b617c57af120841a57fChet Haase public void setupEndValues() { 45221cd1389d2ef218b20994b617c57af120841a57fChet Haase initAnimation(); 45321cd1389d2ef218b20994b617c57af120841a57fChet Haase int numValues = mValues.length; 45421cd1389d2ef218b20994b617c57af120841a57fChet Haase for (int i = 0; i < numValues; ++i) { 45551ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy mValues[i].setupEndValue(mTarget); 45621cd1389d2ef218b20994b617c57af120841a57fChet Haase } 45721cd1389d2ef218b20994b617c57af120841a57fChet Haase } 45821cd1389d2ef218b20994b617c57af120841a57fChet Haase 459f54a8d7c479485174941c38f151ea7083c658da3Chet Haase /** 46017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * This method is called with the elapsed fraction of the animation during every 46117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * animation frame. This function turns the elapsed fraction into an interpolated fraction 46217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * and then into an animated value (from the evaluator. The function is called mostly during 46317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * animation updates, but it is also called when the <code>end()</code> 46417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * function is called, to set the final value on the property. 46517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 46617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <p>Overrides of this method must call the superclass to perform the calculation 46717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * of the animated value.</p> 46817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 46917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * @param fraction The elapsed fraction of the animation. 47017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 47117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase @Override 47217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase void animateValue(float fraction) { 47317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase super.animateValue(fraction); 474602e4d3824bf8b9cb9f817375d195b969712176aChet Haase int numValues = mValues.length; 475602e4d3824bf8b9cb9f817375d195b969712176aChet Haase for (int i = 0; i < numValues; ++i) { 47651ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy mValues[i].setAnimatedValue(mTarget); 47717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 47817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 47949afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase 48049afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase @Override 481a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public ObjectAnimator clone() { 482a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase final ObjectAnimator anim = (ObjectAnimator) super.clone(); 48349afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase return anim; 48449afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase } 485e9140a72b1059574046a624b471b2c3a35806496Chet Haase 486e9140a72b1059574046a624b471b2c3a35806496Chet Haase @Override 487e9140a72b1059574046a624b471b2c3a35806496Chet Haase public String toString() { 488e9140a72b1059574046a624b471b2c3a35806496Chet Haase String returnVal = "ObjectAnimator@" + Integer.toHexString(hashCode()) + ", target " + 489e9140a72b1059574046a624b471b2c3a35806496Chet Haase mTarget; 490e9140a72b1059574046a624b471b2c3a35806496Chet Haase if (mValues != null) { 491e9140a72b1059574046a624b471b2c3a35806496Chet Haase for (int i = 0; i < mValues.length; ++i) { 492e9140a72b1059574046a624b471b2c3a35806496Chet Haase returnVal += "\n " + mValues[i].toString(); 493e9140a72b1059574046a624b471b2c3a35806496Chet Haase } 494e9140a72b1059574046a624b471b2c3a35806496Chet Haase } 495e9140a72b1059574046a624b471b2c3a35806496Chet Haase return returnVal; 496e9140a72b1059574046a624b471b2c3a35806496Chet Haase } 49717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase} 498