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 BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CAPSULE_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CAPSULE_H
18 
19 #include "pixel_map.h"
20 #include "notification_json_convert.h"
21 #include "parcel.h"
22 #include <string>
23 
24 namespace OHOS {
25 namespace Notification {
26 class NotificationCapsule : public Parcelable, public NotificationJsonConvertionBase {
27 public:
28     NotificationCapsule() = default;
29 
30     ~NotificationCapsule() = default;
31 
32     /**
33      * @brief Obtains the title of the notification capsule.
34      *
35      * @return Returns the title of the notification capsule.
36      */
37     std::string GetTitle() const;
38 
39     void SetTitle(const std::string &title);
40 
41     /**
42      * @brief Obtains the icon of the notification capsule.
43      *
44      * @return Returns the icon of the notification capsule.
45      */
46     const std::shared_ptr<Media::PixelMap> GetIcon() const;
47 
48     void SetIcon(const std::shared_ptr<Media::PixelMap> &icon);
49 
50     /**
51      * @brief Obtains the backgroundcolor of the notification capsule.
52      *
53      * @return Returns the backgroundcolor of the notification capsule.
54      */
55     std::string GetBackgroundColor() const;
56 
57     void SetBackgroundColor(const std::string &color);
58 
59     /**
60      * @brief Obtains the content of the notification capsule.
61      *
62      * @return Returns the content of the notification capsule.
63      */
64     std::string GetContent() const;
65 
66     void SetContent(const std::string &content);
67 
68     /**
69      * @brief Returns a string representation of the object.
70      *
71      * @return Returns a string representation of the object.
72      */
73     std::string Dump();
74 
75     /**
76      * @brief Converts a notification capsule object into a Json.
77      *
78      * @param jsonObject Indicates the Json object.
79      * @return Returns true if succeed; returns false otherwise.
80      */
81     bool ToJson(nlohmann::json &jsonObject) const override;
82 
83     /**
84      * @brief Creates a notification capsule object from a Json.
85      *
86      * @param jsonObject Indicates the Json object.
87      * @return Returns the notification capsule.
88      */
89     static NotificationCapsule *FromJson(const nlohmann::json &jsonObject);
90 
91     /**
92      * @brief Marshal a object into a Parcel.
93      *
94      * @param parcel Indicates the object into the parcel.
95      * @return Returns true if succeed; returns false otherwise.
96      */
97     virtual bool Marshalling(Parcel &parcel) const override;
98 
99     /**
100      * @brief Unmarshal object from a Parcel.
101      *
102      * @param parcel Indicates the parcel object.
103      * @return Returns the notification capsule.
104      */
105     static NotificationCapsule *Unmarshalling(Parcel &parcel);
106 
107     void ResetIcon();
108 
109 private:
110 
111     /**
112      * @brief Read a NotificationConversationalMessage object from a Parcel.
113      *
114      * @param parcel Indicates the parcel object.
115      * @return Returns true if succeed; returns false otherwise.
116      */
117     bool ReadFromParcel(Parcel &parcel);
118 
119 private:
120     std::string title_ {};
121     std::string backgroundColor_ {};
122     std::string content_ {};
123     std::shared_ptr<Media::PixelMap> icon_ {};
124 };
125 }  // namespace Notification
126 }  // namespace OHOS
127 
128 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CAPSULE_H
129