Class BaseAdditiveAnimator<T extends BaseAdditiveAnimator,V>
- java.lang.Object
-
- at.wirecube.additiveanimations.additive_animator.sequence.AnimationSequence
-
- at.wirecube.additiveanimations.additive_animator.BaseAdditiveAnimator<T,V>
-
- Type Parameters:
T- This generic should be instantiated with a concrete subclass of BaseAdditiveAnimator. It is used to access the builder methods across hierarchies. Example:public class MyViewAnimator extends BaseAdditiveAnimator<MyViewAnimator, View>V- The type of object to be animated.
- Direct Known Subclasses:
AdditiveObjectAnimator,SubclassableAdditiveViewAnimator
public abstract class BaseAdditiveAnimator<T extends BaseAdditiveAnimator,V> extends AnimationSequence
This is the base class which provides access to all non-specific animation creation methods such as creation, timing and chaining of additive animations. Subclasses should provide builder methods which create specific animations (seeSubclassableAdditiveViewAnimatorfor examples).
-
-
Field Summary
Fields Modifier and Type Field Description protected at.wirecube.additiveanimations.additive_animator.AdditiveAnimationAccumulatormAnimationAccumulatorprotected at.wirecube.additiveanimations.additive_animator.AdditiveAnimatorGroupmAnimatorGroupIndicates which animation group this animator belongs to.protected TimeInterpolatormCurrentCustomInterpolatorprotected VmCurrentTargetprotected TmParentprotected at.wirecube.additiveanimations.additive_animator.RunningAnimationsManager<V>mRunningAnimationsManagerprotected longsequenceDelayDelay set by the animation sequence this animator is a part of.protected longstaggerDelayDelay set when usingtargets(List, long)to create animations.
-
Constructor Summary
Constructors Constructor Description BaseAdditiveAnimator()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description Taction(AnimationAction<V> animationAction)TaddEndAction(AnimationEndListener r)TaddListener(Animator.AnimatorListener listener)TaddPauseListener(Animator.AnimatorPauseListener listener)TaddStartAction(Runnable r)TaddTarget(V v)Deprecated.Use#target(V)instead.TaddUpdateListener(ValueAnimator.AnimatorUpdateListener listener)protected Tanimate(Property<V,Float> property, float target)protected Tanimate(Property<V,Float> property, float target, TypeEvaluator<Float> evaluator)protected Tanimate(Property<V,Float> property, Path p, PathEvaluator.PathMode mode, PathEvaluator sharedEvaluator)protected Tanimate(AdditiveAnimation animation)protected Tanimate(AdditiveAnimation animation, boolean propagateToParentAnimators)Handles some bookkeeping for adding the given animation to the list of running animations.protected TanimatePropertiesAlongPath(Property<V,Float> xProperty, Property<V,Float> yProperty, Property<V,Float> rotationProperty, Path path)TanimateProperty(float target, TypeEvaluator<Float> evaluator, FloatProperty<V> property)Deprecated.Useproperty(float, TypeEvaluator, FloatProperty)instead.TanimateProperty(float target, FloatProperty<V> customProperty)Deprecated.Useproperty(float, FloatProperty)instead.protected TanimatePropertyBy(Property<V,Float> property, float by, boolean byValueCanBeUsedByParentAnimators)TODO: documentation of byValueCanBeUsedByParentAnimatorsstatic <V> voidapply(AnimationAction<V> action, List<V> targets)static <V> voidapply(AnimationAction<V> action, V... targets)Immediately applies the animation action to the given targets.protected voidapplyCustomProperties(Map<String,Float> tempProperties, V target)static voidcancelAnimation(Object target, String animationTag)static voidcancelAnimation(List<Object> targets, String animationTag)static <T> voidcancelAnimation(T target, Property<T,Float> property)static voidcancelAnimationsForObject(Object target)static voidcancelAnimationsForObjects(Object... targets)static <T extends Collection<? extends Object>>
voidcancelAnimationsInCollection(T targets)protected AdditiveAnimation<V>createAnimation(Property<V,Float> property, float targetValue)protected AdditiveAnimation<V>createAnimation(Property<V,Float> property, float targetValue, TypeEvaluator<Float> evaluator)protected AdditiveAnimation<V>createAnimation(Property<V,Float> property, Path path, PathEvaluator.PathMode mode, PathEvaluator sharedEvaluator)protected TcreateChildWithDelayAfterParentStart(long delay, boolean isStagger)protected TcreateChildWithRawDelay(long delay)abstract FloatgetCurrentPropertyValue(String propertyName)Returns the actual value of the animation target with the given name.protected VgetCurrentTarget()protected FloatgetQueuedPropertyValue(String propertyName)Returns the last value that was queued for animation whose animation has not yet started.protected at.wirecube.additiveanimations.additive_animator.RunningAnimationsManager<V>getRunningAnimationsManager()floatgetTargetPropertyValue(Property<V,Float> property)Finds the last target value of the property with the given name, or returns `property.get()` if the property isn't animating at the moment.FloatgetTargetPropertyValue(String propertyName)Finds the last target value of the property with the given name, if it was ever animated.longgetTotalDurationInSequence()protected ValueAnimatorgetValueAnimator()protected voidinitValueAnimatorIfNeeded()protected abstract TnewInstance()Factory method for creation of subclass instances.abstract voidonApplyChanges()This method will be called when the current frame has been calculated.Tproperty(float target, TypeEvaluator<Float> evaluator, FloatProperty<V> property)Tproperty(float target, FloatProperty<V> customProperty)Tproperty(float target, FloatProperty<V> customProperty, boolean by)protected voidrunIfParentIsInSameAnimationGroup(Runnable r)protected Tself()static voidsetDefaultDuration(long defaultDuration)Globally sets the default animation duration to use for all AdditiveAnimator instances.static voidsetDefaultInterpolator(TimeInterpolator interpolator)Globally sets the default interpolator to use for all AdditiveAnimator instances.voidsetDelayInSequence(long delay)TsetDuration(long duration)TsetInterpolator(TimeInterpolator interpolator)protected TsetParent(T other)Copies all relevant attributes, including (ONLY) current target from `other` to self.TsetRepeatCount(int repeatCount)TsetRepeatMode(int repeatMode)static voidsetsDefaultInterpolator(TimeInterpolator interpolator)Deprecated.This method name contains a typo.TsetStartDelay(long startDelay)voidstart()Tstate(AnimationState<V> state)TswitchDuration(long durationMillis)TswitchInterpolator(TimeInterpolator newInterpolator)Switches to the given interpolator only for all following animations.TswitchToDefaultInterpolator()Ttarget(V v)Sets the current animation target.Ttargets(List<V> vs)Used to animate the same property of multiple views.Ttargets(List<V> vs, long stagger)Used to animate the same property of multiple views, with a delay before each element.Ttargets(V... vs)Used to animate the same property of multiple views.Tthen()Creates a new animator configured to start after the current animator with the current target that was configured with this animator.TthenBeforeEnd(long millisBeforeEnd)Creates a new animator configured to start afterdelayBeforeEndmilliseconds before the previous animation finishes with the last used target and interpolator.TthenDelayAfterEnd(long delayAfterEnd)Creates a new animator configured to start afterdelayAfterEndmilliseconds after the previous animation has ended with the last used target and interpolator.TthenWithDelay(long delay)Creates a new animator configured to start afterdelaymilliseconds from now with the last used target and interpolator.-
Methods inherited from class at.wirecube.additiveanimations.additive_animator.sequence.AnimationSequence
playSequentially, playSequentially, playTogether, playTogether, playWithDelayBetweenAnimations
-
-
-
-
Field Detail
-
mParent
protected T extends BaseAdditiveAnimator mParent
-
mCurrentTarget
protected V mCurrentTarget
-
mRunningAnimationsManager
@Nullable protected at.wirecube.additiveanimations.additive_animator.RunningAnimationsManager<V> mRunningAnimationsManager
-
mAnimationAccumulator
protected at.wirecube.additiveanimations.additive_animator.AdditiveAnimationAccumulator mAnimationAccumulator
-
mCurrentCustomInterpolator
protected TimeInterpolator mCurrentCustomInterpolator
-
staggerDelay
protected long staggerDelay
Delay set when usingtargets(List, long)to create animations. Added to the delay set bysetStartDelay(long)andsequenceDelay. Will be considered ingetTotalDuration().
-
sequenceDelay
protected long sequenceDelay
Delay set by the animation sequence this animator is a part of. Added to the delay set bysetStartDelay(long)and the delay introduced by the stagger parameter oftargets(List, long). Will be considered ingetTotalDuration().
-
mAnimatorGroup
protected at.wirecube.additiveanimations.additive_animator.AdditiveAnimatorGroup mAnimatorGroup
Indicates which animation group this animator belongs to. An animation group is a set of animators which have different targets, but share the same animations. An example would be: new AdditiveAnimator().targets(v1, v2).alpha(0).start(); In this case, v1 and v2 have different AdditiveAnimator instances, but share the same animations (alpha = 0). Animation groups are inherited with then() chaining. All animators in the group can have different starting offsets when using the targets(views, stagger) method.
-
-
Method Detail
-
self
protected T self()
-
getRunningAnimationsManager
@NonNull protected final at.wirecube.additiveanimations.additive_animator.RunningAnimationsManager<V> getRunningAnimationsManager()
-
cancelAnimationsForObject
public static void cancelAnimationsForObject(Object target)
-
cancelAnimationsForObjects
public static void cancelAnimationsForObjects(Object... targets)
-
cancelAnimationsInCollection
public static <T extends Collection<? extends Object>> void cancelAnimationsInCollection(T targets)
-
initValueAnimatorIfNeeded
protected void initValueAnimatorIfNeeded()
-
getValueAnimator
protected ValueAnimator getValueAnimator()
-
addTarget
@Deprecated public T addTarget(V v)
Deprecated.Use#target(V)instead.Old API for#target(V), which should be used instead.
-
getTargetPropertyValue
public float getTargetPropertyValue(Property<V,Float> property)
Finds the last target value of the property with the given name, or returns `property.get()` if the property isn't animating at the moment.
-
getTargetPropertyValue
public Float getTargetPropertyValue(String propertyName)
Finds the last target value of the property with the given name, if it was ever animated. This method can return null if the value hasn't been animated or the animation is already done.
-
getCurrentPropertyValue
public abstract Float getCurrentPropertyValue(String propertyName)
Returns the actual value of the animation target with the given name.
-
getQueuedPropertyValue
protected Float getQueuedPropertyValue(String propertyName)
Returns the last value that was queued for animation whose animation has not yet started. This method is for internal use only (keeping track of chained `animateBy` calls).
-
onApplyChanges
public abstract void onApplyChanges()
This method will be called when the current frame has been calculated. Override this method in a subclass to trigger a layout of your view/canvas/custom object.
-
applyCustomProperties
protected void applyCustomProperties(Map<String,Float> tempProperties, V target)
-
getCurrentTarget
protected V getCurrentTarget()
-
createAnimation
protected final AdditiveAnimation<V> createAnimation(Property<V,Float> property, float targetValue)
-
createAnimation
protected final AdditiveAnimation<V> createAnimation(Property<V,Float> property, float targetValue, TypeEvaluator<Float> evaluator)
-
createAnimation
protected final AdditiveAnimation<V> createAnimation(Property<V,Float> property, Path path, PathEvaluator.PathMode mode, PathEvaluator sharedEvaluator)
-
animate
protected final T animate(AdditiveAnimation animation, boolean propagateToParentAnimators)
Handles some bookkeeping for adding the given animation to the list of running animations. You have to call this method to add animations.- Parameters:
animation- The animation to be added to the running animations.propagateToParentAnimators- Whether or not this animation will be propagated to the parent animators. You can set it to `false` if you propagate the animation manually to the other animators in this group. If you fail to propagate the animation correctly,targets(List, long)will not work with that animation. (If you don't know what that means, you should probably just pass `true` and have the base implementation take care of it.)
-
animate
protected final T animate(AdditiveAnimation animation)
-
animate
protected final T animate(Property<V,Float> property, Path p, PathEvaluator.PathMode mode, PathEvaluator sharedEvaluator)
-
animate
protected final T animate(Property<V,Float> property, float target, TypeEvaluator<Float> evaluator)
-
animatePropertyBy
protected final T animatePropertyBy(Property<V,Float> property, float by, boolean byValueCanBeUsedByParentAnimators)
TODO: documentation of byValueCanBeUsedByParentAnimators
-
animatePropertiesAlongPath
protected final T animatePropertiesAlongPath(Property<V,Float> xProperty, Property<V,Float> yProperty, Property<V,Float> rotationProperty, Path path)
-
animateProperty
public T animateProperty(float target, TypeEvaluator<Float> evaluator, FloatProperty<V> property)
Deprecated.Useproperty(float, TypeEvaluator, FloatProperty)instead.Old API forproperty(float, TypeEvaluator, FloatProperty), which should be used instead.
-
property
public T property(float target, TypeEvaluator<Float> evaluator, FloatProperty<V> property)
-
animateProperty
public T animateProperty(float target, FloatProperty<V> customProperty)
Deprecated.Useproperty(float, FloatProperty)instead.Old API forproperty(float, FloatProperty), which should be used instead.
-
property
public T property(float target, FloatProperty<V> customProperty)
-
property
public T property(float target, FloatProperty<V> customProperty, boolean by)
-
state
public T state(AnimationState<V> state)
-
action
public T action(AnimationAction<V> animationAction)
-
apply
public static <V> void apply(AnimationAction<V> action, V... targets)
Immediately applies the animation action to the given targets. (similar to Butterknife's `apply' method).
-
apply
public static <V> void apply(AnimationAction<V> action, List<V> targets)
-
setDefaultDuration
public static void setDefaultDuration(long defaultDuration)
Globally sets the default animation duration to use for all AdditiveAnimator instances. You can override this by callingsetDuration(long)on a specific instance.
-
setsDefaultInterpolator
@Deprecated public static void setsDefaultInterpolator(TimeInterpolator interpolator)
Deprecated.This method name contains a typo. UsesetDefaultInterpolator(TimeInterpolator)instead.
-
setDefaultInterpolator
public static void setDefaultInterpolator(TimeInterpolator interpolator)
Globally sets the default interpolator to use for all AdditiveAnimator instances. You can override this by callingsetInterpolator(TimeInterpolator)on a specific instance.
-
target
public T target(V v)
Sets the current animation target. You can change the animation target multiple times before callingstart():new AdditiveAnimator().target(view1).x(100).target(view2).y(200).start()If you want to animate the same property of multiple views, usetargets(Object[])ortargets(List, long)
-
targets
public T targets(@NonNull V... vs)
Used to animate the same property of multiple views. This is a convenience method which simply creates a series of animators which will start simultaneously. Example:new AdditiveAnimator().targets(textView, button).alpha(0).start()
-
targets
public T targets(@NonNull List<V> vs)
Used to animate the same property of multiple views. This is a convenience method which simply creates a series of animators which will start simultaneously. Example:new AdditiveAnimator().targets(myViewList).alpha(0).start()
-
targets
public T targets(@NonNull List<V> vs, long stagger)
Used to animate the same property of multiple views, with a delay before each element. This is a convenience method which simply creates a series of animators which will start with `stagger` offset after each other. Example:new AdditiveAnimator().targets(Arrays.asList(textView, button), 100).translationYBy(100).alpha(0).start()
-
addUpdateListener
public T addUpdateListener(ValueAnimator.AnimatorUpdateListener listener)
-
addPauseListener
public T addPauseListener(Animator.AnimatorPauseListener listener)
-
addListener
public T addListener(Animator.AnimatorListener listener)
-
addEndAction
public T addEndAction(AnimationEndListener r)
-
setStartDelay
public T setStartDelay(long startDelay)
-
setDuration
public T setDuration(long duration)
-
switchDuration
public T switchDuration(long durationMillis)
-
setInterpolator
public T setInterpolator(TimeInterpolator interpolator)
-
switchToDefaultInterpolator
public T switchToDefaultInterpolator()
-
setRepeatCount
public T setRepeatCount(int repeatCount)
-
setRepeatMode
public T setRepeatMode(int repeatMode)
-
switchInterpolator
public T switchInterpolator(TimeInterpolator newInterpolator)
Switches to the given interpolator only for all following animations. This is different from `setInterpolator` in that it doesn't apply to animations that were created before calling this method. Calling `setInterpolator` after calling this method at least once will behave the same as calling `switchInterpolator` to prevent accidentally overriding the effects of `switchInterpolator`.
-
newInstance
protected abstract T newInstance()
Factory method for creation of subclass instances. Override to use all of the advanced features with your custom subclass.
-
then
public T then()
Creates a new animator configured to start after the current animator with the current target that was configured with this animator.
-
thenWithDelay
public T thenWithDelay(long delay)
Creates a new animator configured to start afterdelaymilliseconds from now with the last used target and interpolator.
-
thenDelayAfterEnd
public T thenDelayAfterEnd(long delayAfterEnd)
Creates a new animator configured to start afterdelayAfterEndmilliseconds after the previous animation has ended with the last used target and interpolator.
-
thenBeforeEnd
public T thenBeforeEnd(long millisBeforeEnd)
Creates a new animator configured to start afterdelayBeforeEndmilliseconds before the previous animation finishes with the last used target and interpolator.
-
createChildWithRawDelay
protected T createChildWithRawDelay(long delay)
-
createChildWithDelayAfterParentStart
protected T createChildWithDelayAfterParentStart(long delay, boolean isStagger)
-
getTotalDurationInSequence
public long getTotalDurationInSequence()
- Specified by:
getTotalDurationInSequencein classAnimationSequence
-
setDelayInSequence
public void setDelayInSequence(long delay)
- Specified by:
setDelayInSequencein classAnimationSequence
-
start
public void start()
- Specified by:
startin classAnimationSequence
-
setParent
protected T setParent(T other)
Copies all relevant attributes, including (ONLY) current target from `other` to self. Override if you have custom properties that need to be copied.
-
runIfParentIsInSameAnimationGroup
protected void runIfParentIsInSameAnimationGroup(Runnable r)
-
-