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_BUTTON_H 17 #define BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_LIVE_VIEW_BUTTON_H 18 19 #include "notification_button_option.h" 20 #include "pixel_map.h" 21 #include "message_user.h" 22 #include "notification_json_convert.h" 23 #include "parcel.h" 24 #include "uri.h" 25 #include <vector> 26 #include "resource_manager.h" 27 28 namespace OHOS { 29 namespace Notification { 30 using namespace Global::Resource; 31 32 class NotificationLocalLiveViewButton : public Parcelable, public NotificationJsonConvertionBase { 33 public: 34 NotificationLocalLiveViewButton() = default; 35 ~NotificationLocalLiveViewButton() = default; 36 37 /** 38 * @brief Obtains the text to be displayed as the content of this message. 39 * 40 * @return Returns the message content. 41 */ 42 std::vector<std::string> GetAllButtonNames() const; 43 44 void addSingleButtonName(const std::string &buttonName); 45 46 /** 47 * @brief Obtains the time when this message arrived. 48 * 49 * @return Returns the time when this message arrived. 50 */ 51 std::vector<std::shared_ptr<Media::PixelMap>> GetAllButtonIcons() const; 52 53 void addSingleButtonIcon(std::shared_ptr<Media::PixelMap> &icon); 54 55 /** 56 * @brief Obtains the buttion icon resource when this message arrived. 57 * 58 * @return Returns the buttion icon resource when this message arrived. 59 */ 60 std::vector<std::shared_ptr<ResourceManager::Resource>> GetAllButtonIconResource() const; 61 62 void addSingleButtonIconResource(std::shared_ptr<ResourceManager::Resource> &iconResource); 63 64 /** 65 * @brief Returns a string representation of the object. 66 * 67 * @return Returns a string representation of the object. 68 */ 69 std::string Dump(); 70 71 /** 72 * @brief Converts a NotificationConversationalMessage object into a Json. 73 * 74 * @param jsonObject Indicates the Json object. 75 * @return Returns true if succeed; returns false otherwise. 76 */ 77 bool ToJson(nlohmann::json &jsonObject) const override; 78 79 /** 80 * @brief Creates a NotificationConversationalMessage object from a Json. 81 * 82 * @param jsonObject Indicates the Json object. 83 * @return Returns the NotificationConversationalMessage. 84 */ 85 static NotificationLocalLiveViewButton *FromJson(const nlohmann::json &jsonObject); 86 87 /** 88 * @brief Marshal a object into a Parcel. 89 * 90 * @param parcel Indicates 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 /** 96 * @brief Unmarshal object from a Parcel. 97 * 98 * @param parcel Indicates the parcel object. 99 * @return Returns the NotificationConversationalMessage. 100 */ 101 static NotificationLocalLiveViewButton *Unmarshalling(Parcel &parcel); 102 103 void ClearButtonIcons(); 104 105 void ClearButtonIconsResource(); 106 107 private: 108 /** 109 * @brief Read a NotificationConversationalMessage object from a Parcel. 110 * 111 * @param parcel Indicates the parcel object. 112 * @return Returns true if succeed; returns false otherwise. 113 */ 114 bool ReadFromParcel(Parcel &parcel); 115 static bool ResourceFromJson(const nlohmann::json &resource, 116 std::shared_ptr<ResourceManager::Resource>& resourceObj); 117 std::vector<std::string> buttonNames_ {}; 118 std::vector<std::shared_ptr<Media::PixelMap>> buttonIcons_ {}; 119 std::vector<std::shared_ptr<ResourceManager::Resource>> buttonIconsResource_ {}; 120 }; 121 } // namespace Notification 122 } // namespace OHOS 123 124 #endif // BASE_NOTIFICATION_DISTRIBUTED_NOTIFICATION_SERVICE_INTERFACES_INNER_API_LOCAL_LIVE_VIEW_BUTTON_H 125