ObjectAnimator.java revision 1ffb280a7d2c70cc16d709c685f5d31fdb86b5e4
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 /** 2781ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * Constructs and returns an ObjectAnimator that animates between color values. A single 2791ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * value implies that that value is the one being animated to. Two values imply starting 2801ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * and ending values. More than two values imply a starting value, values to animate through 2811ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * along the way, and an ending value (these values will be distributed evenly across 2821ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * the duration of the animation). 2831ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * 2841ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * @param target The object whose property is to be animated. This object should 2851ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * have a public method on it called <code>setName()</code>, where <code>name</code> is 2861ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * the value of the <code>propertyName</code> parameter. 2871ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * @param propertyName The name of the property being animated. 2881ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * @param values A set of values that the animation will animate between over time. 2891ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * @return An ObjectAnimator object that is set up to animate between the given values. 2901ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount */ 2911ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount public static ObjectAnimator ofArgb(Object target, String propertyName, int... values) { 2921ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount ObjectAnimator animator = ofInt(target, propertyName, values); 2931ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount animator.setEvaluator(ArgbEvaluator.getInstance()); 2941ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount return animator; 2951ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount } 2961ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount 2971ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount /** 2981ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * Constructs and returns an ObjectAnimator that animates between color values. A single 2991ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * value implies that that value is the one being animated to. Two values imply starting 3001ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * and ending values. More than two values imply a starting value, values to animate through 3011ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * along the way, and an ending value (these values will be distributed evenly across 3021ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * the duration of the animation). 3031ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * 3041ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * @param target The object whose property is to be animated. 3051ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * @param property The property being animated. 3061ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * @param values A set of values that the animation will animate between over time. 3071ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * @return An ObjectAnimator object that is set up to animate between the given values. 3081ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount */ 3091ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount public static <T> ObjectAnimator ofArgb(T target, Property<T, Integer> property, 3101ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount int... values) { 3111ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount ObjectAnimator animator = ofInt(target, property, values); 3121ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount animator.setEvaluator(ArgbEvaluator.getInstance()); 3131ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount return animator; 3141ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount } 3151ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount 3161ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount /** 3172794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * Constructs and returns an ObjectAnimator that animates between float values. A single 31816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 319b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 320b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 321b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 3222794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * 32351ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * @param target The object whose property is to be animated. This object should 32451ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * have a public method on it called <code>setName()</code>, where <code>name</code> is 32551ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * the value of the <code>propertyName</code> parameter. 3262794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param propertyName The name of the property being animated. 3272794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param values A set of values that the animation will animate between over time. 328b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 3292794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase */ 3302794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public static ObjectAnimator ofFloat(Object target, String propertyName, float... values) { 3312794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase ObjectAnimator anim = new ObjectAnimator(target, propertyName); 3322794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setFloatValues(values); 3332794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return anim; 3342794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 3352794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 3362794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase /** 337b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between float values. A single 33816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 339b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 340b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 341b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 342b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * 343b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param target The object whose property is to be animated. 344b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param property The property being animated. 345b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of values that the animation will animate between over time. 346b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 347b39f051631250c49936a475d0e64584afb7f1b93Chet Haase */ 348b39f051631250c49936a475d0e64584afb7f1b93Chet Haase public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> property, 349b39f051631250c49936a475d0e64584afb7f1b93Chet Haase float... values) { 350b39f051631250c49936a475d0e64584afb7f1b93Chet Haase ObjectAnimator anim = new ObjectAnimator(target, property); 351b39f051631250c49936a475d0e64584afb7f1b93Chet Haase anim.setFloatValues(values); 352b39f051631250c49936a475d0e64584afb7f1b93Chet Haase return anim; 353b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 354b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 355b39f051631250c49936a475d0e64584afb7f1b93Chet Haase /** 3564eed52944c0fcb3afa7369aba60fb5c655580286George Mount * Constructs and returns an ObjectAnimator that animates over float values for a multiple 3574eed52944c0fcb3afa7369aba60fb5c655580286George Mount * parameters setter. Only public methods that take only float parameters are supported. 3584eed52944c0fcb3afa7369aba60fb5c655580286George Mount * Each <code>float[]</code> contains a complete set of parameters to the setter method. 3594eed52944c0fcb3afa7369aba60fb5c655580286George Mount * At least two <code>float[]</code> values must be provided, a start and end. More than two 3604eed52944c0fcb3afa7369aba60fb5c655580286George Mount * values imply a starting value, values to animate through along the way, and an ending 3614eed52944c0fcb3afa7369aba60fb5c655580286George Mount * value (these values will be distributed evenly across the duration of the animation). 3624eed52944c0fcb3afa7369aba60fb5c655580286George Mount * 3634eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param target The object whose property is to be animated. This object may 3644eed52944c0fcb3afa7369aba60fb5c655580286George Mount * have a public method on it called <code>setName()</code>, where <code>name</code> is 3654eed52944c0fcb3afa7369aba60fb5c655580286George Mount * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also 3664eed52944c0fcb3afa7369aba60fb5c655580286George Mount * be the complete name of the public method. 3674eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param propertyName The name of the property being animated or the name of the setter method. 3684eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param values A set of values that the animation will animate between over time. 3694eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @return An ObjectAnimator object that is set up to animate between the given values. 3704eed52944c0fcb3afa7369aba60fb5c655580286George Mount */ 3714eed52944c0fcb3afa7369aba60fb5c655580286George Mount public static ObjectAnimator ofMultiFloat(Object target, String propertyName, 3724eed52944c0fcb3afa7369aba60fb5c655580286George Mount float[][] values) { 3734eed52944c0fcb3afa7369aba60fb5c655580286George Mount PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiFloat(propertyName, values); 3744eed52944c0fcb3afa7369aba60fb5c655580286George Mount return ofPropertyValuesHolder(target, pvh); 3754eed52944c0fcb3afa7369aba60fb5c655580286George Mount } 3764eed52944c0fcb3afa7369aba60fb5c655580286George Mount 3774eed52944c0fcb3afa7369aba60fb5c655580286George Mount /** 3784eed52944c0fcb3afa7369aba60fb5c655580286George Mount * Constructs and returns an ObjectAnimator that animates over values for a multiple float 3794eed52944c0fcb3afa7369aba60fb5c655580286George Mount * parameters setter. Only public methods that take only float parameters are supported. 3804eed52944c0fcb3afa7369aba60fb5c655580286George Mount * <p>At least two values must be provided, a start and end. More than two 3814eed52944c0fcb3afa7369aba60fb5c655580286George Mount * values imply a starting value, values to animate through along the way, and an ending 3824eed52944c0fcb3afa7369aba60fb5c655580286George Mount * value (these values will be distributed evenly across the duration of the animation).</p> 3834eed52944c0fcb3afa7369aba60fb5c655580286George Mount * 3844eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param target The object whose property is to be animated. This object may 3854eed52944c0fcb3afa7369aba60fb5c655580286George Mount * have a public method on it called <code>setName()</code>, where <code>name</code> is 3864eed52944c0fcb3afa7369aba60fb5c655580286George Mount * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also 3874eed52944c0fcb3afa7369aba60fb5c655580286George Mount * be the case-sensitive complete name of the public setter method. 3884eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param propertyName The name of the property being animated or the name of the setter method. 3894eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param converter Converts T objects into float parameters for the multi-value setter. 3904eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param evaluator A TypeEvaluator that will be called on each animation frame to 3914eed52944c0fcb3afa7369aba60fb5c655580286George Mount * provide the necessary interpolation between the Object values to derive the animated 3924eed52944c0fcb3afa7369aba60fb5c655580286George Mount * value. 3934eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param values A set of values that the animation will animate between over time. 3944eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @return An ObjectAnimator object that is set up to animate between the given values. 3954eed52944c0fcb3afa7369aba60fb5c655580286George Mount */ 3964eed52944c0fcb3afa7369aba60fb5c655580286George Mount public static <T> ObjectAnimator ofMultiFloat(Object target, String propertyName, 3974eed52944c0fcb3afa7369aba60fb5c655580286George Mount TypeConverter<T, float[]> converter, TypeEvaluator<T> evaluator, T... values) { 3984eed52944c0fcb3afa7369aba60fb5c655580286George Mount PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiFloat(propertyName, converter, 3994eed52944c0fcb3afa7369aba60fb5c655580286George Mount evaluator, values); 4004eed52944c0fcb3afa7369aba60fb5c655580286George Mount return ObjectAnimator.ofPropertyValuesHolder(target, pvh); 4014eed52944c0fcb3afa7369aba60fb5c655580286George Mount } 4024eed52944c0fcb3afa7369aba60fb5c655580286George Mount 4034eed52944c0fcb3afa7369aba60fb5c655580286George Mount /** 404b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between Object values. A single 40516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 406b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 407b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 408b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 40917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 41051ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * @param target The object whose property is to be animated. This object should 411b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * have a public method on it called <code>setName()</code>, where <code>name</code> is 412b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the value of the <code>propertyName</code> parameter. 4132794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param propertyName The name of the property being animated. 4142794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param evaluator A TypeEvaluator that will be called on each animation frame to 415b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * provide the necessary interpolation between the Object values to derive the animated 4162794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * value. 417b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of values that the animation will animate between over time. 418b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 419d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase */ 4202794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public static ObjectAnimator ofObject(Object target, String propertyName, 4212794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase TypeEvaluator evaluator, Object... values) { 4222794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase ObjectAnimator anim = new ObjectAnimator(target, propertyName); 4232794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setObjectValues(values); 4242794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setEvaluator(evaluator); 4252794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return anim; 4262794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 4272794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 4282794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase /** 429b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between Object values. A single 43016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 431b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 432b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 433b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 4342794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * 435b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param target The object whose property is to be animated. 436b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param property The property being animated. 437b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param evaluator A TypeEvaluator that will be called on each animation frame to 438b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * provide the necessary interpolation between the Object values to derive the animated 439b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * value. 440b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of values that the animation will animate between over time. 441b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 442b39f051631250c49936a475d0e64584afb7f1b93Chet Haase */ 443b39f051631250c49936a475d0e64584afb7f1b93Chet Haase public static <T, V> ObjectAnimator ofObject(T target, Property<T, V> property, 444b39f051631250c49936a475d0e64584afb7f1b93Chet Haase TypeEvaluator<V> evaluator, V... values) { 445b39f051631250c49936a475d0e64584afb7f1b93Chet Haase ObjectAnimator anim = new ObjectAnimator(target, property); 446b39f051631250c49936a475d0e64584afb7f1b93Chet Haase anim.setObjectValues(values); 447b39f051631250c49936a475d0e64584afb7f1b93Chet Haase anim.setEvaluator(evaluator); 448b39f051631250c49936a475d0e64584afb7f1b93Chet Haase return anim; 449b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 450b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 451b39f051631250c49936a475d0e64584afb7f1b93Chet Haase /** 45216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * Constructs and returns an ObjectAnimator that animates between Object values. A single 45316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 45416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * and ending values. More than two values imply a starting value, values to animate through 45516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * along the way, and an ending value (these values will be distributed evenly across 45616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * the duration of the animation). This variant supplies a <code>TypeConverter</code> to 45716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * convert from the animated values to the type of the property. If only one value is 45816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * supplied, the <code>TypeConverter</code> must implement 45916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * {@link TypeConverter#convertBack(Object)} to retrieve the current value. 46016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * 46116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @param target The object whose property is to be animated. 46216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @param property The property being animated. 46316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @param converter Converts the animated object to the Property type. 46416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @param evaluator A TypeEvaluator that will be called on each animation frame to 46516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * provide the necessary interpolation between the Object values to derive the animated 46616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value. 46716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @param values A set of values that the animation will animate between over time. 46816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @return An ObjectAnimator object that is set up to animate between the given values. 46916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount */ 47016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount public static <T, V, P> ObjectAnimator ofObject(T target, Property<T, P> property, 47116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount TypeConverter<V, P> converter, TypeEvaluator<V> evaluator, V... values) { 47216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount PropertyValuesHolder pvh = PropertyValuesHolder.ofObject(property, converter, evaluator, 47316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount values); 47416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount return ofPropertyValuesHolder(target, pvh); 47516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount } 47616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount 47716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount /** 478b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between the sets of values specified 479b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * in <code>PropertyValueHolder</code> objects. This variant should be used when animating 480b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * several properties at once with the same ObjectAnimator, since PropertyValuesHolder allows 481b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * you to associate a set of animation values with a property name. 482b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * 483b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param target The object whose property is to be animated. Depending on how the 484b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * PropertyValuesObjects were constructed, the target object should either have the {@link 485b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * android.util.Property} objects used to construct the PropertyValuesHolder objects or (if the 486b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * PropertyValuesHOlder objects were created with property names) the target object should have 487b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * public methods on it called <code>setName()</code>, where <code>name</code> is the name of 488b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the property passed in as the <code>propertyName</code> parameter for each of the 489b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * PropertyValuesHolder objects. 490b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of PropertyValuesHolder objects whose values will be animated between 491b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * over time. 492b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 4932794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase */ 4942794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public static ObjectAnimator ofPropertyValuesHolder(Object target, 4952794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase PropertyValuesHolder... values) { 4962794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase ObjectAnimator anim = new ObjectAnimator(); 49751ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy anim.mTarget = target; 4982794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setValues(values); 4992794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return anim; 5003dd207a6dbd5d9244dc7fe213d5caa3cddaff0dbChet Haase } 5013dd207a6dbd5d9244dc7fe213d5caa3cddaff0dbChet Haase 50283d6e8213230fb0805aa019d266842253baeb114Romain Guy @Override 5032794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public void setIntValues(int... values) { 50483d6e8213230fb0805aa019d266842253baeb114Romain Guy if (mValues == null || mValues.length == 0) { 50583d6e8213230fb0805aa019d266842253baeb114Romain Guy // No values yet - this animator is being constructed piecemeal. Init the values with 50683d6e8213230fb0805aa019d266842253baeb114Romain Guy // whatever the current propertyName is 507b39f051631250c49936a475d0e64584afb7f1b93Chet Haase if (mProperty != null) { 508b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setValues(PropertyValuesHolder.ofInt(mProperty, values)); 509b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } else { 510b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setValues(PropertyValuesHolder.ofInt(mPropertyName, values)); 511b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 51283d6e8213230fb0805aa019d266842253baeb114Romain Guy } else { 5132794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase super.setIntValues(values); 5142794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 5152794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 5162794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 5172794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase @Override 5182794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public void setFloatValues(float... values) { 5192794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase if (mValues == null || mValues.length == 0) { 5202794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase // No values yet - this animator is being constructed piecemeal. Init the values with 5212794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase // whatever the current propertyName is 522b39f051631250c49936a475d0e64584afb7f1b93Chet Haase if (mProperty != null) { 523b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setValues(PropertyValuesHolder.ofFloat(mProperty, values)); 524b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } else { 525b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setValues(PropertyValuesHolder.ofFloat(mPropertyName, values)); 526b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 5272794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } else { 5282794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase super.setFloatValues(values); 5292794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 5302794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 5312794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 5322794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase @Override 5332794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public void setObjectValues(Object... values) { 5342794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase if (mValues == null || mValues.length == 0) { 5352794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase // No values yet - this animator is being constructed piecemeal. Init the values with 5362794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase // whatever the current propertyName is 537b39f051631250c49936a475d0e64584afb7f1b93Chet Haase if (mProperty != null) { 538be19e030a14c8e398e8af97fa898ea80187704dfChet Haase setValues(PropertyValuesHolder.ofObject(mProperty, (TypeEvaluator) null, values)); 539b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } else { 540be19e030a14c8e398e8af97fa898ea80187704dfChet Haase setValues(PropertyValuesHolder.ofObject(mPropertyName, 541be19e030a14c8e398e8af97fa898ea80187704dfChet Haase (TypeEvaluator) null, values)); 542b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 5432794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } else { 5442794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase super.setObjectValues(values); 54583d6e8213230fb0805aa019d266842253baeb114Romain Guy } 5460e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase } 54783d6e8213230fb0805aa019d266842253baeb114Romain Guy 548be19e030a14c8e398e8af97fa898ea80187704dfChet Haase /** 549be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * autoCancel controls whether an ObjectAnimator will be canceled automatically 550be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * when any other ObjectAnimator with the same target and properties is started. 551be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * Setting this flag may make it easier to run different animators on the same target 552be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * object without having to keep track of whether there are conflicting animators that 553be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * need to be manually canceled. Canceling animators must have the same exact set of 554be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * target properties, in the same order. 555be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * 556be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * @param cancel Whether future ObjectAnimators with the same target and properties 557be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * as this ObjectAnimator will cause this ObjectAnimator to be canceled. 558be19e030a14c8e398e8af97fa898ea80187704dfChet Haase */ 559be19e030a14c8e398e8af97fa898ea80187704dfChet Haase public void setAutoCancel(boolean cancel) { 560be19e030a14c8e398e8af97fa898ea80187704dfChet Haase mAutoCancel = cancel; 561be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 562be19e030a14c8e398e8af97fa898ea80187704dfChet Haase 563be19e030a14c8e398e8af97fa898ea80187704dfChet Haase private boolean hasSameTargetAndProperties(Animator anim) { 564be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (anim instanceof ObjectAnimator) { 565be19e030a14c8e398e8af97fa898ea80187704dfChet Haase PropertyValuesHolder[] theirValues = ((ObjectAnimator) anim).getValues(); 566be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (((ObjectAnimator) anim).getTarget() == mTarget && 567be19e030a14c8e398e8af97fa898ea80187704dfChet Haase mValues.length == theirValues.length) { 568be19e030a14c8e398e8af97fa898ea80187704dfChet Haase for (int i = 0; i < mValues.length; ++i) { 569be19e030a14c8e398e8af97fa898ea80187704dfChet Haase PropertyValuesHolder pvhMine = mValues[i]; 570be19e030a14c8e398e8af97fa898ea80187704dfChet Haase PropertyValuesHolder pvhTheirs = theirValues[i]; 571be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (pvhMine.getPropertyName() == null || 572be19e030a14c8e398e8af97fa898ea80187704dfChet Haase !pvhMine.getPropertyName().equals(pvhTheirs.getPropertyName())) { 573be19e030a14c8e398e8af97fa898ea80187704dfChet Haase return false; 574be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 575be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 576be19e030a14c8e398e8af97fa898ea80187704dfChet Haase return true; 577be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 578be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 579be19e030a14c8e398e8af97fa898ea80187704dfChet Haase return false; 580be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 581be19e030a14c8e398e8af97fa898ea80187704dfChet Haase 582e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase @Override 583e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase public void start() { 584be19e030a14c8e398e8af97fa898ea80187704dfChet Haase // See if any of the current active/pending animators need to be canceled 585be19e030a14c8e398e8af97fa898ea80187704dfChet Haase AnimationHandler handler = sAnimationHandler.get(); 586be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (handler != null) { 587be19e030a14c8e398e8af97fa898ea80187704dfChet Haase int numAnims = handler.mAnimations.size(); 588be19e030a14c8e398e8af97fa898ea80187704dfChet Haase for (int i = numAnims - 1; i >= 0; i--) { 589be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (handler.mAnimations.get(i) instanceof ObjectAnimator) { 590be19e030a14c8e398e8af97fa898ea80187704dfChet Haase ObjectAnimator anim = (ObjectAnimator) handler.mAnimations.get(i); 591be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) { 592be19e030a14c8e398e8af97fa898ea80187704dfChet Haase anim.cancel(); 593be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 594be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 595be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 596be19e030a14c8e398e8af97fa898ea80187704dfChet Haase numAnims = handler.mPendingAnimations.size(); 597be19e030a14c8e398e8af97fa898ea80187704dfChet Haase for (int i = numAnims - 1; i >= 0; i--) { 598be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (handler.mPendingAnimations.get(i) instanceof ObjectAnimator) { 599be19e030a14c8e398e8af97fa898ea80187704dfChet Haase ObjectAnimator anim = (ObjectAnimator) handler.mPendingAnimations.get(i); 600be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) { 601be19e030a14c8e398e8af97fa898ea80187704dfChet Haase anim.cancel(); 602be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 603be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 604be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 605be19e030a14c8e398e8af97fa898ea80187704dfChet Haase numAnims = handler.mDelayedAnims.size(); 606be19e030a14c8e398e8af97fa898ea80187704dfChet Haase for (int i = numAnims - 1; i >= 0; i--) { 607be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (handler.mDelayedAnims.get(i) instanceof ObjectAnimator) { 608be19e030a14c8e398e8af97fa898ea80187704dfChet Haase ObjectAnimator anim = (ObjectAnimator) handler.mDelayedAnims.get(i); 609be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) { 610be19e030a14c8e398e8af97fa898ea80187704dfChet Haase anim.cancel(); 611be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 612be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 613be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 614be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 615e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase if (DBG) { 6163c4ce72c4d66d9ee041924259f20381b658c1529Chet Haase Log.d("ObjectAnimator", "Anim target, duration: " + mTarget + ", " + getDuration()); 617e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase for (int i = 0; i < mValues.length; ++i) { 618e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase PropertyValuesHolder pvh = mValues[i]; 619e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase ArrayList<Keyframe> keyframes = pvh.mKeyframeSet.mKeyframes; 620e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase Log.d("ObjectAnimator", " Values[" + i + "]: " + 621e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase pvh.getPropertyName() + ", " + keyframes.get(0).getValue() + ", " + 622e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase keyframes.get(pvh.mKeyframeSet.mNumKeyframes - 1).getValue()); 623e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase } 624e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase } 625e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase super.start(); 626e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase } 627e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase 6283dd207a6dbd5d9244dc7fe213d5caa3cddaff0dbChet Haase /** 62917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * This function is called immediately before processing the first animation 63017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * frame of an animation. If there is a nonzero <code>startDelay</code>, the 63117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * function is called after that delay ends. 63217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * It takes care of the final initialization steps for the 63317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * animation. This includes setting mEvaluator, if the user has not yet 63417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * set it up, and the setter/getter methods, if the user did not supply 63517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * them. 63617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 63717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <p>Overriders of this method should call the superclass method to cause 63817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * internal mechanisms to be set up correctly.</p> 63917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 64017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase @Override 64117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase void initAnimation() { 64221cd1389d2ef218b20994b617c57af120841a57fChet Haase if (!mInitialized) { 64321cd1389d2ef218b20994b617c57af120841a57fChet Haase // mValueType may change due to setter/getter setup; do this before calling super.init(), 64421cd1389d2ef218b20994b617c57af120841a57fChet Haase // which uses mValueType to set up the default type evaluator. 64521cd1389d2ef218b20994b617c57af120841a57fChet Haase int numValues = mValues.length; 64621cd1389d2ef218b20994b617c57af120841a57fChet Haase for (int i = 0; i < numValues; ++i) { 64751ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy mValues[i].setupSetterAndGetter(mTarget); 64821cd1389d2ef218b20994b617c57af120841a57fChet Haase } 64921cd1389d2ef218b20994b617c57af120841a57fChet Haase super.initAnimation(); 65017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 65117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 65217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 6532794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase /** 6542794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * Sets the length of the animation. The default duration is 300 milliseconds. 6552794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * 6562794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param duration The length of the animation, in milliseconds. 6572794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @return ObjectAnimator The object called with setDuration(). This return 6582794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * value makes it easier to compose statements together that construct and then set the 6592794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * duration, as in 6602794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * <code>ObjectAnimator.ofInt(target, propertyName, 0, 10).setDuration(500).start()</code>. 6612794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase */ 6622794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase @Override 6632794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public ObjectAnimator setDuration(long duration) { 6642794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase super.setDuration(duration); 6652794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return this; 6662794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 6672794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 66817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 66917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 67017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * The target object whose property will be animated by this animation 67117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 67251ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * @return The object being animated 67317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 67417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase public Object getTarget() { 67551ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy return mTarget; 67617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 67717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 67817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 67951ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * Sets the target object whose property will be animated by this animation 680f54a8d7c479485174941c38f151ea7083c658da3Chet Haase * 681f54a8d7c479485174941c38f151ea7083c658da3Chet Haase * @param target The object being animated 682f54a8d7c479485174941c38f151ea7083c658da3Chet Haase */ 68321cd1389d2ef218b20994b617c57af120841a57fChet Haase @Override 684f54a8d7c479485174941c38f151ea7083c658da3Chet Haase public void setTarget(Object target) { 68551ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy if (mTarget != target) { 6867beecfaf3b65a1552a7a7cc78ca00bb04133b507Patrick Dubroy final Object oldTarget = mTarget; 68751ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy mTarget = target; 6887beecfaf3b65a1552a7a7cc78ca00bb04133b507Patrick Dubroy if (oldTarget != null && target != null && oldTarget.getClass() == target.getClass()) { 68970d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase return; 69070d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase } 69170d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase // New target type should cause re-initialization prior to starting 69270d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase mInitialized = false; 69370d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase } 694f54a8d7c479485174941c38f151ea7083c658da3Chet Haase } 695f54a8d7c479485174941c38f151ea7083c658da3Chet Haase 69621cd1389d2ef218b20994b617c57af120841a57fChet Haase @Override 69721cd1389d2ef218b20994b617c57af120841a57fChet Haase public void setupStartValues() { 69821cd1389d2ef218b20994b617c57af120841a57fChet Haase initAnimation(); 69921cd1389d2ef218b20994b617c57af120841a57fChet Haase int numValues = mValues.length; 70021cd1389d2ef218b20994b617c57af120841a57fChet Haase for (int i = 0; i < numValues; ++i) { 70151ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy mValues[i].setupStartValue(mTarget); 70221cd1389d2ef218b20994b617c57af120841a57fChet Haase } 70321cd1389d2ef218b20994b617c57af120841a57fChet Haase } 70421cd1389d2ef218b20994b617c57af120841a57fChet Haase 70521cd1389d2ef218b20994b617c57af120841a57fChet Haase @Override 70621cd1389d2ef218b20994b617c57af120841a57fChet Haase public void setupEndValues() { 70721cd1389d2ef218b20994b617c57af120841a57fChet Haase initAnimation(); 70821cd1389d2ef218b20994b617c57af120841a57fChet Haase int numValues = mValues.length; 70921cd1389d2ef218b20994b617c57af120841a57fChet Haase for (int i = 0; i < numValues; ++i) { 71051ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy mValues[i].setupEndValue(mTarget); 71121cd1389d2ef218b20994b617c57af120841a57fChet Haase } 71221cd1389d2ef218b20994b617c57af120841a57fChet Haase } 71321cd1389d2ef218b20994b617c57af120841a57fChet Haase 714f54a8d7c479485174941c38f151ea7083c658da3Chet Haase /** 71517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * This method is called with the elapsed fraction of the animation during every 71617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * animation frame. This function turns the elapsed fraction into an interpolated fraction 71717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * and then into an animated value (from the evaluator. The function is called mostly during 71817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * animation updates, but it is also called when the <code>end()</code> 71917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * function is called, to set the final value on the property. 72017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 72117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <p>Overrides of this method must call the superclass to perform the calculation 72217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * of the animated value.</p> 72317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 72417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * @param fraction The elapsed fraction of the animation. 72517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 72617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase @Override 72717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase void animateValue(float fraction) { 72817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase super.animateValue(fraction); 729602e4d3824bf8b9cb9f817375d195b969712176aChet Haase int numValues = mValues.length; 730602e4d3824bf8b9cb9f817375d195b969712176aChet Haase for (int i = 0; i < numValues; ++i) { 73151ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy mValues[i].setAnimatedValue(mTarget); 73217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 73317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 73449afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase 73549afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase @Override 736a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public ObjectAnimator clone() { 737a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase final ObjectAnimator anim = (ObjectAnimator) super.clone(); 73849afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase return anim; 73949afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase } 740e9140a72b1059574046a624b471b2c3a35806496Chet Haase 741e9140a72b1059574046a624b471b2c3a35806496Chet Haase @Override 742e9140a72b1059574046a624b471b2c3a35806496Chet Haase public String toString() { 743e9140a72b1059574046a624b471b2c3a35806496Chet Haase String returnVal = "ObjectAnimator@" + Integer.toHexString(hashCode()) + ", target " + 744e9140a72b1059574046a624b471b2c3a35806496Chet Haase mTarget; 745e9140a72b1059574046a624b471b2c3a35806496Chet Haase if (mValues != null) { 746e9140a72b1059574046a624b471b2c3a35806496Chet Haase for (int i = 0; i < mValues.length; ++i) { 747e9140a72b1059574046a624b471b2c3a35806496Chet Haase returnVal += "\n " + mValues[i].toString(); 748e9140a72b1059574046a624b471b2c3a35806496Chet Haase } 749e9140a72b1059574046a624b471b2c3a35806496Chet Haase } 750e9140a72b1059574046a624b471b2c3a35806496Chet Haase return returnVal; 751e9140a72b1059574046a624b471b2c3a35806496Chet Haase } 75217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase} 753