| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
#pragma once |
| 18 |
|
| 19 |
#include "Animator.h" |
| 20 |
#include "Interpolator.h" |
| 21 |
#include "PropertyValuesHolder.h" |
| 22 |
|
| 23 |
namespace android { |
| 24 |
namespace uirenderer { |
| 25 |
|
| 26 |
class PropertyAnimator { |
| 27 |
public: |
| 28 |
PropertyAnimator(PropertyValuesHolder* holder, Interpolator* interpolator, nsecs_t startDelay, |
| 29 |
nsecs_t duration, int repeatCount, RepeatMode repeatMode); |
| 30 |
void setCurrentPlayTime(nsecs_t playTime); |
| 31 |
nsecs_t getTotalDuration() { return mTotalDuration; } |
| 32 |
|
| 33 |
void setFraction(float fraction, long iteration); |
| 34 |
|
| 35 |
private: |
| 36 |
std::unique_ptr<PropertyValuesHolder> mPropertyValuesHolder; |
| 37 |
std::unique_ptr<Interpolator> mInterpolator; |
| 38 |
nsecs_t mStartDelay; |
| 39 |
nsecs_t mDuration; |
| 40 |
uint32_t mRepeatCount; |
| 41 |
nsecs_t mTotalDuration; |
| 42 |
RepeatMode mRepeatMode; |
| 43 |
double mLatestFraction = 0; |
| 44 |
}; |
| 45 |
|
| 46 |
|
| 47 |
class PropertyValuesAnimatorSet : public BaseRenderNodeAnimator { |
| 48 |
public: |
| 49 |
friend class PropertyAnimatorSetListener; |
| 50 |
PropertyValuesAnimatorSet(); |
| 51 |
|
| 52 |
void start(AnimationListener* listener); |
| 53 |
void reverse(AnimationListener* listener); |
| 54 |
virtual void reset() override; |
| 55 |
virtual void end() override; |
| 56 |
|
| 57 |
void addPropertyAnimator(PropertyValuesHolder* propertyValuesHolder, |
| 58 |
Interpolator* interpolators, int64_t startDelays, nsecs_t durations, |
| 59 |
int repeatCount, RepeatMode repeatMode); |
| 60 |
virtual uint32_t dirtyMask(); |
| 61 |
bool isInfinite() { return mIsInfinite; } |
| 62 |
void setVectorDrawable(VectorDrawableRoot* vd) { mVectorDrawable = vd; } |
| 63 |
VectorDrawableRoot* getVectorDrawable() const { return mVectorDrawable.get(); } |
| 64 |
AnimationListener* getOneShotListener() { return mOneShotListener.get(); } |
| 65 |
void clearOneShotListener() { mOneShotListener = nullptr; } |
| 66 |
uint32_t getRequestId() const { return mRequestId; } |
| 67 |
|
| 68 |
protected: |
| 69 |
virtual float getValue(RenderNode* target) const override; |
| 70 |
virtual void setValue(RenderNode* target, float value) override; |
| 71 |
virtual void onPlayTimeChanged(nsecs_t playTime) override; |
| 72 |
|
| 73 |
private: |
| 74 |
void init(); |
| 75 |
void onFinished(BaseRenderNodeAnimator* animator); |
| 76 |
|
| 77 |
sp<AnimationListener> mOneShotListener; |
| 78 |
std::vector<std::unique_ptr<PropertyAnimator> > mAnimators; |
| 79 |
float mLastFraction = 0.0f; |
| 80 |
bool mInitialized = false; |
| 81 |
sp<VectorDrawableRoot> mVectorDrawable; |
| 82 |
bool mIsInfinite = false; |
| 83 |
|
| 84 |
|
| 85 |
uint32_t mRequestId = 0; |
| 86 |
}; |
| 87 |
|
| 88 |
class PropertyAnimatorSetListener : public AnimationListener { |
| 89 |
public: |
| 90 |
explicit PropertyAnimatorSetListener(PropertyValuesAnimatorSet* set) : mSet(set) {} |
| 91 |
virtual void onAnimationFinished(BaseRenderNodeAnimator* animator) override; |
| 92 |
|
| 93 |
private: |
| 94 |
PropertyValuesAnimatorSet* mSet; |
| 95 |
}; |
| 96 |
|
| 97 |
} |
| 98 |
} |