1 /* 2 * Copyright (c) 2025 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 #ifndef UPDATER_UI_IMG_VIEW_ADAPTER_H 16 #define UPDATER_UI_IMG_VIEW_ADAPTER_H 17 18 #include <string> 19 #include <thread> 20 #include "animator/animator_manager.h" 21 #include "component_common.h" 22 #include "component_factory.h" 23 #include "components/ui_image_view.h" 24 #include "macros_updater.h" 25 26 namespace Updater { 27 struct UxImageInfo { 28 std::string resPath; 29 std::string filePrefix; 30 uint32_t imgCnt; 31 uint32_t updInterval; 32 }; 33 34 class ImgViewAdapter : public OHOS::UIImageView, public ComponentCommon<ImgViewAdapter, UxImageInfo> { 35 DISALLOW_COPY_MOVE(ImgViewAdapter); 36 class ImgAnimatorCallback; 37 static constexpr uint32_t MAX_IMG_CNT = 300; 38 static constexpr uint32_t MAX_INTERVAL_MS = 5000; 39 static constexpr uint32_t USECOND_TO_MSECOND = 1000; 40 static constexpr int ANIMATION_FILE_NAME_LENGTH = 5; 41 public: 42 43 static constexpr auto COMPONENT_TYPE = "UIImageView"; 44 ImgViewAdapter(); 45 explicit ImgViewAdapter(const UxViewInfo &info); 46 ~ImgViewAdapter(); 47 bool Start(); 48 bool Stop(); 49 #ifdef UPDATER_UT 50 const ImgAnimatorCallback *GetAnimatorCallback() const; 51 const OHOS::Animator *GetAnimator() const; 52 uint32_t GetCurrId() const; 53 #endif 54 static bool IsValid(const UxImageInfo &info); 55 private: 56 void GetRealImgPath(); 57 void ShowNextImage(); 58 void ThreadCb(); 59 static bool IsValidForAnimator(const UxImageInfo &info); 60 static bool IsValidForStaticImg(const UxImageInfo &info); 61 bool animatorStop_ { true }; 62 bool valid_ { false }; 63 uint32_t currId_ { 0 }; 64 uint32_t imgCnt_ { 0 }; 65 uint32_t interval_ { 0 }; 66 std::string currPath_ {}; 67 std::string dir_ {}; 68 std::string filePrefix_ {}; 69 std::unique_ptr<ImgAnimatorCallback> cb_ {}; 70 }; 71 } // namespace Updater 72 #endif // UPDATER_UI_ANIMATION_LABLE_H 73