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