From 1e4c5b2a72171c8ca1b5bf61b681edf9ec0b196c Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Fri, 29 Nov 2024 21:05:19 +0800 Subject: [PATCH] =?utf8?q?=E6=B6=88=E6=81=AF=EF=BC=9A=E4=BC=98=E5=8C=96?= =?utf8?q?=E5=A4=A7=E9=87=8F=E6=B6=88=E6=81=AF=E7=9A=84=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/message/src/MessageModel.cpp | 90 +-- .../msg_center/src/msg_center_customer.cpp | 18 +- .../msg_center/src/msg_center_customerC.h | 17 + .../src/notify/message_notification.cpp | 638 +++++++++--------- .../utils/custom_fileoperate_service.c | 4 + .../drivers/peripheral/utils/custom_utils.h | 2 + 6 files changed, 401 insertions(+), 368 deletions(-) create mode 100644 code/sdk/application/wearable/service/msg_center/src/msg_center_customerC.h diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp index 07d077e5e..41a0f97ad 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp @@ -43,6 +43,8 @@ #include "message/include/MessageControlView.h" #include "message/include/MessageView.h" +#include "traing/include/TraingModel.h" + #define MESSAGE_JSON_FILE "user/userdata/ancs.json" #define MESSAGE_JSON_DIR "user/userdata/message/" #define PRINTFDATA 0 @@ -110,11 +112,7 @@ void MessageUnsubscribeTopic(Topic topic) { } // 存储消息更新的定时器 -static std::chrono::milliseconds updateDelay(500); // 设置更新延迟,0.5s -static std::chrono::steady_clock::time_point lastUpdateTime; -static bool shouldDisplayMessage = false; -static ancs_data_info_t *lastMessageInfo = NULL; -static std::mutex messageMutex; // 互斥锁 +static uint32_t messageTimestamp = 0; static void Notify(void *args, const Topic topic, Request *request) { UNUSED(args); @@ -132,18 +130,18 @@ static void Notify(void *args, const Topic topic, Request *request) { "Processing TOPIC_EVENT_MESSAGE_UPDATA"); // 创建新的消息信息 - ancs_data_info_t *messageInfo = new ancs_data_info_t(); - if (messageInfo == NULL) { + ancs_data_info_t *messageInfo = new (std::nothrow) ancs_data_info_t(); + if (messageInfo == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to allocate memory for ancs_data_info_t"); - return; + return; // 直接返回,不需要释放 } // 复制请求数据到新的消息信息 int rets = memcpy_s(messageInfo, sizeof(ancs_data_info_t), (ancs_data_info_t *)request->data, request->len); if (rets != EOK) { - delete messageInfo; + delete messageInfo; // 释放内存 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "memcpy_s ancs_data_info_t failed, ret = %d", rets); return; @@ -152,53 +150,30 @@ static void Notify(void *args, const Topic topic, Request *request) { // 更新到模型里面的数组 MessageModel::GetInstance().AddMessageData(messageInfo); -#if 0 - // 加锁以保护共享变量 - { - std::lock_guard lock(messageMutex); - shouldDisplayMessage = true; // 标记需要显示新消息 - - // 设置最后更新时间 - lastUpdateTime = std::chrono::steady_clock::now(); - } - // 直接尝试显示消息(用于单条消息的情况) - { - std::lock_guard lock(messageMutex); // 加锁以保护共享变量 - - // 检查是否达到延迟时间 - auto now = std::chrono::steady_clock::now(); - auto timeDiff = now - lastUpdateTime; - WEARABLE_LOGD( - WEARABLE_LOG_MODULE_APP, "Time since last update: %lld milliseconds", - std::chrono::duration_cast(timeDiff) - .count()); - if (timeDiff>=updateDelay) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, - "Displaying new message after time delay"); - // 发送完毕,重置标志 - shouldDisplayMessage = false; // 重置状态 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, - "Reset shouldDisplayMessage to false"); - } else { - WEARABLE_LOGE( WEARABLE_LOG_MODULE_APP, "Message display delayed, waiting for next opportunity %lld ms %lld ms", - std::chrono::duration_cast(timeDiff).count(), - std::chrono::duration_cast(updateDelay).count()); - } + // 检查时间戳 + uint32_t currentTimestamp = + OHOS::TraingModel::GetInstance()->get_current_time(); + if (currentTimestamp - messageTimestamp <= 1) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageTimestamp too short"); + delete messageInfo; // 确保释放内存 + return; } -#endif - // 发送信息进行弹窗 + messageTimestamp = currentTimestamp; + + // 检查训练模式 if (uapi_dev_runtime_get_train_status() || uapi_dev_runtime_get_saveele_status() || uapi_dev_runtime_get_respiratory_training_status()) { - // 增加训练模式下,不弹窗 - // 省电模式,不弹窗 - // 呼吸训练,不弹窗 + // 在这些状态下不弹窗 + delete messageInfo; // 确保释放内存 return; } - // 发送弹窗通知 会自动查询到数组的最新一个 + // 发送弹窗通知 CustomEventPublish(TOPIC_EVENT_MESSAGENOTE, NULL, 0); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Message popup sent"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Message popup sent"); + + delete messageInfo; // 在成功完成后释放内存 } } void saveancsdata() { @@ -423,6 +398,7 @@ void MessageModel::AddMessageData(ancs_data_info_t *messageInfo) { return; } + // 创建并填充 MessageData MessageData data; data.isRead = messageInfo->read; data.labelDetails = messageInfo->msg; @@ -430,30 +406,32 @@ void MessageModel::AddMessageData(ancs_data_info_t *messageInfo) { data.timestamp = messageInfo->time; WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, - "AddMessageData data.isRead is %d,data.labelDetails is " - "%s,data.labelTitle is %s,data.timestamp is %d", + "AddMessageData data.isRead is %d, data.labelDetails is %s, " + "data.labelTitle is %s, data.timestamp is %d", data.isRead, data.labelDetails.c_str(), data.labelTitle.c_str(), data.timestamp); + // 处理时间字符串 char labelTime[20]; if (uapi_get_TIME_STR(data.timestamp, labelTime, '.', ':', DATE_Y_M_D_H_M) != ERRCODE_SUCC) { - data.labelTime = std::string("--"); + data.labelTime = "--"; // 默认值 } else { - data.labelTime = std::string(labelTime); + data.labelTime = labelTime; // 直接使用 labelTime } - // 添加数据 + // 添加数据到消息向量 MessageVector.push_back(data); // 删除多余的数据 - while (MessageVector.size() > MaxMessageListCount) { - MessageVector.erase(MessageVector.begin()); + if (MessageVector.size() > MaxMessageListCount) { + MessageVector.erase(MessageVector.begin(), + MessageVector.begin() + + (MessageVector.size() - MaxMessageListCount)); } WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageInfo add is ok"); } - // 获取目前的项 MessageData *MessageModel::GetCurrentMessageData() { if (currentIndex_ < MessageVector.size()) { diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp index e64a62393..dd9a16171 100644 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp @@ -81,6 +81,7 @@ #include "DialModelCalorie.h" #include "DialModelDistance.h" #include "DialModelStepgoal.h" +#include "msg_center_customerC.h" #define DIALDATASET 1 //#include "Systemupgrade.h" @@ -323,9 +324,10 @@ static OHOS::UIViewGroup* showSOSNotify(void) } /*显示消息提醒*/ -static OHOS::UIViewGroup* showMessageNotify(void) -{ - return OHOS::CreateMessageView(); +static OHOS::UIViewGroup *showMessageNotify(void) { + OHOS::UIViewGroup *view = OHOS::CreateMessageView(); + printf("showMessageNotify %p",view); + return view; } /*显示睡眠提醒*/ static OHOS::UIViewGroup* showSleepNotify(void) @@ -991,8 +993,7 @@ void MsgCenterNotifyMessageProc(const Topic topic, Request* req) unused(req); // WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyMessageProc !"); if (CheckPriority(topic)) { - NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_THREE); - NotificationManager::GetInstance()->ShowNotify(showMessageNotify, (uint16_t)topic, true); + do_custom_fileoperate_service_check_msg(CUSTOM_FILEOPERATE_MSG_TYPE_MESSAGE_DATA_NOTIFY, nullptr, 0); } } @@ -1943,6 +1944,13 @@ void MsgCenterReportBtStatusToJS(uint16_t msgId) WEARABLE_LOGI(WEARABLE_LOG_MODULE_MSG_CENTER, "unexpected msgId %d", msgId); } } + +void show_notify_messgae() { + printf("show_notify_messgae\n"); + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_THREE); + NotificationManager::GetInstance()->ShowNotify(showMessageNotify, TOPIC_EVENT_MESSAGENOTE, true); +} + #endif #ifdef __cplusplus diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customerC.h b/code/sdk/application/wearable/service/msg_center/src/msg_center_customerC.h new file mode 100644 index 000000000..10c26cfa8 --- /dev/null +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customerC.h @@ -0,0 +1,17 @@ +#ifndef MAG_CENTER_CUSTOMER_C_H +#define MAG_CENTER_CUSTOMER_C_H + +#ifdef __cplusplus +#if __cplusplus +extern "C" { +#endif +#endif + +void show_notify_messgae(void); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif +#endif diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp index d468f229a..22a30e9f1 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp @@ -1,21 +1,23 @@ -#include "notification_manager.h" -#include "wearable_log.h" -#include "components/ui_button.h" -#include -#include "ui_service.h" -#include #include "bleEvent.h" +#include "components/ui_button.h" #include "components/ui_label_ext.h" +#include "notification_manager.h" +#include "ui_service.h" #include "uicomponents/UIComponents.h" +#include "wearable_log.h" +#include +#include #ifdef FD230 #include "message/include/MessageModel.h" #endif -#include "message_notification.h" -#include "string" -#include "vibrator_service.h" +#include "../../../../../../../drivers/peripheral/config/include/ConfigModel.h" +#include "../../../../../../../drivers/peripheral/utils/custom_runtime.h" #include "ConfigModel.h" #include "iostream" +#include "message_notification.h" +#include "string" #include "uicomponents/UIComponents.h" +#include "vibrator_service.h" #include #include #include @@ -24,326 +26,348 @@ #include #include #include -#include "../../../../../../../drivers/peripheral/config/include/ConfigModel.h" -#include "../../../../../../../drivers/peripheral/utils/custom_runtime.h" -namespace OHOS -{ +namespace OHOS { - UIViewGroup *MessageGroupView{nullptr}; +UIViewGroup *MessageGroupView{nullptr}; - UILabel *titleLabel{nullptr}; // 标题 - UILabel *timeLabel{nullptr}; // 时间 - UILabel *messageLabel{nullptr}; // 详细label - UILabelButtonExt *deleteButton{nullptr}; // 删除按键 +UILabel *titleLabel{nullptr}; // 标题 +UILabel *timeLabel{nullptr}; // 时间 +UILabel *messageLabel{nullptr}; // 详细label +UILabelButtonExt *deleteButton{nullptr}; // 删除按键 - static std::string titleStr, timeStr, messageStr; - const char *buttonImgSrc = "/user/res/466x100button.bin"; +static std::string titleStr, timeStr, messageStr; +const char *buttonImgSrc = "/user/res/466x100button.bin"; #define DELETEBUTTON "delete_button" - MessageViewEventListener::MessageViewEventListener() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::MessageViewEventListener"); - } +MessageViewEventListener::MessageViewEventListener() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "MessageViewEventListener::MessageViewEventListener"); +} - MessageViewEventListener::~MessageViewEventListener() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::~MessageViewEventListener"); - } +MessageViewEventListener::~MessageViewEventListener() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "MessageViewEventListener::~MessageViewEventListener"); +} - MessageViewEventListener &MessageViewEventListener::GetInstance() - { - static MessageViewEventListener instance; - return instance; - } - bool MessageViewEventListener::OnRelease(UIView &view, const ReleaseEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::OnRelease"); - UNUSED(event); - if (strcmp(view.GetViewId(), DELETEBUTTON) == 0) - { - NotificationManager::GetInstance()->StopNotify(); - // 点击关闭之后通知list进行刷新 - SendMsgToUIService(UI_UPDATE_MESSAGE_DATA, 0, nullptr, 0); - } - - return true; +MessageViewEventListener &MessageViewEventListener::GetInstance() { + static MessageViewEventListener instance; + return instance; +} +bool MessageViewEventListener::OnRelease(UIView &view, + const ReleaseEvent &event) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::OnRelease"); + UNUSED(event); + if (strcmp(view.GetViewId(), DELETEBUTTON) == 0) { + NotificationManager::GetInstance()->StopNotify(); + // 点击关闭之后通知list进行刷新 + SendMsgToUIService(UI_UPDATE_MESSAGE_DATA, 0, nullptr, 0); + } + + return true; +} +bool MessageViewEventListener::OnDrag(UIView &view, const DragEvent &event) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::OnDrag"); + UNUSED(view); + NotificationManager::GetInstance()->StopNotify(); + // 点击关闭之后通知list进行刷新 + SendMsgToUIService(UI_UPDATE_MESSAGE_DATA, 0, nullptr, 0); + return true; +} + +bool MessageViewEventListener::OnDragEnd(UIView &view, const DragEvent &event) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + NotificationManager::GetInstance()->StopNotify(); + } + return true; +} + +/*创建信息弹窗*/ +UIViewGroup *CreateMessageView(void) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateMessageView"); + if (MessageGroupView == nullptr) { + MessageGroupView = new UIViewGroup(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "[CreateMessageView] MessageGroupView new %p", + MessageGroupView); + if (MessageGroupView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "[CreateMessageView] MessageGroupView new fail!!"); + return nullptr; } - bool MessageViewEventListener::OnDrag(UIView &view, const DragEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::OnDrag"); - UNUSED(view); - NotificationManager::GetInstance()->StopNotify(); - // 点击关闭之后通知list进行刷新 - SendMsgToUIService(UI_UPDATE_MESSAGE_DATA, 0, nullptr, 0); - return true; + MessageGroupView->SetPosition(0, 0, 466, 466); + // MessageGroupView->SetStyle(STYLE_BACKGROUND_COLOR, Color::GetColorFromRGB(0x00, 165, 230).full); + // MessageGroupView->SetStyle(STYLE_BACKGROUND_OPA, 255); // 127 : background opacity + MessageGroupView->SetViewId("messagenotify"); + MessageGroupView->SetTouchable(true); + MessageGroupView->SetDraggable(true); + UIView::OnDragListener *dragListener = + static_cast( + &MessageViewEventListener::GetInstance()); + if (dragListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "[CreateMessageView] dragListener new fail!!"); + return nullptr; } - bool MessageViewEventListener::OnDragEnd(UIView &view, const DragEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::OnDragEnd"); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) - { - NotificationManager::GetInstance()->StopNotify(); - } - return true; + MessageGroupView->SetOnDragListener(dragListener); + } + /*获取最新message*/ + MessageData *data = MessageModel::GetInstance().GetNewMessage(); + if (data != nullptr) { + titleStr = data->labelTitle; + timeStr = data->labelTime; + messageStr = data->labelDetails; + } else { + titleStr = "--"; + timeStr = "--"; + messageStr = "--"; + } + /*初始化label*/ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitView"); + /* --------------------------------------------------------------------------*/ + if (titleLabel == nullptr) { + titleLabel = new UILabel(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel:: new UILabel %p", + titleLabel); + if (titleLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel:: new UILabel fail"); + return nullptr; // 内存分配失败,返回 + } + titleLabel->SetPosition(83, 60, 300, 35); + titleLabel->SetText(titleStr.c_str()); + titleLabel->SetStyle(STYLE_TEXT_FONT, 30); + // titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + titleLabel->SetLineBreakMode( + UILabel::LINE_BREAK_OSCILLATION); // 来回滚动属性 + titleLabel->SetRollSpeed(70); + titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + titleLabel->SetVisible(true); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel is ok!"); + } + /* -------------------------------------------------------------------------- + */ + if (timeLabel == nullptr) { + timeLabel = new UILabel(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timeLabel:: new UILabel %p", + timeLabel); + if (timeLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timeLabel:: new UILabel fail"); + return nullptr; // 内存分配失败,返回 } + timeLabel->SetPosition(73, 104, 320, 33); + timeLabel->SetViewId("timeLabel"); + timeLabel->SetText(timeStr.c_str()); + timeLabel->SetTextColor(Color::Gray()); + timeLabel->SetStyle(STYLE_TEXT_FONT, 28); + timeLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28); + timeLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + timeLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + timeLabel->SetVisible(true); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timeLabel is ok!"); + } + /* -------------------------------------------------------------------------- + */ + /*初始化消息内容*/ + if (messageLabel == nullptr) { + messageLabel = new UILabel(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageLabel:: new UILabel %p", + messageLabel); + if (messageLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageLabel:: new UILabel fail"); + return nullptr; // 内存分配失败,返回 + } + messageLabel->SetPosition(53, 170, 360, 144); + messageLabel->SetViewId("messageLabel"); + messageLabel->SetText(messageStr.c_str()); + messageLabel->SetTextColor(Color::Gray()); + messageLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + messageLabel->SetLineBreakMode(UILabel::LINE_BREAK_CLIP); // 换行裁剪 + messageLabel->SetAlign(TEXT_ALIGNMENT_CENTER, + TEXT_ALIGNMENT_CENTER); // 居中显示 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageLabel is ok"); + } + /*加载清除按键*/ + if (deleteButton == nullptr) { + deleteButton = new UILabelButtonExt(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "deleteButton:: new UILabelButtonExt %p", deleteButton); - /*创建信息弹窗*/ - UIViewGroup *CreateMessageView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CreateMessageView"); - MessageGroupView = new UIViewGroup(); - if (MessageGroupView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateMessageView] MessageGroupView new fail!!"); - return nullptr; - } - MessageGroupView->SetPosition(0, 0, 466, 466); - MessageGroupView->SetViewId("messagenotify"); - MessageGroupView->SetTouchable(true); - MessageGroupView->SetDraggable(true); - UIView::OnDragListener *dragListener = static_cast(&MessageViewEventListener::GetInstance()); - if (dragListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateMessageView] dragListener new fail!!"); - return nullptr; - } - MessageGroupView->SetOnDragListener(dragListener); -#ifdef FD230 - /*获取最新message*/ - MessageData *data = MessageModel::GetInstance().GetNewMessage(); - if (data != nullptr) - { - titleStr = data->labelTitle; - timeStr = data->labelTime; - messageStr = data->labelDetails; - } - else - { - titleStr = "--"; - timeStr = "--"; - messageStr = "--"; - } -#endif - /*初始化label*/ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitView"); - /* -------------------------------------------------------------------------- */ - titleLabel = new UILabel(); - if (titleLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel:: new UILabel fail"); - return nullptr; // 内存分配失败,返回 - } - titleLabel->SetPosition(83, 60, 300, 35); - titleLabel->SetText(titleStr.c_str()); - titleLabel->SetStyle(STYLE_TEXT_FONT, 30); - // titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); - titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); // 来回滚动属性 - titleLabel->SetRollSpeed(70); - titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - titleLabel->SetVisible(true); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "titleLabel is ok!"); - /* -------------------------------------------------------------------------- */ - timeLabel = new UILabel(); - if (timeLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timeLabel:: new UILabel fail"); - return nullptr; // 内存分配失败,返回 - } - timeLabel->SetPosition(73, 104, 320, 33); - timeLabel->SetViewId("timeLabel"); - timeLabel->SetText(timeStr.c_str()); - timeLabel->SetTextColor(Color::Gray()); - timeLabel->SetStyle(STYLE_TEXT_FONT, 28); - timeLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28); - timeLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); - timeLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - timeLabel->SetVisible(true); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "timeLabel is ok!"); - /* -------------------------------------------------------------------------- */ - /*初始化消息内容*/ - messageLabel = new UILabel(); - if (messageLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageLabel:: new UILabel fail"); - return nullptr; // 内存分配失败,返回 - } - messageLabel->SetPosition(53, 170, 360, 144); - messageLabel->SetViewId("messageLabel"); - messageLabel->SetText(messageStr.c_str()); - messageLabel->SetTextColor(Color::Gray()); - messageLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - messageLabel->SetLineBreakMode(UILabel::LINE_BREAK_CLIP); // 换行裁剪 - messageLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); // 居中显示 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "messageLabel is ok"); - - /*加载清除按键*/ -#ifdef FD230 - InitButtonExt(deleteButton, 0, 366, 466, 100, DELETEBUTTON, STR_CLOSE, 30); -#else - deleteButton = new UILabelButtonExt(); - if (deleteButton == nullptr) - { - return nullptr; // 内存分配失败,返回 - } - deleteButton->SetPosition(0, 366); - deleteButton->Resize(466, 100); - deleteButton->SetViewId(DELETEBUTTON); - deleteButton->SetText("Close"); - deleteButton->SetStyle(STYLE_TEXT_FONT, 30); - deleteButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - deleteButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - deleteButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED); - deleteButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - deleteButton->SetVisible(true); -#endif - deleteButton->SetImageSrc(buttonImgSrc, buttonImgSrc); - UIView::OnTouchListener *TouchListener = static_cast(&MessageViewEventListener::GetInstance()); - if (TouchListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateMessageView] TouchListener new fail!!"); - return nullptr; - } - deleteButton->SetOnTouchListener(TouchListener); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "deleteButton"); - /* -------------------------------------------------------------------------- */ - MessageGroupView->Add(titleLabel); - MessageGroupView->Add(timeLabel); - MessageGroupView->Add(messageLabel); - MessageGroupView->Add(deleteButton); - - ScreenTurnOn(3000); // 亮屏操作 3000ms 3秒关闭 - - if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get())) - { - // 震动提醒 - ui_api_vibrate_once_func(); - } - - MessageViewEventListener::GetInstance().Message_StartTimer(); // 开启一个3s后弹窗自动销毁定时器 - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Create MessageGroupView succeed!!"); - NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeMessageView); - return MessageGroupView; + if (deleteButton == nullptr) { + return nullptr; // 内存分配失败,返回 } - /*释放消息弹窗视图*/ - void FreeMessageView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FreeMessageView(void)"); - - //销毁定时器 - MessageViewEventListener::GetInstance().Message_StopTimer(); - - if (MessageGroupView != nullptr) - { - MessageGroupView->RemoveAll(); - - delete titleLabel; - titleLabel = nullptr; - - delete timeLabel; - timeLabel = nullptr; - - delete messageLabel; - messageLabel = nullptr; - - delete deleteButton; - deleteButton = nullptr; - - RootView::GetInstance()->Remove(MessageGroupView); - delete MessageGroupView; - MessageGroupView = nullptr; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Free MessageView succeed!!"); - } - ScreenTurnOff(); - return; + deleteButton->SetPosition(0, 366); + deleteButton->Resize(466, 100); + deleteButton->SetViewId(DELETEBUTTON); + deleteButton->SetTextId(STR_CLOSE); + deleteButton->SetStyle(STYLE_TEXT_FONT, 30); + deleteButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + deleteButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + deleteButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, + UIButton::PRESSED); + deleteButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, + UIButton::PRESSED); + deleteButton->SetVisible(true); + deleteButton->SetImageSrc(buttonImgSrc, buttonImgSrc); + UIView::OnTouchListener *TouchListener = + static_cast( + &MessageViewEventListener::GetInstance()); + if (TouchListener == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "[CreateMessageView] TouchListener new fail!!"); + return nullptr; } + deleteButton->SetOnTouchListener(TouchListener); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "deleteButton"); + } + /* -------------------------------------------------------------------------- + */ + MessageGroupView->Add(titleLabel); + MessageGroupView->Add(timeLabel); + MessageGroupView->Add(messageLabel); + MessageGroupView->Add(deleteButton); - /* -------------------------------------------------------------------------- */ + ScreenTurnOn(3000); // 亮屏操作 3000ms 3秒关闭 - // 声明定时器变量 - static osTimerId_t g_timer = NULL; + if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && + (!uapi_sleep_mode_flag_get())) { + // 震动提醒 + ui_api_vibrate_once_func(); + } - /*定时器到期时的处理*/ - static void Message_TimerCallbackProc(int data) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Message_TimerCallbackProc"); - NotificationManager::GetInstance()->StopNotify(); - // 点击关闭之后通知list进行刷新 - SendMsgToUIService(UI_UPDATE_MESSAGE_DATA, 0, nullptr, 0); + MessageViewEventListener::GetInstance() + .Message_StartTimer(); // 开启一个3s后弹窗自动销毁定时器 - } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Create MessageGroupView succeed!!"); + NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeMessageView); + return MessageGroupView; +} +/*释放消息弹窗视图*/ +void FreeMessageView(void) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FreeMessageView(void)"); - /* - * @brief 回调函数 - */ - static void Message_TimerCallback(int data) - { - GraphicService::GetInstance()->PostGraphicEvent(std::bind(Message_TimerCallbackProc, data)); - } + // //销毁定时器 + MessageViewEventListener::GetInstance().Message_StopTimer(); + + if (MessageGroupView != nullptr) { + MessageGroupView->RemoveAll(); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel %p", titleLabel); + delete titleLabel; + titleLabel = nullptr; + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "timeLabel %p", timeLabel); + delete timeLabel; + timeLabel = nullptr; + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageLabel %p", messageLabel); + delete messageLabel; + messageLabel = nullptr; + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "deleteButton %p", deleteButton); + delete deleteButton; + deleteButton = nullptr; + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageGroupView %p", + MessageGroupView); + + delete MessageGroupView; + MessageGroupView = nullptr; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Free MessageView succeed!!"); + } + ScreenTurnOff(); + return; +} + +/* -------------------------------------------------------------------------- */ + +// 声明定时器变量 +static osTimerId_t g_timer = NULL; + +/*定时器到期时的处理*/ +static void Message_TimerCallbackProc(int data) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Message_TimerCallbackProc"); + NotificationManager::GetInstance()->StopNotify(); + // 点击关闭之后通知list进行刷新 + SendMsgToUIService(UI_UPDATE_MESSAGE_DATA, 0, nullptr, 0); +} + +/* + * @brief 回调函数 + */ +static void Message_TimerCallback(int data) { + GraphicService::GetInstance()->PostGraphicEvent( + std::bind(Message_TimerCallbackProc, data)); +} + +/* + * @brief 开启定时器函数 + * @param interval 时间间隔,单位ms + */ +void MessageViewEventListener::Message_StartTimer(uint32_t interval) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "MessageViewEventListener::Message_StartTimer"); + /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 + * ------------------------- */ + if (g_timer != NULL) { + WEARABLE_LOGE( + WEARABLE_LOG_MODULE_APP, + "CountDownModel::CountDown_StartTimer Timer already exists!!"); + return; + } + + /* --------------------------------- 2.创建定时器 + * -------------------------------- */ + g_timer = + osTimerNew((osTimerFunc_t)Message_TimerCallback, osTimerOnce, NULL, NULL); + // 检查定时器创建是否成功 + if (g_timer == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "CountDownModel::CountDown_StartTimer Timer create failed!!"); + return; + } + + /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 + * ---------------------------- */ + int tick = osMs2Tick(interval); - /* - * @brief 开启定时器函数 - * @param interval 时间间隔,单位ms - */ - void MessageViewEventListener::Message_StartTimer(uint32_t interval) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::Message_StartTimer"); - /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ - if (g_timer != NULL) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::CountDown_StartTimer Timer already exists!!"); - return; - } - - /* --------------------------------- 2.创建定时器 -------------------------------- */ - g_timer = osTimerNew((osTimerFunc_t)Message_TimerCallback, osTimerOnce, NULL, NULL); - // 检查定时器创建是否成功 - if (g_timer == NULL) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::CountDown_StartTimer Timer create failed!!"); - return; - } - - /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ - int tick = osMs2Tick(interval); - - /* --------------------------------- 4.启动定时器 -------------------------------- */ - osStatus_t ret = osTimerStart(g_timer, tick); - /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 NULL -------------------- */ - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDown_StartTimer] osTimerDelete failed, ret = %lx!!", ret); - if (g_timer != NULL) - { - ret = osTimerDelete(g_timer); - } - g_timer = NULL; - return; - } - return; + /* --------------------------------- 4.启动定时器 + * -------------------------------- */ + osStatus_t ret = osTimerStart(g_timer, tick); + /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 + * NULL -------------------- */ + if (ret != osOK) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "[CountDown_StartTimer] osTimerDelete failed, ret = %lx!!", + ret); + if (g_timer != NULL) { + ret = osTimerDelete(g_timer); } + g_timer = NULL; + return; + } + return; +} - /* - * @brief 停止定时器 - */ - void MessageViewEventListener::Message_StopTimer(void) - { - // 检查定时器是否存在 - if (g_timer != NULL) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::Message_StopTimer"); - osTimerStop(g_timer); - // 删除定时器并置为 NULL - osStatus_t ret = osTimerDelete(g_timer); - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - } - g_timer = NULL; - } +/* + * @brief 停止定时器 + */ +void MessageViewEventListener::Message_StopTimer(void) { + // 检查定时器是否存在 + if (g_timer != NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "MessageViewEventListener::Message_StopTimer"); + osTimerStop(g_timer); + // 删除定时器并置为 NULL + osStatus_t ret = osTimerDelete(g_timer); + if (ret != osOK) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "osTimerDelete failed, ret = %lx!!", ret); } -} \ No newline at end of file + g_timer = NULL; + } +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c b/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c index f7e755625..eadd410ea 100644 --- a/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c +++ b/code/sdk/drivers/peripheral/utils/custom_fileoperate_service.c @@ -191,6 +191,10 @@ static void custom_fileoperate_service_check_task(void const *arg) battery_save_data(); break; + case CUSTOM_FILEOPERATE_MSG_TYPE_MESSAGE_DATA_NOTIFY: + show_notify_messgae(); + break; + PRINT("Unknown CUSTOM_FILE_OPERATE_MSG cmd 0x%02X \r\n", mail.cmd); break; } diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index c0b4e3dd5..8ef093f0a 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -296,6 +296,8 @@ errcode_t do_custom_cmd_service_check_msg_head(int cmd, void *params, int paraml #define CUSTOM_FILEOPERATE_MSG_TYPE_BATTERY_DATA_READ 0x14 //读取电池数据 #define CUSTOM_FILEOPERATE_MSG_TYPE_BATTERY_DATA_SAVE 0x15 //存储电池数据 +#define CUSTOM_FILEOPERATE_MSG_TYPE_MESSAGE_DATA_NOTIFY 0x16 //消息数据 + errcode_t uapi_custom_fileoperate_service_init(void); errcode_t do_custom_fileoperate_service_check_msg(int cmd, void *params, int paramlen); -- 2.17.1