blob: c7ae7c0e8ce1c947bc5b4e286f9d4b6b4be0c85c [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"
20#include "PropertyValuesHolder.h"
21#include "Interpolator.h"
22
23namespace android {
24namespace uirenderer {
25
26class PropertyAnimator {
27public:
28 PropertyAnimator(PropertyValuesHolder* holder, Interpolator* interpolator, nsecs_t startDelay,
29 nsecs_t duration, int repeatCount);
30 void setCurrentPlayTime(nsecs_t playTime);
31 nsecs_t getTotalDuration() {
32 return mTotalDuration;
33 }
34 void setFraction(float fraction);
35
36private:
37 std::unique_ptr<PropertyValuesHolder> mPropertyValuesHolder;
38 std::unique_ptr<Interpolator> mInterpolator;
39 nsecs_t mStartDelay;
40 nsecs_t mDuration;
41 uint32_t mRepeatCount;
42 nsecs_t mTotalDuration;
43 float mLatestFraction = 0.0f;
44};
45
46class ANDROID_API PropertyValuesAnimatorSet : public BaseRenderNodeAnimator {
47public:
48 friend class PropertyAnimatorSetListener;
49 PropertyValuesAnimatorSet();
50
51 void start(AnimationListener* listener);
52 void reverse(AnimationListener* listener);
Doris Liu766431a2016-02-04 22:17:11 +000053
54 void addPropertyAnimator(PropertyValuesHolder* propertyValuesHolder,
55 Interpolator* interpolators, int64_t startDelays,
56 nsecs_t durations, int repeatCount);
57 virtual uint32_t dirtyMask();
58
59protected:
60 virtual float getValue(RenderNode* target) const override;
61 virtual void setValue(RenderNode* target, float value) override;
62 virtual void onPlayTimeChanged(nsecs_t playTime) override;
63
64private:
65 void init();
66 void onFinished(BaseRenderNodeAnimator* animator);
67 // Listener set from outside
68 sp<AnimationListener> mOneShotListener;
69 std::vector< std::unique_ptr<PropertyAnimator> > mAnimators;
70 float mLastFraction = 0.0f;
71 bool mInitialized = false;
72};
73
74class PropertyAnimatorSetListener : public AnimationListener {
75public:
76 PropertyAnimatorSetListener(PropertyValuesAnimatorSet* set) : mSet(set) {}
77 virtual void onAnimationFinished(BaseRenderNodeAnimator* animator) override;
78
79private:
80 PropertyValuesAnimatorSet* mSet;
81};
82
83} // namespace uirenderer
84} // namespace android