From cd669e9e96c0c1593f4cc56dff0ea80784209f6d Mon Sep 17 00:00:00 2001 From: xue <2144439972@qq.com> Date: Wed, 24 Sep 2025 15:53:41 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E6=97=A5=E7=A8=8B=E4=B8=8E?= =?utf8?q?=E4=BB=BB=E5=8A=A1UI=E5=8A=9F=E8=83=BD=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../thunderbird/include/ThunderBirdModel.h | 6 ++ .../include/ThunderBirdReminderView.h | 3 + .../thunderbird/src/ThunderBirdModel.cpp | 43 +++++++++++++++ .../src/ThunderBirdReminderView.cpp | 31 +++++++++++ .../nativeui/uiservice/src/ui_service.cpp | 55 +++++++++++++++++-- 5 files changed, 134 insertions(+), 4 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 ce774129a..0d156a71f 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 @@ -159,6 +159,12 @@ namespace OHOS bool getbind_status(); bool Get_is_ln_get_device_token_success(); + + // 日程提醒处理函数 + void HandleScheduleReminder(const char* title, const char* content); + + // 任务提醒处理函数 + void HandleTaskReminder(const char* scheduleName); private: ThunderBirdModel(); diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdReminderView.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdReminderView.h index 16b7f9ddf..948b268ca 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdReminderView.h +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdReminderView.h @@ -23,6 +23,9 @@ namespace OHOS // 音量/进度调节接口(用于 THUNDERBIRD_REMINDERVIEW_VOLUME) void AdjustRemindProgress(int16_t delta); // 正数增加,负数减少 void SetRemindProgress(int16_t value); + + // 任务提醒文本更新接口(用于 THUNDERBIRD_REMINDERVIEW_TASK_REMINDER) + void UpdateTaskReminderText(const char* title, const char* content); enum : int16_t { THUNDERBIRD_REMINDERVIEW_VOLUME = 0, // 音量调节 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 3b1691d65..2af88b4fe 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 @@ -1427,5 +1427,48 @@ // ws_register_ai_answer_callback(ws_register_ai_answer_cb); } + void ThunderBirdModel::HandleScheduleReminder(const char* title, const char* content) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::HandleScheduleReminder"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Title: %s", title ? title : "NULL"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Content: %s", content ? content : "NULL"); + + // 示例:通过图形服务显示提醒 + if (title && content) { + // 可以在这里调用UI相关的显示逻辑 + int currentView = ThunderBirdMainView::GetInstance()->GetCurrentView(); + ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_REMINDERVIEW, ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_TASK_REMINDER); + + // 更新任务提醒的文本内容 + if (ThunderBirdReminderView::GetInstance()) { + ThunderBirdReminderView::GetInstance()->UpdateTaskReminderText(content,nullptr); + } + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Processing schedule reminder: %s - %s", title, content); + } + } + + void ThunderBirdModel::HandleTaskReminder(const char* scheduleName) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdModel::HandleTaskReminder"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScheduleName: %s", scheduleName ? scheduleName : "NULL"); + + // 这里可以添加具体的任务提醒处理逻辑 + // 例如:显示任务提醒界面、播放提醒音、更新任务列表等 + + // 示例:通过图形服务显示任务提醒 + if (scheduleName) { + // 可以在这里调用UI相关的显示逻辑 + int currentView = ThunderBirdMainView::GetInstance()->GetCurrentView(); + ThunderBirdMainView::GetInstance()->ChangeView(currentView, THUNDERBIRD_REMINDERVIEW, ThunderBirdReminderView::THUNDERBIRD_REMINDERVIEW_TASK_REMINDER); + + // 更新任务提醒的文本内容 + if (ThunderBirdReminderView::GetInstance()) { + ThunderBirdReminderView::GetInstance()->UpdateTaskReminderText(scheduleName,nullptr); + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Processing task reminder: %s", scheduleName); + } + } + } \ No newline at end of file diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp index 82df46955..db9333dbd 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdReminderView.cpp @@ -416,6 +416,37 @@ namespace OHOS if (RemindButton) { RemindButton->SetVisible(true); } } + void ThunderBirdReminderView::UpdateTaskReminderText(const char* title, const char* content) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdReminderView::UpdateTaskReminderText"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Title: %s, Content: %s", title ? title : "NULL", content ? content : "NULL"); + + if (TextLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TextLabel is null, cannot update task reminder text"); + return; + } + + if (title && content) { + // 组合标题和内容,用换行符分隔 + char combinedText[512] = {0}; + snprintf(combinedText, sizeof(combinedText) - 1, "%s\n%s", title, content); + TextLabel->SetText(combinedText); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Updated task reminder text: %s", combinedText); + } else if (title) { + // 只有标题 + TextLabel->SetText(title); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Updated task reminder text with title only: %s", title); + } else if (content) { + // 只有内容 + TextLabel->SetText(content); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Updated task reminder text with content only: %s", content); + } else { + // 都没有,使用默认文本 + TextLabel->SetText("11点了该睡觉了"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Updated task reminder text with default text"); + } + } + } diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp index ebe38b58e..39e2e3557 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/uiservice/src/ui_service.cpp @@ -305,14 +305,61 @@ void HandleJumpOtaView(Request *request) // 日程提醒通知 void HandScheduleReminderNotify(Request *request) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandScheduleReminderNotify msg_id = %d",request->msgId); - int status = *(int *)request->data; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandScheduleReminderNotify msg_id = %d", request->msgId); + + if (request->data == nullptr || request->len <= 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandScheduleReminderNotify: invalid data"); + return; + } + + // 解析接收到的数据:标题和内容(以'\n'分隔) + // 使用 std::string 创建安全的数据副本 + std::string payload(static_cast(request->data), request->len); + + // 查找分隔符'\n' + size_t newlinePos = payload.find('\n'); + if (newlinePos == std::string::npos) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandScheduleReminderNotify: no separator found"); + return; + } + + // 分离标题和内容 + std::string title = payload.substr(0, newlinePos); + std::string content = payload.substr(newlinePos + 1); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandScheduleReminderNotify title = %s, content = %s", title.c_str(), content.c_str()); + + // 通过图形服务调用 ThunderBirdModel 的处理函数 + GraphicService::GetInstance()->PostGraphicEvent( + [title, content]() { + if (OHOS::ThunderBirdModel::GetInstance()) { + OHOS::ThunderBirdModel::GetInstance()->HandleScheduleReminder(title.c_str(), content.c_str()); + } + }); } // 任务提醒通知 void HandTaskReminderNotify(Request *request) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandTaskReminderNotify msg_id = %d",request->msgId); - int status = *(int *)request->data; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandTaskReminderNotify msg_id = %d", request->msgId); + + if (request->data == nullptr || request->len <= 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandTaskReminderNotify: invalid data"); + return; + } + + // 解析接收到的数据:只有一个参数 scheduleName + // 使用 std::string 创建安全的数据副本 + std::string scheduleName(static_cast(request->data), request->len); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_UI_SERVICE, "HandTaskReminderNotify scheduleName = %s", scheduleName.c_str()); + + // 通过图形服务调用 ThunderBirdModel 的处理函数 + GraphicService::GetInstance()->PostGraphicEvent( + [scheduleName]() { + if (OHOS::ThunderBirdModel::GetInstance()) { + OHOS::ThunderBirdModel::GetInstance()->HandleTaskReminder(scheduleName.c_str()); + } + }); } /* -------------------------------------------------------------------------- */ #ifdef __cplusplus -- 2.17.1