mcu_hi3321_watch/tjd/ui/common/TjdUiScreenDrag.h
2025-05-26 20:15:20 +08:00

76 lines
2.1 KiB
C++

/*----------------------------------------------------------------------------
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
*
* Description:
*
* Author: huangshuyi
*
* Create: 2024-11
*--------------------------------------------------------------------------*/
#ifndef TJDUI_SCREEN_DRAG_H
#define TJDUI_SCREEN_DRAG_H
#include "NativeAbility.h"
#include "components/ui_scroll_view.h"
#include "components/ui_view.h"
#include "drag_event.h"
#include "sys_config.h"
#include <cstdint>
namespace TJD {
#define ENABLE_PRINT_INFO 1
#if ENABLE_PRINT_INFO
#define static_print_info(...) sys_ui_log_i(__VA_ARGS__) //一般信息打印宏控制
#define static_print_warn(...) sys_ui_log_w(__VA_ARGS__) //警告信息打印一般常开
#define static_print_error(...) sys_ui_log_e(__VA_ARGS__) //错误信息打印一般常开
#define static_print_debug(...) sys_ui_log_d(__VA_ARGS__)
#else
#define static_print_info(...)
#define static_print_warn(...)
#define static_print_error(...)
#define static_print_debug(...)
#endif
class TjdUiScreenDragListener : public OHOS::UIView::OnDragListener
{
public:
virtual ~TjdUiScreenDragListener() {}
bool OnDragStart(OHOS::UIView &view, const OHOS::DragEvent &event)
{
if (event.GetStartPoint().x >= 120) {
isExit_ = false;
}
return false;
}
bool OnDrag(OHOS::UIView &view, const OHOS::DragEvent &event)
{
if (isExit_ == false) {
return false;
}
if ((event.GetDragDirection() == OHOS::DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > 20) &&
(event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) {
isExit_ = false;
ScreenDragEventCallback(view, event);
}
return false;
}
bool OnDragEnd(OHOS::UIView &view, const OHOS::DragEvent &event)
{
isExit_ = true;
return false;
}
virtual void ScreenDragEventCallback(OHOS::UIView &view, const OHOS::DragEvent &event)
{
OHOS::NativeAbility::GetInstance().ChangePreSlice();
}
private:
bool isExit_{true};
};
}
#endif