private:\r
// 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承;\r
bool OnClick(UIView &view, const ClickEvent &event) override;\r
+ bool OnDragStart(UIView &view, const DragEvent &event) override;\r
bool OnDrag(UIView &view, const DragEvent &event) override;\r
+ bool OnDragEnd(UIView &view, const DragEvent &event) override;\r
void OnSwipe(UISwipeView &view) override;\r
bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件\r
\r
int tag_ = 0;\r
bool opensensorstuats{false};\r
- // bool OnDragEnd(UIView& view, const DragEvent& event) override;\r
+ bool Y_DRAG_FLAG{false}; // 标记是否为垂直滑动,用于阻止水平滑动\r
};\r
} // namespace OHOS\r
\r
* /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp\r
*/\r
\r
- #include "AppViewIDs.h"\r
- #include "NativeAbility.h"\r
- #include "components/ui_label_ext.h"\r
- #include "ui_resource_string.h"\r
- \r
- #include "ConfigModel.h"\r
- #include "custom_utils.h"\r
- #include "graphic_service.h"\r
- #include "traing/include/TraingModel.h"\r
- #include "traing/training_card/include/TraingCardPresenter.h"\r
- #include "traing/training_card/include/TrainingControlView.h"\r
- #include "uicomponents/UIComponents.h"\r
- #include "vibrator_service.h"\r
+#include "AppViewIDs.h"\r
+#include "NativeAbility.h"\r
+#include "components/ui_label_ext.h"\r
+#include "ui_resource_string.h"\r
+\r
+#include "ConfigModel.h"\r
+#include "custom_utils.h"\r
+#include "graphic_service.h"\r
+#include "traing/include/TraingModel.h"\r
+#include "traing/training_card/include/TraingCardPresenter.h"\r
+#include "traing/training_card/include/TrainingControlView.h"\r
+#include "uicomponents/UIComponents.h"\r
+#include "vibrator_service.h"\r
+#include "UiConfig.h"\r
\r
#include <chrono>\r
#include <iomanip>\r
// ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 长亮屏\r
}\r
\r
- bool TraingCardPresenter::OnDrag(UIView &view, const DragEvent &event) {\r
- UNUSED(view);\r
- return true;\r
- }\r
+bool TraingCardPresenter::OnDragStart(UIView &view, const DragEvent &event) {\r
+ UNUSED(view);\r
+ UNUSED(event);\r
+ // 重置标志\r
+ Y_DRAG_FLAG = false;\r
+ return false;\r
+}\r
+\r
+bool TraingCardPresenter::OnDrag(UIView &view, const DragEvent &event) {\r
+ UNUSED(view);\r
+ // 拖动过程中判断是否是垂直滑动:垂直距离大于阈值,且垂直距离大于水平距离的2倍\r
+ if ((event.GetDeltaY() > X_DRAG_OFFSET || event.GetDeltaY() < -X_DRAG_OFFSET) && \r
+ (MATH_ABS(event.GetDeltaY()) > (DOUBLES * MATH_ABS(event.GetDeltaX())))) {\r
+ Y_DRAG_FLAG = true; // 标记为垂直滑动\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Vertical drag detected (deltaY=%d, deltaX=%d), blocking horizontal swipe", \r
+ event.GetDeltaY(), event.GetDeltaX());\r
+ }\r
+ return true;\r
+}\r
+\r
+bool TraingCardPresenter::OnDragEnd(UIView &view, const DragEvent &event) {\r
+ UNUSED(view);\r
+ // 如果检测到垂直滑动,阻止水平滑动\r
+ if (Y_DRAG_FLAG) {\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Vertical drag ended, blocking horizontal swipe");\r
+ Y_DRAG_FLAG = false;\r
+ // 返回true阻止水平滑动事件\r
+ return true;\r
+ }\r
+ Y_DRAG_FLAG = false;\r
+ return false;\r
+}\r
\r
// 计时器更新timer\r
void TraingCardPresenter::ModifiesTime() {\r
#include "components/ui_label_ext.h"\r
#include "ui_resource_image.h"\r
#include "ui_resource_string.h"\r
+#include <stdbool.h>\r
#include <ui_scroll_view.h>\r
\r
#include "common/screen.h"\r
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "swipe_ new fail");\r
return;\r
}\r
- UIView::OnDragListener *listener =\r
- static_cast<UIView::OnDragListener *>(TraingCardPresenter::GetInstance());\r
- if (listener == nullptr) {\r
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,\r
- "AlarmSetWeekView:: new alarmDragListener fail");\r
- return;\r
- }\r
- swipe_->SetOnDragListener(listener);\r
\r
+ \r
PreLoad();\r
swipe_->SetPosition(0, 0, Screen::GetInstance().GetWidth(),\r
Screen::GetInstance().GetHeight());\r
swipe_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR);\r
swipe_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);\r
\r
- swipe_->EnableScreenCap(false);\r
-\r
+ swipe_->SetOnDragListener(presenter_);\r
+ swipe_->SetOnSwipeListener(presenter_);\r
+ swipe_->EnableScreenCap(true);\r
swipe_->SetAnimatorTime(50);\r
\r
AddViewToRootContainer(swipe_);\r