1 /* 2 * Copyright (c) 2025-2025 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 OHOS_FLOATING_BALL_TEMPLATE_INFO_H 17 #define OHOS_FLOATING_BALL_TEMPLATE_INFO_H 18 19 #include <pixel_map.h> 20 21 #include "wm_common.h" 22 #include "floating_ball_template_base_info.h" 23 24 namespace OHOS::Rosen { 25 class FloatingBallTemplateInfo : public FloatingBallTemplateBaseInfo, 26 public Parcelable { 27 public: 28 FloatingBallTemplateInfo() = default; FloatingBallTemplateInfo(const uint32_t & templateType,const std::string & title,const std::string & content,const std::string & color,const std::shared_ptr<Media::PixelMap> & icon)29 FloatingBallTemplateInfo(const uint32_t& templateType, const std::string& title, const std::string& content, 30 const std::string& color, const std::shared_ptr<Media::PixelMap>& icon) : FloatingBallTemplateBaseInfo( 31 templateType, title, content, color), icon_(icon) {}; 32 // LCOV_EXCL_START FloatingBallTemplateInfo(const FloatingBallTemplateBaseInfo & baseInfo,const std::shared_ptr<Media::PixelMap> & icon)33 FloatingBallTemplateInfo(const FloatingBallTemplateBaseInfo& baseInfo, 34 const std::shared_ptr<Media::PixelMap>& icon) : FloatingBallTemplateBaseInfo(baseInfo.template_, 35 baseInfo.title_, baseInfo.content_, baseInfo.backgroundColor_), icon_(icon) {}; 36 // LCOV_EXCL_STOP 37 ~FloatingBallTemplateInfo() override = default; 38 39 std::shared_ptr<Media::PixelMap> icon_ {}; 40 41 // LCOV_EXCL_START Marshalling(Parcel & parcel)42 bool Marshalling(Parcel& parcel) const override 43 { 44 if (!parcel.WriteUint32(template_) || !parcel.WriteString(title_) || 45 !parcel.WriteString(content_) || !parcel.WriteString(backgroundColor_)) { 46 return false; 47 } 48 bool hasIcon = icon_ ? true : false; 49 if (!parcel.WriteBool(hasIcon)) { 50 return false; 51 } 52 if (hasIcon && !parcel.WriteParcelable(icon_.get())) { 53 return false; 54 } 55 return true; 56 } 57 // LCOV_EXCL_STOP 58 Unmarshalling(Parcel & parcel)59 static FloatingBallTemplateInfo* Unmarshalling(Parcel& parcel) 60 { 61 std::unique_ptr<FloatingBallTemplateInfo> fbTemplateInfo = std::make_unique<FloatingBallTemplateInfo>(); 62 if (!parcel.ReadUint32(fbTemplateInfo->template_) || !parcel.ReadString(fbTemplateInfo->title_) || 63 !parcel.ReadString(fbTemplateInfo->content_) || !parcel.ReadString(fbTemplateInfo->backgroundColor_)) { 64 return nullptr; 65 } 66 bool hasIcon = false; 67 if (!parcel.ReadBool(hasIcon)) { 68 return nullptr; 69 } 70 if (hasIcon) { 71 fbTemplateInfo->icon_ = std::shared_ptr<Media::PixelMap>(parcel.ReadParcelable<Media::PixelMap>()); 72 if (!fbTemplateInfo->icon_) { 73 return nullptr; 74 } 75 } 76 return fbTemplateInfo.release(); 77 } 78 }; 79 } // namespace OHOS::Rosen 80 #endif // OHOS_FLOATING_BALL_TEMPLATE_INFO_H