From 41bd013a9540685bd591e524845e0442701fdbd1 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Sat, 31 Aug 2024 09:45:43 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E6=96=B0=E6=96=B9=E6=B3=95?= =?utf8?q?=E7=9B=B4=E6=8E=A5=E7=94=9F=E6=88=90imageinfo*=20=E6=95=B0?= =?utf8?q?=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../uicomponents/UIComponents.cpp | 39 ++++++++++++++ .../uicomponents/UIComponents.h | 4 ++ .../nativeui/goal/include/goalother.h | 2 - .../fd230app/nativeui/goal/include/goalview.h | 12 ++--- .../fd230app/nativeui/goal/src/goalother.cpp | 31 +---------- .../fd230app/nativeui/goal/src/goalview.cpp | 51 ++++--------------- 6 files changed, 58 insertions(+), 81 deletions(-) diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp index d16a4ff51..6c22e8858 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp @@ -448,7 +448,46 @@ namespace OHOS { InitLabel(label, x, y, width, height, viewId, text, fontName, fontSize); } + /* -------------------------------------------------------------------------- */ + /** + * 创建包含图片文件路径的数组 + * @param basePath 包含图片文件的基本路径 PullUp_%d.bin + * @param fileExtension 图片文件的扩展名 + * @param numImages 图片文件的数量 + * @return 返回包含图片文件info的数组 + */ + const ImageInfo**CreateImageInfoArray(const char *basePath, int numImages, const char *fileExtension) + { + const ImageInfo **imageinfo_array = static_cast(UIMalloc(numImages * sizeof(const ImageInfo *))); + if(imageinfo_array==nullptr) + { + return nullptr; // 检查内存分配是否成功 + } + for(int i = 0; i < numImages; i++) + { + char buffer[256]={0}; + snprintf(buffer, sizeof(buffer), "%s%d.%s", basePath, i + 1, fileExtension); + imageinfo_array[i]=ImageCacheManager::GetInstance().LoadSingleRes(buffer); + if( imageinfo_array[i]==nullptr) + { + UIFree(imageinfo_array); + return nullptr; // 检查内存分配是否成功 + } + } + return imageinfo_array; + } + void FreeImageInfoArray( const ImageInfo** array,const char *basePath, int numImages, const char *fileExtension) + { + for(int i = 0; i < numImages; i++) + { + char buffer[256]={0}; + snprintf(buffer, sizeof(buffer), "%s%d.%s", basePath, i + 1, fileExtension); + ImageCacheManager::GetInstance().UnloadSingleRes(buffer); + } + UIFree(array); + return ; + } /* -------------------------------------------------------------------------- */ /** * 创建包含图片文件路径的数组 diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h index aa7d26516..86c538514 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h @@ -60,6 +60,10 @@ namespace OHOS /*生成动画资源数组*/ const char **CreateImagePathsArray(const char *basePath, int numImages, const char *fileExtension = "bin"); + /*生成动画资源结构体*/ + const ImageInfo**CreateImageInfoArray(const char *basePath, int numImages, const char *fileExtension = "bin"); + + void FreeImageInfoArray( const ImageInfo** array,const char *basePath, int numImages, const char *fileExtension = "bin"); /*释放动画资源数组*/ void FreeImagePathsArray(const char **imagePaths, int numImages); diff --git a/code/sdk/application/wearable/fd230app/nativeui/goal/include/goalother.h b/code/sdk/application/wearable/fd230app/nativeui/goal/include/goalother.h index 50b5d76f5..ee6b4b8f4 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/goal/include/goalother.h +++ b/code/sdk/application/wearable/fd230app/nativeui/goal/include/goalother.h @@ -44,8 +44,6 @@ namespace OHOS UILabelExt *InitLabelExt(int x, int y, int w, int h, const char *text, int textfont, int lineheight); private: - const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages); - void FreeImagePathsArray(const char **imagePaths, const int numImages); void DumpWeatherInfo(); std::string WeatherImag; // 天气图片 std::string Temperature; // 温度 diff --git a/code/sdk/application/wearable/fd230app/nativeui/goal/include/goalview.h b/code/sdk/application/wearable/fd230app/nativeui/goal/include/goalview.h index de286d334..90b6be838 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/goal/include/goalview.h +++ b/code/sdk/application/wearable/fd230app/nativeui/goal/include/goalview.h @@ -18,6 +18,7 @@ #include "components/ui_image_view.h" #include "components/ui_image_animator.h" #include "components/ui_circle_progress.h" +#include "common/image_cache_manager.h" #include "wearable_log.h" #include "AppGroupView.h" @@ -44,10 +45,6 @@ namespace OHOS private: UILabelExt *InitLabelExt(int x, int y, int w, int h, const char *text, int textfont, int lineheight); - private: - void CreateImagePathsArray(const char **,const char *basePath, const char *fileExtension, int numImages); - void FreeImagePathsArray(const char **imagePaths, const int numImages); - private: UICircleProgress * circleProgress1_{nullptr}; //步数进度条 @@ -59,9 +56,10 @@ namespace OHOS UIImageAnimatorView *PullUpAnimatorView{nullptr}; // 上拉动画 UIImageAnimatorView *stepAnimatorView{nullptr}; // 走路动画 ImageAnimatorInfo goalAnimatorInfo[20]{0}; - - const char *PullUpPathsArray[70]{nullptr}; - const char *goalPathsArray[20]{nullptr}; + const ImageInfo** goalAnimator_imageInfo{nullptr}; + const ImageInfo** PullUpimageAnimator_imageInfo{nullptr}; + // const char **PullUpPathsArray{nullptr}; + // const char **goalPathsArray{nullptr}; bool viewInitStatus{false}; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/goal/src/goalother.cpp b/code/sdk/application/wearable/fd230app/nativeui/goal/src/goalother.cpp index a03c3351e..42f646039 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/goal/src/goalother.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/goal/src/goalother.cpp @@ -3,6 +3,7 @@ #include "goal/include/goalmodel.h" #include "common/image_cache_manager.h" #include "goal/include/goalview.h" +#include "uicomponents/UIComponents.h" /* 当至天气界面时,主动获取最新天气数据。 (此操作静默将进行,获取到则立刻更新显示,获取不到则重试 @@ -506,35 +507,5 @@ namespace OHOS return viewInitStatus; } - const char **GoalotherView::CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages) - { - const char **imagePaths = new const char *[numImages]; - char buffer[256]; - for (int i = 0; i < numImages; i++) - { - snprintf(buffer, sizeof(buffer), "%s%d.%s", basePath, i + 1, fileExtension); - imagePaths[i] = strdup(buffer); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " imagePaths[%d] = %s", i, imagePaths[i]); - } - return imagePaths; - } - - /* - * @brief: 释放图片路径数组指针 - * @param {char} imagePaths 图片路径数组 - * @param {int} numImages 图片数量 - */ - void GoalotherView::FreeImagePathsArray(const char **imagePaths, const int numImages) - { - for (int i = 0; i < numImages; i++) - { - ImageCacheManager::GetInstance().UnloadSingleRes(imagePaths[i]); - if(imagePaths[i]) - free( (void *)imagePaths[i]); - imagePaths[i] = nullptr; - } - delete imagePaths; - imagePaths = nullptr; - } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/goal/src/goalview.cpp b/code/sdk/application/wearable/fd230app/nativeui/goal/src/goalview.cpp index 0625c27f5..d37d7b685 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/goal/src/goalview.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/goal/src/goalview.cpp @@ -3,6 +3,7 @@ #include "goal/include/goalmodel.h" #include "common/image_cache_manager.h" #include "gfx_utils/mem_api.h" +#include "uicomponents/UIComponents.h" /* 当至天气界面时,主动获取最新天气数据。 (此操作静默将进行,获取到则立刻更新显示,获取不到则重试 @@ -104,9 +105,10 @@ namespace OHOS // } ImageCacheManager::GetInstance().UnloadSingleRes("/user/res/step/step_b.bin"); - - FreeImagePathsArray(PullUpPathsArray, PULLUP_ANIMATOR_VIEW_NUM_FRAMES); - FreeImagePathsArray(goalPathsArray, 20); + FreeImageInfoArray(goalAnimator_imageInfo,stepPaths, 20); + FreeImageInfoArray(PullUpimageAnimator_imageInfo,PullUpPaths, PULLUP_ANIMATOR_VIEW_NUM_FRAMES); + // FreeImagePathsArray(PullUpPathsArray, PULLUP_ANIMATOR_VIEW_NUM_FRAMES); + // FreeImagePathsArray(goalPathsArray, 20); // if(goalAnimatorInfo) // { @@ -259,7 +261,7 @@ namespace OHOS circleProgress1_->SetCapType(CAP_ROUND); /*----------------------------------------------------------------------------- */ - CreateImagePathsArray(goalPathsArray,stepPaths, "bin", 20); + goalAnimator_imageInfo=CreateImageInfoArray(stepPaths, 20); if (stepAnimatorView == nullptr) { stepAnimatorView = new UIImageAnimatorView(); @@ -274,7 +276,7 @@ namespace OHOS //goalAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO; //goalAnimatorInfo=new ImageAnimatorInfo [20]; //goalAnimatorInfo[i].imageInfo=nullptr; - goalAnimatorInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(goalPathsArray[i]); + goalAnimatorInfo[i].imageInfo = goalAnimator_imageInfo[i]; goalAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO; //goalAnimatorInfo[i].imagePath = goalPathsArray[i]; @@ -298,7 +300,7 @@ namespace OHOS - CreateImagePathsArray( PullUpPathsArray,PullUpPaths, "bin", PULLUP_ANIMATOR_VIEW_NUM_FRAMES); + PullUpimageAnimator_imageInfo =CreateImageInfoArray(PullUpPaths, PULLUP_ANIMATOR_VIEW_NUM_FRAMES); if (PullUpAnimatorView == nullptr) { PullUpAnimatorView = new UIImageAnimatorView(); @@ -311,7 +313,7 @@ namespace OHOS { //PullUpimageAnimatorInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(PullUpPathsArray[i]); //PullUpimageAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO; - PullUpimageAnimatorInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(PullUpPathsArray[i]); + PullUpimageAnimatorInfo[i].imageInfo = PullUpimageAnimator_imageInfo[i]; //PullUpPathsArray[i]; PullUpimageAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO; PullUpimageAnimatorInfo[i].pos.x = PULLUP_ANIMATOR_VIEW_X; @@ -362,40 +364,5 @@ namespace OHOS } - void GoalView::CreateImagePathsArray(const char **imagePaths,const char *basePath, const char *fileExtension, int numImages) - { - //const char **imagePaths = new const char *[numImages]; - char buffer[256]; - for (int i = 0; i < numImages; i++) - { - imagePaths[i]=(char *)UIMalloc(128); - memset_s((void *)imagePaths[i],128,0,128); - snprintf(buffer, sizeof(buffer), "%s%d.%s", basePath, i + 1, fileExtension); - memcpy_s((void*)imagePaths[i],128,(void*)buffer,128); - // imagePaths[i] = strdup(buffer); - //WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " imagePaths[%d] = %s", i, imagePaths[i]); - } - return ; - } - - /* - * @brief: 释放图片路径数组指针 - * @param {char} imagePaths 图片路径数组 - * @param {int} numImages 图片数量 - */ - void GoalView::FreeImagePathsArray(const char **imagePaths, const int numImages) - { - for (int i = 0; i < numImages; i++) - { - //ImageCacheManager::GetInstance().UnloadSingleRes(imagePaths[i]); - ImageCacheManager::GetInstance().UnloadSingleRes(imagePaths[i]); - - if(imagePaths[i]) - UIFree((void*)imagePaths[i]); - //imagePaths[i] = nullptr; - } - // delete[] imagePaths; - // imagePaths=nullptr; - } } \ No newline at end of file -- 2.17.1