连接动画添加判断,若动画类为空则不添加到其父视图scrollview上,确保不会死机
authorluozheng <1732036298@qq.com>
Wed, 25 Sep 2024 03:06:19 +0000 (11:06 +0800)
committerluozheng <1732036298@qq.com>
Wed, 25 Sep 2024 03:06:19 +0000 (11:06 +0800)
修改通用动画接口,若动画资源图片缺少部分,不影响整体动画播放,防止因缺少一张图片导致死机,已验证不会死机

code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp

index c803f5a..5334328 100644 (file)
@@ -737,11 +737,12 @@ namespace OHOS
             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; // 检查内存分配是否成功
-            }
+            // imageinfo_array[i] = ImageCacheManager::GetInstance().LoadSingleRes(buffer);
+            // if (imageinfo_array[i] == nullptr)
+            // {
+            //     UIFree(imageinfo_array);
+            //     return nullptr; // 检查内存分配是否成功
+            // }
         }
         return imageinfo_array;
     }
index c7ba001..bba8719 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-08-03 11:10:08
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-09-03 19:06:26
+ * @LastEditTime: 2024-09-25 10:42:10
  * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp
  */
 #include "aivoice/include/AiVoiceConnectingView.h"
@@ -152,11 +152,14 @@ namespace OHOS
             .textId = STR_CONNECTING,
             .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION,
         };
-        title = AiVoiceConnectingViewLabelInit(labelConfig);
         if (title == nullptr)
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "title new fail!");
-            return false;
+            title = AiVoiceConnectingViewLabelInit(labelConfig);
+            if (title == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "title new fail!");
+                return false;
+            }
         }
         /* -------------------------------------------------------------------------- */
         labelConfig = {
@@ -169,13 +172,16 @@ namespace OHOS
             .textId = STR_CANCEL,
             .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION,
         };
-        cancelLabel = AiVoiceConnectingViewLabelInit(labelConfig);
         if (cancelLabel == nullptr)
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::cancelLabel is nullptr!");
-            return false;
+            cancelLabel = AiVoiceConnectingViewLabelInit(labelConfig);
+            if (cancelLabel == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::cancelLabel is nullptr!");
+                return false;
+            }
+            cancelLabel->SetTextColor(Color::GetColorFromRGBA(0xfd, 0x52, 0x13, 0xff));
         }
-        cancelLabel->SetTextColor(Color::GetColorFromRGBA(0xfd, 0x52, 0x13, 0xff));
 
         return true;
     }
@@ -190,11 +196,14 @@ namespace OHOS
             .h = 90,
             .viewId = AIVOICECONNECTINGVIEW_CANCEL_BUTTON_VIEW_ID,
         };
-        cancelButton = AiVoiceConnectingViewButtonInit(buttonconfig);
         if (cancelButton == nullptr)
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cancelButton new fail!");
-            return false;
+            cancelButton = AiVoiceConnectingViewButtonInit(buttonconfig);
+            if (cancelButton == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cancelButton new fail!");
+                return false;
+            }
         }
         UIView::OnTouchListener *touchListener = static_cast<UIView::OnTouchListener *>(AiVoicePresenter::GetInstance());
         if (touchListener == nullptr)
@@ -210,11 +219,14 @@ namespace OHOS
     bool AiVoiceConnectingView::CreateAivoiceConnectingImageAnimator(void)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAivoiceConnectingImageAnimator");
-        connectingPathsArray = CreateImageInfoArray(AIVoiceListeningImagePaths, AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
         if (connectingPathsArray == nullptr)
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::connectingPathsArray  is nullptr!!");
-            return false;
+            connectingPathsArray = CreateImageInfoArray(AIVoiceListeningImagePaths, AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
+            if (connectingPathsArray == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::connectingPathsArray  is nullptr!!");
+                return false;
+            }
         }
 
         ImageAnimatorConfig imageanimatorconfig = {
@@ -227,11 +239,14 @@ namespace OHOS
             .numFrames = AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES,
             .delay = AIVOICE_CONNECTING_IMAGE_ANIMATOR_DELAY,
         };
-        connectingAnimatorView = connectingImageAnimatorInit(imageanimatorconfig);
         if (connectingAnimatorView == nullptr)
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::connectingAnimatorView new fail");
-            return false;
+            connectingAnimatorView = connectingImageAnimatorInit(imageanimatorconfig);
+            if (connectingAnimatorView == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::connectingAnimatorView new fail");
+                return false;
+            }
         }
 
         return true;
@@ -240,11 +255,14 @@ namespace OHOS
     bool AiVoiceConnectingView::CreateAiVoiceConnectingScrollView(void)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingScrollView");
-        scrollView = new UIScrollView();
         if (scrollView == nullptr)
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::scrollView new fail!");
-            return false;
+            scrollView = new UIScrollView();
+            if (scrollView == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::scrollView new fail!");
+                return false;
+            }
         }
         UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(AiVoicePresenter::GetInstance());
         if (dragListener == nullptr)
@@ -263,11 +281,14 @@ namespace OHOS
     bool AiVoiceConnectingView::CreateAiVoiceConnectingScrollView(uint8_t type)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingScrollView");
-        scrollView = new UIScrollView();
         if (scrollView == nullptr)
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::scrollView new fail!");
-            return false;
+            scrollView = new UIScrollView();
+            if (scrollView == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::scrollView new fail!");
+                return false;
+            }
         }
         scrollView->SetPosition(0, 0, 466, 466);
         scrollView->SetTouchable(true);
@@ -279,6 +300,7 @@ namespace OHOS
     UIScrollView *AiVoiceConnectingView::CreateAiVoiceConnectingView(void)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingView");
+#if 0
         if (!CreateAiVoiceConnectingScrollView() || !CreateAivoiceConnectingImageAnimator() || !CreateAiVoiceConnectingViewLabel() || !CreateAiVoiceConnectingViewButton())
         {
             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingView fail!!");
@@ -290,11 +312,55 @@ namespace OHOS
         scrollView->Add(cancelLabel);
 
         return scrollView;
+#else
+        if (!CreateAiVoiceConnectingScrollView())
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingScrollView fail!!");
+        }
+        if (!CreateAivoiceConnectingImageAnimator())
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAivoiceConnectingImageAnimator fail!!");
+        }
+        if (!CreateAiVoiceConnectingViewLabel())
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingViewLabel fail!!");
+        }
+        if (!CreateAiVoiceConnectingViewButton())
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingViewButton fail!!");
+        }
+
+#endif
+        if (scrollView == nullptr)
+        {
+            return nullptr;
+        }
+        else
+        {
+            if (title)
+            {
+                scrollView->Add(title);
+            }
+            if (connectingAnimatorView)
+            {
+                scrollView->Add(connectingAnimatorView);
+            }
+            if (cancelButton)
+            {
+                scrollView->Add(cancelButton);
+            }
+            if (cancelLabel)
+            {
+                scrollView->Add(cancelLabel);
+            }
+            return scrollView;
+        }
     }
 
     UIScrollView *AiVoiceConnectingView::CreateAiVoiceConnectingView(uint8_t type)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingView");
+#if 0
         if (!CreateAiVoiceConnectingScrollView(type) || !CreateAivoiceConnectingImageAnimator() || !CreateAiVoiceConnectingViewLabel())
         {
             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingView fail!!");
@@ -302,9 +368,41 @@ namespace OHOS
         }
         connectingAnimatorView->SetPosition(183, 183);
         connectingAnimatorView->Invalidate();
-        ScreenTurnOn(30*1000);//亮屏30s
+        ScreenTurnOn(30 * 1000); // 亮屏30s
         scrollView->Add(connectingAnimatorView);
-        return scrollView;
+#else
+        if (!CreateAiVoiceConnectingScrollView(type))
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingScrollView fail!!");
+        }
+        if (!CreateAivoiceConnectingImageAnimator())
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAivoiceConnectingImageAnimator fail!!");
+        }
+        if (!CreateAiVoiceConnectingViewLabel())
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingViewLabel fail!!");
+        }
+        if (scrollView == nullptr)
+        {
+            return nullptr;
+        }
+        else
+        {
+            if (title)
+            {
+                scrollView->Add(title);
+            }
+            if (connectingAnimatorView)
+            {
+                connectingAnimatorView->SetPosition(183, 183);
+                connectingAnimatorView->Invalidate();
+                scrollView->Add(connectingAnimatorView);
+            }
+            ScreenTurnOn(30 * 1000); // 亮屏30s
+            return scrollView;
+        }
+#endif
     }
 
 }
\ No newline at end of file