天气修改
authorluozheng <1732036298@qq.com>
Tue, 19 Mar 2024 13:01:55 +0000 (21:01 +0800)
committerluozheng <1732036298@qq.com>
Tue, 19 Mar 2024 13:01:55 +0000 (21:01 +0800)
code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h
code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp
code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherControlView.cpp
code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp
code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp

index b9c89ee..4d96adf 100644 (file)
@@ -174,6 +174,8 @@ namespace OHOS
         void InitImageAnimatorSource(UIImageAnimatorView *&imageAnimator, ImageAnimatorInfo *&imageAnimatorInfo, const char **imagePaths, const ImageAnimatorConfig &imageAnimatorConfig);
 
         void FreeImagePathsArray(const char **imagePaths, const int numImages);
+
+        void DeleteImageAnimatorInfo(ImageAnimatorInfo *&imageAnimatorInfo);
     };
 }
 #endif
\ No newline at end of file
index 1a73f16..4bba51e 100644 (file)
@@ -222,4 +222,16 @@ namespace OHOS
         }
     }
 
+    void ImageAnimator::DeleteImageAnimatorInfo(ImageAnimatorInfo *&imageAnimatorInfo)
+    {
+        if (imageAnimatorInfo != nullptr)
+        {
+            // 由于 imageAnimatorInfo 是一个数组,我们需要使用 delete[] 来删除它
+            delete[] imageAnimatorInfo;
+
+            // 重置指针防止悬空指针
+            imageAnimatorInfo = nullptr;
+        }
+    }
+
 }
\ No newline at end of file
index f5311c9..9074344 100644 (file)
@@ -32,7 +32,7 @@ namespace OHOS
 
     bool WeatherControlView::InitView(void)
     {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherControlView::InitView()");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherControlView::InitView");
         mainWeatherView = new MainWeatherView();
         if (mainWeatherView == nullptr)
         {
@@ -53,12 +53,12 @@ namespace OHOS
         }
         weatherSwipView->SetOnSwipeListener(weatherOnSwipeListener);
         Add(weatherSwipView);
-        viewiInitStatus = true;
         return true;
     }
 
     void WeatherControlView::PreLoad(void)
     {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherControlView::PreLoad");
         if (!viewiInitStatus)
         {
             InitView();
index f8c449e..80cdec0 100644 (file)
@@ -83,19 +83,17 @@ namespace OHOS
             if (p_ImageAnimator != nullptr)\r
             {\r
                 p_ImageAnimator->FreeImagePathsArray(UVPathsArray, UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);\r
+                p_ImageAnimator->DeleteImageAnimatorInfo(UVimageAnimatorInfo);\r
+\r
                 p_ImageAnimator->FreeImagePathsArray(WindSpeedPathsArray, WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);\r
+                p_ImageAnimator->DeleteImageAnimatorInfo(WindSpeedimageAnimatorInfo);\r
+\r
                 p_ImageAnimator->FreeImagePathsArray(HumidityPathsArray, HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);\r
+                p_ImageAnimator->DeleteImageAnimatorInfo(HumidityimageAnimatorInfo);\r
 \r
                 delete p_ImageAnimator;\r
                 p_ImageAnimator = nullptr;\r
             }\r
-\r
-            delete UVimageAnimatorInfo;\r
-            UVimageAnimatorInfo = nullptr;\r
-            delete WindSpeedimageAnimatorInfo;\r
-            WindSpeedimageAnimatorInfo = nullptr;\r
-            delete HumidityimageAnimatorInfo;\r
-            HumidityimageAnimatorInfo = nullptr;\r
         }\r
     }\r
 \r
index b5e5763..f7d4721 100644 (file)
@@ -44,6 +44,11 @@ namespace OHOS
         if (viewInitStatus == true)
         {
             RemoveAll();
+            if (showWeatherImage != nullptr)
+            {
+                delete showWeatherImage;
+                showWeatherImage = nullptr;
+            }
             if (showCurrentTimeLabel != nullptr)
             {
                 delete showCurrentTimeLabel;
@@ -54,11 +59,6 @@ namespace OHOS
                 delete showTemperatureLabel;
                 showTemperatureLabel = nullptr;
             }
-            if (showWeatherImage != nullptr)
-            {
-                delete showWeatherImage;
-                showWeatherImage = nullptr;
-            }
             if (showWeatherDescriptionLabel != nullptr)
             {
                 delete showWeatherDescriptionLabel;
@@ -83,10 +83,11 @@ namespace OHOS
             if (p_ImageAnimator != nullptr)
             {
                 p_ImageAnimator->FreeImagePathsArray(PullUpPathsArray, PULLUP_ANIMATOR_VIEW_NUM_FRAMES);
+                p_ImageAnimator->DeleteImageAnimatorInfo(PullUpimageAnimatorInfo);
+
                 delete p_ImageAnimator;
                 p_ImageAnimator = nullptr;
             }
-            delete PullUpimageAnimatorInfo;
         }
     }