• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 ANIMATION_CONFIG_H
17 #define ANIMATION_CONFIG_H
18 
19 #include <fstream>
20 #include <memory>
21 #include <mutex>
22 #include <string>
23 
24 #include <cJSON.h>
25 #include "nocopyable.h"
26 
27 namespace OHOS {
28 namespace PowerMgr {
29 struct CommonInfo {
30     int x;
31     int y;
32     int w;
33     int h;
34     std::string id;
35     std::string type;
36     bool visible;
37 };
38 
39 struct LabelComponentInfo {
40     uint8_t fontSize;
41     std::string text;
42     std::string align;
43     std::string fontColor;
44     std::string bgColor;
45     struct CommonInfo common;
46 };
47 
48 struct ImageComponentInfo {
49     std::string resPath;
50     std::string filePrefix;
51     uint32_t imgCnt;
52     uint32_t updInterval;
53     struct CommonInfo common;
54 };
55 
56 class AnimationConfig : public NoCopyable {
57 public:
58     bool ParseConfig();
59     std::pair<ImageComponentInfo, LabelComponentInfo> GetCharingAnimationInfo();
60     LabelComponentInfo GetCharingPromptInfo();
61     LabelComponentInfo GetNotCharingPromptInfo();
62 
~AnimationConfig()63     ~AnimationConfig()
64     {
65         if (configObj_) {
66             cJSON_Delete(configObj_);
67             configObj_ = nullptr;
68         }
69     }
70 
71 private:
72     void ParseAnimationConfig(cJSON* jsonObj);
73     void ParseLackPowerChargingConfig(cJSON* jsonObj);
74     void ParseLackPowerNotChargingConfig(cJSON* jsonObj);
75     void ParseAnimationImage(cJSON* component, ImageComponentInfo& info);
76     void ParseAnimationLabel(cJSON* component, LabelComponentInfo& info);
77     std::pair<ImageComponentInfo, LabelComponentInfo> animationInfo_;
78     LabelComponentInfo chargingInfo_;
79     LabelComponentInfo notChargingInfo_;
80     cJSON* configObj_ = nullptr;
81 };
82 } // namespace PowerMgr
83 } // namespace OHOS
84 #endif
85