1 /* 2 * Copyright (c) 2021-2022 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_LONG_TEXT_CONTENT_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_LONG_TEXT_CONTENT_H 18 19 #include "notification_basic_content.h" 20 #include "parcel.h" 21 22 namespace OHOS { 23 namespace Notification { 24 class NotificationLongTextContent : public NotificationBasicContent { 25 public: 26 NotificationLongTextContent() = default; 27 28 /** 29 * @brief A constructor used to create a NotificationLongTextContent instance with the input parameter longText 30 * passed. 31 * 32 * @param longText Indicates the long text to be included. The value contains a maximum of 1024 characters. 33 */ 34 explicit NotificationLongTextContent(const std::string &longText); 35 36 ~NotificationLongTextContent() = default; 37 38 /** 39 * @brief Sets the title to be displayed when this long text notification is expanded. After this title is set, 40 * the title set by setTitle(string) will be displayed only when this notification is in the collapsed state. 41 * 42 * @param exTitle Indicates the title to be displayed when this notification is expanded. 43 */ 44 void SetExpandedTitle(const std::string &exTitle); 45 46 /** 47 * @brief Obtains the title that will be displayed for this long text notification when it is expanded. 48 * 49 * @return Returns the title to be displayed when this notification is expanded. 50 */ 51 std::string GetExpandedTitle() const; 52 53 /** 54 * @brief Sets the brief text to be included in a long text notification. 55 * The brief text is a summary of a long text notification and is displayed in the first line of the notification. 56 * Similar to setAdditionalText(string), the font of the brief text is also smaller than the notification text. 57 * The positions where the brief text and additional text will display may conflict. 58 * If both texts are set, only the additional text will be displayed. 59 * 60 * @param briefText Indicates the brief text to be included. 61 */ 62 void SetBriefText(const std::string &briefText); 63 64 /** 65 * @brief Obtains the brief text of a long text notification specified by calling the setBriefText(string) method. 66 * 67 * @return Returns the brief text of the long text notification. 68 */ 69 std::string GetBriefText() const; 70 71 /** 72 * @brief Sets the long text to be included in a long text notification. 73 * 74 * @param longText Indicates the long text to be included. The value contains a maximum of 1024 characters. 75 */ 76 void SetLongText(const std::string &longText); 77 78 /** 79 * @brief Obtains a notification's long text, which is set by calling the setLongText(string) method. 80 * 81 * @return Returns the long text. 82 */ 83 std::string GetLongText() const; 84 85 /** 86 * @brief Returns a string representation of the object. 87 * 88 * @return Returns a string representation of the object. 89 */ 90 std::string Dump() override; 91 92 /** 93 * @brief Converts a NotificationLongTextContent object into a Json. 94 * 95 * @param jsonObject Indicates the Json object. 96 * @return Returns true if succeed; returns false otherwise. 97 */ 98 bool ToJson(nlohmann::json &jsonObject) const override; 99 100 /** 101 * @brief Creates a NotificationLongTextContent object from a Json. 102 * 103 * @param jsonObject Indicates the Json object. 104 * @return Returns the NotificationLongTextContent. 105 */ 106 static NotificationLongTextContent *FromJson(const nlohmann::json &jsonObject); 107 108 /** 109 * @brief Marshal a object into a Parcel. 110 * 111 * @param parcel Indicates the object into the parcel. 112 * @return Returns true if succeed; returns false otherwise. 113 */ 114 virtual bool Marshalling(Parcel &parcel) const override; 115 116 /** 117 * @brief Unmarshal object from a Parcel. 118 * 119 * @param parcel Indicates the parcel object. 120 * @return Returns the NotificationLongTextContent object. 121 */ 122 static NotificationLongTextContent *Unmarshalling(Parcel &parcel); 123 124 protected: 125 /** 126 * @brief Read a NotificationLongTextContent object from a Parcel. 127 * 128 * @param parcel Indicates the parcel object. 129 * @return Returns true if succeed; returns false otherwise. 130 */ 131 bool ReadFromParcel(Parcel &parcel) override; 132 133 private: 134 /** 135 * the maximum length of longtext is 1024 characters. 136 */ 137 static const std::size_t MAX_LONGTEXT_LENGTH; 138 139 private: 140 std::string longText_ {}; 141 std::string expandedTitle_ {}; 142 std::string briefText_ {}; 143 }; 144 } // namespace Notification 145 } // namespace OHOS 146 147 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_LONG_TEXT_CONTENT_H