From b390b18e93076168a104cd08f7594ee9d247babe Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Fri, 30 Aug 2024 20:01:17 +0800 Subject: [PATCH] =?utf8?q?=E7=BB=9F=E4=B8=80=E5=8A=A8=E7=94=BB=E6=95=B0?= =?utf8?q?=E7=BB=84=E7=94=9F=E6=88=90=E4=BB=A5=E5=8F=8A=E9=87=8A=E6=94=BE?= =?utf8?q?=E5=87=BD=E6=95=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../uicomponents/UIComponents.cpp | 63 +++++++- .../uicomponents/UIComponents.h | 89 ++++++----- .../aivoice/include/AiVoiceConnectingView.h | 8 +- .../aivoice/include/AivoiceListeningView.h | 8 +- .../aivoice/include/AivoiceThinkingView.h | 2 - .../aivoice/src/AiVoiceConnectingView.cpp | 29 +--- .../aivoice/src/AivoiceListeningView.cpp | 29 +--- .../aivoice/src/AivoiceThinkingView.cpp | 29 +--- .../findphone/include/FindPhoneView.h | 2 - .../nativeui/findphone/src/FindPhoneView.cpp | 48 ++---- .../nativeui/heartrate/src/HeartChartView.cpp | 10 +- .../include/ShutDownImageAnimatorView.h | 3 +- .../src/ShutDownImageAnimatorView.cpp | 33 ++-- .../include/RespiratoryTrainingView.h | 2 - .../src/RespiratoryTrainingView.cpp | 26 ---- .../nativeui/saveele/src/SaveElePresenter.cpp | 10 +- .../nativeui/sleep/include/SleepTimeView.h | 2 - .../sleep/src/SleepControlPresenter.cpp | 2 +- .../takephotos/include/TakephotosView.h | 5 + .../takephotos/src/TakephotosView.cpp | 24 +-- .../training_card/include/TraingCardView.h | 3 + .../training_card/src/TraingCardView.cpp | 9 +- .../weather/include/WeatherReportView.h | 2 - .../nativeui/weather/include/WeatherView.h | 9 +- .../weather/src/WeatherReportView.cpp | 39 ++--- .../nativeui/weather/src/WeatherView.cpp | 28 +--- .../include/notify/pairing_notification.h | 2 - .../src/notify/charge_notification.cpp | 25 +--- .../src/notify/pairing_notification.cpp | 141 +++++++----------- 29 files changed, 253 insertions(+), 429 deletions(-) diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp index 6ef22281d..d16a4ff51 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-08-29 19:24:30 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-30 18:57:46 + * @FilePath: /FD230/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp + */ /*** * @Date: 2024-05-10 10:27:30 * @LastEditors: Caisking 3449750381@qq.com @@ -426,7 +432,15 @@ namespace OHOS imageView->SetPosition(left, top); imageView->SetAutoEnable(true); imageView->SetViewId(viewId); - imageView->SetSrc(imagePath); + + ImageInfo *image = ImageCacheManager::GetInstance().LoadSingleRes(imagePath, false); + if (image == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadAllDialFromRam loadimage %s fail", + imagePath); + return false; + } + imageView->SetSrc(image); return true; } /*带默认参数的初始化label*/ @@ -438,23 +452,56 @@ namespace OHOS /* -------------------------------------------------------------------------- */ /** * 创建包含图片文件路径的数组 - * @param basePath 包含图片文件的基本路径 - * @param fileExtension 图片文件的扩展名 - * @param numImages 图片文件的数量 - * @return 返回包含图片文件路径的数组 + * @param basePath 包含图片文件的基本路径 + * @param fileExtension 图片文件的扩展名 + * @param numImages 图片文件的数量 + * @return 返回包含图片文件路径的数组 */ - const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages) + const char **CreateImagePathsArray(const char *basePath, int numImages, const char *fileExtension) { - const char **imagePaths = new const char *[numImages]; + const char **imagePaths = static_cast(UIMalloc(numImages * sizeof(const char *))); + if (imagePaths == nullptr) + { + return nullptr; // 检查内存分配是否成功 + } + 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); + imagePaths[i] = static_cast(UIMalloc(strlen(buffer) + 1)); // 分配内存来存储每个路径 + if (imagePaths[i] == nullptr) + { + // 如果分配失败,释放已经分配的内存并返回 nullptr + for (int j = 0; j < i; j++) + { + UIFree(const_cast(imagePaths[j])); // 释放已分配的内存 + } + UIFree(imagePaths); + return nullptr; + } + strcpy(const_cast(imagePaths[i]), buffer); // 使用 strcpy 拷贝字符串 } return imagePaths; } + /** + * 释放创建的图片路径数组 + * @param imagePaths 包含图片路径的数组 + * @param numImages 图片文件的数量 + */ + void FreeImagePathsArray(const char **imagePaths, int numImages) + { + if (imagePaths != nullptr) + { + for (int i = 0; i < numImages; i++) + { + UIFree(const_cast(imagePaths[i])); // 释放每个路径字符串 + } + UIFree(const_cast(imagePaths)); // 释放整个数组 + } + } + /*解析动画资源数组 imageche*/ std::vector AnalysisArray(const char *filename, uint32_t startId, uint32_t lastId) { diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h index a49674321..aa7d26516 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h @@ -1,27 +1,4 @@ -/*** - * @Date: 2024-07-29 10:31:48 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-08-21 16:17:07 - * @FilePath: /FD230/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h - */ -/*** - * @Date: 2024-05-30 15:59:37 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-07-29 14:19:44 - * @FilePath: /FD230/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h - */ -/*** - * @Date: 2024-05-30 15:59:37 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-06-27 15:04:48 - * @FilePath: /FD230/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h - */ -/*** - * @Date: 2024-05-10 10:27:30 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-05-10 11:04:28 - * @FilePath: /sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.h - */ + #ifndef UICOMPONENTS_H #define UICOMPONENTS_H @@ -29,6 +6,8 @@ #include "BaseView.h" #include "View.h" #include + +// UI 组件 #include "components/ui_scroll_view.h" #include "components/ui_view_group.h" #include "components/ui_label.h" @@ -40,49 +19,69 @@ #include "components/ui_chart.h" #include "components/ui_list.h" #include "components/icon_adapter.h" +#include "components/ui_card_page.h" + +// 日志和类型定义 #include "wearable_log.h" #include "ohos_types.h" -#include "components/ui_card_page.h" +#include "common/image_cache_manager.h" + #ifdef FD230 #include "traing/include/TraingModel.h" #include "ui_resource_string.h" #endif -#include "common/image_cache_manager.h" namespace OHOS { - /*初始化label[可使用text]*/ + + // 初始化和创建 UI 组件 + // ======================= + /* 初始化 UILabel */ bool InitLabel(UILabelExt *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize); - /*初始化label[可使用text]*/ bool InitUILabel(UILabel *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize); - /*初始化button*/ + + /* 初始化 UIButton */ bool InitButton(UIButton *&button, int left, int top, int width, int height, const char *viewId); - /*初始化labelbutton*/ + + /* 初始化 UILabelButton */ bool InitLabelButton(UILabelButton *&button, int left, int top, int width, int height, const char *viewId, const char *text, int fontSize); - /*初始化image*/ + + /* 初始化 UIImageView */ bool InitImageView(UIImageView *&imageView, int left, int top, int width, int height, const char *viewId, const char *imagePath); - /*生成动画资源数组*/ - const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages); - /*自适应label*/ + + /* 初始化动画资源 */ + void InitImageAnimatorSource(UIImageAnimatorView *&imageAnimator, const std::vector &imagePaths, int numFrames, int left, int top, int width, int height, const char *viewId, int time); + + /* 自适应 UILabel */ bool InitLabelAdapt(UILabelExt *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize); + + // 默认参数的 UILabel 初始化 + void InitLabelDefault(UILabelExt *&label, int x, int y, int width, int height, const char *viewId, const char *text, int fontSize = 30, const char *fontName = DEFAULT_VECTOR_FONT_FILENAME); + + /*生成动画资源数组*/ + const char **CreateImagePathsArray(const char *basePath, int numImages, const char *fileExtension = "bin"); + + /*释放动画资源数组*/ + void FreeImagePathsArray(const char **imagePaths, int numImages); + /*初始化动画资源*/ void InitImageAnimatorSource(UIImageAnimatorView *&imageAnimator, const char **imagePaths, int numFrames, int left, int top, int width, int height, const char *viewId, int time); - /*InitLabel[默认参数]*/ - void InitLabelDefault(UILabelExt *&label, int x, int y, int width, int height, const char *viewId, const char *text, int fontSize = 30, const char *fontName = DEFAULT_VECTOR_FONT_FILENAME); + #ifdef FD230 - /*初始化labelExt*/ + // 扩展功能 + // ======================= bool InitLabelExt(UILabelExt *&label, int left, int top, int width, int height, const char *viewId, UIResourceTextId id, const char *fontName, int fontSize); bool InitButtonExt(UILabelButtonExt *&button, int left, int top, int width, int height, const char *viewId, UIResourceTextId id, int fontSize); - /*通用替换*/ + + // 更新 Label 的文本 std::string UpdateLabelText(UILabelExt *&label, const std::string &newText, UIResourceTextId id); - /*更新label的数字*/ std::string UpdateLabel(UILabelExt *&label, int num, UIResourceTextId id); - /*更新label的字符串*/ std::string UpdateLabel(UILabelExt *&label, const std::string &updatestr, UIResourceTextId id); - /*通过labelext获取Id设置label*/ + + // 设置 Label ID void SetLabelId(UILabel *&label, UIResourceTextId id); -#endif - /*解析动画资源数组 imageche*/ - std::vector AnalysisArray(const char *filename, uint32_t startId, uint32_t lastId); -} +#endif // FD230 + +} // namespace OHOS + #endif // UICOMPONENTS_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h index 5be7c8a68..dfeb450d6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-08-19 19:20:08 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-30 18:57:30 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h + */ /* * @Author: luozheng 1732036298@qq.com * @Date: 2024-08-03 11:09:56 @@ -58,8 +64,6 @@ namespace OHOS UIScrollView *CreateAiVoiceConnectingView(void); UIScrollView *CreateAiVoiceConnectingView(uint8_t); private: - const char **CreateImagePathsArray(const char *basePath, const int numImages, const char *fileExtension = "bin"); - void FreeImagePathsArray(const char **imagePaths, const int numImages); UIImageAnimatorView *connectingImageAnimatorInit(ImageAnimatorConfig &imageanimatorconfig); UILabelExt *AiVoiceConnectingViewLabelInit(LabelConfig &labelconfig); UIButton *AiVoiceConnectingViewButtonInit(ButtonConfig &buttonconfig); diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceListeningView.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceListeningView.h index 9b02ffdfd..c89704334 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceListeningView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceListeningView.h @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-06-26 16:59:51 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-30 18:57:36 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceListeningView.h + */ /* * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-22 16:46:26 @@ -67,8 +73,6 @@ namespace OHOS private: void ClearAll(void); - const char **CreateImagePathsArray(const char *basePath, const int numImages, const char *fileExtension = "bin"); - void FreeImagePathsArray(const char **imagePaths, const int numImages); UILabelExt *AivoiceListeningLabelInit(LabelConfig &labelconfig); UIButton *AivoiceListeningButtonInit(ButtonConfig &buttonconfig); UIImageAnimatorView *AivoiceListeningImageAnimatorInit(ImageAnimatorConfig &imageanimatorconfig); diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceThinkingView.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceThinkingView.h index 93a223ee2..cad3da12f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceThinkingView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceThinkingView.h @@ -67,8 +67,6 @@ namespace OHOS private: void ClearAll(void); - const char **CreateImagePathsArray(const char *basePath, const int numImages, const char *fileExtension = "bin"); - void FreeImagePathsArray(const char **imagePaths, const int numImages); UILabelExt *AivoiceThinkingLabelInit(LabelConfig &labelconfig); UIButton *AivoiceThinkingButtonInit(ButtonConfig &buttonconfig); UIImageAnimatorView *AivoiceThinkingImageAnimatorInit(ImageAnimatorConfig &imageanimatorconfig); diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp index 8e8d88f38..2df64ab0c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp @@ -10,6 +10,7 @@ #include "wearable_log.h" #include "ui_resource_string.h" #include "common/image_cache_manager.h" +#include "uicomponents/UIComponents.h" namespace OHOS { @@ -106,34 +107,6 @@ namespace OHOS return button; } - const char **AiVoiceConnectingView::CreateImagePathsArray(const char *basePath, const int numImages, const char *fileExtension) - { - const char **imagePaths = new const char *[numImages]; - if (imagePaths == nullptr) - { - return nullptr; - } - - 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; - } - - void AiVoiceConnectingView::FreeImagePathsArray(const char **imagePaths, const int numImages) - { - for (int i = 0; i < numImages; i++) - { - // ImageCacheManager::GetInstance().UnloadSingleRes(imagePaths[i]); - delete imagePaths[i]; - imagePaths[i] = nullptr; - } - } - UIImageAnimatorView *AiVoiceConnectingView::connectingImageAnimatorInit(ImageAnimatorConfig &imageanimatorconfig) { UIImageAnimatorView *animatorView = new UIImageAnimatorView(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceListeningView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceListeningView.cpp index 808c30d7e..237a34224 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceListeningView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceListeningView.cpp @@ -10,6 +10,7 @@ #include "wearable_log.h" #include "ui_resource_string.h" #include +#include "uicomponents/UIComponents.h" // #include "common/image_cache_manager.h" namespace OHOS { @@ -73,34 +74,6 @@ namespace OHOS } } - const char **AivoiceListeningView::CreateImagePathsArray(const char *basePath, const int numImages, const char *fileExtension) - { - const char **imagePaths = new const char *[numImages]; - if (imagePaths == nullptr) - { - return nullptr; - } - - 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; - } - - void AivoiceListeningView::FreeImagePathsArray(const char **imagePaths, const int numImages) - { - for (int i = 0; i < numImages; i++) - { - // ImageCacheManager::GetInstance().UnloadSingleRes(imagePaths[i]); - delete imagePaths[i]; - imagePaths[i] = nullptr; - } - } - UILabelExt *AivoiceListeningView::AivoiceListeningLabelInit(LabelConfig &labelconfig) { UILabelExt *label = new UILabelExt(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceThinkingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceThinkingView.cpp index 527551025..40654518e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceThinkingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceThinkingView.cpp @@ -10,6 +10,7 @@ #include "wearable_log.h" #include "ui_resource_string.h" #include +#include "uicomponents/UIComponents.h" // #include "common/image_cache_manager.h" namespace OHOS { @@ -73,34 +74,6 @@ namespace OHOS } } - const char **AivoiceThinkingView::CreateImagePathsArray(const char *basePath, const int numImages, const char *fileExtension) - { - const char **imagePaths = new const char *[numImages]; - if (imagePaths == nullptr) - { - return nullptr; - } - - 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; - } - - void AivoiceThinkingView::FreeImagePathsArray(const char **imagePaths, const int numImages) - { - for (int i = 0; i < numImages; i++) - { - // ImageCacheManager::GetInstance().UnloadSingleRes(imagePaths[i]); - delete imagePaths[i]; - imagePaths[i] = nullptr; - } - } - UILabelExt *AivoiceThinkingView::AivoiceThinkingLabelInit(LabelConfig &labelconfig) { UILabelExt *label = new UILabelExt(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneView.h b/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneView.h index c033ea466..e6cb3916c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneView.h @@ -35,8 +35,6 @@ namespace OHOS void FindPhoneViewInit_BlueToothConnected(void); void FindPhoneViewInit_BlueToothDisConnected(void); void ClearAll(); - const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages); - void FreeImagePathsArray(const char **imagePaths, const int numImages); UIViewGroup *FindPhoneGroupView = nullptr; UILabelExt *FindPhoneTitleLabel = nullptr; UILabelExt *FindPhoneLabel = nullptr; diff --git a/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp b/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp index 541f80f18..f01084c02 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-06-19 19:25:22 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-30 19:23:15 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp + */ /* * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-27 10:47:46 @@ -13,6 +19,7 @@ #include "bletest.h" #include "bleEvent.h" #include "ui_resource_string.h" +#include "uicomponents/UIComponents.h" namespace OHOS { @@ -82,33 +89,6 @@ namespace OHOS } } - const char **FindPhoneView::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 FindPhoneView::FreeImagePathsArray(const char **imagePaths, const int numImages) - { - for (int i = 0; i < numImages; i++) - { - delete imagePaths[i]; - imagePaths[i] = nullptr; - } - } - /*蓝牙如果是未连接状态*/ void FindPhoneView::FindPhoneViewInit_BlueToothDisConnected(void) { @@ -134,7 +114,7 @@ namespace OHOS FindPhoneTitleLabel->SetPosition(133, 51, 200, 40); FindPhoneTitleLabel->SetStyle(STYLE_TEXT_FONT, 30); FindPhoneTitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35); - //FindPhoneTitleLabel->SetText("查找手机"); + // FindPhoneTitleLabel->SetText("查找手机"); FindPhoneTitleLabel->SetTextId(STR_FIND_PHONE); FindPhoneTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); FindPhoneTitleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); @@ -158,7 +138,7 @@ namespace OHOS FindPhoneLabel->SetPosition(33, 270, 400, 40); FindPhoneLabel->SetStyle(STYLE_TEXT_FONT, 30); FindPhoneLabel->SetStyle(STYLE_LINE_HEIGHT, 35); - //FindPhoneLabel->SetText("蓝牙未连接"); + // FindPhoneLabel->SetText("蓝牙未连接"); FindPhoneLabel->SetTextId(STR_BLUETOOTH_DISCONNECTED); FindPhoneLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); FindPhoneLabel->SetTextColor(Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff)); @@ -174,7 +154,7 @@ namespace OHOS FindPhoneLabelButton->SetPosition(0, 366, 466, 100); FindPhoneLabelButton->SetViewId(FINDPHONE_LABELBUTTON); FindPhoneLabelButton->SetImageSrc(PNG_BUTTON_466x100_IMAGE, PNG_BUTTON_466x100_IMAGE); - //FindPhoneLabelButton->SetText("关闭"); + // FindPhoneLabelButton->SetText("关闭"); FindPhoneLabelButton->SetTextId(STR_CLOSE); FindPhoneLabelButton->SetTextColor(Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff)); FindPhoneLabelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); @@ -215,13 +195,13 @@ namespace OHOS FindPhoneTitleLabel->SetPosition(133, 51, 200, 40); FindPhoneTitleLabel->SetStyle(STYLE_TEXT_FONT, 30); FindPhoneTitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35); - //FindPhoneTitleLabel->SetText("查找手机"); + // FindPhoneTitleLabel->SetText("查找手机"); FindPhoneTitleLabel->SetTextId(STR_FIND_PHONE); FindPhoneTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); FindPhoneTitleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); FindPhoneTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); /* ----------------------- FindPhoneImageAnimator ---------------------- */ - FindPhonePathsArray = CreateImagePathsArray("/user/res/findphone/", "bin", FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + FindPhonePathsArray = CreateImagePathsArray("/user/res/findphone/",FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); if (FindPhoneImageAnimator == nullptr) { FindPhoneImageAnimator = new UIImageAnimatorView(); @@ -256,7 +236,7 @@ namespace OHOS FindPhoneLabel->SetPosition(33, 270, 400, 40); FindPhoneLabel->SetStyle(STYLE_TEXT_FONT, 30); FindPhoneLabel->SetStyle(STYLE_LINE_HEIGHT, 35); - //FindPhoneLabel->SetText("手机正在响铃/震动"); + // FindPhoneLabel->SetText("手机正在响铃/震动"); FindPhoneLabel->SetTextId(STR_PHONE_RINGING_VIBRATING); FindPhoneLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); FindPhoneLabel->SetTextColor(Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff)); @@ -272,7 +252,7 @@ namespace OHOS FindPhoneLabelButton->SetPosition(0, 366, 466, 100); FindPhoneLabelButton->SetViewId(FINDPHONE_LABELBUTTON); FindPhoneLabelButton->SetImageSrc(PNG_466x100BUTTON_IMAGE, PNG_466x100BUTTON_IMAGE); - //FindPhoneLabelButton->SetText("停止"); + // FindPhoneLabelButton->SetText("停止"); FindPhoneLabelButton->SetTextId(STR_STOP); FindPhoneLabelButton->SetTextColor(Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff)); FindPhoneLabelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); diff --git a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartChartView.cpp b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartChartView.cpp index b98dd720e..036b66a32 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartChartView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartChartView.cpp @@ -68,10 +68,11 @@ namespace OHOS HeartChartView::~HeartChartView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartChartView::~HeartChartView"); - imageAnimator->Stop(); + + // imageAnimator->Stop(); /* - UIViewGroup *tmpGroup = dynamic_cast(container_); - UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup); + UIViewGroup *tmpGroup = dynamic_cast(container_); + UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup); */ delete CurrentHeartText; @@ -95,7 +96,6 @@ namespace OHOS delete imageAnimator; imageAnimator = nullptr; - heartchart->ClearDataSerial(); delete heartSerial; heartSerial = nullptr; @@ -292,7 +292,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HeartChartView::InitHeartView fail"); } - HeartImageAnimator(); + // HeartImageAnimator(); InitChartView(); SetDataChart(); SetDataTopAndBottom(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/include/ShutDownImageAnimatorView.h b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/include/ShutDownImageAnimatorView.h index ae0efbb09..89cc1e561 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/include/ShutDownImageAnimatorView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/include/ShutDownImageAnimatorView.h @@ -37,8 +37,7 @@ namespace OHOS void OnAnimatorStop(UIView &view) override; void ClearAll(void); bool ShowUpShutDownAnimatorView(); - const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages); - void FreeImagePathsArray(const char **imagePaths, const int numImages); + UIViewGroup *group{nullptr}; UIImageAnimatorView *shutDownImageAnimatorView{nullptr}; // 关机动画 ImageAnimatorInfo ShutDownImageInfo[SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; // 关机图像的信息 diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/ShutDownImageAnimatorView.cpp b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/ShutDownImageAnimatorView.cpp index a9504e494..b73683f58 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/ShutDownImageAnimatorView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/ShutDownImageAnimatorView.cpp @@ -1,7 +1,14 @@ +/*** + * @Date: 2024-08-29 11:02:07 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-30 19:24:04 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/ShutDownImageAnimatorView.cpp + */ #include "rebootandshutdown/include/ShutDownImageAnimatorView.h" #include "rebootandshutdown/include/RebootAndShutdownPresenter.h" #include "wearable_log.h" #include +#include "uicomponents/UIComponents.h" namespace OHOS { @@ -22,28 +29,6 @@ namespace OHOS return g_pShutDownAnimatorView; } - const char **ShutDownImageAnimatorView::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; - } - - void ShutDownImageAnimatorView::FreeImagePathsArray(const char **imagePaths, const int numImages) - { - for (int i = 0; i < numImages; i++) - { - delete imagePaths[i]; - imagePaths[i] = nullptr; - } - } - void ShutDownImageAnimatorView::ClearAll(void) { if (group != nullptr) @@ -87,7 +72,7 @@ namespace OHOS isShutDownImageAnimatorStart = true; } - //获取开机动画是否已经开始 + // 获取开机动画是否已经开始 bool ShutDownImageAnimatorView::GetShutDownImageAnimatorIsStart(void) { return isShutDownImageAnimatorStart; @@ -96,7 +81,7 @@ namespace OHOS bool ShutDownImageAnimatorView::ShowUpShutDownAnimatorView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ShutDownImageAnimatorView::ShowUpShutDownAnimatorView"); - ShutDownPathsArray = CreateImagePathsArray(ShutDownPaths, "bin", SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + ShutDownPathsArray = CreateImagePathsArray(ShutDownPaths, SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); if (shutDownImageAnimatorView == nullptr) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/respiratorytraining/include/RespiratoryTrainingView.h b/code/sdk/application/wearable/fd230app/nativeui/respiratorytraining/include/RespiratoryTrainingView.h index d6cf3dcaa..0ff35846e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/respiratorytraining/include/RespiratoryTrainingView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/respiratorytraining/include/RespiratoryTrainingView.h @@ -91,8 +91,6 @@ namespace OHOS void RespiratoryTrainingViewInit(void); void ClearAll(void); #if 0 - const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages); - void FreeImagePathsArray(const char **imagePaths, const int numImages); void InitializeRespiratoryTrainingImageInfo(); void SetAnimatorViewProperties(); void CreateRespiratoryTrainingAnimatorView(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/respiratorytraining/src/RespiratoryTrainingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/respiratorytraining/src/RespiratoryTrainingView.cpp index 04fa4a729..af98867bf 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/respiratorytraining/src/RespiratoryTrainingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/respiratorytraining/src/RespiratoryTrainingView.cpp @@ -165,32 +165,6 @@ namespace OHOS } } - const char **RespiratoryTrainingView::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 RespiratoryTrainingView::FreeImagePathsArray(const char **imagePaths, const int numImages) - { - for (int i = 0; i < numImages; i++) - { - delete imagePaths[i]; - imagePaths[i] = nullptr; - } - } - // 初始化呼吸训练动画图片信息 void RespiratoryTrainingView::InitializeRespiratoryTrainingImageInfo() { diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveElePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveElePresenter.cpp index e83142710..6c084ed83 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveElePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveElePresenter.cpp @@ -19,7 +19,7 @@ #include "common/key_code.h" #include "saveele/include/SaveElePresenter.h" - +#include "gfx_utils/mem_check.h" namespace OHOS { @@ -28,13 +28,17 @@ namespace OHOS SaveElePresenter::SaveElePresenter() { - +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(true); +#endif g_pSaveElePresenter = this; } SaveElePresenter::~SaveElePresenter() { - +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(false); +#endif g_pSaveElePresenter = nullptr; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h index faa5c33f8..f44d3d90e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h @@ -51,8 +51,6 @@ namespace OHOS void SleepDataRefresh(); private: - const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages); - void FreeImagePathsArray(const char **imagePaths, const int numImages); void DumpWeatherInfo(); private: diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlPresenter.cpp index dd9776cef..d300dc71d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlPresenter.cpp @@ -33,7 +33,7 @@ namespace OHOS { g_pSleepControlPresenter = nullptr; #ifdef MEM_CHECK - MemCheck::GetInstance()->EnableLeakCheck(true); + MemCheck::GetInstance()->EnableLeakCheck(false); #endif } diff --git a/code/sdk/application/wearable/fd230app/nativeui/takephotos/include/TakephotosView.h b/code/sdk/application/wearable/fd230app/nativeui/takephotos/include/TakephotosView.h index 37f202444..46717ada8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/takephotos/include/TakephotosView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/takephotos/include/TakephotosView.h @@ -83,6 +83,11 @@ namespace OHOS UIImageAnimatorView *smileAnimator{nullptr}; bool viewiInitStatus{false}; + + std::string creambasePath; + const char **creamimagePaths; + std::string smilebasePath; + const char **smileimagePaths; }; } // namespace OHOS #endif // Takephotos_PRESENTER_H diff --git a/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosView.cpp b/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosView.cpp index 4c6614c22..76f08718b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosView.cpp @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-08-29 19:34:29 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-30 19:46:48 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosView.cpp + */ #include "takephotos/include/TakephotosView.h" #include "takephotos/include/TakephotosModel.h" @@ -25,7 +31,9 @@ namespace OHOS // DeInit(); creamAnimator->Stop(); - smileAnimator->Start(); + smileAnimator->Stop(); + FreeImagePathsArray(creamimagePaths, 50); + FreeImagePathsArray(smileimagePaths, 27); UIViewGroup *tmpGroup = dynamic_cast(container_); UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup); @@ -137,10 +145,9 @@ namespace OHOS buttongo->SetOnClickListener(static_cast(TakephotosPresenter::GetInstance())); // 初始化图片数组以及动画 - const char *basePath = "/user/res/takephotos/cream/"; - const char *fileExtension = "bin"; - const char **imagePaths = CreateImagePathsArray(basePath, fileExtension, 50); - InitImageAnimatorSource(creamAnimator, imagePaths, 50, 163, 103, 140, 140, "imageAnimator", 100); + creambasePath = "/user/res/takephotos/cream/"; + creamimagePaths = CreateImagePathsArray(creambasePath.c_str(), 50); + InitImageAnimatorSource(creamAnimator, creamimagePaths, 50, 163, 103, 140, 140, "imageAnimator", 100); creamView->Add(creamAnimator); creamView->Add(labeltitle_); @@ -189,10 +196,9 @@ namespace OHOS buttontake->SetOnClickListener(static_cast(TakephotosPresenter::GetInstance())); // 初始化图片数组以及动画 {修改为统一动画} - const char *basePath = "/user/res/takephotos/cream/"; - const char *fileExtension = "bin"; - const char **imagePaths = CreateImagePathsArray(basePath, fileExtension, 27); - InitImageAnimatorSource(smileAnimator, imagePaths, 27, 163, 140, 140, 140, "imageAnimator", 100); + smilebasePath = "/user/res/takephotos/cream/"; + smileimagePaths = CreateImagePathsArray(smilebasePath.c_str(), 27); + InitImageAnimatorSource(smileAnimator, smileimagePaths, 27, 163, 140, 140, 140, "imageAnimator", 100); takeView->Add(smileAnimator); takeView->Add(labeltake_); diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TraingCardView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TraingCardView.h index fb8ef2c21..a98a15120 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TraingCardView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TraingCardView.h @@ -134,6 +134,9 @@ namespace OHOS bool viewiInitStatus{false}; bool momentumFlag{false}; + + std::string winbasePath; + const char **winimagePaths; }; } // namespace OHOS #endif // TraingCard_PRESENTER_H diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardView.cpp index 2ba20c01f..aa5f4f5be 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardView.cpp @@ -87,7 +87,9 @@ namespace OHOS TraingCardView::~TraingCardView() { + FreeImagePathsArray(winimagePaths, 94); DeInit(); + g_pTraingCardView = nullptr; DisableTimer(); // 关闭计时器 TraingModel::GetInstance()->SetTimestamp(); @@ -486,10 +488,9 @@ namespace OHOS getView->Add(labeltag); // 初始化图片数组以及动画 - const char *basePath = "/user/res/Training/training_GIF/win/"; - const char *fileExtension = "bin"; - const char **imagePaths = CreateImagePathsArray(basePath, fileExtension, 94); - InitImageAnimatorSource(imageAnimator, imagePaths, 94, 173, 100, 120, 120, "imageAnimator1", 10); + winbasePath = "/user/res/Training/training_GIF/win/"; + winimagePaths = CreateImagePathsArray(winbasePath.c_str(), 94); + InitImageAnimatorSource(imageAnimator, winimagePaths, 94, 173, 100, 120, 120, "imageAnimator1", 10); getView->Add(imageAnimator); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h index b4c928555..a88438626 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h @@ -57,8 +57,6 @@ namespace OHOS std::string WindSpeedData; // 风速数据 std::string HumidityData; // 湿度数据 private: - const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages); - void FreeImagePathsArray(const char **imagePaths, const int numImages); UILabelExt *SetUpLabel(LabelConfig &labelconfig); // 设置标签 UILabelExt *SetUpLabelExt(LabelConfig &labelconfig); bool WeatherReportViewLabelInit(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h index 56bc2ff70..0eac61d28 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-08-19 11:01:42 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-30 19:24:56 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h + */ /* * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-30 09:14:38 @@ -40,9 +46,6 @@ namespace OHOS private: UILabelExt *InitLabelExt(int x, int y, int w, int h, const char *text, int textfont, int lineheight); - const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages); - void FreeImagePathsArray(const char **imagePaths, const int numImages); - private: void DumpWeatherInfo(); bool SetImageSource(UIImageView *image, const std::string &source); diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp index 641e0dbe7..2aa956335 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp @@ -1,7 +1,14 @@ +/*** + * @Date: 2024-08-19 11:01:42 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-30 19:25:11 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp + */ #include "weather/include/WeatherReportView.h" #include "wearable_log.h" #include "weather/include/WeatherModel.h" #include "common/image_cache_manager.h" +#include "uicomponents/UIComponents.h" namespace OHOS { static constexpr int16_t UV_IMAGE_ANIMATOR_VIEW_X = 53; @@ -249,7 +256,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherReportView::WeatherReportViewImageAnimatorViewInit"); /* ----------------------------- UVImageAnimatorView---------------------------- */ - UVPathsArray = CreateImagePathsArray(UVPaths, "bin", UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + UVPathsArray = CreateImagePathsArray(UVPaths, UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); if (UVImageAnimatorView == nullptr) { UVImageAnimatorView = new UIImageAnimatorView(); @@ -275,7 +282,7 @@ namespace OHOS UVImageAnimatorView->Start(); } /* ----------------------- WindSpeedImageAnimatorView ----------------------- */ - WindSpeedPathsArray = CreateImagePathsArray(WindSpeedPaths, "bin", WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + WindSpeedPathsArray = CreateImagePathsArray(WindSpeedPaths, WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); if (WindSpeedImageAnimatorView == nullptr) { WindSpeedImageAnimatorView = new UIImageAnimatorView(); @@ -301,7 +308,7 @@ namespace OHOS WindSpeedImageAnimatorView->Start(); } /* ------------------------ HumidityImageAnimatorView ----------------------- */ - HumidityPathsArray = CreateImagePathsArray(HumidityPaths, "bin", HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + HumidityPathsArray = CreateImagePathsArray(HumidityPaths, HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); if (HumidityImageAnimatorView == nullptr) { HumidityImageAnimatorView = new UIImageAnimatorView(); @@ -373,32 +380,6 @@ namespace OHOS return true; } - const char **WeatherReportView::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 WeatherReportView::FreeImagePathsArray(const char **imagePaths, const int numImages) - { - for (int i = 0; i < numImages; i++) - { - delete imagePaths[i]; - imagePaths[i] = nullptr; - } - } // 设置文本标签的通用函数 bool WeatherReportView::SetTextLabel(UILabel *label, const std::string &text) diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp index e23379c84..fae96ec99 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp @@ -328,33 +328,7 @@ namespace OHOS return true; } - const char **WeatherView::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 WeatherView::FreeImagePathsArray(const char **imagePaths, const int numImages) - { - for (int i = 0; i < numImages; i++) - { - delete imagePaths[i]; - imagePaths[i] = nullptr; - } - } - + // 设置文本标签的通用函数 bool WeatherView::SetTextLabel(UILabel *label, const std::string &text) { diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/pairing_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/pairing_notification.h index 1edfdc305..eb1ca8086 100644 --- a/code/sdk/application/wearable/service/msg_center/include/notify/pairing_notification.h +++ b/code/sdk/application/wearable/service/msg_center/include/notify/pairing_notification.h @@ -23,8 +23,6 @@ namespace OHOS { public: static PairingViewEventListener &GetInstance(void); - const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages); - void FreeImagePathsArray(const char **imagePaths, const int numImages); bool OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) override; void SetDeviceName(char *Name); char *GetDeviceName(); diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp index 87f2fa7c8..a67451ae2 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp @@ -298,29 +298,6 @@ namespace OHOS } - static void FreeImagePathsArray(const char **imagePaths, const int numImages) - { - for (int i = 0; i < numImages; i++) - { - // ImageCacheManager::GetInstance().UnloadSingleRes(imagePaths[i]); - delete imagePaths[i]; - imagePaths[i] = nullptr; - } - } - - static const char ** 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; - } - void ShowUpShutDownAnimatorView() { group = new UIViewGroup(); @@ -332,7 +309,7 @@ namespace OHOS group->SetPosition(0, 0, 466, 466); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShutDownAnimatorView::ShowUpShutDownAnimatorView"); - ShutDownPathsArray = CreateImagePathsArray_(ShutDownPaths, "bin", SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + ShutDownPathsArray = CreateImagePathsArray(ShutDownPaths, SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); if (ShutDownImageAnimatorView == nullptr) { diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/pairing_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/pairing_notification.cpp index d7456b7e1..dc90b53cc 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/pairing_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/pairing_notification.cpp @@ -17,7 +17,6 @@ #endif - #include #include #include @@ -25,6 +24,7 @@ #include "iostream" #include #include +#include "uicomponents/UIComponents.h" namespace OHOS { @@ -85,10 +85,10 @@ namespace OHOS { PairingViewEventListener::GetInstance().Pairing_StopTimer(); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PairingViewEventListener:: DeviceBindingButtonCancel OnClick"); - // 终止当前的绑定流程并关闭相关的通知界面。 - #ifdef SUPPORT_BLE_SERVICE +// 终止当前的绑定流程并关闭相关的通知界面。 +#ifdef SUPPORT_BLE_SERVICE comfirmPaire(0); - #endif +#endif NotificationManager::GetInstance()->StopNotify(); } else if (&view == DeviceBindingButtonOK) // 设备绑定确认按钮 @@ -101,45 +101,44 @@ namespace OHOS * 3.发送绑定请求到设备或服务器等. */ PairingViewEventListener::GetInstance().Pairing_StopTimer(); - // 关闭通知界面 - #ifdef SUPPORT_BLE_SERVICE +// 关闭通知界面 +#ifdef SUPPORT_BLE_SERVICE comfirmPaire(1); - #endif +#endif NotificationManager::GetInstance()->StopNotify(); } else if (&view == DeviceUnBindingButtonCancel) // 设备解绑取消按钮 { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PairingViewEventListener:: DeviceUnBindingButtonCancel OnClick"); - // 不想执行解绑动作,并关闭解绑的通知界面。 - #ifdef SUPPORT_BLE_SERVICE - cleanUnbindInfor(0); - #endif +// 不想执行解绑动作,并关闭解绑的通知界面。 +#ifdef SUPPORT_BLE_SERVICE + cleanUnbindInfor(0); +#endif NotificationManager::GetInstance()->StopNotify(); } else if (&view == DeviceUnBindingButtonOK) // 设备解绑确认按钮 { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PairingViewEventListener:: DeviceUnBindingButtonOK OnClick"); - /* - * 可能会执行的解绑流程: - * 1.通知设备或服务器执行解绑操作. - * 2.从绑定设备列表移除设备. - * 3.更新UI状态. - */ +/* + * 可能会执行的解绑流程: + * 1.通知设备或服务器执行解绑操作. + * 2.从绑定设备列表移除设备. + * 3.更新UI状态. + */ - // 关闭通知界面 - #ifdef SUPPORT_BLE_SERVICE - cleanUnbindInfor(1); - #endif +// 关闭通知界面 +#ifdef SUPPORT_BLE_SERVICE + cleanUnbindInfor(1); +#endif NotificationManager::GetInstance()->StopNotify(); } else if (&view == DeviceUnbindingRequestButtonOK) // 设备解除绑定请求(与新设备连接)确认 { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PairingViewEventListener:: DeviceUnbindingRequestButtonOK OnClick"); - - + NotificationManager::GetInstance()->StopNotify(); } - else if (&view == DeviceUnbindingRequestButtonCancel) //设备解除绑定请求(与新设备连接)取消 + else if (&view == DeviceUnbindingRequestButtonCancel) // 设备解除绑定请求(与新设备连接)取消 { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PairingViewEventListener:: DeviceUnbindingRequestButtonCancel OnClick"); NotificationManager::GetInstance()->StopNotify(); @@ -147,32 +146,6 @@ namespace OHOS return true; } - const char **PairingViewEventListener::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 PairingViewEventListener::FreeImagePathsArray(const char **imagePaths, const int numImages) - { - for (int i = 0; i < numImages; i++) - { - delete imagePaths[i]; - imagePaths[i] = nullptr; - } - } - static UIButton *CreateButton(unsigned int x, unsigned int y, unsigned int w, unsigned int h, const char *imageSrc) { UIButton *button = new UIButton(); @@ -191,24 +164,24 @@ namespace OHOS void PairingViewEventListener::SetDeviceName(char *Name) { // printf("Name:%s\r\n",Name); - memset(DeviceName,0,sizeof(DeviceName)); - if(Name == NULL) + memset(DeviceName, 0, sizeof(DeviceName)); + if (Name == NULL) { - strcpy(DeviceName,"phone"); + strcpy(DeviceName, "phone"); return; } int len = strlen(Name); - if(len > sizeof(DeviceName)) + if (len > sizeof(DeviceName)) len = sizeof(DeviceName); - Name[len]='\0'; - - memcpy(DeviceName,Name,len); + Name[len] = '\0'; + + memcpy(DeviceName, Name, len); } /*获取设备名称*/ char *PairingViewEventListener::GetDeviceName(void) { - return DeviceName; //先用固定字符串测试 + return DeviceName; // 先用固定字符串测试 } /* @@ -257,13 +230,15 @@ namespace OHOS DeviceBindingName->SetStyle(STYLE_TEXT_FONT, 30); DeviceBindingName->SetStyle(STYLE_LINE_HEIGHT, 35); - if(strlen(devanme)){ + if (strlen(devanme)) + { DeviceBindingName->SetText(devanme); - }else + } + else { DeviceBindingName->SetText(" "); } - + DeviceBindingName->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); DeviceBindingName->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); DeviceBindingName->SetRollSpeed(60); @@ -307,9 +282,9 @@ namespace OHOS DeviceBindingView->Add(DeviceBindingViewLabel); DeviceBindingView->Add(DeviceBindingButtonCancel); DeviceBindingView->Add(DeviceBindingButtonOK); - #if NO_LCD_TEST_CONNECT +#if NO_LCD_TEST_CONNECT PairingViewEventListener::GetInstance().Pairing_StartTimer(); - #endif +#endif } NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeDeviceBindingView); @@ -335,7 +310,7 @@ namespace OHOS DeviceUnBindingView->SetDraggable(true); DeviceUnBindingView->SetTouchable(true); /* ----------------------- DeviceUnBindingAnimatorView ---------------------- */ - UnBindPathsArray = PairingViewEventListener::GetInstance().CreateImagePathsArray("/user/res/remind/unbind/", "bin", UNBIND_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + UnBindPathsArray = CreateImagePathsArray("/user/res/remind/unbind/", UNBIND_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); if (DeviceUnBindingAnimatorView == nullptr) { DeviceUnBindingAnimatorView = new UIImageAnimatorView(); @@ -385,13 +360,14 @@ namespace OHOS DeviceUnBindingName->SetStyle(STYLE_TEXT_FONT, 30); DeviceUnBindingName->SetStyle(STYLE_LINE_HEIGHT, 35); - char *devanme = PairingViewEventListener::GetInstance().GetDeviceName(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceUnBindingView] DeviceUnBindingName devanme :%s",devanme); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceUnBindingView] DeviceUnBindingName devanme :%s", devanme); - if(strlen(devanme)){ + if (strlen(devanme)) + { DeviceUnBindingName->SetText(devanme); - }else + } + else { DeviceUnBindingName->SetText(" "); } @@ -440,7 +416,6 @@ namespace OHOS DeviceUnBindingView->Add(DeviceUnBindingViewLabel); DeviceUnBindingView->Add(DeviceUnBindingButtonCancel); DeviceUnBindingView->Add(DeviceUnBindingButtonOK); - } WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceUnBindingView] DeviceUnBindingView new success!!"); NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeDeviceUnBindingView); @@ -515,7 +490,7 @@ namespace OHOS DeviceUnbindingRequestViewLabel[0]->SetStyle(STYLE_LINE_HEIGHT, 40); char str[512]; memset(str, 0, 512); - + sprintf(str, "当前设备已经与 %s 绑定", PairingViewEventListener::GetInstance().GetDeviceName()); DeviceUnbindingRequestViewLabel[0]->SetText(str); DeviceUnbindingRequestViewLabel[0]->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); @@ -623,25 +598,21 @@ namespace OHOS delete DeviceUnBindingViewTitleLabel; DeviceUnBindingViewTitleLabel = nullptr; - PairingViewEventListener::GetInstance().FreeImagePathsArray(UnBindPathsArray, UNBIND_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); - + FreeImagePathsArray(UnBindPathsArray, UNBIND_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + DeviceUnBindingAnimatorView->Stop(); delete DeviceUnBindingAnimatorView; DeviceUnBindingAnimatorView = nullptr; - delete DeviceUnBindingName; DeviceUnBindingName = nullptr; - delete DeviceUnBindingViewLabel; DeviceUnBindingViewLabel = nullptr; - delete DeviceUnBindingButtonCancel; DeviceUnBindingButtonCancel = nullptr; - delete DeviceUnBindingButtonOK; DeviceUnBindingButtonOK = nullptr; @@ -695,7 +666,7 @@ namespace OHOS } /* -------------------------------------------------------------------------- */ - + // 声明定时器变量 static osTimerId_t g_timer = NULL; @@ -703,22 +674,22 @@ namespace OHOS static void Pairing_TimerCallbackProc(int data) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Pairing_TimerCallbackProc"); - #ifdef SUPPORT_BLE_SERVICE - #if NO_LCD_TEST_CONNECT +#ifdef SUPPORT_BLE_SERVICE +#if NO_LCD_TEST_CONNECT comfirmPaire(1); - #else +#else comfirmPaire(0); - #endif - #endif - if( NotificationManager::GetInstance()->GetShowingNotifyId() == TOPIC_EVENT_DEVICE_BIND && +#endif +#endif + if (NotificationManager::GetInstance()->GetShowingNotifyId() == TOPIC_EVENT_DEVICE_BIND && NotificationManager::GetInstance()->HasNotifyShowing() == true) { NotificationManager::GetInstance()->StopNotify(); } - + PairingViewEventListener::GetInstance().Pairing_StopTimer(); } - + /* * @brief 回调函数 */ -- 2.17.1