• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_CALLBACK_H
17 #define RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_CALLBACK_H
18 
19 #include <functional>
20 #include <utility>
21 
22 #include "animation/rs_animation_timing_protocol.h"
23 #include "common/rs_macros.h"
24 
25 namespace OHOS {
26 namespace Rosen {
27 class RSC_EXPORT AnimationCallback {
28 public:
29     explicit AnimationCallback(const std::function<void()>&& callback);
30     virtual ~AnimationCallback();
31 
32 protected:
33     std::function<void()> callback_;
34 };
35 
36 class RSC_EXPORT AnimationFinishCallback : public AnimationCallback {
37 public:
38     AnimationFinishCallback(
39         std::function<void()> callback, FinishCallbackType finishCallbackType = FinishCallbackType::TIME_SENSITIVE);
40     ~AnimationFinishCallback() override = default;
41     // Execute the callback function immediately, can only be called once.
42     void Execute();
43     bool IsValid();
SetAnimationBeenPaused()44     void SetAnimationBeenPaused()
45     {
46         hasAnimationBeenPaused = true;
47     }
HasAnimationBeenPaused()48     bool HasAnimationBeenPaused()
49     {
50         return hasAnimationBeenPaused;
51     }
52 
53     const FinishCallbackType finishCallbackType_;
54 private:
55     bool hasAnimationBeenPaused = false;
56 };
57 
58 class RSC_EXPORT AnimationRepeatCallback {
59 public:
AnimationRepeatCallback(std::function<void ()> callback)60     AnimationRepeatCallback(std::function<void()> callback) : callback_(std::move(callback)) {}
61     ~AnimationRepeatCallback() = default;
62     // Execute the callback function, can be called repeatedly.
63     void Execute();
64 
65 protected:
66     std::function<void()> callback_;
67 };
68 
69 class RSC_EXPORT InteractiveAnimatorFinishCallback : public AnimationCallback {
70 public:
71     InteractiveAnimatorFinishCallback(std::function<void()> callback);
72     ~InteractiveAnimatorFinishCallback() override = default;
73 };
74 } // namespace Rosen
75 } // namespace OHOS
76 
77 #endif // RENDER_SERVICE_CLIENT_CORE_ANIMATION_RS_ANIMATION_CALLBACK_H
78