From: luozheng <1732036298@qq.com> Date: Wed, 25 Jun 2025 03:19:17 +0000 (+0800) Subject: 消息弹窗合并,待验证 X-Git-Tag: leiniao_debug_1.0.0_20250922_020716~257 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=ec9bd9486de7f50b5d5dc32f8204f88f1aa1f612;p=mirrors%2FFD230.git 消息弹窗合并,待验证 --- diff --git a/code/sdk/application/wearable/fd230/service/msg_center/CMakeLists.txt b/code/sdk/application/wearable/fd230/service/msg_center/CMakeLists.txt index f826ec67f..39c03d13f 100644 --- a/code/sdk/application/wearable/fd230/service/msg_center/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230/service/msg_center/CMakeLists.txt @@ -164,6 +164,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/debug_output_notification/debug_output_notification_adapter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/debug_output_notification/debug_output_notification_itemview.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/debug_output_notification/debug_output_notification.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/message_notification.cpp ) else() set(SOURCES @@ -182,6 +183,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/debug_output_notification/debug_output_notification_adapter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/debug_output_notification/debug_output_notification_itemview.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/debug_output_notification/debug_output_notification.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/message_notification.cpp ) endif() diff --git a/code/sdk/application/wearable/fd230/service/msg_center/include/notify/message_notification.h b/code/sdk/application/wearable/fd230/service/msg_center/include/notify/message_notification.h new file mode 100644 index 000000000..944e6c281 --- /dev/null +++ b/code/sdk/application/wearable/fd230/service/msg_center/include/notify/message_notification.h @@ -0,0 +1,30 @@ +#ifndef MESSAGE_NOTIFICATION +#define MESSAGE_NOTIFICATION + +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; + + void Message_StartTimer(uint32_t interval = 1000 * 3); + void Message_StopTimer(void); + 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/fd230/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/fd230/service/msg_center/src/msg_center_customer.cpp index f7d30a95d..d4942b59f 100644 --- a/code/sdk/application/wearable/fd230/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/fd230/service/msg_center/src/msg_center_customer.cpp @@ -54,6 +54,7 @@ #include "saveele/include/SaveEleModel.h" #include "testchangingC.h" #include "custom_runtime.h" +#include "message_notification.h" #ifdef SUPPORT_POWER_MANAGER #include "power_display_service.h" @@ -215,6 +216,10 @@ static OHOS::UIViewGroup* showDebugOutputNotify(void) { return OHOS::CreateDebugOutputMainView(); } +/*显示消息提醒*/ +static OHOS::UIViewGroup *showMessageNotify(void) { + return OHOS::CreateMessageView(); +} void MsgCenterNotifyAlarmProc(const Topic topic, Request* req) { diff --git a/code/sdk/application/wearable/fd230/service/msg_center/src/notify/message_notification.cpp b/code/sdk/application/wearable/fd230/service/msg_center/src/notify/message_notification.cpp new file mode 100644 index 000000000..21701129f --- /dev/null +++ b/code/sdk/application/wearable/fd230/service/msg_center/src/notify/message_notification.cpp @@ -0,0 +1,430 @@ +#include "components/ui_button.h" +#include "components/ui_label_ext.h" +#include "notification_manager.h" +#include "uiservice/include/ui_service.h" +#include "uicomponents/UIComponents.h" +#include "wearable_log.h" +#ifdef FD230 +#include "message/include/MessageModel.h" +#endif +#include "custom_runtime.h" +#include "ConfigModel.h" +#include "iostream" +#include "string" +#include "vibrator/service/vibrator_service.h" +#include +#include +#include +#include +#include +#include +#include "message_notification.h" +#include "ui_resource_string.h" + +#ifdef SUPPORT_BLE_SERVICE +#include "bleEvent.h" +#endif + +namespace OHOS +{ + + UIViewGroup *MessageGroupView{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"; + +#define DELETEBUTTON "delete_button" + + MessageViewEventListener::MessageViewEventListener() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "MessageViewEventListener::MessageViewEventListener"); + } + + MessageViewEventListener::~MessageViewEventListener() + { + WEARABLE_LOGD(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); +#ifdef FD230 + MessageModel::GetInstance().UpdateMessageView(); +#endif + } + + return true; + } + 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); +#ifdef FD230 + MessageModel::GetInstance().UpdateMessageView(); +#endif + 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_LOGD(WEARABLE_LOG_MODULE_APP, "CreateMessageView"); + if (MessageGroupView == nullptr) + { + MessageGroupView = new UIViewGroup(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "[CreateMessageView] MessageGroupView new %p", + MessageGroupView); + if (MessageGroupView == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "[CreateMessageView] MessageGroupView new fail!!"); + return nullptr; + } + 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_LOGD(WEARABLE_LOG_MODULE_APP, + "[CreateMessageView] dragListener new fail!!"); + return nullptr; + } + + MessageGroupView->SetOnDragListener(dragListener); + } +/*获取最新message*/ +#ifdef FD230 + MessageData *data = MessageModel::GetInstance().GetNewMessage(); + if (data != nullptr) + { + titleStr = data->labelTitle; + timeStr = data->labelTime; + messageStr = data->labelDetails; + } + else + { + titleStr = "--"; + timeStr = "--"; + messageStr = "--"; + } +#else + titleStr = "--"; + timeStr = "--"; + messageStr = "--"; +#endif + /*初始化label*/ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "InitView"); + /* --------------------------------------------------------------------------*/ + if (titleLabel == nullptr) + { + titleLabel = new UILabel(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "titleLabel:: new UILabel %p", + titleLabel); + if (titleLabel == nullptr) + { + WEARABLE_LOGD(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(23); + 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!"); + } + /* -------------------------------------------------------------------------- + */ + if (timeLabel == nullptr) + { + timeLabel = new UILabel(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "timeLabel:: new UILabel %p", + timeLabel); + if (timeLabel == nullptr) + { + WEARABLE_LOGD(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!"); + } + /* -------------------------------------------------------------------------- + */ + /*初始化消息内容*/ + if (messageLabel == nullptr) + { + messageLabel = new UILabel(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "messageLabel:: new UILabel %p", + messageLabel); + if (messageLabel == nullptr) + { + WEARABLE_LOGD(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"); + } + /*加载清除按键*/ + if (deleteButton == nullptr) + { + deleteButton = new UILabelButtonExt(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "deleteButton:: new UILabelButtonExt %p", deleteButton); + + if (deleteButton == nullptr) + { + return nullptr; // 内存分配失败,返回 + } + 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_LOGD(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; + } + /*释放消息弹窗视图*/ + void FreeMessageView(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FreeMessageView(void)"); + + // //销毁定时器 + MessageViewEventListener::GetInstance().Message_StopTimer(); + + if (MessageGroupView != nullptr) + { + MessageGroupView->RemoveAll(); + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "titleLabel %p", titleLabel); + delete titleLabel; + titleLabel = nullptr; + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "timeLabel %p", timeLabel); + delete timeLabel; + timeLabel = nullptr; + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "messageLabel %p", messageLabel); + delete messageLabel; + messageLabel = nullptr; + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "deleteButton %p", deleteButton); + delete deleteButton; + deleteButton = nullptr; + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MessageGroupView %p", + MessageGroupView); + + RootView::GetInstance()->Remove(MessageGroupView); + + delete MessageGroupView; + MessageGroupView = nullptr; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Free MessageView succeed!!"); + } + // 恢复亮屏 + ScreenTurnOff(); + return; + } + + /* -------------------------------------------------------------------------- */ + + // 声明定时器变量 + static osTimerId_t g_timer = NULL; + + /*定时器到期时的处理*/ + static void Message_TimerCallbackProc(int data) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Message_TimerCallbackProc"); + NotificationManager::GetInstance()->StopNotify(); +// 点击关闭之后通知list进行刷新 +// SendMsgToUIService(UI_UPDATE_MESSAGE_DATA, 0, nullptr, 0); +#ifdef FD230 + MessageModel::GetInstance().UpdateMessageView(); +#endif + } + + /* + * @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_LOGD(WEARABLE_LOG_MODULE_APP, + "MessageViewEventListener::Message_StartTimer"); + /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 + * ------------------------- */ + if (g_timer != NULL) + { + WEARABLE_LOGD( + 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_LOGD(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_LOGD(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_LOGD(WEARABLE_LOG_MODULE_APP, + "MessageViewEventListener::Message_StopTimer"); + osTimerStop(g_timer); + // 删除定时器并置为 NULL + osStatus_t ret = osTimerDelete(g_timer); + if (ret != osOK) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "osTimerDelete failed, ret = %lx!!", ret); + } + g_timer = NULL; + } + } +} // namespace OHOS \ No newline at end of file