增加新方法直接生成imageinfo* 数组 837/3 837/head 844/target/1
authorhcj <1224667075@qq.com>
Sat, 31 Aug 2024 01:45:43 +0000 (09:45 +0800)
committerhcj <1224667075@qq.com>
Sat, 31 Aug 2024 01:45:43 +0000 (09:45 +0800)
code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp
code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h
code/sdk/application/wearable/fd230app/nativeui/goal/include/goalother.h
code/sdk/application/wearable/fd230app/nativeui/goal/include/goalview.h
code/sdk/application/wearable/fd230app/nativeui/goal/src/goalother.cpp
code/sdk/application/wearable/fd230app/nativeui/goal/src/goalview.cpp

index d16a4ff..6c22e88 100644 (file)
@@ -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<const ImageInfo **>(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 ;
+    }
     /* -------------------------------------------------------------------------- */
     /**
      * 创建包含图片文件路径的数组
index aa7d265..86c5385 100644 (file)
@@ -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);
index 50b5d76..ee6b4b8 100644 (file)
@@ -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;          // 温度
index de286d3..90b6be8 100644 (file)
@@ -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
index a03c335..42f6460 100644 (file)
@@ -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
index 0625c27..d37d7b6 100644 (file)
@@ -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