403 lines
14 KiB
C++
403 lines
14 KiB
C++
/*----------------------------------------------------------------------------
|
|
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
|
|
*
|
|
* Description:
|
|
*
|
|
* Author: wuchangxin
|
|
*
|
|
* Create: 2024-6-17
|
|
*--------------------------------------------------------------------------*/
|
|
|
|
#include "TjdUiAppMainPageFourLeafClover.h"
|
|
#include "TjdUiAppLuckyCloverModel.h"
|
|
#include "TjdUiImageIds.h"
|
|
#include "TjdUiMultiLanguageExt.h"
|
|
#include "common/image_cache_manager.h"
|
|
#include "gfx_utils/mem_check.h"
|
|
#include "sys_config.h"
|
|
#include <iomanip>
|
|
#include <sstream>
|
|
|
|
#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 {
|
|
|
|
#define MAIN_FOUR_LEAF_CLOVER_IMAGE_BIN_PATH TJD_IMAGE_PATH "img_main_flc.bin"
|
|
|
|
static TjdUiAppMainPageFourLeafClover *g_fourLeafCloverPage = nullptr;
|
|
|
|
TjdUiAppMainPageFourLeafClover::TjdUiAppMainPageFourLeafClover()
|
|
{
|
|
SetPosition(0, 0, OHOS::Screen::GetInstance().GetWidth(), OHOS::Screen::GetInstance().GetHeight());
|
|
g_fourLeafCloverPage = this;
|
|
}
|
|
|
|
TjdUiAppMainPageFourLeafClover::~TjdUiAppMainPageFourLeafClover()
|
|
{
|
|
UnLoad();
|
|
g_fourLeafCloverPage = nullptr;
|
|
}
|
|
|
|
TjdUiAppMainPageFourLeafClover *TjdUiAppMainPageFourLeafClover::GetInstance(void) { return g_fourLeafCloverPage; }
|
|
|
|
void TjdUiAppMainPageFourLeafClover::PreLoad(void)
|
|
{
|
|
static_print_debug("TjdUiAppMainPageFourLeafClover::PreLoad");
|
|
// OHOS::MemCheck::GetInstance()->EnableLeakCheck(true);
|
|
if (!viewiInitStatus) {
|
|
OHOS::ImageCacheManager::GetInstance().LoadAllInMultiRes(MAIN_FOUR_LEAF_CLOVER_IMAGE_BIN_PATH);
|
|
InitView();
|
|
UpdateValue();
|
|
viewiInitStatus = true;
|
|
}
|
|
}
|
|
|
|
void TjdUiAppMainPageFourLeafClover::UnLoad(void)
|
|
{
|
|
static_print_debug("TjdUiAppMainPageFourLeafClover::UnLoad");
|
|
if (viewiInitStatus) {
|
|
OHOS::ImageCacheManager::GetInstance().UnloadAllInMultiRes(MAIN_FOUR_LEAF_CLOVER_IMAGE_BIN_PATH);
|
|
RemoveAll();
|
|
if (container_) {
|
|
container_->RemoveAll();
|
|
delete container_;
|
|
container_ = nullptr;
|
|
}
|
|
if (standBg_) {
|
|
delete standBg_;
|
|
standBg_ = nullptr;
|
|
}
|
|
if (standFull_) {
|
|
delete standFull_;
|
|
standFull_ = nullptr;
|
|
}
|
|
if (standIocn_) {
|
|
delete standIocn_;
|
|
standIocn_ = nullptr;
|
|
}
|
|
if (standProgress_) {
|
|
delete standProgress_;
|
|
standProgress_ = nullptr;
|
|
}
|
|
if (standArcLabel_) {
|
|
delete standArcLabel_;
|
|
standArcLabel_ = nullptr;
|
|
}
|
|
if (kcalBg_) {
|
|
delete kcalBg_;
|
|
kcalBg_ = nullptr;
|
|
}
|
|
if (kcalFull_) {
|
|
delete kcalFull_;
|
|
kcalFull_ = nullptr;
|
|
}
|
|
if (kcalIocn_) {
|
|
delete kcalIocn_;
|
|
kcalIocn_ = nullptr;
|
|
}
|
|
if (kcalProgress_) {
|
|
delete kcalProgress_;
|
|
kcalProgress_ = nullptr;
|
|
}
|
|
if (kcalArcLabel_) {
|
|
delete kcalArcLabel_;
|
|
kcalArcLabel_ = nullptr;
|
|
}
|
|
if (strengthBg_) {
|
|
delete strengthBg_;
|
|
strengthBg_ = nullptr;
|
|
}
|
|
if (strengthFull_) {
|
|
delete strengthFull_;
|
|
strengthFull_ = nullptr;
|
|
}
|
|
if (strengthIocn_) {
|
|
delete strengthIocn_;
|
|
strengthIocn_ = nullptr;
|
|
}
|
|
if (strengthProgress_) {
|
|
delete strengthProgress_;
|
|
strengthProgress_ = nullptr;
|
|
}
|
|
if (strengthArcLabel_) {
|
|
delete strengthArcLabel_;
|
|
strengthArcLabel_ = nullptr;
|
|
}
|
|
if (stepBg_) {
|
|
delete stepBg_;
|
|
stepBg_ = nullptr;
|
|
}
|
|
if (stepFull_) {
|
|
delete stepFull_;
|
|
stepFull_ = nullptr;
|
|
}
|
|
if (stepIocn_) {
|
|
delete stepIocn_;
|
|
stepIocn_ = nullptr;
|
|
}
|
|
if (stepProgress_) {
|
|
delete stepProgress_;
|
|
stepProgress_ = nullptr;
|
|
}
|
|
if (stepArcLabel_) {
|
|
delete stepArcLabel_;
|
|
stepArcLabel_ = nullptr;
|
|
}
|
|
|
|
viewiInitStatus = false;
|
|
}
|
|
}
|
|
|
|
void TjdUiAppMainPageFourLeafClover::NotifyTick(void) {}
|
|
|
|
static inline void InitArcComponent(OHOS::UICircleProgress *circleProgress, OHOS::UIArcLabel *arcLabel, int startAngle,
|
|
int endAngle, uint32_t colorFull)
|
|
{
|
|
if (circleProgress == nullptr || arcLabel == nullptr) {
|
|
return;
|
|
}
|
|
auto screenWidth = OHOS::Screen::GetInstance().GetWidth();
|
|
auto screenHeight = OHOS::Screen::GetInstance().GetHeight();
|
|
OHOS::ColorType color = {};
|
|
color.full = colorFull;
|
|
circleProgress->SetPosition(0, 0, screenWidth, screenHeight);
|
|
circleProgress->SetCenterPosition(screenWidth / 2, screenHeight / 2);
|
|
circleProgress->SetRadius((screenWidth >> 1) - 13);
|
|
circleProgress->SetBackgroundStyle(OHOS::STYLE_LINE_WIDTH, 6);
|
|
circleProgress->SetForegroundStyle(OHOS::STYLE_LINE_WIDTH, 6);
|
|
circleProgress->SetStartAngle(startAngle);
|
|
circleProgress->SetEndAngle(endAngle);
|
|
circleProgress->SetLineColor(color);
|
|
circleProgress->SetCapType(OHOS::CapType::CAP_ROUND);
|
|
|
|
arcLabel->SetPosition(0, 0, screenWidth, screenHeight);
|
|
arcLabel->SetArcTextCenter(screenWidth / 2, screenHeight / 2);
|
|
arcLabel->SetArcTextRadius((screenWidth >> 1) - 26);
|
|
arcLabel->SetArcTextAngle(startAngle, endAngle);
|
|
arcLabel->SetText("-");
|
|
if (endAngle > 90 && endAngle < 270) {
|
|
arcLabel->SetArcTextOrientation(OHOS::UIArcLabel::TextOrientation::OUTSIDE);
|
|
} else {
|
|
arcLabel->SetArcTextOrientation(OHOS::UIArcLabel::TextOrientation::INSIDE);
|
|
}
|
|
arcLabel->SetFont(TJD_D_DIN_PRO_MEDIUM_FONT_FILENAME, 22);
|
|
arcLabel->SetStyle(OHOS::STYLE_TEXT_COLOR, 0xFF6D6D6D);
|
|
arcLabel->SetAlign(OHOS::UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER);
|
|
}
|
|
|
|
void TjdUiAppMainPageFourLeafClover::InitView(void)
|
|
{
|
|
auto &image = OHOS::ImageCacheManager::GetInstance();
|
|
|
|
container_ = new UIViewGroup();
|
|
container_->SetPosition(0, 0, OHOS::Screen::GetInstance().GetWidth(), OHOS::Screen::GetInstance().GetHeight());
|
|
|
|
standBg_ = new OHOS::UIImageView();
|
|
standBg_->SetPosition(74, 74, 157, 157);
|
|
standBg_->SetSrc(image.LoadOneInMultiRes(IMG_MAIN_FLC_BG_01_01, MAIN_FOUR_LEAF_CLOVER_IMAGE_BIN_PATH));
|
|
container_->Add(standBg_);
|
|
|
|
standFull_ = new OHOS::UIImageView();
|
|
standFull_->SetPosition(74, 74, 157, 157);
|
|
standFull_->SetSrc(image.LoadOneInMultiRes(IMG_MAIN_FLC_BG_01, MAIN_FOUR_LEAF_CLOVER_IMAGE_BIN_PATH));
|
|
container_->Add(standFull_);
|
|
|
|
standIocn_ = new OHOS::UIImageView();
|
|
standIocn_->SetPosition(166, 166, 59, 59);
|
|
standIocn_->SetSrc(image.LoadOneInMultiRes(IMG_MAIN_FLC_STAND, MAIN_FOUR_LEAF_CLOVER_IMAGE_BIN_PATH));
|
|
container_->Add(standIocn_);
|
|
|
|
standProgress_ = new OHOS::UICircleProgress();
|
|
standArcLabel_ = new OHOS::UIArcLabel();
|
|
InitArcComponent(standProgress_, standArcLabel_, 290, 350, 0xFF00C95D);
|
|
container_->Add(standProgress_);
|
|
container_->Add(standArcLabel_);
|
|
|
|
kcalBg_ = new OHOS::UIImageView();
|
|
kcalBg_->SetPosition(235, 74, 157, 157);
|
|
kcalBg_->SetSrc(image.LoadOneInMultiRes(IMG_MAIN_FLC_BG_02_01, MAIN_FOUR_LEAF_CLOVER_IMAGE_BIN_PATH));
|
|
container_->Add(kcalBg_);
|
|
|
|
kcalFull_ = new OHOS::UIImageView();
|
|
kcalFull_->SetPosition(235, 74, 157, 157);
|
|
kcalFull_->SetSrc(image.LoadOneInMultiRes(IMG_MAIN_FLC_BG_02, MAIN_FOUR_LEAF_CLOVER_IMAGE_BIN_PATH));
|
|
container_->Add(kcalFull_);
|
|
|
|
kcalIocn_ = new OHOS::UIImageView();
|
|
kcalIocn_->SetPosition(242, 166, 59, 59);
|
|
kcalIocn_->SetSrc(image.LoadOneInMultiRes(IMG_MAIN_FLC_KCAL, MAIN_FOUR_LEAF_CLOVER_IMAGE_BIN_PATH));
|
|
container_->Add(kcalIocn_);
|
|
|
|
kcalProgress_ = new OHOS::UICircleProgress();
|
|
kcalArcLabel_ = new OHOS::UIArcLabel();
|
|
InitArcComponent(kcalProgress_, kcalArcLabel_, 20, 80, 0xFFFF9823);
|
|
container_->Add(kcalProgress_);
|
|
container_->Add(kcalArcLabel_);
|
|
|
|
strengthBg_ = new OHOS::UIImageView();
|
|
strengthBg_->SetPosition(74, 235, 157, 157);
|
|
strengthBg_->SetSrc(image.LoadOneInMultiRes(IMG_MAIN_FLC_BG_03_01, MAIN_FOUR_LEAF_CLOVER_IMAGE_BIN_PATH));
|
|
container_->Add(strengthBg_);
|
|
|
|
strengthFull_ = new OHOS::UIImageView();
|
|
strengthFull_->SetPosition(74, 235, 157, 157);
|
|
strengthFull_->SetSrc(image.LoadOneInMultiRes(IMG_MAIN_FLC_BG_03, MAIN_FOUR_LEAF_CLOVER_IMAGE_BIN_PATH));
|
|
container_->Add(strengthFull_);
|
|
|
|
strengthIocn_ = new OHOS::UIImageView();
|
|
strengthIocn_->SetPosition(166, 242, 59, 59);
|
|
strengthIocn_->SetSrc(image.LoadOneInMultiRes(IMG_MAIN_FLC_STRENGTH, MAIN_FOUR_LEAF_CLOVER_IMAGE_BIN_PATH));
|
|
container_->Add(strengthIocn_);
|
|
|
|
strengthProgress_ = new OHOS::UICircleProgress();
|
|
strengthArcLabel_ = new OHOS::UIArcLabel();
|
|
InitArcComponent(strengthProgress_, strengthArcLabel_, 200, 260, 0xFF2E82FF);
|
|
container_->Add(strengthProgress_);
|
|
container_->Add(strengthArcLabel_);
|
|
|
|
stepBg_ = new OHOS::UIImageView();
|
|
stepBg_->SetPosition(235, 235, 157, 157);
|
|
stepBg_->SetSrc(image.LoadOneInMultiRes(IMG_MAIN_FLC_BG_04_01, MAIN_FOUR_LEAF_CLOVER_IMAGE_BIN_PATH));
|
|
container_->Add(stepBg_);
|
|
|
|
stepFull_ = new OHOS::UIImageView();
|
|
stepFull_->SetPosition(235, 235, 157, 157);
|
|
stepFull_->SetSrc(image.LoadOneInMultiRes(IMG_MAIN_FLC_BG_04, MAIN_FOUR_LEAF_CLOVER_IMAGE_BIN_PATH));
|
|
container_->Add(stepFull_);
|
|
|
|
stepIocn_ = new OHOS::UIImageView();
|
|
stepIocn_->SetPosition(242, 242, 59, 59);
|
|
stepIocn_->SetSrc(image.LoadOneInMultiRes(IMG_MAIN_FLC_STEP, MAIN_FOUR_LEAF_CLOVER_IMAGE_BIN_PATH));
|
|
container_->Add(stepIocn_);
|
|
|
|
stepProgress_ = new OHOS::UICircleProgress();
|
|
stepArcLabel_ = new OHOS::UIArcLabel();
|
|
InitArcComponent(stepProgress_, stepArcLabel_, 110, 170, 0xFFFF4D3A);
|
|
container_->Add(stepProgress_);
|
|
container_->Add(stepArcLabel_);
|
|
|
|
Add(container_);
|
|
}
|
|
|
|
enum class FourLeafClover
|
|
{
|
|
STAND = 0,
|
|
KCAL,
|
|
STRENGTH,
|
|
STEP,
|
|
};
|
|
|
|
static void FourLeafCloverScale(OHOS::UIView *view, int32_t curValue, int32_t tarValue, FourLeafClover index)
|
|
{
|
|
if (view == nullptr) {
|
|
return;
|
|
}
|
|
const int16_t curWidth = view->GetWidth();
|
|
const int16_t curHeight = view->GetHeight();
|
|
float sizeScale = (float)curValue / (float)tarValue;
|
|
const OHOS::Vector2<float> &scale = {sizeScale, sizeScale};
|
|
OHOS::Vector2<float> pivot = {};
|
|
// clang-format off
|
|
switch (index) {
|
|
case FourLeafClover::STAND: pivot.x_ = curWidth; pivot.y_ = curHeight;break;
|
|
case FourLeafClover::KCAL: pivot.x_ = 0; pivot.y_ = curHeight;break;
|
|
case FourLeafClover::STRENGTH: pivot.x_ = curWidth; pivot.y_ = 0;break;
|
|
case FourLeafClover::STEP: pivot.x_ = 0; pivot.y_ = 0;break;
|
|
}
|
|
// clang-format on
|
|
view->Scale(scale, pivot);
|
|
view->Invalidate();
|
|
}
|
|
|
|
void TjdUiAppMainPageFourLeafClover::UpdateValue(void)
|
|
{
|
|
std::stringstream ss;
|
|
const lucky_clover_t data = TjdUiAppLuckyCloverModel::GetInstance()->get_lucky_clover_info();
|
|
|
|
/* 转换数据类型 */
|
|
const int stand = data.currentStandNum;
|
|
const int kcal = data.currentCalorieNum;
|
|
const int strength = data.currentStrengthTime;
|
|
const int step = data.currentStepNum;
|
|
const int targetStand = data.goalStandNum;
|
|
const int targetKcal = data.goalCalorieNum;
|
|
const int targetStrength = data.goalStrengthTime;
|
|
const int targetStep = data.goalStepNum;
|
|
|
|
FourLeafCloverScale(standFull_, stand, targetStand, FourLeafClover::STAND);
|
|
FourLeafCloverScale(kcalFull_, kcal, targetKcal, FourLeafClover::KCAL);
|
|
FourLeafCloverScale(strengthFull_, strength, targetStrength, FourLeafClover::STRENGTH);
|
|
FourLeafCloverScale(stepFull_, step, targetStep, FourLeafClover::STEP);
|
|
|
|
if (standProgress_) {
|
|
standProgress_->SetRange(targetStand, 0);
|
|
standProgress_->SetValue(stand);
|
|
}
|
|
if (kcalProgress_) {
|
|
kcalProgress_->SetRange(targetKcal, 0);
|
|
kcalProgress_->SetValue(kcal);
|
|
}
|
|
if (strengthProgress_) {
|
|
strengthProgress_->SetRange(targetStrength, 0);
|
|
strengthProgress_->SetValue(strength);
|
|
}
|
|
if (stepProgress_) {
|
|
stepProgress_->SetRange(targetStep, 0);
|
|
stepProgress_->SetValue(step);
|
|
}
|
|
|
|
if (standArcLabel_) {
|
|
ss.str("");
|
|
if (stand == 0) {
|
|
ss << "0 STAND";
|
|
} else {
|
|
ss << stand << " STANDS";
|
|
}
|
|
standArcLabel_->SetText(ss.str().c_str());
|
|
}
|
|
if (kcalArcLabel_) {
|
|
ss.str("");
|
|
if (kcal == 0) {
|
|
ss << "0 KCAL";
|
|
} else {
|
|
ss << kcal << " KCAL";
|
|
}
|
|
kcalArcLabel_->SetText(ss.str().c_str());
|
|
}
|
|
if (strengthArcLabel_) {
|
|
ss.str("");
|
|
if (strength == 0) {
|
|
ss << "0 MIN";
|
|
} else {
|
|
ss << strength << " MIN";
|
|
}
|
|
std::string reverseStr = ss.str();
|
|
reverse(reverseStr.begin(), reverseStr.end());
|
|
strengthArcLabel_->SetText(reverseStr.c_str());
|
|
}
|
|
if (stepArcLabel_) {
|
|
ss.str("");
|
|
if (step == 0) {
|
|
ss << "0 STEPS";
|
|
} else {
|
|
ss << step << " STEPS";
|
|
}
|
|
std::string reverseStr = ss.str();
|
|
reverse(reverseStr.begin(), reverseStr.end());
|
|
stepArcLabel_->SetText(reverseStr.c_str());
|
|
}
|
|
}
|
|
|
|
} // namespace TJD
|