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 CHARGER_UI_ANIMATION_LABLE_H 17 #define CHARGER_UI_ANIMATION_LABLE_H 18 #include <ctime> 19 #include <thread> 20 #include <unistd.h> 21 #include <vector> 22 #include <memory> 23 #include "frame.h" 24 #include "png.h" 25 26 namespace OHOS { 27 namespace HDI { 28 namespace Battery { 29 namespace V1_0 { 30 class AnimationLabel : public View { 31 public: 32 enum class PlayMode { 33 ANIMATION_MODE = 0, 34 STATIC_MODE, 35 }; 36 AnimationLabel(int startX, int startY, int w, int h, Frame* mParent); AnimationLabel()37 AnimationLabel() {} 38 ~AnimationLabel() override; 39 public: 40 void AddImg(const std::string& imgFileName); 41 int AddStaticImg(const std::string& imgFileName); 42 void SetStaticImg(int picId); 43 void SetPlayMode(AnimationLabel::PlayMode mode); 44 void SetInterval(int ms); 45 std::thread updateThread; 46 bool selectable = false; 47 static void SetIsVisible(const bool visible); 48 void UpdateLoop(); 49 static bool needStop_; 50 private: 51 struct PictureAttr { 52 png_uint_32 pictureWidth; 53 png_uint_32 pictureHeight; 54 png_byte pictureChannels; 55 int bitDepth; 56 int colorType; 57 }; 58 void* LoadPng(const std::string& imgFileName); 59 View::BRGA888Pixel* HandleLoadPng(FILE** fp, char** pictureBufferTmp, struct PictureAttr& attr); 60 int LoadPngInternalWithFile(FILE* fp, png_structpp pngPtr, png_infopp pngInfoPtr, struct PictureAttr& attr); 61 void CopyPictureBuffer(struct PictureAttr& attr, char* pictureBufferTmp, BRGA888Pixel* pictureBuffer) const; 62 Frame* parent_ {}; 63 int intervalMs_ = 50; 64 std::vector<char*> imgList_ {}; 65 char* staticImgList_[255] {}; 66 int staticShowId_ = 0; 67 bool showStatic_ = false; 68 int staticImgSize_ = 0; 69 static bool isVisible_; 70 }; 71 } // namespace V1_0 72 } // namespace Battery 73 } // namespace HDI 74 } // namespace OHOS 75 #endif // CHARGER_UI_ANIMATION_LABLE_H 76