ObjectAnimator.java revision f505b1f08d606688881d56591d018c0d9162d739
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 1987ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viveretteimport android.annotation.NonNull; 2087ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viveretteimport android.annotation.Nullable; 21c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mountimport android.graphics.Path; 22c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mountimport android.graphics.PointF; 2317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haaseimport android.util.Log; 24b39f051631250c49936a475d0e64584afb7f1b93Chet Haaseimport android.util.Property; 2517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 2687ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viveretteimport java.lang.ref.WeakReference; 27e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haaseimport java.util.ArrayList; 2817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 2917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase/** 30a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * This subclass of {@link ValueAnimator} provides support for animating properties on target objects. 3117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * The constructors of this class take parameters to define the target object that will be animated 3217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * as well as the name of the property that will be animated. Appropriate set/get functions 3317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * are then determined internally and the animation will call these functions as necessary to 3417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * animate the property. 356e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * 363aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <div class="special reference"> 373aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <h3>Developer Guides</h3> 383aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <p>For more information about animating with {@code ObjectAnimator}, read the 393aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <a href="{@docRoot}guide/topics/graphics/prop-animation.html#object-animator">Property 403aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * Animation</a> developer guide.</p> 413aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * </div> 423aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * 436e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * @see #setPropertyName(String) 446e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * 4517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 462794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haasepublic final class ObjectAnimator extends ValueAnimator { 4787ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette private static final String LOG_TAG = "ObjectAnimator"; 4887ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette 49e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase private static final boolean DBG = false; 5017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 5187ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette /** 5287ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette * A weak reference to the target object on which the property exists, set 5387ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette * in the constructor. We'll cancel the animation if this goes away. 5487ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette */ 5587ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette private WeakReference<Object> mTarget; 5617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 5717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase private String mPropertyName; 5817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 59b39f051631250c49936a475d0e64584afb7f1b93Chet Haase private Property mProperty; 60b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 61be19e030a14c8e398e8af97fa898ea80187704dfChet Haase private boolean mAutoCancel = false; 62be19e030a14c8e398e8af97fa898ea80187704dfChet Haase 6317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 6417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * Sets the name of the property that will be animated. This name is used to derive 6517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * a setter function that will be called to set animated values. 6617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * For example, a property name of <code>foo</code> will result 6717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * in a call to the function <code>setFoo()</code> on the target object. If either 6817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <code>valueFrom</code> or <code>valueTo</code> is null, then a getter function will 6917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * also be derived and called. 7017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 716e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * <p>For best performance of the mechanism that calls the setter function determined by the 726e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * name of the property being animated, use <code>float</code> or <code>int</code> typed values, 736e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * and make the setter function for those properties have a <code>void</code> return value. This 746e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * will cause the code to take an optimized path for these constrained circumstances. Other 756e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * property types and return types will work, but will have more overhead in processing 766e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * the requests due to normal reflection mechanisms.</p> 776e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * 7817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <p>Note that the setter function derived from this property name 7917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * must take the same parameter type as the 8017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <code>valueFrom</code> and <code>valueTo</code> properties, otherwise the call to 8117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * the setter function will fail.</p> 8217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 83a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * <p>If this ObjectAnimator has been set up to animate several properties together, 84d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase * using more than one PropertyValuesHolder objects, then setting the propertyName simply 85d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase * sets the propertyName in the first of those PropertyValuesHolder objects.</p> 86d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase * 87b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param propertyName The name of the property being animated. Should not be null. 8817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 8987ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette public void setPropertyName(@NonNull String propertyName) { 900e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase // mValues could be null if this is being constructed piecemeal. Just record the 910e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase // propertyName to be used later when setValues() is called if so. 92d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase if (mValues != null) { 93602e4d3824bf8b9cb9f817375d195b969712176aChet Haase PropertyValuesHolder valuesHolder = mValues[0]; 94602e4d3824bf8b9cb9f817375d195b969712176aChet Haase String oldName = valuesHolder.getPropertyName(); 95d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase valuesHolder.setPropertyName(propertyName); 96602e4d3824bf8b9cb9f817375d195b969712176aChet Haase mValuesMap.remove(oldName); 97602e4d3824bf8b9cb9f817375d195b969712176aChet Haase mValuesMap.put(propertyName, valuesHolder); 98d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase } 9917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase mPropertyName = propertyName; 1000e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase // New property/values/target should cause re-initialization prior to starting 1010e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase mInitialized = false; 10217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 10317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 10417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 105b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Sets the property that will be animated. Property objects will take precedence over 106b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * properties specified by the {@link #setPropertyName(String)} method. Animations should 107b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * be set up to use one or the other, not both. 108b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * 109b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param property The property being animated. Should not be null. 110b39f051631250c49936a475d0e64584afb7f1b93Chet Haase */ 11187ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette public void setProperty(@NonNull Property property) { 112b39f051631250c49936a475d0e64584afb7f1b93Chet Haase // mValues could be null if this is being constructed piecemeal. Just record the 113b39f051631250c49936a475d0e64584afb7f1b93Chet Haase // propertyName to be used later when setValues() is called if so. 114b39f051631250c49936a475d0e64584afb7f1b93Chet Haase if (mValues != null) { 115b39f051631250c49936a475d0e64584afb7f1b93Chet Haase PropertyValuesHolder valuesHolder = mValues[0]; 116b39f051631250c49936a475d0e64584afb7f1b93Chet Haase String oldName = valuesHolder.getPropertyName(); 117b39f051631250c49936a475d0e64584afb7f1b93Chet Haase valuesHolder.setProperty(property); 118b39f051631250c49936a475d0e64584afb7f1b93Chet Haase mValuesMap.remove(oldName); 119b39f051631250c49936a475d0e64584afb7f1b93Chet Haase mValuesMap.put(mPropertyName, valuesHolder); 120b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 121b39f051631250c49936a475d0e64584afb7f1b93Chet Haase if (mProperty != null) { 122b39f051631250c49936a475d0e64584afb7f1b93Chet Haase mPropertyName = property.getName(); 123b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 124b39f051631250c49936a475d0e64584afb7f1b93Chet Haase mProperty = property; 125b39f051631250c49936a475d0e64584afb7f1b93Chet Haase // New property/values/target should cause re-initialization prior to starting 126b39f051631250c49936a475d0e64584afb7f1b93Chet Haase mInitialized = false; 127b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 128b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 129b39f051631250c49936a475d0e64584afb7f1b93Chet Haase /** 13017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * Gets the name of the property that will be animated. This name will be used to derive 13117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * a setter function that will be called to set animated values. 13217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * For example, a property name of <code>foo</code> will result 13317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * in a call to the function <code>setFoo()</code> on the target object. If either 13417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <code>valueFrom</code> or <code>valueTo</code> is null, then a getter function will 13517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * also be derived and called. 136fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase * 137fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase * <p>If this animator was created with a {@link Property} object instead of the 138fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase * string name of a property, then this method will return the {@link 139fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase * Property#getName() name} of that Property object instead. If this animator was 140fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase * created with one or more {@link PropertyValuesHolder} objects, then this method 141fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase * will return the {@link PropertyValuesHolder#getPropertyName() name} of that 142fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase * object (if there was just one) or a comma-separated list of all of the 143fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase * names (if there are more than one).</p> 14417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 14587ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette @Nullable 14617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase public String getPropertyName() { 147fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase String propertyName = null; 148fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase if (mPropertyName != null) { 149fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase propertyName = mPropertyName; 150fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase } else if (mProperty != null) { 151fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase propertyName = mProperty.getName(); 152fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase } else if (mValues != null && mValues.length > 0) { 153fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase for (int i = 0; i < mValues.length; ++i) { 154fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase if (i == 0) { 155fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase propertyName = ""; 156fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase } else { 157fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase propertyName += ","; 158fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase } 159fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase propertyName += mValues[i].getPropertyName(); 160fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase } 161fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase } 162fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase return propertyName; 163fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase } 164fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase 165fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase @Override 166fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase String getNameForTrace() { 167fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase return "animator:" + getPropertyName(); 16817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 16917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 17017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 171a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * Creates a new ObjectAnimator object. This default constructor is primarily for 172d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase * use internally; the other constructors which take parameters are more generally 173d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase * useful. 174d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase */ 175a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public ObjectAnimator() { 176d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase } 177d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase 178d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase /** 179b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Private utility constructor that initializes the target object and name of the 180b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * property being animated. 181fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase * 18251ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * @param target The object whose property is to be animated. This object should 18351ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * have a public method on it called <code>setName()</code>, where <code>name</code> is 18451ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * the value of the <code>propertyName</code> parameter. 185d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase * @param propertyName The name of the property being animated. 186fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase */ 1872794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase private ObjectAnimator(Object target, String propertyName) { 18887ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette setTarget(target); 189d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase setPropertyName(propertyName); 190fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase } 191fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase 192fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase /** 193b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Private utility constructor that initializes the target object and property being animated. 194b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * 195b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param target The object whose property is to be animated. 196b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param property The property being animated. 197b39f051631250c49936a475d0e64584afb7f1b93Chet Haase */ 198b39f051631250c49936a475d0e64584afb7f1b93Chet Haase private <T> ObjectAnimator(T target, Property<T, ?> property) { 19987ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette setTarget(target); 200b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setProperty(property); 201b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 202b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 203b39f051631250c49936a475d0e64584afb7f1b93Chet Haase /** 2042794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * Constructs and returns an ObjectAnimator that animates between int values. A single 20516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 206b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 207b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 208b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 2092794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * 21051ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * @param target The object whose property is to be animated. This object should 21151ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * have a public method on it called <code>setName()</code>, where <code>name</code> is 21251ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * the value of the <code>propertyName</code> parameter. 2132794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param propertyName The name of the property being animated. 2142794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param values A set of values that the animation will animate between over time. 215b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 2162794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase */ 2172794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public static ObjectAnimator ofInt(Object target, String propertyName, int... values) { 2182794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase ObjectAnimator anim = new ObjectAnimator(target, propertyName); 2192794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setIntValues(values); 2202794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return anim; 2212794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 2222794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 2232794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase /** 224c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * Constructs and returns an ObjectAnimator that animates coordinates along a <code>Path</code> 225c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * using two properties. A <code>Path</code></> animation moves in two dimensions, animating 226c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * coordinates <code>(x, y)</code> together to follow the line. In this variation, the 227c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * coordinates are integers that are set to separate properties designated by 228c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * <code>xPropertyName</code> and <code>yPropertyName</code>. 229c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * 230c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param target The object whose properties are to be animated. This object should 231c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * have public methods on it called <code>setNameX()</code> and 232c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * <code>setNameY</code>, where <code>nameX</code> and <code>nameY</code> 233c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * are the value of <code>xPropertyName</code> and <code>yPropertyName</code> 234c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * parameters, respectively. 235c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param xPropertyName The name of the property for the x coordinate being animated. 236c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param yPropertyName The name of the property for the y coordinate being animated. 237c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param path The <code>Path</code> to animate values along. 238c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @return An ObjectAnimator object that is set up to animate along <code>path</code>. 239c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount */ 240c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount public static ObjectAnimator ofInt(Object target, String xPropertyName, String yPropertyName, 241c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount Path path) { 242c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount Keyframe[][] keyframes = PropertyValuesHolder.createKeyframes(path, true); 243c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount PropertyValuesHolder x = PropertyValuesHolder.ofKeyframe(xPropertyName, keyframes[0]); 244c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount PropertyValuesHolder y = PropertyValuesHolder.ofKeyframe(yPropertyName, keyframes[1]); 245c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount return ofPropertyValuesHolder(target, x, y); 246c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount } 247c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount 248c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount /** 249b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between int values. A single 25016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 251b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 252b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 253b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 254b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * 255b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param target The object whose property is to be animated. 256b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param property The property being animated. 257b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of values that the animation will animate between over time. 258b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 259b39f051631250c49936a475d0e64584afb7f1b93Chet Haase */ 260b39f051631250c49936a475d0e64584afb7f1b93Chet Haase public static <T> ObjectAnimator ofInt(T target, Property<T, Integer> property, int... values) { 261b39f051631250c49936a475d0e64584afb7f1b93Chet Haase ObjectAnimator anim = new ObjectAnimator(target, property); 262b39f051631250c49936a475d0e64584afb7f1b93Chet Haase anim.setIntValues(values); 263b39f051631250c49936a475d0e64584afb7f1b93Chet Haase return anim; 264b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 265b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 266b39f051631250c49936a475d0e64584afb7f1b93Chet Haase /** 267c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * Constructs and returns an ObjectAnimator that animates coordinates along a <code>Path</code> 268c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * using two properties. A <code>Path</code></> animation moves in two dimensions, animating 269c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * coordinates <code>(x, y)</code> together to follow the line. In this variation, the 270c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * coordinates are integers that are set to separate properties, <code>xProperty</code> and 271c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * <code>yProperty</code>. 272c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * 273c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param target The object whose properties are to be animated. 274c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param xProperty The property for the x coordinate being animated. 275c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param yProperty The property for the y coordinate being animated. 276c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param path The <code>Path</code> to animate values along. 277c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @return An ObjectAnimator object that is set up to animate along <code>path</code>. 278c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount */ 279c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount public static <T> ObjectAnimator ofInt(T target, Property<T, Integer> xProperty, 280c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount Property<T, Integer> yProperty, Path path) { 281c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount Keyframe[][] keyframes = PropertyValuesHolder.createKeyframes(path, true); 282c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount PropertyValuesHolder x = PropertyValuesHolder.ofKeyframe(xProperty, keyframes[0]); 283c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount PropertyValuesHolder y = PropertyValuesHolder.ofKeyframe(yProperty, keyframes[1]); 284c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount return ofPropertyValuesHolder(target, x, y); 285c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount } 286c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount 287c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount /** 2884eed52944c0fcb3afa7369aba60fb5c655580286George Mount * Constructs and returns an ObjectAnimator that animates over int values for a multiple 2894eed52944c0fcb3afa7369aba60fb5c655580286George Mount * parameters setter. Only public methods that take only int parameters are supported. 2904eed52944c0fcb3afa7369aba60fb5c655580286George Mount * Each <code>int[]</code> contains a complete set of parameters to the setter method. 2914eed52944c0fcb3afa7369aba60fb5c655580286George Mount * At least two <code>int[]</code> values must be provided, a start and end. More than two 2924eed52944c0fcb3afa7369aba60fb5c655580286George Mount * values imply a starting value, values to animate through along the way, and an ending 2934eed52944c0fcb3afa7369aba60fb5c655580286George Mount * value (these values will be distributed evenly across the duration of the animation). 2944eed52944c0fcb3afa7369aba60fb5c655580286George Mount * 2954eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param target The object whose property is to be animated. This object may 2964eed52944c0fcb3afa7369aba60fb5c655580286George Mount * have a public method on it called <code>setName()</code>, where <code>name</code> is 2974eed52944c0fcb3afa7369aba60fb5c655580286George Mount * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also 2984eed52944c0fcb3afa7369aba60fb5c655580286George Mount * be the case-sensitive complete name of the public setter method. 2994eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param propertyName The name of the property being animated or the name of the setter method. 3004eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param values A set of values that the animation will animate between over time. 3014eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @return An ObjectAnimator object that is set up to animate between the given values. 3024eed52944c0fcb3afa7369aba60fb5c655580286George Mount */ 3034eed52944c0fcb3afa7369aba60fb5c655580286George Mount public static ObjectAnimator ofMultiInt(Object target, String propertyName, int[][] values) { 3044eed52944c0fcb3afa7369aba60fb5c655580286George Mount PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiInt(propertyName, values); 3054eed52944c0fcb3afa7369aba60fb5c655580286George Mount return ofPropertyValuesHolder(target, pvh); 3064eed52944c0fcb3afa7369aba60fb5c655580286George Mount } 3074eed52944c0fcb3afa7369aba60fb5c655580286George Mount 3084eed52944c0fcb3afa7369aba60fb5c655580286George Mount /** 309c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * Constructs and returns an ObjectAnimator that animates the target using a multi-int setter 310c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * along the given <code>Path</code>. A <code>Path</code></> animation moves in two dimensions, 311c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * animating coordinates <code>(x, y)</code> together to follow the line. In this variation, the 312c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * coordinates are integer x and y coordinates used in the first and second parameter of the 313c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * setter, respectively. 314c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * 315c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param target The object whose property is to be animated. This object may 316c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * have a public method on it called <code>setName()</code>, where <code>name</code> is 317c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also 318c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * be the case-sensitive complete name of the public setter method. 319c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param propertyName The name of the property being animated or the name of the setter method. 320c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param path The <code>Path</code> to animate values along. 321c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @return An ObjectAnimator object that is set up to animate along <code>path</code>. 322c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount */ 323c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount public static ObjectAnimator ofMultiInt(Object target, String propertyName, Path path) { 324c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiInt(propertyName, path); 325c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount return ofPropertyValuesHolder(target, pvh); 326c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount } 327c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount 328c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount /** 3294eed52944c0fcb3afa7369aba60fb5c655580286George Mount * Constructs and returns an ObjectAnimator that animates over values for a multiple int 3304eed52944c0fcb3afa7369aba60fb5c655580286George Mount * parameters setter. Only public methods that take only int parameters are supported. 3314eed52944c0fcb3afa7369aba60fb5c655580286George Mount * <p>At least two values must be provided, a start and end. More than two 3324eed52944c0fcb3afa7369aba60fb5c655580286George Mount * values imply a starting value, values to animate through along the way, and an ending 3334eed52944c0fcb3afa7369aba60fb5c655580286George Mount * value (these values will be distributed evenly across the duration of the animation).</p> 3344eed52944c0fcb3afa7369aba60fb5c655580286George Mount * 3354eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param target The object whose property is to be animated. This object may 3364eed52944c0fcb3afa7369aba60fb5c655580286George Mount * have a public method on it called <code>setName()</code>, where <code>name</code> is 3374eed52944c0fcb3afa7369aba60fb5c655580286George Mount * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also 338c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * be the case-sensitive complete name of the public setter method. 3394eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param propertyName The name of the property being animated or the name of the setter method. 3404eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param converter Converts T objects into int parameters for the multi-value setter. 3414eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param evaluator A TypeEvaluator that will be called on each animation frame to 3424eed52944c0fcb3afa7369aba60fb5c655580286George Mount * provide the necessary interpolation between the Object values to derive the animated 3434eed52944c0fcb3afa7369aba60fb5c655580286George Mount * value. 3444eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param values A set of values that the animation will animate between over time. 3454eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @return An ObjectAnimator object that is set up to animate between the given values. 3464eed52944c0fcb3afa7369aba60fb5c655580286George Mount */ 3474eed52944c0fcb3afa7369aba60fb5c655580286George Mount public static <T> ObjectAnimator ofMultiInt(Object target, String propertyName, 3484eed52944c0fcb3afa7369aba60fb5c655580286George Mount TypeConverter<T, int[]> converter, TypeEvaluator<T> evaluator, T... values) { 3494eed52944c0fcb3afa7369aba60fb5c655580286George Mount PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiInt(propertyName, converter, 3504eed52944c0fcb3afa7369aba60fb5c655580286George Mount evaluator, values); 3514eed52944c0fcb3afa7369aba60fb5c655580286George Mount return ObjectAnimator.ofPropertyValuesHolder(target, pvh); 3524eed52944c0fcb3afa7369aba60fb5c655580286George Mount } 3534eed52944c0fcb3afa7369aba60fb5c655580286George Mount 3544eed52944c0fcb3afa7369aba60fb5c655580286George Mount /** 3551ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * Constructs and returns an ObjectAnimator that animates between color values. A single 3561ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * value implies that that value is the one being animated to. Two values imply starting 3571ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * and ending values. More than two values imply a starting value, values to animate through 3581ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * along the way, and an ending value (these values will be distributed evenly across 3591ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * the duration of the animation). 3601ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * 3611ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * @param target The object whose property is to be animated. This object should 3621ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * have a public method on it called <code>setName()</code>, where <code>name</code> is 3631ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * the value of the <code>propertyName</code> parameter. 3641ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * @param propertyName The name of the property being animated. 3651ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * @param values A set of values that the animation will animate between over time. 3661ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * @return An ObjectAnimator object that is set up to animate between the given values. 3671ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount */ 3681ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount public static ObjectAnimator ofArgb(Object target, String propertyName, int... values) { 3691ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount ObjectAnimator animator = ofInt(target, propertyName, values); 3701ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount animator.setEvaluator(ArgbEvaluator.getInstance()); 3711ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount return animator; 3721ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount } 3731ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount 3741ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount /** 3751ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * Constructs and returns an ObjectAnimator that animates between color values. A single 3761ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * value implies that that value is the one being animated to. Two values imply starting 3771ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * and ending values. More than two values imply a starting value, values to animate through 3781ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * along the way, and an ending value (these values will be distributed evenly across 3791ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * the duration of the animation). 3801ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * 3811ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * @param target The object whose property is to be animated. 3821ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * @param property The property being animated. 3831ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * @param values A set of values that the animation will animate between over time. 3841ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount * @return An ObjectAnimator object that is set up to animate between the given values. 3851ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount */ 3861ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount public static <T> ObjectAnimator ofArgb(T target, Property<T, Integer> property, 3871ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount int... values) { 3881ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount ObjectAnimator animator = ofInt(target, property, values); 3891ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount animator.setEvaluator(ArgbEvaluator.getInstance()); 3901ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount return animator; 3911ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount } 3921ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount 3931ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount /** 3942794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * Constructs and returns an ObjectAnimator that animates between float values. A single 39516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 396b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 397b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 398b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 3992794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * 40051ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * @param target The object whose property is to be animated. This object should 40151ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * have a public method on it called <code>setName()</code>, where <code>name</code> is 40251ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * the value of the <code>propertyName</code> parameter. 4032794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param propertyName The name of the property being animated. 4042794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param values A set of values that the animation will animate between over time. 405b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 4062794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase */ 4072794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public static ObjectAnimator ofFloat(Object target, String propertyName, float... values) { 4082794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase ObjectAnimator anim = new ObjectAnimator(target, propertyName); 4092794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setFloatValues(values); 4102794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return anim; 4112794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 4122794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 4132794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase /** 414c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * Constructs and returns an ObjectAnimator that animates coordinates along a <code>Path</code> 415c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * using two properties. A <code>Path</code></> animation moves in two dimensions, animating 416c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * coordinates <code>(x, y)</code> together to follow the line. In this variation, the 417c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * coordinates are floats that are set to separate properties designated by 418c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * <code>xPropertyName</code> and <code>yPropertyName</code>. 419c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * 420c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param target The object whose properties are to be animated. This object should 421c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * have public methods on it called <code>setNameX()</code> and 422c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * <code>setNameY</code>, where <code>nameX</code> and <code>nameY</code> 423c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * are the value of the <code>xPropertyName</code> and <code>yPropertyName</code> 424c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * parameters, respectively. 425c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param xPropertyName The name of the property for the x coordinate being animated. 426c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param yPropertyName The name of the property for the y coordinate being animated. 427c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param path The <code>Path</code> to animate values along. 428c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @return An ObjectAnimator object that is set up to animate along <code>path</code>. 429c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount */ 430c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount public static ObjectAnimator ofFloat(Object target, String xPropertyName, String yPropertyName, 431c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount Path path) { 432c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount Keyframe[][] keyframes = PropertyValuesHolder.createKeyframes(path, false); 433c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount PropertyValuesHolder x = PropertyValuesHolder.ofKeyframe(xPropertyName, keyframes[0]); 434c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount PropertyValuesHolder y = PropertyValuesHolder.ofKeyframe(yPropertyName, keyframes[1]); 435c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount return ofPropertyValuesHolder(target, x, y); 436c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount } 437c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount 438c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount /** 439b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between float values. A single 44016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 441b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 442b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 443b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 444b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * 445b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param target The object whose property is to be animated. 446b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param property The property being animated. 447b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of values that the animation will animate between over time. 448b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 449b39f051631250c49936a475d0e64584afb7f1b93Chet Haase */ 450b39f051631250c49936a475d0e64584afb7f1b93Chet Haase public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> property, 451b39f051631250c49936a475d0e64584afb7f1b93Chet Haase float... values) { 452b39f051631250c49936a475d0e64584afb7f1b93Chet Haase ObjectAnimator anim = new ObjectAnimator(target, property); 453b39f051631250c49936a475d0e64584afb7f1b93Chet Haase anim.setFloatValues(values); 454b39f051631250c49936a475d0e64584afb7f1b93Chet Haase return anim; 455b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 456b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 457b39f051631250c49936a475d0e64584afb7f1b93Chet Haase /** 458c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * Constructs and returns an ObjectAnimator that animates coordinates along a <code>Path</code> 459c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * using two properties. A <code>Path</code></> animation moves in two dimensions, animating 460c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * coordinates <code>(x, y)</code> together to follow the line. In this variation, the 461c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * coordinates are floats that are set to separate properties, <code>xProperty</code> and 462c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * <code>yProperty</code>. 463c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * 464c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param target The object whose properties are to be animated. 465c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param xProperty The property for the x coordinate being animated. 466c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param yProperty The property for the y coordinate being animated. 467c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param path The <code>Path</code> to animate values along. 468c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @return An ObjectAnimator object that is set up to animate along <code>path</code>. 469c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount */ 470c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> xProperty, 471c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount Property<T, Float> yProperty, Path path) { 472f505b1f08d606688881d56591d018c0d9162d739George Mount Keyframe[][] keyframes = PropertyValuesHolder.createKeyframes(path, false); 473f505b1f08d606688881d56591d018c0d9162d739George Mount PropertyValuesHolder x = PropertyValuesHolder.ofKeyframe(xProperty, keyframes[0]); 474f505b1f08d606688881d56591d018c0d9162d739George Mount PropertyValuesHolder y = PropertyValuesHolder.ofKeyframe(yProperty, keyframes[1]); 475f505b1f08d606688881d56591d018c0d9162d739George Mount return ofPropertyValuesHolder(target, x, y); 476c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount } 477c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount 478c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount /** 4794eed52944c0fcb3afa7369aba60fb5c655580286George Mount * Constructs and returns an ObjectAnimator that animates over float values for a multiple 4804eed52944c0fcb3afa7369aba60fb5c655580286George Mount * parameters setter. Only public methods that take only float parameters are supported. 4814eed52944c0fcb3afa7369aba60fb5c655580286George Mount * Each <code>float[]</code> contains a complete set of parameters to the setter method. 4824eed52944c0fcb3afa7369aba60fb5c655580286George Mount * At least two <code>float[]</code> values must be provided, a start and end. More than two 4834eed52944c0fcb3afa7369aba60fb5c655580286George Mount * values imply a starting value, values to animate through along the way, and an ending 4844eed52944c0fcb3afa7369aba60fb5c655580286George Mount * value (these values will be distributed evenly across the duration of the animation). 4854eed52944c0fcb3afa7369aba60fb5c655580286George Mount * 4864eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param target The object whose property is to be animated. This object may 4874eed52944c0fcb3afa7369aba60fb5c655580286George Mount * have a public method on it called <code>setName()</code>, where <code>name</code> is 4884eed52944c0fcb3afa7369aba60fb5c655580286George Mount * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also 489c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * be the case-sensitive complete name of the public setter method. 4904eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param propertyName The name of the property being animated or the name of the setter method. 4914eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param values A set of values that the animation will animate between over time. 4924eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @return An ObjectAnimator object that is set up to animate between the given values. 4934eed52944c0fcb3afa7369aba60fb5c655580286George Mount */ 4944eed52944c0fcb3afa7369aba60fb5c655580286George Mount public static ObjectAnimator ofMultiFloat(Object target, String propertyName, 4954eed52944c0fcb3afa7369aba60fb5c655580286George Mount float[][] values) { 4964eed52944c0fcb3afa7369aba60fb5c655580286George Mount PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiFloat(propertyName, values); 4974eed52944c0fcb3afa7369aba60fb5c655580286George Mount return ofPropertyValuesHolder(target, pvh); 4984eed52944c0fcb3afa7369aba60fb5c655580286George Mount } 4994eed52944c0fcb3afa7369aba60fb5c655580286George Mount 5004eed52944c0fcb3afa7369aba60fb5c655580286George Mount /** 501c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * Constructs and returns an ObjectAnimator that animates the target using a multi-float setter 502c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * along the given <code>Path</code>. A <code>Path</code></> animation moves in two dimensions, 503c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * animating coordinates <code>(x, y)</code> together to follow the line. In this variation, the 504c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * coordinates are float x and y coordinates used in the first and second parameter of the 505c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * setter, respectively. 506c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * 507c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param target The object whose property is to be animated. This object may 508c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * have a public method on it called <code>setName()</code>, where <code>name</code> is 509c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also 510c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * be the case-sensitive complete name of the public setter method. 511c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param propertyName The name of the property being animated or the name of the setter method. 512c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param path The <code>Path</code> to animate values along. 513c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @return An ObjectAnimator object that is set up to animate along <code>path</code>. 514c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount */ 515c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount public static ObjectAnimator ofMultiFloat(Object target, String propertyName, Path path) { 516c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiFloat(propertyName, path); 517c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount return ofPropertyValuesHolder(target, pvh); 518c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount } 519c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount 520c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount /** 5214eed52944c0fcb3afa7369aba60fb5c655580286George Mount * Constructs and returns an ObjectAnimator that animates over values for a multiple float 5224eed52944c0fcb3afa7369aba60fb5c655580286George Mount * parameters setter. Only public methods that take only float parameters are supported. 5234eed52944c0fcb3afa7369aba60fb5c655580286George Mount * <p>At least two values must be provided, a start and end. More than two 5244eed52944c0fcb3afa7369aba60fb5c655580286George Mount * values imply a starting value, values to animate through along the way, and an ending 5254eed52944c0fcb3afa7369aba60fb5c655580286George Mount * value (these values will be distributed evenly across the duration of the animation).</p> 5264eed52944c0fcb3afa7369aba60fb5c655580286George Mount * 5274eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param target The object whose property is to be animated. This object may 5284eed52944c0fcb3afa7369aba60fb5c655580286George Mount * have a public method on it called <code>setName()</code>, where <code>name</code> is 5294eed52944c0fcb3afa7369aba60fb5c655580286George Mount * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also 5304eed52944c0fcb3afa7369aba60fb5c655580286George Mount * be the case-sensitive complete name of the public setter method. 5314eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param propertyName The name of the property being animated or the name of the setter method. 5324eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param converter Converts T objects into float parameters for the multi-value setter. 5334eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param evaluator A TypeEvaluator that will be called on each animation frame to 5344eed52944c0fcb3afa7369aba60fb5c655580286George Mount * provide the necessary interpolation between the Object values to derive the animated 5354eed52944c0fcb3afa7369aba60fb5c655580286George Mount * value. 5364eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @param values A set of values that the animation will animate between over time. 5374eed52944c0fcb3afa7369aba60fb5c655580286George Mount * @return An ObjectAnimator object that is set up to animate between the given values. 5384eed52944c0fcb3afa7369aba60fb5c655580286George Mount */ 5394eed52944c0fcb3afa7369aba60fb5c655580286George Mount public static <T> ObjectAnimator ofMultiFloat(Object target, String propertyName, 5404eed52944c0fcb3afa7369aba60fb5c655580286George Mount TypeConverter<T, float[]> converter, TypeEvaluator<T> evaluator, T... values) { 5414eed52944c0fcb3afa7369aba60fb5c655580286George Mount PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiFloat(propertyName, converter, 5424eed52944c0fcb3afa7369aba60fb5c655580286George Mount evaluator, values); 5434eed52944c0fcb3afa7369aba60fb5c655580286George Mount return ObjectAnimator.ofPropertyValuesHolder(target, pvh); 5444eed52944c0fcb3afa7369aba60fb5c655580286George Mount } 5454eed52944c0fcb3afa7369aba60fb5c655580286George Mount 5464eed52944c0fcb3afa7369aba60fb5c655580286George Mount /** 547b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between Object values. A single 54816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 549b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 550b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 551b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 55217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 55351ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * @param target The object whose property is to be animated. This object should 554b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * have a public method on it called <code>setName()</code>, where <code>name</code> is 555b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the value of the <code>propertyName</code> parameter. 5562794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param propertyName The name of the property being animated. 5572794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param evaluator A TypeEvaluator that will be called on each animation frame to 558b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * provide the necessary interpolation between the Object values to derive the animated 5592794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * value. 560b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of values that the animation will animate between over time. 561b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 562d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase */ 5632794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public static ObjectAnimator ofObject(Object target, String propertyName, 5642794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase TypeEvaluator evaluator, Object... values) { 5652794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase ObjectAnimator anim = new ObjectAnimator(target, propertyName); 5662794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setObjectValues(values); 5672794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setEvaluator(evaluator); 5682794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return anim; 5692794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 5702794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 5712794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase /** 572c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * Constructs and returns an ObjectAnimator that animates a property along a <code>Path</code>. 573c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * A <code>Path</code></> animation moves in two dimensions, animating coordinates 574c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * <code>(x, y)</code> together to follow the line. This variant animates the coordinates 575c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * in a <code>PointF</code> to follow the <code>Path</code>. If the <code>Property</code> 576c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * associated with <code>propertyName</code> uses a type other than <code>PointF</code>, 577c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * <code>converter</code> can be used to change from <code>PointF</code> to the type 578c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * associated with the <code>Property</code>. 579c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * 580c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param target The object whose property is to be animated. This object should 581c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * have a public method on it called <code>setName()</code>, where <code>name</code> is 582c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * the value of the <code>propertyName</code> parameter. 583c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param propertyName The name of the property being animated. 584c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param converter Converts a PointF to the type associated with the setter. May be 585c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * null if conversion is unnecessary. 586c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param path The <code>Path</code> to animate values along. 587c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @return An ObjectAnimator object that is set up to animate along <code>path</code>. 588c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount */ 58987ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette @NonNull 590c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount public static ObjectAnimator ofObject(Object target, String propertyName, 59187ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette @Nullable TypeConverter<PointF, ?> converter, Path path) { 592c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount PropertyValuesHolder pvh = PropertyValuesHolder.ofObject(propertyName, converter, path); 593c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount return ofPropertyValuesHolder(target, pvh); 594c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount } 595c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount 596c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount /** 597b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between Object values. A single 59816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 599b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * and ending values. More than two values imply a starting value, values to animate through 600b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * along the way, and an ending value (these values will be distributed evenly across 601b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the duration of the animation). 6022794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * 603b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param target The object whose property is to be animated. 604b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param property The property being animated. 605b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param evaluator A TypeEvaluator that will be called on each animation frame to 606b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * provide the necessary interpolation between the Object values to derive the animated 607b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * value. 608b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of values that the animation will animate between over time. 609b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 610b39f051631250c49936a475d0e64584afb7f1b93Chet Haase */ 61187ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette @NonNull 612b39f051631250c49936a475d0e64584afb7f1b93Chet Haase public static <T, V> ObjectAnimator ofObject(T target, Property<T, V> property, 613b39f051631250c49936a475d0e64584afb7f1b93Chet Haase TypeEvaluator<V> evaluator, V... values) { 614b39f051631250c49936a475d0e64584afb7f1b93Chet Haase ObjectAnimator anim = new ObjectAnimator(target, property); 615b39f051631250c49936a475d0e64584afb7f1b93Chet Haase anim.setObjectValues(values); 616b39f051631250c49936a475d0e64584afb7f1b93Chet Haase anim.setEvaluator(evaluator); 617b39f051631250c49936a475d0e64584afb7f1b93Chet Haase return anim; 618b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 619b39f051631250c49936a475d0e64584afb7f1b93Chet Haase 620b39f051631250c49936a475d0e64584afb7f1b93Chet Haase /** 62116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * Constructs and returns an ObjectAnimator that animates between Object values. A single 62216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value implies that that value is the one being animated to. Two values imply starting 62316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * and ending values. More than two values imply a starting value, values to animate through 62416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * along the way, and an ending value (these values will be distributed evenly across 62516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * the duration of the animation). This variant supplies a <code>TypeConverter</code> to 62616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * convert from the animated values to the type of the property. If only one value is 62742516d19db936b10874c27e16eeacda041af01f9George Mount * supplied, the <code>TypeConverter</code> must be a 62842516d19db936b10874c27e16eeacda041af01f9George Mount * {@link android.animation.BidirectionalTypeConverter} to retrieve the current value. 62916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * 63016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @param target The object whose property is to be animated. 63116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @param property The property being animated. 63216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @param converter Converts the animated object to the Property type. 63316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @param evaluator A TypeEvaluator that will be called on each animation frame to 63416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * provide the necessary interpolation between the Object values to derive the animated 63516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * value. 63616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @param values A set of values that the animation will animate between over time. 63716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @return An ObjectAnimator object that is set up to animate between the given values. 63816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount */ 63987ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette @NonNull 64016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount public static <T, V, P> ObjectAnimator ofObject(T target, Property<T, P> property, 64116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount TypeConverter<V, P> converter, TypeEvaluator<V> evaluator, V... values) { 64216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount PropertyValuesHolder pvh = PropertyValuesHolder.ofObject(property, converter, evaluator, 64316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount values); 64416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount return ofPropertyValuesHolder(target, pvh); 64516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount } 64616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount 64716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount /** 648c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * Constructs and returns an ObjectAnimator that animates a property along a <code>Path</code>. 649c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * A <code>Path</code></> animation moves in two dimensions, animating coordinates 650c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * <code>(x, y)</code> together to follow the line. This variant animates the coordinates 651c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * in a <code>PointF</code> to follow the <code>Path</code>. If <code>property</code> 652c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * uses a type other than <code>PointF</code>, <code>converter</code> can be used to change 653c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * from <code>PointF</code> to the type associated with the <code>Property</code>. 654c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * 655c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param target The object whose property is to be animated. 656c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param property The property being animated. Should not be null. 657c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param converter Converts a PointF to the type associated with the setter. May be 658c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * null if conversion is unnecessary. 659c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @param path The <code>Path</code> to animate values along. 660c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount * @return An ObjectAnimator object that is set up to animate along <code>path</code>. 661c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount */ 66287ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette @NonNull 66387ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette public static <T, V> ObjectAnimator ofObject(T target, @NonNull Property<T, V> property, 66487ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette @Nullable TypeConverter<PointF, V> converter, Path path) { 665c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount PropertyValuesHolder pvh = PropertyValuesHolder.ofObject(property, converter, path); 666c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount return ofPropertyValuesHolder(target, pvh); 667c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount } 668c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount 669c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount /** 670b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * Constructs and returns an ObjectAnimator that animates between the sets of values specified 671b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * in <code>PropertyValueHolder</code> objects. This variant should be used when animating 672b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * several properties at once with the same ObjectAnimator, since PropertyValuesHolder allows 673b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * you to associate a set of animation values with a property name. 674b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * 675b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param target The object whose property is to be animated. Depending on how the 676b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * PropertyValuesObjects were constructed, the target object should either have the {@link 677b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * android.util.Property} objects used to construct the PropertyValuesHolder objects or (if the 678b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * PropertyValuesHOlder objects were created with property names) the target object should have 679b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * public methods on it called <code>setName()</code>, where <code>name</code> is the name of 680b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * the property passed in as the <code>propertyName</code> parameter for each of the 681b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * PropertyValuesHolder objects. 682b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @param values A set of PropertyValuesHolder objects whose values will be animated between 683b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * over time. 684b39f051631250c49936a475d0e64584afb7f1b93Chet Haase * @return An ObjectAnimator object that is set up to animate between the given values. 6852794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase */ 68687ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette @NonNull 6872794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public static ObjectAnimator ofPropertyValuesHolder(Object target, 6882794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase PropertyValuesHolder... values) { 6892794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase ObjectAnimator anim = new ObjectAnimator(); 69087ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette anim.setTarget(target); 6912794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase anim.setValues(values); 6922794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return anim; 6933dd207a6dbd5d9244dc7fe213d5caa3cddaff0dbChet Haase } 6943dd207a6dbd5d9244dc7fe213d5caa3cddaff0dbChet Haase 69583d6e8213230fb0805aa019d266842253baeb114Romain Guy @Override 6962794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public void setIntValues(int... values) { 69783d6e8213230fb0805aa019d266842253baeb114Romain Guy if (mValues == null || mValues.length == 0) { 69883d6e8213230fb0805aa019d266842253baeb114Romain Guy // No values yet - this animator is being constructed piecemeal. Init the values with 69983d6e8213230fb0805aa019d266842253baeb114Romain Guy // whatever the current propertyName is 700b39f051631250c49936a475d0e64584afb7f1b93Chet Haase if (mProperty != null) { 701b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setValues(PropertyValuesHolder.ofInt(mProperty, values)); 702b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } else { 703b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setValues(PropertyValuesHolder.ofInt(mPropertyName, values)); 704b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 70583d6e8213230fb0805aa019d266842253baeb114Romain Guy } else { 7062794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase super.setIntValues(values); 7072794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 7082794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 7092794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 7102794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase @Override 7112794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public void setFloatValues(float... values) { 7122794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase if (mValues == null || mValues.length == 0) { 7132794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase // No values yet - this animator is being constructed piecemeal. Init the values with 7142794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase // whatever the current propertyName is 715b39f051631250c49936a475d0e64584afb7f1b93Chet Haase if (mProperty != null) { 716b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setValues(PropertyValuesHolder.ofFloat(mProperty, values)); 717b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } else { 718b39f051631250c49936a475d0e64584afb7f1b93Chet Haase setValues(PropertyValuesHolder.ofFloat(mPropertyName, values)); 719b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 7202794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } else { 7212794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase super.setFloatValues(values); 7222794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 7232794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 7242794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 7252794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase @Override 7262794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public void setObjectValues(Object... values) { 7272794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase if (mValues == null || mValues.length == 0) { 7282794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase // No values yet - this animator is being constructed piecemeal. Init the values with 7292794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase // whatever the current propertyName is 730b39f051631250c49936a475d0e64584afb7f1b93Chet Haase if (mProperty != null) { 731be19e030a14c8e398e8af97fa898ea80187704dfChet Haase setValues(PropertyValuesHolder.ofObject(mProperty, (TypeEvaluator) null, values)); 732b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } else { 733be19e030a14c8e398e8af97fa898ea80187704dfChet Haase setValues(PropertyValuesHolder.ofObject(mPropertyName, 734be19e030a14c8e398e8af97fa898ea80187704dfChet Haase (TypeEvaluator) null, values)); 735b39f051631250c49936a475d0e64584afb7f1b93Chet Haase } 7362794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } else { 7372794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase super.setObjectValues(values); 73883d6e8213230fb0805aa019d266842253baeb114Romain Guy } 7390e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase } 74083d6e8213230fb0805aa019d266842253baeb114Romain Guy 741be19e030a14c8e398e8af97fa898ea80187704dfChet Haase /** 742be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * autoCancel controls whether an ObjectAnimator will be canceled automatically 743be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * when any other ObjectAnimator with the same target and properties is started. 744be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * Setting this flag may make it easier to run different animators on the same target 745be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * object without having to keep track of whether there are conflicting animators that 746be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * need to be manually canceled. Canceling animators must have the same exact set of 747be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * target properties, in the same order. 748be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * 749be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * @param cancel Whether future ObjectAnimators with the same target and properties 750be19e030a14c8e398e8af97fa898ea80187704dfChet Haase * as this ObjectAnimator will cause this ObjectAnimator to be canceled. 751be19e030a14c8e398e8af97fa898ea80187704dfChet Haase */ 752be19e030a14c8e398e8af97fa898ea80187704dfChet Haase public void setAutoCancel(boolean cancel) { 753be19e030a14c8e398e8af97fa898ea80187704dfChet Haase mAutoCancel = cancel; 754be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 755be19e030a14c8e398e8af97fa898ea80187704dfChet Haase 75687ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette private boolean hasSameTargetAndProperties(@Nullable Animator anim) { 757be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (anim instanceof ObjectAnimator) { 758be19e030a14c8e398e8af97fa898ea80187704dfChet Haase PropertyValuesHolder[] theirValues = ((ObjectAnimator) anim).getValues(); 75987ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette if (((ObjectAnimator) anim).getTarget() == getTarget() && 760be19e030a14c8e398e8af97fa898ea80187704dfChet Haase mValues.length == theirValues.length) { 761be19e030a14c8e398e8af97fa898ea80187704dfChet Haase for (int i = 0; i < mValues.length; ++i) { 762be19e030a14c8e398e8af97fa898ea80187704dfChet Haase PropertyValuesHolder pvhMine = mValues[i]; 763be19e030a14c8e398e8af97fa898ea80187704dfChet Haase PropertyValuesHolder pvhTheirs = theirValues[i]; 764be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (pvhMine.getPropertyName() == null || 765be19e030a14c8e398e8af97fa898ea80187704dfChet Haase !pvhMine.getPropertyName().equals(pvhTheirs.getPropertyName())) { 766be19e030a14c8e398e8af97fa898ea80187704dfChet Haase return false; 767be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 768be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 769be19e030a14c8e398e8af97fa898ea80187704dfChet Haase return true; 770be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 771be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 772be19e030a14c8e398e8af97fa898ea80187704dfChet Haase return false; 773be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 774be19e030a14c8e398e8af97fa898ea80187704dfChet Haase 775e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase @Override 776e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase public void start() { 777be19e030a14c8e398e8af97fa898ea80187704dfChet Haase // See if any of the current active/pending animators need to be canceled 778be19e030a14c8e398e8af97fa898ea80187704dfChet Haase AnimationHandler handler = sAnimationHandler.get(); 779be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (handler != null) { 780be19e030a14c8e398e8af97fa898ea80187704dfChet Haase int numAnims = handler.mAnimations.size(); 781be19e030a14c8e398e8af97fa898ea80187704dfChet Haase for (int i = numAnims - 1; i >= 0; i--) { 782be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (handler.mAnimations.get(i) instanceof ObjectAnimator) { 783be19e030a14c8e398e8af97fa898ea80187704dfChet Haase ObjectAnimator anim = (ObjectAnimator) handler.mAnimations.get(i); 784be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) { 785be19e030a14c8e398e8af97fa898ea80187704dfChet Haase anim.cancel(); 786be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 787be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 788be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 789be19e030a14c8e398e8af97fa898ea80187704dfChet Haase numAnims = handler.mPendingAnimations.size(); 790be19e030a14c8e398e8af97fa898ea80187704dfChet Haase for (int i = numAnims - 1; i >= 0; i--) { 791be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (handler.mPendingAnimations.get(i) instanceof ObjectAnimator) { 792be19e030a14c8e398e8af97fa898ea80187704dfChet Haase ObjectAnimator anim = (ObjectAnimator) handler.mPendingAnimations.get(i); 793be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) { 794be19e030a14c8e398e8af97fa898ea80187704dfChet Haase anim.cancel(); 795be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 796be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 797be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 798be19e030a14c8e398e8af97fa898ea80187704dfChet Haase numAnims = handler.mDelayedAnims.size(); 799be19e030a14c8e398e8af97fa898ea80187704dfChet Haase for (int i = numAnims - 1; i >= 0; i--) { 800be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (handler.mDelayedAnims.get(i) instanceof ObjectAnimator) { 801be19e030a14c8e398e8af97fa898ea80187704dfChet Haase ObjectAnimator anim = (ObjectAnimator) handler.mDelayedAnims.get(i); 802be19e030a14c8e398e8af97fa898ea80187704dfChet Haase if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) { 803be19e030a14c8e398e8af97fa898ea80187704dfChet Haase anim.cancel(); 804be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 805be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 806be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 807be19e030a14c8e398e8af97fa898ea80187704dfChet Haase } 808e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase if (DBG) { 80987ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette Log.d(LOG_TAG, "Anim target, duration: " + getTarget() + ", " + getDuration()); 810e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase for (int i = 0; i < mValues.length; ++i) { 811e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase PropertyValuesHolder pvh = mValues[i]; 812e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase ArrayList<Keyframe> keyframes = pvh.mKeyframeSet.mKeyframes; 81387ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette Log.d(LOG_TAG, " Values[" + i + "]: " + 814e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase pvh.getPropertyName() + ", " + keyframes.get(0).getValue() + ", " + 815e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase keyframes.get(pvh.mKeyframeSet.mNumKeyframes - 1).getValue()); 816e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase } 817e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase } 818e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase super.start(); 819e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase } 820e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase 8213dd207a6dbd5d9244dc7fe213d5caa3cddaff0dbChet Haase /** 82217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * This function is called immediately before processing the first animation 82317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * frame of an animation. If there is a nonzero <code>startDelay</code>, the 82417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * function is called after that delay ends. 82517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * It takes care of the final initialization steps for the 82617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * animation. This includes setting mEvaluator, if the user has not yet 82717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * set it up, and the setter/getter methods, if the user did not supply 82817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * them. 82917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 83017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <p>Overriders of this method should call the superclass method to cause 83117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * internal mechanisms to be set up correctly.</p> 83217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 83317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase @Override 83417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase void initAnimation() { 83521cd1389d2ef218b20994b617c57af120841a57fChet Haase if (!mInitialized) { 83621cd1389d2ef218b20994b617c57af120841a57fChet Haase // mValueType may change due to setter/getter setup; do this before calling super.init(), 83721cd1389d2ef218b20994b617c57af120841a57fChet Haase // which uses mValueType to set up the default type evaluator. 83887ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette final Object target = getTarget(); 83987ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette if (target != null) { 84087ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette final int numValues = mValues.length; 84187ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette for (int i = 0; i < numValues; ++i) { 84287ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette mValues[i].setupSetterAndGetter(target); 84387ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette } 84421cd1389d2ef218b20994b617c57af120841a57fChet Haase } 84521cd1389d2ef218b20994b617c57af120841a57fChet Haase super.initAnimation(); 84617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 84717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 84817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 8492794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase /** 8502794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * Sets the length of the animation. The default duration is 300 milliseconds. 8512794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * 8522794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @param duration The length of the animation, in milliseconds. 8532794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * @return ObjectAnimator The object called with setDuration(). This return 8542794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * value makes it easier to compose statements together that construct and then set the 8552794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * duration, as in 8562794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase * <code>ObjectAnimator.ofInt(target, propertyName, 0, 10).setDuration(500).start()</code>. 8572794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase */ 8582794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase @Override 85987ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette @NonNull 8602794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase public ObjectAnimator setDuration(long duration) { 8612794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase super.setDuration(duration); 8622794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase return this; 8632794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase } 8642794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase 86517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 86617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 86717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * The target object whose property will be animated by this animation 86817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 86951ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * @return The object being animated 87017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 87187ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette @Nullable 87217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase public Object getTarget() { 87387ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette return mTarget == null ? null : mTarget.get(); 87417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 87517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase 87617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase /** 87751ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy * Sets the target object whose property will be animated by this animation 878f54a8d7c479485174941c38f151ea7083c658da3Chet Haase * 879f54a8d7c479485174941c38f151ea7083c658da3Chet Haase * @param target The object being animated 880f54a8d7c479485174941c38f151ea7083c658da3Chet Haase */ 88121cd1389d2ef218b20994b617c57af120841a57fChet Haase @Override 88287ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette public void setTarget(@Nullable Object target) { 88387ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette final Object oldTarget = getTarget(); 88487ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette if (oldTarget != target) { 88587ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette mTarget = target == null ? null : new WeakReference<Object>(target); 8867beecfaf3b65a1552a7a7cc78ca00bb04133b507Patrick Dubroy if (oldTarget != null && target != null && oldTarget.getClass() == target.getClass()) { 88770d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase return; 88870d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase } 88970d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase // New target type should cause re-initialization prior to starting 89070d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase mInitialized = false; 89170d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase } 892f54a8d7c479485174941c38f151ea7083c658da3Chet Haase } 893f54a8d7c479485174941c38f151ea7083c658da3Chet Haase 89421cd1389d2ef218b20994b617c57af120841a57fChet Haase @Override 89521cd1389d2ef218b20994b617c57af120841a57fChet Haase public void setupStartValues() { 89621cd1389d2ef218b20994b617c57af120841a57fChet Haase initAnimation(); 89787ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette 89887ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette final Object target = getTarget(); 89987ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette if (target != null) { 90087ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette final int numValues = mValues.length; 90187ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette for (int i = 0; i < numValues; ++i) { 90287ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette mValues[i].setupStartValue(target); 90387ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette } 90421cd1389d2ef218b20994b617c57af120841a57fChet Haase } 90521cd1389d2ef218b20994b617c57af120841a57fChet Haase } 90621cd1389d2ef218b20994b617c57af120841a57fChet Haase 90721cd1389d2ef218b20994b617c57af120841a57fChet Haase @Override 90821cd1389d2ef218b20994b617c57af120841a57fChet Haase public void setupEndValues() { 90921cd1389d2ef218b20994b617c57af120841a57fChet Haase initAnimation(); 91087ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette 91187ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette final Object target = getTarget(); 91287ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette if (target != null) { 91387ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette final int numValues = mValues.length; 91487ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette for (int i = 0; i < numValues; ++i) { 91587ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette mValues[i].setupEndValue(target); 91687ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette } 91721cd1389d2ef218b20994b617c57af120841a57fChet Haase } 91821cd1389d2ef218b20994b617c57af120841a57fChet Haase } 91921cd1389d2ef218b20994b617c57af120841a57fChet Haase 920f54a8d7c479485174941c38f151ea7083c658da3Chet Haase /** 92117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * This method is called with the elapsed fraction of the animation during every 92217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * animation frame. This function turns the elapsed fraction into an interpolated fraction 92317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * and then into an animated value (from the evaluator. The function is called mostly during 92417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * animation updates, but it is also called when the <code>end()</code> 92517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * function is called, to set the final value on the property. 92617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 92717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * <p>Overrides of this method must call the superclass to perform the calculation 92817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * of the animated value.</p> 92917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * 93017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * @param fraction The elapsed fraction of the animation. 93117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */ 93217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase @Override 93317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase void animateValue(float fraction) { 93487ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette final Object target = getTarget(); 93587ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette if (mTarget != null && target == null) { 93687ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette // We lost the target reference, cancel and clean up. 93787ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette cancel(); 93887ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette return; 93987ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette } 94087ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette 94117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase super.animateValue(fraction); 942602e4d3824bf8b9cb9f817375d195b969712176aChet Haase int numValues = mValues.length; 943602e4d3824bf8b9cb9f817375d195b969712176aChet Haase for (int i = 0; i < numValues; ++i) { 94487ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette mValues[i].setAnimatedValue(target); 94517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 94617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase } 94749afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase 94849afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase @Override 949a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase public ObjectAnimator clone() { 950a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase final ObjectAnimator anim = (ObjectAnimator) super.clone(); 95149afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase return anim; 95249afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase } 953e9140a72b1059574046a624b471b2c3a35806496Chet Haase 954e9140a72b1059574046a624b471b2c3a35806496Chet Haase @Override 95587ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette @NonNull 956e9140a72b1059574046a624b471b2c3a35806496Chet Haase public String toString() { 957e9140a72b1059574046a624b471b2c3a35806496Chet Haase String returnVal = "ObjectAnimator@" + Integer.toHexString(hashCode()) + ", target " + 95887ac5f60e20fba335497aa9dc03b7c29c4b966a2Alan Viverette getTarget(); 959e9140a72b1059574046a624b471b2c3a35806496Chet Haase if (mValues != null) { 960e9140a72b1059574046a624b471b2c3a35806496Chet Haase for (int i = 0; i < mValues.length; ++i) { 961e9140a72b1059574046a624b471b2c3a35806496Chet Haase returnVal += "\n " + mValues[i].toString(); 962e9140a72b1059574046a624b471b2c3a35806496Chet Haase } 963e9140a72b1059574046a624b471b2c3a35806496Chet Haase } 964e9140a72b1059574046a624b471b2c3a35806496Chet Haase return returnVal; 965e9140a72b1059574046a624b471b2c3a35806496Chet Haase } 96617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase} 967