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 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_PICKER_ANIMATION_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_PICKER_ANIMATION_H 18 19 #include "core/animation/animator.h" 20 #include "core/animation/curve.h" 21 #include "core/animation/curve_animation.h" 22 #include "core/animation/curves.h" 23 #include "core/pipeline/pipeline_base.h" 24 25 namespace OHOS::Ace { 26 27 class PickerAnimation : public virtual AceType { 28 DECLARE_ACE_TYPE(PickerAnimation, AceType); 29 30 public: 31 PickerAnimation() = delete; 32 ~PickerAnimation() = default; PickerAnimation(const WeakPtr<PipelineBase> & pipe,double start,double end,int delay,int duration,const RefPtr<Curve> & curve,const std::function<void (double)> & callback)33 PickerAnimation(const WeakPtr<PipelineBase>& pipe, double start, double end, int delay, int duration, 34 const RefPtr<Curve>& curve, const std::function<void(double)>& callback) 35 : start_(start), end_(end), delay_(delay), duration_(duration), pipe_(pipe), curve_(curve), callback_(callback) 36 { 37 Init(); 38 } 39 40 void Play(); 41 42 void Stop(); 43 AddStopCallback(const std::function<void ()> & value)44 void AddStopCallback(const std::function<void()>& value) 45 { 46 if (controller_) { 47 controller_->AddStopListener(value); 48 } 49 } 50 ClearStopCallback()51 void ClearStopCallback() 52 { 53 if (!controller_) { 54 return; 55 } 56 controller_->ClearStopListeners(); 57 } 58 59 private: 60 void Init(); 61 62 double start_ = 0.0; 63 double end_ = 0.0; 64 int delay_ = 0; 65 int duration_ = 0; 66 67 WeakPtr<PipelineBase> pipe_; 68 RefPtr<Curve> curve_; 69 std::function<void(double)> callback_; 70 RefPtr<CurveAnimation<double>> animation_; 71 RefPtr<Animator> controller_; 72 }; 73 74 } // namespace OHOS::Ace 75 76 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PICKER_PICKER_ANIMATION_H 77