blob: e4214b22d1cc94b8375b39007cf112499683db3e [file] [log] [blame]
Doris Liu766431a2016-02-04 22:17:11 +00001/*
2 * Copyright (C) 2016 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include "Animator.h"
Doris Liu766431a2016-02-04 22:17:11 +000020#include "Interpolator.h"
John Reck1bcacfd2017-11-03 10:12:19 -070021#include "PropertyValuesHolder.h"
Doris Liu766431a2016-02-04 22:17:11 +000022
23namespace android {
24namespace uirenderer {
25
26class PropertyAnimator {
27public:
28 PropertyAnimator(PropertyValuesHolder* holder, Interpolator* interpolator, nsecs_t startDelay,
John Reck1bcacfd2017-11-03 10:12:19 -070029 nsecs_t duration, int repeatCount, RepeatMode repeatMode);
Doris Liu766431a2016-02-04 22:17:11 +000030 void setCurrentPlayTime(nsecs_t playTime);
John Reck1bcacfd2017-11-03 10:12:19 -070031 nsecs_t getTotalDuration() { return mTotalDuration; }
Doris Liuf7167e82016-08-03 17:54:28 -070032 // fraction range: [0, 1], iteration range [0, repeatCount]
33 void setFraction(float fraction, long iteration);
Doris Liu766431a2016-02-04 22:17:11 +000034
35private:
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;
Doris Liuf7167e82016-08-03 17:54:28 -070042 RepeatMode mRepeatMode;
43 double mLatestFraction = 0;
Doris Liu766431a2016-02-04 22:17:11 +000044};
45
Doris Liu718cd3e2016-05-17 16:50:31 -070046// TODO: This class should really be named VectorDrawableAnimator
Doris Liu766431a2016-02-04 22:17:11 +000047class ANDROID_API PropertyValuesAnimatorSet : public BaseRenderNodeAnimator {
48public:
49 friend class PropertyAnimatorSetListener;
50 PropertyValuesAnimatorSet();
51
52 void start(AnimationListener* listener);
53 void reverse(AnimationListener* listener);
Doris Liu718cd3e2016-05-17 16:50:31 -070054 virtual void reset() override;
55 virtual void end() override;
Doris Liu766431a2016-02-04 22:17:11 +000056
57 void addPropertyAnimator(PropertyValuesHolder* propertyValuesHolder,
John Reck1bcacfd2017-11-03 10:12:19 -070058 Interpolator* interpolators, int64_t startDelays, nsecs_t durations,
59 int repeatCount, RepeatMode repeatMode);
Doris Liu766431a2016-02-04 22:17:11 +000060 virtual uint32_t dirtyMask();
Doris Liu718cd3e2016-05-17 16:50:31 -070061 bool isInfinite() { return mIsInfinite; }
62 void setVectorDrawable(VectorDrawableRoot* vd) { mVectorDrawable = vd; }
Doris Liu98980cd2016-07-12 18:48:52 -070063 VectorDrawableRoot* getVectorDrawable() const { return mVectorDrawable.get(); }
Doris Liu718cd3e2016-05-17 16:50:31 -070064 AnimationListener* getOneShotListener() { return mOneShotListener.get(); }
65 void clearOneShotListener() { mOneShotListener = nullptr; }
66 uint32_t getRequestId() const { return mRequestId; }
Doris Liu766431a2016-02-04 22:17:11 +000067
68protected:
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
73private:
74 void init();
75 void onFinished(BaseRenderNodeAnimator* animator);
76 // Listener set from outside
77 sp<AnimationListener> mOneShotListener;
John Reck1bcacfd2017-11-03 10:12:19 -070078 std::vector<std::unique_ptr<PropertyAnimator> > mAnimators;
Doris Liu766431a2016-02-04 22:17:11 +000079 float mLastFraction = 0.0f;
80 bool mInitialized = false;
Doris Liu98980cd2016-07-12 18:48:52 -070081 sp<VectorDrawableRoot> mVectorDrawable;
Doris Liu718cd3e2016-05-17 16:50:31 -070082 bool mIsInfinite = false;
83 // This request id gets incremented (on UI thread only) when a new request to modfiy the
84 // lifecycle of an animation happens, namely when start/end/reset/reverse is called.
85 uint32_t mRequestId = 0;
Doris Liu766431a2016-02-04 22:17:11 +000086};
87
88class PropertyAnimatorSetListener : public AnimationListener {
89public:
Chih-Hung Hsieha619ec72016-08-29 14:52:43 -070090 explicit PropertyAnimatorSetListener(PropertyValuesAnimatorSet* set) : mSet(set) {}
Doris Liu766431a2016-02-04 22:17:11 +000091 virtual void onAnimationFinished(BaseRenderNodeAnimator* animator) override;
92
93private:
94 PropertyValuesAnimatorSet* mSet;
95};
96
John Reck1bcacfd2017-11-03 10:12:19 -070097} // namespace uirenderer
98} // namespace android