From c36197c645688106cf05cac56f0f82e684d2ce81 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Fri, 21 Jun 2024 10:18:03 +0800 Subject: [PATCH] =?utf8?q?=E5=90=8C=E6=AD=A5=E6=B6=88=E6=81=AF=E5=BC=B9?= =?utf8?q?=E7=AA=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/message/include/MessageModel.h | 7 + .../nativeui/message/src/MessageModel.cpp | 8 + .../broadcast/include/broadcast_feature.h | 1 + .../broadcast/src/broadcast_implement.c | 1 + .../service/msg_center/CMakeLists.txt | 2 + .../include/notify/message_notification.h | 35 ++++ .../msg_center/src/msg_center_customer.cpp | 20 +- .../src/notify/message_notification.cpp | 198 ++++++++++++++++++ 8 files changed, 271 insertions(+), 1 deletion(-) create mode 100644 code/sdk/application/wearable/service/msg_center/include/notify/message_notification.h create mode 100644 code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp diff --git a/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageModel.h b/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageModel.h index c04313803..3d8415698 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageModel.h @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-04-15 10:55:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-20 10:02:36 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/message/include/MessageModel.h + */ #ifndef MESSAGE_MODEL_H #define MESSAGE_MODEL_H @@ -41,6 +47,7 @@ namespace OHOS void SetCurrentMessageData(MessageData *data); // 设置当前消息数据 bool ClearAllData(); // 清除所有数据 bool DeleteSingleItem(); // 删除单个项 + MessageData *GetNewestData(); // 获取最新信息项 private: MessageModel(); 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 87b8699be..0ec8dcb67 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/message/src/MessageModel.cpp @@ -196,5 +196,13 @@ namespace OHOS { return true; } + // 获取最新消息项 + MessageData *MessageModel::GetNewestData() + { + std::vector messageVector = LoadMessageData(); + numberOfItems = messageVector.size(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the numberOfItems is %d", numberOfItems); + return &messageVector[numberOfItems - 1]; + } } diff --git a/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h b/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h index 1c94cd48d..7f0757d1c 100644 --- a/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h +++ b/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h @@ -87,6 +87,7 @@ typedef enum { TOPIC_EVENT_FIND_WATCH, //查找手表 TOPIC_EVENT_CANCEL_FIND_WATCH,//取消查找 TOPIC_EVENT_DRINKREMINDER,//喝水提醒 + TOPIC_EVENT_MESSAGENOTE, //消息通知 TOPIC_END_NUM = 20000, } TopicNum; diff --git a/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c b/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c index a9e59252a..c8194eb57 100644 --- a/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c +++ b/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c @@ -65,6 +65,7 @@ static const TopicToCore topicToCoreArray[] = { {TOPIC_EVENT_FIND_WATCH,A_CORE_MASK, 1},//查找手表 {TOPIC_EVENT_CANCEL_FIND_WATCH,A_CORE_MASK, 1}, {TOPIC_EVENT_DRINKREMINDER,A_CORE_MASK, 1}, + {TOPIC_EVENT_MESSAGENOTE,A_CORE_MASK, 1}, #ifdef SUPPORT_CAT1_MODEM {TOPIC_EVENT_CAT1_INCOMMING, A_CORE_MASK, 1}, {TOPIC_EVENT_CAT1_CALLCONNTED, A_CORE_MASK, 1}, diff --git a/code/sdk/application/wearable/service/msg_center/CMakeLists.txt b/code/sdk/application/wearable/service/msg_center/CMakeLists.txt index a58b970bd..0fe23e29a 100644 --- a/code/sdk/application/wearable/service/msg_center/CMakeLists.txt +++ b/code/sdk/application/wearable/service/msg_center/CMakeLists.txt @@ -166,6 +166,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/drinkReminder_notification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/sedentaryReminder_notification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/transmitting.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/message_notification.cpp ) else() set(SOURCES @@ -180,6 +181,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/drinkReminder_notification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/sedentaryReminder_notification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/transmitting.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/message_notification.cpp ) endif() diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/message_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/message_notification.h new file mode 100644 index 000000000..977cc2cd5 --- /dev/null +++ b/code/sdk/application/wearable/service/msg_center/include/notify/message_notification.h @@ -0,0 +1,35 @@ +/*** + * @Date: 2024-06-20 09:43:23 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-20 09:47:45 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/service/msg_center/include/notify/message_notification.h + */ +#ifndef MESSAGE_NOTIFICATION +#define MESSAGE_NOTIFICATION + +#include "BaseView.h" +namespace OHOS +{ + UIViewGroup *CreateMessageView(void); + void FreeMessageView(void); + + class MessageViewEventListener : public UIView::OnTouchListener,public UIView::OnDragListener + { + public: + static MessageViewEventListener &GetInstance(); + bool OnRelease(UIView &view, const ReleaseEvent &event) override; + bool OnDrag(UIView& view, const DragEvent& event) override; + bool OnDragEnd(UIView& view, const DragEvent& event) override; + + private: + MessageViewEventListener(); + ~MessageViewEventListener(); + MessageViewEventListener(const MessageViewEventListener &) = delete; + const MessageViewEventListener &operator=(const MessageViewEventListener &) = delete; + bool X_DRAG_FLAG{false}; + + }; + +} + +#endif \ No newline at end of file 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 5a65e5f71..10d7600ac 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 @@ -29,6 +29,7 @@ #include "power_display_service.h" #include "cat1_server.h" #include "testchanging.h" +#include "message_notification.h" #include "testcat1.h" #include "testold.h" #include "testhrsenson.h" @@ -77,7 +78,6 @@ const PriorityMapper PRI_MAPPER[] = { {TOPIC_EVENT_HFP_WATCH_ACTIVE, PRIORITY_ONE}, {TOPIC_EVENT_HFP_WATCH_TO_PHONE, PRIORITY_ONE}, {TOPIC_EVENT_HFP_PHONE_TO_WATCH, PRIORITY_ONE}, - #ifdef SUPPORT_CAT1_MODEM {TOPIC_EVENT_CAT1_INCOMMING, PRIORITY_ONE}, {TOPIC_EVENT_CAT1_CALLCONNTED, PRIORITY_ONE}, @@ -105,6 +105,7 @@ const PriorityMapper PRI_MAPPER[] = { {TOPIC_EVENT_FIND_WATCH,PRIORITY_TWO}, {TOPIC_EVENT_CANCEL_FIND_WATCH,PRIORITY_TWO}, {TOPIC_EVENT_DRINKREMINDER,PRIORITY_TWO}, + {TOPIC_EVENT_MESSAGENOTE,PRIORITY_TWO}, }; static bool CheckPriority(const Topic topic) @@ -177,6 +178,7 @@ void MsgCenterSubscribe() MsgCenterSubscribeTopic(TOPIC_EVENT_FIND_WATCH); MsgCenterSubscribeTopic(TOPIC_EVENT_CANCEL_FIND_WATCH); MsgCenterSubscribeTopic(TOPIC_EVENT_DRINKREMINDER); + MsgCenterSubscribeTopic(TOPIC_EVENT_MESSAGENOTE); } static OHOS::UIViewGroup* ShowAlarmNotify(void) @@ -252,6 +254,12 @@ static OHOS::UIViewGroup* showtransmitNotify(void) return OHOS::transmittingShow(); } +/*显示消息提醒*/ +static OHOS::UIViewGroup* showMessageNotify(void) +{ + return OHOS::CreateMessageView(); +} + void MsgCenterNotifyAlarmProc(const Topic topic, Request* req) { unused(req); @@ -908,6 +916,15 @@ void MsgCenterNotifyDrinkReminderProc(const Topic topic, Request* req) NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); NotificationManager::GetInstance()->ShowNotify(showDrinkReminderNotify, (uint16_t)topic, true); } +//消息通知 +void MsgCenterNotifyMessageProc(const Topic topic, Request* req) +{ + unused(topic); + unused(req); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyMessageProc !"); + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); + NotificationManager::GetInstance()->ShowNotify(showMessageNotify, (uint16_t)topic, true); +} void MsgCenterNotifyActivityProc(const Topic topic, Request* req) { unused(topic); @@ -1092,6 +1109,7 @@ static MsgCenterNotifyTable g_msgCenterNotifyTable[] = { {TOPIC_EVENT_FIND_WATCH,MsgCenterNotifyFindWatchProc}, {TOPIC_EVENT_CANCEL_FIND_WATCH,MsgCenterNotifyCanCelFindWatchProc}, {TOPIC_EVENT_DRINKREMINDER,MsgCenterNotifyDrinkReminderProc}, + {TOPIC_EVENT_MESSAGENOTE,MsgCenterNotifyMessageProc}, }; static MsgCenterNotifyTable *MsgCenterGetNotifyTblCb(uint8_t idx) 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 new file mode 100644 index 000000000..b2ff7d1e5 --- /dev/null +++ b/code/sdk/application/wearable/service/msg_center/src/notify/message_notification.cpp @@ -0,0 +1,198 @@ +#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_label_ext.h" +#include "uicomponents/UIComponents.h" +#include "message/include/MessageModel.h" +#include "message_notification.h" +#include "string" +namespace OHOS +{ + + UIViewGroup *MessageGroupView{nullptr}; + + UILabel *titleLabel{nullptr}; // 标题 + UILabel *timeLabel{nullptr}; // 时间 + UILabel *messageLabel{nullptr}; // 详细label + UILabelButtonExt *deleteButton{nullptr}; // 删除按键 + + static std::string titleStr, timeStr, messageStr; + +#define DELETEBUTTON "delete_button" + + MessageViewEventListener::MessageViewEventListener() + { + WEARABLE_LOGE(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_LOGE(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::OnRelease"); + UNUSED(event); + if (strcmp(view.GetViewId(), DELETEBUTTON) == 0) + { + NotificationManager::GetInstance()->StopNotify(); + } + + return true; + } + bool MessageViewEventListener::OnDrag(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageViewEventListener::OnDrag"); + UNUSED(view); + return true; + } + + 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; + } + + /*创建信息弹窗*/ + UIViewGroup *CreateMessageView(void) + { + WEARABLE_LOGE(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); + /*获取最新message*/ + MessageData *data = MessageModel::GetInstance().GetNewestData(); + if (data != nullptr) + { + titleStr = data->labelTitle; + timeStr = data->labelTime; + messageStr = data->labelDetails; + } + /*初始化label*/ + WEARABLE_LOGE(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->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!"); + /* -------------------------------------------------------------------------- */ + 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_LOGE(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); + timeLabel->SetLineBreakMode(UILabel::LINE_BREAK_CLIP); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "messageLabel is ok"); + + /*加载清除按键*/ + InitButtonExt(deleteButton, 0, 366, 466, 100, DELETEBUTTON, STR_CLOSE, 30); + const char *buttonImgSrc = "/user/res/466x100button.bin"; + 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); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Create MessageGroupView succeed!!"); + + return MessageGroupView; + } + /*释放消息弹窗视图*/ + void FreeMessageView(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FreeMessageView(void)"); + 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_LOGE(WEARABLE_LOG_MODULE_APP, "Free MessageView succeed!!"); + } + return; + } +} \ No newline at end of file -- 2.17.1