380 lines
12 KiB
C++
380 lines
12 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
|
*
|
|
* Description:
|
|
*
|
|
* Author: huangshuyi
|
|
*
|
|
* Create: 2024-4
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
#include "TjdUiWFPageCustom.h"
|
|
#include "TjdUiAppMainPresenter.h"
|
|
#include "TjdUiImageIds.h"
|
|
#include "TjdUiMemManage.h"
|
|
#include "TjdUiMultiLanguageExt.h"
|
|
#include "TjdUiWFCustomParse.h"
|
|
#include "common/image_cache_manager.h"
|
|
#include "common/key_code.h"
|
|
#include "rtc_api.h"
|
|
#include "sql_setting.h"
|
|
#include "sys_config.h"
|
|
#include "ui_screennotify.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 IMAGE_WF_CUNSTOM_BIN_PATH TJD_IMAGE_PATH "img_main_wf.bin"
|
|
|
|
static TjdUiWFPageCustom *g_wfPageCustom = nullptr;
|
|
|
|
static TjdUiWFCustomVideoPage *g_video{nullptr};
|
|
|
|
static void ScreenStatusNotify(ScreenStatus status)
|
|
{
|
|
if (g_video == nullptr) {
|
|
return;
|
|
}
|
|
if (status == SCREEN_STATUS_OFF) {
|
|
g_video->PausePlay();
|
|
} else if (status == SCREEN_STATUS_ON) {
|
|
if (g_video->IsPaused()) {
|
|
g_video->ResumePlay();
|
|
} else if (!g_video->IsPlayed()) {
|
|
g_video->StartPlay();
|
|
}
|
|
}
|
|
}
|
|
|
|
TjdUiWFPageCustom::TjdUiWFPageCustom() : wfParse_(new TjdUiWFCustomParse())
|
|
{
|
|
SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
|
|
SetPeriod(500);
|
|
registerNotifyScreenStatus(ScreenStatusNotify);
|
|
}
|
|
|
|
TjdUiWFPageCustom::~TjdUiWFPageCustom()
|
|
{
|
|
deregisterNotifyScreenStatus(ScreenStatusNotify);
|
|
if (viewiInitStatus) {
|
|
OnInactive();
|
|
ImageCacheManager::GetInstance().UnloadAllInMultiRes(IMAGE_WF_CUNSTOM_BIN_PATH);
|
|
mainView_.RemoveAll();
|
|
wfParse_->Unload();
|
|
viewiInitStatus = false;
|
|
}
|
|
UnLoad();
|
|
}
|
|
|
|
void TjdUiWFPageCustom::PreLoad(void)
|
|
{
|
|
static_print_debug("TjdUiWFPageCustom::PreLoad");
|
|
// MemCheck::GetInstance()->EnableLeakCheck(true);
|
|
if (!viewiInitStatus) {
|
|
ImageCacheManager::GetInstance().LoadAllInMultiRes(IMAGE_WF_CUNSTOM_BIN_PATH);
|
|
InitView();
|
|
Update();
|
|
viewiInitStatus = true;
|
|
}
|
|
}
|
|
|
|
void TjdUiWFPageCustom::UnLoad(void)
|
|
{
|
|
static_print_debug("TjdUiWFPageCustom::UnLoad");
|
|
// MemCheck::GetInstance()->EnableLeakCheck(false);
|
|
// Main clock view is commonly used page, so we do not release it's resources inner slice.
|
|
}
|
|
|
|
void TjdUiWFPageCustom::InitView(void)
|
|
{
|
|
ImageCacheManager &images = ImageCacheManager::GetInstance();
|
|
static_print_debug("TjdUiWFPageCustom::InitView");
|
|
SetCoverable(true);
|
|
|
|
mainView_.SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
|
|
Add(&mainView_);
|
|
|
|
if (wfParse_->ParseOnlineWfData(&mainView_) == false) {
|
|
static_print_error("ParseOnlineWfData failed, use default view");
|
|
mainView_.Add(&bg_);
|
|
bg_.SetPosition(0, 0);
|
|
bg_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_BG, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
}
|
|
video_ = wfParse_->GetVideoPage();
|
|
|
|
uint8_t hour = 8;
|
|
uint8_t min = 0;
|
|
uint8_t am_pm = 0;
|
|
|
|
hourHigh_.SetViewId("hourHigh");
|
|
mainView_.Add(&hourHigh_);
|
|
hourHigh_.SetPosition(141, 193);
|
|
hourHigh_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_TIME_NUM_0 + hour / 10 % 10, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
|
|
mainView_.Add(&hourLow_);
|
|
hourLow_.SetViewId("hourLow_");
|
|
hourLow_.AlignRightToSibling(hourHigh_.GetViewId());
|
|
hourLow_.AlignTopToSibling(hourHigh_.GetViewId());
|
|
hourLow_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_TIME_NUM_0 + hour % 10, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
|
|
mainView_.Add(&colon_);
|
|
colon_.SetViewId("colon_");
|
|
colon_.AlignRightToSibling(hourLow_.GetViewId());
|
|
colon_.AlignTopToSibling(hourLow_.GetViewId());
|
|
colon_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_TIME_NUM_B, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
colon_.SetVisible(false);
|
|
|
|
mainView_.Add(&minHigh_);
|
|
minHigh_.SetViewId("minHigh_");
|
|
minHigh_.AlignRightToSibling(colon_.GetViewId());
|
|
minHigh_.AlignTopToSibling(colon_.GetViewId());
|
|
minHigh_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_TIME_NUM_0 + min / 10 % 10, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
|
|
mainView_.Add(&minLow_);
|
|
minLow_.SetViewId("minLow_");
|
|
minLow_.AlignRightToSibling(minHigh_.GetViewId());
|
|
minLow_.AlignTopToSibling(minHigh_.GetViewId());
|
|
minLow_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_TIME_NUM_0 + min % 10, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
|
|
uint8_t month = 1; //获得当前的月份
|
|
uint8_t day = 1; //获得当前的日期
|
|
|
|
mainView_.Add(&monthHigh_);
|
|
monthHigh_.SetViewId("monthHigh_");
|
|
monthHigh_.SetPosition(150, 256);
|
|
monthHigh_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_DATE_NUM_0 + 1 / 10 % 10, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
|
|
mainView_.Add(&monthLow_);
|
|
monthLow_.SetViewId("monthLow_");
|
|
monthLow_.AlignRightToSibling(monthHigh_.GetViewId());
|
|
monthLow_.AlignTopToSibling(monthHigh_.GetViewId());
|
|
monthLow_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_DATE_NUM_0 + month % 10, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
|
|
mainView_.Add(&date_);
|
|
date_.SetViewId("date_");
|
|
date_.AlignRightToSibling(monthLow_.GetViewId());
|
|
date_.AlignTopToSibling(monthLow_.GetViewId());
|
|
date_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_DATE_NUM_A, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
|
|
mainView_.Add(&dayHigh_);
|
|
dayHigh_.SetViewId("dayHigh_");
|
|
dayHigh_.AlignRightToSibling(date_.GetViewId());
|
|
dayHigh_.AlignTopToSibling(date_.GetViewId());
|
|
dayHigh_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_DATE_NUM_0 + day / 10 % 10, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
|
|
mainView_.Add(&dayLow_);
|
|
dayLow_.SetViewId("dayLow_");
|
|
dayLow_.AlignRightToSibling(dayHigh_.GetViewId());
|
|
dayLow_.AlignTopToSibling(dayHigh_.GetViewId());
|
|
dayLow_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_DATE_NUM_0 + day % 10, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
|
|
uint8_t lang = LANGUAGE_CHINESE; //获得多语言的值
|
|
uint8_t week = 1; //获得当前是星期几
|
|
|
|
mainView_.Add(&week_);
|
|
week_.SetPosition(238, 253);
|
|
week_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_WEEK_CH_0 + week % 7, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
|
|
uint32_t imgList[2][2] = {{IMG_MAIN_WF_AM_EN, IMG_MAIN_WF_PM_EN}, {IMG_MAIN_WF_AM_CH, IMG_MAIN_WF_PM_CH}};
|
|
amPm_.SetSrc(images.LoadOneInMultiRes(imgList[lang][am_pm], IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
mainView_.Add(&amPm_);
|
|
amPm_.SetPosition(301, 203);
|
|
}
|
|
|
|
void TjdUiWFPageCustom::Update(void)
|
|
{
|
|
ImageCacheManager &images = ImageCacheManager::GetInstance();
|
|
if (colon_.IsVisible()) {
|
|
colon_.SetVisible(0);
|
|
} else {
|
|
colon_.SetVisible(1);
|
|
}
|
|
|
|
rtc_class_ops *rtc = tjd_driver_rtc_get_ops();
|
|
struct rtc_time localTime;
|
|
rtc->get_rtc_time(&localTime);
|
|
uint8_t hour = localTime.tm_hour; //获得当前的小时
|
|
uint8_t min = localTime.tm_min;
|
|
uint8_t am_pm = 0;
|
|
if (sql_setting_get_time_format() == 1) {
|
|
if (hour > 12) {
|
|
hour -= 12;
|
|
am_pm = 1;
|
|
} else if (hour == 0) {
|
|
hour = 12;
|
|
} else if (hour == 12) {
|
|
am_pm = 1;
|
|
}
|
|
}
|
|
|
|
hourHigh_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_TIME_NUM_0 + hour / 10 % 10, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
hourLow_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_TIME_NUM_0 + hour % 10, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
minHigh_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_TIME_NUM_0 + min / 10 % 10, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
minLow_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_TIME_NUM_0 + min % 10, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
|
|
uint8_t month = localTime.tm_mon; //获得当前的月份
|
|
uint8_t day = localTime.tm_mday; //获得当前的日期
|
|
uint8_t week = localTime.tm_wday; //获得当前是星期几
|
|
|
|
monthHigh_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_DATE_NUM_0 + month / 10 % 10, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
monthLow_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_DATE_NUM_0 + month % 10, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
dayHigh_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_DATE_NUM_0 + day / 10 % 10, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
dayLow_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_DATE_NUM_0 + day % 10, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
|
|
uint8_t lang = sql_setting_get_language(); //获得多语言的值
|
|
lang = (lang > 1) ? 1 : lang;
|
|
if (lang == 0) {
|
|
week_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_WEEK_EN_0 + week % 7, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
} else {
|
|
week_.SetSrc(images.LoadOneInMultiRes(IMG_MAIN_WF_WEEK_CH_0 + week % 7, IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
}
|
|
|
|
uint32_t imgList[2][2] = {{IMG_MAIN_WF_AM_EN, IMG_MAIN_WF_PM_EN}, {IMG_MAIN_WF_AM_CH, IMG_MAIN_WF_PM_CH}};
|
|
amPm_.SetSrc(images.LoadOneInMultiRes(imgList[lang][am_pm], IMAGE_WF_CUNSTOM_BIN_PATH));
|
|
if (sql_setting_get_time_format() == 0) {
|
|
amPm_.SetVisible(false);
|
|
} else {
|
|
amPm_.SetVisible(true);
|
|
}
|
|
}
|
|
|
|
void TjdUiWFPageCustom::ScrollBegin(bool isActive)
|
|
{
|
|
static_print_debug("TjdUiWFPageCustom::ScrollBegin");
|
|
TjdUiWfBase::ScrollBegin(isActive);
|
|
if (isActive) {
|
|
DoPause();
|
|
}
|
|
}
|
|
|
|
void TjdUiWFPageCustom::ScrollEnd(bool isActive)
|
|
{
|
|
static_print_debug("TjdUiWFPageCustom::ScrollEnd");
|
|
TjdUiWfBase::ScrollEnd(isActive);
|
|
|
|
TjdUiAppMainPresenter *mainPresenter = TjdUiAppMainPresenter::GetInstance();
|
|
if ((mainPresenter == nullptr) ||
|
|
(mainPresenter->GetMainPresenterState() != TjdUiAppMainPresenter::MainPresenterState::RESUME)) {
|
|
return;
|
|
}
|
|
if (isActive) {
|
|
DoStart();
|
|
} else {
|
|
if (video_ != nullptr && !video_->IsStopped()) {
|
|
video_->StopPlay();
|
|
}
|
|
if (video_ != nullptr) {
|
|
ClearCache();
|
|
}
|
|
}
|
|
}
|
|
|
|
void TjdUiWFPageCustom::CoverBegin(bool isCovered)
|
|
{
|
|
static_print_debug("TjdUiWFPageCustom::CoverBegin");
|
|
TjdUiWfBase::CoverBegin(isCovered);
|
|
if (!isCovered) {
|
|
DoPause();
|
|
}
|
|
}
|
|
|
|
void TjdUiWFPageCustom::CoverEnd(bool isCovered)
|
|
{
|
|
static_print_debug("TjdUiWFPageCustom::CoverEnd");
|
|
TjdUiWfBase::CoverEnd(isCovered);
|
|
TjdUiAppMainPresenter *mainPresenter = TjdUiAppMainPresenter::GetInstance();
|
|
if ((mainPresenter == nullptr) ||
|
|
(mainPresenter->GetMainPresenterState() != TjdUiAppMainPresenter::MainPresenterState::RESUME)) {
|
|
return;
|
|
}
|
|
if (!isCovered) {
|
|
DoStart();
|
|
}
|
|
}
|
|
|
|
void TjdUiWFPageCustom::OnActive(void)
|
|
{
|
|
static_print_debug("TjdUiWFPageCustom::OnActive");
|
|
TjdUiWfBase::OnActive();
|
|
TjdUiAppMainPresenter *mainPresenter = TjdUiAppMainPresenter::GetInstance();
|
|
if ((mainPresenter == nullptr) ||
|
|
(mainPresenter->GetMainPresenterState() != TjdUiAppMainPresenter::MainPresenterState::RESUME)) {
|
|
return;
|
|
}
|
|
DoStart();
|
|
}
|
|
|
|
void TjdUiWFPageCustom::OnInactive()
|
|
{
|
|
static_print_debug("TjdUiWFPageCustom::OnInactive");
|
|
TjdUiWfBase::OnInactive();
|
|
DoStop();
|
|
}
|
|
|
|
void TjdUiWFPageCustom::OnCovered(void)
|
|
{
|
|
TjdUiAppMainPresenter *mainPresenter = TjdUiAppMainPresenter::GetInstance();
|
|
if ((mainPresenter == nullptr) ||
|
|
(mainPresenter->GetMainPresenterState() != TjdUiAppMainPresenter::MainPresenterState::RESUME)) {
|
|
return;
|
|
}
|
|
DoPause();
|
|
}
|
|
|
|
void TjdUiWFPageCustom::OnUncovered(void)
|
|
{
|
|
TjdUiAppMainPresenter *mainPresenter = TjdUiAppMainPresenter::GetInstance();
|
|
if ((mainPresenter == nullptr) ||
|
|
(mainPresenter->GetMainPresenterState() != TjdUiAppMainPresenter::MainPresenterState::RESUME)) {
|
|
return;
|
|
}
|
|
DoStart();
|
|
}
|
|
|
|
void TjdUiWFPageCustom::OnPause(void) { DoPause(); }
|
|
|
|
void TjdUiWFPageCustom::OnResume(void) { DoStart(); }
|
|
|
|
void TjdUiWFPageCustom::DoStop(void)
|
|
{
|
|
if (video_ != nullptr && !video_->IsStopped()) {
|
|
video_->StopPlay();
|
|
}
|
|
}
|
|
|
|
void TjdUiWFPageCustom::DoStart(void)
|
|
{
|
|
if (video_ != nullptr) {
|
|
if (video_->IsPaused()) {
|
|
video_->ResumePlay();
|
|
} else if (!video_->IsPlayed()) {
|
|
video_->StartPlay();
|
|
}
|
|
}
|
|
}
|
|
|
|
void TjdUiWFPageCustom::DoPause(void)
|
|
{
|
|
if (video_ != nullptr) {
|
|
video_->PausePlay();
|
|
}
|
|
}
|
|
|
|
} // namespace TJD
|