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_MULTILINE_CONTENT_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_MULTILINE_CONTENT_H 18 19 #include "notification_basic_content.h" 20 #include "parcel.h" 21 22 namespace OHOS { 23 namespace Notification { 24 class NotificationMultiLineContent : public NotificationBasicContent { 25 public: 26 NotificationMultiLineContent() = default; 27 28 ~NotificationMultiLineContent() = default; 29 30 /** 31 * @brief Sets the title to be displayed when this multi-line notification is expanded. 32 * After this title is set, the title set by setTitle(string) will be displayed only 33 * when this notification is in the collapsed state. 34 * 35 * @param exTitle Indicates the title to be displayed when this notification is expanded. 36 */ 37 void SetExpandedTitle(const std::string &exTitle); 38 39 /** 40 * @brief Obtains the title that will be displayed for this multi-line notification when it is expanded. 41 * 42 * @return Returns the title to be displayed when this notification is expanded. 43 */ 44 std::string GetExpandedTitle() const; 45 46 /** 47 * @brief Sets the brief text to be included in a multi-line notification. 48 * The brief text is a summary of this multi-line notification and is displayed in the first line of 49 * the notification. Similar to setAdditionalText(string), the font of the brief text is also 50 * smaller than the notification text set by calling setText(string). 51 * The positions where the brief text and additional text will display may conflict. 52 * If both texts are set, only the additional text will be displayed. 53 * 54 * @param briefText Indicates the brief text to be included. 55 */ 56 void SetBriefText(const std::string &briefText); 57 58 /** 59 * @brief Obtains the brief text that has been set by calling setBriefText(string) for this multi-line notification. 60 * 61 * @return Returns the brief text of this notification. 62 */ 63 std::string GetBriefText() const; 64 65 /** 66 * @brief Adds a single line of text to this notification. 67 * You can call this method up to seven times to add seven lines to a notification. 68 * 69 * @param oneLine Indicates the single line of text to be included. 70 */ 71 void AddSingleLine(const std::string &oneLine); 72 73 /** 74 * @brief Obtains the list of lines included in this multi-line notification. 75 * 76 * @return Returns the list of lines included in this notification. 77 */ 78 std::vector<std::string> GetAllLines() const; 79 80 /** 81 * @brief Returns a string representation of the object. 82 * 83 * @return Returns a string representation of the object. 84 */ 85 std::string Dump() override; 86 87 /** 88 * @brief Converts a NotificationMultiLineContent object into a Json. 89 * 90 * @param jsonObject Indicates the Json object. 91 * @return Returns true if succeed; returns false otherwise. 92 */ 93 virtual bool ToJson(nlohmann::json &jsonObject) const override; 94 95 /** 96 * @brief Creates a NotificationMultiLineContent object from a Json. 97 * 98 * @param jsonObject Indicates the Json object. 99 * @return Returns the NotificationMultiLineContent object. 100 */ 101 static NotificationMultiLineContent *FromJson(const nlohmann::json &jsonObject); 102 103 /** 104 * @brief Marshal a object into a Parcel. 105 * 106 * @param parcel the object into the parcel. 107 * @return Returns true if succeed; returns false otherwise. 108 */ 109 virtual bool Marshalling(Parcel &parcel) const override; 110 111 /** 112 * @brief Unmarshal object from a Parcel. 113 * 114 * @param parcel Indicates the parcel object. 115 * @return Returns the NotificationMultiLineContent object. 116 */ 117 static NotificationMultiLineContent *Unmarshalling(Parcel &parcel); 118 119 protected: 120 /** 121 * @brief Read a NotificationMultiLineContent object from a Parcel. 122 * 123 * @param parcel Indicates the parcel object. 124 * @return Returns true if succeed; returns false otherwise. 125 */ 126 bool ReadFromParcel(Parcel &parcel) override; 127 128 private: 129 /** 130 * the maximum size of vector is 7. 131 */ 132 static const std::vector<std::string>::size_type MAX_LINES; 133 134 private: 135 std::string expandedTitle_ {}; 136 std::string briefText_ {}; 137 std::vector<std::string> allLines_ {}; 138 }; 139 } // namespace Notification 140 } // namespace OHOS 141 142 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_NOTIFICATION_MULTILINE_CONTENT_H