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_CONTROLLER_H 17 #define COMPONENT_EXT_MOVING_PHOTO_MOVING_PHOTO_CONTROLLER_H 18 19 #include <functional> 20 21 #include "base/memory/ace_type.h" 22 23 namespace OHOS::Ace::NG { 24 25 class MovingPhotoController : public virtual AceType { 26 DECLARE_ACE_TYPE(MovingPhotoController, AceType); 27 28 public: 29 MovingPhotoController() = default; 30 ~MovingPhotoController() override = default; 31 32 using StartPlaybackImpl = std::function<void()>; 33 using StopPlaybackImpl = std::function<void()>; 34 using RefreshMovingPhotoImpl = std::function<void()>; 35 using PauseImpl = std::function<void()>; 36 using ResetImpl = std::function<void()>; 37 using RestartImpl = std::function<void()>; 38 using EnableTransitionImpl = std::function<void(bool)>; 39 using SetPlaybackPeriodFucImpl = std::function<void(int64_t, int64_t)>; 40 using EnableAutoPlayImpl = std::function<void(bool)>; 41 using NotifyTransitionImpl = std::function<void()>; 42 SetStartPlaybackImpl(StartPlaybackImpl && startPlaybackImpl)43 void SetStartPlaybackImpl(StartPlaybackImpl&& startPlaybackImpl) 44 { 45 startPlaybackImpl_ = std::move(startPlaybackImpl); 46 } 47 StartPlayback()48 void StartPlayback() 49 { 50 if (startPlaybackImpl_) { 51 startPlaybackImpl_(); 52 } 53 } 54 SetStopPlaybackImpl(StopPlaybackImpl && stopPlaybackImpl)55 void SetStopPlaybackImpl(StopPlaybackImpl&& stopPlaybackImpl) 56 { 57 stopPlaybackImpl_ = std::move(stopPlaybackImpl); 58 } 59 StopPlayback()60 void StopPlayback() 61 { 62 if (stopPlaybackImpl_) { 63 stopPlaybackImpl_(); 64 } 65 } 66 SetRefreshMovingPhotoImpl(RefreshMovingPhotoImpl && refreshMovingPhotoImpl)67 void SetRefreshMovingPhotoImpl(RefreshMovingPhotoImpl&& refreshMovingPhotoImpl) 68 { 69 refreshMovingPhotoImpl_ = std::move(refreshMovingPhotoImpl); 70 } 71 RefreshMovingPhoto()72 void RefreshMovingPhoto() 73 { 74 if (refreshMovingPhotoImpl_) { 75 refreshMovingPhotoImpl_(); 76 } 77 } 78 SetPauseImpl(PauseImpl && pauseImpl)79 void SetPauseImpl(PauseImpl&& pauseImpl) 80 { 81 pauseImpl_ = std::move(pauseImpl); 82 } 83 Pause()84 void Pause() 85 { 86 if (pauseImpl_) { 87 pauseImpl_(); 88 } 89 } 90 SetResetImpl(ResetImpl && resetImpl)91 void SetResetImpl(ResetImpl&& resetImpl) 92 { 93 resetImpl_ = std::move(resetImpl); 94 } 95 Reset()96 void Reset() 97 { 98 if (resetImpl_) { 99 resetImpl_(); 100 } 101 } 102 SetRestartImpl(RestartImpl && restartImpl)103 void SetRestartImpl(RestartImpl&& restartImpl) 104 { 105 restartImpl_ = std::move(restartImpl); 106 } 107 Restart()108 void Restart() 109 { 110 if (restartImpl_) { 111 restartImpl_(); 112 } 113 } 114 SetPlaybackPeriodImpl(SetPlaybackPeriodFucImpl && setPlaybackPeriodImpl)115 void SetPlaybackPeriodImpl(SetPlaybackPeriodFucImpl&& setPlaybackPeriodImpl) 116 { 117 setPlaybackPeriodFucImpl_ = std::move(setPlaybackPeriodImpl); 118 } 119 SetPlaybackPeriod(int64_t startTime,int64_t endTime)120 void SetPlaybackPeriod(int64_t startTime, int64_t endTime) 121 { 122 if (setPlaybackPeriodFucImpl_) { 123 setPlaybackPeriodFucImpl_(startTime, endTime); 124 } 125 } 126 SetEnableTransitionImpl(EnableTransitionImpl && enableTransitionImpl)127 void SetEnableTransitionImpl(EnableTransitionImpl&& enableTransitionImpl) 128 { 129 enableTransitionImpl_ = std::move(enableTransitionImpl); 130 } 131 EnableTransition(bool enabled)132 void EnableTransition(bool enabled) 133 { 134 if (enableTransitionImpl_) { 135 enableTransitionImpl_(enabled); 136 } 137 } 138 SetEnableAutoPlayImpl(EnableAutoPlayImpl && enableAutoPlayImpl)139 void SetEnableAutoPlayImpl(EnableAutoPlayImpl&& enableAutoPlayImpl) 140 { 141 enableAutoPlayImpl_ = std::move(enableAutoPlayImpl); 142 } 143 EnableAutoPlay(bool enabled)144 void EnableAutoPlay(bool enabled) 145 { 146 if (enableAutoPlayImpl_) { 147 enableAutoPlayImpl_(enabled); 148 } 149 } 150 SetNotifyTransitionImpl(NotifyTransitionImpl && notifyTransitionImpl)151 void SetNotifyTransitionImpl(NotifyTransitionImpl&& 152 notifyTransitionImpl) 153 { 154 notifyTransitionImpl_ = std::move(notifyTransitionImpl); 155 } 156 NotifyTransition()157 void NotifyTransition() 158 { 159 if (notifyTransitionImpl_) { 160 notifyTransitionImpl_(); 161 } 162 } 163 164 private: 165 StartPlaybackImpl startPlaybackImpl_; 166 StopPlaybackImpl stopPlaybackImpl_; 167 RefreshMovingPhotoImpl refreshMovingPhotoImpl_; 168 PauseImpl pauseImpl_; 169 ResetImpl resetImpl_; 170 RestartImpl restartImpl_; 171 EnableTransitionImpl enableTransitionImpl_; 172 SetPlaybackPeriodFucImpl setPlaybackPeriodFucImpl_; 173 EnableAutoPlayImpl enableAutoPlayImpl_; 174 NotifyTransitionImpl notifyTransitionImpl_; 175 }; 176 177 } // namespace OHOS::Ace::NG 178 179 #endif // COMPONENT_EXT_MOVING_PHOTO_MOVING_PHOTO_CONTROLLER_H