mcu_hi3321_watch/tjd/ui/watch_face/TjdUiWatchFaceBase.cpp
2025-05-26 20:15:20 +08:00

181 lines
5.0 KiB
C++

/*----------------------------------------------------------------------------
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
*
* Description: TjdUiWatchFaceBase.cpp
*
* Author: liuguanwu
*
* Create: 2024-10
*--------------------------------------------------------------------------*/
#include "TjdUiWatchFaceBase.h"
#include "DialModelTime.h"
#include "TjdDialModelTime.h"
#include "View.h"
#include "common/image_cache_manager.h"
#include "sys_config.h"
#if ENABLE_MEMORY_CHECK
#include "gfx_utils/mem_check.h"
#endif
using namespace OHOS;
namespace TJD {
#define ENABLE_PRINT_INFO 0
#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
#define WF_BIN_PATH TJD_FS_DIR_WF
/**********************************************************************************************************************
* PUBLIC FUNCTIONS
*/
TjdUiWfBase::TjdUiWfBase() : dialViewGroup_(nullptr), isDialView_(false), cardPageEvent_(nullptr)
{
SetPosition(0, 0, OHOS::Screen::GetInstance().GetWidth(), OHOS::Screen::GetInstance().GetHeight());
SetViewId("wf_card");
SetCoverable(true);
}
TjdUiWfBase::TjdUiWfBase(OHOS::DialViewGroup *dialViewGroup)
: dialViewGroup_(dialViewGroup), isDialView_(true), cardPageEvent_(nullptr)
{
SetPosition(0, 0, OHOS::Screen::GetInstance().GetWidth(), OHOS::Screen::GetInstance().GetHeight());
SetViewId("wf_card");
SetCoverable(true);
Add(dialViewGroup);
}
TjdUiWfBase::~TjdUiWfBase()
{
if (dialViewGroup_) {
delete dialViewGroup_;
dialViewGroup_ = nullptr;
}
TjdDialModelTime::GetInstance()->Unload();
}
void TjdUiWfBase::SetPeriod(uint32_t period)
{
if (period_ < OHOS::DEFAULT_TASK_PERIOD) {
period_ = OHOS::DEFAULT_TASK_PERIOD;
} else {
period_ = period;
}
}
uint32_t TjdUiWfBase::GetPeriod(void) { return period_; }
void TjdUiWfBase::Update()
{
if (dialViewGroup_ != nullptr) {
DialModelTime::GetInstance()->UpdateTime();
TjdDialModelTime::GetInstance()->UpdateTime();
dialViewGroup_->UpdateViewsByPeriodicUpdateData();
return;
}
}
bool TjdUiWfBase::IsDialView() { return isDialView_; }
OHOS::DialViewGroup *TjdUiWfBase::GetDialViewGroup() { return dialViewGroup_; }
void TjdUiWfBase::ScrollBegin(bool isActive)
{
static_print_debug("TjdUiWfBase::ScrollBegin %d", isActive);
CallCardPageEvent(CardPageEvent::CARD_PAGE_EVENT_SCROLLBEGIN, isActive);
if (dialViewGroup_ != nullptr) {
dialViewGroup_->ScrollBegin(isActive);
}
}
void TjdUiWfBase::ScrollEnd(bool isActive)
{
static_print_debug("TjdUiWfBase::ScrollEnd %d", isActive);
CallCardPageEvent(CardPageEvent::CARD_PAGE_EVENT_SCROLLEND, isActive);
if (dialViewGroup_ != nullptr) {
dialViewGroup_->ScrollEnd(isActive);
}
}
void TjdUiWfBase::CoverBegin(bool isCovered)
{
static_print_debug("TjdUiWfBase::CoverBegin %d", isCovered);
CallCardPageEvent(CardPageEvent::CARD_PAGE_EVENT_COVERBEGIN, isCovered);
if (dialViewGroup_ != nullptr) {
dialViewGroup_->CoverBegin(isCovered);
}
}
void TjdUiWfBase::CoverEnd(bool isCovered)
{
static_print_debug("TjdUiWfBase::CoverEnd %d", isCovered);
CallCardPageEvent(CardPageEvent::CARD_PAGE_EVENT_COVEREND, isCovered);
if (dialViewGroup_ != nullptr) {
dialViewGroup_->CoverEnd(isCovered);
}
}
void TjdUiWfBase::OnActive(void)
{
static_print_debug("TjdUiWfBase::OnActive");
CallCardPageEvent(CardPageEvent::CARD_PAGE_EVENT_ONACTIVE, true);
if (dialViewGroup_ != nullptr) {
dialViewGroup_->OnActive();
}
}
void TjdUiWfBase::OnInactive(void)
{
static_print_debug("TjdUiWfBase::OnInactive");
CallCardPageEvent(CardPageEvent::CARD_PAGE_EVENT_ONINACTIVE, true);
if (dialViewGroup_ != nullptr) {
dialViewGroup_->OnInactive();
}
}
void TjdUiWfBase::OnCovered(void)
{
static_print_debug("TjdUiWfBase::OnCovered");
if (dialViewGroup_ != nullptr) {
dialViewGroup_->OnCovered();
}
}
void TjdUiWfBase::OnUncovered(void)
{
static_print_debug("TjdUiWfBase::OnUncovered");
if (dialViewGroup_ != nullptr) {
dialViewGroup_->OnUncovered();
}
}
void TjdUiWfBase::OnPause(void)
{
static_print_debug("TjdUiWfBase::OnPause");
CallCardPageEvent(CardPageEvent::CARD_PAGE_EVENT_ONINACTIVE, false);
if (dialViewGroup_ != nullptr) {
dialViewGroup_->OnPause();
}
}
void TjdUiWfBase::CallCardPageEvent(CardPageEvent event, bool eventValue)
{
if (cardPageEvent_) {
static_print_debug("TjdUiWfBase::CallCardPageEvent:%d", event);
cardPageEvent_(event, eventValue);
}
}
} // namespace TJD