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_NOTIFICATION_BASIC_CONTENT_H
17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_BASIC_CONTENT_H
18 
19 #include "notification_json_convert.h"
20 #include "parcel.h"
21 #include "pixel_map.h"
22 
23 namespace OHOS {
24 namespace Notification {
25 class NotificationBasicContent : public Parcelable, public NotificationJsonConvertionBase {
26 public:
27     virtual ~NotificationBasicContent();
28 
29     /**
30      * @brief Sets the additional text to be included in a notification.
31      * The additional text is mainly a supplement to the notification text set by calling setText(std::string).
32      * The font of the additional text is smaller than the notification text and is displayed in a separate line.
33      *
34      * @param text Indicates the additional text to be included.
35      */
36     virtual void SetAdditionalText(const std::string &additionalText);
37 
38     /**
39      * @brief Obtains the additional text of a notification specified by calling setAdditionalText(std::string).
40      *
41      * @return Returns the additional text of the notification.
42      */
43     virtual std::string GetAdditionalText() const;
44 
45     /**
46      * @brief Sets the text to be included in a notification.
47      *
48      * @param text Indicates the text to be included.
49      */
50     virtual void SetText(const std::string &text);
51 
52     /**
53      * @brief Obtains the text of a notification specified by calling setText(std::string).
54      *
55      * @return Returns the text of the notification.
56      */
57     virtual std::string GetText() const;
58 
59     /**
60      * @brief Sets the title of a notification.
61      *
62      * @param title Indicates the title of the notification.
63      */
64     virtual void SetTitle(const std::string &title);
65 
66     /**
67      * @brief Obtains the title of a notification specified by calling the setTitle(std::string) method.
68      *
69      * @return Returns the title of the notification.
70      */
71     virtual std::string GetTitle() const;
72 
73     /**
74      * @brief Sets the lockScreenPicture of a notification.
75      *
76      * @param lockScreenPicture Indicates the lockScreenPicture of the notification.
77      */
78     virtual void SetLockScreenPicture(const std::shared_ptr<Media::PixelMap> &lockScreenPicture);
79 
80     /**
81      * @brief Obtains the lockScreenPicture of a notification.
82      *
83      * @return Returns the lockScreenPicture_ of the notification.
84      */
85     virtual std::shared_ptr<Media::PixelMap> GetLockScreenPicture() const;
86 
87     /**
88      * @brief Returns a string representation of the object.
89      *
90      * @return Returns a string representation of the object.
91      */
92     virtual std::string Dump();
93 
94     /**
95      * @brief Converts a NotificationBasicContent object into a Json.
96      *
97      * @param jsonObject Indicates the Json object.
98      * @return Returns true if succeed; returns false otherwise.
99      */
100     virtual bool ToJson(nlohmann::json &jsonObject) const override;
101 
102     /**
103      * @brief Marshal a object into a Parcel.
104      *
105      * @param parcel the object into the parcel.
106      * @return Returns true if succeed; returns false otherwise.
107      */
108     virtual bool Marshalling(Parcel &parcel) const override;
109 
SetContentType(int32_t type)110     inline void SetContentType(int32_t type)
111     {
112         contentType_ = type;
113     }
114 
115 protected:
116     NotificationBasicContent() = default;
117 
118     /**
119      * @brief Read data from a Parcel.
120      *
121      * @param parcel Indicates the parcel object.
122      * @return Returns true if read success; returns false otherwise.
123      */
124     virtual bool ReadFromParcel(Parcel &parcel);
125 
126     /**
127      * @brief Creates a NotificationBasicContent object from a Json.
128      *
129      * @param jsonObject Indicates the Json object.
130      */
131     void ReadFromJson(const nlohmann::json &jsonObject);
132 
133 protected:
134     std::string text_ {};
135     std::string title_ {};
136     std::string additionalText_ {};
137     std::shared_ptr<Media::PixelMap> lockScreenPicture_ {};
138     int32_t contentType_;
139 };
140 }  // namespace Notification
141 }  // namespace OHOS
142 
143 #endif  // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_BASIC_CONTENT_H
144