327 lines
12 KiB
C++
327 lines
12 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
|
*
|
|
* Description:
|
|
*
|
|
* Author: huangshuyi
|
|
*
|
|
* Create: 2024-10
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
#include "TjdUiFootball1Page.h"
|
|
#include "rtc_api.h"
|
|
#include <time.h>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <cstring>
|
|
#include <iomanip>
|
|
#include "sys/time.h"
|
|
#include "graphic_service.h"
|
|
|
|
using namespace OHOS;
|
|
|
|
#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
|
|
|
|
|
|
namespace TJD {
|
|
static constexpr uint8_t PLANES_NUM = 20;
|
|
#define IMAGE_BIN_PATH TJD_IMAGE_PATH"img_football1.bin"
|
|
static TjdUiFootball1Page *g_pFootball1Page = nullptr;
|
|
|
|
TjdUiFootball1Page::~TjdUiFootball1Page()
|
|
{
|
|
static_print_debug("TjdUiFootball1Page::~TjdUiFootball1Page\n");
|
|
if (callback_ != nullptr) {
|
|
delete callback_;
|
|
callback_ = nullptr;
|
|
}
|
|
if (secondHand) {
|
|
delete secondHand;
|
|
secondHand = nullptr;
|
|
}
|
|
if (minuteHand) {
|
|
delete minuteHand;
|
|
minuteHand = nullptr;
|
|
}
|
|
if (hourHand) {
|
|
delete hourHand;
|
|
hourHand = nullptr;
|
|
}
|
|
if (dotHand) {
|
|
delete dotHand;
|
|
dotHand = nullptr;
|
|
}
|
|
if (timesClock_) {
|
|
delete timesClock_;
|
|
timesClock_ = nullptr;
|
|
}
|
|
g_pFootball1Page = nullptr;
|
|
ImageCacheManager::GetInstance().UnloadAllInMultiRes(IMAGE_BIN_PATH);
|
|
}
|
|
|
|
void TjdUiFootball1Page::EntryAnimatorCallback::Callback(UIView *view)
|
|
{
|
|
UIIcosahedronView* footView = dynamic_cast<UIIcosahedronView*>(view);
|
|
//int16_t el = EasingEquation::LinearEaseNone(startPos_, endPos_, animator_->GetRunTime(), animator_->GetTime());
|
|
//footView->SetSideLength(el);
|
|
//footView->RefreshIcosahedron();
|
|
const Vector3<float> rotateStart(Screen::GetInstance().GetWidth() / 2.0, // 2.0: divisor
|
|
Screen::GetInstance().GetHeight() / 2.0, 0); // 2.0: divisor
|
|
const Vector3<float> rotateEnd(0, 0, 0);
|
|
// 270 : stop angle
|
|
|
|
//int16_t angle = EasingEquation::LinearEaseNone(0, 270, animator_->GetRunTime(), animator_->GetTime());
|
|
static int16_t angle = 0;
|
|
angle += 1;
|
|
if (angle >= 360) {
|
|
angle = 0;
|
|
}
|
|
footView->RotatePlanes(angle, rotateStart, rotateEnd);
|
|
// printf("TjdUiFootball1Page::EntryAnimatorCallback::Callback, animator run time=%d, time=%d, el=%d, angle=%d\n",
|
|
// animator_->GetRunTime(), animator_->GetTime(), el, angle);
|
|
}
|
|
|
|
void TjdUiFootball1Page::Notify(void)
|
|
{
|
|
// 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 sec = localTime.tm_sec;
|
|
// mainSweepClock->SetTime24Hour(hour, min, sec);
|
|
// static constexpr int16_t SEC_TO_MILLI = 1000;
|
|
// static constexpr int16_t USEC_TO_MILLI = 1000;
|
|
// static constexpr int16_t MIN_TO_HOUR = 60;
|
|
// static constexpr int16_t HOURLY_SYSTEM = 24;
|
|
// static constexpr int16_t INTERVAL = 30;
|
|
// struct timeval tv;
|
|
// gettimeofday(&tv, nullptr);
|
|
// uint64_t second = static_cast<uint64_t>(tv.tv_sec);
|
|
// uint64_t uSecond = static_cast<uint64_t>(tv.tv_usec);
|
|
// uint64_t minute = second / MIN_TO_HOUR;
|
|
// uint64_t hour1 = minute / MIN_TO_HOUR;
|
|
// uint8_t realHour = static_cast<uint8_t>(hour1 % HOURLY_SYSTEM);
|
|
// uint8_t realMinute = static_cast<uint8_t>(minute % MIN_TO_HOUR);
|
|
// uint16_t realMilliSecond = static_cast<uint16_t>((second % MIN_TO_HOUR) *
|
|
// SEC_TO_MILLI + uSecond / USEC_TO_MILLI);
|
|
// //sweepClock->SetSweepTime12Hour(realHour, realMinute, realMilliSecond, 1);
|
|
|
|
// printf("TjdUiFootball1Page::Notify, hour=%d, min=%d, sec=%d\n", hour, min, sec);
|
|
// printf("TjdUiFootball1Page::Notify, realHour=%d, realMinute=%d, realMilliSecond=%d,second=%d\n", realHour, realMinute, realMilliSecond, second);
|
|
}
|
|
|
|
void TjdUiFootball1Page::UpdateClock(void)
|
|
{
|
|
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 sec = localTime.tm_sec;
|
|
|
|
static constexpr int16_t SEC_TO_MILLI = 1000;
|
|
static constexpr int16_t USEC_TO_MILLI = 1000;
|
|
static constexpr int16_t MIN_TO_HOUR = 60;
|
|
static constexpr int16_t HOURLY_SYSTEM = 24;
|
|
static constexpr int16_t INTERVAL = 30;
|
|
struct timeval tv;
|
|
gettimeofday(&tv, nullptr);
|
|
uint64_t second = static_cast<uint64_t>(tv.tv_sec);
|
|
uint64_t uSecond = static_cast<uint64_t>(tv.tv_usec);
|
|
uint64_t minute = second / MIN_TO_HOUR;
|
|
uint64_t hour1 = minute / MIN_TO_HOUR;
|
|
uint8_t realHour = static_cast<uint8_t>(hour1 % HOURLY_SYSTEM);
|
|
uint8_t realMinute = static_cast<uint8_t>(minute % MIN_TO_HOUR);
|
|
uint16_t realMilliSecond = static_cast<uint16_t>((second % MIN_TO_HOUR) *
|
|
SEC_TO_MILLI + uSecond / USEC_TO_MILLI);
|
|
//sweepClock->SetSweepTime12Hour(realHour, realMinute, realMilliSecond, 1);
|
|
|
|
// printf("TjdUiFootball1Page::Notify, hour=%d, min=%d, sec=%d\n", hour, min, sec);
|
|
// printf("TjdUiFootball1Page::Notify, realHour=%d, realMinute=%d, realMilliSecond=%d,second=%d\n", realHour, realMinute, realMilliSecond, second);
|
|
mainSweepClock->SetSweepTime24Hour(hour, min, realMilliSecond);
|
|
}
|
|
|
|
static void ClockTimerCallback(void *param)
|
|
{
|
|
GraphicService::GetInstance()->PostGraphicEvent([] {
|
|
if (g_pFootball1Page) {
|
|
g_pFootball1Page->UpdateClock();
|
|
}});
|
|
}
|
|
|
|
void TjdUiFootball1Page::InitClock(void)
|
|
{
|
|
mainSweepClock = new UISweepClock();
|
|
if (mainSweepClock == nullptr) {
|
|
GRAPHIC_LOGE("mainSweepClock new fail\n");
|
|
return;
|
|
}
|
|
mainSweepClock->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
|
|
mainSweepClock->SetWorkMode(UISweepClock::WorkMode::NORMAL);
|
|
mainSweepClock->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
|
|
mainSweepClock->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
|
|
|
|
secondHand = new Image();
|
|
if (secondHand == nullptr) {
|
|
GRAPHIC_LOGE("secondHand new fail\n");
|
|
return;
|
|
}
|
|
ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_FOOTBALL1_SECOND, IMAGE_BIN_PATH);
|
|
if (image == nullptr) {
|
|
return;
|
|
}
|
|
secondHand->SetSrc(image);
|
|
ImageHeader header;
|
|
secondHand->GetHeader(header);
|
|
int16_t centerx = header.width / 2;
|
|
int16_t centery = header.height - 15;
|
|
int16_t positionx = Screen::GetInstance().GetWidth() / 2 - centerx;
|
|
int16_t positiony = Screen::GetInstance().GetHeight() / 2 - centery;
|
|
mainSweepClock->SetHandImage(UISweepClock::HandType::SECOND_HAND, *secondHand,
|
|
{ positionx, positiony }, { centerx, centery});
|
|
|
|
minuteHand = new Image();
|
|
if (minuteHand == nullptr) {
|
|
GRAPHIC_LOGE("minuteHand new fail\n");
|
|
return;
|
|
}
|
|
image = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_FOOTBALL1_MINUTE, IMAGE_BIN_PATH);
|
|
if (image == nullptr) {
|
|
return;
|
|
}
|
|
minuteHand->SetSrc(image);
|
|
minuteHand->GetHeader(header);
|
|
centerx = header.width / 2;
|
|
centery = header.height - 8;
|
|
positionx = Screen::GetInstance().GetWidth() / 2 - centerx;
|
|
positiony = Screen::GetInstance().GetHeight() / 2 - centery;
|
|
mainSweepClock->SetHandImage(UISweepClock::HandType::MINUTE_HAND, *minuteHand,
|
|
{ positionx, positiony }, { centerx, centery});
|
|
|
|
hourHand = new Image();
|
|
if (hourHand == nullptr) {
|
|
GRAPHIC_LOGE("hourHand new fail\n");
|
|
return;
|
|
}
|
|
image = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_FOOTBALL1_HOUR, IMAGE_BIN_PATH);
|
|
if (image == nullptr) {
|
|
return;
|
|
}
|
|
hourHand->SetSrc(image);
|
|
hourHand->GetHeader(header);
|
|
centerx = header.width / 2;
|
|
centery = header.height - 8;
|
|
positionx = Screen::GetInstance().GetWidth() / 2 - centerx;
|
|
positiony = Screen::GetInstance().GetHeight() / 2 - centery;
|
|
mainSweepClock->SetHandImage(UISweepClock::HandType::HOUR_HAND, *hourHand,
|
|
{ positionx, positiony }, { centerx, centery});
|
|
|
|
dotHand = new Image();
|
|
if (dotHand == nullptr) {
|
|
GRAPHIC_LOGE("dotHand new fail\n");
|
|
return;
|
|
}
|
|
image = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_FOOTBALL1_DOT, IMAGE_BIN_PATH);
|
|
if (image == nullptr) {
|
|
return;
|
|
}
|
|
dotHand->SetSrc(image);
|
|
dotHand->GetHeader(header);
|
|
centerx = header.width / 2;
|
|
centery = header.height / 2;
|
|
positionx = Screen::GetInstance().GetWidth() / 2 - centerx;
|
|
positiony = Screen::GetInstance().GetHeight() / 2 - centery;
|
|
mainSweepClock->SetHandCircleImage(UISweepClock::HandType::SECOND_HAND, *dotHand,
|
|
{ positionx, positiony });
|
|
mainSweepClock->SetHandCircleImage(UISweepClock::HandType::MINUTE_HAND, *dotHand,
|
|
{ positionx, positiony });
|
|
mainSweepClock->SetHandCircleImage(UISweepClock::HandType::HOUR_HAND, *dotHand,
|
|
{ positionx, positiony });
|
|
|
|
mainSweepClock->SetInitTime24Hour(0, 0, 0);
|
|
parent_->Add(mainSweepClock);
|
|
if (timesClock_ == nullptr) {
|
|
timesClock_ = new OHOS::GraphicTimer(50, ClockTimerCallback, nullptr, true);
|
|
timesClock_->Start();
|
|
}
|
|
}
|
|
|
|
|
|
void TjdUiFootball1Page::PageInit(void)
|
|
{
|
|
g_pFootball1Page = this;
|
|
SetPeriod(50);
|
|
UIImageView *backGround = new UIImageView();
|
|
ImageInfo* imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_FOOTBALL1_BG, IMAGE_BIN_PATH);
|
|
parent_->Add(backGround);
|
|
backGround->SetPosition(0, 0);
|
|
backGround->SetSrc(imgInfo);
|
|
if (imgInfo_ == nullptr) {
|
|
imgInfo_ = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_FOOTBALL1_FOOTBALL_SIDE, IMAGE_BIN_PATH);
|
|
if (imgInfo_ == nullptr) {
|
|
return;
|
|
}
|
|
}
|
|
if (imgInverseInfo_ == nullptr) {
|
|
imgInverseInfo_ = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_FOOTBALL1_FOOTBALL_SIDE, IMAGE_BIN_PATH);
|
|
if (imgInverseInfo_ == nullptr) {
|
|
return;
|
|
}
|
|
}
|
|
if (container_ == nullptr) {
|
|
container_ = new FootballUIIcosahedronView();
|
|
container_->SetViewId("football1");
|
|
parent_->Add(container_);
|
|
//container_->SetIntercept(true);
|
|
// container_->SetOpaScale(OPA_TRANSPARENT);
|
|
container_->SetStyle(STYLE_BACKGROUND_OPA, 0);
|
|
container_->SetDefaultImage(imgInfo_);
|
|
container_->SetSwipeACCLevel(200); // 0-255
|
|
container_->SetDragACCLevel(8); // 5: drag acceleration
|
|
//container_->SetLuminanceFactor(10000);
|
|
// container_->EnabelLightAndDrak(false);
|
|
container_->SetThrowDrag(true);
|
|
int cycle_r = Screen::GetInstance().GetWidth() / 2;
|
|
container_->SetPosition(0, 0, cycle_r * 2, cycle_r * 2);
|
|
|
|
if (callback_ == nullptr) {
|
|
callback_ = new EntryAnimatorCallback(container_, 20, 140); // 30: Initial Size 200: Final display size
|
|
}
|
|
enterAnimator_ = callback_->GetAnimator();
|
|
//uint16_t len = std::sqrt(Screen::GetInstance().GetWidth()*Screen::GetInstance().GetWidth()*2) / 4; // 2: divisor
|
|
container_->SetSideLength(160);
|
|
container_->RefreshIcosahedron();
|
|
|
|
int16_t cycle_recy_x = cycle_r - 145;
|
|
int16_t cycle_recy_y = cycle_r - 145;
|
|
int16_t cycle_recy_len = 145*2;
|
|
Rect footballRect(cycle_recy_x, cycle_recy_y, cycle_recy_x + cycle_recy_len, cycle_recy_y + cycle_recy_len);
|
|
container_->footballRect_ = footballRect;
|
|
// UIViewGroup*temp = new UIViewGroup();
|
|
// temp->SetPosition(cycle_recy_x, cycle_recy_y, cycle_recy_len, cycle_recy_len);
|
|
// temp->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full);
|
|
// temp->SetStyle(STYLE_BACKGROUND_OPA, 100);
|
|
//parent_->Add(temp);
|
|
enterAnimator_->Start();
|
|
}
|
|
InitClock();
|
|
}
|
|
|
|
TjdUiFootball1Page* TjdUiFootball1PageCreate(UIViewGroup*& parent)
|
|
{
|
|
return new TjdUiFootball1Page(parent);
|
|
}
|
|
} // namespace TJD
|