117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase/*
217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * Copyright (C) 2010 The Android Open Source Project
317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase *
417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * Licensed under the Apache License, Version 2.0 (the "License");
517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * you may not use this file except in compliance with the License.
617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * You may obtain a copy of the License at
717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase *
817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase *      http://www.apache.org/licenses/LICENSE-2.0
917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase *
1017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * Unless required by applicable law or agreed to in writing, software
1117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * distributed under the License is distributed on an "AS IS" BASIS,
1217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * See the License for the specific language governing permissions and
1417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * limitations under the License.
1517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */
1617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
1717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haasepackage android.animation;
1817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
1917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haaseimport android.util.Log;
20b39f051631250c49936a475d0e64584afb7f1b93Chet Haaseimport android.util.Property;
2117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
2217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haaseimport java.lang.reflect.Method;
23e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haaseimport java.util.ArrayList;
2417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
2517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase/**
26a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * This subclass of {@link ValueAnimator} provides support for animating properties on target objects.
2717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * The constructors of this class take parameters to define the target object that will be animated
2817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * as well as the name of the property that will be animated. Appropriate set/get functions
2917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * are then determined internally and the animation will call these functions as necessary to
3017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * animate the property.
316e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase *
326e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * @see #setPropertyName(String)
336e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase *
3417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */
352794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haasepublic final class ObjectAnimator extends ValueAnimator {
36e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase    private static final boolean DBG = false;
3717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
3817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    // The target object on which the property exists, set in the constructor
3951ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy    private Object mTarget;
4017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
4117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    private String mPropertyName;
4217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
43b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    private Property mProperty;
44b39f051631250c49936a475d0e64584afb7f1b93Chet Haase
4517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    /**
4617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * Sets the name of the property that will be animated. This name is used to derive
4717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * a setter function that will be called to set animated values.
4817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * For example, a property name of <code>foo</code> will result
4917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * in a call to the function <code>setFoo()</code> on the target object. If either
5017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * <code>valueFrom</code> or <code>valueTo</code> is null, then a getter function will
5117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * also be derived and called.
5217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *
536e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase     * <p>For best performance of the mechanism that calls the setter function determined by the
546e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase     * name of the property being animated, use <code>float</code> or <code>int</code> typed values,
556e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase     * and make the setter function for those properties have a <code>void</code> return value. This
566e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase     * will cause the code to take an optimized path for these constrained circumstances. Other
576e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase     * property types and return types will work, but will have more overhead in processing
586e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase     * the requests due to normal reflection mechanisms.</p>
596e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase     *
6017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * <p>Note that the setter function derived from this property name
6117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * must take the same parameter type as the
6217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * <code>valueFrom</code> and <code>valueTo</code> properties, otherwise the call to
6317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * the setter function will fail.</p>
6417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *
65a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase     * <p>If this ObjectAnimator has been set up to animate several properties together,
66d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase     * using more than one PropertyValuesHolder objects, then setting the propertyName simply
67d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase     * sets the propertyName in the first of those PropertyValuesHolder objects.</p>
68d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase     *
69b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param propertyName The name of the property being animated. Should not be null.
7017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     */
7117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    public void setPropertyName(String propertyName) {
720e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase        // mValues could be null if this is being constructed piecemeal. Just record the
730e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase        // propertyName to be used later when setValues() is called if so.
74d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase        if (mValues != null) {
75602e4d3824bf8b9cb9f817375d195b969712176aChet Haase            PropertyValuesHolder valuesHolder = mValues[0];
76602e4d3824bf8b9cb9f817375d195b969712176aChet Haase            String oldName = valuesHolder.getPropertyName();
77d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase            valuesHolder.setPropertyName(propertyName);
78602e4d3824bf8b9cb9f817375d195b969712176aChet Haase            mValuesMap.remove(oldName);
79602e4d3824bf8b9cb9f817375d195b969712176aChet Haase            mValuesMap.put(propertyName, valuesHolder);
80d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase        }
8117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase        mPropertyName = propertyName;
820e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase        // New property/values/target should cause re-initialization prior to starting
830e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase        mInitialized = false;
8417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    }
8517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
8617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    /**
87b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * Sets the property that will be animated. Property objects will take precedence over
88b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * properties specified by the {@link #setPropertyName(String)} method. Animations should
89b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * be set up to use one or the other, not both.
90b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     *
91b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param property The property being animated. Should not be null.
92b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     */
93b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    public void setProperty(Property property) {
94b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        // mValues could be null if this is being constructed piecemeal. Just record the
95b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        // propertyName to be used later when setValues() is called if so.
96b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        if (mValues != null) {
97b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            PropertyValuesHolder valuesHolder = mValues[0];
98b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            String oldName = valuesHolder.getPropertyName();
99b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            valuesHolder.setProperty(property);
100b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            mValuesMap.remove(oldName);
101b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            mValuesMap.put(mPropertyName, valuesHolder);
102b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        }
103b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        if (mProperty != null) {
104b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            mPropertyName = property.getName();
105b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        }
106b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        mProperty = property;
107b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        // New property/values/target should cause re-initialization prior to starting
108b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        mInitialized = false;
109b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    }
110b39f051631250c49936a475d0e64584afb7f1b93Chet Haase
111b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    /**
11217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * Gets the name of the property that will be animated. This name will be used to derive
11317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * a setter function that will be called to set animated values.
11417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * For example, a property name of <code>foo</code> will result
11517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * in a call to the function <code>setFoo()</code> on the target object. If either
11617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * <code>valueFrom</code> or <code>valueTo</code> is null, then a getter function will
11717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * also be derived and called.
11817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     */
11917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    public String getPropertyName() {
12017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase        return mPropertyName;
12117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    }
12217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
12317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    /**
124a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase     * Creates a new ObjectAnimator object. This default constructor is primarily for
125d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase     * use internally; the other constructors which take parameters are more generally
126d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase     * useful.
127d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase     */
128a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase    public ObjectAnimator() {
129d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase    }
130d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase
131d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase    /**
132b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * Private utility constructor that initializes the target object and name of the
133b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * property being animated.
134fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase     *
13551ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * @param target The object whose property is to be animated. This object should
13651ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * have a public method on it called <code>setName()</code>, where <code>name</code> is
13751ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * the value of the <code>propertyName</code> parameter.
138d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase     * @param propertyName The name of the property being animated.
139fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase     */
1402794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    private ObjectAnimator(Object target, String propertyName) {
14151ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy        mTarget = target;
142d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase        setPropertyName(propertyName);
143fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase    }
144fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase
145fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase    /**
146b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * Private utility constructor that initializes the target object and property being animated.
147b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     *
148b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param target The object whose property is to be animated.
149b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param property The property being animated.
150b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     */
151b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    private <T> ObjectAnimator(T target, Property<T, ?> property) {
152b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        mTarget = target;
153b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        setProperty(property);
154b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    }
155b39f051631250c49936a475d0e64584afb7f1b93Chet Haase
156b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    /**
1572794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * Constructs and returns an ObjectAnimator that animates between int values. A single
158b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * value implies that that value is the one being animated to. Two values imply a starting
159b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * and ending values. More than two values imply a starting value, values to animate through
160b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * along the way, and an ending value (these values will be distributed evenly across
161b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * the duration of the animation).
1622794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     *
16351ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * @param target The object whose property is to be animated. This object should
16451ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * have a public method on it called <code>setName()</code>, where <code>name</code> is
16551ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * the value of the <code>propertyName</code> parameter.
1662794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * @param propertyName The name of the property being animated.
1672794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * @param values A set of values that the animation will animate between over time.
168b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @return An ObjectAnimator object that is set up to animate between the given values.
1692794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     */
1702794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    public static ObjectAnimator ofInt(Object target, String propertyName, int... values) {
1712794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        ObjectAnimator anim = new ObjectAnimator(target, propertyName);
1722794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        anim.setIntValues(values);
1732794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        return anim;
1742794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    }
1752794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase
1762794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    /**
177b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * Constructs and returns an ObjectAnimator that animates between int values. A single
178b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * value implies that that value is the one being animated to. Two values imply a starting
179b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * and ending values. More than two values imply a starting value, values to animate through
180b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * along the way, and an ending value (these values will be distributed evenly across
181b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * the duration of the animation).
182b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     *
183b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param target The object whose property is to be animated.
184b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param property The property being animated.
185b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param values A set of values that the animation will animate between over time.
186b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @return An ObjectAnimator object that is set up to animate between the given values.
187b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     */
188b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    public static <T> ObjectAnimator ofInt(T target, Property<T, Integer> property, int... values) {
189b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        ObjectAnimator anim = new ObjectAnimator(target, property);
190b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        anim.setIntValues(values);
191b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        return anim;
192b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    }
193b39f051631250c49936a475d0e64584afb7f1b93Chet Haase
194b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    /**
1952794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * Constructs and returns an ObjectAnimator that animates between float values. A single
196b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * value implies that that value is the one being animated to. Two values imply a starting
197b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * and ending values. More than two values imply a starting value, values to animate through
198b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * along the way, and an ending value (these values will be distributed evenly across
199b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * the duration of the animation).
2002794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     *
20151ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * @param target The object whose property is to be animated. This object should
20251ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * have a public method on it called <code>setName()</code>, where <code>name</code> is
20351ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * the value of the <code>propertyName</code> parameter.
2042794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * @param propertyName The name of the property being animated.
2052794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * @param values A set of values that the animation will animate between over time.
206b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @return An ObjectAnimator object that is set up to animate between the given values.
2072794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     */
2082794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    public static ObjectAnimator ofFloat(Object target, String propertyName, float... values) {
2092794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        ObjectAnimator anim = new ObjectAnimator(target, propertyName);
2102794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        anim.setFloatValues(values);
2112794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        return anim;
2122794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    }
2132794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase
2142794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    /**
215b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * Constructs and returns an ObjectAnimator that animates between float values. A single
216b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * value implies that that value is the one being animated to. Two values imply a starting
217b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * and ending values. More than two values imply a starting value, values to animate through
218b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * along the way, and an ending value (these values will be distributed evenly across
219b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * the duration of the animation).
220b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     *
221b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param target The object whose property is to be animated.
222b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param property The property being animated.
223b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param values A set of values that the animation will animate between over time.
224b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @return An ObjectAnimator object that is set up to animate between the given values.
225b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     */
226b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> property,
227b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            float... values) {
228b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        ObjectAnimator anim = new ObjectAnimator(target, property);
229b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        anim.setFloatValues(values);
230b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        return anim;
231b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    }
232b39f051631250c49936a475d0e64584afb7f1b93Chet Haase
233b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    /**
234b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * Constructs and returns an ObjectAnimator that animates between Object values. A single
235b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * value implies that that value is the one being animated to. Two values imply a starting
236b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * and ending values. More than two values imply a starting value, values to animate through
237b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * along the way, and an ending value (these values will be distributed evenly across
238b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * the duration of the animation).
23917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *
24051ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * @param target The object whose property is to be animated. This object should
241b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * have a public method on it called <code>setName()</code>, where <code>name</code> is
242b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * the value of the <code>propertyName</code> parameter.
2432794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * @param propertyName The name of the property being animated.
2442794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * @param evaluator A TypeEvaluator that will be called on each animation frame to
245b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * provide the necessary interpolation between the Object values to derive the animated
2462794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * value.
247b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param values A set of values that the animation will animate between over time.
248b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @return An ObjectAnimator object that is set up to animate between the given values.
249d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase     */
2502794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    public static ObjectAnimator ofObject(Object target, String propertyName,
2512794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase            TypeEvaluator evaluator, Object... values) {
2522794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        ObjectAnimator anim = new ObjectAnimator(target, propertyName);
2532794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        anim.setObjectValues(values);
2542794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        anim.setEvaluator(evaluator);
2552794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        return anim;
2562794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    }
2572794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase
2582794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    /**
259b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * Constructs and returns an ObjectAnimator that animates between Object values. A single
260b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * value implies that that value is the one being animated to. Two values imply a starting
261b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * and ending values. More than two values imply a starting value, values to animate through
262b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * along the way, and an ending value (these values will be distributed evenly across
263b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * the duration of the animation).
2642794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     *
265b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param target The object whose property is to be animated.
266b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param property The property being animated.
267b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param evaluator A TypeEvaluator that will be called on each animation frame to
268b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * provide the necessary interpolation between the Object values to derive the animated
269b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * value.
270b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param values A set of values that the animation will animate between over time.
271b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @return An ObjectAnimator object that is set up to animate between the given values.
272b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     */
273b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    public static <T, V> ObjectAnimator ofObject(T target, Property<T, V> property,
274b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            TypeEvaluator<V> evaluator, V... values) {
275b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        ObjectAnimator anim = new ObjectAnimator(target, property);
276b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        anim.setObjectValues(values);
277b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        anim.setEvaluator(evaluator);
278b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        return anim;
279b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    }
280b39f051631250c49936a475d0e64584afb7f1b93Chet Haase
281b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    /**
282b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * Constructs and returns an ObjectAnimator that animates between the sets of values specified
283b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * in <code>PropertyValueHolder</code> objects. This variant should be used when animating
284b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * several properties at once with the same ObjectAnimator, since PropertyValuesHolder allows
285b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * you to associate a set of animation values with a property name.
286b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     *
287b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param target The object whose property is to be animated. Depending on how the
288b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * PropertyValuesObjects were constructed, the target object should either have the {@link
289b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * android.util.Property} objects used to construct the PropertyValuesHolder objects or (if the
290b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * PropertyValuesHOlder objects were created with property names) the target object should have
291b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * public methods on it called <code>setName()</code>, where <code>name</code> is the name of
292b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * the property passed in as the <code>propertyName</code> parameter for each of the
293b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * PropertyValuesHolder objects.
294b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param values A set of PropertyValuesHolder objects whose values will be animated between
295b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * over time.
296b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @return An ObjectAnimator object that is set up to animate between the given values.
2972794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     */
2982794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    public static ObjectAnimator ofPropertyValuesHolder(Object target,
2992794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase            PropertyValuesHolder... values) {
3002794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        ObjectAnimator anim = new ObjectAnimator();
30151ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy        anim.mTarget = target;
3022794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        anim.setValues(values);
3032794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        return anim;
3043dd207a6dbd5d9244dc7fe213d5caa3cddaff0dbChet Haase    }
3053dd207a6dbd5d9244dc7fe213d5caa3cddaff0dbChet Haase
30683d6e8213230fb0805aa019d266842253baeb114Romain Guy    @Override
3072794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    public void setIntValues(int... values) {
30883d6e8213230fb0805aa019d266842253baeb114Romain Guy        if (mValues == null || mValues.length == 0) {
30983d6e8213230fb0805aa019d266842253baeb114Romain Guy            // No values yet - this animator is being constructed piecemeal. Init the values with
31083d6e8213230fb0805aa019d266842253baeb114Romain Guy            // whatever the current propertyName is
311b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            if (mProperty != null) {
312b39f051631250c49936a475d0e64584afb7f1b93Chet Haase                setValues(PropertyValuesHolder.ofInt(mProperty, values));
313b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            } else {
314b39f051631250c49936a475d0e64584afb7f1b93Chet Haase                setValues(PropertyValuesHolder.ofInt(mPropertyName, values));
315b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            }
31683d6e8213230fb0805aa019d266842253baeb114Romain Guy        } else {
3172794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase            super.setIntValues(values);
3182794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        }
3192794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    }
3202794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase
3212794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    @Override
3222794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    public void setFloatValues(float... values) {
3232794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        if (mValues == null || mValues.length == 0) {
3242794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase            // No values yet - this animator is being constructed piecemeal. Init the values with
3252794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase            // whatever the current propertyName is
326b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            if (mProperty != null) {
327b39f051631250c49936a475d0e64584afb7f1b93Chet Haase                setValues(PropertyValuesHolder.ofFloat(mProperty, values));
328b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            } else {
329b39f051631250c49936a475d0e64584afb7f1b93Chet Haase                setValues(PropertyValuesHolder.ofFloat(mPropertyName, values));
330b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            }
3312794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        } else {
3322794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase            super.setFloatValues(values);
3332794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        }
3342794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    }
3352794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase
3362794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    @Override
3372794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    public void setObjectValues(Object... values) {
3382794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        if (mValues == null || mValues.length == 0) {
3392794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase            // No values yet - this animator is being constructed piecemeal. Init the values with
3402794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase            // whatever the current propertyName is
341b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            if (mProperty != null) {
342b39f051631250c49936a475d0e64584afb7f1b93Chet Haase                setValues(PropertyValuesHolder.ofObject(mProperty, (TypeEvaluator)null, values));
343b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            } else {
344b39f051631250c49936a475d0e64584afb7f1b93Chet Haase                setValues(PropertyValuesHolder.ofObject(mPropertyName, (TypeEvaluator)null, values));
345b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            }
3462794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        } else {
3472794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase            super.setObjectValues(values);
34883d6e8213230fb0805aa019d266842253baeb114Romain Guy        }
3490e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase    }
35083d6e8213230fb0805aa019d266842253baeb114Romain Guy
351e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase    @Override
352e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase    public void start() {
353e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase        if (DBG) {
3543c4ce72c4d66d9ee041924259f20381b658c1529Chet Haase            Log.d("ObjectAnimator", "Anim target, duration: " + mTarget + ", " + getDuration());
355e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase            for (int i = 0; i < mValues.length; ++i) {
356e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase                PropertyValuesHolder pvh = mValues[i];
357e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase                ArrayList<Keyframe> keyframes = pvh.mKeyframeSet.mKeyframes;
358e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase                Log.d("ObjectAnimator", "   Values[" + i + "]: " +
359e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase                    pvh.getPropertyName() + ", " + keyframes.get(0).getValue() + ", " +
360e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase                    keyframes.get(pvh.mKeyframeSet.mNumKeyframes - 1).getValue());
361e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase            }
362e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase        }
363e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase        super.start();
364e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase    }
365e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase
3663dd207a6dbd5d9244dc7fe213d5caa3cddaff0dbChet Haase    /**
36717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * This function is called immediately before processing the first animation
36817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * frame of an animation. If there is a nonzero <code>startDelay</code>, the
36917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * function is called after that delay ends.
37017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * It takes care of the final initialization steps for the
37117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * animation. This includes setting mEvaluator, if the user has not yet
37217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * set it up, and the setter/getter methods, if the user did not supply
37317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * them.
37417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *
37517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *  <p>Overriders of this method should call the superclass method to cause
37617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *  internal mechanisms to be set up correctly.</p>
37717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     */
37817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    @Override
37917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    void initAnimation() {
38021cd1389d2ef218b20994b617c57af120841a57fChet Haase        if (!mInitialized) {
38121cd1389d2ef218b20994b617c57af120841a57fChet Haase            // mValueType may change due to setter/getter setup; do this before calling super.init(),
38221cd1389d2ef218b20994b617c57af120841a57fChet Haase            // which uses mValueType to set up the default type evaluator.
38321cd1389d2ef218b20994b617c57af120841a57fChet Haase            int numValues = mValues.length;
38421cd1389d2ef218b20994b617c57af120841a57fChet Haase            for (int i = 0; i < numValues; ++i) {
38551ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy                mValues[i].setupSetterAndGetter(mTarget);
38621cd1389d2ef218b20994b617c57af120841a57fChet Haase            }
38721cd1389d2ef218b20994b617c57af120841a57fChet Haase            super.initAnimation();
38817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase        }
38917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    }
39017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
3912794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    /**
3922794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * Sets the length of the animation. The default duration is 300 milliseconds.
3932794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     *
3942794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * @param duration The length of the animation, in milliseconds.
3952794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * @return ObjectAnimator The object called with setDuration(). This return
3962794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * value makes it easier to compose statements together that construct and then set the
3972794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * duration, as in
3982794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * <code>ObjectAnimator.ofInt(target, propertyName, 0, 10).setDuration(500).start()</code>.
3992794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     */
4002794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    @Override
4012794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    public ObjectAnimator setDuration(long duration) {
4022794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        super.setDuration(duration);
4032794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        return this;
4042794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    }
4052794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase
40617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
40717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    /**
40817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * The target object whose property will be animated by this animation
40917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *
41051ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * @return The object being animated
41117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     */
41217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    public Object getTarget() {
41351ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy        return mTarget;
41417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    }
41517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
41617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    /**
41751ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * Sets the target object whose property will be animated by this animation
418f54a8d7c479485174941c38f151ea7083c658da3Chet Haase     *
419f54a8d7c479485174941c38f151ea7083c658da3Chet Haase     * @param target The object being animated
420f54a8d7c479485174941c38f151ea7083c658da3Chet Haase     */
42121cd1389d2ef218b20994b617c57af120841a57fChet Haase    @Override
422f54a8d7c479485174941c38f151ea7083c658da3Chet Haase    public void setTarget(Object target) {
42351ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy        if (mTarget != target) {
4247beecfaf3b65a1552a7a7cc78ca00bb04133b507Patrick Dubroy            final Object oldTarget = mTarget;
42551ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy            mTarget = target;
4267beecfaf3b65a1552a7a7cc78ca00bb04133b507Patrick Dubroy            if (oldTarget != null && target != null && oldTarget.getClass() == target.getClass()) {
42770d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase                return;
42870d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase            }
42970d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase            // New target type should cause re-initialization prior to starting
43070d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase            mInitialized = false;
43170d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase        }
432f54a8d7c479485174941c38f151ea7083c658da3Chet Haase    }
433f54a8d7c479485174941c38f151ea7083c658da3Chet Haase
43421cd1389d2ef218b20994b617c57af120841a57fChet Haase    @Override
43521cd1389d2ef218b20994b617c57af120841a57fChet Haase    public void setupStartValues() {
43621cd1389d2ef218b20994b617c57af120841a57fChet Haase        initAnimation();
43721cd1389d2ef218b20994b617c57af120841a57fChet Haase        int numValues = mValues.length;
43821cd1389d2ef218b20994b617c57af120841a57fChet Haase        for (int i = 0; i < numValues; ++i) {
43951ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy            mValues[i].setupStartValue(mTarget);
44021cd1389d2ef218b20994b617c57af120841a57fChet Haase        }
44121cd1389d2ef218b20994b617c57af120841a57fChet Haase    }
44221cd1389d2ef218b20994b617c57af120841a57fChet Haase
44321cd1389d2ef218b20994b617c57af120841a57fChet Haase    @Override
44421cd1389d2ef218b20994b617c57af120841a57fChet Haase    public void setupEndValues() {
44521cd1389d2ef218b20994b617c57af120841a57fChet Haase        initAnimation();
44621cd1389d2ef218b20994b617c57af120841a57fChet Haase        int numValues = mValues.length;
44721cd1389d2ef218b20994b617c57af120841a57fChet Haase        for (int i = 0; i < numValues; ++i) {
44851ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy            mValues[i].setupEndValue(mTarget);
44921cd1389d2ef218b20994b617c57af120841a57fChet Haase        }
45021cd1389d2ef218b20994b617c57af120841a57fChet Haase    }
45121cd1389d2ef218b20994b617c57af120841a57fChet Haase
452f54a8d7c479485174941c38f151ea7083c658da3Chet Haase    /**
45317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * This method is called with the elapsed fraction of the animation during every
45417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * animation frame. This function turns the elapsed fraction into an interpolated fraction
45517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * and then into an animated value (from the evaluator. The function is called mostly during
45617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * animation updates, but it is also called when the <code>end()</code>
45717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * function is called, to set the final value on the property.
45817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *
45917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * <p>Overrides of this method must call the superclass to perform the calculation
46017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * of the animated value.</p>
46117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *
46217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * @param fraction The elapsed fraction of the animation.
46317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     */
46417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    @Override
46517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    void animateValue(float fraction) {
46617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase        super.animateValue(fraction);
467602e4d3824bf8b9cb9f817375d195b969712176aChet Haase        int numValues = mValues.length;
468602e4d3824bf8b9cb9f817375d195b969712176aChet Haase        for (int i = 0; i < numValues; ++i) {
46951ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy            mValues[i].setAnimatedValue(mTarget);
47017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase        }
47117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    }
47249afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase
47349afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase    @Override
474a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase    public ObjectAnimator clone() {
475a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase        final ObjectAnimator anim = (ObjectAnimator) super.clone();
47649afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase        return anim;
47749afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase    }
478e9140a72b1059574046a624b471b2c3a35806496Chet Haase
479e9140a72b1059574046a624b471b2c3a35806496Chet Haase    @Override
480e9140a72b1059574046a624b471b2c3a35806496Chet Haase    public String toString() {
481e9140a72b1059574046a624b471b2c3a35806496Chet Haase        String returnVal = "ObjectAnimator@" + Integer.toHexString(hashCode()) + ", target " +
482e9140a72b1059574046a624b471b2c3a35806496Chet Haase            mTarget;
483e9140a72b1059574046a624b471b2c3a35806496Chet Haase        if (mValues != null) {
484e9140a72b1059574046a624b471b2c3a35806496Chet Haase            for (int i = 0; i < mValues.length; ++i) {
485e9140a72b1059574046a624b471b2c3a35806496Chet Haase                returnVal += "\n    " + mValues[i].toString();
486e9140a72b1059574046a624b471b2c3a35806496Chet Haase            }
487e9140a72b1059574046a624b471b2c3a35806496Chet Haase        }
488e9140a72b1059574046a624b471b2c3a35806496Chet Haase        return returnVal;
489e9140a72b1059574046a624b471b2c3a35806496Chet Haase    }
49017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase}
491