From: Caisking Date: Sun, 11 Jan 2026 11:05:27 +0000 (+0800) Subject: 优化运动卡片的滑动效果 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=340c46d3bff9843e121222a9b8770ea7c9e3579b;p=mirrors%2FFD230.git 优化运动卡片的滑动效果 --- diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingModel.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingModel.cpp index 61fa5a6d9..52c19924d 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingModel.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingModel.cpp @@ -1868,7 +1868,7 @@ } } - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "duration:[%d] g_motionTimes[%d]\r\n", + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "duration:[%d] g_motionTimes[%d]\r\n", sportdata->duration, g_motionTimes); } #ifdef __cplusplus diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/include/TraingCardPresenter.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/include/TraingCardPresenter.h index 51935d4b6..46660b0bb 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/include/TraingCardPresenter.h +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/include/TraingCardPresenter.h @@ -76,13 +76,15 @@ public: private: // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDragStart(UIView &view, const DragEvent &event) override; bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; void OnSwipe(UISwipeView &view) override; bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 int tag_ = 0; bool opensensorstuats{false}; - // bool OnDragEnd(UIView& view, const DragEvent& event) override; + bool Y_DRAG_FLAG{false}; // 标记是否为垂直滑动,用于阻止水平滑动 }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/TraingCardPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/TraingCardPresenter.cpp index aeb0a858e..744cd8ac3 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/TraingCardPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/TraingCardPresenter.cpp @@ -13,19 +13,20 @@ * /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp */ - #include "AppViewIDs.h" - #include "NativeAbility.h" - #include "components/ui_label_ext.h" - #include "ui_resource_string.h" - - #include "ConfigModel.h" - #include "custom_utils.h" - #include "graphic_service.h" - #include "traing/include/TraingModel.h" - #include "traing/training_card/include/TraingCardPresenter.h" - #include "traing/training_card/include/TrainingControlView.h" - #include "uicomponents/UIComponents.h" - #include "vibrator_service.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "components/ui_label_ext.h" +#include "ui_resource_string.h" + +#include "ConfigModel.h" +#include "custom_utils.h" +#include "graphic_service.h" +#include "traing/include/TraingModel.h" +#include "traing/training_card/include/TraingCardPresenter.h" +#include "traing/training_card/include/TrainingControlView.h" +#include "uicomponents/UIComponents.h" +#include "vibrator_service.h" +#include "UiConfig.h" #include #include @@ -93,10 +94,38 @@ // ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 长亮屏 } - bool TraingCardPresenter::OnDrag(UIView &view, const DragEvent &event) { - UNUSED(view); - return true; - } +bool TraingCardPresenter::OnDragStart(UIView &view, const DragEvent &event) { + UNUSED(view); + UNUSED(event); + // 重置标志 + Y_DRAG_FLAG = false; + return false; +} + +bool TraingCardPresenter::OnDrag(UIView &view, const DragEvent &event) { + UNUSED(view); + // 拖动过程中判断是否是垂直滑动:垂直距离大于阈值,且垂直距离大于水平距离的2倍 + if ((event.GetDeltaY() > X_DRAG_OFFSET || event.GetDeltaY() < -X_DRAG_OFFSET) && + (MATH_ABS(event.GetDeltaY()) > (DOUBLES * MATH_ABS(event.GetDeltaX())))) { + Y_DRAG_FLAG = true; // 标记为垂直滑动 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Vertical drag detected (deltaY=%d, deltaX=%d), blocking horizontal swipe", + event.GetDeltaY(), event.GetDeltaX()); + } + return true; +} + +bool TraingCardPresenter::OnDragEnd(UIView &view, const DragEvent &event) { + UNUSED(view); + // 如果检测到垂直滑动,阻止水平滑动 + if (Y_DRAG_FLAG) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Vertical drag ended, blocking horizontal swipe"); + Y_DRAG_FLAG = false; + // 返回true阻止水平滑动事件 + return true; + } + Y_DRAG_FLAG = false; + return false; +} // 计时器更新timer void TraingCardPresenter::ModifiesTime() { diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/TraingCardView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/TraingCardView.cpp index 2e5336415..f2b78335f 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/TraingCardView.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/src/TraingCardView.cpp @@ -6,6 +6,7 @@ #include "components/ui_label_ext.h" #include "ui_resource_image.h" #include "ui_resource_string.h" +#include #include #include "common/screen.h" @@ -751,15 +752,8 @@ void TraingCardView::OnStart() { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "swipe_ new fail"); return; } - UIView::OnDragListener *listener = - static_cast(TraingCardPresenter::GetInstance()); - if (listener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "AlarmSetWeekView:: new alarmDragListener fail"); - return; - } - swipe_->SetOnDragListener(listener); + PreLoad(); swipe_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); @@ -768,8 +762,9 @@ void TraingCardView::OnStart() { swipe_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR); swipe_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - swipe_->EnableScreenCap(false); - + swipe_->SetOnDragListener(presenter_); + swipe_->SetOnSwipeListener(presenter_); + swipe_->EnableScreenCap(true); swipe_->SetAnimatorTime(50); AddViewToRootContainer(swipe_);