141 lines
5.0 KiB
C++
141 lines
5.0 KiB
C++
#include "TjdUiAppLockScreenPresenter.h"
|
|
#include "TjdUiAppLockScreenView.h"
|
|
#include "TjdUiOnKeyListener.h"
|
|
#include "TjdUiScreenEvent.h"
|
|
#include "common/key_code.h"
|
|
#include "dock/input_device.h"
|
|
#include "graphic_service.h"
|
|
#include "sys_config.h"
|
|
#include "wearable_log.h"
|
|
|
|
#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
|
|
|
|
using namespace OHOS;
|
|
|
|
namespace TJD {
|
|
|
|
static bool LockScreenEnable = false;
|
|
|
|
static TjdUiAppLockScreenView *g_appLockScreenView = nullptr;
|
|
static TjdUiAppLockScreenPresenter *g_appLockScreenPresenter = nullptr;
|
|
TjdUiAppLockScreenPresenter::TjdUiAppLockScreenPresenter()
|
|
{
|
|
g_appLockScreenPresenter = this;
|
|
TjdUiCommonOnKeyListener::GetInstance()->SetLongPressActIntercept(true);
|
|
}
|
|
|
|
TjdUiAppLockScreenPresenter::~TjdUiAppLockScreenPresenter()
|
|
{
|
|
g_appLockScreenPresenter = nullptr;
|
|
TjdUiCommonOnKeyListener::GetInstance()->SetLongPressActIntercept(false);
|
|
}
|
|
|
|
TjdUiAppLockScreenPresenter *TjdUiAppLockScreenPresenter::GetInstance(void) { return g_appLockScreenPresenter; }
|
|
|
|
bool TjdUiAppLockScreenPresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event)
|
|
{
|
|
UNUSED(view);
|
|
uint8_t state = event.GetState();
|
|
uint16_t keyid = event.GetKeyId();
|
|
TjdUiAppLockScreenView *lockScreenView = TjdUiAppLockScreenView::GetInstance();
|
|
if (state == OHOS::InputDevice::STATE_PRESS && event.GetKeyId() == 4165) {
|
|
// lockScreenView->TimerStart();
|
|
LockScreenView::GetInstance()->lockScreenAnimator_->Start();
|
|
return true;
|
|
} else if (state == OHOS::InputDevice::STATE_LONGPRESS_1S || state == OHOS::InputDevice::STATE_LONGPRESS_2S ||
|
|
state == OHOS::InputDevice::STATE_LONGPRESS_3S) {
|
|
} else {
|
|
if (LockScreenView::GetInstance()->lockScreenAnimator_) {
|
|
LockScreenView::GetInstance()->lockScreenAnimator_->Stop();
|
|
}
|
|
}
|
|
// if (state == OHOS::InputDevice::STATE_RELEASE ||
|
|
// state == OHOS::InputDevice::STATE_LONGPRESS_1S_OVER ||
|
|
// state == OHOS::InputDevice::STATE_LONGPRESS_2S_OVER ||
|
|
// state == OHOS::InputDevice::STATE_LONGPRESS_2S ||
|
|
// state == OHOS::InputDevice::STATE_DOUBLE_CLICK ) {
|
|
// static_print_info("ZliteKeyCode::ZLITE_KEY_TJD_RIGHTDOWN");
|
|
// // lockScreenView->TimerStop();
|
|
// LockScreenView::GetInstance()->lockScreenAnimator_->Stop();
|
|
// }
|
|
return true;
|
|
}
|
|
|
|
bool TjdUiAppLockScreenPresenter::OnDragStart(OHOS::UIView &view, const OHOS::DragEvent &event)
|
|
{
|
|
dragStartX_ = event.GetStartPoint().x;
|
|
return true;
|
|
}
|
|
|
|
bool TjdUiAppLockScreenPresenter::OnDrag(OHOS::UIView &view, const OHOS::DragEvent &event)
|
|
{
|
|
dragCurrentX_ = event.GetCurrentPos().x;
|
|
dragDistance_ = dragCurrentX_ - dragStartX_;
|
|
return true;
|
|
}
|
|
|
|
bool TjdUiAppLockScreenPresenter::OnDragEnd(OHOS::UIView &view, const OHOS::DragEvent &event)
|
|
{
|
|
dragDistance_ = dragCurrentX_ - dragStartX_;
|
|
if (dragDistance_ >= 250 && dragStartX_ < 120) {
|
|
isExit_ = true;
|
|
} else {
|
|
isExit_ = false;
|
|
}
|
|
dragDistance_ = 0;
|
|
if (isExit_ == false) {
|
|
return false;
|
|
}
|
|
|
|
if (event.GetDragDirection() == OHOS::DragEvent::DIRECTION_LEFT_TO_RIGHT) {
|
|
TjdUiScreenEventEndEvent();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void HideLockScreenView()
|
|
{
|
|
static_print_info("HideLockScreenView");
|
|
GraphicService::GetInstance()->PostGraphicEvent([]() {
|
|
delete g_appLockScreenPresenter;
|
|
g_appLockScreenPresenter = nullptr;
|
|
if (g_appLockScreenView) {
|
|
RootView::GetInstance()->RemoveSystemView(g_appLockScreenView);
|
|
delete g_appLockScreenView;
|
|
g_appLockScreenView = nullptr;
|
|
TJD::TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::LOCK_SCREEN_KEY_TYPE);
|
|
}
|
|
});
|
|
}
|
|
|
|
void ShowLockScreenView()
|
|
{
|
|
static_print_info("ShowLockScreenView");
|
|
if (g_appLockScreenView == nullptr) {
|
|
g_appLockScreenPresenter = new TjdUiAppLockScreenPresenter();
|
|
TJD::TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(g_appLockScreenPresenter,
|
|
KeyModelType::LOCK_SCREEN_KEY_TYPE);
|
|
g_appLockScreenView = new TjdUiAppLockScreenView();
|
|
RootView::GetInstance()->AddSystemView(g_appLockScreenView);
|
|
g_appLockScreenView->Invalidate();
|
|
}
|
|
}
|
|
|
|
bool IsShowLockScreenView() { return g_appLockScreenView != nullptr; }
|
|
|
|
bool IsLockScreenEnable(void) { return LockScreenEnable; };
|
|
|
|
void SetLockScreenEnable(bool enable) { LockScreenEnable = enable; };
|
|
|
|
} // namespace TJD
|