From f71b70b971c49138fc433b7b85371b1f72ebc087 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Tue, 4 Jun 2024 10:11:47 +0800 Subject: [PATCH] =?utf8?q?=E4=B9=85=E5=9D=90=E6=8F=90=E9=86=92=E6=B7=BB?= =?utf8?q?=E5=8A=A0=E5=8F=B3=E6=BB=91=E9=80=80=E5=87=BA=E8=A7=86=E5=9B=BE?= =?utf8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../notify/sedentaryReminder_notification.h | 5 +- .../notify/sedentaryReminder_notification.cpp | 57 ++++++++++++++++--- 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/sedentaryReminder_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/sedentaryReminder_notification.h index 490f7de34..769a51daa 100644 --- a/code/sdk/application/wearable/service/msg_center/include/notify/sedentaryReminder_notification.h +++ b/code/sdk/application/wearable/service/msg_center/include/notify/sedentaryReminder_notification.h @@ -8,11 +8,13 @@ namespace OHOS UIViewGroup *CreateSedentaryReminderView(void); void FreeSedentaryReminderView(void); - class SedentaryReminderViewEventListener : public UIView::OnTouchListener + class SedentaryReminderViewEventListener : public UIView::OnTouchListener,public UIView::OnDragListener { public: static SedentaryReminderViewEventListener &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; bool IsReminderTime(); int GetIntervalTime(); private: @@ -22,6 +24,7 @@ namespace OHOS const SedentaryReminderViewEventListener &operator=(const SedentaryReminderViewEventListener &) = delete; int interval; // 久坐间隔设置 std::string reminderTime; // 提醒时间段设置 + bool X_DRAG_FLAG{false}; }; } diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/sedentaryReminder_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/sedentaryReminder_notification.cpp index c6b65ac96..81e776367 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/sedentaryReminder_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/sedentaryReminder_notification.cpp @@ -23,7 +23,11 @@ namespace OHOS UILabelExt *SedentaryReminderLabel{nullptr}; UIButton *SedentaryReminderButton{nullptr}; - static constexpr const char *SedentaryReminderBUTTONVIEWID = "SedentaryReminderButton"; + static constexpr const int X_DRAG_OFFSET = 20; + static constexpr const int DOUBLES = 2; + + static constexpr const char *SEDENTARY_REMINDER_GROUPVIEWID = "sedentary_reminder_groupviewid"; + static constexpr const char *SEDENTARY_REMINDER_BUTTONVIEWID = "sedentary_reminder_buttonviewid"; SedentaryReminderViewEventListener::SedentaryReminderViewEventListener() { @@ -43,10 +47,10 @@ namespace OHOS bool SedentaryReminderViewEventListener::OnRelease(UIView &view, const ReleaseEvent &event) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SedentaryReminderViewEventListener::OnRelease"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SedentaryReminderViewEventListener::OnRelease"); UNUSED(event); std::string viewId = view.GetViewId(); - if (viewId == SedentaryReminderBUTTONVIEWID) + if (viewId == SEDENTARY_REMINDER_BUTTONVIEWID) { NotificationManager::GetInstance()->StopNotify(); } @@ -54,6 +58,32 @@ namespace OHOS return true; } + bool SedentaryReminderViewEventListener::OnDrag(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SedentaryReminderViewEventListener::OnDrag"); + UNUSED(view); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + SedentaryReminderViewEventListener::X_DRAG_FLAG = true; + } + return true; + } + + bool SedentaryReminderViewEventListener::OnDragEnd(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SedentaryReminderViewEventListener::OnDragEnd"); + std::string viewId = view.GetViewId(); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && SedentaryReminderViewEventListener::X_DRAG_FLAG) + { + if (viewId == SEDENTARY_REMINDER_GROUPVIEWID) + { + NotificationManager::GetInstance()->StopNotify(); + } + SedentaryReminderViewEventListener::X_DRAG_FLAG = false; + } + return true; + } + // 是否是久坐提醒时间段内 bool SedentaryReminderViewEventListener::IsReminderTime() { @@ -76,7 +106,7 @@ namespace OHOS int SedentaryReminderViewEventListener::GetIntervalTime() { interval = ConfigModel::GetInstance()->GetSedentaryInterval(); - return interval; + return interval; } /*创建久坐提醒视图*/ @@ -92,8 +122,16 @@ namespace OHOS return nullptr; } SedentaryReminderGroupView->SetPosition(0, 0, 466, 466); + SedentaryReminderGroupView->SetViewId(SEDENTARY_REMINDER_GROUPVIEWID); SedentaryReminderGroupView->SetTouchable(true); SedentaryReminderGroupView->SetDraggable(true); + UIView::OnDragListener *dragListener = static_cast(&SedentaryReminderViewEventListener::GetInstance()); + if (dragListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateSedentaryReminderView] dragListener new fail!!"); + return nullptr; + } + SedentaryReminderGroupView->SetOnDragListener(dragListener); /* ------------------------- SedentaryReminderTitleLabel ------------------------ */ SedentaryReminderTitleLabel = new UILabelExt(); if (SedentaryReminderTitleLabel == nullptr) @@ -146,12 +184,17 @@ namespace OHOS return nullptr; } SedentaryReminderButton->SetPosition(0, 366, 466, 100); - SedentaryReminderButton->SetViewId(SedentaryReminderBUTTONVIEWID); + SedentaryReminderButton->SetViewId(SEDENTARY_REMINDER_BUTTONVIEWID); const char *buttonImgSrc = "/user/res/466x100button.bin"; SedentaryReminderButton->SetImageSrc(buttonImgSrc, buttonImgSrc); SedentaryReminderButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff0b1928, UIButton::PRESSED); - UIView::OnTouchListener *listener = static_cast(&SedentaryReminderViewEventListener::GetInstance()); - SedentaryReminderButton->SetOnTouchListener(listener); + UIView::OnTouchListener *TouchListener = static_cast(&SedentaryReminderViewEventListener::GetInstance()); + if (TouchListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateSedentaryReminderView] TouchListener new fail!!"); + return nullptr; + } + SedentaryReminderButton->SetOnTouchListener(TouchListener); /* --------------------------- SedentaryReminderLabel --------------------------- */ SedentaryReminderLabel = new UILabelExt(); if (SedentaryReminderLabel == nullptr) -- 2.17.1