ObjectAnimator.java revision 4eed52944c0fcb3afa7369aba60fb5c655580286
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 22e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haaseimport java.util.ArrayList; 2317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 2417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase/** 25a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * This subclass of {@link ValueAnimator} provides support for animating properties on target objects. 2617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * The constructors of this class take parameters to define the target object that will be animated 2717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * as well as the name of the property that will be animated. Appropriate set/get functions 2817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * are then determined internally and the animation will call these functions as necessary to 2917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * animate the property. 306e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * 313aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <div class="special reference"> 323aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <h3>Developer Guides</h3> 333aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <p>For more information about animating with {@code ObjectAnimator}, read the 343aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <a href="{@docRoot}guide/topics/graphics/prop-animation.html#object-animator">Property 353aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * Animation</a> developer guide.</p> 363aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * </div> 373aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * 386e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * @see #setPropertyName(String) 396e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * 4017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 412794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haasepublic final class ObjectAnimator extends ValueAnimator { 42e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase private static final boolean DBG = false; 4317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 4417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase // The target object on which the property exists, set in the constructor 4551ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy private Object mTarget; 4617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 4717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase private String mPropertyName; 4817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 49b39f051631250c49936a475d0e64584afb7f1b93Chet Haase private Property mProperty; 50b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 51be19e030a14c8e398e8af97fa898ea80187704dfChet Haase private boolean mAutoCancel = false; 52be19e030a14c8e398e8af97fa898ea80187704dfChet Haase 5317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 5417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * Sets the name of the property that will be animated. This name is used to derive 5517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * a setter function that will be called to set animated values. 5617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * For example, a property name of <code>foo</code> will result 5717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * in a call to the function <code>setFoo()</code> on the target object. If either 5817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <code>valueFrom</code> or <code>valueTo</code> is null, then a getter function will 5917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * also be derived and called. 6017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 616e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * <p>For best performance of the mechanism that calls the setter function determined by the 626e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * name of the property being animated, use <code>float</code> or <code>int</code> typed values, 636e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * and make the setter function for those properties have a <code>void</code> return value. This 646e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * will cause the code to take an optimized path for these constrained circumstances. Other 656e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * property types and return types will work, but will have more overhead in processing 666e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * the requests due to normal reflection mechanisms.</p> 676e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * 6817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <p>Note that the setter function derived from this property name 6917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * must take the same parameter type as the 7017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <code>valueFrom</code> and <code>valueTo</code> properties, otherwise the call to 7117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * the setter function will fail.</p> 7217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 73a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * <p>If this ObjectAnimator has been set up to animate several properties together, 74d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase * using more than one PropertyValuesHolder objects, then setting the propertyName simply 75d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase * sets the propertyName in the first of those PropertyValuesHolder objects.</p> 76d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase * 77b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param propertyName The name of the property being animated. Should not be null. 7817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 7917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase public void setPropertyName(String propertyName) { 800e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase // mValues could be null if this is being constructed piecemeal. Just record the 810e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase // propertyName to be used later when setValues() is called if so. 82d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase if (mValues != null) { 83602e4d3824bf8b9cb9f817375d195b969712176aChet Haase PropertyValuesHolder valuesHolder = mValues[0]; 84602e4d3824bf8b9cb9f817375d195b969712176aChet Haase String oldName = valuesHolder.getPropertyName(); 85d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase valuesHolder.setPropertyName(propertyName); 86602e4d3824bf8b9cb9f817375d195b969712176aChet Haase mValuesMap.remove(oldName); 87602e4d3824bf8b9cb9f817375d195b969712176aChet Haase mValuesMap.put(propertyName, valuesHolder); 88d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase } 8917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase mPropertyName = propertyName; 900e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase // New property/values/target should cause re-initialization prior to starting 910e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase mInitialized = false; 9217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 9317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 9417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 95b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Sets the property that will be animated. Property objects will take precedence over 96b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * properties specified by the {@link #setPropertyName(String)} method. Animations should 97b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * be set up to use one or the other, not both. 98b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * 99b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param property The property being animated. Should not be null. 100b39f051631250c49936a475d0e64584afb7f1b93Chet Haase */ 101b39f051631250c49936a475d0e64584afb7f1b93Chet Haase public void setProperty(Property property) { 102b39f051631250c49936a475d0e64584afb7f1b93Chet Haase // mValues could be null if this is being constructed piecemeal. Just record the 103b39f051631250c49936a475d0e64584afb7f1b93Chet Haase // propertyName to be used later when setValues() is called if so. 104b39f051631250c49936a475d0e64584afb7f1b93Chet Haase if (mValues != null) { 105b39f051631250c49936a475d0e64584afb7f1b93Chet Haase PropertyValuesHolder valuesHolder = mValues[0]; 106b39f051631250c49936a475d0e64584afb7f1b93Chet Haase String oldName = valuesHolder.getPropertyName(); 107b39f051631250c49936a475d0e64584afb7f1b93Chet Haase valuesHolder.setProperty(property); 108b39f051631250c49936a475d0e64584afb7f1b93Chet Haase mValuesMap.remove(oldName); 109b39f051631250c49936a475d0e64584afb7f1b93Chet Haase mValuesMap.put(mPropertyName, valuesHolder); 110b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 111b39f051631250c49936a475d0e64584afb7f1b93Chet Haase if (mProperty != null) { 112b39f051631250c49936a475d0e64584afb7f1b93Chet Haase mPropertyName = property.getName(); 113b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 114b39f051631250c49936a475d0e64584afb7f1b93Chet Haase mProperty = property; 115b39f051631250c49936a475d0e64584afb7f1b93Chet Haase // New property/values/target should cause re-initialization prior to starting 116b39f051631250c49936a475d0e64584afb7f1b93Chet Haase mInitialized = false; 117b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 118b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 119b39f051631250c49936a475d0e64584afb7f1b93Chet Haase /** 12017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * Gets the name of the property that will be animated. This name will be used to derive 12117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * a setter function that will be called to set animated values. 12217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * For example, a property name of <code>foo</code> will result 12317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * in a call to the function <code>setFoo()</code> on the target object. If either 12417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <code>valueFrom</code> or <code>valueTo</code> is null, then a getter function will 12517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * also be derived and called. 126fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase * 127fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase * <p>If this animator was created with a {@link Property} object instead of the 128fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase * string name of a property, then this method will return the {@link 129fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase * Property#getName() name} of that Property object instead. If this animator was 130fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase * created with one or more {@link PropertyValuesHolder} objects, then this method 131fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase * will return the {@link PropertyValuesHolder#getPropertyName() name} of that 132fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase * object (if there was just one) or a comma-separated list of all of the 133fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase * names (if there are more than one).</p> 13417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 13517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase public String getPropertyName() { 136fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase String propertyName = null; 137fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase if (mPropertyName != null) { 138fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase propertyName = mPropertyName; 139fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase } else if (mProperty != null) { 140fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase propertyName = mProperty.getName(); 141fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase } else if (mValues != null && mValues.length > 0) { 142fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase for (int i = 0; i < mValues.length; ++i) { 143fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase if (i == 0) { 144fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase propertyName = ""; 145fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase } else { 146fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase propertyName += ","; 147fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase } 148fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase propertyName += mValues[i].getPropertyName(); 149fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase } 150fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase } 151fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase return propertyName; 152fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase } 153fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase 154fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase @Override 155fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase String getNameForTrace() { 156fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase return "animator:" + getPropertyName(); 15717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 15817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 15917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 160a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Creates a new ObjectAnimator object. This default constructor is primarily for 161d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase * use internally; the other constructors which take parameters are more generally 162d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase * useful. 163d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase */ 164a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public ObjectAnimator() { 165d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase } 166d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase 167d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase /** 168b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Private utility constructor that initializes the target object and name of the 169b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * property being animated. 170fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase * 17151ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * @param target The object whose property is to be animated. This object should 17251ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * have a public method on it called <code>setName()</code>, where <code>name</code> is 17351ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * the value of the <code>propertyName</code> parameter. 174d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase * @param propertyName The name of the property being animated. 175fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase */ 1762794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase private ObjectAnimator(Object target, String propertyName) { 17751ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy mTarget = target; 178d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase setPropertyName(propertyName); 179fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase } 180fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase 181fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase /** 182b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Private utility constructor that initializes the target object and property being animated. 183b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * 184b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param target The object whose property is to be animated. 185b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param property The property being animated. 186b39f051631250c49936a475d0e64584afb7f1b93Chet Haase */ 187b39f051631250c49936a475d0e64584afb7f1b93Chet Haase private <T> ObjectAnimator(T target, Property<T, ?> property) { 188b39f051631250c49936a475d0e64584afb7f1b93Chet Haase mTarget = target; 189b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setProperty(property); 190b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 191b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 192b39f051631250c49936a475d0e64584afb7f1b93Chet Haase /** 1932794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * Constructs and returns an ObjectAnimator that animates between int values. A single 19416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 195b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 196b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 197b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 1982794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * 19951ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * @param target The object whose property is to be animated. This object should 20051ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * have a public method on it called <code>setName()</code>, where <code>name</code> is 20151ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * the value of the <code>propertyName</code> parameter. 2022794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param propertyName The name of the property being animated. 2032794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param values A set of values that the animation will animate between over time. 204b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 2052794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase */ 2062794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public static ObjectAnimator ofInt(Object target, String propertyName, int... values) { 2072794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase ObjectAnimator anim = new ObjectAnimator(target, propertyName); 2082794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setIntValues(values); 2092794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return anim; 2102794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 2112794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 2122794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase /** 213b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between int values. A single 21416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 215b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 216b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 217b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 218b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * 219b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param target The object whose property is to be animated. 220b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param property The property being animated. 221b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of values that the animation will animate between over time. 222b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 223b39f051631250c49936a475d0e64584afb7f1b93Chet Haase */ 224b39f051631250c49936a475d0e64584afb7f1b93Chet Haase public static <T> ObjectAnimator ofInt(T target, Property<T, Integer> property, int... values) { 225b39f051631250c49936a475d0e64584afb7f1b93Chet Haase ObjectAnimator anim = new ObjectAnimator(target, property); 226b39f051631250c49936a475d0e64584afb7f1b93Chet Haase anim.setIntValues(values); 227b39f051631250c49936a475d0e64584afb7f1b93Chet Haase return anim; 228b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 229b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 230b39f051631250c49936a475d0e64584afb7f1b93Chet Haase /** 2314eed52944c0fcb3afa7369aba60fb5c655580286George Mount * Constructs and returns an ObjectAnimator that animates over int values for a multiple 2324eed52944c0fcb3afa7369aba60fb5c655580286George Mount * parameters setter. Only public methods that take only int parameters are supported. 2334eed52944c0fcb3afa7369aba60fb5c655580286George Mount * Each <code>int[]</code> contains a complete set of parameters to the setter method. 2344eed52944c0fcb3afa7369aba60fb5c655580286George Mount * At least two <code>int[]</code> values must be provided, a start and end. More than two 2354eed52944c0fcb3afa7369aba60fb5c655580286George Mount * values imply a starting value, values to animate through along the way, and an ending 2364eed52944c0fcb3afa7369aba60fb5c655580286George Mount * value (these values will be distributed evenly across the duration of the animation). 2374eed52944c0fcb3afa7369aba60fb5c655580286George Mount * 2384eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param target The object whose property is to be animated. This object may 2394eed52944c0fcb3afa7369aba60fb5c655580286George Mount * have a public method on it called <code>setName()</code>, where <code>name</code> is 2404eed52944c0fcb3afa7369aba60fb5c655580286George Mount * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also 2414eed52944c0fcb3afa7369aba60fb5c655580286George Mount * be the case-sensitive complete name of the public setter method. 2424eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param propertyName The name of the property being animated or the name of the setter method. 2434eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param values A set of values that the animation will animate between over time. 2444eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @return An ObjectAnimator object that is set up to animate between the given values. 2454eed52944c0fcb3afa7369aba60fb5c655580286George Mount */ 2464eed52944c0fcb3afa7369aba60fb5c655580286George Mount public static ObjectAnimator ofMultiInt(Object target, String propertyName, int[][] values) { 2474eed52944c0fcb3afa7369aba60fb5c655580286George Mount PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiInt(propertyName, values); 2484eed52944c0fcb3afa7369aba60fb5c655580286George Mount return ofPropertyValuesHolder(target, pvh); 2494eed52944c0fcb3afa7369aba60fb5c655580286George Mount } 2504eed52944c0fcb3afa7369aba60fb5c655580286George Mount 2514eed52944c0fcb3afa7369aba60fb5c655580286George Mount /** 2524eed52944c0fcb3afa7369aba60fb5c655580286George Mount * Constructs and returns an ObjectAnimator that animates over values for a multiple int 2534eed52944c0fcb3afa7369aba60fb5c655580286George Mount * parameters setter. Only public methods that take only int parameters are supported. 2544eed52944c0fcb3afa7369aba60fb5c655580286George Mount * <p>At least two values must be provided, a start and end. More than two 2554eed52944c0fcb3afa7369aba60fb5c655580286George Mount * values imply a starting value, values to animate through along the way, and an ending 2564eed52944c0fcb3afa7369aba60fb5c655580286George Mount * value (these values will be distributed evenly across the duration of the animation).</p> 2574eed52944c0fcb3afa7369aba60fb5c655580286George Mount * 2584eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param target The object whose property is to be animated. This object may 2594eed52944c0fcb3afa7369aba60fb5c655580286George Mount * have a public method on it called <code>setName()</code>, where <code>name</code> is 2604eed52944c0fcb3afa7369aba60fb5c655580286George Mount * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also 2614eed52944c0fcb3afa7369aba60fb5c655580286George Mount * be the complete name of the public method. 2624eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param propertyName The name of the property being animated or the name of the setter method. 2634eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param converter Converts T objects into int parameters for the multi-value setter. 2644eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param evaluator A TypeEvaluator that will be called on each animation frame to 2654eed52944c0fcb3afa7369aba60fb5c655580286George Mount * provide the necessary interpolation between the Object values to derive the animated 2664eed52944c0fcb3afa7369aba60fb5c655580286George Mount * value. 2674eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param values A set of values that the animation will animate between over time. 2684eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @return An ObjectAnimator object that is set up to animate between the given values. 2694eed52944c0fcb3afa7369aba60fb5c655580286George Mount */ 2704eed52944c0fcb3afa7369aba60fb5c655580286George Mount public static <T> ObjectAnimator ofMultiInt(Object target, String propertyName, 2714eed52944c0fcb3afa7369aba60fb5c655580286George Mount TypeConverter<T, int[]> converter, TypeEvaluator<T> evaluator, T... values) { 2724eed52944c0fcb3afa7369aba60fb5c655580286George Mount PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiInt(propertyName, converter, 2734eed52944c0fcb3afa7369aba60fb5c655580286George Mount evaluator, values); 2744eed52944c0fcb3afa7369aba60fb5c655580286George Mount return ObjectAnimator.ofPropertyValuesHolder(target, pvh); 2754eed52944c0fcb3afa7369aba60fb5c655580286George Mount } 2764eed52944c0fcb3afa7369aba60fb5c655580286George Mount 2774eed52944c0fcb3afa7369aba60fb5c655580286George Mount /** 2782794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * Constructs and returns an ObjectAnimator that animates between float values. A single 27916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 280b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 281b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 282b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 2832794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * 28451ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * @param target The object whose property is to be animated. This object should 28551ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * have a public method on it called <code>setName()</code>, where <code>name</code> is 28651ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * the value of the <code>propertyName</code> parameter. 2872794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param propertyName The name of the property being animated. 2882794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param values A set of values that the animation will animate between over time. 289b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 2902794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase */ 2912794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public static ObjectAnimator ofFloat(Object target, String propertyName, float... values) { 2922794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase ObjectAnimator anim = new ObjectAnimator(target, propertyName); 2932794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setFloatValues(values); 2942794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return anim; 2952794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 2962794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 2972794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase /** 298b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between float values. A single 29916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 300b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 301b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 302b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 303b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * 304b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param target The object whose property is to be animated. 305b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param property The property being animated. 306b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of values that the animation will animate between over time. 307b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 308b39f051631250c49936a475d0e64584afb7f1b93Chet Haase */ 309b39f051631250c49936a475d0e64584afb7f1b93Chet Haase public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> property, 310b39f051631250c49936a475d0e64584afb7f1b93Chet Haase float... values) { 311b39f051631250c49936a475d0e64584afb7f1b93Chet Haase ObjectAnimator anim = new ObjectAnimator(target, property); 312b39f051631250c49936a475d0e64584afb7f1b93Chet Haase anim.setFloatValues(values); 313b39f051631250c49936a475d0e64584afb7f1b93Chet Haase return anim; 314b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 315b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 316b39f051631250c49936a475d0e64584afb7f1b93Chet Haase /** 3174eed52944c0fcb3afa7369aba60fb5c655580286George Mount * Constructs and returns an ObjectAnimator that animates over float values for a multiple 3184eed52944c0fcb3afa7369aba60fb5c655580286George Mount * parameters setter. Only public methods that take only float parameters are supported. 3194eed52944c0fcb3afa7369aba60fb5c655580286George Mount * Each <code>float[]</code> contains a complete set of parameters to the setter method. 3204eed52944c0fcb3afa7369aba60fb5c655580286George Mount * At least two <code>float[]</code> values must be provided, a start and end. More than two 3214eed52944c0fcb3afa7369aba60fb5c655580286George Mount * values imply a starting value, values to animate through along the way, and an ending 3224eed52944c0fcb3afa7369aba60fb5c655580286George Mount * value (these values will be distributed evenly across the duration of the animation). 3234eed52944c0fcb3afa7369aba60fb5c655580286George Mount * 3244eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param target The object whose property is to be animated. This object may 3254eed52944c0fcb3afa7369aba60fb5c655580286George Mount * have a public method on it called <code>setName()</code>, where <code>name</code> is 3264eed52944c0fcb3afa7369aba60fb5c655580286George Mount * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also 3274eed52944c0fcb3afa7369aba60fb5c655580286George Mount * be the complete name of the public method. 3284eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param propertyName The name of the property being animated or the name of the setter method. 3294eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param values A set of values that the animation will animate between over time. 3304eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @return An ObjectAnimator object that is set up to animate between the given values. 3314eed52944c0fcb3afa7369aba60fb5c655580286George Mount */ 3324eed52944c0fcb3afa7369aba60fb5c655580286George Mount public static ObjectAnimator ofMultiFloat(Object target, String propertyName, 3334eed52944c0fcb3afa7369aba60fb5c655580286George Mount float[][] values) { 3344eed52944c0fcb3afa7369aba60fb5c655580286George Mount PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiFloat(propertyName, values); 3354eed52944c0fcb3afa7369aba60fb5c655580286George Mount return ofPropertyValuesHolder(target, pvh); 3364eed52944c0fcb3afa7369aba60fb5c655580286George Mount } 3374eed52944c0fcb3afa7369aba60fb5c655580286George Mount 3384eed52944c0fcb3afa7369aba60fb5c655580286George Mount /** 3394eed52944c0fcb3afa7369aba60fb5c655580286George Mount * Constructs and returns an ObjectAnimator that animates over values for a multiple float 3404eed52944c0fcb3afa7369aba60fb5c655580286George Mount * parameters setter. Only public methods that take only float parameters are supported. 3414eed52944c0fcb3afa7369aba60fb5c655580286George Mount * <p>At least two values must be provided, a start and end. More than two 3424eed52944c0fcb3afa7369aba60fb5c655580286George Mount * values imply a starting value, values to animate through along the way, and an ending 3434eed52944c0fcb3afa7369aba60fb5c655580286George Mount * value (these values will be distributed evenly across the duration of the animation).</p> 3444eed52944c0fcb3afa7369aba60fb5c655580286George Mount * 3454eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param target The object whose property is to be animated. This object may 3464eed52944c0fcb3afa7369aba60fb5c655580286George Mount * have a public method on it called <code>setName()</code>, where <code>name</code> is 3474eed52944c0fcb3afa7369aba60fb5c655580286George Mount * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also 3484eed52944c0fcb3afa7369aba60fb5c655580286George Mount * be the case-sensitive complete name of the public setter method. 3494eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param propertyName The name of the property being animated or the name of the setter method. 3504eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param converter Converts T objects into float parameters for the multi-value setter. 3514eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param evaluator A TypeEvaluator that will be called on each animation frame to 3524eed52944c0fcb3afa7369aba60fb5c655580286George Mount * provide the necessary interpolation between the Object values to derive the animated 3534eed52944c0fcb3afa7369aba60fb5c655580286George Mount * value. 3544eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param values A set of values that the animation will animate between over time. 3554eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @return An ObjectAnimator object that is set up to animate between the given values. 3564eed52944c0fcb3afa7369aba60fb5c655580286George Mount */ 3574eed52944c0fcb3afa7369aba60fb5c655580286George Mount public static <T> ObjectAnimator ofMultiFloat(Object target, String propertyName, 3584eed52944c0fcb3afa7369aba60fb5c655580286George Mount TypeConverter<T, float[]> converter, TypeEvaluator<T> evaluator, T... values) { 3594eed52944c0fcb3afa7369aba60fb5c655580286George Mount PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiFloat(propertyName, converter, 3604eed52944c0fcb3afa7369aba60fb5c655580286George Mount evaluator, values); 3614eed52944c0fcb3afa7369aba60fb5c655580286George Mount return ObjectAnimator.ofPropertyValuesHolder(target, pvh); 3624eed52944c0fcb3afa7369aba60fb5c655580286George Mount } 3634eed52944c0fcb3afa7369aba60fb5c655580286George Mount 3644eed52944c0fcb3afa7369aba60fb5c655580286George Mount /** 365b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between Object values. A single 36616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 367b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 368b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 369b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 37017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 37151ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * @param target The object whose property is to be animated. This object should 372b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * have a public method on it called <code>setName()</code>, where <code>name</code> is 373b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the value of the <code>propertyName</code> parameter. 3742794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param propertyName The name of the property being animated. 3752794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param evaluator A TypeEvaluator that will be called on each animation frame to 376b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * provide the necessary interpolation between the Object values to derive the animated 3772794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * value. 378b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of values that the animation will animate between over time. 379b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 380d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase */ 3812794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public static ObjectAnimator ofObject(Object target, String propertyName, 3822794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase TypeEvaluator evaluator, Object... values) { 3832794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase ObjectAnimator anim = new ObjectAnimator(target, propertyName); 3842794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setObjectValues(values); 3852794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setEvaluator(evaluator); 3862794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return anim; 3872794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 3882794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 3892794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase /** 390b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between Object values. A single 39116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 392b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 393b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 394b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 3952794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * 396b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param target The object whose property is to be animated. 397b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param property The property being animated. 398b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param evaluator A TypeEvaluator that will be called on each animation frame to 399b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * provide the necessary interpolation between the Object values to derive the animated 400b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * value. 401b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of values that the animation will animate between over time. 402b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 403b39f051631250c49936a475d0e64584afb7f1b93Chet Haase */ 404b39f051631250c49936a475d0e64584afb7f1b93Chet Haase public static <T, V> ObjectAnimator ofObject(T target, Property<T, V> property, 405b39f051631250c49936a475d0e64584afb7f1b93Chet Haase TypeEvaluator<V> evaluator, V... values) { 406b39f051631250c49936a475d0e64584afb7f1b93Chet Haase ObjectAnimator anim = new ObjectAnimator(target, property); 407b39f051631250c49936a475d0e64584afb7f1b93Chet Haase anim.setObjectValues(values); 408b39f051631250c49936a475d0e64584afb7f1b93Chet Haase anim.setEvaluator(evaluator); 409b39f051631250c49936a475d0e64584afb7f1b93Chet Haase return anim; 410b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 411b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 412b39f051631250c49936a475d0e64584afb7f1b93Chet Haase /** 41316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * Constructs and returns an ObjectAnimator that animates between Object values. A single 41416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 41516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * and ending values. More than two values imply a starting value, values to animate through 41616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * along the way, and an ending value (these values will be distributed evenly across 41716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * the duration of the animation). This variant supplies a <code>TypeConverter</code> to 41816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * convert from the animated values to the type of the property. If only one value is 41916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * supplied, the <code>TypeConverter</code> must implement 42016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * {@link TypeConverter#convertBack(Object)} to retrieve the current value. 42116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * 42216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @param target The object whose property is to be animated. 42316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @param property The property being animated. 42416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @param converter Converts the animated object to the Property type. 42516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @param evaluator A TypeEvaluator that will be called on each animation frame to 42616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * provide the necessary interpolation between the Object values to derive the animated 42716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value. 42816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @param values A set of values that the animation will animate between over time. 42916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @return An ObjectAnimator object that is set up to animate between the given values. 43016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount */ 43116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount public static <T, V, P> ObjectAnimator ofObject(T target, Property<T, P> property, 43216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount TypeConverter<V, P> converter, TypeEvaluator<V> evaluator, V... values) { 43316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount PropertyValuesHolder pvh = PropertyValuesHolder.ofObject(property, converter, evaluator, 43416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount values); 43516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount return ofPropertyValuesHolder(target, pvh); 43616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount } 43716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount 43816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount /** 439b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between the sets of values specified 440b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * in <code>PropertyValueHolder</code> objects. This variant should be used when animating 441b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * several properties at once with the same ObjectAnimator, since PropertyValuesHolder allows 442b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * you to associate a set of animation values with a property name. 443b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * 444b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param target The object whose property is to be animated. Depending on how the 445b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * PropertyValuesObjects were constructed, the target object should either have the {@link 446b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * android.util.Property} objects used to construct the PropertyValuesHolder objects or (if the 447b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * PropertyValuesHOlder objects were created with property names) the target object should have 448b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * public methods on it called <code>setName()</code>, where <code>name</code> is the name of 449b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the property passed in as the <code>propertyName</code> parameter for each of the 450b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * PropertyValuesHolder objects. 451b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of PropertyValuesHolder objects whose values will be animated between 452b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * over time. 453b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 4542794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase */ 4552794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public static ObjectAnimator ofPropertyValuesHolder(Object target, 4562794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase PropertyValuesHolder... values) { 4572794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase ObjectAnimator anim = new ObjectAnimator(); 45851ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy anim.mTarget = target; 4592794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setValues(values); 4602794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return anim; 4613dd207a6dbd5d9244dc7fe213d5caa3cddaff0dbChet Haase } 4623dd207a6dbd5d9244dc7fe213d5caa3cddaff0dbChet Haase 46383d6e8213230fb0805aa019d266842253baeb114Romain Guy @Override 4642794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public void setIntValues(int... values) { 46583d6e8213230fb0805aa019d266842253baeb114Romain Guy if (mValues == null || mValues.length == 0) { 46683d6e8213230fb0805aa019d266842253baeb114Romain Guy // No values yet - this animator is being constructed piecemeal. Init the values with 46783d6e8213230fb0805aa019d266842253baeb114Romain Guy // whatever the current propertyName is 468b39f051631250c49936a475d0e64584afb7f1b93Chet Haase if (mProperty != null) { 469b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setValues(PropertyValuesHolder.ofInt(mProperty, values)); 470b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } else { 471b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setValues(PropertyValuesHolder.ofInt(mPropertyName, values)); 472b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 47383d6e8213230fb0805aa019d266842253baeb114Romain Guy } else { 4742794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase super.setIntValues(values); 4752794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 4762794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 4772794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 4782794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase @Override 4792794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public void setFloatValues(float... values) { 4802794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase if (mValues == null || mValues.length == 0) { 4812794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase // No values yet - this animator is being constructed piecemeal. Init the values with 4822794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase // whatever the current propertyName is 483b39f051631250c49936a475d0e64584afb7f1b93Chet Haase if (mProperty != null) { 484b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setValues(PropertyValuesHolder.ofFloat(mProperty, values)); 485b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } else { 486b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setValues(PropertyValuesHolder.ofFloat(mPropertyName, values)); 487b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 4882794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } else { 4892794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase super.setFloatValues(values); 4902794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 4912794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 4922794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 4932794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase @Override 4942794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public void setObjectValues(Object... values) { 4952794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase if (mValues == null || mValues.length == 0) { 4962794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase // No values yet - this animator is being constructed piecemeal. Init the values with 4972794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase // whatever the current propertyName is 498b39f051631250c49936a475d0e64584afb7f1b93Chet Haase if (mProperty != null) { 499be19e030a14c8e398e8af97fa898ea80187704dfChet Haase setValues(PropertyValuesHolder.ofObject(mProperty, (TypeEvaluator) null, values)); 500b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } else { 501be19e030a14c8e398e8af97fa898ea80187704dfChet Haase setValues(PropertyValuesHolder.ofObject(mPropertyName, 502be19e030a14c8e398e8af97fa898ea80187704dfChet Haase (TypeEvaluator) null, values)); 503b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 5042794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } else { 5052794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase super.setObjectValues(values); 50683d6e8213230fb0805aa019d266842253baeb114Romain Guy } 5070e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase } 50883d6e8213230fb0805aa019d266842253baeb114Romain Guy 509be19e030a14c8e398e8af97fa898ea80187704dfChet Haase /** 510be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * autoCancel controls whether an ObjectAnimator will be canceled automatically 511be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * when any other ObjectAnimator with the same target and properties is started. 512be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * Setting this flag may make it easier to run different animators on the same target 513be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * object without having to keep track of whether there are conflicting animators that 514be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * need to be manually canceled. Canceling animators must have the same exact set of 515be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * target properties, in the same order. 516be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * 517be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * @param cancel Whether future ObjectAnimators with the same target and properties 518be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * as this ObjectAnimator will cause this ObjectAnimator to be canceled. 519be19e030a14c8e398e8af97fa898ea80187704dfChet Haase */ 520be19e030a14c8e398e8af97fa898ea80187704dfChet Haase public void setAutoCancel(boolean cancel) { 521be19e030a14c8e398e8af97fa898ea80187704dfChet Haase mAutoCancel = cancel; 522be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 523be19e030a14c8e398e8af97fa898ea80187704dfChet Haase 524be19e030a14c8e398e8af97fa898ea80187704dfChet Haase private boolean hasSameTargetAndProperties(Animator anim) { 525be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (anim instanceof ObjectAnimator) { 526be19e030a14c8e398e8af97fa898ea80187704dfChet Haase PropertyValuesHolder[] theirValues = ((ObjectAnimator) anim).getValues(); 527be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (((ObjectAnimator) anim).getTarget() == mTarget && 528be19e030a14c8e398e8af97fa898ea80187704dfChet Haase mValues.length == theirValues.length) { 529be19e030a14c8e398e8af97fa898ea80187704dfChet Haase for (int i = 0; i < mValues.length; ++i) { 530be19e030a14c8e398e8af97fa898ea80187704dfChet Haase PropertyValuesHolder pvhMine = mValues[i]; 531be19e030a14c8e398e8af97fa898ea80187704dfChet Haase PropertyValuesHolder pvhTheirs = theirValues[i]; 532be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (pvhMine.getPropertyName() == null || 533be19e030a14c8e398e8af97fa898ea80187704dfChet Haase !pvhMine.getPropertyName().equals(pvhTheirs.getPropertyName())) { 534be19e030a14c8e398e8af97fa898ea80187704dfChet Haase return false; 535be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 536be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 537be19e030a14c8e398e8af97fa898ea80187704dfChet Haase return true; 538be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 539be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 540be19e030a14c8e398e8af97fa898ea80187704dfChet Haase return false; 541be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 542be19e030a14c8e398e8af97fa898ea80187704dfChet Haase 543e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase @Override 544e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase public void start() { 545be19e030a14c8e398e8af97fa898ea80187704dfChet Haase // See if any of the current active/pending animators need to be canceled 546be19e030a14c8e398e8af97fa898ea80187704dfChet Haase AnimationHandler handler = sAnimationHandler.get(); 547be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (handler != null) { 548be19e030a14c8e398e8af97fa898ea80187704dfChet Haase int numAnims = handler.mAnimations.size(); 549be19e030a14c8e398e8af97fa898ea80187704dfChet Haase for (int i = numAnims - 1; i >= 0; i--) { 550be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (handler.mAnimations.get(i) instanceof ObjectAnimator) { 551be19e030a14c8e398e8af97fa898ea80187704dfChet Haase ObjectAnimator anim = (ObjectAnimator) handler.mAnimations.get(i); 552be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) { 553be19e030a14c8e398e8af97fa898ea80187704dfChet Haase anim.cancel(); 554be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 555be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 556be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 557be19e030a14c8e398e8af97fa898ea80187704dfChet Haase numAnims = handler.mPendingAnimations.size(); 558be19e030a14c8e398e8af97fa898ea80187704dfChet Haase for (int i = numAnims - 1; i >= 0; i--) { 559be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (handler.mPendingAnimations.get(i) instanceof ObjectAnimator) { 560be19e030a14c8e398e8af97fa898ea80187704dfChet Haase ObjectAnimator anim = (ObjectAnimator) handler.mPendingAnimations.get(i); 561be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) { 562be19e030a14c8e398e8af97fa898ea80187704dfChet Haase anim.cancel(); 563be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 564be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 565be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 566be19e030a14c8e398e8af97fa898ea80187704dfChet Haase numAnims = handler.mDelayedAnims.size(); 567be19e030a14c8e398e8af97fa898ea80187704dfChet Haase for (int i = numAnims - 1; i >= 0; i--) { 568be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (handler.mDelayedAnims.get(i) instanceof ObjectAnimator) { 569be19e030a14c8e398e8af97fa898ea80187704dfChet Haase ObjectAnimator anim = (ObjectAnimator) handler.mDelayedAnims.get(i); 570be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) { 571be19e030a14c8e398e8af97fa898ea80187704dfChet Haase anim.cancel(); 572be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 573be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 574be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 575be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 576e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase if (DBG) { 5773c4ce72c4d66d9ee041924259f20381b658c1529Chet Haase Log.d("ObjectAnimator", "Anim target, duration: " + mTarget + ", " + getDuration()); 578e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase for (int i = 0; i < mValues.length; ++i) { 579e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase PropertyValuesHolder pvh = mValues[i]; 580e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase ArrayList<Keyframe> keyframes = pvh.mKeyframeSet.mKeyframes; 581e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase Log.d("ObjectAnimator", " Values[" + i + "]: " + 582e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase pvh.getPropertyName() + ", " + keyframes.get(0).getValue() + ", " + 583e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase keyframes.get(pvh.mKeyframeSet.mNumKeyframes - 1).getValue()); 584e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase } 585e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase } 586e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase super.start(); 587e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase } 588e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase 5893dd207a6dbd5d9244dc7fe213d5caa3cddaff0dbChet Haase /** 59017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * This function is called immediately before processing the first animation 59117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * frame of an animation. If there is a nonzero <code>startDelay</code>, the 59217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * function is called after that delay ends. 59317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * It takes care of the final initialization steps for the 59417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * animation. This includes setting mEvaluator, if the user has not yet 59517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * set it up, and the setter/getter methods, if the user did not supply 59617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * them. 59717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 59817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <p>Overriders of this method should call the superclass method to cause 59917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * internal mechanisms to be set up correctly.</p> 60017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 60117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase @Override 60217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase void initAnimation() { 60321cd1389d2ef218b20994b617c57af120841a57fChet Haase if (!mInitialized) { 60421cd1389d2ef218b20994b617c57af120841a57fChet Haase // mValueType may change due to setter/getter setup; do this before calling super.init(), 60521cd1389d2ef218b20994b617c57af120841a57fChet Haase // which uses mValueType to set up the default type evaluator. 60621cd1389d2ef218b20994b617c57af120841a57fChet Haase int numValues = mValues.length; 60721cd1389d2ef218b20994b617c57af120841a57fChet Haase for (int i = 0; i < numValues; ++i) { 60851ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy mValues[i].setupSetterAndGetter(mTarget); 60921cd1389d2ef218b20994b617c57af120841a57fChet Haase } 61021cd1389d2ef218b20994b617c57af120841a57fChet Haase super.initAnimation(); 61117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 61217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 61317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 6142794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase /** 6152794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * Sets the length of the animation. The default duration is 300 milliseconds. 6162794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * 6172794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param duration The length of the animation, in milliseconds. 6182794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @return ObjectAnimator The object called with setDuration(). This return 6192794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * value makes it easier to compose statements together that construct and then set the 6202794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * duration, as in 6212794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * <code>ObjectAnimator.ofInt(target, propertyName, 0, 10).setDuration(500).start()</code>. 6222794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase */ 6232794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase @Override 6242794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public ObjectAnimator setDuration(long duration) { 6252794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase super.setDuration(duration); 6262794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return this; 6272794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 6282794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 62917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 63017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 63117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * The target object whose property will be animated by this animation 63217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 63351ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * @return The object being animated 63417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 63517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase public Object getTarget() { 63651ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy return mTarget; 63717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 63817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 63917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 64051ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * Sets the target object whose property will be animated by this animation 641f54a8d7c479485174941c38f151ea7083c658da3Chet Haase * 642f54a8d7c479485174941c38f151ea7083c658da3Chet Haase * @param target The object being animated 643f54a8d7c479485174941c38f151ea7083c658da3Chet Haase */ 64421cd1389d2ef218b20994b617c57af120841a57fChet Haase @Override 645f54a8d7c479485174941c38f151ea7083c658da3Chet Haase public void setTarget(Object target) { 64651ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy if (mTarget != target) { 6477beecfaf3b65a1552a7a7cc78ca00bb04133b507Patrick Dubroy final Object oldTarget = mTarget; 64851ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy mTarget = target; 6497beecfaf3b65a1552a7a7cc78ca00bb04133b507Patrick Dubroy if (oldTarget != null && target != null && oldTarget.getClass() == target.getClass()) { 65070d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase return; 65170d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase } 65270d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase // New target type should cause re-initialization prior to starting 65370d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase mInitialized = false; 65470d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase } 655f54a8d7c479485174941c38f151ea7083c658da3Chet Haase } 656f54a8d7c479485174941c38f151ea7083c658da3Chet Haase 65721cd1389d2ef218b20994b617c57af120841a57fChet Haase @Override 65821cd1389d2ef218b20994b617c57af120841a57fChet Haase public void setupStartValues() { 65921cd1389d2ef218b20994b617c57af120841a57fChet Haase initAnimation(); 66021cd1389d2ef218b20994b617c57af120841a57fChet Haase int numValues = mValues.length; 66121cd1389d2ef218b20994b617c57af120841a57fChet Haase for (int i = 0; i < numValues; ++i) { 66251ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy mValues[i].setupStartValue(mTarget); 66321cd1389d2ef218b20994b617c57af120841a57fChet Haase } 66421cd1389d2ef218b20994b617c57af120841a57fChet Haase } 66521cd1389d2ef218b20994b617c57af120841a57fChet Haase 66621cd1389d2ef218b20994b617c57af120841a57fChet Haase @Override 66721cd1389d2ef218b20994b617c57af120841a57fChet Haase public void setupEndValues() { 66821cd1389d2ef218b20994b617c57af120841a57fChet Haase initAnimation(); 66921cd1389d2ef218b20994b617c57af120841a57fChet Haase int numValues = mValues.length; 67021cd1389d2ef218b20994b617c57af120841a57fChet Haase for (int i = 0; i < numValues; ++i) { 67151ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy mValues[i].setupEndValue(mTarget); 67221cd1389d2ef218b20994b617c57af120841a57fChet Haase } 67321cd1389d2ef218b20994b617c57af120841a57fChet Haase } 67421cd1389d2ef218b20994b617c57af120841a57fChet Haase 675f54a8d7c479485174941c38f151ea7083c658da3Chet Haase /** 67617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * This method is called with the elapsed fraction of the animation during every 67717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * animation frame. This function turns the elapsed fraction into an interpolated fraction 67817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * and then into an animated value (from the evaluator. The function is called mostly during 67917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * animation updates, but it is also called when the <code>end()</code> 68017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * function is called, to set the final value on the property. 68117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 68217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <p>Overrides of this method must call the superclass to perform the calculation 68317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * of the animated value.</p> 68417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 68517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * @param fraction The elapsed fraction of the animation. 68617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 68717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase @Override 68817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase void animateValue(float fraction) { 68917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase super.animateValue(fraction); 690602e4d3824bf8b9cb9f817375d195b969712176aChet Haase int numValues = mValues.length; 691602e4d3824bf8b9cb9f817375d195b969712176aChet Haase for (int i = 0; i < numValues; ++i) { 69251ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy mValues[i].setAnimatedValue(mTarget); 69317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 69417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 69549afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase 69649afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase @Override 697a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public ObjectAnimator clone() { 698a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase final ObjectAnimator anim = (ObjectAnimator) super.clone(); 69949afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase return anim; 70049afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase } 701e9140a72b1059574046a624b471b2c3a35806496Chet Haase 702e9140a72b1059574046a624b471b2c3a35806496Chet Haase @Override 703e9140a72b1059574046a624b471b2c3a35806496Chet Haase public String toString() { 704e9140a72b1059574046a624b471b2c3a35806496Chet Haase String returnVal = "ObjectAnimator@" + Integer.toHexString(hashCode()) + ", target " + 705e9140a72b1059574046a624b471b2c3a35806496Chet Haase mTarget; 706e9140a72b1059574046a624b471b2c3a35806496Chet Haase if (mValues != null) { 707e9140a72b1059574046a624b471b2c3a35806496Chet Haase for (int i = 0; i < mValues.length; ++i) { 708e9140a72b1059574046a624b471b2c3a35806496Chet Haase returnVal += "\n " + mValues[i].toString(); 709e9140a72b1059574046a624b471b2c3a35806496Chet Haase } 710e9140a72b1059574046a624b471b2c3a35806496Chet Haase } 711e9140a72b1059574046a624b471b2c3a35806496Chet Haase return returnVal; 712e9140a72b1059574046a624b471b2c3a35806496Chet Haase } 71317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase} 714