From 6d98c4af13c2e2c14fdbbcb21049f91cf1795c56 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Wed, 25 Jun 2025 15:28:34 +0800 Subject: [PATCH] =?utf8?q?=E5=96=9D=E6=B0=B4=E6=8F=90=E9=86=92=E5=BC=B9?= =?utf8?q?=E7=AA=97=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../broadcast/src/broadcast_implement.c | 1 + .../fd230/service/msg_center/CMakeLists.txt | 3 + .../notify/drinkReminder_notification.h | 31 ++ .../msg_center/src/msg_center_customer.cpp | 25 ++ .../src/notify/drinkReminder_notification.cpp | 305 ++++++++++++++++++ .../src/notify/goal_notification.cpp | 2 +- 6 files changed, 366 insertions(+), 1 deletion(-) create mode 100644 code/sdk/application/wearable/fd230/service/msg_center/include/notify/drinkReminder_notification.h create mode 100644 code/sdk/application/wearable/fd230/service/msg_center/src/notify/drinkReminder_notification.cpp diff --git a/code/sdk/application/wearable/fd230/service/broadcast/src/broadcast_implement.c b/code/sdk/application/wearable/fd230/service/broadcast/src/broadcast_implement.c index 6188dcf3c..9cda922ef 100644 --- a/code/sdk/application/wearable/fd230/service/broadcast/src/broadcast_implement.c +++ b/code/sdk/application/wearable/fd230/service/broadcast/src/broadcast_implement.c @@ -42,6 +42,7 @@ static const TopicToCore topicToCoreArray[] = { {TOPIC_EVENT_FIND_WATCH, A_CORE_MASK, 1}, {TOPIC_EVENT_DEBUGOUTPUT, A_CORE_MASK, 1}, {TOPIC_EVENT_GOAL_SHOW_VIEW, A_CORE_MASK, 1}, + {TOPIC_EVENT_DRINKREMINDER, A_CORE_MASK, 1}, }; /* 所有的topic,其对应的位图 */ 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 cb8a7ccdb..66b85e274 100644 --- a/code/sdk/application/wearable/fd230/service/msg_center/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230/service/msg_center/CMakeLists.txt @@ -166,6 +166,8 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/debug_output_notification/debug_output_notification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/message_notification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/goal_notification.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/drinkReminder_notification.cpp + ) else() set(SOURCES @@ -186,6 +188,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/debug_output_notification/debug_output_notification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/message_notification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/goal_notification.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/drinkReminder_notification.cpp ) endif() diff --git a/code/sdk/application/wearable/fd230/service/msg_center/include/notify/drinkReminder_notification.h b/code/sdk/application/wearable/fd230/service/msg_center/include/notify/drinkReminder_notification.h new file mode 100644 index 000000000..d58f46bd8 --- /dev/null +++ b/code/sdk/application/wearable/fd230/service/msg_center/include/notify/drinkReminder_notification.h @@ -0,0 +1,31 @@ +#ifndef DRINKREMINDER_NOTIFICATION +#define DRINKREMINDER_NOTIFICATION + +namespace OHOS +{ + UIViewGroup *CreateDrinkReminderView(void); + void FreeDrinkReminderView(void); + + class DrinkReminderViewEventListener : public UIView::OnTouchListener, public UIView::OnDragListener + { + public: + static DrinkReminderViewEventListener &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 set_screen_on_and_vibration(void); + + void record_drink_reminder_log(void); + + private: + DrinkReminderViewEventListener(); + ~DrinkReminderViewEventListener(); + DrinkReminderViewEventListener(const DrinkReminderViewEventListener &) = delete; + const DrinkReminderViewEventListener &operator=(const DrinkReminderViewEventListener &) = 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 261eaab19..fb0d3094b 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 @@ -56,6 +56,7 @@ #include "custom_runtime.h" #include "message_notification.h" #include "goal_notification.h" +#include "drinkReminder_notification.h" #ifdef SUPPORT_POWER_MANAGER #include "power_display_service.h" @@ -92,6 +93,8 @@ const PriorityMapper PRI_MAPPER[] = { {TOPIC_EVENT_FIND_WATCH,PRIORITY_TWO}, // 查找找手表 {TOPIC_EVENT_DEBUGOUTPUT,PRIORITY_ONE}, //开发调试专用窗口 {TOPIC_EVENT_GOAL_SHOW_VIEW,PRIORITY_TWO}, // 训练目标弹窗 + {TOPIC_EVENT_DRINKREMINDER,PRIORITY_TWO}, // 训练目标弹窗 + }; @@ -140,6 +143,7 @@ void MsgCenterSubscribe() MsgCenterSubscribeTopic(TOPIC_EVENT_FIND_WATCH); MsgCenterSubscribeTopic(TOPIC_EVENT_DEBUGOUTPUT); MsgCenterSubscribeTopic(TOPIC_EVENT_GOAL_SHOW_VIEW); + MsgCenterSubscribeTopic(TOPIC_EVENT_DRINKREMINDER); } @@ -227,6 +231,11 @@ static OHOS::UIViewGroup* ShowGoalNotify(void) { return OHOS::GoalviewShow(); } +/*显示喝水提醒视图*/ +static OHOS::UIViewGroup* showDrinkReminderNotify(void) +{ + return OHOS::CreateDrinkReminderView(); +} void MsgCenterNotifyAlarmProc(const Topic topic, Request* req) { @@ -684,6 +693,21 @@ void MsgCenterNotifyGoalShowViewProc(const Topic topic, Request* req) } } } +//喝水提醒通知 +void MsgCenterNotifyDrinkReminderProc(const Topic topic, Request *req) +{ + // unused(topic); + unused(req); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyDrinkReminderProc !"); + // DrinkReminderViewEventListener::GetInstance().set_screen_on_and_vibration(); + DrinkReminderViewEventListener::GetInstance().record_drink_reminder_log(); + if (CheckPriority(topic)) + { + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); + NotificationManager::GetInstance()->ShowNotify(showDrinkReminderNotify, (uint16_t)topic, true); + } +} + #endif /* 订阅事件通知逻辑可定制 */ @@ -710,6 +734,7 @@ static MsgCenterNotifyTable g_msgCenterNotifyTable[] = { {TOPIC_EVENT_FIND_WATCH,MsgCenterNotifyFindWatchProc}, {TOPIC_EVENT_DEBUGOUTPUT,MsgCenterNotifyDebugOutProc}, {TOPIC_EVENT_GOAL_SHOW_VIEW,MsgCenterNotifyGoalShowViewProc}, + {TOPIC_EVENT_DRINKREMINDER,MsgCenterNotifyDrinkReminderProc}, // {TOPIC_EVENT_DEVICE_UNBIND, MsgCenterNotifyDeviceUnBindProc}, // {TOPIC_EVENT_DEVICE_UNBINDING_REQUEST, MsgCenterNotifyDeviceUnBindingRequestProc}, diff --git a/code/sdk/application/wearable/fd230/service/msg_center/src/notify/drinkReminder_notification.cpp b/code/sdk/application/wearable/fd230/service/msg_center/src/notify/drinkReminder_notification.cpp new file mode 100644 index 000000000..9ba0d30fb --- /dev/null +++ b/code/sdk/application/wearable/fd230/service/msg_center/src/notify/drinkReminder_notification.cpp @@ -0,0 +1,305 @@ +#include "notification_manager.h" +#include "wearable_log.h" +#include "components/ui_button.h" +#include "components/ui_image_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_scroll_view.h" +#ifdef FD230 +#include "ui_resource_string.h" +#endif +#include +#include +#include +#include +#include "ConfigModel.h" +#include +#include +#include +#include "custom_runtime.h" +#include "uiservice/include/ui_service.h" +#include "vibrator/service/vibrator_service.h" +#include "system/include/SystemLogModel.h" +#include "drinkReminder_notification.h" + +namespace OHOS +{ + + UIViewGroup *DrinkReminderGroupView{nullptr}; + UIScrollView *DrinkReminderScrollView{nullptr}; + UILabelExt *DrinkReminderTitleLabel{nullptr}; // 标题: 喝水提醒 + UIImageView *DrinkReminderImage{nullptr}; + UILabelExt *DrinkReminderNoteLabel{nullptr}; // 喝水提醒note + UILabelExt *DrinkReminderLabel{nullptr}; + UIButton *DrinkReminderButton{nullptr}; + + static constexpr const int X_DRAG_OFFSET = 20; + static constexpr const int DOUBLES = 2; + + static constexpr const char *DRINKREMINDERGROUPVIEWID = "DrinkReminderGroupview"; + static constexpr const char *DRINKREMINDERBUTTONVIEWID = "DrinkReminderButton"; + + DrinkReminderViewEventListener::DrinkReminderViewEventListener() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DrinkReminderViewEventListener::DrinkReminderViewEventListener"); + } + + DrinkReminderViewEventListener::~DrinkReminderViewEventListener() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DrinkReminderViewEventListener::~DrinkReminderViewEventListener"); + } + + DrinkReminderViewEventListener &DrinkReminderViewEventListener::GetInstance() + { + static DrinkReminderViewEventListener instance; + return instance; + } + + bool DrinkReminderViewEventListener::OnRelease(UIView &view, const ReleaseEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DrinkReminderViewEventListener::OnRelease"); + UNUSED(event); + std::string viewId = view.GetViewId(); + if (viewId == DRINKREMINDERBUTTONVIEWID) + { + NotificationManager::GetInstance()->StopNotify(); + } + + return true; + } + + bool DrinkReminderViewEventListener::OnDrag(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DrinkReminderViewEventListener::OnDrag"); + UNUSED(view); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + DrinkReminderViewEventListener::X_DRAG_FLAG = true; + } + return true; + } + + bool DrinkReminderViewEventListener::OnDragEnd(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DrinkReminderViewEventListener::OnDragEnd"); + std::string viewId = view.GetViewId(); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && DrinkReminderViewEventListener::X_DRAG_FLAG) + { + if (viewId == DRINKREMINDERGROUPVIEWID) + { + NotificationManager::GetInstance()->StopNotify(); + } + DrinkReminderViewEventListener::X_DRAG_FLAG = false; + } + return true; + } + + void DrinkReminderViewEventListener::set_screen_on_and_vibration(void) + { + /*亮屏加震动*/ + uapi_set_screen_on_api(); + if (true != ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get())) + { + // uapi_vibrationModeSet(ConfigModel::GetInstance()->GetVibrationReminder()); + ui_api_vibrate_once_func(); + } + } + + // 记录喝水提醒日志 + void DrinkReminderViewEventListener::record_drink_reminder_log(void) + { + // popup_windows_log_data systemlog; + // systemlog.type = popup_windows_type::DRINK_WATER_REMINDER; + // systemlog.timestamp = SystemLogModel::GetInstance()->GetCurrentTime(); + // SystemLogModel::GetInstance()->save_popup_windows_log(systemlog); + uint8_t type = 1; + do_custom_fileoperate_service_check_msg(CUSTOM_FILEOPERATE_MSG_TYPE_POPUP_WINDOWS_DATA_LIST, &type, sizeof(type)); + } + + /*创建喝水提醒视图*/ + UIViewGroup *CreateDrinkReminderView(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CreateDrinkReminderView(void)"); + if (DrinkReminderGroupView == nullptr) + { + DrinkReminderGroupView = new UIViewGroup(); + if (DrinkReminderGroupView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDrinkReminderView] DrinkReminderGroupView new fail!!"); + return nullptr; + } + DrinkReminderGroupView->SetPosition(0, 0, 466, 466); + DrinkReminderGroupView->SetViewId(DRINKREMINDERGROUPVIEWID); + DrinkReminderGroupView->SetTouchable(true); + DrinkReminderGroupView->SetDraggable(true); + UIView::OnDragListener *dragListener = static_cast(&DrinkReminderViewEventListener::GetInstance()); + if (dragListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDrinkReminderView] dragListener new fail!!"); + return nullptr; + } + DrinkReminderGroupView->SetOnDragListener(dragListener); + /* -------------------------------------------------------------------------- */ + if (DrinkReminderScrollView == nullptr) + { + DrinkReminderScrollView = new UIScrollView(); + if (DrinkReminderScrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DrinkReminderScrollView new fail"); + return nullptr; + } + } + DrinkReminderScrollView->SetPosition(0, 0, 466, 466); + DrinkReminderScrollView->SetThrowDrag(true); + DrinkReminderScrollView->SetDraggable(true); + DrinkReminderScrollView->SetTouchable(true); + DrinkReminderScrollView->SetReboundSize(30); + DrinkReminderScrollView->SetScrollBlankSize(30); + DrinkReminderScrollView->SetSwipeACCLevel(200); // 800: compensation distance + DrinkReminderScrollView->SetDragACCLevel(5); // 5: drag acceleration + DrinkReminderScrollView->SetMaxScrollDistance(1000); + DrinkReminderScrollView->SetDirection(UIScrollView::VERTICAL); + DrinkReminderScrollView->RequestFocus(); + DrinkReminderScrollView->SetRotateFactor(1.0); + /* ------------------------- DrinkReminderTitleLabel ------------------------ */ + DrinkReminderTitleLabel = new UILabelExt(); + if (DrinkReminderTitleLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDrinkReminderView] DrinkReminderTitleLabel new fail!!"); + return nullptr; + } + DrinkReminderTitleLabel->SetPosition(83, 52, 300, 35); + DrinkReminderTitleLabel->SetStyle(STYLE_TEXT_FONT, 30); + DrinkReminderTitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35); +#ifdef FD230 + DrinkReminderTitleLabel->SetTextId(STR_DRINK_WATER_REMINDER); +#else + DrinkReminderTitleLabel->SetText("喝水提醒"); +#endif + DrinkReminderTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + DrinkReminderTitleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + DrinkReminderTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* --------------------------- DrinkReminderImage --------------------------- */ + DrinkReminderImage = new UIImageView(); + if (DrinkReminderImage == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDrinkReminderView] DrinkReminderImage new fail!!"); + return nullptr; + } + DrinkReminderImage->SetPosition(193, 130, 80, 80); + DrinkReminderImage->SetSrc("/user/res/drinkReminder/DrinkReminder.bin"); + /* ------------------------- DrinkReminderNoteLabel ------------------------- */ + DrinkReminderNoteLabel = new UILabelExt(); + if (DrinkReminderNoteLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDrinkReminderView] DrinkReminderNoteLabel new fail!!"); + return nullptr; + } + DrinkReminderNoteLabel->SetPosition(53, 248, 360, 70); + DrinkReminderNoteLabel->SetStyle(STYLE_TEXT_FONT, 30); + DrinkReminderNoteLabel->SetStyle(STYLE_LINE_HEIGHT, 35); +#ifdef FD230 + DrinkReminderNoteLabel->SetTextId(STR_DRINK_WATER_REMINDER_NOTE); +#endif + DrinkReminderNoteLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + DrinkReminderNoteLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + DrinkReminderNoteLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* --------------------------- DrinkReminderButton -------------------------- */ + DrinkReminderButton = new UIButton(); + if (DrinkReminderButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDrinkReminderView] DrinkReminderButton new fail!!"); + return nullptr; + } + DrinkReminderButton->SetPosition(0, 366, 466, 100); + DrinkReminderButton->SetViewId(DRINKREMINDERBUTTONVIEWID); + const char *buttonImgSrc = "/user/res/466x100button.bin"; + DrinkReminderButton->SetImageSrc(buttonImgSrc, buttonImgSrc); + DrinkReminderButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff0b1928, UIButton::PRESSED); + UIView::OnTouchListener *TouchListener = static_cast(&DrinkReminderViewEventListener::GetInstance()); + if (TouchListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDrinkReminderView] TouchListener new fail!!"); + return nullptr; + } + DrinkReminderButton->SetOnTouchListener(TouchListener); + /* --------------------------- DrinkReminderLabel --------------------------- */ + DrinkReminderLabel = new UILabelExt(); + if (DrinkReminderLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDrinkReminderView] DrinkReminderLabel new fail!!"); + return nullptr; + } + DrinkReminderLabel->SetPosition(133, 399, 200, 35); + DrinkReminderLabel->SetStyle(STYLE_TEXT_FONT, 30); + DrinkReminderLabel->SetStyle(STYLE_LINE_HEIGHT, 35); +#ifdef FD230 + DrinkReminderLabel->SetTextId(STR_KONW); +#else + DrinkReminderLabel->SetText("知道了"); +#endif + DrinkReminderLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + DrinkReminderLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + DrinkReminderLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* ----------------------------------- Add ---------------------------------- */ + DrinkReminderScrollView->Add(DrinkReminderTitleLabel); + DrinkReminderScrollView->Add(DrinkReminderImage); + DrinkReminderScrollView->Add(DrinkReminderNoteLabel); + DrinkReminderScrollView->Add(DrinkReminderButton); + DrinkReminderScrollView->Add(DrinkReminderLabel); + DrinkReminderGroupView->Add(DrinkReminderScrollView); + + /* -------------------------------------------------------------------------- */ + if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get())) + { + ui_api_vibrate_once_func(); // 震动一次 + } + + ScreenTurnOn(10 * 1000); // 亮屏操作 10秒关闭 + /* -------------------------------------------------------------------------- */ + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Create DrinkReminderView succeed!!"); + } + + NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeDrinkReminderView); + return DrinkReminderGroupView; + } + + /*释放喝水提醒视图*/ + void FreeDrinkReminderView(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FreeDrinkReminderView(void)"); + if (DrinkReminderGroupView != nullptr) + { + DrinkReminderGroupView->RemoveAll(); + + if (DrinkReminderScrollView != nullptr) + { + DrinkReminderScrollView->RemoveAll(); + delete DrinkReminderTitleLabel; + DrinkReminderTitleLabel = nullptr; + + delete DrinkReminderImage; + DrinkReminderImage = nullptr; + + delete DrinkReminderNoteLabel; + DrinkReminderNoteLabel = nullptr; + + delete DrinkReminderButton; + DrinkReminderButton = nullptr; + + delete DrinkReminderLabel; + DrinkReminderLabel = nullptr; + + DrinkReminderScrollView->ClearFocus(); + delete DrinkReminderScrollView; + DrinkReminderScrollView = nullptr; + } + RootView::GetInstance()->Remove(DrinkReminderGroupView); + delete DrinkReminderGroupView; + DrinkReminderGroupView = nullptr; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Free DrinkReminderView succeed!!"); + ScreenTurnOff(); + } + return; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/service/msg_center/src/notify/goal_notification.cpp b/code/sdk/application/wearable/fd230/service/msg_center/src/notify/goal_notification.cpp index ae03651b9..f56113b04 100644 --- a/code/sdk/application/wearable/fd230/service/msg_center/src/notify/goal_notification.cpp +++ b/code/sdk/application/wearable/fd230/service/msg_center/src/notify/goal_notification.cpp @@ -25,7 +25,7 @@ #include "custom_runtime.h" #include "vibrator/service/vibrator_service.h" #ifdef SUPPORT_BLE_SERVICE -/#include "bleEvent.h" +#include "bleEvent.h" #endif namespace OHOS { -- 2.17.1