From 895d9b9ff3f229245828f71893ffc47719df6a4c Mon Sep 17 00:00:00 2001 From: penglei <1624952103@qq.com> Date: Tue, 19 Aug 2025 19:51:56 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E6=94=B9=E4=BA=A7=E6=B5=8B=E4=BB=A3?= =?utf8?q?=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../zhihui/UI/producttest/include/testModel.h | 12 +- .../zhihui/UI/producttest/include/testView.h | 65 +++-- .../zhihui/UI/producttest/src/testModel.cpp | 187 +++++++------- .../UI/producttest/src/testPresenter.cpp | 3 + .../zhihui/UI/producttest/src/testView.cpp | 236 ++++++++++-------- 5 files changed, 268 insertions(+), 235 deletions(-) diff --git a/code/sdk/zhihui/UI/producttest/include/testModel.h b/code/sdk/zhihui/UI/producttest/include/testModel.h index 2dd2a5682..e73117535 100644 --- a/code/sdk/zhihui/UI/producttest/include/testModel.h +++ b/code/sdk/zhihui/UI/producttest/include/testModel.h @@ -1,3 +1,11 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2025-08-19 18:24:19 + * @LastEditors: penglei 1624952103@qq.com + * @LastEditTime: 2025-08-19 18:34:47 + * @FilePath: /FD230/code/sdk/zhihui/UI/producttest/include/testModel.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ #ifndef TEST_MODEL_H #define TEST_MODEL_H #include @@ -62,9 +70,9 @@ namespace OHOS public: static testModel *GetInstance(void); void testModelupdata(int); - bool SetResult(int viewId, bool pass); + bool SetResult(int viewId, test_status_enum pass); bool SetResult(std::string viewIdstr); - bool GetResult(int viewId); + test_status_enum GetResult(int viewId); std::string GetSummaryString(); std::string GetViewId(int viewid); diff --git a/code/sdk/zhihui/UI/producttest/include/testView.h b/code/sdk/zhihui/UI/producttest/include/testView.h index 5520e49c1..f23bfe141 100644 --- a/code/sdk/zhihui/UI/producttest/include/testView.h +++ b/code/sdk/zhihui/UI/producttest/include/testView.h @@ -1,7 +1,6 @@ #ifndef TEST_VIEW_H #define TEST_VIEW_H - #include "View.h" #include "components/ui_view_group.h" @@ -11,19 +10,20 @@ #include "components/ui_image_view.h" #include "components/ui_button.h" #include "components/ui_label_button_ext.h" +#include "components/ui_label_button.h" #include "producttest/include/testabout.h" #include "producttest/include/testLCD.h" #include "producttest/include/testTP.h" #include "producttest/include/testluminance.h" #include "producttest/include/testchanging.h" -#include "producttest/include/testspeak.h" +#include "producttest/include/testspeak.h" #include "producttest/include/testmotor.h" #include "producttest/include/testbutton.h" #include "producttest/include/testmagnetic.h" #include "producttest/include/testmicrophone.h" -#include "producttest/include/testcat1.h" -#include "producttest/include/testhrsenson.h" +#include "producttest/include/testcat1.h" +#include "producttest/include/testhrsenson.h" #include "producttest/include/testgsenson.h" #include "producttest/include/testold.h" #include "producttest/include/testbt.h" @@ -40,10 +40,7 @@ #endif namespace OHOS { - - - class testPresenter; class testView : public View { @@ -54,7 +51,7 @@ namespace OHOS static testView *GetInstance(void); void OnStart() override; - + struct ButtonConfig { int x; @@ -74,14 +71,13 @@ namespace OHOS const char *ViewId; const char *ImageSrc; - //label + // label int label_x; int label_y; uint8_t ALIGN; - int Fontsize; - + int Fontsize; }; - + bool ChangeSystemView(int16_t thisView); bool ChangeSystemAboutView(int16_t thisView); bool ChangeLCDTESTView(int16_t thisView); @@ -106,22 +102,24 @@ namespace OHOS #ifdef ENABLE_LQBP002TA bool ChangepressureTestTESTView(int16_t thisView); #endif - #ifdef SUPPORT_A5133_SERVICE +#ifdef SUPPORT_A5133_SERVICE bool ChangeA5133TESTView(int16_t thisView); - #endif +#endif bool ClickFunc(int16_t interface); void ChangeView(int16_t hideView, int16_t showView); UIScrollView *GetSystemScrollView(int ViewId); + void AddResultButtons(UIScrollView *scrollView, int16_t viewId); + private: void InitIView(void); - void initView_ext(int x,int y,int w,int h,int interval,const char *imagsrc); + void initView_ext(int x, int y, int w, int h, int interval, const char *imagsrc); void ClearAll(void); bool SetTheSystemScrollView(void); bool SetTheTitle(void); UIButton *SetTheButton(ButtonConfig &buttonconfig, UIView::OnClickListener *clickListener); UILabelButtonExt *SetTheButton_ext(ButtonConfig_ext_t &ButtonConfig_ext, UIView::OnClickListener *clickListener); - + testAboutView *test_about_view; UIScrollView *SystemScrollView[30]{nullptr}; UIViewGroup *group{nullptr}; @@ -150,30 +148,27 @@ namespace OHOS testGPSView *test_GPS_view{nullptr}; #endif #ifdef ENABLE_LQBP002TA - testpressureView * test_pressure_view{nullptr}; + testpressureView *test_pressure_view{nullptr}; #endif - #ifdef SUPPORT_A5133_SERVICE - testA5133View *test_A5133_view{nullptr}; - #endif - UILabelButtonExt *button[30]={NULL}; +#ifdef SUPPORT_A5133_SERVICE + testA5133View *test_A5133_view{nullptr}; +#endif + UILabelButtonExt *button[30] = {NULL}; bool initViewStatus{false}; + + UILabelButton *oktestBtn{nullptr}; + UILabelButton *failtestBtn{nullptr}; }; - struct test_ext + struct test_ext { - const int16_t viewId; - char *viewid_str; - char *Labe_str; - char *viewid_str_next; - bool (testView::*func)(int16_t thisView); - bool enable_falg; + const int16_t viewId; + char *viewid_str; + char *Labe_str; + char *viewid_str_next; + bool (testView::*func)(int16_t thisView); + bool enable_falg; }; - extern test_ext Test_ViewMapper_t[]; - - - - UILabelButtonExt *okBtn{nullptr}; - UILabelButtonExt *failBtn{nullptr}; - + extern test_ext Test_ViewMapper_t[]; } // namespace OHOS diff --git a/code/sdk/zhihui/UI/producttest/src/testModel.cpp b/code/sdk/zhihui/UI/producttest/src/testModel.cpp index 9676f28ed..f53318330 100644 --- a/code/sdk/zhihui/UI/producttest/src/testModel.cpp +++ b/code/sdk/zhihui/UI/producttest/src/testModel.cpp @@ -2,53 +2,54 @@ * @Author: penglei 1624952103@qq.com * @Date: 2024-08-22 16:59:44 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2025-08-16 14:51:45 + * @LastEditTime: 2025-08-19 19:31:32 * @FilePath: /FD230/code/sdk/application/wearable/fd230/nativeapp/nativeui/producttest/src/testModel.cpp -* @Description: - * - * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. + * @Description: + * + * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. */ #include "producttest/include/testModel.h" #include "producttest/include/testPresenter.h" #include "producttest/include/testLCDC.h" #include "producttest/include/testTPC.h" +#include "wearable_log.h" #include "custom_utils.h" namespace OHOS { - //测试结果数组 + // 测试结果数组 test_status_t test_status_list[MAX_TEST_ITEM] = { - { LCD_TEST, TEST_STATUS_NONE, "LCD_Test" }, - { TP_TEST, TEST_STATUS_NONE, "Touch_Panel_Test" }, - { MAGNETIC_TEST, TEST_STATUS_NONE, "Magnetic_Test" }, - { LUMINANCE_TEST, TEST_STATUS_NONE, "Luminance_Test" }, - { BAT_TEST, TEST_STATUS_NONE, "Battery_Charger_Test" }, - { SPK_TEST, TEST_STATUS_NONE, "Speaker_Test" }, - { KEY_TEST, TEST_STATUS_NONE, "Key_Test" }, - { MOTOR_TEST, TEST_STATUS_NONE, "Motor_Vibration_Test" }, - { HR_TEST, TEST_STATUS_NONE, "Heart_Rate_Sensor_Test" }, - { GSENSOR_TEST, TEST_STATUS_NONE, "G_Sensor_Test" }, - { CAT1_TEST, TEST_STATUS_NONE, "CAT1_Module_Test" }, - { BUTTON_TEST, TEST_STATUS_NONE, "Physical_Buttons_Test" }, - { BT_TEST, TEST_STATUS_NONE, "Bluetooth_Test" }, - { APPI_TEST, TEST_STATUS_NONE, "SE_Chip_Test" }, - { GPS_TEST, TEST_STATUS_NONE, "GPS_Position_Test" }, - // { LOWPOWER_TEST, TEST_STATUS_NONE, "Deep_Sleep_Current_Test" }, + {LCD_TEST, TEST_STATUS_NONE, "LCD"}, + {TP_TEST, TEST_STATUS_NONE, "Touch_Panel"}, + {MAGETIC_TEST, TEST_STATUS_NONE, "Magnetic"}, + {LUMINANCE_TEST, TEST_STATUS_NONE, "Luminance"}, + {BAT_TEST, TEST_STATUS_NONE, "BatteryCharger"}, + {SPK_TEST, TEST_STATUS_NONE, "Speaker"}, + {KEY_TEST, TEST_STATUS_NONE, "Key"}, + {MOTOR_TEST, TEST_STATUS_NONE, "Motor"}, + {HR_TEST, TEST_STATUS_NONE, "Heart_Rate"}, + {GSENSOR_TEST, TEST_STATUS_NONE, "G_Sensor"}, + {CAT1_TEST, TEST_STATUS_NONE, "CAT1"}, + {BUTTON_TEST, TEST_STATUS_NONE, "Buttons"}, + {BT_TEST, TEST_STATUS_NONE, "Bluetooth"}, + {APPI_TEST, TEST_STATUS_NONE, "SE_Chip"}, + {GPS_TEST, TEST_STATUS_NONE, "GPS"}, + // { LOWPOWER_TEST, TEST_STATUS_NONE, "Deep_Sleep_Current" }, }; - //设置测试结果 + // 设置测试结果 bool testModel::SetResult(int viewId, test_status_enum pass) { - //判断viewId是否在测试项枚举范围内 - if(viewId < 0 || viewId >= MAX_TEST_ITEM) + // 判断viewId是否在测试项枚举范围内 + if (viewId < 0 || viewId >= MAX_TEST_ITEM) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "testModel::SetResult: viewId out of range"); return false; } - //记录开始时间 - if(is_first_test) + // 记录开始时间 + if (is_first_test) { - //设置测试开始时间 + // 设置测试开始时间 char current_time[9]; // 分配内存给current_time if (uapi_get_HHMMSS_Time(current_time, ':', true) != ERRCODE_SUCC) { @@ -57,21 +58,22 @@ namespace OHOS m_start_time = current_time; is_first_test = false; } - //更新测试结果 + // 更新测试结果 test_status_list[viewId].status = pass ? TEST_STATUS_SUCCESS : TEST_STATUS_ERROR; return true; } - //通过测试项描述进行更新 + // 通过测试项描述进行更新 bool testModel::SetResult(std::string viewIdstr) { - //解析执行结果 + printf("目前传过来的idstr:%s\n", viewIdstr.c_str()); + // 解析执行结果 test_status_enum status = TEST_STATUS_NONE; - if(strncmp(viewIdstr.c_str(), "TestOK", 6) == 0) + if (strncmp(viewIdstr.c_str(), "TestOK", 6) == 0) { status = TEST_STATUS_SUCCESS; } - else if(strncmp(viewIdstr.c_str(), "TestNO", 6) == 0) + else if (strncmp(viewIdstr.c_str(), "TestNO", 6) == 0) { status = TEST_STATUS_ERROR; } @@ -80,17 +82,18 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "testModel::SetResult: invalid status string"); return false; } - - //提取测试项描述(跳过前面的"TestOK"或"TestNO") + + // 提取测试项描述(跳过前面的"TestOK"或"TestNO") std::string desc = viewIdstr.substr(6); - - //查找匹配的测试项并更新状态 - for(int i = 0; i < MAX_TEST_ITEM; i++) + printf("提取的测试项:%s\n", desc.c_str()); + + // 查找匹配的测试项并更新状态 + for (int i = 0; i < MAX_TEST_ITEM; i++) { - if(strcmp(test_status_list[i].desc, desc.c_str()) == 0) + if (strcmp((test_status_list[i].test_result).c_str(), desc.c_str()) == 0) { - //记录开始时间(与ID更新方式保持一致) - if(is_first_test) + // 记录开始时间(与ID更新方式保持一致) + if (is_first_test) { char current_time[9]; if (uapi_get_HHMMSS_Time(current_time, ':', true) != ERRCODE_SUCC) @@ -100,62 +103,62 @@ namespace OHOS m_start_time = current_time; is_first_test = false; } - - //更新测试状态 + + // 更新测试状态 test_status_list[i].status = status; return true; } } - - //未找到匹配的测试项 + + // 未找到匹配的测试项 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "testModel::SetResult: test item not found - %s", desc.c_str()); return false; } - //获取测试结果 + // 获取测试结果 test_status_enum testModel::GetResult(int viewId) { - if(viewId < 0 || viewId >= MAX_TEST_ITEM) + if (viewId < 0 || viewId >= MAX_TEST_ITEM) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "testModel::GetResult: viewId out of range"); - return false; + return TEST_STATUS_NONE; } return test_status_list[viewId].status; } - //获取描述str - std::string testModel::GetViewId(int viewid) + // 获取描述str + std::string testModel::GetViewId(int viewId) { - if(viewId < 0 || viewId >= MAX_TEST_ITEM) + if (viewId < 0 || viewId >= MAX_TEST_ITEM) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "testModel::GetResult: viewId out of range"); - return false; + return nullptr; } return test_status_list[viewId].test_result; } - //汇总测试项结果 + // 汇总测试项结果 std::string testModel::GetSummaryString() { - //清空测试结果总结 + // 清空测试结果总结 m_summary.clear(); m_skipped_tests = 0; m_failed_tests = 0; - //进行编译 设置未测试的测试项;未通过的测试项; - for(int i = 0; i < MAX_TEST_ITEM; i++) + // 进行编译 设置未测试的测试项;未通过的测试项; + for (int i = 0; i < MAX_TEST_ITEM; i++) { - if(test_status_list[i].status == TEST_STATUS_NONE) + if (test_status_list[i].status == TEST_STATUS_NONE) { m_summary += test_status_list[i].test_result + "未测试\n"; m_skipped_tests++; } - else if(test_status_list[i].status == TEST_STATUS_ERROR) + else if (test_status_list[i].status == TEST_STATUS_ERROR) { m_summary += test_status_list[i].test_result + "未通过\n"; m_failed_tests++; } } - + return m_summary; } @@ -167,48 +170,44 @@ namespace OHOS void testModel::testModelupdata(int type) { - printf("testModelupdata : %d\n",type); + printf("testModelupdata : %d\n", type); switch (type) { - case 1: - if( testView::GetInstance()) - { - testView::GetInstance()->ChangeView(TESTVIEW,LCD); - factorytest_hide_test_lcd_button(); - } - break; + case 1: + if (testView::GetInstance()) + { + testView::GetInstance()->ChangeView(TESTVIEW, LCD); + factorytest_hide_test_lcd_button(); + } + break; - case 2: - if( testView::GetInstance()) - { - testView::GetInstance()->ChangeView(TESTVIEW,TP); - factorytest_hide_test_tp_button(); - } - break; - - case 3: - if( testView::GetInstance()) - { - testView::GetInstance()->ChangeView(TESTVIEW,BUTTON); - factorytest_hide_test_lcd_button(); - } - break; + case 2: + if (testView::GetInstance()) + { + testView::GetInstance()->ChangeView(TESTVIEW, TP); + factorytest_hide_test_tp_button(); + } + break; - case 4: - if( testView::GetInstance()) - { - testView::GetInstance()->ChangeView(TESTVIEW,OLDTEST); - factorytest_hide_test_lcd_button(); - } - break; + case 3: + if (testView::GetInstance()) + { + testView::GetInstance()->ChangeView(TESTVIEW, BUTTON); + factorytest_hide_test_lcd_button(); + } + break; - default: - break; - } + case 4: + if (testView::GetInstance()) + { + testView::GetInstance()->ChangeView(TESTVIEW, OLDTEST); + factorytest_hide_test_lcd_button(); + } + break; + default: + break; + } } - - - } \ No newline at end of file diff --git a/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp b/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp index d55e87d52..7abf16fd7 100644 --- a/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp +++ b/code/sdk/zhihui/UI/producttest/src/testPresenter.cpp @@ -230,14 +230,17 @@ namespace OHOS } // 处理各测试界面的 成功/失败 按钮 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"view.GetViewId() %s ",view.GetViewId()); if (strncmp(view.GetViewId(), "TestOK", 6) == 0 || strncmp(view.GetViewId(), "TestNO", 6) == 0) { std::string vid = view.GetViewId(); if(testModel::GetInstance()->SetResult(vid)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"222"); return true; } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"111"); return false; } diff --git a/code/sdk/zhihui/UI/producttest/src/testView.cpp b/code/sdk/zhihui/UI/producttest/src/testView.cpp index 14ccf1e92..c2575c794 100644 --- a/code/sdk/zhihui/UI/producttest/src/testView.cpp +++ b/code/sdk/zhihui/UI/producttest/src/testView.cpp @@ -1,5 +1,6 @@ #include "producttest/include/testView.h" #include "producttest/include/testPresenter.h" +#include "producttest/include/testModel.h" #include "components/ui_label_button.h" #include "power_display_service.h" #include "wearable_log.h" @@ -50,7 +51,7 @@ namespace OHOS #ifdef SUPPORT_CAT1_SERVICE {CAT1, "cat1button", "CAT1", "cat1button_next", &testView::ChangeCAT1TESTView, true}, #endif - {BUTTON, "buttonbutton", "button", "buttonbutton_next", &testView::ChangKEYTESTView, true}, + {BUTTON, "buttonbutton", "oktestBtn", "buttonbutton_next", &testView::ChangKEYTESTView, true}, {MICROPHONE, "microphonebutton", "microphone", "microphonebutton_next", &testView::ChangeMPTESTView, true}, {HRSENSON, "hrsensonbutton", "hrsensor", "hrsensonbutton_next", &testView::ChangeHRTESTView, true}, {GSENSON, "gsensonbutton", "gsensor", "gsensonbutton_next", &testView::ChangeGTESTView, true}, @@ -120,15 +121,15 @@ namespace OHOS } } ///////////////////////// - if(okBtn) - { - delete okBtn; - okBtn = nullptr; + if (oktestBtn) + { + delete oktestBtn; + oktestBtn = nullptr; } - if(failBtn) - { - delete failBtn; - failBtn = nullptr; + if (failtestBtn) + { + delete failtestBtn; + failtestBtn = nullptr; } ///////////////////////////// if (test_about_view) @@ -274,33 +275,133 @@ namespace OHOS return true; } + void testView::AddResultButtons(UIScrollView *scrollView, int16_t viewId) + { + if (scrollView == nullptr) + { + return; + } + + printf("目前测试项id:%d",viewId); + + // 创建新按钮(如果当前按钮为空) + if (oktestBtn == nullptr) + { + oktestBtn = new UILabelButton(); + if (oktestBtn == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitButtonExt is error"); + return; // 内存分配失败,返回false + } + oktestBtn->SetPosition(40, 80); + oktestBtn->Resize(135, 88); + + oktestBtn->SetStyle(STYLE_TEXT_FONT, 30); + oktestBtn->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + } + if (failtestBtn == nullptr) + { + failtestBtn = new UILabelButton(); + if (failtestBtn == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitButtonExt is error"); + return; // 内存分配失败,返回false + } + failtestBtn->SetPosition(220, 80); + failtestBtn->Resize(135, 88); + + failtestBtn->SetStyle(STYLE_TEXT_FONT, 30); + failtestBtn->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + } + + // 获取当前测试项状态 + test_status_enum status = testModel::GetInstance()->GetResult(viewId); + printf("目前该项的测试状态为:%d\n",status); + // 获取测试项描述 + std::string viewDesc = testModel::GetInstance()->GetViewId(viewId); + printf("目前测试项的描述是:%s\n",viewDesc.c_str()); + + if (oktestBtn) + { + oktestBtn->SetText("成功"); + oktestBtn->SetAlign(TEXT_ALIGNMENT_CENTER); + // 根据状态设置按钮样式 + switch (status) + { + case TEST_STATUS_NONE: + oktestBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + break; + case TEST_STATUS_SUCCESS: + oktestBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Green().full); + break; + case TEST_STATUS_ERROR: + oktestBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + break; + } + + // 设置按钮标识 + std::string okIdStr = "TestOK" + viewDesc; + printf("设置 按键的viewId %s\n", okIdStr.c_str()); + oktestBtn->SetViewId(okIdStr.c_str()); + oktestBtn->SetOnClickListener(testPresenter::GetInstance()); + scrollView->Add(oktestBtn); + } + + if (failtestBtn) + { + failtestBtn->SetText("失败"); + failtestBtn->SetAlign(TEXT_ALIGNMENT_CENTER); + + // 根据状态设置按钮样式 + switch (status) + { + case TEST_STATUS_NONE: + failtestBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + break; + case TEST_STATUS_SUCCESS: + failtestBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); + break; + case TEST_STATUS_ERROR: + failtestBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full); + break; + } + + // 设置按钮标识(修复了原代码中的错误) + std::string failIdStr = "TestNO" + viewDesc; + printf("设置 按键的viewId %s\n", failIdStr.c_str()); + failtestBtn->SetViewId(failIdStr.c_str()); + failtestBtn->SetOnClickListener(testPresenter::GetInstance()); + scrollView->Add(failtestBtn); + } + } + /// @brief 设置按钮 - /// @param button + /// @param oktestBtn /// @return true 设置成功,false 失败 UILabelButtonExt *testView::SetTheButton_ext(ButtonConfig_ext_t &buttonconfig, UIView::OnClickListener *clickListener) { - UILabelButtonExt *button = new UILabelButtonExt(); - if (button == nullptr) + UILabelButtonExt *oktestBtn = new UILabelButtonExt(); + if (oktestBtn == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SystemView::SetTheButton: button new fail!"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SystemView::SetTheButton: oktestBtn new fail!"); return nullptr; } - button->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h); - button->SetViewId(buttonconfig.ViewId); - button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - button->SetImageSrc(buttonconfig.ImageSrc, buttonconfig.ImageSrc); - button->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - button->SetOnClickListener(clickListener); - - button->SetText(buttonconfig.str); - button->SetAlign(TEXT_ALIGNMENT_LEFT); - button->SetLabelPosition(buttonconfig.label_x, buttonconfig.label_y); - button->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, buttonconfig.Fontsize); - // button->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - - button->SetImagePosition(326, 37); - return button; + oktestBtn->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h); + oktestBtn->SetViewId(buttonconfig.ViewId); + oktestBtn->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + oktestBtn->SetImageSrc(buttonconfig.ImageSrc, buttonconfig.ImageSrc); + oktestBtn->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + oktestBtn->SetOnClickListener(clickListener); + + oktestBtn->SetText(buttonconfig.str); + oktestBtn->SetAlign(TEXT_ALIGNMENT_LEFT); + oktestBtn->SetLabelPosition(buttonconfig.label_x, buttonconfig.label_y); + oktestBtn->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, buttonconfig.Fontsize); + // oktestBtn->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + + oktestBtn->SetImagePosition(326, 37); + return oktestBtn; } void testView::initView_ext(int x, int y, int w, int h, int interval, const char *imagsrc) @@ -418,7 +519,7 @@ namespace OHOS return false; } SystemScrollView[thisView] = test_MG_view->testmagicInitIView(thisView); - AddResultButtons(SystemScrollView[thisView], MAGNETIC_TEST); + AddResultButtons(SystemScrollView[thisView], MAGETIC_TEST); group->Add(SystemScrollView[thisView]); } return true; @@ -944,8 +1045,8 @@ namespace OHOS display_api->set_auto_timeout_function(false); uint8_t cnt = pm_veto_get_id_cnt(PM_ID_P_TEST); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cnt : %d\n",cnt); - if (cnt == 0) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cnt : %d\n", cnt); + if (cnt == 0) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_pm_add_sleep_veto(PM_ID_P_TEST);"); uapi_pm_add_sleep_veto(PM_ID_P_TEST); @@ -971,77 +1072,4 @@ namespace OHOS AddViewToRootContainer(group); } - int16_t testView::GetCurrentViewId() - { - return m_currentViewId; - } - - void testView::AddResultButtons(UIScrollView *scrollView, int16_t viewId) -{ - if (scrollView == nullptr) { - return; - } - - // 放到上方,避免被内容遮挡 - if(okBtn == nullptr) - okBtn = testAboutView::GetInstance()->init_button_next(40, 80, (char*)"TestOK"); - if(failBtn == nullptr) - failBtn = testAboutView::GetInstance()->init_button_next(220, 80, (char*)"TestNO"); - - // 获取当前测试项状态 - test_status_enum status = testModel::GetInstance()->GetResult(viewId); - // 获取测试项描述 - std::string viewDesc = testModel::GetInstance()->GetViewId(viewId); - - if (okBtn) { - okBtn->SetText("成功"); - okBtn->SetAlign(TEXT_ALIGNMENT_CENTER); - - // 根据状态设置按钮样式 - switch(status) - { - case TEST_STATUS_NONE: - okBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); - break; - case TEST_STATUS_SUCCESS: - okBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Green().full); - break; - case TEST_STATUS_ERROR: - okBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); - break; - } - - // 设置按钮标识 - std::string okIdStr = "TestOK" + viewDesc; - okBtn->SetViewId(okIdStr.c_str()); - scrollView->Add(okBtn); - okBtn->SetOnClickListener(testPresenter::GetInstance()); - } - - if (failBtn) { - failBtn->SetText("失败"); - failBtn->SetAlign(TEXT_ALIGNMENT_CENTER); - - // 根据状态设置按钮样式 - switch(status) - { - case TEST_STATUS_NONE: - failBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); - break; - case TEST_STATUS_SUCCESS: - failBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray().full); - break; - case TEST_STATUS_ERROR: - failBtn->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full); - break; - } - - // 设置按钮标识(修复了原代码中的错误) - std::string failIdStr = "TestNO" + viewDesc; - failBtn->SetViewId(failIdStr.c_str()); - scrollView->Add(failBtn); - failBtn->SetOnClickListener(testPresenter::GetInstance()); - } -} - } // namespace OHOS \ No newline at end of file -- 2.17.1