• 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 "foundation/multimedia/image_framework/interfaces/innerkits/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 text to be displayed as the content of this message.
34      *
35      * @return Returns the message content.
36      */
37     std::string GetTitle() const;
38 
39     void SetTitle(const std::string &title);
40 
41     /**
42      * @brief Obtains the time when this message arrived.
43      *
44      * @return Returns the time when this message arrived.
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 sender of this message.
52      *
53      * @return Returns the message sender.
54      */
55     std::string GetBackgroundColor() const;
56 
57     void SetBackgroundColor(const std::string &color);
58 
59     /**
60      * @brief Returns a string representation of the object.
61      *
62      * @return Returns a string representation of the object.
63      */
64     std::string Dump();
65 
66     /**
67      * @brief Converts a NotificationConversationalMessage object into a Json.
68      *
69      * @param jsonObject Indicates the Json object.
70      * @return Returns true if succeed; returns false otherwise.
71      */
72     bool ToJson(nlohmann::json &jsonObject) const override;
73 
74     /**
75      * @brief Creates a NotificationConversationalMessage object from a Json.
76      *
77      * @param jsonObject Indicates the Json object.
78      * @return Returns the NotificationConversationalMessage.
79      */
80     static NotificationCapsule *FromJson(const nlohmann::json &jsonObject);
81 
82     /**
83      * @brief Marshal a object into a Parcel.
84      *
85      * @param parcel Indicates the object into the parcel.
86      * @return Returns true if succeed; returns false otherwise.
87      */
88     virtual bool Marshalling(Parcel &parcel) const override;
89 
90     /**
91      * @brief Unmarshal object from a Parcel.
92      *
93      * @param parcel Indicates the parcel object.
94      * @return Returns the NotificationConversationalMessage.
95      */
96     static NotificationCapsule *Unmarshalling(Parcel &parcel);
97 
98 private:
99     /**
100      * @brief Read a NotificationConversationalMessage object from a Parcel.
101      *
102      * @param parcel Indicates the parcel object.
103      * @return Returns true if succeed; returns false otherwise.
104      */
105     bool ReadFromParcel(Parcel &parcel);
106 
107 private:
108     std::string title_ {};
109     std::shared_ptr<Media::PixelMap> icon_ {};
110     std::string backgroundColor_ {};
111 };
112 }  // namespace Notification
113 }  // namespace OHOS
114 
115 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CAPSULE_H