From c8baf18f0241cc77b69c2d6e771634fdb03211da Mon Sep 17 00:00:00 2001 From: xue <2144439972@qq.com> Date: Sat, 20 Sep 2025 18:02:49 +0800 Subject: [PATCH] =?utf8?q?=E8=A7=A3=E5=86=B3=E5=86=85=E5=AD=98=E6=B3=84?= =?utf8?q?=E6=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../thunderbird/include/ThunderBirdModel.h | 2 + .../src/ThunderBirdLullabyView.cpp | 35 ++++++++++--- .../thunderbird/src/ThunderBirdMainView.cpp | 49 +++++++++++++------ .../thunderbird/src/ThunderBirdModel.cpp | 37 ++++++++++++-- .../thunderbird/src/ThunderBirdOtaView.cpp | 21 +++++--- .../thunderbird/src/ThunderBirdPresenter.cpp | 11 +++++ 6 files changed, 124 insertions(+), 31 deletions(-) diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h index 59c5e37d7..ad740c940 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdModel.h @@ -23,6 +23,7 @@ namespace OHOS void StopTimer(void); void StartTimer(uint32_t interval = 2 * 1000);//2秒 void StartReminderHideTimer(uint32_t intervalMs = 1000); + void StopReminderHideTimer(void); void StartOtaCountdown(uint32_t startVal); void StopOtaCountdown(void); void StartCountUpTimer(uint32_t targetSeconds); @@ -53,6 +54,7 @@ namespace OHOS // 对话相关函数 bool StartRecording(std::string audioPath); bool StopRecording(); + bool IsRecording() const; bool SendRecording(); bool ReceiveAnswer(); std::string GetConversationText(); diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdLullabyView.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdLullabyView.cpp index b4666982e..a607394b1 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdLullabyView.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdLullabyView.cpp @@ -126,16 +126,39 @@ namespace OHOS { if (group != nullptr) { + // 移除所有子组件 group->RemoveAll(); + + // 删除子组件 + if (TextLabel != nullptr) { + delete TextLabel; + TextLabel = nullptr; + } + if (TextLabel_Y != nullptr) { + delete TextLabel_Y; + TextLabel_Y = nullptr; + } + if (RemindLabel != nullptr) { + delete RemindLabel; + RemindLabel = nullptr; + } + if (RemindIcon != nullptr) { + delete RemindIcon; + RemindIcon = nullptr; + } + if (RemindIcon2 != nullptr) { + delete RemindIcon2; + RemindIcon2 = nullptr; + } + if (listenAnimator != nullptr) { + delete listenAnimator; + listenAnimator = nullptr; + } + + // 最后删除group delete group; group = nullptr; } - if (TextLabel != nullptr) { delete TextLabel; TextLabel = nullptr; } - if (TextLabel_Y != nullptr) { delete TextLabel_Y; TextLabel_Y = nullptr; } - if (RemindLabel != nullptr) { delete RemindLabel; RemindLabel = nullptr; } - if (RemindIcon != nullptr) { delete RemindIcon; RemindIcon = nullptr; } - if (RemindIcon2 != nullptr) { delete RemindIcon2; RemindIcon2 = nullptr; } - if (listenAnimator != nullptr) { delete listenAnimator; listenAnimator = nullptr; } } bool ThunderBirdLullabyView::EnsureListenAnimator() { diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdMainView.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdMainView.cpp index 562b193f9..7c77f4314 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdMainView.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdMainView.cpp @@ -73,7 +73,7 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::ThunderBirdMainView"); g_pThunderBirdMainView = this; - ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 打开屏幕常亮 + //ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 打开屏幕常亮 ThunderBirdModel::GetInstance()->StartTimer(); } @@ -88,7 +88,7 @@ namespace OHOS ScrollView_ = nullptr; } g_pThunderBirdMainView = nullptr; - ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 关闭屏幕常亮 + //ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 关闭屏幕常亮 ThunderBirdModel::GetInstance()->StopTimer(); } @@ -99,6 +99,16 @@ namespace OHOS void ThunderBirdMainView::DeInit() { + // 先清理所有group,确保UI组件正确移除 + for (int i = 0; i < MAXVIEW; i++) + { + if (group[i] != nullptr && ScrollView_ != nullptr) + { + ScrollView_->Remove(group[i]); + group[i] = nullptr; + } + } + // 释放各子界面对象 if (g_pThunderBirdOtaView) { @@ -135,16 +145,6 @@ namespace OHOS delete g_pThunderBirdShutdownView; g_pThunderBirdShutdownView = nullptr; } - if (g_pThunderBirdShutdownView) - { - delete g_pThunderBirdShutdownView; - g_pThunderBirdShutdownView = nullptr; - } - // 置空所有分组索引,避免悬空指针 - for (int i = 0; i < MAXVIEW; i++) - { - group[i] = nullptr; - } // 不再持有旧 View 实例,全部使用聚合组件 // 先停止视频播放 @@ -170,12 +170,20 @@ namespace OHOS if (curFace != nullptr) { + // 先从父组件中移除 + if (ScrollView_ != nullptr) { + ScrollView_->Remove(curFace); + } delete curFace; curFace = nullptr; } if (surfaceView_ != nullptr) { + // 先从父组件中移除 + if (ScrollView_ != nullptr) { + ScrollView_->Remove(surfaceView_); + } delete surfaceView_; surfaceView_ = nullptr; } @@ -183,6 +191,15 @@ namespace OHOS // 清理顶部状态UI group1 及其子控件 if (group1 != nullptr) { + // 先从父组件中移除group1 + if (ScrollView_ != nullptr) { + ScrollView_->Remove(group1); + } + + // 移除所有子组件 + group1->RemoveAll(); + + // 删除子组件 if (timeLabel != nullptr) { delete timeLabel; @@ -221,7 +238,8 @@ namespace OHOS delete chargeBatteryicon; chargeBatteryicon = nullptr; } - group1->RemoveAll(); + + // 最后删除group1 delete group1; group1 = nullptr; } @@ -307,8 +325,11 @@ namespace OHOS bool ThunderBirdMainView::SwitchVideo(const char *uri) // 切换表情接口 { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::SwitchVideo: Switching to video: %s", uri ? uri : "null"); + if (uri == nullptr || surfaceView_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdMainView::SwitchVideo: Invalid parameters"); return false; } // 停止并销毁旧播放器 @@ -631,7 +652,7 @@ namespace OHOS return; } curFace->SetAutoEnable(false); - curFace->SetPosition(0, 0, 360, 360); + curFace->SetPosition(0, 0, 360, 243); curFace->SetResizeMode(UIImageView::COVER); curFace->SetStyle(STYLE_BACKGROUND_OPA, 0x00); //curFace->SetStyle(STYLE_BACKGROUND_COLOR, 0xffe0c7c1); diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp index 35006c5ac..2d7454420 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdModel.cpp @@ -55,8 +55,23 @@ ThunderBirdModel::~ThunderBirdModel() { + // 停止所有定时器 + StopTimer(); + StopOtaCountdown(); + StopCountUpTimer(); + StopReminderHideTimer(); + + // 停止录音 + if (IsRecording()) { + StopRecording(); + } + // 析构时保存提醒数据 // SaveRemindersToFile(); + + // 清理字符串资源 + ClearTextStr(); + m_reminders.clear(); } ThunderBirdModel *ThunderBirdModel::GetInstance() @@ -236,8 +251,19 @@ } } - - + void ThunderBirdModel::StopReminderHideTimer(void) + { + if (g_reminderHideTimer != nullptr) + { + osTimerStop(g_reminderHideTimer); + osStatus_t ret = osTimerDelete(g_reminderHideTimer); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopReminderHideTimer delete failed, ret = %lx!!", ret); + } + g_reminderHideTimer = nullptr; + } + } // ---------------------- OTA 倒计时定时器(5 -> 1,每步1秒,然后监控下载状态) ---------------------- static osTimerId_t g_otaCountdownTimer = nullptr; @@ -595,7 +621,12 @@ return true; // 模拟成功 } - + + bool ThunderBirdModel::IsRecording() const + { + return g_isRecording; + } + bool ThunderBirdModel::StopRecording() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::StopRecording"); diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdOtaView.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdOtaView.cpp index 95fd3b7e2..c02e75740 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdOtaView.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdOtaView.cpp @@ -27,18 +27,23 @@ namespace OHOS { if (group != nullptr) { + // 移除所有子组件 group->RemoveAll(); + + // 删除子组件 + if (titleLabel != nullptr) { delete titleLabel; titleLabel = nullptr; } + if (TextLabel != nullptr) { delete TextLabel; TextLabel = nullptr; } + if (LittleTextLabel != nullptr) { delete LittleTextLabel; LittleTextLabel = nullptr; } + if (LittleTextLabel_2 != nullptr) { delete LittleTextLabel_2; LittleTextLabel_2 = nullptr; } + if (RemindLabel != nullptr) { delete RemindLabel; RemindLabel = nullptr; } + if (RemindIcon != nullptr) { delete RemindIcon; RemindIcon = nullptr; } + if (RemindIcon2 != nullptr) { delete RemindIcon2; RemindIcon2 = nullptr; } + if (BackGround != nullptr) { delete BackGround; BackGround = nullptr; } + + // 最后删除group delete group; group = nullptr; } - if (titleLabel != nullptr) { delete titleLabel; titleLabel = nullptr; } - if (TextLabel != nullptr) { delete TextLabel; TextLabel = nullptr; } - if (LittleTextLabel != nullptr) { delete LittleTextLabel; LittleTextLabel = nullptr; } - if (LittleTextLabel_2 != nullptr) { delete LittleTextLabel_2; LittleTextLabel_2 = nullptr; } - if (RemindLabel != nullptr) { delete RemindLabel; RemindLabel = nullptr; } - if (RemindIcon != nullptr) { delete RemindIcon; RemindIcon = nullptr; } - if (RemindIcon2 != nullptr) { delete RemindIcon2; RemindIcon2 = nullptr; } - if (BackGround != nullptr) { delete BackGround; BackGround = nullptr; } } UIViewGroup *ThunderBirdOtaView::ThunderBirdOtaViewInit(void) diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp index d813b9122..3cd7add26 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp @@ -58,6 +58,17 @@ namespace OHOS ThunderBirdPresenter::~ThunderBirdPresenter() { + // 停止所有定时器和资源 + ThunderBirdModel::GetInstance()->StopTimer(); + ThunderBirdModel::GetInstance()->StopOtaCountdown(); + ThunderBirdModel::GetInstance()->StopCountUpTimer(); + ThunderBirdModel::GetInstance()->StopReminderHideTimer(); + + // 停止录音 + if (ThunderBirdModel::GetInstance()->IsRecording()) { + ThunderBirdModel::GetInstance()->StopRecording(); + } + g_pThunderBirdPresenter = nullptr; } -- 2.17.1