272 lines
11 KiB
C++
272 lines
11 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
|
*
|
|
* Description:
|
|
*
|
|
* Author: huangshuyi
|
|
*
|
|
* Create: 2024-9
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
#include "TjdUiFootballPage.h"
|
|
#include "rtc_api.h"
|
|
#include <time.h>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <cstring>
|
|
#include <iomanip>
|
|
|
|
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_football.bin"
|
|
static const char* week_ch[] = {"周日", "周一", "周二", "周三", "周四", "周五", "周六"};
|
|
static const char* week_en[] = {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"};
|
|
|
|
TjdUiFootballPage::~TjdUiFootballPage()
|
|
{
|
|
static_print_debug("TjdUiFootballPage::~TjdUiFootballPage\n");
|
|
if (callback_ != nullptr) {
|
|
delete callback_;
|
|
callback_ = nullptr;
|
|
}
|
|
ImageCacheManager::GetInstance().UnloadAllInMultiRes(IMAGE_BIN_PATH);
|
|
}
|
|
|
|
void TjdUiFootballPage::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());
|
|
footView->RotatePlanes(angle, rotateStart, rotateEnd);
|
|
// printf("TjdUiFootballPage::EntryAnimatorCallback::Callback, animator run time=%d, time=%d, el=%d, angle=%d\n",
|
|
// animator_->GetRunTime(), animator_->GetTime(), el, angle);
|
|
}
|
|
|
|
void TjdUiFootballPage::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 month = localTime.tm_mon;//获得当前的月份
|
|
uint8_t day = localTime.tm_mday;//获得当前的日期
|
|
uint8_t weekIndex = localTime.tm_wday;//获得当前是星期几
|
|
std::string result;
|
|
std::ostringstream oss;
|
|
static uint8_t flag = 0;
|
|
if (labelDiv_) {
|
|
if (flag) {
|
|
labelDiv_->SetVisible(true);
|
|
} else {
|
|
labelDiv_->SetVisible(false);
|
|
}
|
|
flag = !flag;
|
|
}
|
|
|
|
if (labelTimeH_ != nullptr) {
|
|
oss.str("");
|
|
oss << std::setw(2) << std::setfill('0') << static_cast<int>(hour);
|
|
result = oss.str();
|
|
labelTimeH_->SetText(result.c_str());
|
|
}
|
|
if (labelTimeM_ != nullptr) {
|
|
oss.str("");
|
|
oss << std::setw(2) << std::setfill('0') << static_cast<int>(min);
|
|
result = oss.str();
|
|
labelTimeM_->SetText(result.c_str());
|
|
}
|
|
|
|
oss.str("");
|
|
oss << std::setw(2) << std::setfill('0') << static_cast<int>(month) << '/'
|
|
<< std::setw(2) << std::setfill('0') << static_cast<int>(day);
|
|
result = oss.str();
|
|
if (labelDate_ != nullptr) {
|
|
labelDate_->SetText(result.c_str());
|
|
}
|
|
|
|
const char* weekStr = nullptr;
|
|
TjdUiLanguageId language = TjdUiMultiLanguageExt::GetCurrentLanguage();
|
|
if (language == LANGUAGE_ID_CHS) {
|
|
weekStr = week_ch[weekIndex];
|
|
} else {
|
|
weekStr = week_en[weekIndex];
|
|
}
|
|
if (labelWeek_ != nullptr) {
|
|
labelWeek_->SetText(weekStr);
|
|
}
|
|
}
|
|
|
|
void TjdUiFootballPage::PageInit(void)
|
|
{
|
|
SetPeriod(1000);
|
|
UIImageView *backGround = new UIImageView();
|
|
ImageInfo* imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_FOOTBALL_BG, IMAGE_BIN_PATH);
|
|
parent_->Add(backGround);
|
|
backGround->SetPosition(0, 0);
|
|
backGround->SetSrc(imgInfo);
|
|
if (imgInfo_ == nullptr) {
|
|
imgInfo_ = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_FOOTBALL_FOOTBALL, IMAGE_BIN_PATH);
|
|
if (imgInfo_ == nullptr) {
|
|
return;
|
|
}
|
|
}
|
|
if (imgInverseInfo_ == nullptr) {
|
|
imgInverseInfo_ = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_FOOTBALL_FOOTBALL, IMAGE_BIN_PATH);
|
|
if (imgInverseInfo_ == nullptr) {
|
|
return;
|
|
}
|
|
}
|
|
if (container_ == nullptr) {
|
|
container_ = new FootballUIIcosahedronView();
|
|
container_->SetViewId("football");
|
|
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 + Screen::GetInstance().GetWidth() / 4 - 50;
|
|
container_->SetPosition(0, 0, cycle_r * 2, cycle_r * 2);
|
|
// for (uint8_t i = 0; i < 1; i++) {
|
|
// UIImageView* view = new UIImageView();
|
|
// view->SetTouchable(true);
|
|
// view->SetOnClickListener(this);
|
|
// view->SetSrc(imgInfo_);
|
|
// container_->Add(view);
|
|
// }
|
|
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(140);
|
|
// container_->RefreshIcosahedron();
|
|
|
|
int16_t cycle_recy_x = cycle_r - 125;
|
|
int16_t cycle_recy_y = cycle_r - 125;
|
|
int16_t cycle_recy_len = 125*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();
|
|
|
|
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 month = localTime.tm_mon;//获得当前的月份
|
|
uint8_t day = localTime.tm_mday;//获得当前的日期
|
|
uint8_t weekIndex = localTime.tm_wday;//获得当前是星期几
|
|
|
|
UIViewGroup *timeGroup = new UIViewGroup();
|
|
parent_->Add(timeGroup);
|
|
timeGroup->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
|
|
timeGroup->SetViewId("timeGroup");
|
|
timeGroup->SetAutoSize(true);
|
|
|
|
std::string result;
|
|
std::ostringstream oss;
|
|
oss.str("");
|
|
oss << std::setw(2) << std::setfill('0') << static_cast<int>(hour);
|
|
result = oss.str();
|
|
labelTimeH_ = new UILabel();
|
|
timeGroup->Add(labelTimeH_);
|
|
labelTimeH_->SetViewId("labelTimeH_");
|
|
labelTimeH_->SetText(result.c_str());
|
|
labelTimeH_->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_76);
|
|
labelTimeH_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
|
labelTimeH_->SetX(0);
|
|
labelTimeH_->SetY(0);
|
|
|
|
labelDiv_ = new UILabel();
|
|
timeGroup->Add(labelDiv_);
|
|
labelDiv_->SetViewId("labelDiv_");
|
|
labelDiv_->SetText(":");
|
|
labelDiv_->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_76);
|
|
labelDiv_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
|
labelDiv_->LayoutRightToSibling(labelTimeH_->GetViewId(), 0);
|
|
labelDiv_->SetY(0);
|
|
|
|
oss.str("");
|
|
oss << std::setw(2) << std::setfill('0') << static_cast<int>(min);
|
|
result = oss.str();
|
|
labelTimeM_ = new UILabel();
|
|
timeGroup->Add(labelTimeM_);
|
|
labelTimeM_->SetViewId("labelTimeM_");
|
|
labelTimeM_->SetText(result.c_str());
|
|
labelTimeM_->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_76);
|
|
labelTimeM_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
|
labelTimeM_->LayoutRightToSibling(labelDiv_->GetViewId(), 0);
|
|
labelTimeM_->SetY(0);
|
|
timeGroup->Remove(labelTimeM_);
|
|
timeGroup->Add(labelTimeM_);
|
|
timeGroup->LayoutCenterOfParent();
|
|
timeGroup->SetY(36);
|
|
|
|
oss.str("");
|
|
oss << std::setw(2) << std::setfill('0') << static_cast<int>(month) << '/'
|
|
<< std::setw(2) << std::setfill('0') << static_cast<int>(day);
|
|
result = oss.str();
|
|
labelDate_ = new UILabel();
|
|
parent_->Add(labelDate_);
|
|
labelDate_->SetText(result.c_str());
|
|
labelDate_->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_28);
|
|
labelDate_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
|
labelDate_->LayoutBottomToSibling(timeGroup->GetViewId(), -15);
|
|
labelDate_->AlignLeftToSibling(timeGroup->GetViewId(), 15);
|
|
|
|
const char* weekStr = nullptr;
|
|
TjdUiLanguageId language = TjdUiMultiLanguageExt::GetCurrentLanguage();
|
|
if (language == LANGUAGE_ID_CHS) {
|
|
weekStr = week_ch[weekIndex];
|
|
} else {
|
|
weekStr = week_en[weekIndex];
|
|
}
|
|
labelWeek_ = new UILabel();
|
|
parent_->Add(labelWeek_);
|
|
labelWeek_->SetText(weekStr);
|
|
labelWeek_->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_28);
|
|
labelWeek_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
|
|
labelWeek_->LayoutBottomToSibling(timeGroup->GetViewId(), -15);
|
|
labelWeek_->AlignRightToSibling(timeGroup->GetViewId(), 15);
|
|
}
|
|
}
|
|
|
|
TjdUiFootballPage* TjdUiFootballPageCreate(UIViewGroup*& parent)
|
|
{
|
|
return new TjdUiFootballPage(parent);
|
|
}
|
|
} // namespace TJD
|