From ac55ef8ee06872f67d4ea48bbad242b981da9508 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Tue, 8 Oct 2024 14:46:23 +0800 Subject: [PATCH] =?utf8?q?=E7=B3=BB=E7=BB=9F=EF=BC=9A=E5=AE=89=E5=85=A8?= =?utf8?q?=E6=A8=A1=E5=BC=8F=E5=A2=9E=E5=8A=A0=E6=89=8B=E8=A1=A8=E8=93=9D?= =?utf8?q?=E7=89=99=E5=90=8D=E7=A7=B0=EF=BC=8C=E7=89=88=E6=9C=AC=E5=8F=B7?= =?utf8?q?=EF=BC=8C=E5=9B=BA=E4=BB=B6=E7=89=88=E6=9C=AC=E7=AD=89=E7=9B=B8?= =?utf8?q?=E5=85=B3=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../include/SafeModeManagerModel.h | 5 + .../include/SafeModeManagerView.h | 44 ++++- .../src/SafeModeManagerModel.cpp | 42 ++++- .../src/SafeModeManagerView.cpp | 158 ++++++++---------- 4 files changed, 153 insertions(+), 96 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerModel.h b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerModel.h index 663967e7a..ea7b45279 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerModel.h @@ -100,6 +100,11 @@ public: // 输出当前状态 void PrintState() const; + /* ---------------------------------- 手表信息 + * ---------------------------------- */ + std::string get_voltage_and_version_string(); + std::string get_bluetooth_name(); + private: SafeModeManagerModel() = default; // 默认构造函数 ~SafeModeManagerModel() = default; // 默认析构函数 diff --git a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerView.h b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerView.h index 3a9617033..7c926bc56 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/SafeModeManagerView.h @@ -28,6 +28,37 @@ typedef enum { MAX_VIEW_ID, // Maximum View ID } SafeViewID; +// 定义结构体用于位置设置 +struct Position { + int x; + int y; +}; + +// 初始化背景项及其位置 +struct BackgroundItem { + UIImageView *background; + Position position; +}; +// 定义按钮 +struct ButtonItem { + UIToggleButton *button; + Position position; + const char *viewId; +}; + +// 定义功能状态标签 +struct StatusLabelItem { + UILabel *label; + std::string text; + Position position; +}; + +struct SafeViewItem { + BackgroundItem background; + ButtonItem button; + StatusLabelItem statusLabel; +}; + class SafeModeManagerPresenter; class ResourceCheckView; @@ -71,7 +102,8 @@ private: SafeModeManagerView &operator=(SafeModeManagerView &&) = delete; // UI Components - UILabelExt labelTitle_; // Title Label + UILabel labelTitle_; // Title Label + UILabel labelInfo_; // Background Images for Features UIImageView backgroundBLE_; // BLE OTA Background Image @@ -88,11 +120,11 @@ private: UIToggleButton btnRestart_; // Restart Toggle Button // Status Labels - UILabelExt labelBLEStatus_; // BLE OTA Status Label - UILabelExt labelAutoOTAStatus_; // Auto OTA Status Label - UILabelExt labelFactoryResetStatus_; // Factory Reset Status Label - UILabelExt labelResourceCheckStatus_; // Resource Check Status Label - UILabelExt labelRestart_; // Restart Status Label + UILabel labelBLEStatus_; // BLE OTA Status Label + UILabel labelAutoOTAStatus_; // Auto OTA Status Label + UILabel labelFactoryResetStatus_; // Factory Reset Status Label + UILabel labelResourceCheckStatus_; // Resource Check Status Label + UILabel labelRestart_; // Restart Status Label UIScrollView *SafeModeScrollView[MAX_VIEW_ID]{nullptr}; }; diff --git a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerModel.cpp index cf361c63b..2c2fb8948 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerModel.cpp @@ -19,16 +19,29 @@ #include "custom_runtime.h" #include "custom_utils.h" #include "graphic_service.h" +#include "iostream" #include "lwip/apps/http_client.h" +#include "string" #include "tcxo.h" #include "thread_adapter.h" #include "thread_init.h" +#include "ui_resource_string.h" #include "wearable_log.h" +#include +#include +#include +#include -extern "C" bool resfile_checksum_thread(void); extern "C" { #include "build_version.h" const char *get_version_string(void); + +#include "battery_hal.h" +#include "build_version.h" +extern uint8_t battery_get_voltage(float *voltage); +const char *get_version_string(void); + +bool resfile_checksum_thread(void); } static const char *CHECK_DIFFERENTIAL_FILE = "/system/check_differential.txt"; @@ -410,4 +423,31 @@ void SafeModeManagerModel::UpdateSginOperate() { } } } + +//手表信息 +std::string SafeModeManagerModel::get_voltage_and_version_string(void) { + // 电量 + float voltage = 0.0F; + uint8_t value = battery_get_voltage(&voltage); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "battery_get_voltage = %d", value); + + // 版本号 + std::string version_string = + std::string("V") + get_version_string(); // 修正字符串拼接 + + // 拼接字符串 + std::ostringstream oss; + oss << "bat: " << static_cast(value) << "% " << version_string; + + return oss.str(); +} + +// 蓝牙名称 +std::string SafeModeManagerModel::get_bluetooth_name(void) { + uint8_t ble_name[30] = {0}; + uint32_t ble_name_len = sizeof(ble_name); + errcode_t ret = uapi_get_nv_btname(ble_name, &ble_name_len); + + return std::string(reinterpret_cast(ble_name)); +} } // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerView.cpp b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerView.cpp index 60b4f27ca..fb2c4ce06 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/SafeModeManagerView.cpp @@ -54,11 +54,12 @@ SafeModeManagerView *SafeModeManagerView::GetInstance() { } void SafeModeManagerView::InitView() { + // 初始化 SafeModeScrollView if (SafeModeScrollView[VIEW_SAFE_LIST] == nullptr) { SafeModeScrollView[VIEW_SAFE_LIST] = new UIScrollView(); if (SafeModeScrollView[VIEW_SAFE_LIST] == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, - "SafeModeScrollView[VIEW_SAFE_LIST] new fail"); + "SafeModeScrollView[VIEW_SAFE_LIST] new fail"); return; } SafeModeScrollView[VIEW_SAFE_LIST]->SetScrollBlankSize(35); @@ -70,104 +71,83 @@ void SafeModeManagerView::InitView() { SafeModeScrollView[VIEW_SAFE_LIST]->SetOnDragListener(presenter_); SafeModeScrollView[VIEW_SAFE_LIST]->SetTouchable(true); SafeModeScrollView[VIEW_SAFE_LIST]->SetDraggable(true); - SafeModeScrollView[VIEW_SAFE_LIST]->SetStyle(STYLE_BACKGROUND_COLOR, - BACK_GROUND_COLOR); SafeModeScrollView[VIEW_SAFE_LIST]->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SafeModeScrollView[VIEW_SAFE_LIST]->SetStyle(STYLE_BACKGROUND_OPA, 0xff); } - // 初始化背景图和按钮的位置 - backgroundBLE_.SetPosition(43, 120, 380, 100); // BLE OTA 背景 - backgroundBLE_.SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - backgroundBLE_.SetStyle(STYLE_BACKGROUND_OPA, 0xff); - backgroundBLE_.SetStyle(STYLE_BORDER_RADIUS, 100); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&backgroundBLE_); - - backgroundAutoOTA_.SetPosition(43, 240, 380, 100); // Auto OTA 背景 - backgroundAutoOTA_.SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - backgroundAutoOTA_.SetStyle(STYLE_BACKGROUND_OPA, 0xff); - backgroundAutoOTA_.SetStyle(STYLE_BORDER_RADIUS, 100); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&backgroundAutoOTA_); - - backgroundFactoryReset_.SetPosition(43, 360, 380, 100); // 恢复出厂设置背景 - backgroundFactoryReset_.SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - backgroundFactoryReset_.SetStyle(STYLE_BACKGROUND_OPA, 0xff); - backgroundFactoryReset_.SetStyle(STYLE_BORDER_RADIUS, 100); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&backgroundFactoryReset_); - - backgroundResourceCheck_.SetPosition(43, 480, 380, 100); // 资源校验背景 - backgroundResourceCheck_.SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - backgroundResourceCheck_.SetStyle(STYLE_BACKGROUND_OPA, 0xff); - backgroundResourceCheck_.SetStyle(STYLE_BORDER_RADIUS, 100); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&backgroundResourceCheck_); - - backgroundRestart_.SetPosition(43, 600, 380, 100); // 资源校验背景 - backgroundRestart_.SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - backgroundRestart_.SetStyle(STYLE_BACKGROUND_OPA, 0xff); - backgroundRestart_.SetStyle(STYLE_BORDER_RADIUS, 100); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&backgroundRestart_); - + // 初始化标题 labelTitle_.SetPosition(83, 50, 300, 60); labelTitle_.SetFont(GILROY_BOLD_FONT, 30); labelTitle_.SetText("Safe Mode"); - labelTitle_.SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); // 居中 + labelTitle_.SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); labelTitle_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); SafeModeScrollView[VIEW_SAFE_LIST]->Add(&labelTitle_); - // 设置四个功能状态标签 - labelBLEStatus_.SetPosition(90, 153, 200, 60); - labelBLEStatus_.SetFont(GILROY_BOLD_FONT, 30); - labelBLEStatus_.SetText("BLE OTA"); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&labelBLEStatus_); - - labelAutoOTAStatus_.SetPosition(90, 273, 200, 60); - labelAutoOTAStatus_.SetFont(GILROY_BOLD_FONT, 30); - labelAutoOTAStatus_.SetText("Auto OTA"); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&labelAutoOTAStatus_); - - labelFactoryResetStatus_.SetPosition(90, 393, 200, 60); - labelFactoryResetStatus_.SetFont(GILROY_BOLD_FONT, 30); - labelFactoryResetStatus_.SetText("Factory Reset"); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&labelFactoryResetStatus_); - - labelResourceCheckStatus_.SetPosition(90, 513, 200, 60); - labelResourceCheckStatus_.SetFont(GILROY_BOLD_FONT, 30); - labelResourceCheckStatus_.SetText("Resource Check"); - labelResourceCheckStatus_.SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); - labelResourceCheckStatus_.SetAlign(TEXT_ALIGNMENT_CENTER); - labelResourceCheckStatus_.SetRollSpeed(30); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&labelResourceCheckStatus_); - - labelRestart_.SetPosition(90, 633, 200, 60); - labelRestart_.SetFont(GILROY_BOLD_FONT, 30); - labelRestart_.SetText("Restart"); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&labelRestart_); - - // 设置四个切换按钮 - btnBLE_.SetPosition(245, 120, 200, 100); // BLE OTA 切换按钮 - btnBLE_.SetViewId(BLE_OTA); // 设置按钮的ViewId - btnBLE_.SetOnClickListener(presenter_); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&btnBLE_); - - btnAutoOTA_.SetPosition(245, 240, 200, 100); // Auto OTA 切换按钮 - btnAutoOTA_.SetViewId(AUTO_OTA); // 设置按钮的ViewId - btnAutoOTA_.SetOnClickListener(presenter_); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&btnAutoOTA_); - - btnFactoryReset_.SetPosition(245, 360, 200, 100); // 恢复出厂设置切换按钮 - btnFactoryReset_.SetViewId(FACTORY_RESET_SAFE); // 设置按钮的ViewId - btnFactoryReset_.SetOnClickListener(presenter_); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&btnFactoryReset_); - - btnResourceCheck_.SetPosition(245, 480, 200, 100); // 资源校验切换按钮 - btnResourceCheck_.SetViewId(RESOURCE_CHECK); // 设置按钮的ViewId - btnResourceCheck_.SetOnClickListener(presenter_); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&btnResourceCheck_); - - btnRestart_.SetPosition(245, 600, 200, 100); // 资源校验切换按钮 - btnRestart_.SetViewId(RE_START); // 设置按钮的ViewId - btnRestart_.SetOnClickListener(presenter_); - SafeModeScrollView[VIEW_SAFE_LIST]->Add(&btnRestart_); + // 初始化信息标签 + std::string infostr = + SafeModeManagerModel::GetInstance()->get_voltage_and_version_string() + + "\n" + SafeModeManagerModel::GetInstance()->get_bluetooth_name(); + labelInfo_.SetPosition(43, 100, 380, 60); + labelInfo_.SetFont(GILROY_BOLD_FONT, 26); + labelInfo_.SetText(infostr.c_str()); + labelInfo_.SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + labelInfo_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + SafeModeScrollView[VIEW_SAFE_LIST]->Add(&labelInfo_); + + // 定义安全视图项 + SafeViewItem safeItems[] = { + {{&backgroundBLE_, {43, 120}}, + {&btnBLE_, {245, 120}, BLE_OTA}, + {&labelBLEStatus_, "BLE OTA", {90, 153}}}, + {{&backgroundAutoOTA_, {43, 0}}, + {&btnAutoOTA_, {245, 0}, AUTO_OTA}, + {&labelAutoOTAStatus_, "Auto OTA", {90, 0}}}, + {{&backgroundFactoryReset_, {43, 0}}, + {&btnFactoryReset_, {245, 0}, FACTORY_RESET_SAFE}, + {&labelFactoryResetStatus_, "Factory Reset", {90, 0}}}, + {{&backgroundResourceCheck_, {43, 0}}, + {&btnResourceCheck_, {245, 0}, RESOURCE_CHECK}, + {&labelResourceCheckStatus_, "Resource Check", {90, 0}}}, + {{&backgroundRestart_, {43, 0}}, + {&btnRestart_, {245, 0}, RE_START}, + {&labelRestart_, "Restart", {90, 0}}}}; + + // 初始 Y 坐标 + int initialY = 180; + int itemHeight = 120; // 每个 item 的高度,包括背景和按钮的高度 + + // 遍历安全视图项并设置UI元素 + for (const auto &item : safeItems) { + // 设置背景 + item.background.background->SetPosition(item.background.position.x, + initialY, 380, 100); + item.background.background->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + item.background.background->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + item.background.background->SetStyle(STYLE_BORDER_RADIUS, 100); + SafeModeScrollView[VIEW_SAFE_LIST]->Add(item.background.background); + + // 设置状态标签 + item.statusLabel.label->SetPosition(item.statusLabel.position.x, + initialY + 33, 200, 60); + item.statusLabel.label->SetFont(GILROY_BOLD_FONT, 30); + item.statusLabel.label->SetText(item.statusLabel.text.c_str()); + if (item.statusLabel.text == "Resource Check") { + item.statusLabel.label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + item.statusLabel.label->SetAlign(TEXT_ALIGNMENT_CENTER); + item.statusLabel.label->SetRollSpeed(30); + } + SafeModeScrollView[VIEW_SAFE_LIST]->Add(item.statusLabel.label); + + // 设置按钮 + item.button.button->SetPosition(item.button.position.x, initialY, 200, 100); + item.button.button->SetViewId(item.button.viewId); + item.button.button->SetOnClickListener(presenter_); + SafeModeScrollView[VIEW_SAFE_LIST]->Add(item.button.button); + + // 更新 Y 坐标 + initialY += itemHeight; + } } /* -------------------------------------------------------------------------- */ // 主视图 -- 2.17.1