1 /*
2 * Copyright (c) 2021 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "core/animation/test/mock/mock_animation.h"
17
18 #include "base/log/log.h"
19 #include "core/components/dialog_modal/dialog_modal_component.h"
20 #include "core/components/semi_modal/semi_modal_component.h"
21 #include "core/image/image_loader.h"
22
23 namespace OHOS::Ace {
OnPostFlush()24 void MockAnimation::OnPostFlush()
25 {
26 postFlushCallTimes_++;
27 CreateInterpolators();
28 AddListeners();
29 animator_->SetDuration(animationDuration_);
30 setRepeatSucc_ = animator_->SetIteration(iteration_);
31 animator_->SetStartDelay(startDelay_);
32 ExecuteOperation();
33 }
34
ExecuteOperation()35 void MockAnimation::ExecuteOperation()
36 {
37 switch (operation_) {
38 case AnimationOperation::PLAY:
39 animator_->Play();
40 break;
41 case AnimationOperation::REVERSE:
42 animator_->Reverse();
43 break;
44 case AnimationOperation::FINISH:
45 animator_->Finish();
46 break;
47 case AnimationOperation::PAUSE:
48 animator_->Pause();
49 break;
50 case AnimationOperation::CANCEL:
51 animator_->Cancel();
52 break;
53 case AnimationOperation::NONE:
54 default:
55 break;
56 }
57 }
58
AddListeners()59 void MockAnimation::AddListeners()
60 {
61 auto weak = AceType::WeakClaim(this);
62 animator_->AddStartListener([weak]() {
63 auto simulator = weak.Upgrade();
64 if (simulator) {
65 simulator->animationStartStatus_ = true;
66 }
67 });
68 animator_->AddStopListener([weak]() {
69 auto simulator = weak.Upgrade();
70 if (simulator) {
71 simulator->animationStopStatus_ = true;
72 simulator->animationIntStopValue_ = simulator->animationIntValue_;
73 }
74 });
75 animator_->AddRepeatListener([weak]() {
76 auto simulator = weak.Upgrade();
77 if (simulator) {
78 ++(simulator->repeatDoneTimes_);
79 }
80 });
81 animator_->AddIdleListener([weak]() {
82 auto simulator = weak.Upgrade();
83 if (simulator) {
84 simulator->animationIdleStatus_ = true;
85 }
86 });
87 animator_->AddPauseListener([weak]() {
88 auto simulator = weak.Upgrade();
89 if (simulator) {
90 simulator->animationPauseStatus_ = true;
91 }
92 });
93 }
94
CreatePictureInterpolators()95 void MockAnimation::CreatePictureInterpolators()
96 {
97 auto weak = AceType::WeakClaim(this);
98 if (pictureInt_) {
99 pictureInt_->AddListener([weak](const int& value) {
100 auto simulator = weak.Upgrade();
101 if (simulator) {
102 simulator->pictureIntValue_ = value;
103 }
104 });
105 animator_->AddInterpolator(pictureInt_);
106 }
107 if (pictureString_) {
108 pictureString_->AddListener([weak](const std::string& value) {
109 auto simulator = weak.Upgrade();
110 if (simulator) {
111 simulator->pictureStringValue_ = value;
112 }
113 });
114 animator_->AddInterpolator(pictureString_);
115 }
116 }
117
CreateInterpolators()118 void MockAnimation::CreateInterpolators()
119 {
120 auto weak = AceType::WeakClaim(this);
121 if (animationInt_) {
122 animationInt_->AddListener([weak](const int& value) {
123 auto simulator = weak.Upgrade();
124 if (simulator) {
125 simulator->animationIntValue_ = value;
126 }
127 });
128 animator_->AddInterpolator(animationInt_);
129 }
130 if (animationFloat_) {
131 animationFloat_->AddListener([weak](const float& value) {
132 auto simulator = weak.Upgrade();
133 if (simulator) {
134 simulator->animationFloatValue_ = value;
135 }
136 });
137 animator_->AddInterpolator(animationFloat_);
138 }
139 if (keyframeAnimation_) {
140 keyframeAnimation_->AddListener([weak](const float& value) {
141 auto simulator = weak.Upgrade();
142 if (simulator) {
143 simulator->keyframeAnimationValue_ = value;
144 }
145 });
146 animator_->AddInterpolator(keyframeAnimation_);
147 }
148 if (animationColor_) {
149 animationColor_->AddListener([weak](const Color& value) {
150 auto simulator = weak.Upgrade();
151 if (simulator) {
152 simulator->animationColorValue_ = value;
153 }
154 });
155 animator_->AddInterpolator(animationColor_);
156 }
157 CreatePictureInterpolators();
158 }
159
GetAnimator() const160 const RefPtr<Animator>& MockAnimation::GetAnimator() const
161 {
162 return animator_;
163 }
164
GetPositionResult() const165 double MockAnimation::GetPositionResult() const
166 {
167 return positionResult_;
168 }
169
SetPositionResult(double positionResult)170 void MockAnimation::SetPositionResult(double positionResult)
171 {
172 positionResult_ = positionResult;
173 }
174
Create(RefPtr<Component> child,bool isFullScreen,int32_t modalHeight,uint32_t color)175 RefPtr<Component> SemiModalComponent::Create(
176 RefPtr<Component> child, bool isFullScreen, int32_t modalHeight, uint32_t color)
177 {
178 return nullptr;
179 }
180
Create(RefPtr<Component> child)181 RefPtr<Component> DialogModalComponent::Create(RefPtr<Component> child)
182 {
183 return nullptr;
184 }
185
186 #ifndef USE_ROSEN_DRAWING
LoadImageData(const std::string & src,const WeakPtr<PipelineContext> context)187 sk_sp<SkData> FileImageLoader::LoadImageData(const std::string& src, const WeakPtr<PipelineContext> context)
188 #else
189 std::shared_ptr<RSData> FileImageLoader::LoadImageData(const std::string& src, const WeakPtr<PipelineContext> context)
190 #endif
191 {
192 return nullptr;
193 }
194 } // namespace OHOS::Ace
195