127 lines
3.6 KiB
C++
127 lines
3.6 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 "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()
|
|
{
|
|
timer_ = new OHOS::GraphicTimer(
|
|
3000,
|
|
[](void *arg) {
|
|
GraphicService::GetInstance()->PostGraphicEvent([]() {
|
|
TjdUiWatchFacePresenter *presenter = TjdUiWatchFacePresenter::GetInstance();
|
|
if (presenter == nullptr) {
|
|
return;
|
|
}
|
|
presenter->SelectDefaultWatchFace();
|
|
});
|
|
},
|
|
this, true);
|
|
TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE);
|
|
}
|
|
|
|
void TjdUiWatchFacePresenter::OnStop()
|
|
{
|
|
TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE);
|
|
if (timer_) {
|
|
timer_->Stop();
|
|
delete timer_;
|
|
timer_ = nullptr;
|
|
}
|
|
}
|
|
|
|
void TjdUiWatchFacePresenter::OnResume()
|
|
{
|
|
Presenter::OnResume();
|
|
view_->SetUpCoverflowView();
|
|
if (timer_ && !osTimerIsRunning(timer_->GetNativeTimer())) {
|
|
timer_->Start();
|
|
}
|
|
}
|
|
|
|
bool TjdUiWatchFacePresenter::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
|
|
{
|
|
uint32_t id = 0;
|
|
auto itemView = dynamic_cast<WatchFaceCoverflowItemView *>(&view);
|
|
if (itemView != nullptr) {
|
|
id = itemView->GetWfId();
|
|
}
|
|
sql_setting_set_watch_face_id(id);
|
|
TjdUiAppMainView::ChangeMainViewToMainPage();
|
|
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(uint16_t distance)
|
|
{
|
|
ResetTimer();
|
|
return true;
|
|
}
|
|
|
|
void TjdUiWatchFacePresenter::SelectDefaultWatchFace(void)
|
|
{
|
|
uint32_t id = view_->GetCurCoverflowItemWfId();
|
|
sql_setting_set_watch_face_id(id);
|
|
TjdUiAppMainView::ChangeMainViewToMainPage();
|
|
}
|
|
|
|
void TjdUiWatchFacePresenter::ResetTimer(void)
|
|
{
|
|
if (timer_) {
|
|
timer_->Stop();
|
|
timer_->Start();
|
|
}
|
|
}
|
|
|
|
} // namespace TJD
|