ObjectAnimator.java revision 42516d19db936b10874c27e16eeacda041af01f9
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
19c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mountimport android.graphics.Path;
20c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mountimport android.graphics.PointF;
2117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haaseimport android.util.Log;
22b39f051631250c49936a475d0e64584afb7f1b93Chet Haaseimport android.util.Property;
2317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
24e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haaseimport java.util.ArrayList;
2517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
2617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase/**
27a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase * This subclass of {@link ValueAnimator} provides support for animating properties on target objects.
2817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * The constructors of this class take parameters to define the target object that will be animated
2917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * as well as the name of the property that will be animated. Appropriate set/get functions
3017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * are then determined internally and the animation will call these functions as necessary to
3117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase * animate the property.
326e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase *
333aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <div class="special reference">
343aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <h3>Developer Guides</h3>
353aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <p>For more information about animating with {@code ObjectAnimator}, read the
363aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * <a href="{@docRoot}guide/topics/graphics/prop-animation.html#object-animator">Property
373aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * Animation</a> developer guide.</p>
383aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez * </div>
393aef8e1d1b2f0b87d470bcccf37ba4ebb6560c45Joe Fernandez *
406e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase * @see #setPropertyName(String)
416e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase *
4217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase */
432794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haasepublic final class ObjectAnimator extends ValueAnimator {
44e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase    private static final boolean DBG = false;
4517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
4617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    // The target object on which the property exists, set in the constructor
4751ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy    private Object mTarget;
4817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
4917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    private String mPropertyName;
5017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
51b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    private Property mProperty;
52b39f051631250c49936a475d0e64584afb7f1b93Chet Haase
53be19e030a14c8e398e8af97fa898ea80187704dfChet Haase    private boolean mAutoCancel = false;
54be19e030a14c8e398e8af97fa898ea80187704dfChet Haase
5517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    /**
5617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * Sets the name of the property that will be animated. This name is used to derive
5717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * a setter function that will be called to set animated values.
5817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * For example, a property name of <code>foo</code> will result
5917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * in a call to the function <code>setFoo()</code> on the target object. If either
6017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * <code>valueFrom</code> or <code>valueTo</code> is null, then a getter function will
6117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * also be derived and called.
6217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *
636e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase     * <p>For best performance of the mechanism that calls the setter function determined by the
646e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase     * name of the property being animated, use <code>float</code> or <code>int</code> typed values,
656e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase     * and make the setter function for those properties have a <code>void</code> return value. This
666e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase     * will cause the code to take an optimized path for these constrained circumstances. Other
676e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase     * property types and return types will work, but will have more overhead in processing
686e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase     * the requests due to normal reflection mechanisms.</p>
696e0ecb4eed5cd2e1f15766d7028467129974a12dChet Haase     *
7017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * <p>Note that the setter function derived from this property name
7117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * must take the same parameter type as the
7217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * <code>valueFrom</code> and <code>valueTo</code> properties, otherwise the call to
7317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * the setter function will fail.</p>
7417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *
75a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase     * <p>If this ObjectAnimator has been set up to animate several properties together,
76d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase     * using more than one PropertyValuesHolder objects, then setting the propertyName simply
77d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase     * sets the propertyName in the first of those PropertyValuesHolder objects.</p>
78d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase     *
79b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param propertyName The name of the property being animated. Should not be null.
8017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     */
8117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    public void setPropertyName(String propertyName) {
820e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase        // mValues could be null if this is being constructed piecemeal. Just record the
830e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase        // propertyName to be used later when setValues() is called if so.
84d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase        if (mValues != null) {
85602e4d3824bf8b9cb9f817375d195b969712176aChet Haase            PropertyValuesHolder valuesHolder = mValues[0];
86602e4d3824bf8b9cb9f817375d195b969712176aChet Haase            String oldName = valuesHolder.getPropertyName();
87d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase            valuesHolder.setPropertyName(propertyName);
88602e4d3824bf8b9cb9f817375d195b969712176aChet Haase            mValuesMap.remove(oldName);
89602e4d3824bf8b9cb9f817375d195b969712176aChet Haase            mValuesMap.put(propertyName, valuesHolder);
90d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase        }
9117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase        mPropertyName = propertyName;
920e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase        // New property/values/target should cause re-initialization prior to starting
930e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase        mInitialized = false;
9417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    }
9517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
9617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    /**
97b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * Sets the property that will be animated. Property objects will take precedence over
98b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * properties specified by the {@link #setPropertyName(String)} method. Animations should
99b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * be set up to use one or the other, not both.
100b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     *
101b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param property The property being animated. Should not be null.
102b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     */
103b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    public void setProperty(Property property) {
104b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        // mValues could be null if this is being constructed piecemeal. Just record the
105b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        // propertyName to be used later when setValues() is called if so.
106b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        if (mValues != null) {
107b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            PropertyValuesHolder valuesHolder = mValues[0];
108b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            String oldName = valuesHolder.getPropertyName();
109b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            valuesHolder.setProperty(property);
110b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            mValuesMap.remove(oldName);
111b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            mValuesMap.put(mPropertyName, valuesHolder);
112b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        }
113b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        if (mProperty != null) {
114b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            mPropertyName = property.getName();
115b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        }
116b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        mProperty = property;
117b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        // New property/values/target should cause re-initialization prior to starting
118b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        mInitialized = false;
119b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    }
120b39f051631250c49936a475d0e64584afb7f1b93Chet Haase
121b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    /**
12217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * Gets the name of the property that will be animated. This name will be used to derive
12317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * a setter function that will be called to set animated values.
12417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * For example, a property name of <code>foo</code> will result
12517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * in a call to the function <code>setFoo()</code> on the target object. If either
12617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * <code>valueFrom</code> or <code>valueTo</code> is null, then a getter function will
12717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * also be derived and called.
128fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase     *
129fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase     * <p>If this animator was created with a {@link Property} object instead of the
130fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase     * string name of a property, then this method will return the {@link
131fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase     * Property#getName() name} of that Property object instead. If this animator was
132fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase     * created with one or more {@link PropertyValuesHolder} objects, then this method
133fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase     * will return the {@link PropertyValuesHolder#getPropertyName() name} of that
134fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase     * object (if there was just one) or a comma-separated list of all of the
135fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase     * names (if there are more than one).</p>
13617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     */
13717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    public String getPropertyName() {
138fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase        String propertyName = null;
139fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase        if (mPropertyName != null) {
140fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase            propertyName = mPropertyName;
141fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase        } else if (mProperty != null) {
142fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase            propertyName = mProperty.getName();
143fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase        } else if (mValues != null && mValues.length > 0) {
144fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase            for (int i = 0; i < mValues.length; ++i) {
145fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase                if (i == 0) {
146fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase                    propertyName = "";
147fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase                } else {
148fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase                    propertyName += ",";
149fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase                }
150fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase                propertyName += mValues[i].getPropertyName();
151fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase            }
152fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase        }
153fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase        return propertyName;
154fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase    }
155fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase
156fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase    @Override
157fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase    String getNameForTrace() {
158fdd3ad7018ebb054c0288b8cd92739703a973181Chet Haase        return "animator:" + getPropertyName();
15917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    }
16017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
16117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    /**
162a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase     * Creates a new ObjectAnimator object. This default constructor is primarily for
163d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase     * use internally; the other constructors which take parameters are more generally
164d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase     * useful.
165d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase     */
166a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase    public ObjectAnimator() {
167d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase    }
168d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase
169d51d368f2d512ab657b8ae45780c82c0dbea94c3Chet Haase    /**
170b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * Private utility constructor that initializes the target object and name of the
171b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * property being animated.
172fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase     *
17351ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * @param target The object whose property is to be animated. This object should
17451ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * have a public method on it called <code>setName()</code>, where <code>name</code> is
17551ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * the value of the <code>propertyName</code> parameter.
176d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase     * @param propertyName The name of the property being animated.
177fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase     */
1782794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    private ObjectAnimator(Object target, String propertyName) {
17951ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy        mTarget = target;
180d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase        setPropertyName(propertyName);
181fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase    }
182fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase
183fe591563f8529305bd52e1f0640e83b9a93d562fChet Haase    /**
184b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * Private utility constructor that initializes the target object and property being animated.
185b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     *
186b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param target The object whose property is to be animated.
187b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param property The property being animated.
188b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     */
189b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    private <T> ObjectAnimator(T target, Property<T, ?> property) {
190b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        mTarget = target;
191b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        setProperty(property);
192b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    }
193b39f051631250c49936a475d0e64584afb7f1b93Chet Haase
194b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    /**
1952794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * Constructs and returns an ObjectAnimator that animates between int values. A single
19616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * value implies that that value is the one being animated to. Two values imply 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 ofInt(Object target, String propertyName, int... values) {
2092794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        ObjectAnimator anim = new ObjectAnimator(target, propertyName);
2102794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        anim.setIntValues(values);
2112794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        return anim;
2122794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    }
2132794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase
2142794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    /**
215c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * Constructs and returns an ObjectAnimator that animates coordinates along a <code>Path</code>
216c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * using two properties. A <code>Path</code></> animation moves in two dimensions, animating
217c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * coordinates <code>(x, y)</code> together to follow the line. In this variation, the
218c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * coordinates are integers that are set to separate properties designated by
219c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * <code>xPropertyName</code> and <code>yPropertyName</code>.
220c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     *
221c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param target The object whose properties are to be animated. This object should
222c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     *               have public methods on it called <code>setNameX()</code> and
223c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     *               <code>setNameY</code>, where <code>nameX</code> and <code>nameY</code>
224c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     *               are the value of <code>xPropertyName</code> and <code>yPropertyName</code>
225c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     *               parameters, respectively.
226c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param xPropertyName The name of the property for the x coordinate being animated.
227c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param yPropertyName The name of the property for the y coordinate being animated.
228c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param path The <code>Path</code> to animate values along.
229c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @return An ObjectAnimator object that is set up to animate along <code>path</code>.
230c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     */
231c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    public static ObjectAnimator ofInt(Object target, String xPropertyName, String yPropertyName,
232c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount            Path path) {
233c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        Keyframe[][] keyframes = PropertyValuesHolder.createKeyframes(path, true);
234c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        PropertyValuesHolder x = PropertyValuesHolder.ofKeyframe(xPropertyName, keyframes[0]);
235c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        PropertyValuesHolder y = PropertyValuesHolder.ofKeyframe(yPropertyName, keyframes[1]);
236c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        return ofPropertyValuesHolder(target, x, y);
237c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    }
238c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount
239c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    /**
240b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * Constructs and returns an ObjectAnimator that animates between int values. A single
24116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * value implies that that value is the one being animated to. Two values imply starting
242b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * and ending values. More than two values imply a starting value, values to animate through
243b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * along the way, and an ending value (these values will be distributed evenly across
244b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * the duration of the animation).
245b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     *
246b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param target The object whose property is to be animated.
247b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param property The property being animated.
248b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param values A set of values that the animation will animate between over time.
249b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @return An ObjectAnimator object that is set up to animate between the given values.
250b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     */
251b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    public static <T> ObjectAnimator ofInt(T target, Property<T, Integer> property, int... values) {
252b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        ObjectAnimator anim = new ObjectAnimator(target, property);
253b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        anim.setIntValues(values);
254b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        return anim;
255b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    }
256b39f051631250c49936a475d0e64584afb7f1b93Chet Haase
257b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    /**
258c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * Constructs and returns an ObjectAnimator that animates coordinates along a <code>Path</code>
259c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * using two properties.  A <code>Path</code></> animation moves in two dimensions, animating
260c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * coordinates <code>(x, y)</code> together to follow the line. In this variation, the
261c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * coordinates are integers that are set to separate properties, <code>xProperty</code> and
262c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * <code>yProperty</code>.
263c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     *
264c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param target The object whose properties are to be animated.
265c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param xProperty The property for the x coordinate being animated.
266c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param yProperty The property for the y coordinate being animated.
267c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param path The <code>Path</code> to animate values along.
268c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @return An ObjectAnimator object that is set up to animate along <code>path</code>.
269c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     */
270c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    public static <T> ObjectAnimator ofInt(T target, Property<T, Integer> xProperty,
271c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount            Property<T, Integer> yProperty, Path path) {
272c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        Keyframe[][] keyframes = PropertyValuesHolder.createKeyframes(path, true);
273c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        PropertyValuesHolder x = PropertyValuesHolder.ofKeyframe(xProperty, keyframes[0]);
274c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        PropertyValuesHolder y = PropertyValuesHolder.ofKeyframe(yProperty, keyframes[1]);
275c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        return ofPropertyValuesHolder(target, x, y);
276c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    }
277c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount
278c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    /**
2794eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * Constructs and returns an ObjectAnimator that animates over int values for a multiple
2804eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * parameters setter. Only public methods that take only int parameters are supported.
2814eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * Each <code>int[]</code> contains a complete set of parameters to the setter method.
2824eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * At least two <code>int[]</code> values must be provided, a start and end. More than two
2834eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * values imply a starting value, values to animate through along the way, and an ending
2844eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * value (these values will be distributed evenly across the duration of the animation).
2854eed52944c0fcb3afa7369aba60fb5c655580286George Mount     *
2864eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @param target The object whose property is to be animated. This object may
2874eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * have a public method on it called <code>setName()</code>, where <code>name</code> is
2884eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also
2894eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * be the case-sensitive complete name of the public setter method.
2904eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @param propertyName The name of the property being animated or the name of the setter method.
2914eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @param values A set of values that the animation will animate between over time.
2924eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @return An ObjectAnimator object that is set up to animate between the given values.
2934eed52944c0fcb3afa7369aba60fb5c655580286George Mount     */
2944eed52944c0fcb3afa7369aba60fb5c655580286George Mount    public static ObjectAnimator ofMultiInt(Object target, String propertyName, int[][] values) {
2954eed52944c0fcb3afa7369aba60fb5c655580286George Mount        PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiInt(propertyName, values);
2964eed52944c0fcb3afa7369aba60fb5c655580286George Mount        return ofPropertyValuesHolder(target, pvh);
2974eed52944c0fcb3afa7369aba60fb5c655580286George Mount    }
2984eed52944c0fcb3afa7369aba60fb5c655580286George Mount
2994eed52944c0fcb3afa7369aba60fb5c655580286George Mount    /**
300c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * Constructs and returns an ObjectAnimator that animates the target using a multi-int setter
301c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * along the given <code>Path</code>. A <code>Path</code></> animation moves in two dimensions,
302c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * animating coordinates <code>(x, y)</code> together to follow the line. In this variation, the
303c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * coordinates are integer x and y coordinates used in the first and second parameter of the
304c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * setter, respectively.
305c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     *
306c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param target The object whose property is to be animated. This object may
307c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * have a public method on it called <code>setName()</code>, where <code>name</code> is
308c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also
309c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * be the case-sensitive complete name of the public setter method.
310c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param propertyName The name of the property being animated or the name of the setter method.
311c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param path The <code>Path</code> to animate values along.
312c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @return An ObjectAnimator object that is set up to animate along <code>path</code>.
313c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     */
314c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    public static ObjectAnimator ofMultiInt(Object target, String propertyName, Path path) {
315c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiInt(propertyName, path);
316c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        return ofPropertyValuesHolder(target, pvh);
317c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    }
318c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount
319c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    /**
3204eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * Constructs and returns an ObjectAnimator that animates over values for a multiple int
3214eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * parameters setter. Only public methods that take only int parameters are supported.
3224eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * <p>At least two values must be provided, a start and end. More than two
3234eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * values imply a starting value, values to animate through along the way, and an ending
3244eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * value (these values will be distributed evenly across the duration of the animation).</p>
3254eed52944c0fcb3afa7369aba60fb5c655580286George Mount     *
3264eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @param target The object whose property is to be animated. This object may
3274eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * have a public method on it called <code>setName()</code>, where <code>name</code> is
3284eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also
329c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * be the case-sensitive complete name of the public setter method.
3304eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @param propertyName The name of the property being animated or the name of the setter method.
3314eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @param converter Converts T objects into int parameters for the multi-value setter.
3324eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @param evaluator A TypeEvaluator that will be called on each animation frame to
3334eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * provide the necessary interpolation between the Object values to derive the animated
3344eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * value.
3354eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @param values A set of values that the animation will animate between over time.
3364eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @return An ObjectAnimator object that is set up to animate between the given values.
3374eed52944c0fcb3afa7369aba60fb5c655580286George Mount     */
3384eed52944c0fcb3afa7369aba60fb5c655580286George Mount    public static <T> ObjectAnimator ofMultiInt(Object target, String propertyName,
3394eed52944c0fcb3afa7369aba60fb5c655580286George Mount            TypeConverter<T, int[]> converter, TypeEvaluator<T> evaluator, T... values) {
3404eed52944c0fcb3afa7369aba60fb5c655580286George Mount        PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiInt(propertyName, converter,
3414eed52944c0fcb3afa7369aba60fb5c655580286George Mount                evaluator, values);
3424eed52944c0fcb3afa7369aba60fb5c655580286George Mount        return ObjectAnimator.ofPropertyValuesHolder(target, pvh);
3434eed52944c0fcb3afa7369aba60fb5c655580286George Mount    }
3444eed52944c0fcb3afa7369aba60fb5c655580286George Mount
3454eed52944c0fcb3afa7369aba60fb5c655580286George Mount    /**
3461ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * Constructs and returns an ObjectAnimator that animates between color values. A single
3471ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * value implies that that value is the one being animated to. Two values imply starting
3481ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * and ending values. More than two values imply a starting value, values to animate through
3491ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * along the way, and an ending value (these values will be distributed evenly across
3501ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * the duration of the animation).
3511ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     *
3521ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * @param target The object whose property is to be animated. This object should
3531ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * have a public method on it called <code>setName()</code>, where <code>name</code> is
3541ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * the value of the <code>propertyName</code> parameter.
3551ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * @param propertyName The name of the property being animated.
3561ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * @param values A set of values that the animation will animate between over time.
3571ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * @return An ObjectAnimator object that is set up to animate between the given values.
3581ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     */
3591ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount    public static ObjectAnimator ofArgb(Object target, String propertyName, int... values) {
3601ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount        ObjectAnimator animator = ofInt(target, propertyName, values);
3611ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount        animator.setEvaluator(ArgbEvaluator.getInstance());
3621ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount        return animator;
3631ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount    }
3641ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount
3651ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount    /**
3661ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * Constructs and returns an ObjectAnimator that animates between color values. A single
3671ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * value implies that that value is the one being animated to. Two values imply starting
3681ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * and ending values. More than two values imply a starting value, values to animate through
3691ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * along the way, and an ending value (these values will be distributed evenly across
3701ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * the duration of the animation).
3711ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     *
3721ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * @param target The object whose property is to be animated.
3731ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * @param property The property being animated.
3741ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * @param values A set of values that the animation will animate between over time.
3751ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     * @return An ObjectAnimator object that is set up to animate between the given values.
3761ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount     */
3771ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount    public static <T> ObjectAnimator ofArgb(T target, Property<T, Integer> property,
3781ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount            int... values) {
3791ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount        ObjectAnimator animator = ofInt(target, property, values);
3801ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount        animator.setEvaluator(ArgbEvaluator.getInstance());
3811ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount        return animator;
3821ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount    }
3831ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount
3841ffb280a7d2c70cc16d709c685f5d31fdb86b5e4George Mount    /**
3852794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * Constructs and returns an ObjectAnimator that animates between float values. A single
38616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * value implies that that value is the one being animated to. Two values imply starting
387b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * and ending values. More than two values imply a starting value, values to animate through
388b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * along the way, and an ending value (these values will be distributed evenly across
389b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * the duration of the animation).
3902794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     *
39151ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * @param target The object whose property is to be animated. This object should
39251ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * have a public method on it called <code>setName()</code>, where <code>name</code> is
39351ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * the value of the <code>propertyName</code> parameter.
3942794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * @param propertyName The name of the property being animated.
3952794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * @param values A set of values that the animation will animate between over time.
396b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @return An ObjectAnimator object that is set up to animate between the given values.
3972794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     */
3982794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    public static ObjectAnimator ofFloat(Object target, String propertyName, float... values) {
3992794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        ObjectAnimator anim = new ObjectAnimator(target, propertyName);
4002794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        anim.setFloatValues(values);
4012794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        return anim;
4022794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    }
4032794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase
4042794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    /**
405c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * Constructs and returns an ObjectAnimator that animates coordinates along a <code>Path</code>
406c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * using two properties. A <code>Path</code></> animation moves in two dimensions, animating
407c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * coordinates <code>(x, y)</code> together to follow the line. In this variation, the
408c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * coordinates are floats that are set to separate properties designated by
409c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * <code>xPropertyName</code> and <code>yPropertyName</code>.
410c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     *
411c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param target The object whose properties are to be animated. This object should
412c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     *               have public methods on it called <code>setNameX()</code> and
413c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     *               <code>setNameY</code>, where <code>nameX</code> and <code>nameY</code>
414c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     *               are the value of the <code>xPropertyName</code> and <code>yPropertyName</code>
415c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     *               parameters, respectively.
416c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param xPropertyName The name of the property for the x coordinate being animated.
417c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param yPropertyName The name of the property for the y coordinate being animated.
418c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param path The <code>Path</code> to animate values along.
419c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @return An ObjectAnimator object that is set up to animate along <code>path</code>.
420c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     */
421c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    public static ObjectAnimator ofFloat(Object target, String xPropertyName, String yPropertyName,
422c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount            Path path) {
423c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        Keyframe[][] keyframes = PropertyValuesHolder.createKeyframes(path, false);
424c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        PropertyValuesHolder x = PropertyValuesHolder.ofKeyframe(xPropertyName, keyframes[0]);
425c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        PropertyValuesHolder y = PropertyValuesHolder.ofKeyframe(yPropertyName, keyframes[1]);
426c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        return ofPropertyValuesHolder(target, x, y);
427c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    }
428c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount
429c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    /**
430b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * Constructs and returns an ObjectAnimator that animates between float values. A single
43116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * value implies that that value is the one being animated to. Two values imply starting
432b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * and ending values. More than two values imply a starting value, values to animate through
433b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * along the way, and an ending value (these values will be distributed evenly across
434b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * the duration of the animation).
435b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     *
436b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param target The object whose property is to be animated.
437b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param property The property being animated.
438b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param values A set of values that the animation will animate between over time.
439b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @return An ObjectAnimator object that is set up to animate between the given values.
440b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     */
441b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> property,
442b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            float... values) {
443b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        ObjectAnimator anim = new ObjectAnimator(target, property);
444b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        anim.setFloatValues(values);
445b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        return anim;
446b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    }
447b39f051631250c49936a475d0e64584afb7f1b93Chet Haase
448b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    /**
449c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * Constructs and returns an ObjectAnimator that animates coordinates along a <code>Path</code>
450c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * using two properties. A <code>Path</code></> animation moves in two dimensions, animating
451c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * coordinates <code>(x, y)</code> together to follow the line. In this variation, the
452c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * coordinates are floats that are set to separate properties, <code>xProperty</code> and
453c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * <code>yProperty</code>.
454c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     *
455c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param target The object whose properties are to be animated.
456c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param xProperty The property for the x coordinate being animated.
457c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param yProperty The property for the y coordinate being animated.
458c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param path The <code>Path</code> to animate values along.
459c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @return An ObjectAnimator object that is set up to animate along <code>path</code>.
460c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     */
461c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    public static <T> ObjectAnimator ofFloat(T target, Property<T, Float> xProperty,
462c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount            Property<T, Float> yProperty, Path path) {
463c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        return ofFloat(target, xProperty.getName(), yProperty.getName(), path);
464c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    }
465c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount
466c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    /**
4674eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * Constructs and returns an ObjectAnimator that animates over float values for a multiple
4684eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * parameters setter. Only public methods that take only float parameters are supported.
4694eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * Each <code>float[]</code> contains a complete set of parameters to the setter method.
4704eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * At least two <code>float[]</code> values must be provided, a start and end. More than two
4714eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * values imply a starting value, values to animate through along the way, and an ending
4724eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * value (these values will be distributed evenly across the duration of the animation).
4734eed52944c0fcb3afa7369aba60fb5c655580286George Mount     *
4744eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @param target The object whose property is to be animated. This object may
4754eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * have a public method on it called <code>setName()</code>, where <code>name</code> is
4764eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also
477c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * be the case-sensitive complete name of the public setter method.
4784eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @param propertyName The name of the property being animated or the name of the setter method.
4794eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @param values A set of values that the animation will animate between over time.
4804eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @return An ObjectAnimator object that is set up to animate between the given values.
4814eed52944c0fcb3afa7369aba60fb5c655580286George Mount     */
4824eed52944c0fcb3afa7369aba60fb5c655580286George Mount    public static ObjectAnimator ofMultiFloat(Object target, String propertyName,
4834eed52944c0fcb3afa7369aba60fb5c655580286George Mount            float[][] values) {
4844eed52944c0fcb3afa7369aba60fb5c655580286George Mount        PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiFloat(propertyName, values);
4854eed52944c0fcb3afa7369aba60fb5c655580286George Mount        return ofPropertyValuesHolder(target, pvh);
4864eed52944c0fcb3afa7369aba60fb5c655580286George Mount    }
4874eed52944c0fcb3afa7369aba60fb5c655580286George Mount
4884eed52944c0fcb3afa7369aba60fb5c655580286George Mount    /**
489c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * Constructs and returns an ObjectAnimator that animates the target using a multi-float setter
490c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * along the given <code>Path</code>. A <code>Path</code></> animation moves in two dimensions,
491c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * animating coordinates <code>(x, y)</code> together to follow the line. In this variation, the
492c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * coordinates are float x and y coordinates used in the first and second parameter of the
493c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * setter, respectively.
494c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     *
495c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param target The object whose property is to be animated. This object may
496c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * have a public method on it called <code>setName()</code>, where <code>name</code> is
497c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also
498c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * be the case-sensitive complete name of the public setter method.
499c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param propertyName The name of the property being animated or the name of the setter method.
500c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param path The <code>Path</code> to animate values along.
501c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @return An ObjectAnimator object that is set up to animate along <code>path</code>.
502c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     */
503c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    public static ObjectAnimator ofMultiFloat(Object target, String propertyName, Path path) {
504c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiFloat(propertyName, path);
505c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        return ofPropertyValuesHolder(target, pvh);
506c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    }
507c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount
508c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    /**
5094eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * Constructs and returns an ObjectAnimator that animates over values for a multiple float
5104eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * parameters setter. Only public methods that take only float parameters are supported.
5114eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * <p>At least two values must be provided, a start and end. More than two
5124eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * values imply a starting value, values to animate through along the way, and an ending
5134eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * value (these values will be distributed evenly across the duration of the animation).</p>
5144eed52944c0fcb3afa7369aba60fb5c655580286George Mount     *
5154eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @param target The object whose property is to be animated. This object may
5164eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * have a public method on it called <code>setName()</code>, where <code>name</code> is
5174eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * the value of the <code>propertyName</code> parameter. <code>propertyName</code> may also
5184eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * be the case-sensitive complete name of the public setter method.
5194eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @param propertyName The name of the property being animated or the name of the setter method.
5204eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @param converter Converts T objects into float parameters for the multi-value setter.
5214eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @param evaluator A TypeEvaluator that will be called on each animation frame to
5224eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * provide the necessary interpolation between the Object values to derive the animated
5234eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * value.
5244eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @param values A set of values that the animation will animate between over time.
5254eed52944c0fcb3afa7369aba60fb5c655580286George Mount     * @return An ObjectAnimator object that is set up to animate between the given values.
5264eed52944c0fcb3afa7369aba60fb5c655580286George Mount     */
5274eed52944c0fcb3afa7369aba60fb5c655580286George Mount    public static <T> ObjectAnimator ofMultiFloat(Object target, String propertyName,
5284eed52944c0fcb3afa7369aba60fb5c655580286George Mount            TypeConverter<T, float[]> converter, TypeEvaluator<T> evaluator, T... values) {
5294eed52944c0fcb3afa7369aba60fb5c655580286George Mount        PropertyValuesHolder pvh = PropertyValuesHolder.ofMultiFloat(propertyName, converter,
5304eed52944c0fcb3afa7369aba60fb5c655580286George Mount                evaluator, values);
5314eed52944c0fcb3afa7369aba60fb5c655580286George Mount        return ObjectAnimator.ofPropertyValuesHolder(target, pvh);
5324eed52944c0fcb3afa7369aba60fb5c655580286George Mount    }
5334eed52944c0fcb3afa7369aba60fb5c655580286George Mount
5344eed52944c0fcb3afa7369aba60fb5c655580286George Mount    /**
535b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * Constructs and returns an ObjectAnimator that animates between Object values. A single
53616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * value implies that that value is the one being animated to. Two values imply starting
537b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * and ending values. More than two values imply a starting value, values to animate through
538b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * along the way, and an ending value (these values will be distributed evenly across
539b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * the duration of the animation).
54017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *
54151ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * @param target The object whose property is to be animated. This object should
542b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * have a public method on it called <code>setName()</code>, where <code>name</code> is
543b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * the value of the <code>propertyName</code> parameter.
5442794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * @param propertyName The name of the property being animated.
5452794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * @param evaluator A TypeEvaluator that will be called on each animation frame to
546b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * provide the necessary interpolation between the Object values to derive the animated
5472794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * value.
548b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param values A set of values that the animation will animate between over time.
549b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @return An ObjectAnimator object that is set up to animate between the given values.
550d953d08e9299072130d9f4411cbcf6678bbce822Chet Haase     */
5512794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    public static ObjectAnimator ofObject(Object target, String propertyName,
5522794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase            TypeEvaluator evaluator, Object... values) {
5532794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        ObjectAnimator anim = new ObjectAnimator(target, propertyName);
5542794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        anim.setObjectValues(values);
5552794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        anim.setEvaluator(evaluator);
5562794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        return anim;
5572794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    }
5582794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase
5592794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    /**
560c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * Constructs and returns an ObjectAnimator that animates a property along a <code>Path</code>.
561c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * A <code>Path</code></> animation moves in two dimensions, animating coordinates
562c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * <code>(x, y)</code> together to follow the line. This variant animates the coordinates
563c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * in a <code>PointF</code> to follow the <code>Path</code>. If the <code>Property</code>
564c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * associated with <code>propertyName</code> uses a type other than <code>PointF</code>,
565c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * <code>converter</code> can be used to change from <code>PointF</code> to the type
566c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * associated with the <code>Property</code>.
567c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     *
568c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param target The object whose property is to be animated. This object should
569c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * have a public method on it called <code>setName()</code>, where <code>name</code> is
570c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * the value of the <code>propertyName</code> parameter.
571c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param propertyName The name of the property being animated.
572c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param converter Converts a PointF to the type associated with the setter. May be
573c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     *                  null if conversion is unnecessary.
574c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param path The <code>Path</code> to animate values along.
575c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @return An ObjectAnimator object that is set up to animate along <code>path</code>.
576c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     */
577c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    public static ObjectAnimator ofObject(Object target, String propertyName,
578c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount            TypeConverter<PointF, ?> converter, Path path) {
579c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        PropertyValuesHolder pvh = PropertyValuesHolder.ofObject(propertyName, converter, path);
580c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        return ofPropertyValuesHolder(target, pvh);
581c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    }
582c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount
583c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    /**
584b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * Constructs and returns an ObjectAnimator that animates between Object values. A single
58516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * value implies that that value is the one being animated to. Two values imply starting
586b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * and ending values. More than two values imply a starting value, values to animate through
587b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * along the way, and an ending value (these values will be distributed evenly across
588b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * the duration of the animation).
5892794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     *
590b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param target The object whose property is to be animated.
591b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param property The property being animated.
592b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param evaluator A TypeEvaluator that will be called on each animation frame to
593b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * provide the necessary interpolation between the Object values to derive the animated
594b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * value.
595b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param values A set of values that the animation will animate between over time.
596b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @return An ObjectAnimator object that is set up to animate between the given values.
597b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     */
598b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    public static <T, V> ObjectAnimator ofObject(T target, Property<T, V> property,
599b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            TypeEvaluator<V> evaluator, V... values) {
600b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        ObjectAnimator anim = new ObjectAnimator(target, property);
601b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        anim.setObjectValues(values);
602b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        anim.setEvaluator(evaluator);
603b39f051631250c49936a475d0e64584afb7f1b93Chet Haase        return anim;
604b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    }
605b39f051631250c49936a475d0e64584afb7f1b93Chet Haase
606b39f051631250c49936a475d0e64584afb7f1b93Chet Haase    /**
60716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * Constructs and returns an ObjectAnimator that animates between Object values. A single
60816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * value implies that that value is the one being animated to. Two values imply starting
60916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * and ending values. More than two values imply a starting value, values to animate through
61016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * along the way, and an ending value (these values will be distributed evenly across
61116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * the duration of the animation). This variant supplies a <code>TypeConverter</code> to
61216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * convert from the animated values to the type of the property. If only one value is
61342516d19db936b10874c27e16eeacda041af01f9George Mount     * supplied, the <code>TypeConverter</code> must be a
61442516d19db936b10874c27e16eeacda041af01f9George Mount     * {@link android.animation.BidirectionalTypeConverter} to retrieve the current value.
61516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     *
61616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * @param target The object whose property is to be animated.
61716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * @param property The property being animated.
61816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * @param converter Converts the animated object to the Property type.
61916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * @param evaluator A TypeEvaluator that will be called on each animation frame to
62016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * provide the necessary interpolation between the Object values to derive the animated
62116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * value.
62216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * @param values A set of values that the animation will animate between over time.
62316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     * @return An ObjectAnimator object that is set up to animate between the given values.
62416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount     */
62516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount    public static <T, V, P> ObjectAnimator ofObject(T target, Property<T, P> property,
62616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount            TypeConverter<V, P> converter, TypeEvaluator<V> evaluator, V... values) {
62716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount        PropertyValuesHolder pvh = PropertyValuesHolder.ofObject(property, converter, evaluator,
62816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount                values);
62916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount        return ofPropertyValuesHolder(target, pvh);
63016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount    }
63116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount
63216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount    /**
633c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * Constructs and returns an ObjectAnimator that animates a property along a <code>Path</code>.
634c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * A <code>Path</code></> animation moves in two dimensions, animating coordinates
635c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * <code>(x, y)</code> together to follow the line. This variant animates the coordinates
636c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * in a <code>PointF</code> to follow the <code>Path</code>. If <code>property</code>
637c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * uses a type other than <code>PointF</code>, <code>converter</code> can be used to change
638c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * from <code>PointF</code> to the type associated with the <code>Property</code>.
639c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     *
640c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param target The object whose property is to be animated.
641c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param property The property being animated. Should not be null.
642c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param converter Converts a PointF to the type associated with the setter. May be
643c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     *                  null if conversion is unnecessary.
644c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @param path The <code>Path</code> to animate values along.
645c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     * @return An ObjectAnimator object that is set up to animate along <code>path</code>.
646c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount     */
647c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    public static <T, V> ObjectAnimator ofObject(T target, Property<T, V> property,
648c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount            TypeConverter<PointF, V> converter, Path path) {
649c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        PropertyValuesHolder pvh = PropertyValuesHolder.ofObject(property, converter, path);
650c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount        return ofPropertyValuesHolder(target, pvh);
651c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    }
652c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount
653c96c7b2e54965e30c8fb82295f1ca9f891ebd5e7George Mount    /**
654b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * Constructs and returns an ObjectAnimator that animates between the sets of values specified
655b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * in <code>PropertyValueHolder</code> objects. This variant should be used when animating
656b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * several properties at once with the same ObjectAnimator, since PropertyValuesHolder allows
657b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * you to associate a set of animation values with a property name.
658b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     *
659b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param target The object whose property is to be animated. Depending on how the
660b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * PropertyValuesObjects were constructed, the target object should either have the {@link
661b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * android.util.Property} objects used to construct the PropertyValuesHolder objects or (if the
662b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * PropertyValuesHOlder objects were created with property names) the target object should have
663b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * public methods on it called <code>setName()</code>, where <code>name</code> is the name of
664b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * the property passed in as the <code>propertyName</code> parameter for each of the
665b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * PropertyValuesHolder objects.
666b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @param values A set of PropertyValuesHolder objects whose values will be animated between
667b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * over time.
668b39f051631250c49936a475d0e64584afb7f1b93Chet Haase     * @return An ObjectAnimator object that is set up to animate between the given values.
6692794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     */
6702794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    public static ObjectAnimator ofPropertyValuesHolder(Object target,
6712794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase            PropertyValuesHolder... values) {
6722794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        ObjectAnimator anim = new ObjectAnimator();
67351ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy        anim.mTarget = target;
6742794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        anim.setValues(values);
6752794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        return anim;
6763dd207a6dbd5d9244dc7fe213d5caa3cddaff0dbChet Haase    }
6773dd207a6dbd5d9244dc7fe213d5caa3cddaff0dbChet Haase
67883d6e8213230fb0805aa019d266842253baeb114Romain Guy    @Override
6792794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    public void setIntValues(int... values) {
68083d6e8213230fb0805aa019d266842253baeb114Romain Guy        if (mValues == null || mValues.length == 0) {
68183d6e8213230fb0805aa019d266842253baeb114Romain Guy            // No values yet - this animator is being constructed piecemeal. Init the values with
68283d6e8213230fb0805aa019d266842253baeb114Romain Guy            // whatever the current propertyName is
683b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            if (mProperty != null) {
684b39f051631250c49936a475d0e64584afb7f1b93Chet Haase                setValues(PropertyValuesHolder.ofInt(mProperty, values));
685b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            } else {
686b39f051631250c49936a475d0e64584afb7f1b93Chet Haase                setValues(PropertyValuesHolder.ofInt(mPropertyName, values));
687b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            }
68883d6e8213230fb0805aa019d266842253baeb114Romain Guy        } else {
6892794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase            super.setIntValues(values);
6902794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        }
6912794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    }
6922794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase
6932794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    @Override
6942794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    public void setFloatValues(float... values) {
6952794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        if (mValues == null || mValues.length == 0) {
6962794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase            // No values yet - this animator is being constructed piecemeal. Init the values with
6972794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase            // whatever the current propertyName is
698b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            if (mProperty != null) {
699b39f051631250c49936a475d0e64584afb7f1b93Chet Haase                setValues(PropertyValuesHolder.ofFloat(mProperty, values));
700b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            } else {
701b39f051631250c49936a475d0e64584afb7f1b93Chet Haase                setValues(PropertyValuesHolder.ofFloat(mPropertyName, values));
702b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            }
7032794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        } else {
7042794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase            super.setFloatValues(values);
7052794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        }
7062794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    }
7072794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase
7082794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    @Override
7092794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    public void setObjectValues(Object... values) {
7102794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        if (mValues == null || mValues.length == 0) {
7112794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase            // No values yet - this animator is being constructed piecemeal. Init the values with
7122794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase            // whatever the current propertyName is
713b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            if (mProperty != null) {
714be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                setValues(PropertyValuesHolder.ofObject(mProperty, (TypeEvaluator) null, values));
715b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            } else {
716be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                setValues(PropertyValuesHolder.ofObject(mPropertyName,
717be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                        (TypeEvaluator) null, values));
718b39f051631250c49936a475d0e64584afb7f1b93Chet Haase            }
7192794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        } else {
7202794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase            super.setObjectValues(values);
72183d6e8213230fb0805aa019d266842253baeb114Romain Guy        }
7220e0590bf3cb32e73f423c0fe39a180d4b3c4343dChet Haase    }
72383d6e8213230fb0805aa019d266842253baeb114Romain Guy
724be19e030a14c8e398e8af97fa898ea80187704dfChet Haase    /**
725be19e030a14c8e398e8af97fa898ea80187704dfChet Haase     * autoCancel controls whether an ObjectAnimator will be canceled automatically
726be19e030a14c8e398e8af97fa898ea80187704dfChet Haase     * when any other ObjectAnimator with the same target and properties is started.
727be19e030a14c8e398e8af97fa898ea80187704dfChet Haase     * Setting this flag may make it easier to run different animators on the same target
728be19e030a14c8e398e8af97fa898ea80187704dfChet Haase     * object without having to keep track of whether there are conflicting animators that
729be19e030a14c8e398e8af97fa898ea80187704dfChet Haase     * need to be manually canceled. Canceling animators must have the same exact set of
730be19e030a14c8e398e8af97fa898ea80187704dfChet Haase     * target properties, in the same order.
731be19e030a14c8e398e8af97fa898ea80187704dfChet Haase     *
732be19e030a14c8e398e8af97fa898ea80187704dfChet Haase     * @param cancel Whether future ObjectAnimators with the same target and properties
733be19e030a14c8e398e8af97fa898ea80187704dfChet Haase     * as this ObjectAnimator will cause this ObjectAnimator to be canceled.
734be19e030a14c8e398e8af97fa898ea80187704dfChet Haase     */
735be19e030a14c8e398e8af97fa898ea80187704dfChet Haase    public void setAutoCancel(boolean cancel) {
736be19e030a14c8e398e8af97fa898ea80187704dfChet Haase        mAutoCancel = cancel;
737be19e030a14c8e398e8af97fa898ea80187704dfChet Haase    }
738be19e030a14c8e398e8af97fa898ea80187704dfChet Haase
739be19e030a14c8e398e8af97fa898ea80187704dfChet Haase    private boolean hasSameTargetAndProperties(Animator anim) {
740be19e030a14c8e398e8af97fa898ea80187704dfChet Haase        if (anim instanceof ObjectAnimator) {
741be19e030a14c8e398e8af97fa898ea80187704dfChet Haase            PropertyValuesHolder[] theirValues = ((ObjectAnimator) anim).getValues();
742be19e030a14c8e398e8af97fa898ea80187704dfChet Haase            if (((ObjectAnimator) anim).getTarget() == mTarget &&
743be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                    mValues.length == theirValues.length) {
744be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                for (int i = 0; i < mValues.length; ++i) {
745be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                    PropertyValuesHolder pvhMine = mValues[i];
746be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                    PropertyValuesHolder pvhTheirs = theirValues[i];
747be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                    if (pvhMine.getPropertyName() == null ||
748be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                            !pvhMine.getPropertyName().equals(pvhTheirs.getPropertyName())) {
749be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                        return false;
750be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                    }
751be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                }
752be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                return true;
753be19e030a14c8e398e8af97fa898ea80187704dfChet Haase            }
754be19e030a14c8e398e8af97fa898ea80187704dfChet Haase        }
755be19e030a14c8e398e8af97fa898ea80187704dfChet Haase        return false;
756be19e030a14c8e398e8af97fa898ea80187704dfChet Haase    }
757be19e030a14c8e398e8af97fa898ea80187704dfChet Haase
758e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase    @Override
759e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase    public void start() {
760be19e030a14c8e398e8af97fa898ea80187704dfChet Haase        // See if any of the current active/pending animators need to be canceled
761be19e030a14c8e398e8af97fa898ea80187704dfChet Haase        AnimationHandler handler = sAnimationHandler.get();
762be19e030a14c8e398e8af97fa898ea80187704dfChet Haase        if (handler != null) {
763be19e030a14c8e398e8af97fa898ea80187704dfChet Haase            int numAnims = handler.mAnimations.size();
764be19e030a14c8e398e8af97fa898ea80187704dfChet Haase            for (int i = numAnims - 1; i >= 0; i--) {
765be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                if (handler.mAnimations.get(i) instanceof ObjectAnimator) {
766be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                    ObjectAnimator anim = (ObjectAnimator) handler.mAnimations.get(i);
767be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                    if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) {
768be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                        anim.cancel();
769be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                    }
770be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                }
771be19e030a14c8e398e8af97fa898ea80187704dfChet Haase            }
772be19e030a14c8e398e8af97fa898ea80187704dfChet Haase            numAnims = handler.mPendingAnimations.size();
773be19e030a14c8e398e8af97fa898ea80187704dfChet Haase            for (int i = numAnims - 1; i >= 0; i--) {
774be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                if (handler.mPendingAnimations.get(i) instanceof ObjectAnimator) {
775be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                    ObjectAnimator anim = (ObjectAnimator) handler.mPendingAnimations.get(i);
776be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                    if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) {
777be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                        anim.cancel();
778be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                    }
779be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                }
780be19e030a14c8e398e8af97fa898ea80187704dfChet Haase            }
781be19e030a14c8e398e8af97fa898ea80187704dfChet Haase            numAnims = handler.mDelayedAnims.size();
782be19e030a14c8e398e8af97fa898ea80187704dfChet Haase            for (int i = numAnims - 1; i >= 0; i--) {
783be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                if (handler.mDelayedAnims.get(i) instanceof ObjectAnimator) {
784be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                    ObjectAnimator anim = (ObjectAnimator) handler.mDelayedAnims.get(i);
785be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                    if (anim.mAutoCancel && hasSameTargetAndProperties(anim)) {
786be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                        anim.cancel();
787be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                    }
788be19e030a14c8e398e8af97fa898ea80187704dfChet Haase                }
789be19e030a14c8e398e8af97fa898ea80187704dfChet Haase            }
790be19e030a14c8e398e8af97fa898ea80187704dfChet Haase        }
791e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase        if (DBG) {
7923c4ce72c4d66d9ee041924259f20381b658c1529Chet Haase            Log.d("ObjectAnimator", "Anim target, duration: " + mTarget + ", " + getDuration());
793e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase            for (int i = 0; i < mValues.length; ++i) {
794e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase                PropertyValuesHolder pvh = mValues[i];
795e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase                ArrayList<Keyframe> keyframes = pvh.mKeyframeSet.mKeyframes;
796e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase                Log.d("ObjectAnimator", "   Values[" + i + "]: " +
797e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase                    pvh.getPropertyName() + ", " + keyframes.get(0).getValue() + ", " +
798e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase                    keyframes.get(pvh.mKeyframeSet.mNumKeyframes - 1).getValue());
799e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase            }
800e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase        }
801e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase        super.start();
802e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase    }
803e2ab7ccd385cdb6517955c719e1d2b49771bedb6Chet Haase
8043dd207a6dbd5d9244dc7fe213d5caa3cddaff0dbChet Haase    /**
80517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * This function is called immediately before processing the first animation
80617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * frame of an animation. If there is a nonzero <code>startDelay</code>, the
80717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * function is called after that delay ends.
80817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * It takes care of the final initialization steps for the
80917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * animation. This includes setting mEvaluator, if the user has not yet
81017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * set it up, and the setter/getter methods, if the user did not supply
81117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * them.
81217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *
81317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *  <p>Overriders of this method should call the superclass method to cause
81417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *  internal mechanisms to be set up correctly.</p>
81517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     */
81617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    @Override
81717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    void initAnimation() {
81821cd1389d2ef218b20994b617c57af120841a57fChet Haase        if (!mInitialized) {
81921cd1389d2ef218b20994b617c57af120841a57fChet Haase            // mValueType may change due to setter/getter setup; do this before calling super.init(),
82021cd1389d2ef218b20994b617c57af120841a57fChet Haase            // which uses mValueType to set up the default type evaluator.
82121cd1389d2ef218b20994b617c57af120841a57fChet Haase            int numValues = mValues.length;
82221cd1389d2ef218b20994b617c57af120841a57fChet Haase            for (int i = 0; i < numValues; ++i) {
82351ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy                mValues[i].setupSetterAndGetter(mTarget);
82421cd1389d2ef218b20994b617c57af120841a57fChet Haase            }
82521cd1389d2ef218b20994b617c57af120841a57fChet Haase            super.initAnimation();
82617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase        }
82717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    }
82817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
8292794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    /**
8302794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * Sets the length of the animation. The default duration is 300 milliseconds.
8312794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     *
8322794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * @param duration The length of the animation, in milliseconds.
8332794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * @return ObjectAnimator The object called with setDuration(). This return
8342794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * value makes it easier to compose statements together that construct and then set the
8352794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * duration, as in
8362794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     * <code>ObjectAnimator.ofInt(target, propertyName, 0, 10).setDuration(500).start()</code>.
8372794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase     */
8382794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    @Override
8392794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    public ObjectAnimator setDuration(long duration) {
8402794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        super.setDuration(duration);
8412794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase        return this;
8422794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase    }
8432794eb3b02e2404d453d3ad22a8a85a138130a07Chet Haase
84417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
84517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    /**
84617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * The target object whose property will be animated by this animation
84717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *
84851ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * @return The object being animated
84917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     */
85017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    public Object getTarget() {
85151ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy        return mTarget;
85217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    }
85317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase
85417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    /**
85551ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy     * Sets the target object whose property will be animated by this animation
856f54a8d7c479485174941c38f151ea7083c658da3Chet Haase     *
857f54a8d7c479485174941c38f151ea7083c658da3Chet Haase     * @param target The object being animated
858f54a8d7c479485174941c38f151ea7083c658da3Chet Haase     */
85921cd1389d2ef218b20994b617c57af120841a57fChet Haase    @Override
860f54a8d7c479485174941c38f151ea7083c658da3Chet Haase    public void setTarget(Object target) {
86151ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy        if (mTarget != target) {
8627beecfaf3b65a1552a7a7cc78ca00bb04133b507Patrick Dubroy            final Object oldTarget = mTarget;
86351ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy            mTarget = target;
8647beecfaf3b65a1552a7a7cc78ca00bb04133b507Patrick Dubroy            if (oldTarget != null && target != null && oldTarget.getClass() == target.getClass()) {
86570d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase                return;
86670d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase            }
86770d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase            // New target type should cause re-initialization prior to starting
86870d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase            mInitialized = false;
86970d4ba15b1f0c1133c5aabc86de828b41e482fffChet Haase        }
870f54a8d7c479485174941c38f151ea7083c658da3Chet Haase    }
871f54a8d7c479485174941c38f151ea7083c658da3Chet Haase
87221cd1389d2ef218b20994b617c57af120841a57fChet Haase    @Override
87321cd1389d2ef218b20994b617c57af120841a57fChet Haase    public void setupStartValues() {
87421cd1389d2ef218b20994b617c57af120841a57fChet Haase        initAnimation();
87521cd1389d2ef218b20994b617c57af120841a57fChet Haase        int numValues = mValues.length;
87621cd1389d2ef218b20994b617c57af120841a57fChet Haase        for (int i = 0; i < numValues; ++i) {
87751ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy            mValues[i].setupStartValue(mTarget);
87821cd1389d2ef218b20994b617c57af120841a57fChet Haase        }
87921cd1389d2ef218b20994b617c57af120841a57fChet Haase    }
88021cd1389d2ef218b20994b617c57af120841a57fChet Haase
88121cd1389d2ef218b20994b617c57af120841a57fChet Haase    @Override
88221cd1389d2ef218b20994b617c57af120841a57fChet Haase    public void setupEndValues() {
88321cd1389d2ef218b20994b617c57af120841a57fChet Haase        initAnimation();
88421cd1389d2ef218b20994b617c57af120841a57fChet Haase        int numValues = mValues.length;
88521cd1389d2ef218b20994b617c57af120841a57fChet Haase        for (int i = 0; i < numValues; ++i) {
88651ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy            mValues[i].setupEndValue(mTarget);
88721cd1389d2ef218b20994b617c57af120841a57fChet Haase        }
88821cd1389d2ef218b20994b617c57af120841a57fChet Haase    }
88921cd1389d2ef218b20994b617c57af120841a57fChet Haase
890f54a8d7c479485174941c38f151ea7083c658da3Chet Haase    /**
89117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * This method is called with the elapsed fraction of the animation during every
89217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * animation frame. This function turns the elapsed fraction into an interpolated fraction
89317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * and then into an animated value (from the evaluator. The function is called mostly during
89417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * animation updates, but it is also called when the <code>end()</code>
89517fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * function is called, to set the final value on the property.
89617fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *
89717fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * <p>Overrides of this method must call the superclass to perform the calculation
89817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * of the animated value.</p>
89917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     *
90017fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     * @param fraction The elapsed fraction of the animation.
90117fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase     */
90217fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    @Override
90317fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    void animateValue(float fraction) {
90417fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase        super.animateValue(fraction);
905602e4d3824bf8b9cb9f817375d195b969712176aChet Haase        int numValues = mValues.length;
906602e4d3824bf8b9cb9f817375d195b969712176aChet Haase        for (int i = 0; i < numValues; ++i) {
90751ae5fc2d22a7bb616f432d7bac66bbbf8a1927fPatrick Dubroy            mValues[i].setAnimatedValue(mTarget);
90817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase        }
90917fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase    }
91049afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase
91149afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase    @Override
912a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase    public ObjectAnimator clone() {
913a18a86b43e40e3c15dcca0ae0148d641be9b25feChet Haase        final ObjectAnimator anim = (ObjectAnimator) super.clone();
91449afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase        return anim;
91549afa5bc100e5d4c069fea980dd6b09501f56397Chet Haase    }
916e9140a72b1059574046a624b471b2c3a35806496Chet Haase
917e9140a72b1059574046a624b471b2c3a35806496Chet Haase    @Override
918e9140a72b1059574046a624b471b2c3a35806496Chet Haase    public String toString() {
919e9140a72b1059574046a624b471b2c3a35806496Chet Haase        String returnVal = "ObjectAnimator@" + Integer.toHexString(hashCode()) + ", target " +
920e9140a72b1059574046a624b471b2c3a35806496Chet Haase            mTarget;
921e9140a72b1059574046a624b471b2c3a35806496Chet Haase        if (mValues != null) {
922e9140a72b1059574046a624b471b2c3a35806496Chet Haase            for (int i = 0; i < mValues.length; ++i) {
923e9140a72b1059574046a624b471b2c3a35806496Chet Haase                returnVal += "\n    " + mValues[i].toString();
924e9140a72b1059574046a624b471b2c3a35806496Chet Haase            }
925e9140a72b1059574046a624b471b2c3a35806496Chet Haase        }
926e9140a72b1059574046a624b471b2c3a35806496Chet Haase        return returnVal;
927e9140a72b1059574046a624b471b2c3a35806496Chet Haase    }
92817fb4b0d1cfbad1f026fec704c86640f070b4c2fChet Haase}
929