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