ViewPropertyAnimator.java revision a00f3865f55c5c9cb74510ee2b239d101230133c
1a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase/*
2a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * Copyright (C) 2010 The Android Open Source Project
3a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase *
4a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * Licensed under the Apache License, Version 2.0 (the "License");
5a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * you may not use this file except in compliance with the License.
6a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * You may obtain a copy of the License at
7a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase *
8a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase *      http://www.apache.org/licenses/LICENSE-2.0
9a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase *
10a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * Unless required by applicable law or agreed to in writing, software
11a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * distributed under the License is distributed on an "AS IS" BASIS,
12a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * See the License for the specific language governing permissions and
14a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * limitations under the License.
15a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */
16a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
17a00f3865f55c5c9cb74510ee2b239d101230133cChet Haasepackage android.view;
18a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
19a00f3865f55c5c9cb74510ee2b239d101230133cChet Haaseimport android.animation.Animator;
20a00f3865f55c5c9cb74510ee2b239d101230133cChet Haaseimport android.animation.ValueAnimator;
21a00f3865f55c5c9cb74510ee2b239d101230133cChet Haaseimport android.animation.TimeInterpolator;
22a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
23a00f3865f55c5c9cb74510ee2b239d101230133cChet Haaseimport java.util.ArrayList;
24a00f3865f55c5c9cb74510ee2b239d101230133cChet Haaseimport java.util.HashMap;
25a00f3865f55c5c9cb74510ee2b239d101230133cChet Haaseimport java.util.Set;
26a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
27a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase/**
28a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This class enables automatic and optimized animation of select properties on View objects.
29a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * If only one or two properties on a View object are being animated, then using an
30a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * {@link android.animation.ObjectAnimator} is fine; the property setters called by ObjectAnimator
31a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * are well equipped to do the right thing to set the property and invalidate the view
32a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * appropriately. But if several properties are animated simultaneously, or if you just want a
33a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * more convenient syntax to animate a specific property, then ViewPropertyAnimator might be
34a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * more well-suited to the task.
35a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase *
36a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * <p>This class could provide better performance for several simultaneous animations, because
37a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * it will optimize invalidatesionto take place only once for several properties instead of each
38a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * aniamted property independently causing its own invalidation. Also, the syntax of using this
39a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * class could be easier to use because the caller need only tell the View object which
40a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * property to animate, and the value to animate either to or by, and this calss handles the
41a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * details of configuring the underlying Animator class and starting it.</p>
42a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase *
43a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * <p>This class is not constructed by the caller, but rather by the View whose properties
44a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * it will animate. Calls to {@link android.view.View#animate()} will return a reference
45a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * to the appropriate ViewPropertyAnimator object for that View.</p>
46a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase *
47a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */
48a00f3865f55c5c9cb74510ee2b239d101230133cChet Haasepublic class ViewPropertyAnimator {
49a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
50a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
51a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * The View whose properties are being animated by this class. This is set at
52a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * construction time.
53a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
54a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private View mView;
55a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
56a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
57a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * The duration of the underlying Animator object. By default, we don't set the duration
58a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * on the Animator and just use its default duration. If the duration is ever set on this
59a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * Animator, then we use the duration that it was set to.
60a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
61a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private long mDuration;
62a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
63a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
64a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * A flag indicating whether the duration has been set on this object. If not, we don't set
65a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * the duration on the underlying Animator, but instead just use its default duration.
66a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
67a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private boolean mDurationSet = false;
68a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
69a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
70a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * The interpolator of the underlying Animator object. By default, we don't set the interpolator
71a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * on the Animator and just use its default interpolator. If the interpolator is ever set on
72a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * this Animator, then we use the interpolator that it was set to.
73a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
74a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private TimeInterpolator mInterpolator;
75a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
76a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
77a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * A flag indicating whether the interpolator has been set on this object. If not, we don't set
78a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * the interpolator on the underlying Animator, but instead just use its default interpolator.
79a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
80a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private boolean mInterpolatorSet = false;
81a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
82a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
83a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * Listener for the lifecycle events of the underlying
84a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
85a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private Animator.AnimatorListener mListener = null;
86a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
87a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
88a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This listener is the mechanism by which the underlying Animator causes changes to the
89a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * properties currently being animated, as well as the cleanup after an animation is
90a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * complete.
91a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
92a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private AnimatorEventListener mAnimatorEventListener = new AnimatorEventListener();
93a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
94a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
95a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This list holds the properties that have been asked to animate. We allow the caller to
96a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * request several animations prior to actually starting the underlying animator. This
97a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * enables us to run one single animator to handle several properties in parallel. Each
98a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * property is tossed onto the pending list until the animation actually starts (which is
99a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * done by posting it onto mView), at which time the pending list is cleared and the properties
100a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * on that list are added to the list of properties associated with that animator.
101a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
102a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    ArrayList<NameValuesHolder> mPendingAnimations = new ArrayList<NameValuesHolder>();
103a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
104a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
105a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * Constants used to associate a property being requested and the mechanism used to set
106a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * the property (this calss calls directly into View to set the properties in question).
107a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
108a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private static final int NONE           = 0x0000;
109a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private static final int TRANSLATION_X  = 0x0001;
110a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private static final int TRANSLATION_Y  = 0x0002;
111a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private static final int SCALE_X        = 0x0004;
112a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private static final int SCALE_Y        = 0x0008;
113a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private static final int ROTATION       = 0x0010;
114a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private static final int ROTATION_X     = 0x0020;
115a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private static final int ROTATION_Y     = 0x0040;
116a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private static final int X              = 0x0080;
117a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private static final int Y              = 0x0100;
118a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private static final int ALPHA          = 0x0200;
119a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
120a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private static final int TRANSFORM_MASK = TRANSLATION_X | TRANSLATION_Y | SCALE_X | SCALE_Y |
121a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            ROTATION | ROTATION_X | ROTATION_Y | X | Y;
122a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
123a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
124a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * The mechanism by which the user can request several properties that are then animated
125a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * together works by posting this Runnable to start the underlying Animator. Every time
126a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * a property animation is requested, we cancel any previous postings of the Runnable
127a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * and re-post it. This means that we will only ever run the Runnable (and thus start the
128a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * underlying animator) after the caller is done setting the properties that should be
129a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * animated together.
130a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
131a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private Runnable mAnimationStarter = new Runnable() {
132a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        @Override
133a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        public void run() {
134a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            startAnimation();
135a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        }
136a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    };
137a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
138a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
139a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This class holds information about the overall animation being run on the set of
140a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * properties. The mask describes which properties are being animated and the
141a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * values holder is the list of all property/value objects.
142a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
143a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private static class PropertyBundle {
144a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        int mPropertyMask;
145a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        ArrayList<NameValuesHolder> mNameValuesHolder;
146a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        PropertyBundle(int propertyMask, ArrayList<NameValuesHolder> nameValuesHolder) {
147a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            mPropertyMask = propertyMask;
148a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            mNameValuesHolder = nameValuesHolder;
149a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        }
150a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
151a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
152a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
153a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This list tracks the list of properties being animated by any particular animator.
154a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * In most situations, there would only ever be one animator running at a time. But it is
155a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * possible to request some properties to animate together, then while those properties
156a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * are animating, to request some other properties to animate together. The way that
157a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * works is by having this map associate the group of properties being animated with the
158a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * animator handling the animation. On every update event for an Animator, we ask the
159a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * map for the associated properties and set them accordingly.
160a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
161a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private HashMap<Animator, PropertyBundle> mAnimatorMap =
162a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            new HashMap<Animator, PropertyBundle>();
163a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
164a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
165a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This is the information we need to set each property during the animation.
166a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * mNameConstant is used to set the appropriate field in View, and the from/delta
167a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * values are used to calculate the animated value for a given animation fraction
168a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * during the animation.
169a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
170a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private static class NameValuesHolder {
171a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        int mNameConstant;
172a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        float mFromValue;
173a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        float mDeltaValue;
174a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        NameValuesHolder(int nameConstant, float fromValue, float deltaValue) {
175a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            mNameConstant = nameConstant;
176a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            mFromValue = fromValue;
177a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            mDeltaValue = deltaValue;
178a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        }
179a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
180a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
181a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
182a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * Constructor, called by View. This is private by design, as the user should only
183a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * get a ViewPropertyAnimator by calling View.animate().
184a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
185a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param view The View associated with this ViewPropertyAnimator
186a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
187a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    ViewPropertyAnimator(View view) {
188a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        mView = view;
189a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
190a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
191a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
192a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * Sets the duration for the underlying animator that animates the requested properties.
193a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * By default, the animator uses the default value for ValueAnimator. Calling this method
194a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * will cause the declared value to be used instead.
195a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param duration The length of ensuing property animations, in milliseconds. The value
196a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * cannot be negative.
197a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
198a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
199a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator setDuration(long duration) {
200a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        if (duration < 0) {
201a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            throw new IllegalArgumentException("Animators cannot have negative duration: " +
202a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                    duration);
203a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        }
204a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        mDurationSet = true;
205a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        mDuration = duration;
206a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
207a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
208a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
209a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
210a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * Sets the interpolator for the underlying animator that animates the requested properties.
211a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * By default, the animator uses the default interpolator for ValueAnimator. Calling this method
212a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * will cause the declared object to be used instead.
213a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
214a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param interpolator The TimeInterpolator to be used for ensuing property animations.
215a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
216a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
217a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator setInterpolator(TimeInterpolator interpolator) {
218a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        mInterpolatorSet = true;
219a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        mInterpolator = interpolator;
220a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
221a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
222a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
223a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
224a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * Sets a listener for events in the underlying Animators that run the property
225a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * animations.
226a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
227a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param listener The listener to be called with AnimatorListener events.
228a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
229a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
230a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator setListener(Animator.AnimatorListener listener) {
231a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        mListener = listener;
232a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
233a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
234a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
235a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
236a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>x</code> property to be animated to the
237a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specifed value.
238a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
239a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The value to be animated to.
240a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setX(float)
241a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
242a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
243a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator x(float value) {
244a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animateProperty(X, value);
245a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
246a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
247a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
248a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
249a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>x</code> property to be animated by the
250a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specifed value.
251a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
252a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The amount to be animated by, as an offset from the current value.
253a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setX(float)
254a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
255a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
256a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator xBy(float value) {
257a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animatePropertyBy(X, value);
258a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
259a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
260a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
261a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
262a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>y</code> property to be animated to the
263a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specifed value.
264a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
265a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The value to be animated to.
266a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setY(float)
267a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
268a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
269a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator y(float value) {
270a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animateProperty(Y, value);
271a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
272a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
273a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
274a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
275a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>y</code> property to be animated by the
276a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specifed value.
277a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
278a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The amount to be animated by, as an offset from the current value.
279a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setY(float)
280a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
281a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
282a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator yBy(float value) {
283a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animatePropertyBy(Y, value);
284a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
285a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
286a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
287a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
288a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>rotation</code> property to be animated to the
289a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specifed value.
290a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
291a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The value to be animated to.
292a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setRotation(float)
293a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
294a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
295a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator rotation(float value) {
296a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animateProperty(ROTATION, value);
297a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
298a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
299a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
300a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
301a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>rotation</code> property to be animated by the
302a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specifed value.
303a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
304a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The amount to be animated by, as an offset from the current value.
305a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setRotation(float)
306a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
307a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
308a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator rotationBy(float value) {
309a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animatePropertyBy(ROTATION, value);
310a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
311a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
312a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
313a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
314a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>rotationX</code> property to be animated to the
315a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specifed value.
316a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
317a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The value to be animated to.
318a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setRotationX(float)
319a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
320a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
321a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator rotationX(float value) {
322a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animateProperty(ROTATION_X, value);
323a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
324a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
325a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
326a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
327a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>rotationX</code> property to be animated by the
328a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specifed value.
329a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
330a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The amount to be animated by, as an offset from the current value.
331a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setRotationX(float)
332a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
333a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
334a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator rotationXBy(float value) {
335a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animatePropertyBy(ROTATION_X, value);
336a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
337a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
338a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
339a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
340a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>rotationY</code> property to be animated to the
341a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specifed value.
342a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
343a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The value to be animated to.
344a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setRotationY(float)
345a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
346a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
347a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator rotationY(float value) {
348a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animateProperty(ROTATION_Y, value);
349a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
350a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
351a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
352a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
353a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>rotationY</code> property to be animated by the
354a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specifed value.
355a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
356a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The amount to be animated by, as an offset from the current value.
357a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setRotationY(float)
358a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
359a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
360a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator rotationYBy(float value) {
361a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animatePropertyBy(ROTATION_Y, value);
362a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
363a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
364a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
365a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
366a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>translationX</code> property to be animated to the
367a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specifed value.
368a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
369a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The value to be animated to.
370a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setTranslationX(float)
371a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
372a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
373a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator translationX(float value) {
374a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animateProperty(TRANSLATION_X, value);
375a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
376a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
377a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
378a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
379a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>translationX</code> property to be animated by the
380a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specifed value.
381a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
382a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The amount to be animated by, as an offset from the current value.
383a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setTranslationX(float)
384a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
385a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
386a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator translationXBy(float value) {
387a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animatePropertyBy(TRANSLATION_X, value);
388a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
389a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
390a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
391a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
392a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>translationY</code> property to be animated to the
393a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specifed value.
394a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
395a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The value to be animated to.
396a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setTranslationY(float)
397a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
398a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
399a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator translationY(float value) {
400a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animateProperty(TRANSLATION_Y, value);
401a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
402a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
403a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
404a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
405a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>translationY</code> property to be animated by the
406a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specifed value.
407a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
408a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The amount to be animated by, as an offset from the current value.
409a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setTranslationY(float)
410a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
411a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
412a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator translationYBy(float value) {
413a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animatePropertyBy(TRANSLATION_Y, value);
414a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
415a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
416a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
417a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
418a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>scaleX</code> property to be animated to the
419a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specifed value.
420a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
421a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The value to be animated to.
422a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setScaleX(float)
423a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
424a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
425a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator scaleX(float value) {
426a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animateProperty(SCALE_X, value);
427a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
428a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
429a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
430a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
431a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>scaleX</code> property to be animated by the
432a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specifed value.
433a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
434a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The amount to be animated by, as an offset from the current value.
435a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setScaleX(float)
436a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
437a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
438a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator scaleXBy(float value) {
439a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animatePropertyBy(SCALE_X, value);
440a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
441a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
442a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
443a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
444a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>scaleY</code> property to be animated to the
445a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specifed value.
446a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
447a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The value to be animated to.
448a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setScaleY(float)
449a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
450a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
451a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator scaleY(float value) {
452a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animateProperty(SCALE_Y, value);
453a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
454a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
455a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
456a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
457a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>scaleY</code> property to be animated by the
458a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specifed value.
459a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
460a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The amount to be animated by, as an offset from the current value.
461a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setScaleY(float)
462a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
463a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
464a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator scaleYBy(float value) {
465a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animatePropertyBy(SCALE_Y, value);
466a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
467a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
468a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
469a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
470a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>alpha</code> property to be animated to the
471a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specified value.
472a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
473a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The value to be animated to.
474a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setAlpha(float)
475a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
476a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
477a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator alpha(float value) {
478a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animateProperty(ALPHA, value);
479a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
480a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
481a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
482a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
483a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method will cause the View's <code>alpha</code> property to be animated by the
484a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specified value.
485a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
486a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The amount to be animated by, as an offset from the current value.
487a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @see View#setAlpha(float)
488a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return This object, allowing calls to methods in this class to be chained.
489a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
490a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    public ViewPropertyAnimator alphaBy(float value) {
491a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animatePropertyBy(ALPHA, value);
492a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return this;
493a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
494a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
495a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
496a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * Starts the underlying Animator for a set of properties. We use a single animator that
497a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * simply runs from 0 to 1, and then use that fractional value to set each property
498a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * value accordingly.
499a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
500a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private void startAnimation() {
501a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        ValueAnimator animator = ValueAnimator.ofFloat(1.0f);
502a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        ArrayList<NameValuesHolder> nameValueList =
503a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                (ArrayList<NameValuesHolder>) mPendingAnimations.clone();
504a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        mPendingAnimations.clear();
505a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        int propertyMask = 0;
506a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        int propertyCount = nameValueList.size();
507a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        for (int i = 0; i < propertyCount; ++i) {
508a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            NameValuesHolder nameValuesHolder = nameValueList.get(i);
509a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            propertyMask |= nameValuesHolder.mNameConstant;
510a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        }
511a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        // First, cancel any running animation on the same property set
512a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        if (mAnimatorMap.size() > 0) {
513a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            Animator animatorToCancel = null;
514a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            Set<Animator> animatorSet = mAnimatorMap.keySet();
515a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            for (Animator runningAnim : animatorSet) {
516a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                PropertyBundle bundle = mAnimatorMap.get(runningAnim);
517a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                if (bundle.mPropertyMask == propertyMask) {
518a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                    // There can be only one such duplicate, because that animation would
519a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                    // have caused previous ones to cancel prior to starting. So break when we
520a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                    // find one.
521a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                    animatorToCancel = runningAnim;
522a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                    break;
523a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                }
524a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            }
525a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            if (animatorToCancel != null) {
526a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                animatorToCancel.cancel();
527a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            }
528a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        }
529a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        mAnimatorMap.put(animator, new PropertyBundle(propertyMask, nameValueList));
530a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animator.addUpdateListener(mAnimatorEventListener);
531a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animator.addListener(mAnimatorEventListener);
532a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        if (mDurationSet) {
533a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            animator.setDuration(mDuration);
534a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        }
535a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        if (mInterpolatorSet) {
536a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            animator.setInterpolator(mInterpolator);
537a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        }
538a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animator.start();
539a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
540a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
541a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
542a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * Utility function, called by the various x(), y(), etc. methods. This stores the
543a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * constnat name for the property along with the from/delta values that will be used to
544a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * calculate and set the property during the animation. This structure is added to the
545a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * pending animations, awaiting the eventual start() of the underlying animator. A
546a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * Runnable is posted to start the animation, and any pending such Runnable is canceled
547a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * (which enables us to end up starting just one animator for all of the properties
548a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * specified at one time).
549a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
550a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param constantName The specifier for the property being animated
551a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param toValue The value to which the property will animate
552a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
553a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private void animateProperty(int constantName, float toValue) {
554a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        float fromValue = getValue(constantName);
555a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        float deltaValue = toValue - fromValue;
556a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animatePropertyBy(constantName, fromValue, deltaValue);
557a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
558a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
559a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
560a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * Utility function, called by the various xBy(), yBy(), etc. methods. This method is
561a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * just like animateProperty(), except the value is an offset from the property's
562a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * current value, instead of an absolute "to" value.
563a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
564a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param constantName The specifier for the property being animated
565a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param byValue The amount by which the property will change
566a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
567a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private void animatePropertyBy(int constantName, float byValue) {
568a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        float fromValue = getValue(constantName);
569a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        animatePropertyBy(constantName, fromValue, byValue);
570a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
571a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
572a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
573a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * Utility function, called by animatePropert() and animatePropertyBy(), which handles the
574a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * details of adding a pending animation and posting the request to start the animation.
575a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
576a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param constantName The specifier for the property being animated
577a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param fromValue The starting value of the property
578a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param byValue The amount by which the property will change
579a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
580a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private void animatePropertyBy(int constantName, float fromValue, float byValue) {
581a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        float startValue = getValue(constantName);
582a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        NameValuesHolder nameValuePair = new NameValuesHolder(constantName, startValue, byValue);
583a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        mPendingAnimations.add(nameValuePair);
584a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        mView.getHandler().removeCallbacks(mAnimationStarter);
585a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        mView.post(mAnimationStarter);
586a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
587a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
588a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
589a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method handles setting the property values directly in the View object's fields.
590a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * propertyConstant tells it which property should be set, value is the value to set
591a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * the property to.
592a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
593a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param propertyConstant The property to be set
594a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param value The value to set the property to
595a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
596a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private void setValue(int propertyConstant, float value) {
597a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        switch (propertyConstant) {
598a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case TRANSLATION_X:
599a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                mView.mTranslationX = value;
600a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                break;
601a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case TRANSLATION_Y:
602a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                mView.mTranslationY = value;
603a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                break;
604a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case ROTATION:
605a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                mView.mRotation = value;
606a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                break;
607a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case ROTATION_X:
608a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                mView.mRotationX = value;
609a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                break;
610a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case ROTATION_Y:
611a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                mView.mRotationY = value;
612a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                break;
613a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case SCALE_X:
614a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                mView.mScaleX = value;
615a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                break;
616a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case SCALE_Y:
617a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                mView.mScaleY = value;
618a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                break;
619a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case X:
620a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                mView.mTranslationX = value - mView.mLeft;
621a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                break;
622a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case Y:
623a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                mView.mTranslationY = value - mView.mTop;
624a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                break;
625a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case ALPHA:
626a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                mView.mAlpha = value;
627a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                break;
628a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        }
629a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
630a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
631a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
632a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * This method gets the value of the named property from the View object.
633a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     *
634a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @param propertyConstant The property whose value should be returned
635a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * @return float The value of the named property
636a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
637a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private float getValue(int propertyConstant) {
638a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        switch (propertyConstant) {
639a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case TRANSLATION_X:
640a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                return mView.mTranslationX;
641a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case TRANSLATION_Y:
642a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                return mView.mTranslationY;
643a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case ROTATION:
644a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                return mView.mRotation;
645a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case ROTATION_X:
646a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                return mView.mRotationX;
647a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case ROTATION_Y:
648a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                return mView.mRotationY;
649a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case SCALE_X:
650a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                return mView.mScaleX;
651a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case SCALE_Y:
652a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                return mView.mScaleY;
653a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case X:
654a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                return mView.mLeft + mView.mTranslationX;
655a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case Y:
656a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                return mView.mTop + mView.mTranslationY;
657a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            case ALPHA:
658a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                return mView.mAlpha;
659a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        }
660a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        return 0;
661a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
662a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
663a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    /**
664a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * Utility class that handles the various Animator events. The only ones we care
665a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * about are the end event (which we use to clean up the animator map when an animator
666a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * finishes) and the update event (which we use to calculate the current value of each
667a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     * property and then set it on the view object).
668a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase     */
669a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    private class AnimatorEventListener
670a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            implements Animator.AnimatorListener, ValueAnimator.AnimatorUpdateListener {
671a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        @Override
672a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        public void onAnimationStart(Animator animation) {
673a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            if (mListener != null) {
674a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                mListener.onAnimationStart(animation);
675a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            }
676a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        }
677a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
678a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        @Override
679a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        public void onAnimationCancel(Animator animation) {
680a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            if (mListener != null) {
681a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                mListener.onAnimationCancel(animation);
682a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            }
683a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        }
684a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
685a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        @Override
686a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        public void onAnimationRepeat(Animator animation) {
687a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            if (mListener != null) {
688a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                mListener.onAnimationRepeat(animation);
689a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            }
690a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        }
691a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
692a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        @Override
693a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        public void onAnimationEnd(Animator animation) {
694a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            if (mListener != null) {
695a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                mListener.onAnimationEnd(animation);
696a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            }
697a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            mAnimatorMap.remove(animation);
698a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        }
699a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase
700a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        /**
701a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase         * Calculate the current value for each property and set it on the view. Invalidate
702a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase         * the view object appropriately, depending on which properties are being animated.
703a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase         *
704a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase         * @param animation The animator associated with the properties that need to be
705a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase         * set. This animator holds the animation fraction which we will use to calculate
706a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase         * the current value of each property.
707a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase         */
708a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        @Override
709a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        public void onAnimationUpdate(ValueAnimator animation) {
710a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            // alpha requires slightly different treatment than the other (transform) properties.
711a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            // The logic in setAlpha() is not simply setting mAlpha, plus the invalidation
712a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            // logic is dependent on how the view handles an internal call to onSetAlpha().
713a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            // We track what kinds of properties are set, and how alpha is handled when it is
714a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            // set, and perform the invalidation steps appropriately.
715a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            boolean alphaHandled = false;
716a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            mView.invalidateParentCaches();
717a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            float fraction = animation.getAnimatedFraction();
718a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            PropertyBundle propertyBundle = mAnimatorMap.get(animation);
719a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            int propertyMask = propertyBundle.mPropertyMask;
720a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            if ((propertyMask & TRANSFORM_MASK) != 0) {
721a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                mView.invalidate(false);
722a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            }
723a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            ArrayList<NameValuesHolder> valueList = propertyBundle.mNameValuesHolder;
724a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            if (valueList != null) {
725a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                int count = valueList.size();
726a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                for (int i = 0; i < count; ++i) {
727a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                    NameValuesHolder values = valueList.get(i);
728a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                    float value = values.mFromValue + fraction * values.mDeltaValue;
729a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                    if (values.mNameConstant == ALPHA) {
730a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                        alphaHandled = mView.setAlphaNoInvalidation(value);
731a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                    } else {
732a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                        setValue(values.mNameConstant, value);
733a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                    }
734a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                }
735a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            }
736a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            if ((propertyMask & TRANSFORM_MASK) != 0) {
737a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                mView.mMatrixDirty = true;
738a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase                mView.mPrivateFlags |= View.DRAWN; // force another invalidation
739a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            }
740a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            // invalidate(false) in all cases except if alphaHandled gets set to true
741a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            // via the call to setAlphaNoInvalidation(), above
742a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase            mView.invalidate(alphaHandled);
743a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase        }
744a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase    }
745a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase}
746