• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_ICON_BUTTON_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_ICON_BUTTON_H
18 
19 #include "notification_json_convert.h"
20 #include "resource_manager.h"
21 #include "parcel.h"
22 #include <string>
23 #include <vector>
24 #include "pixel_map.h"
25 namespace OHOS {
26 namespace Notification {
27 using namespace Global::Resource;
28 const uint32_t BUTTON_MAX_SIZE = 3;
29 const uint32_t CAPSULE_BTN_MAX_SIZE = 2;
30 const uint32_t BUTTON_RESOURCE_SIZE = 3;
31 const uint32_t RESOURCE_BUNDLENAME_INDEX = 0;
32 const uint32_t RESOURCE_MODULENAME_INDEX = 1;
33 const uint32_t RESOURCE_ID_INDEX = 2;
34 
35 class NotificationIconButton : public Parcelable, public NotificationJsonConvertionBase {
36 public:
37     NotificationIconButton() = default;
38     ~NotificationIconButton() = default;
39 
40     /**
41      * @brief Obtains the icon of the notification capsule.
42      *
43      * @return Returns the icon of the notification capsule.
44      */
45     const std::shared_ptr<ResourceManager::Resource> GetIconResource() const;
46 
47     void SetIconResource(const std::shared_ptr<ResourceManager::Resource> &iconResource);
48 
49     const std::shared_ptr<Media::PixelMap> GetIconImage() const;
50 
51     void SetIconImage(const std::shared_ptr<Media::PixelMap> &iconImage);
52 
53     /**
54      * @brief Obtains the text of the notification button.
55      *
56      * @return Returns the text of the notification button.
57      */
58     std::string GetText() const;
59 
60     void SetText(const std::string &text);
61 
62     /**
63      * @brief Obtains the unqiue name of the notification button.
64      *
65      * @return Returns the unqiue name of the notification button.
66      */
67     std::string GetName() const;
68 
69     void SetName(const std::string &name);
70 
71     /**
72      * @brief Obtains the hidePanel of the notification button.
73      *
74      * @return Returns the hidePanel of the notification button.
75      */
76     bool GetHidePanel() const;
77 
78     void SetHidePanel(bool hidePanel);
79 
80     /**
81      * @brief Returns a string representation of the object.
82      *
83      * @return Returns a string representation of the object.
84      */
85     std::string Dump();
86 
87     /**
88      * @brief Converts a notification capsule object into a Json.
89      *
90      * @param jsonObject Indicates the Json object.
91      * @return Returns true if succeed; returns false otherwise.
92      */
93     bool ToJson(nlohmann::json &jsonObject) const override;
94 
95     /**
96      * @brief Creates a notification capsule object from a Json.
97      *
98      * @param jsonObject Indicates the Json object.
99      * @return Returns the notification capsule.
100      */
101     static NotificationIconButton *FromJson(const nlohmann::json &jsonObject);
102 
103     /**
104      * @brief Marshal a object into a Parcel.
105      *
106      * @param parcel Indicates the object into the parcel.
107      * @return Returns true if succeed; returns false otherwise.
108      */
109     virtual bool Marshalling(Parcel &parcel) const override;
110 
111     /**
112      * @brief Unmarshal object from a Parcel.
113      *
114      * @param parcel Indicates the parcel object.
115      * @return Returns the notification capsule.
116      */
117     static NotificationIconButton *Unmarshalling(Parcel &parcel);
118 
119     void ClearButtonIconsResource();
120 
121     bool WriteIconToParcel(Parcel &parcel) const;
122 
123     bool ReadResourceFromParcel(Parcel &parcel, std::shared_ptr<ResourceManager::Resource> &resourceObj);
124 private:
125 
126     /**
127      * @brief Read a NotificationConversationalMessage object from a Parcel.
128      *
129      * @param parcel Indicates the parcel object.
130      * @return Returns true if succeed; returns false otherwise.
131      */
132     bool ReadFromParcel(Parcel &parcel);
133     static bool ResourceFromJson(const nlohmann::json &resource,
134         std::shared_ptr<ResourceManager::Resource>& resourceObj);
135 private:
136     std::string text_ {};
137     std::string name_ {};
138     std::shared_ptr<ResourceManager::Resource> iconResource_ {};
139     std::shared_ptr<Media::PixelMap> iconImage_ {};
140     bool hidePanel_;
141 };
142 }  // namespace Notification
143 }  // namespace OHOS
144 #endif  //BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_ICON_BUTTON_H
145