• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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 "components/ui_image_view.h"
22 #include "view_api.h"
23 
24 namespace Updater {
25 class ImgViewAdapter : public OHOS::UIImageView {
26     DISALLOW_COPY_MOVE(ImgViewAdapter);
27     class ImgAnimatorCallback;
28     static constexpr uint32_t MAX_IMG_CNT = 300;
29     static constexpr uint32_t MAX_INTERVAL_MS = 5000;
30     static constexpr uint32_t USECOND_TO_MSECOND = 1000;
31     static constexpr int ANIMATION_FILE_NAME_LENGTH = 5;
32 public:
33     using SpecificInfoType = UxImageInfo;
34     ImgViewAdapter();
35     explicit ImgViewAdapter(const UxViewInfo &info);
36     ~ImgViewAdapter();
37     bool Start();
38     bool Stop();
39 #ifdef UPDATER_UT
40     const ImgAnimatorCallback *GetAnimatorCallback() const;
41     const OHOS::Animator *GetAnimator() const;
42     uint32_t GetCurrId() const;
43 #endif
44     static bool IsValid(const UxImageInfo &info);
45 private:
46     void ShowNextImage();
47     void ThreadCb();
48     static bool IsValidForAnimator(const UxImageInfo &info);
49     static bool IsValidForStaticImg(const UxImageInfo &info);
50     bool animatorStop_ { true };
51     bool valid_ { false };
52     uint32_t currId_ { 0 };
53     uint32_t imgCnt_ { 0 };
54     uint32_t interval_ { 0 };
55     std::string currPath_ {};
56     std::string dir_ {};
57     std::string viewId_ {};
58     std::string filePrefix_ {};
59     std::unique_ptr<ImgAnimatorCallback> cb_ {};
60 };
61 } // namespace Updater
62 #endif // UPDATER_UI_ANIMATION_LABLE_H
63