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