mcu_hi3321_watch/tjd/ui/app/stress/TjdUiAppStressView.cpp
2025-05-26 20:15:20 +08:00

712 lines
27 KiB
C++
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*----------------------------------------------------------------------------
* Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved.
*
* Description:
*
* Author: wuchangxin
*
* Create: 2024-6-27
*--------------------------------------------------------------------------*/
#include "TjdUiAppStressView.h"
#include "TjdUiAppStressModel.h"
#include "TjdUiImageIds.h"
#include "TjdUiMemManage.h"
#include "TjdUiMultiLanguageExt.h"
#include "TjdUiUtils.h"
#include "common/image_cache_manager.h"
#include "rtc_api.h"
#include "sys_config.h"
#include "wearable_log.h"
#include <cmath>
#include <iostream>
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__) // 错误信息打印一般常开
#else
#define static_print_info(...)
#define static_print_warn(...)
#define static_print_error(...)
#endif
namespace TJD {
#define STRESS_IMAGE_BIN_PATH TJD_IMAGE_PATH "img_stress.bin"
static TjdUiAppStressView *g_pv_AppStressView = nullptr;
TjdUiAppStressView::TjdUiAppStressView() { g_pv_AppStressView = this; }
TjdUiAppStressView::~TjdUiAppStressView()
{
RemoveAll();
g_pv_AppStressView = nullptr;
if (swipeContainer_ != nullptr) {
swipeContainer_->ClearFocus();
}
if (dataSerial_ != nullptr) {
delete dataSerial_;
dataSerial_ = nullptr;
}
if (uiChart1_ != nullptr) {
stressContainer_->Remove(uiChart1_);
delete uiChart1_;
uiChart1_ = nullptr;
}
if (swipeContainer_ != nullptr) {
swipeContainer_->RemoveAll();
delete swipeContainer_;
swipeContainer_ = nullptr;
}
ImageCacheManager::GetInstance().UnloadAllInMultiRes(STRESS_IMAGE_BIN_PATH);
TjdUiMemManage::DeleteChildren(stressContainer_);
TjdUiMemManage::DeleteChildren(dataContainer_);
}
TjdUiAppStressView *TjdUiAppStressView::GetInstance(void) { return g_pv_AppStressView; }
void TjdUiAppStressView::OnStart()
{
OHOS::FocusManager::GetInstance()->ClearFocus();
TjdUiAppStressModel::GetInstance()->StressPointArrayInit();
if (onSwipeListener_ == nullptr) {
onSwipeListener_ = static_cast<UISwipeView::OnSwipeListener *>(TjdUiAppStressPresenter::GetInstance());
}
if (OnDragListener_ == nullptr) {
OnDragListener_ = static_cast<UIView::OnDragListener *>(TjdUiAppStressPresenter::GetInstance());
}
if (swipeContainer_ == nullptr) {
swipeContainer_ = new UISwipeViewNested(UISwipeView::VERTICAL);
swipeContainer_->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
swipeContainer_->SetViewId("swipeContainer_");
swipeContainer_->SetStyle(STYLE_BACKGROUND_OPA, 0);
swipeContainer_->SetOnSwipeListener(onSwipeListener_);
if (OHOS::PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) {
swipeContainer_->SetOnDragListener(OnDragListener_);
}
swipeContainer_->RequestFocus();
}
StressMainViewInit();
StressDataViewInit();
StressProgressUpdate();
StressDataUpdate();
AddViewToRootContainer(swipeContainer_);
}
void TjdUiAppStressView::OnStop() {}
void TjdUiAppStressView::StressMainViewInit(void)
{
/*-----------------------------Add stressContainer_ to App------------------------------*/
// static_print_info("MainViewInit");
if (stressContainer_ == nullptr) {
stressContainer_ = new UIViewGroup();
stressContainer_->SetPosition(0, 0, 466, 466);
stressContainer_->SetStyle(STYLE_BACKGROUND_OPA, 0);
}
/*-----------------------------Add labelTitle to App------------------------------*/
if (labelTitle == nullptr) {
labelTitle = new UILabelExt();
}
labelTitle->SetPosition(210, 18); // widget's left position and top position
labelTitle->Resize(46, 24); // widget's width and height
labelTitle->SetViewId("labelTitle"); // Set style
labelTitle->SetStyle(STYLE_TEXT_FONT, 28);
// Set additional property
// labelTitle->SetText("压力");
labelTitle->SetTextId(STR_ID_03);
labelTitle->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
labelTitle->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
labelTitle->SetRollSpeed(0);
labelTitle->SetFont(TJD_VECTOR_FONT_FILENAME, 28);
stressContainer_->Add(labelTitle);
labelTitle->SetVisible(true);
TjdUiUtils::AutoAlignHorizontalCenter(*labelTitle);
/*-----------------------------Add labelHigh to App------------------------------*/
if (labelHigh == nullptr) {
labelHigh = new UILabel();
}
labelHigh->SetPosition(144, 371); // widget's left position and top position
labelHigh->Resize(38, 29); // widget's width and height
labelHigh->SetViewId("labelHigh"); // Set style
labelHigh->SetStyle(STYLE_TEXT_FONT, 40);
// Set additional property
labelHigh->SetText("--");
labelHigh->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
labelHigh->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
labelHigh->SetRollSpeed(0);
labelHigh->SetFont(TJD_VECTOR_FONT_FILENAME, 40);
// Add to rootView
stressContainer_->Add(labelHigh);
labelHigh->SetVisible(true);
/*-----------------------------Add labelLow to App------------------------------*/
if (labelLow == nullptr) {
labelLow = new UILabel();
}
labelLow->SetPosition(299, 371); // widget's left position and top position
labelLow->Resize(38, 29); // widget's width and height
labelLow->SetViewId("labelLow"); // Set style
labelLow->SetStyle(STYLE_TEXT_FONT, 40);
// Set additional property
labelLow->SetText("--");
labelLow->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
labelLow->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
labelLow->SetRollSpeed(0);
labelLow->SetFont(TJD_VECTOR_FONT_FILENAME, 40);
// Add to rootView
stressContainer_->Add(labelLow);
labelLow->SetVisible(true);
/*-----------------------------Add imageBg to App------------------------------*/
// Add ImageView to App
if (imageBg == nullptr) {
imageBg = new UIImageView();
}
imageBg->SetPosition(33, 121); // widget's left position and top position
imageBg->Resize(400, 194); // widget's width and height
imageBg->SetViewId("imageBg"); // Set style
// Set additional property
imageBg->SetAutoEnable(false);
ImageInfo *imgInfo =
ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_STRESS_CHART_TIME, STRESS_IMAGE_BIN_PATH);
if (imgInfo == nullptr) {
static_print_info("load stress image error\n");
}
imageBg->SetSrc(imgInfo);
// Add to rootView
stressContainer_->Add(imageBg);
imageBg->SetVisible(true);
/*-----------------------------Add imageHigh to App------------------------------*/
if (imageHigh == nullptr) {
imageHigh = new UIImageView();
}
imageHigh->SetPosition(108, 385); // widget's left position and top position
imageHigh->Resize(22, 20); // widget's width and height
imageHigh->SetViewId("imageHigh"); // Set style
// Set additional property
imageHigh->SetAutoEnable(false);
imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_STRESS_HIGH, STRESS_IMAGE_BIN_PATH);
if (imgInfo == nullptr) {
static_print_info("load stress image error\n");
}
imageHigh->SetSrc(imgInfo);
// Add to rootView
stressContainer_->Add(imageHigh);
imageHigh->SetVisible(true);
/*-----------------------------Add imagePullUp to App------------------------------*/
if (imagePullUp == nullptr) {
imagePullUp = new UIImageView();
}
imagePullUp->SetPosition(214, 430); // widget's left position and top position
imagePullUp->Resize(39, 14); // widget's width and height
imagePullUp->SetViewId("imagePullUp"); // Set style
// Set additional property
imagePullUp->SetAutoEnable(false);
imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_STRESS_PULL_UP, STRESS_IMAGE_BIN_PATH);
if (imgInfo == nullptr) {
static_print_info("load stress image error\n");
}
imagePullUp->SetSrc(imgInfo);
// Add to rootView
stressContainer_->Add(imagePullUp);
imagePullUp->SetVisible(true);
/*-----------------------------Add imageLow to App------------------------------*/
if (imageLow == nullptr) {
imageLow = new UIImageView();
}
imageLow->SetPosition(264, 385); // widget's left position and top position
imageLow->Resize(22, 20); // widget's width and height
imageLow->SetViewId("imageLow"); // Set style
// Set additional property
imageLow->SetAutoEnable(false);
imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_STRESS_LOW, STRESS_IMAGE_BIN_PATH);
if (imgInfo == nullptr) {
static_print_info("load stress image error\n");
}
imageLow->SetSrc(imgInfo);
// Add to rootView
stressContainer_->Add(imageLow);
imageLow->SetVisible(true);
/*-----------------------------Add dataSerial_ to App------------------------------*/
if (dataSerial_ == nullptr) {
dataSerial_ = new UIChartDataSerial();
}
dataSerial_->SetMaxDataCount(24);
Point *stressPointArray = TjdUiAppStressModel::GetInstance()->GetStressPointArray();
for (int i = 0; i < 24; i++) {
printf("stressPointArray[%d] = %d\n", i, stressPointArray[i].y);
}
dataSerial_->AddPoints(stressPointArray, 24); // 5: number of data points
dataSerial_->SetLineColor(Color::GetColorFromRGBA(0x00, 0xFF, 0xEA, 0xff));
dataSerial_->SetFillColor(Color::GetColorFromRGBA(0x00, 0xFF, 0xEA, 0xff));
dataSerial_->EnableGradient(true);
dataSerial_->EnableSmooth(true);
/*-----------------------------Add uiChart1_ to App------------------------------*/
if (uiChart1_ == nullptr) {
uiChart1_ = new UIChartPolyline();
}
uiChart1_->SetPosition(48, 150);
uiChart1_->Resize(365, 135);
uiChart1_->SetViewId("uiChart1");
uiChart1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
UIXAxis &xAxis = uiChart1_->GetXAxis();
UIYAxis &yAxis = uiChart1_->GetYAxis();
xAxis.SetMarkNum(5); // 5: number of scales
yAxis.SetMarkNum(24);
xAxis.SetDataRange(0, 23); // 0: minimum value, 5: maximum value
yAxis.SetDataRange(0, 99); // 0: minimum value, 3500: maximum value
xAxis.SetVisible(false);
yAxis.SetVisible(false);
uiChart1_->SetGradientOpacity(25, 127); // 25: min opacity, 127: max opacity
uiChart1_->AddDataSerial(dataSerial_);
stressContainer_->Add(uiChart1_);
uiChart1_->SetVisible(true);
swipeContainer_->Add(stressContainer_);
}
void TjdUiAppStressView::StressDataViewInit(void)
{
if (dataContainer_ == nullptr) {
dataContainer_ = new UIViewGroup();
dataContainer_->SetPosition(0, 0, 466, 466);
dataContainer_->SetStyle(STYLE_BACKGROUND_OPA, 0);
}
/*-----------------------------Add textTitle to App------------------------------*/
if (textTitle == nullptr) {
textTitle = new UILabelExt();
}
textTitle->SetPosition(185, 18); // widget's left position and top position
textTitle->Resize(96, 37); // widget's width and height); // widget's width and height
textTitle->SetViewId("textTitle"); // Set style
textTitle->SetStyle(STYLE_TEXT_FONT, 28);
// Set additional property
// textTitle->SetText("压力占比");
textTitle->SetTextId(STR_ID_123);
textTitle->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
textTitle->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
textTitle->SetRollSpeed(0);
textTitle->SetFont(TJD_VECTOR_FONT_FILENAME, 28);
// Add to rootView
dataContainer_->Add(textTitle);
textTitle->SetVisible(true);
TjdUiUtils::AutoAlignHorizontalCenter(*textTitle);
/*-----------------------------Add textHigh to App------------------------------*/
if (textHigh == nullptr) {
textHigh = new UILabelExt();
}
textHigh->SetPosition(52, 87); // widget's left position and top position
// textHigh->Resize(47, 24); // widget's width and height
textHigh->SetViewId("textHigh"); // Set style
textHigh->SetStyle(STYLE_TEXT_FONT, 28);
// Set additional property
textHigh->SetTextId(STR_ID_124);
std::string textStr = FontGlobalManager::GetInstance()->GetText(STR_ID_124);
textHigh->SetText((textStr + std::string(" 70-99")).c_str());
textHigh->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
textHigh->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
textHigh->SetRollSpeed(0);
textHigh->SetFont(TJD_VECTOR_FONT_FILENAME, 28);
// Add to rootView
dataContainer_->Add(textHigh);
textHigh->SetVisible(true);
/*-----------------------------Add textMiddle to App------------------------------*/
if (textMiddle == nullptr) {
textMiddle = new UILabelExt();
}
textMiddle->SetPosition(52, 166); // widget's left position and top position
// textMiddle->Resize(38, 29); // widget's width and height
textMiddle->SetViewId("textMiddle"); // Set style
textMiddle->SetStyle(STYLE_TEXT_FONT, 28);
// Set additional property
textMiddle->SetTextId(STR_ID_125);
textStr.clear();
textStr = FontGlobalManager::GetInstance()->GetText(STR_ID_125);
textMiddle->SetText((textStr + std::string(" 50-69")).c_str());
textMiddle->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
textMiddle->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
textMiddle->SetRollSpeed(0);
textMiddle->SetFont(TJD_VECTOR_FONT_FILENAME, 28);
// Add to rootView
dataContainer_->Add(textMiddle);
textMiddle->SetVisible(true);
/*-----------------------------Add textNormal to App------------------------------*/
if (textNormal == nullptr) {
textNormal = new UILabelExt();
}
textNormal->SetPosition(51, 245); // widget's left position and top position
// textNormal->Resize(38, 29); // widget's width and height
textNormal->SetViewId("textNormal"); // Set style
textNormal->SetStyle(STYLE_TEXT_FONT, 28);
// Set additional property
textNormal->SetTextId(STR_ID_126);
textStr.clear();
textStr = FontGlobalManager::GetInstance()->GetText(STR_ID_126);
textNormal->SetText((textStr + std::string(" 50-69")).c_str());
// textNormal->SetText("正常 30-49");
textNormal->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
textNormal->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
textNormal->SetRollSpeed(0);
textNormal->SetFont(TJD_VECTOR_FONT_FILENAME, 28);
// Add to rootView
dataContainer_->Add(textNormal);
textNormal->SetVisible(true);
/*-----------------------------Add textRelax to App------------------------------*/
if (textRelax == nullptr) {
textRelax = new UILabelExt();
}
textRelax->SetPosition(52, 324); // widget's left position and top position
// textRelax->Resize(38, 29); // widget's width and height
textRelax->SetViewId("textRelax"); // Set style
textRelax->SetStyle(STYLE_TEXT_FONT, 28);
// Set additional property
textRelax->SetTextId(STR_ID_127);
textStr.clear();
textStr = FontGlobalManager::GetInstance()->GetText(STR_ID_127);
textRelax->SetText((textStr + std::string(" 01-29")).c_str());
// textRelax->SetText("放松 01-29");
textRelax->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
textRelax->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
textRelax->SetRollSpeed(0);
textRelax->SetFont(TJD_VECTOR_FONT_FILENAME, 28);
// Add to rootView
dataContainer_->Add(textRelax);
textRelax->SetVisible(true);
/*-----------------------------Add dataHigh to App------------------------------*/
if (dataHigh == nullptr) {
dataHigh = new UILabel();
}
dataHigh->SetPosition(361, 90); // widget's left position and top position
dataHigh->Resize(51, 20); // widget's width and height
dataHigh->SetViewId("dataHigh"); // Set style
dataHigh->SetStyle(STYLE_TEXT_FONT, 28);
// Set additional property
dataHigh->SetText("--%");
dataHigh->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
dataHigh->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
dataHigh->SetRollSpeed(0);
dataHigh->SetFont(TJD_VECTOR_FONT_FILENAME, 28);
// Add to rootView
dataContainer_->Add(dataHigh);
dataHigh->SetVisible(true);
/*-----------------------------Add dataMiddle to App------------------------------*/
if (dataMiddle == nullptr) {
dataMiddle = new UILabel();
}
dataMiddle->SetPosition(361, 169); // widget's left position and top position
dataMiddle->Resize(51, 20); // widget's width and height
dataMiddle->SetViewId("dataMiddle"); // Set style
dataMiddle->SetStyle(STYLE_TEXT_FONT, 28);
// Set additional property
dataMiddle->SetText("--%");
dataMiddle->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
dataMiddle->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
dataMiddle->SetRollSpeed(0);
dataMiddle->SetFont(TJD_VECTOR_FONT_FILENAME, 28);
// Add to rootView
dataContainer_->Add(dataMiddle);
dataMiddle->SetVisible(true);
/*-----------------------------Add dataNormal to App------------------------------*/
if (dataNormal == nullptr) {
dataNormal = new UILabel();
}
dataNormal->SetPosition(361, 248); // widget's left position and top position
dataNormal->Resize(51, 20); // widget's width and height
dataNormal->SetViewId("dataNormal"); // Set style
dataNormal->SetStyle(STYLE_TEXT_FONT, 28);
// Set additional property
dataNormal->SetText("--%");
dataNormal->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
dataNormal->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
dataNormal->SetRollSpeed(0);
dataNormal->SetFont(TJD_VECTOR_FONT_FILENAME, 28);
// Add to rootView
dataContainer_->Add(dataNormal);
dataNormal->SetVisible(true);
/*-----------------------------Add dataRelax to App------------------------------*/
if (dataRelax == nullptr) {
dataRelax = new UILabel();
}
dataRelax->SetPosition(361, 327); // widget's left position and top position
dataRelax->Resize(51, 20); // widget's width and height
dataRelax->SetViewId("dataRelax"); // Set style
dataRelax->SetStyle(STYLE_TEXT_FONT, 28);
// Set additional property
dataRelax->SetText("--%");
dataRelax->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
dataRelax->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
dataRelax->SetRollSpeed(0);
dataRelax->SetFont(TJD_VECTOR_FONT_FILENAME, 28);
// Add to rootView
dataContainer_->Add(dataRelax);
dataRelax->SetVisible(true);
// /*-----------------------------Add sliderHigh_ to App------------------------------*/
if (sliderHigh_ == nullptr) {
sliderHigh_ = new UISlider();
}
sliderHigh_->SetPosition(53, 125); // widget's left position and top position
sliderHigh_->Resize(360, 14); // widget's width and height
sliderHigh_->SetViewId("sliderHigh_"); // Set style
sliderHigh_->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
sliderHigh_->SetStyle(STYLE_BORDER_RADIUS, 8);
sliderHigh_->SetSliderRadius(8, 8);
sliderHigh_->SetTouchable(false);
// Set additional property
sliderHigh_->SetValidWidth(360);
sliderHigh_->SetValidHeight(14);
sliderHigh_->SetValue(2);
sliderHigh_->SetSliderColor(Color::GetColorFromRGBA(0x80, 0x80, 0x80, 0xff),
Color::GetColorFromRGBA(0xff, 0x00, 0x00, 0xff));
sliderHigh_->SetKnobWidth(14);
sliderHigh_->SetKnobStyle(STYLE_BACKGROUND_COLOR, 0xffff0000);
sliderHigh_->SetKnobRadius(8);
sliderHigh_->SetForegroundStyle(STYLE_BACKGROUND_OPA, 0xff);
// Add to rootView
dataContainer_->Add(sliderHigh_);
sliderHigh_->SetVisible(true);
// /*-----------------------------Add sliderMiddle_ to App------------------------------*/
if (sliderMiddle_ == nullptr) {
sliderMiddle_ = new UISlider();
}
sliderMiddle_->SetPosition(53, 204); // widget's left position and top position
sliderMiddle_->Resize(360, 14); // widget's width and height
sliderMiddle_->SetViewId("sliderMiddle_"); // Set style
sliderMiddle_->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
sliderMiddle_->SetStyle(STYLE_BORDER_RADIUS, 8);
sliderMiddle_->SetSliderRadius(8, 8);
sliderMiddle_->SetTouchable(false);
// Set additional property
sliderMiddle_->SetValidWidth(360);
sliderMiddle_->SetValidHeight(14);
sliderMiddle_->SetValue(2);
sliderMiddle_->SetSliderColor(Color::GetColorFromRGBA(0x80, 0x80, 0x80, 0xff),
Color::GetColorFromRGBA(0xff, 0x52, 0x0D, 0xff));
sliderMiddle_->SetKnobWidth(14);
sliderMiddle_->SetKnobStyle(STYLE_BACKGROUND_COLOR, 0xffff520D);
sliderMiddle_->SetKnobRadius(8);
sliderMiddle_->SetForegroundStyle(STYLE_BACKGROUND_OPA, 0xff);
// Add to rootView
dataContainer_->Add(sliderMiddle_);
sliderMiddle_->SetVisible(true);
// /*-----------------------------Add sliderNormal_ to App------------------------------*/
if (sliderNormal_ == nullptr) {
sliderNormal_ = new UISlider();
}
sliderNormal_->SetPosition(53, 283); // widget's left position and top position
sliderNormal_->Resize(360, 14); // widget's width and height
sliderNormal_->SetViewId("sliderNormal_"); // Set style
sliderNormal_->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
sliderNormal_->SetStyle(STYLE_BORDER_RADIUS, 8);
sliderNormal_->SetSliderRadius(8, 8);
sliderNormal_->SetTouchable(false);
// Set additional property
sliderNormal_->SetValidWidth(360);
sliderNormal_->SetValidHeight(14);
sliderNormal_->SetValue(2);
sliderNormal_->SetSliderColor(Color::GetColorFromRGBA(0x80, 0x80, 0x80, 0xff),
Color::GetColorFromRGBA(0xff, 0xE4, 0x00, 0xff));
sliderNormal_->SetKnobWidth(14);
sliderNormal_->SetKnobStyle(STYLE_BACKGROUND_COLOR, 0xffffE400);
sliderNormal_->SetKnobRadius(8);
sliderNormal_->SetForegroundStyle(STYLE_BACKGROUND_OPA, 0xff);
// Add to rootView
dataContainer_->Add(sliderNormal_);
sliderNormal_->SetVisible(true);
// /*-----------------------------Add sliderRelax_ to App------------------------------*/
if (sliderRelax_ == nullptr) {
sliderRelax_ = new UISlider();
}
sliderRelax_->SetPosition(53, 362); // widget's left position and top position
sliderRelax_->Resize(360, 14); // widget's width and height
sliderRelax_->SetViewId("sliderRelax_"); // Set style
sliderRelax_->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
sliderRelax_->SetStyle(STYLE_BORDER_RADIUS, 8);
sliderRelax_->SetSliderRadius(8, 8);
sliderRelax_->SetTouchable(false);
// Set additional property
sliderRelax_->SetValidWidth(360);
sliderRelax_->SetValidHeight(14);
sliderRelax_->SetValue(2);
sliderRelax_->SetSliderColor(Color::GetColorFromRGBA(0x80, 0x80, 0x80, 0xff),
Color::GetColorFromRGBA(0x38, 0xFC, 0x6A, 0xff));
sliderRelax_->SetKnobWidth(14);
sliderRelax_->SetKnobStyle(STYLE_BACKGROUND_COLOR, 0xff38FC6A);
sliderRelax_->SetKnobRadius(8);
sliderRelax_->SetForegroundStyle(STYLE_BACKGROUND_OPA, 0xff);
// Add to rootView
dataContainer_->Add(sliderRelax_);
sliderRelax_->SetVisible(true);
swipeContainer_->Add(dataContainer_);
}
void TjdUiAppStressView::StressDataUpdate(void)
{
printf("stress data update!!!!!!!!!!\n");
struct rtc_time time;
tjd_driver_rtc_get_ops()->get_rtc_time(&time);
uint8_t maxStress = sql_fit_get_stress_max(time.tm_wday); // 跟进最近心率值进行换算减去50
uint8_t minStress = sql_fit_get_stress_min(time.tm_wday);
printf("max:%d, min:%d\n", maxStress, minStress);
if (maxStress != 0 && minStress < 100) {
if (labelHigh->GetText() != std::string("--")) {
if (maxStress > std::stoi(labelHigh->GetText())) {
labelHigh->SetText(std::to_string(maxStress).c_str());
labelHigh->Invalidate();
}
} else {
labelHigh->SetText(std::to_string(maxStress).c_str());
labelHigh->Invalidate();
}
if (labelLow->GetText() != std::string("--")) {
if (minStress < std::stoi(labelLow->GetText())) {
labelLow->SetText(std::to_string(minStress).c_str());
labelLow->Invalidate();
}
} else {
labelLow->SetText(std::to_string(minStress).c_str());
labelLow->Invalidate();
}
}
}
void TjdUiAppStressView::StressProgressUpdate(void)
{
// printf("stress Progress update!!!!!!!!!!\n");
char temp_str[8] = {0};
stressPercentage_t ProgressPercentage = TjdUiAppStressModel::GetInstance()->GetStressPercentage();
if (ProgressPercentage.highValue) {
uint8_t highPercentage =
static_cast<int>(std::round(ProgressPercentage.highValue / ProgressPercentage.valid * 100.0f));
sliderHigh_->SetValue(highPercentage);
sprintf(temp_str, "%d%%", highPercentage);
dataHigh->SetText(temp_str);
sliderHigh_->Invalidate();
dataHigh->Invalidate();
}
if (ProgressPercentage.middleValue) {
uint8_t middlePercentage =
static_cast<int>(std::round(ProgressPercentage.middleValue / ProgressPercentage.valid * 100.0f));
sliderMiddle_->SetValue(middlePercentage);
memset(temp_str, 0, sizeof(temp_str));
sprintf(temp_str, "%d%%", middlePercentage);
dataMiddle->SetText(temp_str);
sliderMiddle_->Invalidate();
dataMiddle->Invalidate();
}
if (ProgressPercentage.normalValue) {
uint8_t normalPercentage =
static_cast<int>(std::round(ProgressPercentage.normalValue / ProgressPercentage.valid * 100.0f));
sliderNormal_->SetValue(normalPercentage);
memset(temp_str, 0, sizeof(temp_str));
sprintf(temp_str, "%d%%", normalPercentage);
dataNormal->SetText(temp_str);
sliderNormal_->Invalidate();
textNormal->Invalidate();
}
if (ProgressPercentage.relaxValue) {
uint8_t relaxPercentage =
static_cast<int>(std::round(ProgressPercentage.relaxValue / ProgressPercentage.valid * 100.0f));
sliderRelax_->SetValue(relaxPercentage);
memset(temp_str, 0, sizeof(temp_str));
sprintf(temp_str, "%d%%", relaxPercentage);
dataRelax->SetText(temp_str);
sliderRelax_->Invalidate();
dataRelax->Invalidate();
}
}
} // namespace TJD