1 /* 2 * Copyright (c) 2024 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 COMPONENT_EXT_MOVING_PHOTO_MOVING_PHOTO_EVENT_HUB_H 17 #define COMPONENT_EXT_MOVING_PHOTO_MOVING_PHOTO_EVENT_HUB_H 18 19 #include <functional> 20 21 #include "base/memory/ace_type.h" 22 #include "core/common/recorder/event_recorder.h" 23 #include "core/components_ng/base/frame_node.h" 24 #include "core/components_ng/event/event_hub.h" 25 #include "core/components_ng/event/gesture_event_hub.h" 26 27 namespace OHOS::Ace::NG { 28 29 using MovingPhotoEventFunc = std::function<void()>; 30 31 class MovingPhotoEventHub : public EventHub { 32 DECLARE_ACE_TYPE(MovingPhotoEventHub, EventHub) 33 34 public: 35 MovingPhotoEventHub() = default; 36 ~MovingPhotoEventHub() override = default; 37 SetOnComplete(MovingPhotoEventFunc && onComplete)38 void SetOnComplete(MovingPhotoEventFunc&& onComplete) 39 { 40 onComplete_ = std::move(onComplete); 41 } 42 GetOnComplete()43 MovingPhotoEventFunc GetOnComplete() 44 { 45 return onComplete_; 46 } 47 FireCompleteEvent()48 void FireCompleteEvent() 49 { 50 if (onComplete_) { 51 onComplete_(); 52 } 53 } 54 SetOnStart(MovingPhotoEventFunc && onStart)55 void SetOnStart(MovingPhotoEventFunc&& onStart) 56 { 57 onStart_ = std ::move(onStart); 58 } 59 GetOnStart()60 MovingPhotoEventFunc GetOnStart() 61 { 62 return onStart_; 63 } 64 FireStartEvent()65 void FireStartEvent() 66 { 67 if (onStart_) { 68 auto onStart = onStart_; 69 onStart(); 70 } 71 } 72 SetOnPause(MovingPhotoEventFunc && onPause)73 void SetOnPause(MovingPhotoEventFunc&& onPause) 74 { 75 onPause_ = std ::move(onPause); 76 } 77 FirePauseEvent()78 void FirePauseEvent() 79 { 80 if (onPause_) { 81 auto onPause = onPause_; 82 onPause(); 83 } 84 } 85 SetOnStop(MovingPhotoEventFunc && onStop)86 void SetOnStop(MovingPhotoEventFunc&& onStop) 87 { 88 onStop_ = std ::move(onStop); 89 } 90 GetOnStop()91 MovingPhotoEventFunc GetOnStop() 92 { 93 return onStop_; 94 } 95 FireStopEvent()96 void FireStopEvent() 97 { 98 if (onStop_) { 99 auto onStop = onStop_; 100 onStop(); 101 } 102 } 103 SetOnFinish(MovingPhotoEventFunc && onFinish)104 void SetOnFinish(MovingPhotoEventFunc&& onFinish) 105 { 106 onFinish_ = std ::move(onFinish); 107 } 108 GetOnFinish()109 MovingPhotoEventFunc GetOnFinish() 110 { 111 return onFinish_; 112 } 113 FireFinishEvent()114 void FireFinishEvent() 115 { 116 if (onFinish_) { 117 auto onFinish = onFinish_; 118 onFinish(); 119 } 120 } 121 SetOnError(MovingPhotoEventFunc && onError)122 void SetOnError(MovingPhotoEventFunc&& onError) 123 { 124 onError_ = std ::move(onError); 125 } 126 GetOnError()127 MovingPhotoEventFunc GetOnError() 128 { 129 return onError_; 130 } 131 FireErrorEvent()132 void FireErrorEvent() 133 { 134 if (onError_) { 135 auto onError = onError_; 136 onError(); 137 } 138 } 139 140 private: 141 MovingPhotoEventFunc onComplete_; 142 MovingPhotoEventFunc onStart_; 143 MovingPhotoEventFunc onStop_; 144 MovingPhotoEventFunc onPause_; 145 MovingPhotoEventFunc onFinish_; 146 MovingPhotoEventFunc onError_; 147 }; 148 149 } // namespace OHOS::Ace::NG 150 151 #endif // COMPONENT_EXT_MOVING_PHOTO_MOVING_PHOTO_EVENT_HUB_H 152