From 58c1f2829a75061613867c309573c8da3f66c8bb Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Wed, 26 Jun 2024 18:49:42 +0800 Subject: [PATCH] =?utf8?q?=E4=B8=BB=E7=95=8C=E9=9D=A2=E5=8D=A1=E7=89=87?= =?utf8?q?=E9=85=8D=E7=BD=AEunload?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/heart_blood/BloodCardView.cpp | 1 - .../training_card/src/Training_CardView.cpp | 104 +++++++++++++----- 2 files changed, 77 insertions(+), 28 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/BloodCardView.cpp b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/BloodCardView.cpp index 5e78deca0..4d51fde35 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/BloodCardView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/BloodCardView.cpp @@ -78,7 +78,6 @@ namespace OHOS */ bool BloodCardView::AddButton() { - return true; } /*** diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/Training_CardView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/Training_CardView.cpp index ad3d6e50c..7a3bc15c8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/Training_CardView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/Training_CardView.cpp @@ -19,17 +19,17 @@ namespace OHOS { static Training_CardView *g_pTraining_CardView{nullptr}; - + std::string file = TRAINING_IAMGES; Training_CardView::Training_CardView() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Training_CardView::Training_CardView"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Training_CardView::Training_CardView"); SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); g_pTraining_CardView = this; } Training_CardView::~Training_CardView() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Training_CardView::~Training_CardView"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Training_CardView::~Training_CardView"); RemoveAll(); DeInit(); g_pTraining_CardView = nullptr; @@ -50,7 +50,6 @@ namespace OHOS // 加载图片函数(针对UILabelButtonExt) bool Training_CardView::LoadImage(UILabelButtonExt *view, uint32_t resId) { - std::string file = TRAINING_IAMGES; WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingView LoadImage: %s, resID=0x%x", TRAINING_IAMGES, resId); ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); if (image == nullptr) @@ -58,7 +57,11 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Training_CardView::LoadImage %x fail", resId); return false; } - // Assuming SetImageSrc is the correct function for UILabelButtonExt + if (view == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "view is null"); + return false; + } view->SetImageSrc(image, nullptr); return true; } @@ -66,7 +69,6 @@ namespace OHOS // 加载图片函数(针对UIImageView) bool Training_CardView::LoadImage(UIImageView *view, uint32_t resId) { - std::string file = TRAINING_IAMGES; WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingView LoadImage: %s, resID=0x%x", TRAINING_IAMGES, resId); ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); if (image == nullptr) @@ -74,6 +76,11 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Training_CardView::LoadImage %x fail", resId); return false; } + if (view == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "view is null"); + return false; + } view->SetSrc(image); // Assuming SetSrc is the correct function for UIImageView return true; } @@ -98,20 +105,16 @@ namespace OHOS for (auto &buttonInfo : buttons) { - if (buttonInfo.button == nullptr) - { - buttonInfo.button = new UILabelButtonExt(); - } - if (!LoadImage(buttonInfo.button, buttonInfo.defaultImgSrc)) + buttonInfo.button = new UILabelButtonExt(); + if (buttonInfo.button == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], triangulation load fail", __LINE__); - return false; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "buttonInfo.button is NULL"); } buttonInfo.button->SetPosition(buttonInfo.posX, buttonInfo.posY); buttonInfo.button->Resize(140, 140); - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Id:[%s]", buttonInfo.viewid); + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Id:[%s]", buttonInfo.viewid); buttonInfo.button->SetTextId(buttonInfo.textid); buttonInfo.button->SetLabelPosition(0, 70); buttonInfo.button->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 25); @@ -121,13 +124,33 @@ namespace OHOS UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::TraingOnClickListener::GetInstance(); if (clickListener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AddButton::OnStart clickListener NULL"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddButton::OnStart clickListener NULL"); return false; } buttonInfo.button->SetOnClickListener(clickListener); - Add(buttonInfo.button); + // 根据按钮的 viewid 分配给对应的成员变量 + if (strcmp(buttonInfo.viewid, BUTTON1) == 0) + { + Button1 = buttonInfo.button; + } + else if (strcmp(buttonInfo.viewid, BUTTON2) == 0) + { + Button2 = buttonInfo.button; + } + else if (strcmp(buttonInfo.viewid, BUTTON3) == 0) + { + Button3 = buttonInfo.button; + } + else if (strcmp(buttonInfo.viewid, BUTTONMORE) == 0) + { + ButtonMore = buttonInfo.button; + } } + Add(Button1); + Add(Button2); + Add(Button3); + Add(ButtonMore); return true; } @@ -149,27 +172,32 @@ namespace OHOS for (auto &imageInfo : images) { + imageInfo.image = new UIImageView(); if (imageInfo.image == nullptr) { - imageInfo.image = new UIImageView(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "imageInfo.image is NULL"); } imageInfo.image->SetPosition(imageInfo.posX, imageInfo.posY); imageInfo.image->Resize(100, 100); - if (!LoadImage(imageInfo.image, imageInfo.imagePath)) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[%d], triangulation load fail", __LINE__); - return false; - } + imageInfo.image->SetViewId(imageInfo.viewId); - Add(imageInfo.image); + // Add(imageInfo.image); } + image1 = images[0].image; + image2 = images[1].image; + image3 = images[2].image; + + Add(image1); + Add(image2); + Add(image3); + return true; } /* -------------------------------------------------------------------------- */ bool Training_CardView::InitView() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Training_CardView::InitView()"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Training_CardView::InitView()"); if (!InitLable()) { printf("InitLable error!\n"); @@ -182,6 +210,7 @@ namespace OHOS { printf("InitImage error!\n"); }; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Training_CardView::InitView() is ok"); // SetCoverable(true); return true; } @@ -224,15 +253,36 @@ namespace OHOS InitView(); viewiInitStatus = true; } + if (!resLoadStatus) + { + LoadImage(image1, TRAINING_WALKING_BIG); + LoadImage(image2, TRAINING_RIDING_BIG2); + LoadImage(image3, TRAINING_RUNNING_BIG); + + LoadImage(Button1, TRAINING_BUTTONGROUND2); + LoadImage(Button2, TRAINING_BOUTTONGROUND); + LoadImage(Button3, TRAINING_BOUTTONGROUND); + LoadImage(ButtonMore, TRAINING_MORE); + resLoadStatus = true; + } } void Training_CardView::UnLoad(void) { -#if 0 - if (viewiInitStatus) + + if (resLoadStatus) { + ImageInfo *img = nullptr; + image1->SetSrc(img); + image2->SetSrc(img); + image3->SetSrc(img); + + Button1->SetImageSrc(img, img); + Button2->SetImageSrc(img, img); + Button3->SetImageSrc(img, img); + ButtonMore->SetImageSrc(img, img); ImageCacheManager::GetInstance().UnloadAllInMultiRes(TRAINING_IAMGES); + resLoadStatus = false; } -#endif } } -- 2.17.1