1151 lines
40 KiB
C++
1151 lines
40 KiB
C++
#include "TjdUiAppProductView.h"
|
||
#include "TjdUiImageIds.h"
|
||
#include "TjdUiMemManage.h"
|
||
#include "TjdUiMultiLanguageExt.h"
|
||
#include "animator/animator_manager.h"
|
||
#include "common/image_cache_manager.h"
|
||
#include "gfx_utils/mem_check.h"
|
||
#include "graphic_service.h"
|
||
#include "sys_config.h"
|
||
#include <sstream>
|
||
|
||
namespace TJD {
|
||
|
||
#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
|
||
|
||
constexpr uint8_t REBOUND_SIZE = 200;
|
||
constexpr float ROTATE_FACTOR = -10;
|
||
constexpr uint8_t ROTATE_THRESHOLD = 8;
|
||
// clang-format off
|
||
static inline void SetRotateEnable(OHOS::UIScrollView &view)
|
||
{
|
||
view.SetThrowDrag(true);
|
||
view.SetScrollBlankSize(17);
|
||
view.SetReboundSize(REBOUND_SIZE);
|
||
view.SetYScrollBarVisible(true);
|
||
}
|
||
|
||
static inline int16_t VerticalCenter(int16_t height, int16_t parentHeight) { return (parentHeight - height) / 2; }
|
||
|
||
static inline int16_t HorizontalCenter(int16_t width, int16_t parentWidth) { return (parentWidth - width) / 2; }
|
||
|
||
static inline void InitLabelHorCenter(OHOS::UILabel &label, uint8_t size, int16_t y, int16_t target, const char *text)
|
||
{
|
||
label.SetFont(TJD_VECTOR_FONT_FILENAME, size);
|
||
label.SetText(text);
|
||
label.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
|
||
label.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
||
label.SetPosition(HorizontalCenter(label.GetWidth(), target), y);
|
||
}
|
||
|
||
static inline void InitLabelVerCenter(OHOS::UILabel &label, uint8_t size, int16_t x, int16_t target, const char *text)
|
||
{
|
||
label.SetFont(TJD_VECTOR_FONT_FILENAME, size);
|
||
label.SetText(text);
|
||
label.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
|
||
label.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
||
label.SetPosition(x, label.GetY() + VerticalCenter(label.GetHeight(), target));
|
||
}
|
||
|
||
static inline void InitLabelCenter(OHOS::UILabel &label, uint8_t size, int16_t parentWidth, int16_t parentHeight,const char *text)
|
||
{
|
||
label.SetFont(TJD_VECTOR_FONT_FILENAME, size);
|
||
label.SetText(text);
|
||
label.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
|
||
label.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
||
label.SetPosition(HorizontalCenter(label.GetWidth(), parentWidth), VerticalCenter(label.GetHeight(), parentHeight));
|
||
}
|
||
// clang-format on
|
||
|
||
#define IMAGE_BIN_PATH TJD_IMAGE_PATH "img_production.bin"
|
||
|
||
static TjdUiAppProductView *g_productView = nullptr;
|
||
|
||
ProductViewIndex TjdUiAppProductView::currentViewIndex_ = ProductViewIndex::PRODUCT_UNKNOWN;
|
||
|
||
TjdUiAppProductView::TjdUiAppProductView()
|
||
{
|
||
// OHOS::MemCheck::GetInstance()->EnableLeakCheck(true);
|
||
g_productView = this;
|
||
}
|
||
|
||
TjdUiAppProductView::~TjdUiAppProductView()
|
||
{
|
||
// OHOS::MemCheck::GetInstance()->EnableLeakCheck(false);
|
||
g_productView = nullptr;
|
||
}
|
||
|
||
TjdUiAppProductView *TjdUiAppProductView::GetInstance(void) { return g_productView; }
|
||
|
||
void TjdUiAppProductView::OnStart()
|
||
{
|
||
OHOS::ImageCacheManager::GetInstance().LoadAllInMultiRes(IMAGE_BIN_PATH);
|
||
|
||
if (mainView_ == nullptr) {
|
||
mainView_ = new OHOS::UIScrollView();
|
||
}
|
||
mainView_->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
||
mainView_->SetOnDragListener(TjdUiAppProductPresenter::GetInstance());
|
||
|
||
AddViewToRootContainer(mainView_);
|
||
}
|
||
|
||
void TjdUiAppProductView::OnStop()
|
||
{
|
||
if (mainView_ != nullptr) {
|
||
mainView_->RemoveAll();
|
||
delete mainView_;
|
||
mainView_ = nullptr;
|
||
}
|
||
for (int i = 0; i < ProductViewIndex::PRODUCT_UNKNOWN; i++) {
|
||
if (viewManager_[i] != nullptr) {
|
||
delete viewManager_[i];
|
||
viewManager_[i] = nullptr;
|
||
}
|
||
}
|
||
OHOS::ImageCacheManager::GetInstance().UnloadAllInMultiRes(IMAGE_BIN_PATH);
|
||
}
|
||
|
||
void TjdUiAppProductView::InitTargetView(ProductViewIndex index)
|
||
{
|
||
if (viewManager_[index] != nullptr) {
|
||
return;
|
||
}
|
||
|
||
// clang-format off
|
||
switch (index) {
|
||
case PRODUCT_SELECT_LIST: viewManager_[index] = new ProductSelectListView(); break;
|
||
case PRODUCT_LCD_TEST: viewManager_[index] = new ProductLcdTestView(); break;
|
||
case PRODUCT_TP_CLICK_TEST: viewManager_[index] = new ProductTpTestView(); break;
|
||
case PRODUCT_TP_SLIDE_TEST: viewManager_[index] = new ProductTpSlideTestView(); break;
|
||
case PRODUCT_HEART_RATE_TEST: viewManager_[index] = new ProductHeartRateTestView(); break;
|
||
case PRODUCT_GSENSOR_TEST: viewManager_[index] = new ProductGSensorTestView(); break;
|
||
case PRODUCT_SPEAKER_TEST: viewManager_[index] = new ProductSpeakerTestView(); break;
|
||
case PRODUCT_MOTOR_TEST: viewManager_[index] = new ProductMotorTestView(); break;
|
||
case PRODUCT_MICROPHONE_TEST: viewManager_[index] = new ProductMicTestView(); break;
|
||
case PRODUCT_BUTTON_TEST: viewManager_[index] = new ProductButtonTestView(); break;
|
||
case PRODUCT_AGING_CHOOSE_TEST: viewManager_[index] = new ProductAgingTestChooseView(); break;
|
||
case PRODUCT_AGING_TEST: viewManager_[index] = new ProductAgingTestView(); break;
|
||
case PRODUCT_TP_REPORT_TEST: viewManager_[index] = new ProductTpReportTestView(); break;
|
||
case PRODUCT_GPS_REPORT_TEST: viewManager_[index] = new ProductGPSTestView(); break;
|
||
default: break;
|
||
}
|
||
// clang-format on
|
||
|
||
if (viewManager_[index] == nullptr) {
|
||
return;
|
||
}
|
||
|
||
viewManager_[index]->SetPosition(0, 0);
|
||
viewManager_[index]->SetVisible(false);
|
||
mainView_->Add(viewManager_[index]);
|
||
}
|
||
|
||
void TjdUiAppProductView::ShowView(ProductViewIndex showIndex)
|
||
{
|
||
if (showIndex < 0 || showIndex >= ProductViewIndex::PRODUCT_UNKNOWN) {
|
||
return;
|
||
}
|
||
|
||
InitTargetView(showIndex);
|
||
|
||
if (currentViewIndex_ >= 0 && currentViewIndex_ < ProductViewIndex::PRODUCT_UNKNOWN &&
|
||
viewManager_[currentViewIndex_] != nullptr) {
|
||
viewManager_[currentViewIndex_]->HideView();
|
||
}
|
||
|
||
TjdUiAppProductPresenter *presenter = TjdUiAppProductPresenter::GetInstance();
|
||
if (presenter != nullptr) {
|
||
presenter->ShowViewEvent(showIndex);
|
||
}
|
||
|
||
if (viewManager_[showIndex] != nullptr) {
|
||
viewManager_[showIndex]->ShowView();
|
||
}
|
||
|
||
currentViewIndex_ = showIndex;
|
||
}
|
||
|
||
#pragma region 事件转发
|
||
void TjdUiAppProductView::SetLcdFullColor(uint32_t color)
|
||
{
|
||
InitTargetView(ProductViewIndex::PRODUCT_LCD_TEST);
|
||
dynamic_cast<ProductLcdTestView *>(viewManager_[ProductViewIndex::PRODUCT_LCD_TEST])->SetLcdFullColor(color);
|
||
}
|
||
|
||
void TjdUiAppProductView::SetAgingTestColor(uint32_t color)
|
||
{
|
||
InitTargetView(ProductViewIndex::PRODUCT_AGING_TEST);
|
||
dynamic_cast<ProductAgingTestView *>(viewManager_[ProductViewIndex::PRODUCT_AGING_TEST])->SetColor(color);
|
||
}
|
||
|
||
bool TjdUiAppProductView::IsTpBtnSelectedAll()
|
||
{
|
||
InitTargetView(ProductViewIndex::PRODUCT_TP_CLICK_TEST);
|
||
return dynamic_cast<ProductTpTestView *>(viewManager_[ProductViewIndex::PRODUCT_TP_CLICK_TEST])
|
||
->IsTpBtnSelectedAll();
|
||
}
|
||
|
||
void TjdUiAppProductView::ClearTpBtnMap()
|
||
{
|
||
InitTargetView(ProductViewIndex::PRODUCT_TP_CLICK_TEST);
|
||
dynamic_cast<ProductTpTestView *>(viewManager_[ProductViewIndex::PRODUCT_TP_CLICK_TEST])->ClearTpBtnMap();
|
||
}
|
||
|
||
void TjdUiAppProductView::DragTpSlidePos(OHOS::Point pos)
|
||
{
|
||
if (currentViewIndex_ == ProductViewIndex::PRODUCT_TP_SLIDE_TEST) {
|
||
InitTargetView(ProductViewIndex::PRODUCT_TP_SLIDE_TEST);
|
||
dynamic_cast<ProductTpSlideTestView *>(viewManager_[ProductViewIndex::PRODUCT_TP_SLIDE_TEST])->DragPos(pos);
|
||
} else if (currentViewIndex_ == ProductViewIndex::PRODUCT_TP_REPORT_TEST) {
|
||
InitTargetView(ProductViewIndex::PRODUCT_TP_REPORT_TEST);
|
||
dynamic_cast<ProductTpReportTestView *>(viewManager_[ProductViewIndex::PRODUCT_TP_REPORT_TEST])->DragPos(pos);
|
||
}
|
||
}
|
||
|
||
bool TjdUiAppProductView::IsTpDragAllArea()
|
||
{
|
||
InitTargetView(ProductViewIndex::PRODUCT_TP_SLIDE_TEST);
|
||
return dynamic_cast<ProductTpSlideTestView *>(viewManager_[ProductViewIndex::PRODUCT_TP_SLIDE_TEST])->IsTpTestOk();
|
||
}
|
||
|
||
void TjdUiAppProductView::SetHeartRateValue(int value)
|
||
{
|
||
InitTargetView(ProductViewIndex::PRODUCT_HEART_RATE_TEST);
|
||
dynamic_cast<ProductHeartRateTestView *>(viewManager_[ProductViewIndex::PRODUCT_HEART_RATE_TEST])->SetValue(value);
|
||
}
|
||
|
||
void TjdUiAppProductView::SetGSensorValue(int step, int16_t x, int16_t y, int16_t z)
|
||
{
|
||
InitTargetView(ProductViewIndex::PRODUCT_GSENSOR_TEST);
|
||
dynamic_cast<ProductGSensorTestView *>(viewManager_[ProductViewIndex::PRODUCT_GSENSOR_TEST])
|
||
->SetValue(step, x, y, z);
|
||
}
|
||
|
||
void TjdUiAppProductView::SetRespButtonState(OHOS::UIButton::ButtonState state)
|
||
{
|
||
InitTargetView(ProductViewIndex::PRODUCT_BUTTON_TEST);
|
||
dynamic_cast<ProductButtonTestView *>(viewManager_[ProductViewIndex::PRODUCT_BUTTON_TEST])
|
||
->SetRespButtonState(state);
|
||
}
|
||
|
||
AngingTestItem TjdUiAppProductView::GetAgingTestItem(void)
|
||
{
|
||
InitTargetView(ProductViewIndex::PRODUCT_AGING_CHOOSE_TEST);
|
||
auto view = dynamic_cast<ProductAgingTestChooseView *>(viewManager_[ProductViewIndex::PRODUCT_AGING_CHOOSE_TEST]);
|
||
AngingTestItem item = {
|
||
.lcdTest = view->IsLcdSelected(),
|
||
.heartRate = view->IsHeartRateSelected(),
|
||
.motor = view->IsMotorSelected(),
|
||
.speaker = view->IsSpeakerSelected(),
|
||
};
|
||
return item;
|
||
}
|
||
|
||
void TjdUiAppProductView::AngingSetStatus(AngingTestItem &item)
|
||
{
|
||
InitTargetView(ProductViewIndex::PRODUCT_AGING_TEST);
|
||
dynamic_cast<ProductAgingTestView *>(viewManager_[ProductViewIndex::PRODUCT_AGING_TEST])->SetState(item);
|
||
}
|
||
|
||
void TjdUiAppProductView::AngingSetValue(int power, uint32_t time)
|
||
{
|
||
InitTargetView(ProductViewIndex::PRODUCT_AGING_TEST);
|
||
dynamic_cast<ProductAgingTestView *>(viewManager_[ProductViewIndex::PRODUCT_AGING_TEST])->SetPower(power);
|
||
dynamic_cast<ProductAgingTestView *>(viewManager_[ProductViewIndex::PRODUCT_AGING_TEST])->SetTime(time);
|
||
}
|
||
|
||
void TjdUiAppProductView::AngingReset(void)
|
||
{
|
||
InitTargetView(ProductViewIndex::PRODUCT_AGING_TEST);
|
||
dynamic_cast<ProductAgingTestView *>(viewManager_[ProductViewIndex::PRODUCT_AGING_TEST])->Reset();
|
||
}
|
||
|
||
void TjdUiAppProductView::AngingChooseSetRecord(AngingTestResult &result)
|
||
{
|
||
InitTargetView(ProductViewIndex::PRODUCT_AGING_CHOOSE_TEST);
|
||
dynamic_cast<ProductAgingTestChooseView *>(viewManager_[ProductViewIndex::PRODUCT_AGING_CHOOSE_TEST])
|
||
->SetRecord(result);
|
||
}
|
||
|
||
void TjdUiAppProductView::RefrashGpsPlot()
|
||
{
|
||
InitTargetView(ProductViewIndex::PRODUCT_GPS_REPORT_TEST);
|
||
dynamic_cast<ProductGPSTestView *>(viewManager_[ProductViewIndex::PRODUCT_GPS_REPORT_TEST])->RefrashPlot();
|
||
}
|
||
|
||
void TjdUiAppProductView::SetStarNumber(int usable, int visible)
|
||
{
|
||
InitTargetView(ProductViewIndex::PRODUCT_GPS_REPORT_TEST);
|
||
dynamic_cast<ProductGPSTestView *>(viewManager_[ProductViewIndex::PRODUCT_GPS_REPORT_TEST])->SetUsableStar(usable);
|
||
dynamic_cast<ProductGPSTestView *>(viewManager_[ProductViewIndex::PRODUCT_GPS_REPORT_TEST])
|
||
->SetVisibleStar(visible);
|
||
}
|
||
|
||
void TjdUiAppProductView::SetGpsState(const char *text)
|
||
{
|
||
InitTargetView(ProductViewIndex::PRODUCT_GPS_REPORT_TEST);
|
||
dynamic_cast<ProductGPSTestView *>(viewManager_[ProductViewIndex::PRODUCT_GPS_REPORT_TEST])->SetState(text);
|
||
}
|
||
#pragma endregion
|
||
|
||
#pragma region 选择列表
|
||
ProductSelectListView::ProductSelectListView()
|
||
{
|
||
auto exitRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_PRODUCTION_EXIT, IMAGE_BIN_PATH);
|
||
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
||
SetThrowDrag(true);
|
||
SetScrollBlankSize(17);
|
||
SetYScrollBarVisible(true);
|
||
SetRotateEnable(*this);
|
||
SetReboundSize(0);
|
||
|
||
InitLabelHorCenter(title_, 28, 17, 466, "工厂测试模式");
|
||
Add(&title_);
|
||
|
||
struct ButtonConfig
|
||
{
|
||
OHOS::UILabelButton *button;
|
||
const char *viewId;
|
||
const char *text;
|
||
};
|
||
// clang-format off
|
||
ButtonConfig buttonConfigs[] = {
|
||
{&normalButton_, PRODUCT_NORMAL_BTN_VIEW_ID, "常规测试"},
|
||
{&agingButton_, PRODUCT_AGING_BTN_VIEW_ID, "老化测试"},
|
||
{&touchButton_, PRODUCT_TOUCH_BTN_VIEW_ID, "触摸测试"},
|
||
{&gpsButton_, PRODUCT_GPS_BTN_VIEW_ID, "GPS测试"}
|
||
};
|
||
// clang-format on
|
||
int startY = 147;
|
||
for (auto &config : buttonConfigs) {
|
||
config.button->SetPosition(8, startY, 450, 110);
|
||
config.button->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff262626);
|
||
config.button->SetText(config.text);
|
||
config.button->SetFont(TJD_VECTOR_FONT_FILENAME, 34);
|
||
config.button->SetAlign(OHOS::UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER);
|
||
config.button->SetViewId(config.viewId);
|
||
config.button->SetOnClickListener(TjdUiAppProductPresenter::GetInstance());
|
||
Add(config.button);
|
||
startY += 118;
|
||
}
|
||
retButton_.SetPosition(52, startY + 38, 362, 86);
|
||
retButton_.SetViewId(PRODUCT_BACK_BTN_VIEW_ID);
|
||
retButton_.SetTouchable(true);
|
||
retButton_.SetOnClickListener(TjdUiAppProductPresenter::GetInstance());
|
||
if (exitRes != nullptr) {
|
||
retButton_.SetSrc(exitRes);
|
||
} else {
|
||
retButton_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff00E345);
|
||
retButton_.SetStyle(OHOS::STYLE_BACKGROUND_OPA, OHOS::OPA_OPAQUE);
|
||
}
|
||
Add(&retButton_);
|
||
}
|
||
#pragma endregion
|
||
|
||
#pragma region LCD测试
|
||
ProductLcdTestView::ProductLcdTestView()
|
||
{
|
||
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
||
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xffD9001B);
|
||
SetStyle(OHOS::STYLE_BACKGROUND_OPA, OHOS::OPA_OPAQUE);
|
||
SetTouchable(true);
|
||
SetOnClickListener(TjdUiAppProductPresenter::GetInstance());
|
||
}
|
||
|
||
void ProductLcdTestView::SetLcdFullColor(uint32_t color)
|
||
{
|
||
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, color);
|
||
Invalidate();
|
||
}
|
||
#pragma endregion
|
||
|
||
#pragma region TP测试
|
||
ProductTpTestView::ProductTpTestView()
|
||
{
|
||
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
||
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff262626);
|
||
SetStyle(OHOS::STYLE_BACKGROUND_OPA, OHOS::OPA_OPAQUE);
|
||
int btnIndex = 0;
|
||
for (int y = 0; y < 4; ++y) {
|
||
int posX = y * 118;
|
||
for (int x = 0; x < 4; ++x) {
|
||
tpTestButton_[btnIndex].SetPosition(posX, x * 118, 114, 114);
|
||
tpTestButton_[btnIndex].SetOnClickListener(TjdUiAppProductPresenter::GetInstance());
|
||
Add(&tpTestButton_[btnIndex++]);
|
||
}
|
||
}
|
||
}
|
||
|
||
bool ProductTpTestView::IsTpBtnSelectedAll(void)
|
||
{
|
||
for (int i = 0; i < PRODUCTION_TP_BTN_NUM; i++) {
|
||
if (tpTestButton_[i].GetState() == false) {
|
||
return false;
|
||
}
|
||
}
|
||
return true;
|
||
}
|
||
|
||
void ProductTpTestView::ClearTpBtnMap(void)
|
||
{
|
||
for (int i = 0; i < PRODUCTION_TP_BTN_NUM; i++) {
|
||
tpTestButton_[i].SetState(false);
|
||
}
|
||
}
|
||
#pragma endregion
|
||
|
||
#pragma region TP滑动测试
|
||
ProductTpSlideTestView::ProductTpSlideTestView()
|
||
{
|
||
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
||
SetOnDragListener(TjdUiAppProductPresenter::GetInstance());
|
||
canvas_.SetPosition(0, 0, 466, 466);
|
||
ClearTpTest();
|
||
Add(&canvas_);
|
||
}
|
||
|
||
bool ProductTpSlideTestView::IsTpTestOk(void)
|
||
{
|
||
int coveredArea = 0;
|
||
for (const auto &point : draggedPoints_) {
|
||
OHOS::Point p = {point.first, point.second};
|
||
if (IsPointInLine({367, 367}, {98, 98}, p, lineWidth_) || IsPointInLine({98, 367}, {367, 98}, p, lineWidth_)) {
|
||
coveredArea++;
|
||
}
|
||
}
|
||
double coveredRatio = static_cast<double>(coveredArea) / originalArea_;
|
||
return coveredRatio >= threshold_;
|
||
}
|
||
|
||
void ProductTpSlideTestView::ClearTpTest(void)
|
||
{
|
||
canvas_.Clear();
|
||
draggedPoints_.clear();
|
||
|
||
OHOS::PaintExt paint;
|
||
paint.SetStrokeWidth(45);
|
||
paint.SetCapType(OHOS::CapType::CAP_ROUND);
|
||
OHOS::ColorType color;
|
||
color.full = 0xFF262626;
|
||
paint.SetStrokeColor(color);
|
||
|
||
OHOS::Point start1Point = {367, 367};
|
||
OHOS::Point end1Point = {98, 98};
|
||
canvas_.DrawLine(start1Point, end1Point, paint);
|
||
|
||
OHOS::Point start2Point = {98, 367};
|
||
OHOS::Point end2Point = {367, 98};
|
||
canvas_.DrawLine(start2Point, end2Point, paint);
|
||
Invalidate();
|
||
}
|
||
|
||
void ProductTpSlideTestView::DragPos(OHOS::Point pos)
|
||
{
|
||
OHOS::PaintExt paint;
|
||
paint.SetStyle(OHOS::Paint::STROKE_FILL_STYLE);
|
||
paint.SetStrokeColor((OHOS::ColorType){.full = 0xFFFF0000});
|
||
paint.SetFillColor((OHOS::ColorType){.full = 0xFFFF0000});
|
||
canvas_.DrawCircle(pos, 45 / 2, paint);
|
||
// 记录拖动的点
|
||
draggedPoints_.insert({pos.x, pos.y});
|
||
}
|
||
|
||
bool ProductTpSlideTestView::IsPointInLine(OHOS::Point start, OHOS::Point end, OHOS::Point point, int width)
|
||
{
|
||
// 计算点到线段的距离
|
||
double A = point.x - start.x;
|
||
double B = point.y - start.y;
|
||
double C = end.x - start.x;
|
||
double D = end.y - start.y;
|
||
|
||
double dot = A * C + B * D;
|
||
double len_sq = C * C + D * D;
|
||
double param = (len_sq != 0) ? (dot / len_sq) : -1;
|
||
|
||
double xx, yy;
|
||
|
||
if (param < 0) {
|
||
xx = start.x;
|
||
yy = start.y;
|
||
} else if (param > 1) {
|
||
xx = end.x;
|
||
yy = end.y;
|
||
} else {
|
||
xx = start.x + param * C;
|
||
yy = start.y + param * D;
|
||
}
|
||
|
||
double dx = point.x - xx;
|
||
double dy = point.y - yy;
|
||
return (dx * dx + dy * dy) <= (width * width / 4);
|
||
}
|
||
#pragma endregion
|
||
|
||
#pragma region 心率测试
|
||
ProductHeartRateTestView::ProductHeartRateTestView()
|
||
{
|
||
auto nextRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_PRODUCTION_CONTINUE, IMAGE_BIN_PATH);
|
||
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
||
|
||
InitLabelHorCenter(title_, 34, 42, 466, "心率测试");
|
||
|
||
nextButton_.SetPosition(52, 380, 362, 86);
|
||
if (nextRes != nullptr) {
|
||
nextButton_.SetSrc(nextRes);
|
||
} else {
|
||
nextButton_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff00E345);
|
||
nextButton_.SetStyle(OHOS::STYLE_BACKGROUND_OPA, OHOS::OPA_OPAQUE);
|
||
}
|
||
nextButton_.SetTouchable(true);
|
||
nextButton_.SetViewId(PRODUCT_NEXT_BTN_VIEW_ID);
|
||
nextButton_.SetOnClickListener(TjdUiAppProductPresenter::GetInstance());
|
||
|
||
value_.SetFont(TJD_VECTOR_FONT_FILENAME, 50);
|
||
value_.SetText("---");
|
||
value_.SetPosition(159, 198, 100, 30);
|
||
value_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_WRAP);
|
||
value_.SetAlign(OHOS::TEXT_ALIGNMENT_RIGHT, OHOS::TEXT_ALIGNMENT_CENTER);
|
||
InitLabelVerCenter(unit_, 36, 275, 466, "bpm");
|
||
|
||
Add(&title_);
|
||
Add(&nextButton_);
|
||
Add(&value_);
|
||
Add(&unit_);
|
||
}
|
||
|
||
void ProductHeartRateTestView::SetValue(int value)
|
||
{
|
||
char buf[8] = {0};
|
||
if (value == 0) {
|
||
value_.SetText("---");
|
||
return;
|
||
}
|
||
snprintf(buf, sizeof(buf), "%d", value);
|
||
value_.SetText(buf);
|
||
}
|
||
#pragma endregion
|
||
|
||
#pragma region G - sensor测试
|
||
ProductGSensorTestView::ProductGSensorTestView()
|
||
{
|
||
auto nextRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_PRODUCTION_CONTINUE, IMAGE_BIN_PATH);
|
||
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
||
|
||
InitLabelHorCenter(title_, 34, 42, 466, "G-sensor测试");
|
||
|
||
nextButton_.SetPosition(52, 380, 362, 86);
|
||
if (nextRes != nullptr) {
|
||
nextButton_.SetSrc(nextRes);
|
||
} else {
|
||
nextButton_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff00E345);
|
||
nextButton_.SetStyle(OHOS::STYLE_BACKGROUND_OPA, OHOS::OPA_OPAQUE);
|
||
}
|
||
nextButton_.SetTouchable(true);
|
||
nextButton_.SetViewId(PRODUCT_NEXT_BTN_VIEW_ID);
|
||
nextButton_.SetOnClickListener(TjdUiAppProductPresenter::GetInstance());
|
||
|
||
InitLabelHorCenter(stepDesc_, 34, 0, 466, "步数");
|
||
stepDesc_.SetPosition(151, 170, 66, 32);
|
||
InitLabelHorCenter(stepValue_, 40, 0, 466, "0000");
|
||
stepValue_.SetPosition(stepDesc_.GetX() + stepDesc_.GetWidth() + 13, 166, 81, 50);
|
||
|
||
value_.SetPosition(50, 234, 351, 80);
|
||
value_.SetTextColor(OHOS::Color::White());
|
||
value_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
||
value_.SetText("X:0000 Y:0000 Z:0000");
|
||
value_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_WRAP);
|
||
value_.SetFont(TJD_VECTOR_FONT_FILENAME, 40);
|
||
|
||
Add(&title_);
|
||
Add(&stepDesc_);
|
||
Add(&stepValue_);
|
||
Add(&value_);
|
||
Add(&nextButton_);
|
||
}
|
||
|
||
void ProductGSensorTestView::SetValue(int step, int16_t x, int16_t y, int16_t z)
|
||
{
|
||
char buf[64] = {0};
|
||
snprintf(buf, sizeof(buf), "%04d", step);
|
||
stepValue_.SetText(buf);
|
||
snprintf(buf, sizeof(buf), "X:%d Y:%d Z:%d", x, y, z);
|
||
value_.SetText(buf);
|
||
}
|
||
#pragma endregion
|
||
|
||
#pragma region 喇叭测试
|
||
ProductSpeakerTestView::ProductSpeakerTestView()
|
||
{
|
||
auto nextRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_PRODUCTION_CONTINUE, IMAGE_BIN_PATH);
|
||
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
||
|
||
InitLabelHorCenter(title_, 34, 42, 466, "喇叭测试");
|
||
|
||
nextButton_.SetPosition(52, 380, 362, 86);
|
||
if (nextRes != nullptr) {
|
||
nextButton_.SetSrc(nextRes);
|
||
} else {
|
||
nextButton_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff00E345);
|
||
nextButton_.SetStyle(OHOS::STYLE_BACKGROUND_OPA, OHOS::OPA_OPAQUE);
|
||
}
|
||
nextButton_.SetTouchable(true);
|
||
nextButton_.SetViewId(PRODUCT_NEXT_BTN_VIEW_ID);
|
||
nextButton_.SetOnClickListener(TjdUiAppProductPresenter::GetInstance());
|
||
|
||
onceButton_.SetPosition(8, 147, 450, 110);
|
||
onceButton_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff262626);
|
||
onceButton_.SetText("单次播放");
|
||
onceButton_.SetFont(TJD_VECTOR_FONT_FILENAME, 34);
|
||
onceButton_.SetAlign(OHOS::UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER);
|
||
onceButton_.SetViewId(PRODUCT_ONCE_BTN_VIEW_ID);
|
||
onceButton_.SetOnClickListener(TjdUiAppProductPresenter::GetInstance());
|
||
|
||
repeatButton_.SetPosition(45, 265, 375, 90);
|
||
repeatButton_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff262626);
|
||
repeatButton_.SetText("重复播放");
|
||
repeatButton_.SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
||
repeatButton_.SetAlign(OHOS::UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER);
|
||
repeatButton_.SetViewId(PRODUCT_REPEAT_BTN_VIEW_ID);
|
||
repeatButton_.SetOnClickListener(TjdUiAppProductPresenter::GetInstance());
|
||
|
||
Add(&title_);
|
||
Add(&onceButton_);
|
||
Add(&repeatButton_);
|
||
Add(&nextButton_);
|
||
}
|
||
#pragma endregion
|
||
|
||
#pragma region 马达测试
|
||
ProductMotorTestView::ProductMotorTestView()
|
||
{
|
||
auto nextRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_PRODUCTION_CONTINUE, IMAGE_BIN_PATH);
|
||
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
||
|
||
InitLabelHorCenter(title_, 34, 42, 466, "马达测试");
|
||
|
||
nextButton_.SetPosition(52, 380, 362, 86);
|
||
if (nextRes != nullptr) {
|
||
nextButton_.SetSrc(nextRes);
|
||
} else {
|
||
nextButton_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff00E345);
|
||
nextButton_.SetStyle(OHOS::STYLE_BACKGROUND_OPA, OHOS::OPA_OPAQUE);
|
||
}
|
||
nextButton_.SetTouchable(true);
|
||
nextButton_.SetViewId(PRODUCT_NEXT_BTN_VIEW_ID);
|
||
nextButton_.SetOnClickListener(TjdUiAppProductPresenter::GetInstance());
|
||
|
||
onceButton_.SetPosition(8, 147, 450, 110);
|
||
onceButton_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff262626);
|
||
onceButton_.SetText("单次震动");
|
||
onceButton_.SetFont(TJD_VECTOR_FONT_FILENAME, 34);
|
||
onceButton_.SetAlign(OHOS::UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER);
|
||
onceButton_.SetViewId(PRODUCT_ONCE_BTN_VIEW_ID);
|
||
onceButton_.SetOnClickListener(TjdUiAppProductPresenter::GetInstance());
|
||
|
||
repeatButton_.SetPosition(45, 265, 375, 90);
|
||
repeatButton_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff262626);
|
||
repeatButton_.SetText("重复震动");
|
||
repeatButton_.SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
||
repeatButton_.SetAlign(OHOS::UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER);
|
||
repeatButton_.SetViewId(PRODUCT_REPEAT_BTN_VIEW_ID);
|
||
repeatButton_.SetOnClickListener(TjdUiAppProductPresenter::GetInstance());
|
||
|
||
Add(&title_);
|
||
Add(&onceButton_);
|
||
Add(&repeatButton_);
|
||
Add(&nextButton_);
|
||
}
|
||
#pragma endregion
|
||
|
||
#pragma region 麦克风测试
|
||
ProductMicTestView::ProductMicTestView()
|
||
{
|
||
auto nextRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_PRODUCTION_CONTINUE, IMAGE_BIN_PATH);
|
||
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
||
|
||
InitLabelHorCenter(title_, 34, 42, 466, "麦克测试");
|
||
|
||
nextButton_.SetPosition(52, 380, 362, 86);
|
||
if (nextRes != nullptr) {
|
||
nextButton_.SetSrc(nextRes);
|
||
} else {
|
||
nextButton_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff00E345);
|
||
nextButton_.SetStyle(OHOS::STYLE_BACKGROUND_OPA, OHOS::OPA_OPAQUE);
|
||
}
|
||
nextButton_.SetTouchable(true);
|
||
nextButton_.SetViewId(PRODUCT_NEXT_BTN_VIEW_ID);
|
||
nextButton_.SetOnClickListener(TjdUiAppProductPresenter::GetInstance());
|
||
|
||
InitLabelHorCenter(desc_, 34, 185, 466, "对着麦克说话,\n喇叭发生即为正常");
|
||
|
||
Add(&title_);
|
||
Add(&desc_);
|
||
Add(&nextButton_);
|
||
}
|
||
#pragma endregion
|
||
|
||
#pragma region 按键测试
|
||
ProductButtonTestView::ProductButtonTestView()
|
||
{
|
||
auto nextRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_PRODUCTION_CONTINUE, IMAGE_BIN_PATH);
|
||
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
||
|
||
InitLabelHorCenter(title_, 34, 42, 466, "按键测试");
|
||
|
||
nextButton_.SetPosition(52, 380, 362, 86);
|
||
if (nextRes != nullptr) {
|
||
nextButton_.SetSrc(nextRes);
|
||
} else {
|
||
nextButton_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff00E345);
|
||
nextButton_.SetStyle(OHOS::STYLE_BACKGROUND_OPA, OHOS::OPA_OPAQUE);
|
||
}
|
||
nextButton_.SetTouchable(true);
|
||
nextButton_.SetViewId(PRODUCT_NEXT_BTN_VIEW_ID);
|
||
nextButton_.SetOnClickListener(TjdUiAppProductPresenter::GetInstance());
|
||
|
||
respButton_.SetPosition(8, 147, 450, 110);
|
||
respButton_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff262626);
|
||
respButton_.SetText("按键响应区域");
|
||
respButton_.SetFont(TJD_VECTOR_FONT_FILENAME, 34);
|
||
respButton_.SetAlign(OHOS::UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER);
|
||
respButton_.SetTouchable(false);
|
||
|
||
Add(&title_);
|
||
Add(&respButton_);
|
||
Add(&nextButton_);
|
||
}
|
||
|
||
void ProductButtonTestView::SetRespButtonState(OHOS::UIButton::ButtonState state)
|
||
{
|
||
if (state == OHOS::UIButton::ButtonState::PRESSED) {
|
||
respButton_.SetStyleForState(OHOS::STYLE_BACKGROUND_COLOR, 0xff1895FE, OHOS::UIButton::ButtonState::RELEASED);
|
||
} else if (state == OHOS::UIButton::ButtonState::RELEASED) {
|
||
respButton_.SetStyleForState(OHOS::STYLE_BACKGROUND_COLOR, 0xff262626, OHOS::UIButton::ButtonState::RELEASED);
|
||
}
|
||
respButton_.Invalidate();
|
||
}
|
||
#pragma endregion
|
||
|
||
#pragma region 老化测试选择
|
||
void ProductAgingTestChooseView::AgingTestCheckBox::InitView(const char *desc)
|
||
{
|
||
auto selRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_PRODUCTION_CHOOSE, IMAGE_BIN_PATH);
|
||
auto unSelRes =
|
||
OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_PRODUCTION_CANCELLATION, IMAGE_BIN_PATH);
|
||
touchable_ = true;
|
||
checkBox_.SetPosition(0, 0, 32, 32);
|
||
if (selRes != nullptr && unSelRes != nullptr) {
|
||
checkBox_.SetImages(selRes, unSelRes);
|
||
}
|
||
checkBox_.SetTouchable(false);
|
||
|
||
InitLabelVerCenter(desc_, 28, checkBox_.GetWidth() + 19, 32, desc);
|
||
desc_.SetY(desc_.GetY() - 2);
|
||
|
||
Add(&checkBox_);
|
||
Add(&desc_);
|
||
}
|
||
|
||
ProductAgingTestChooseView::ProductAgingTestChooseView()
|
||
{
|
||
auto backRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_PRODUCTION_BACK, IMAGE_BIN_PATH);
|
||
auto enterRes = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_PRODUCTION_ENTER, IMAGE_BIN_PATH);
|
||
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
||
|
||
InitLabelHorCenter(title_, 28, 17, 466, "老化测试");
|
||
|
||
lcdCheckBox_.SetPosition(92, 95);
|
||
lcdCheckBox_.InitView("屏幕");
|
||
lcdCheckBox_.SetState(true);
|
||
heartRateCheckBox_.SetPosition(264, 95);
|
||
heartRateCheckBox_.InitView("心率");
|
||
heartRateCheckBox_.SetState(true);
|
||
motorCheckBox_.SetPosition(92, 174);
|
||
motorCheckBox_.InitView("马达");
|
||
motorCheckBox_.SetState(true);
|
||
speakerCheckBox_.SetPosition(264, 174);
|
||
speakerCheckBox_.InitView("喇叭");
|
||
speakerCheckBox_.SetState(true);
|
||
|
||
InitLabelHorCenter(lastTestTitle_, 28, 273, 466, "上次测试记录");
|
||
|
||
int startX = 38;
|
||
int startY = 332;
|
||
int height = 98;
|
||
int width = 419;
|
||
time_.SetPosition(startX, startY, width, height / 3);
|
||
power_.SetPosition(startX, startY + height / 3, width, height / 3);
|
||
func_.SetPosition(startX, startY + height * 2 / 3, width, height / 3);
|
||
|
||
time_.SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
||
time_.SetText("时间:00:00:00");
|
||
time_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_WRAP);
|
||
time_.SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_CENTER);
|
||
|
||
power_.SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
||
power_.SetText("电量:100%-50%");
|
||
power_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_WRAP);
|
||
power_.SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_CENTER);
|
||
|
||
func_.SetFont(TJD_VECTOR_FONT_FILENAME, 28);
|
||
func_.SetText("功能:屏幕、心率、马达、喇叭");
|
||
func_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_WRAP);
|
||
func_.SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_CENTER);
|
||
|
||
retButton_.SetPosition(52, 499, 179, 86);
|
||
if (backRes != nullptr) {
|
||
retButton_.SetSrc(backRes);
|
||
} else {
|
||
retButton_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xFF262626);
|
||
retButton_.SetStyle(OHOS::STYLE_BACKGROUND_OPA, OHOS::OPA_OPAQUE);
|
||
}
|
||
retButton_.SetTouchable(true);
|
||
retButton_.SetViewId(PRODUCT_BACK_BTN_VIEW_ID);
|
||
retButton_.SetOnClickListener(TjdUiAppProductPresenter::GetInstance());
|
||
|
||
nextButton_.SetPosition(235, 499, 231, 86);
|
||
if (enterRes != nullptr) {
|
||
nextButton_.SetSrc(enterRes);
|
||
} else {
|
||
nextButton_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xFF00E345);
|
||
nextButton_.SetStyle(OHOS::STYLE_BACKGROUND_OPA, OHOS::OPA_OPAQUE);
|
||
}
|
||
nextButton_.SetTouchable(true);
|
||
nextButton_.SetViewId(PRODUCT_NEXT_BTN_VIEW_ID);
|
||
nextButton_.SetOnClickListener(TjdUiAppProductPresenter::GetInstance());
|
||
|
||
Add(&title_);
|
||
Add(&lcdCheckBox_);
|
||
Add(&heartRateCheckBox_);
|
||
Add(&motorCheckBox_);
|
||
Add(&speakerCheckBox_);
|
||
Add(&lastTestTitle_);
|
||
Add(&time_);
|
||
Add(&power_);
|
||
Add(&func_);
|
||
Add(&retButton_);
|
||
Add(&nextButton_);
|
||
}
|
||
|
||
void ProductAgingTestChooseView::SetRecord(AngingTestResult &result)
|
||
{
|
||
char buf[64] = {0};
|
||
snprintf(buf, sizeof(buf), "时间:%02d:%02d:%02d", result.endTime_ / 3600, (result.endTime_ % 3600) / 60,
|
||
result.endTime_ % 60);
|
||
time_.SetText(buf);
|
||
|
||
snprintf(buf, sizeof(buf), "电量:%d%%-%d%%", result.startPower_, result.endPower_);
|
||
power_.SetText(buf);
|
||
|
||
snprintf(buf, sizeof(buf), "功能:");
|
||
if (result.testItem_.lcdTest) {
|
||
strcat(buf, "屏幕、");
|
||
}
|
||
if (result.testItem_.heartRate) {
|
||
strcat(buf, "心率、");
|
||
}
|
||
if (result.testItem_.motor) {
|
||
strcat(buf, "马达、");
|
||
}
|
||
if (result.testItem_.speaker) {
|
||
strcat(buf, "喇叭、");
|
||
}
|
||
func_.SetText(buf);
|
||
}
|
||
#pragma endregion
|
||
|
||
#pragma region 老化测试
|
||
ProductAgingTestView::ProductAgingTestView()
|
||
{
|
||
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
||
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0XFFD9001B);
|
||
|
||
InitLabelHorCenter(power_, 34, 19, 466, "100%");
|
||
InitLabelHorCenter(heartRateState_, 34, 118, 466, "心率工作中");
|
||
InitLabelCenter(motorState_, 34, 466, 466, "马达工作中");
|
||
InitLabelHorCenter(speakerState_, 34, 314, 466, "喇叭工作中");
|
||
InitLabelHorCenter(time_, 34, 414, 466, "00:00:00");
|
||
power_.SetTextColor(OHOS::Color::Black());
|
||
heartRateState_.SetTextColor(OHOS::Color::Black());
|
||
motorState_.SetTextColor(OHOS::Color::Black());
|
||
speakerState_.SetTextColor(OHOS::Color::Black());
|
||
time_.SetTextColor(OHOS::Color::Black());
|
||
|
||
Add(&power_);
|
||
Add(&heartRateState_);
|
||
Add(&motorState_);
|
||
Add(&speakerState_);
|
||
Add(&time_);
|
||
}
|
||
|
||
void ProductAgingTestView::SetTime(uint32_t time)
|
||
{
|
||
char buf[9] = {0};
|
||
snprintf(buf, sizeof(buf), "%02d:%02d:%02d", time / 3600, (time % 3600) / 60, time % 60);
|
||
time_.SetText(buf);
|
||
}
|
||
|
||
void ProductAgingTestView::SetPower(int power)
|
||
{
|
||
char buf[8] = {0};
|
||
snprintf(buf, sizeof(buf), "%d%%", power);
|
||
power_.SetText(buf);
|
||
}
|
||
|
||
void ProductAgingTestView::SetState(AngingTestItem &item)
|
||
{
|
||
if (item.heartRate) {
|
||
heartRateState_.SetText("心率工作中");
|
||
} else {
|
||
heartRateState_.SetText("心率停止");
|
||
}
|
||
|
||
if (item.motor) {
|
||
motorState_.SetText("马达工作中");
|
||
} else {
|
||
motorState_.SetText("马达停止");
|
||
}
|
||
|
||
if (item.speaker) {
|
||
speakerState_.SetText("喇叭工作中");
|
||
} else {
|
||
speakerState_.SetText("喇叭停止");
|
||
}
|
||
}
|
||
|
||
void ProductAgingTestView::SetColor(uint32_t color)
|
||
{
|
||
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, color);
|
||
Invalidate();
|
||
}
|
||
|
||
void ProductAgingTestView::Reset(void)
|
||
{
|
||
time_.SetText("00:00:00");
|
||
Invalidate();
|
||
}
|
||
#pragma endregion
|
||
|
||
#pragma region TP报点测试
|
||
ProductTpReportTestView::ProductTpReportTestView()
|
||
{
|
||
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
||
SetOnDragListener(TjdUiAppProductPresenter::GetInstance());
|
||
SetOnTouchListener(TjdUiAppProductPresenter::GetInstance());
|
||
canvas_.SetPosition(0, 0, 466, 466);
|
||
InitLabelHorCenter(pointLabel_, 28, 360, 466, "(0, 0)");
|
||
Add(&canvas_);
|
||
Add(&pointLabel_);
|
||
}
|
||
|
||
void ProductTpReportTestView::DragPos(OHOS::Point pos)
|
||
{
|
||
canvas_.Clear();
|
||
OHOS::PaintExt paint;
|
||
paint.SetStyle(OHOS::Paint::STROKE_FILL_STYLE);
|
||
paint.SetStrokeColor((OHOS::ColorType){.full = 0xFFFF0000});
|
||
paint.SetFillColor((OHOS::ColorType){.full = 0xFFFF0000});
|
||
canvas_.DrawCircle(pos, 10 / 2, paint);
|
||
|
||
OHOS::Point startH = {pos.x - lineLen / 2, pos.y};
|
||
OHOS::Point endH = {pos.x + lineLen / 2, pos.y};
|
||
canvas_.DrawLine(startH, endH, paint);
|
||
|
||
OHOS::Point startV = {pos.x, pos.y - lineLen / 2};
|
||
OHOS::Point endV = {pos.x, pos.y + lineLen / 2};
|
||
canvas_.DrawLine(startV, endV, paint);
|
||
|
||
std::ostringstream oss;
|
||
oss << "(" << pos.x << ", " << pos.y << ")";
|
||
pointLabel_.SetText(oss.str().c_str());
|
||
pointLabel_.SetX(HorizontalCenter(pointLabel_.GetWidth(), 466));
|
||
}
|
||
#pragma endregion
|
||
|
||
#pragma region GPS测试
|
||
TjdChartPlot::~TjdChartPlot()
|
||
{
|
||
RemoveAll();
|
||
for (auto it : uiDataMap_) {
|
||
delete it.second.column_;
|
||
delete it.second.number_;
|
||
delete it.second.type_;
|
||
delete it.second.value_;
|
||
}
|
||
}
|
||
|
||
void TjdChartPlot::RefrashPlot()
|
||
{
|
||
currentPos_ = 0;
|
||
for (auto gsv : *gsvData) {
|
||
std::string number = gsv.first;
|
||
int showValue = gsv.second;
|
||
auto it = uiDataMap_.find(number);
|
||
if (it != uiDataMap_.end()) {
|
||
OHOS::UIView *column_ = uiDataMap_[gsv.first].column_;
|
||
OHOS::UILabel *value = uiDataMap_[gsv.first].value_;
|
||
const int16_t viewHeight = CalculateViewHeight(showValue);
|
||
const int16_t viewY = CalculateViewY(viewHeight);
|
||
if (showValue >= 30) {
|
||
column_->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xFF12D051);
|
||
} else if (showValue >= 15) {
|
||
column_->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xFFE6E046);
|
||
} else {
|
||
column_->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xFFFF0000);
|
||
}
|
||
column_->SetPosition(column_->GetX(), viewY, column_->GetWidth(), viewHeight);
|
||
std::string valueStr = std::to_string(showValue);
|
||
value->SetText(valueStr.c_str());
|
||
value->SetPosition(column_->GetX() + HorizontalCenter(value->GetWidth(), 24),
|
||
column_->GetY() - value->GetHeight() - 8);
|
||
} else {
|
||
AddColumn(gsv.first, gsv.second);
|
||
}
|
||
};
|
||
Invalidate();
|
||
}
|
||
|
||
void TjdChartPlot::AddColumn(std::string number, int showValue)
|
||
{
|
||
OHOS::UIView *view = new OHOS::UIView();
|
||
view->SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff);
|
||
view->SetStyle(OHOS::STYLE_BORDER_RADIUS, 0x6);
|
||
|
||
UIView *tailView = GetChildrenTail();
|
||
if (tailView != nullptr) {
|
||
currentPos_ = tailView->GetX() + tailView->GetWidth() + interval_;
|
||
}
|
||
|
||
const int16_t viewHeight = CalculateViewHeight(showValue);
|
||
const int16_t viewY = CalculateViewY(viewHeight);
|
||
view->SetPosition(currentPos_, viewY, weight_, viewHeight);
|
||
if (showValue >= 30) {
|
||
view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xFF12D051);
|
||
} else if (showValue >= 15) {
|
||
view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xFFE6E046);
|
||
} else {
|
||
view->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xFFFF0000);
|
||
}
|
||
|
||
OHOS::UILabel *name = new OHOS::UILabel();
|
||
std::string text = std::to_string(GetStarNumber(number));
|
||
name->SetFont(TJD_VECTOR_FONT_FILENAME, 14);
|
||
name->SetText(text.c_str());
|
||
name->SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ELLIPSIS);
|
||
name->SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff);
|
||
name->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xffffffff);
|
||
name->SetStyle(OHOS::STYLE_BORDER_RADIUS, 0x3);
|
||
name->SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
||
name->SetPosition(view->GetX(), view->GetY() + view->GetHeight() + 13, 26, 22);
|
||
name->SetStyle(OHOS::STYLE_TEXT_COLOR, 0xff000000);
|
||
|
||
OHOS::UILabel *type = new OHOS::UILabel();
|
||
type->SetFont(TJD_VECTOR_FONT_FILENAME, 14);
|
||
type->SetText(GetGnssType(number).c_str());
|
||
type->SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ELLIPSIS);
|
||
type->SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff);
|
||
type->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xffffffff);
|
||
type->SetStyle(OHOS::STYLE_BORDER_RADIUS, 0x3);
|
||
type->SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
||
type->SetPosition(view->GetX(), name->GetY() + name->GetHeight() + 13, 26, 22);
|
||
type->SetStyle(OHOS::STYLE_TEXT_COLOR, 0xff000000);
|
||
|
||
std::string valueStr = std::to_string(showValue);
|
||
OHOS::UILabel *value = new OHOS::UILabel();
|
||
value->SetFont(TJD_VECTOR_FONT_FILENAME, 20);
|
||
value->SetText(valueStr.c_str());
|
||
value->SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
|
||
value->SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
||
value->SetPosition(view->GetX() + HorizontalCenter(value->GetWidth(), 24), view->GetY() - value->GetHeight() - 8);
|
||
Add(name);
|
||
Add(type);
|
||
Add(value);
|
||
Add(view);
|
||
uiDataMap_[number] = {view, name, value, type};
|
||
}
|
||
|
||
ProductGPSTestView::ProductGPSTestView()
|
||
{
|
||
Resize(466, 466);
|
||
plot.SetPosition(53, 135, 360, 300);
|
||
InitLabelHorCenter(title, 24, 17, GetHeight(), "星历数据");
|
||
InitLabelHorCenter(visibleStarDesc, 24, 17, GetHeight(), "可见");
|
||
visibleStarDesc.SetPosition(102, 59);
|
||
visibleStarDesc.SetStyle(OHOS::STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.3);
|
||
|
||
visibleStarValue.SetFont(TJD_VECTOR_FONT_FILENAME, 40);
|
||
visibleStarValue.SetText("0");
|
||
visibleStarValue.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_WRAP);
|
||
visibleStarValue.SetPosition(102, 90, 48, 29);
|
||
visibleStarValue.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
||
|
||
InitLabelHorCenter(usableStarDesc, 24, 17, GetHeight(), "可用");
|
||
usableStarDesc.SetPosition(318, 59);
|
||
usableStarDesc.SetStyle(OHOS::STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.3);
|
||
|
||
usableStarValue.SetFont(TJD_VECTOR_FONT_FILENAME, 40);
|
||
usableStarValue.SetText("0");
|
||
usableStarValue.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_WRAP);
|
||
usableStarValue.SetPosition(319, 90, 48, 29);
|
||
usableStarValue.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
||
|
||
line_.SetPosition(53, 340, 360, 1);
|
||
line_.SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff);
|
||
line_.SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xffffffff);
|
||
line_.SetStyle(OHOS::STYLE_BACKGROUND_OPA, OHOS::OPA_OPAQUE * 0.5);
|
||
|
||
InitLabelHorCenter(state, 24, 415, 466, "正常");
|
||
|
||
Add(&plot);
|
||
Add(&title);
|
||
Add(&visibleStarDesc);
|
||
Add(&visibleStarValue);
|
||
Add(&usableStarDesc);
|
||
Add(&usableStarValue);
|
||
Add(&state);
|
||
Add(&line_);
|
||
|
||
plot.SetData(&TjdUiAppProductPresenter::GetInstance()->GetGsvData());
|
||
plot.DrawPlot();
|
||
}
|
||
|
||
ProductGPSTestView::~ProductGPSTestView() { RemoveAll(); }
|
||
|
||
void ProductGPSTestView::SetState(const char *text)
|
||
{
|
||
state.SetText(text);
|
||
state.SetX(HorizontalCenter(state.GetWidth(), 466));
|
||
state.Invalidate();
|
||
}
|
||
|
||
void ProductGPSTestView::SetUsableStar(int value)
|
||
{
|
||
if (value == -1) {
|
||
return;
|
||
}
|
||
usableStarValue.SetText(std::to_string(value).c_str());
|
||
}
|
||
|
||
void ProductGPSTestView::SetVisibleStar(int value)
|
||
{
|
||
if (value == -1) {
|
||
return;
|
||
}
|
||
visibleStarValue.SetText(std::to_string(value).c_str());
|
||
}
|
||
#pragma endregion
|
||
|
||
} // namespace TJD
|