111 lines
3.3 KiB
C++
111 lines
3.3 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
|
*
|
|
* Description:
|
|
*
|
|
* Author: huangshuyi
|
|
*
|
|
* Create: 2024-4
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
#include "TjdUiWatchFacePresenter.h"
|
|
#include "NativeAbility.h"
|
|
#include "TjdUiAppIds.h"
|
|
#include "TjdUiAppMainView.h"
|
|
#include "TjdUiRegisterManager.h"
|
|
#include "TjdUiWatchFaceView.h"
|
|
#include "common/key_code.h"
|
|
#include "dock/input_device.h"
|
|
#include "graphic_service.h"
|
|
#include "hal_tick.h"
|
|
#include "sql_setting.h"
|
|
#include "sys_config.h"
|
|
|
|
namespace TJD {
|
|
|
|
TJD_REGIST_SLICE(TJD_APP_VIEW_WF_SELECT, TjdUiWatchFaceView, TjdUiWatchFacePresenter);
|
|
|
|
#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
|
|
|
|
static TjdUiWatchFacePresenter *g_watchFacePresenter = nullptr;
|
|
|
|
TjdUiWatchFacePresenter::TjdUiWatchFacePresenter() { g_watchFacePresenter = this; }
|
|
|
|
TjdUiWatchFacePresenter::~TjdUiWatchFacePresenter() { g_watchFacePresenter = nullptr; }
|
|
|
|
TjdUiWatchFacePresenter *TjdUiWatchFacePresenter::GetInstance(void) { return g_watchFacePresenter; }
|
|
|
|
void TjdUiWatchFacePresenter::OnStart()
|
|
{
|
|
TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE);
|
|
}
|
|
|
|
void TjdUiWatchFacePresenter::OnStop()
|
|
{
|
|
TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE);
|
|
}
|
|
|
|
void TjdUiWatchFacePresenter::OnTickEvent()
|
|
{
|
|
uint64_t current_time = static_cast<uint64_t>(OHOS::HALTick::GetInstance().GetTime());
|
|
if ((startTime != 0) && (current_time - startTime > 3000)) {
|
|
SelectCurWatchFace();
|
|
}
|
|
}
|
|
|
|
bool TjdUiWatchFacePresenter::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
|
|
{
|
|
OHOS::Point point = event.GetCurrentPos();
|
|
const int SCREEN_SIZE = 466;
|
|
const int ITEM_SIZE = 246;
|
|
int startX = (SCREEN_SIZE - ITEM_SIZE) / 2;
|
|
int startY = startX;
|
|
int endX = startX + ITEM_SIZE;
|
|
int endY = startY + ITEM_SIZE;
|
|
if (point.x >= startX && point.x <= endX && point.y >= startY && point.y <= endY) {
|
|
SelectCurWatchFace();
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
bool TjdUiWatchFacePresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event)
|
|
{
|
|
if (!TjdUiCommonOnKeyListener::CheckIsExitEvent(event)) {
|
|
return true;
|
|
}
|
|
OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_MAIN, OHOS::TransitionType::TRANSITION_INVALID);
|
|
return true;
|
|
}
|
|
|
|
bool TjdUiWatchFacePresenter::OnScroll()
|
|
{
|
|
view_->CoverflowViewScroll();
|
|
return true;
|
|
}
|
|
|
|
void TjdUiWatchFacePresenter::SelectCurWatchFace(void)
|
|
{
|
|
uint32_t id = view_->GetCurCoverflowItemWfId();
|
|
sql_setting_set_watch_face_id(id);
|
|
OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_MAIN);
|
|
}
|
|
|
|
void TjdUiWatchFacePresenter::ResetTimer(void)
|
|
{
|
|
startTime = static_cast<uint64_t>(OHOS::HALTick::GetInstance().GetTime());
|
|
}
|
|
|
|
} // namespace TJD
|