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_LOCAL_LIVE_VIEW_CONTENT_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_LIVE_VIEW_CONTENT_H 18 19 #include "notification_capsule.h" 20 #include "notification_progress.h" 21 #include "notification_local_live_view_button.h" 22 #include "message_user.h" 23 #include "notification_basic_content.h" 24 #include "notification_conversational_message.h" 25 #include "notification_json_convert.h" 26 #include "notification_time.h" 27 #include "parcel.h" 28 #include <vector> 29 30 namespace OHOS { 31 namespace Notification { 32 class NotificationLocalLiveViewContent : public NotificationBasicContent { 33 public: 34 enum LiveViewContentInner { 35 CAPSULE = 1, 36 BUTTON, 37 PROGRESS, 38 TIME, 39 INITIAL_TIME, 40 }; 41 42 NotificationLocalLiveViewContent() = default; 43 ~NotificationLocalLiveViewContent() = default; 44 45 /* 46 * @brief Sets the type to be included in a local live view notification. 47 * 48 * @param type Indicates the type to be included. 49 */ 50 void SetType(int32_t type); 51 52 /* 53 * @brief Get the type of a local live view notification. 54 * 55 */ 56 int32_t GetType(); 57 58 /* 59 * @brief Sets the capsule to be included in a local live view notification. 60 * 61 * @param capsule Indicates the type to be included. 62 */ 63 void SetCapsule(NotificationCapsule capsule); 64 65 /* 66 * @brief Get the capsule of a local live view notification. 67 * 68 */ 69 NotificationCapsule GetCapsule(); 70 71 /* 72 * @brief Sets the button to be included in a local live view notification. 73 * 74 * @param button Indicates the type to be included. 75 */ 76 void SetButton(NotificationLocalLiveViewButton button); 77 78 /* 79 * @brief Get the button of a local live view notification. 80 * 81 */ 82 NotificationLocalLiveViewButton GetButton(); 83 84 /* 85 * @brief Sets the progress to be included in a local live view notification. 86 * 87 * @param progress Indicates the type to be included. 88 89 */ 90 void SetProgress(NotificationProgress progress); 91 92 /* 93 * @brief Get the progress of a local live view notification. 94 * 95 */ 96 NotificationProgress GetProgress(); 97 98 /* 99 * @brief Sets the time to be included in a local live view notification. 100 * 101 * @param time Indicates the type to be included. 102 103 */ 104 void SetTime(NotificationTime time); 105 106 /* 107 * @brief Get the time of a local live view notification. 108 * 109 */ 110 NotificationTime GetTime(); 111 112 /* 113 * @add flag function. 114 * 115 * @param flag Indicates the flag to be added. 116 117 */ 118 void addFlag(int32_t flag); 119 120 /* 121 * @return is the given flag exist. 122 * 123 * @param flag Indicates the flag to be added. 124 */ 125 bool isFlagExist(int32_t flag); 126 127 /** 128 * @brief Returns a string representation of the object. 129 * 130 * @return Returns a string representation of the object. 131 */ 132 std::string Dump() override; 133 134 /** 135 * @brief Converts a NotificationConversationalContent object into a Json. 136 * 137 * @param jsonObject Indicates the Json object. 138 * @return Returns true if succeed; returns false otherwise. 139 */ 140 virtual bool ToJson(nlohmann::json &jsonObject) const override; 141 142 /** 143 * @brief Creates a NotificationConversationalContent object from a Json. 144 * 145 * @param jsonObject Indicates the Json object. 146 * @return Returns the NotificationConversationalContent. 147 */ 148 static NotificationLocalLiveViewContent *FromJson(const nlohmann::json &jsonObject); 149 150 /** 151 * @brief Marshal a object into a Parcel. 152 * 153 * @param parcel Indicates the object into the parcel. 154 * @return Returns true if succeed; returns false otherwise. 155 */ 156 virtual bool Marshalling(Parcel &parcel) const override; 157 158 /** 159 * @brief Unmarshal object from a Parcel. 160 * 161 * @param parcel Indicates the parcel object. 162 * @return Returns the NotificationConversationalContent. 163 */ 164 static NotificationLocalLiveViewContent *Unmarshalling(Parcel &parcel); 165 166 void ClearButton(); 167 168 void ClearCapsuleIcon(); 169 170 protected: 171 /** 172 * @brief Read a NotificationConversationalContent object from a Parcel. 173 * 174 * @param parcel Indicates the parcel object. 175 * @return Returns true if succeed; returns false otherwise. 176 */ 177 bool ReadFromParcel(Parcel &parcel) override; 178 179 private: 180 int32_t type_ {0}; 181 NotificationCapsule capsule_ {}; 182 NotificationLocalLiveViewButton button_ {}; 183 NotificationProgress progress_ {}; 184 NotificationTime time_ {}; 185 std::vector<int32_t> flags_ {}; 186 }; 187 } // namespace Notification 188 } // namespace OHOS 189 190 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_CONVERSATIONAL_CONTENT_H 191