ViewPropertyAnimator.java revision d666cf320db4134938f72b0ffe18212997f8c8d8
1a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase/* 2d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * Copyright (C) 2011 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 * 36d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * <p>This class may provide better performance for several simultaneous animations, because 37d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * it will optimize invalidate calls to take place only once for several properties instead of each 38d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * animated 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 40d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * property to animate, and the value to animate either to or by, and this class 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 106d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * the property (this class 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; 146ba592d200390d89723682f1a7e40d308d7804b36Chet Haase 147a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase PropertyBundle(int propertyMask, ArrayList<NameValuesHolder> nameValuesHolder) { 148a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mPropertyMask = propertyMask; 149a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mNameValuesHolder = nameValuesHolder; 150a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 151ba592d200390d89723682f1a7e40d308d7804b36Chet Haase 152ba592d200390d89723682f1a7e40d308d7804b36Chet Haase /** 153ba592d200390d89723682f1a7e40d308d7804b36Chet Haase * Removes the given property from being animated as a part of this 154ba592d200390d89723682f1a7e40d308d7804b36Chet Haase * PropertyBundle. If the property was a part of this bundle, it returns 155ba592d200390d89723682f1a7e40d308d7804b36Chet Haase * true to indicate that it was, in fact, canceled. This is an indication 156ba592d200390d89723682f1a7e40d308d7804b36Chet Haase * to the caller that a cancellation actually occurred. 157ba592d200390d89723682f1a7e40d308d7804b36Chet Haase * 158ba592d200390d89723682f1a7e40d308d7804b36Chet Haase * @param propertyConstant The property whose cancellation is requested. 159ba592d200390d89723682f1a7e40d308d7804b36Chet Haase * @return true if the given property is a part of this bundle and if it 160ba592d200390d89723682f1a7e40d308d7804b36Chet Haase * has therefore been canceled. 161ba592d200390d89723682f1a7e40d308d7804b36Chet Haase */ 162ba592d200390d89723682f1a7e40d308d7804b36Chet Haase boolean cancel(int propertyConstant) { 163ba592d200390d89723682f1a7e40d308d7804b36Chet Haase if ((mPropertyMask & propertyConstant) != 0 && mNameValuesHolder != null) { 164ba592d200390d89723682f1a7e40d308d7804b36Chet Haase int count = mNameValuesHolder.size(); 165ba592d200390d89723682f1a7e40d308d7804b36Chet Haase for (int i = 0; i < count; ++i) { 166ba592d200390d89723682f1a7e40d308d7804b36Chet Haase NameValuesHolder nameValuesHolder = mNameValuesHolder.get(i); 167ba592d200390d89723682f1a7e40d308d7804b36Chet Haase if (nameValuesHolder.mNameConstant == propertyConstant) { 168ba592d200390d89723682f1a7e40d308d7804b36Chet Haase mNameValuesHolder.remove(i); 169ba592d200390d89723682f1a7e40d308d7804b36Chet Haase mPropertyMask &= ~propertyConstant; 170ba592d200390d89723682f1a7e40d308d7804b36Chet Haase return true; 171ba592d200390d89723682f1a7e40d308d7804b36Chet Haase } 172ba592d200390d89723682f1a7e40d308d7804b36Chet Haase } 173ba592d200390d89723682f1a7e40d308d7804b36Chet Haase } 174ba592d200390d89723682f1a7e40d308d7804b36Chet Haase return false; 175ba592d200390d89723682f1a7e40d308d7804b36Chet Haase } 176a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 177a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 178a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 179a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This list tracks the list of properties being animated by any particular animator. 180a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * In most situations, there would only ever be one animator running at a time. But it is 181a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * possible to request some properties to animate together, then while those properties 182a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * are animating, to request some other properties to animate together. The way that 183a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * works is by having this map associate the group of properties being animated with the 184a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * animator handling the animation. On every update event for an Animator, we ask the 185a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * map for the associated properties and set them accordingly. 186a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 187a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase private HashMap<Animator, PropertyBundle> mAnimatorMap = 188a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase new HashMap<Animator, PropertyBundle>(); 189a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 190a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 191a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This is the information we need to set each property during the animation. 192a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * mNameConstant is used to set the appropriate field in View, and the from/delta 193a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * values are used to calculate the animated value for a given animation fraction 194a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * during the animation. 195a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 196a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase private static class NameValuesHolder { 197a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase int mNameConstant; 198a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase float mFromValue; 199a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase float mDeltaValue; 200a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase NameValuesHolder(int nameConstant, float fromValue, float deltaValue) { 201a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mNameConstant = nameConstant; 202a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mFromValue = fromValue; 203a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mDeltaValue = deltaValue; 204a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 205a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 206a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 207a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 208a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * Constructor, called by View. This is private by design, as the user should only 209a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * get a ViewPropertyAnimator by calling View.animate(). 210a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 211a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param view The View associated with this ViewPropertyAnimator 212a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 213a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase ViewPropertyAnimator(View view) { 214a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mView = view; 215a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 216a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 217a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 218a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * Sets the duration for the underlying animator that animates the requested properties. 219a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * By default, the animator uses the default value for ValueAnimator. Calling this method 220a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * will cause the declared value to be used instead. 221a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param duration The length of ensuing property animations, in milliseconds. The value 222a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * cannot be negative. 223a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 224a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 225a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator setDuration(long duration) { 226a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase if (duration < 0) { 227a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase throw new IllegalArgumentException("Animators cannot have negative duration: " + 228a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase duration); 229a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 230a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mDurationSet = true; 231a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mDuration = duration; 232a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 233a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 234a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 235a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 236a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * Sets the interpolator for the underlying animator that animates the requested properties. 237a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * By default, the animator uses the default interpolator for ValueAnimator. Calling this method 238a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * will cause the declared object to be used instead. 239a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 240a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param interpolator The TimeInterpolator to be used for ensuing property animations. 241a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 242a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 243a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator setInterpolator(TimeInterpolator interpolator) { 244a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mInterpolatorSet = true; 245a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mInterpolator = interpolator; 246a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 247a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 248a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 249a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 250a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * Sets a listener for events in the underlying Animators that run the property 251a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * animations. 252a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 253a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param listener The listener to be called with AnimatorListener events. 254a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 255a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 256a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator setListener(Animator.AnimatorListener listener) { 257a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mListener = listener; 258a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 259a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 260a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 261a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 262a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>x</code> property to be animated to the 263d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 264a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 265a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The value to be animated to. 266a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setX(float) 267a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 268a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 269a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator x(float value) { 270a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animateProperty(X, value); 271a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 272a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 273a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 274a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 275a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>x</code> property to be animated by the 276d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 277a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 278a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The amount to be animated by, as an offset from the current value. 279a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setX(float) 280a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 281a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 282a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator xBy(float value) { 283a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animatePropertyBy(X, value); 284a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 285a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 286a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 287a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 288a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>y</code> property to be animated to the 289d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 290a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 291a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The value to be animated to. 292a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setY(float) 293a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 294a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 295a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator y(float value) { 296a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animateProperty(Y, value); 297a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 298a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 299a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 300a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 301a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>y</code> property to be animated by the 302d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 303a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 304a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The amount to be animated by, as an offset from the current value. 305a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setY(float) 306a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 307a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 308a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator yBy(float value) { 309a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animatePropertyBy(Y, value); 310a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 311a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 312a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 313a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 314a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>rotation</code> property to be animated to the 315d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 316a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 317a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The value to be animated to. 318a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setRotation(float) 319a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 320a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 321a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator rotation(float value) { 322a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animateProperty(ROTATION, value); 323a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 324a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 325a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 326a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 327a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>rotation</code> property to be animated by the 328d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 329a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 330a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The amount to be animated by, as an offset from the current value. 331a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setRotation(float) 332a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 333a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 334a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator rotationBy(float value) { 335a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animatePropertyBy(ROTATION, value); 336a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 337a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 338a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 339a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 340a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>rotationX</code> property to be animated to the 341d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 342a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 343a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The value to be animated to. 344a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setRotationX(float) 345a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 346a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 347a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator rotationX(float value) { 348a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animateProperty(ROTATION_X, value); 349a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 350a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 351a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 352a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 353a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>rotationX</code> property to be animated by the 354d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 355a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 356a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The amount to be animated by, as an offset from the current value. 357a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setRotationX(float) 358a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 359a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 360a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator rotationXBy(float value) { 361a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animatePropertyBy(ROTATION_X, value); 362a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 363a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 364a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 365a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 366a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>rotationY</code> property to be animated to the 367d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 368a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 369a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The value to be animated to. 370a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setRotationY(float) 371a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 372a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 373a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator rotationY(float value) { 374a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animateProperty(ROTATION_Y, value); 375a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 376a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 377a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 378a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 379a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>rotationY</code> property to be animated by the 380d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 381a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 382a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The amount to be animated by, as an offset from the current value. 383a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setRotationY(float) 384a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 385a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 386a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator rotationYBy(float value) { 387a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animatePropertyBy(ROTATION_Y, value); 388a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 389a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 390a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 391a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 392a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>translationX</code> property to be animated to the 393d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 394a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 395a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The value to be animated to. 396a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setTranslationX(float) 397a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 398a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 399a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator translationX(float value) { 400a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animateProperty(TRANSLATION_X, value); 401a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 402a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 403a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 404a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 405a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>translationX</code> property to be animated by the 406d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 407a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 408a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The amount to be animated by, as an offset from the current value. 409a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setTranslationX(float) 410a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 411a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 412a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator translationXBy(float value) { 413a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animatePropertyBy(TRANSLATION_X, value); 414a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 415a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 416a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 417a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 418a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>translationY</code> property to be animated to the 419d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 420a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 421a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The value to be animated to. 422a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setTranslationY(float) 423a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 424a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 425a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator translationY(float value) { 426a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animateProperty(TRANSLATION_Y, value); 427a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 428a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 429a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 430a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 431a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>translationY</code> property to be animated by the 432d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 433a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 434a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The amount to be animated by, as an offset from the current value. 435a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setTranslationY(float) 436a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 437a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 438a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator translationYBy(float value) { 439a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animatePropertyBy(TRANSLATION_Y, value); 440a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 441a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 442a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 443a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 444a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>scaleX</code> property to be animated to the 445d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 446a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 447a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The value to be animated to. 448a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setScaleX(float) 449a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 450a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 451a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator scaleX(float value) { 452a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animateProperty(SCALE_X, value); 453a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 454a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 455a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 456a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 457a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>scaleX</code> property to be animated by the 458d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 459a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 460a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The amount to be animated by, as an offset from the current value. 461a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setScaleX(float) 462a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 463a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 464a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator scaleXBy(float value) { 465a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animatePropertyBy(SCALE_X, value); 466a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 467a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 468a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 469a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 470a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>scaleY</code> property to be animated to the 471d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 472a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 473a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The value to be animated to. 474a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setScaleY(float) 475a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 476a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 477a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator scaleY(float value) { 478a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animateProperty(SCALE_Y, value); 479a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 480a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 481a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 482a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 483a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>scaleY</code> property to be animated by the 484d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 485a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 486a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The amount to be animated by, as an offset from the current value. 487a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setScaleY(float) 488a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 489a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 490a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator scaleYBy(float value) { 491a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animatePropertyBy(SCALE_Y, value); 492a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 493a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 494a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 495a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 496a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>alpha</code> property to be animated to the 497d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 498a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 499a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The value to be animated to. 500a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setAlpha(float) 501a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 502a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 503a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator alpha(float value) { 504a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animateProperty(ALPHA, value); 505a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 506a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 507a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 508a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 509a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method will cause the View's <code>alpha</code> property to be animated by the 510d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * specified value. Animations already running on the property will be canceled. 511a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 512a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The amount to be animated by, as an offset from the current value. 513a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @see View#setAlpha(float) 514a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return This object, allowing calls to methods in this class to be chained. 515a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 516a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public ViewPropertyAnimator alphaBy(float value) { 517a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animatePropertyBy(ALPHA, value); 518a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return this; 519a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 520a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 521a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 522a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * Starts the underlying Animator for a set of properties. We use a single animator that 523a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * simply runs from 0 to 1, and then use that fractional value to set each property 524a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * value accordingly. 525a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 526a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase private void startAnimation() { 527a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase ValueAnimator animator = ValueAnimator.ofFloat(1.0f); 528a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase ArrayList<NameValuesHolder> nameValueList = 529a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase (ArrayList<NameValuesHolder>) mPendingAnimations.clone(); 530a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mPendingAnimations.clear(); 531a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase int propertyMask = 0; 532a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase int propertyCount = nameValueList.size(); 533a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase for (int i = 0; i < propertyCount; ++i) { 534a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase NameValuesHolder nameValuesHolder = nameValueList.get(i); 535a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase propertyMask |= nameValuesHolder.mNameConstant; 536a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 537a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mAnimatorMap.put(animator, new PropertyBundle(propertyMask, nameValueList)); 538a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animator.addUpdateListener(mAnimatorEventListener); 539a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animator.addListener(mAnimatorEventListener); 540a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase if (mDurationSet) { 541a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animator.setDuration(mDuration); 542a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 543a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase if (mInterpolatorSet) { 544a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animator.setInterpolator(mInterpolator); 545a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 546a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animator.start(); 547a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 548a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 549a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 550a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * Utility function, called by the various x(), y(), etc. methods. This stores the 551d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * constant name for the property along with the from/delta values that will be used to 552a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * calculate and set the property during the animation. This structure is added to the 553a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * pending animations, awaiting the eventual start() of the underlying animator. A 554a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * Runnable is posted to start the animation, and any pending such Runnable is canceled 555a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * (which enables us to end up starting just one animator for all of the properties 556a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * specified at one time). 557a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 558a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param constantName The specifier for the property being animated 559a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param toValue The value to which the property will animate 560a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 561a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase private void animateProperty(int constantName, float toValue) { 562a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase float fromValue = getValue(constantName); 563a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase float deltaValue = toValue - fromValue; 564a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animatePropertyBy(constantName, fromValue, deltaValue); 565a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 566a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 567a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 568a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * Utility function, called by the various xBy(), yBy(), etc. methods. This method is 569a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * just like animateProperty(), except the value is an offset from the property's 570a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * current value, instead of an absolute "to" value. 571a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 572a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param constantName The specifier for the property being animated 573a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param byValue The amount by which the property will change 574a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 575a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase private void animatePropertyBy(int constantName, float byValue) { 576a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase float fromValue = getValue(constantName); 577a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase animatePropertyBy(constantName, fromValue, byValue); 578a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 579a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 580a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 581d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * Utility function, called by animateProperty() and animatePropertyBy(), which handles the 582a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * details of adding a pending animation and posting the request to start the animation. 583a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 584a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param constantName The specifier for the property being animated 585d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase * @param startValue The starting value of the property 586a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param byValue The amount by which the property will change 587a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 588d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase private void animatePropertyBy(int constantName, float startValue, float byValue) { 589ba592d200390d89723682f1a7e40d308d7804b36Chet Haase // First, cancel any existing animations on this property 590ba592d200390d89723682f1a7e40d308d7804b36Chet Haase if (mAnimatorMap.size() > 0) { 591ba592d200390d89723682f1a7e40d308d7804b36Chet Haase Animator animatorToCancel = null; 592ba592d200390d89723682f1a7e40d308d7804b36Chet Haase Set<Animator> animatorSet = mAnimatorMap.keySet(); 593ba592d200390d89723682f1a7e40d308d7804b36Chet Haase for (Animator runningAnim : animatorSet) { 594ba592d200390d89723682f1a7e40d308d7804b36Chet Haase PropertyBundle bundle = mAnimatorMap.get(runningAnim); 595ba592d200390d89723682f1a7e40d308d7804b36Chet Haase if (bundle.cancel(constantName)) { 596ba592d200390d89723682f1a7e40d308d7804b36Chet Haase // property was canceled - cancel the animation if it's now empty 597ba592d200390d89723682f1a7e40d308d7804b36Chet Haase // Note that it's safe to break out here because every new animation 598ba592d200390d89723682f1a7e40d308d7804b36Chet Haase // on a property will cancel a previous animation on that property, so 599ba592d200390d89723682f1a7e40d308d7804b36Chet Haase // there can only ever be one such animation running. 600ba592d200390d89723682f1a7e40d308d7804b36Chet Haase if (bundle.mPropertyMask == NONE) { 601d666cf320db4134938f72b0ffe18212997f8c8d8Chet Haase // the animation is not longer changing anything - cancel it 602ba592d200390d89723682f1a7e40d308d7804b36Chet Haase animatorToCancel = runningAnim; 603ba592d200390d89723682f1a7e40d308d7804b36Chet Haase break; 604ba592d200390d89723682f1a7e40d308d7804b36Chet Haase } 605ba592d200390d89723682f1a7e40d308d7804b36Chet Haase } 606ba592d200390d89723682f1a7e40d308d7804b36Chet Haase } 607ba592d200390d89723682f1a7e40d308d7804b36Chet Haase if (animatorToCancel != null) { 608ba592d200390d89723682f1a7e40d308d7804b36Chet Haase animatorToCancel.cancel(); 609ba592d200390d89723682f1a7e40d308d7804b36Chet Haase } 610ba592d200390d89723682f1a7e40d308d7804b36Chet Haase } 611ba592d200390d89723682f1a7e40d308d7804b36Chet Haase 612a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase NameValuesHolder nameValuePair = new NameValuesHolder(constantName, startValue, byValue); 613a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mPendingAnimations.add(nameValuePair); 614a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mView.getHandler().removeCallbacks(mAnimationStarter); 615a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mView.post(mAnimationStarter); 616a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 617a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 618a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 619a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method handles setting the property values directly in the View object's fields. 620a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * propertyConstant tells it which property should be set, value is the value to set 621a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * the property to. 622a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 623a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param propertyConstant The property to be set 624a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param value The value to set the property to 625a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 626a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase private void setValue(int propertyConstant, float value) { 627a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase switch (propertyConstant) { 628a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case TRANSLATION_X: 629a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mView.mTranslationX = value; 630a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase break; 631a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case TRANSLATION_Y: 632a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mView.mTranslationY = value; 633a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase break; 634a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case ROTATION: 635a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mView.mRotation = value; 636a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase break; 637a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case ROTATION_X: 638a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mView.mRotationX = value; 639a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase break; 640a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case ROTATION_Y: 641a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mView.mRotationY = value; 642a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase break; 643a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case SCALE_X: 644a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mView.mScaleX = value; 645a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase break; 646a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case SCALE_Y: 647a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mView.mScaleY = value; 648a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase break; 649a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case X: 650a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mView.mTranslationX = value - mView.mLeft; 651a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase break; 652a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case Y: 653a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mView.mTranslationY = value - mView.mTop; 654a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase break; 655a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case ALPHA: 656a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mView.mAlpha = value; 657a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase break; 658a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 659a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 660a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 661a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 662a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * This method gets the value of the named property from the View object. 663a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 664a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param propertyConstant The property whose value should be returned 665a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @return float The value of the named property 666a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 667a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase private float getValue(int propertyConstant) { 668a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase switch (propertyConstant) { 669a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case TRANSLATION_X: 670a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return mView.mTranslationX; 671a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case TRANSLATION_Y: 672a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return mView.mTranslationY; 673a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case ROTATION: 674a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return mView.mRotation; 675a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case ROTATION_X: 676a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return mView.mRotationX; 677a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case ROTATION_Y: 678a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return mView.mRotationY; 679a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case SCALE_X: 680a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return mView.mScaleX; 681a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case SCALE_Y: 682a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return mView.mScaleY; 683a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case X: 684a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return mView.mLeft + mView.mTranslationX; 685a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case Y: 686a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return mView.mTop + mView.mTranslationY; 687a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase case ALPHA: 688a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return mView.mAlpha; 689a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 690a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase return 0; 691a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 692a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 693a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 694a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * Utility class that handles the various Animator events. The only ones we care 695a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * about are the end event (which we use to clean up the animator map when an animator 696a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * finishes) and the update event (which we use to calculate the current value of each 697a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * property and then set it on the view object). 698a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 699a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase private class AnimatorEventListener 700a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase implements Animator.AnimatorListener, ValueAnimator.AnimatorUpdateListener { 701a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase @Override 702a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public void onAnimationStart(Animator animation) { 703a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase if (mListener != null) { 704a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mListener.onAnimationStart(animation); 705a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 706a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 707a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 708a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase @Override 709a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public void onAnimationCancel(Animator animation) { 710a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase if (mListener != null) { 711a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mListener.onAnimationCancel(animation); 712a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 713a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 714a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 715a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase @Override 716a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public void onAnimationRepeat(Animator animation) { 717a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase if (mListener != null) { 718a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mListener.onAnimationRepeat(animation); 719a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 720a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 721a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 722a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase @Override 723a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public void onAnimationEnd(Animator animation) { 724a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase if (mListener != null) { 725a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mListener.onAnimationEnd(animation); 726a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 727a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mAnimatorMap.remove(animation); 728a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 729a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase 730a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase /** 731a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * Calculate the current value for each property and set it on the view. Invalidate 732a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * the view object appropriately, depending on which properties are being animated. 733a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * 734a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * @param animation The animator associated with the properties that need to be 735a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * set. This animator holds the animation fraction which we will use to calculate 736a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase * the current value of each property. 737a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase */ 738a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase @Override 739a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase public void onAnimationUpdate(ValueAnimator animation) { 740a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase // alpha requires slightly different treatment than the other (transform) properties. 741a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase // The logic in setAlpha() is not simply setting mAlpha, plus the invalidation 742a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase // logic is dependent on how the view handles an internal call to onSetAlpha(). 743a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase // We track what kinds of properties are set, and how alpha is handled when it is 744a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase // set, and perform the invalidation steps appropriately. 745a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase boolean alphaHandled = false; 746a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mView.invalidateParentCaches(); 747a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase float fraction = animation.getAnimatedFraction(); 748a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase PropertyBundle propertyBundle = mAnimatorMap.get(animation); 749a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase int propertyMask = propertyBundle.mPropertyMask; 750a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase if ((propertyMask & TRANSFORM_MASK) != 0) { 751a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mView.invalidate(false); 752a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 753a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase ArrayList<NameValuesHolder> valueList = propertyBundle.mNameValuesHolder; 754a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase if (valueList != null) { 755a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase int count = valueList.size(); 756a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase for (int i = 0; i < count; ++i) { 757a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase NameValuesHolder values = valueList.get(i); 758a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase float value = values.mFromValue + fraction * values.mDeltaValue; 759a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase if (values.mNameConstant == ALPHA) { 760a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase alphaHandled = mView.setAlphaNoInvalidation(value); 761a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } else { 762a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase setValue(values.mNameConstant, value); 763a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 764a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 765a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 766a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase if ((propertyMask & TRANSFORM_MASK) != 0) { 767a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mView.mMatrixDirty = true; 768a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mView.mPrivateFlags |= View.DRAWN; // force another invalidation 769a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 770a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase // invalidate(false) in all cases except if alphaHandled gets set to true 771a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase // via the call to setAlphaNoInvalidation(), above 772a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase mView.invalidate(alphaHandled); 773a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 774a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase } 775a00f3865f55c5c9cb74510ee2b239d101230133cChet Haase} 776