mcu_hi3321_watch/tjd/ui/app/dock/TjdUiAppDockPresenter.cpp
2025-05-26 20:15:20 +08:00

64 lines
2.0 KiB
C++

/*----------------------------------------------------------------------------
* Copyright (c) TJD Technologies Co., Ltd. 2025. All rights reserved.
*
* Description: TjdUiAppDockPresenter.cpp
*
* Author: luziquan@ss-tjd.com
*
* Create: 2024-06-15
*--------------------------------------------------------------------------*/
#include "TjdUiAppDockPresenter.h"
#include "NativeAbility.h"
#include "TjdUiAppDockView.h"
#include "TjdUiOnKeyListener.h"
#include "TjdUiRegisterManager.h"
#include "common/key_code.h"
#include "dock/input_device.h"
namespace TJD {
TJD_REGIST_SLICE(TJD_APP_VIEW_DOCK, TjdUiAppDockView, TjdUiAppDockPresenter);
static TjdUiAppDockPresenter *g_dockPresenter = nullptr;
TjdUiAppDockPresenter::TjdUiAppDockPresenter() { g_dockPresenter = this; }
TjdUiAppDockPresenter::~TjdUiAppDockPresenter() { g_dockPresenter = nullptr; }
TjdUiAppDockPresenter *TjdUiAppDockPresenter::GetInstance(void) { return g_dockPresenter; }
void TjdUiAppDockPresenter::OnStart()
{
TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE);
}
void TjdUiAppDockPresenter::OnStop()
{
TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE);
}
bool TjdUiAppDockPresenter::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
{
int sliceId = view.GetViewIndex();
if (sliceId != 0) {
OHOS::NativeAbility::GetInstance().ChangeSlice(sliceId);
}
return false;
}
bool TjdUiAppDockPresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event)
{
if (event.GetKeyId() == static_cast<uint16_t>(OHOS::ZliteKeyCode::ZLITE_KEY_TJD_LEFT)) {
return false;
}
if (event.GetState() != OHOS::InputDevice::STATE_RELEASE &&
event.GetState() != OHOS::InputDevice::STATE_DOUBLE_CLICK) {
return false;
}
OHOS::NativeAbility::GetInstance().ChangePreSlice();
return false;
}
} // namespace TJD