From e0bed2a157865b46685abca66cded8563fb04f13 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Thu, 12 Sep 2024 20:06:04 +0800 Subject: [PATCH] =?utf8?q?=E5=AE=89=E5=85=A8=E6=A8=A1=E5=BC=8F=EF=BC=9A?= =?utf8?q?=E5=A2=9E=E5=8A=A0=E8=B5=84=E6=BA=90=E4=BF=AE=E5=A4=8D=E4=B8=8B?= =?utf8?q?=E8=BD=BDUI?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../safemodemanager/include/RepairView.h | 42 +++ .../safemodemanager/src/RepairView.cpp | 268 ++++++++++++++++++ 2 files changed, 310 insertions(+) create mode 100644 code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/RepairView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/RepairView.cpp diff --git a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/RepairView.h b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/RepairView.h new file mode 100644 index 000000000..03b6ac005 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/include/RepairView.h @@ -0,0 +1,42 @@ + +#ifndef Repair_VIEW_H +#define Repair_VIEW_H + +#include "BaseView.h" +#include "View.h" + +#include "components/ui_button.h" +#include "components/ui_image_view.h" +#include "components/ui_label_button_ext.h" +#include "components/ui_label_ext.h" +#include "components/ui_scroll_view.h" +namespace OHOS { +class RepairView { +public: + RepairView(); + virtual ~RepairView(); + static RepairView *GetInstance(void); + + UIScrollView *RepairViewInit(void); + void ClearAll(void); + + void UpdateView(void); + void InitScrollView(void); + void InitLabels(void); + void InitButtons(void); + void InitBasicdata(void); + +private: + UIScrollView *scrollView_{nullptr}; + UILabel *signalLabel_{nullptr}; + UILabel *operationLabel_{nullptr}; + UILabel *instructionLabel_{nullptr}; + UILabelButtonExt *repairButton_{nullptr}; + UILabelButtonExt *wakeUpButton_{nullptr}; + UILabel *downLabel_{nullptr}; + UILabel *totalLabel_{nullptr}; + UILabel *versionLabel_{nullptr}; + UILabel *downingLabel_{nullptr}; +}; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/RepairView.cpp b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/RepairView.cpp new file mode 100644 index 000000000..1f13562d3 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/safemodemanager/src/RepairView.cpp @@ -0,0 +1,268 @@ +#include "safemodemanager/include/RepairView.h" +#include "safemodemanager/include/SafeModeManagerModel.h" +#include "safemodemanager/include/SafeModeManagerPresenter.h" + +#include "UiConfig.h" +#include "ui_resource_string.h" +#include "wearable_log.h" + +namespace OHOS { + +static RepairView *g_pRepairView{nullptr}; + +RepairView::RepairView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RepairView::RepairView"); + g_pRepairView = this; +} + +RepairView::~RepairView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RepairView::~RepairView"); + ClearAll(); + g_pRepairView = nullptr; +} + +RepairView *RepairView::GetInstance() { return g_pRepairView; } + +void RepairView::ClearAll() { + scrollView_->RemoveAll(); + delete signalLabel_; + signalLabel_ = nullptr; + delete operationLabel_; + operationLabel_ = nullptr; + delete instructionLabel_; + instructionLabel_ = nullptr; + delete versionLabel_; + versionLabel_ = nullptr; + delete wakeUpButton_; + wakeUpButton_ = nullptr; + delete repairButton_; + repairButton_ = nullptr; + delete downLabel_; + downLabel_ = nullptr; + delete totalLabel_; + totalLabel_ = nullptr; + delete downingLabel_; + downingLabel_ = nullptr; + delete scrollView_; + scrollView_ = nullptr; +} + +void RepairView::InitScrollView() { + if (scrollView_ == nullptr) { + scrollView_ = new UIScrollView(); + scrollView_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), + Screen::GetInstance().GetHeight()); + scrollView_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollView_->SetScrollBlankSize(100); + scrollView_->SetMaxScrollDistance(1000); + scrollView_->SetThrowDrag(true); + scrollView_->SetHorizontalScrollState(false); + } +} + +void RepairView::InitLabels() { + // Signal Label + if (signalLabel_ == nullptr) { + signalLabel_ = new UILabel(); + signalLabel_->SetPosition(133, 130); + signalLabel_->Resize(200, 60); + signalLabel_->SetViewId("signalLabel"); + signalLabel_->SetText("Signal: 26"); + signalLabel_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + signalLabel_->SetAlign(TEXT_ALIGNMENT_CENTER); + signalLabel_->SetFont(GILROY_BOLD_FONT, + 30); // Updated font size + signalLabel_->SetTextColor( + Color::GetColorFromRGBA(0x15, 0xcb, 0x06, 0xff)); // Updated text color + scrollView_->Add(signalLabel_); + signalLabel_->SetVisible(true); + } + + // Operation Label + if (operationLabel_ == nullptr) { + operationLabel_ = new UILabel(); + operationLabel_->SetPosition(83, 80); + operationLabel_->Resize(300, 60); + operationLabel_->SetViewId("operationLabel"); + operationLabel_->SetText("Operation: CHN_CT"); + operationLabel_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + operationLabel_->SetAlign(TEXT_ALIGNMENT_CENTER); + operationLabel_->SetFont(GILROY_BOLD_FONT, + 30); // Updated font size + scrollView_->Add(operationLabel_); + operationLabel_->SetVisible(true); + } + + // Instruction Label + if (instructionLabel_ == nullptr) { + instructionLabel_ = new UILabel(); + instructionLabel_->SetPosition(20, 180); + instructionLabel_->Resize(400, 60); + instructionLabel_->SetViewId("instructionLabel"); + instructionLabel_->SetText("If the signal is outside the range of 0 to 30, " + "please click 'Wake Up' and wait for a moment."); + instructionLabel_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + instructionLabel_->SetAlign(TEXT_ALIGNMENT_CENTER); + instructionLabel_->SetTextColor( + Color::GetColorFromRGBA(0xeb, 0x05, 0x05, 0xff)); + instructionLabel_->SetFont(GILROY_BOLD_FONT, + 20); // Updated font size + // scrollView_->Add(instructionLabel_); + // instructionLabel_->SetVisible(true); + } + + // Version Label + if (versionLabel_ == nullptr) { + versionLabel_ = new UILabel(); + versionLabel_->SetPosition(133, 180); + versionLabel_->Resize(200, 60); + versionLabel_->SetViewId("versionLabel"); + versionLabel_->SetText("Version: 1.1.47"); + versionLabel_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + versionLabel_->SetAlign(TEXT_ALIGNMENT_CENTER); + versionLabel_->SetFont(GILROY_BOLD_FONT, + 30); // Updated font size + scrollView_->Add(versionLabel_); + versionLabel_->SetVisible(true); + } + + // down Label + if (downingLabel_ == nullptr) { + downingLabel_ = new UILabel(); + downingLabel_->SetPosition(133, 406); + downingLabel_->Resize(200, 60); + downingLabel_->SetViewId("label11"); + downingLabel_->SetStyle(STYLE_TEXT_FONT, 26); + downingLabel_->SetText("downing..."); + downingLabel_->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + downingLabel_->SetTextColor( + Color::GetColorFromRGBA(0xef, 0x0e, 0x0e, 0xff)); + downingLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + downingLabel_->SetRollSpeed(0); + downingLabel_->SetFont(GILROY_BOLD_FONT, 26); + scrollView_->Add(versionLabel_); + versionLabel_->SetVisible(false); + } +} + +void RepairView::InitButtons() { + // Repair Button + if (repairButton_ == nullptr) { + repairButton_ = new UILabelButtonExt(); + repairButton_->SetPosition(265, 245); + repairButton_->Resize(160, 80); // Updated size + repairButton_->SetViewId("repairButton"); + repairButton_->SetText("Repair File"); + repairButton_->SetFont(GILROY_BOLD_FONT, + 26); // Updated font size + repairButton_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff14ff00); + scrollView_->Add(repairButton_); + repairButton_->SetVisible(true); + } + + // Wake Up Button + if (wakeUpButton_ == nullptr) { + wakeUpButton_ = new UILabelButtonExt(); + wakeUpButton_->SetPosition(45, 245); + wakeUpButton_->Resize(160, 80); // Updated size + wakeUpButton_->SetViewId("wakeUpButton"); + wakeUpButton_->SetText("Wake Up"); + wakeUpButton_->SetFont(GILROY_BOLD_FONT, + 26); // Updated font size + wakeUpButton_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff0c77e6); + scrollView_->Add(wakeUpButton_); + wakeUpButton_->SetVisible(true); + } +} +UIScrollView *RepairView::RepairViewInit() { + + InitScrollView(); + // 设置拖拽监听器 + UIView::OnDragListener *dragListener = static_cast( + SafeModeManagerPresenter::GetInstance()); + if (!dragListener) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "SafeModeManagerPresenter::获取实例失败!"); + return nullptr; // 获取失败,返回空指针 + } + scrollView_->SetOnDragListener(dragListener); + + InitLabels(); + InitButtons(); + + // Adding other labels + if (downLabel_ == nullptr) { + downLabel_ = new UILabel(); + downLabel_->SetPosition(26, 366); + downLabel_->Resize(200, 60); + downLabel_->SetViewId("downLabel"); + downLabel_->SetText("down: 10"); + downLabel_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + downLabel_->SetAlign(TEXT_ALIGNMENT_CENTER); + downLabel_->SetFont(GILROY_BOLD_FONT, + 30); // Updated font size + downLabel_->SetTextColor( + Color::GetColorFromRGBA(0x15, 0xcb, 0x06, 0xff)); // Updated text color + scrollView_->Add(downLabel_); + downLabel_->SetVisible(true); + } + + if (totalLabel_ == nullptr) { + totalLabel_ = new UILabel(); + totalLabel_->SetPosition(230, 366); + totalLabel_->Resize(200, 60); + totalLabel_->SetViewId("totalLabel"); + totalLabel_->SetText("total: 100"); + totalLabel_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + totalLabel_->SetAlign(TEXT_ALIGNMENT_CENTER); + totalLabel_->SetFont(GILROY_BOLD_FONT, + 30); // Updated font size + scrollView_->Add(totalLabel_); + totalLabel_->SetVisible(true); + } + + return scrollView_; +} + +//初始化版本号与运营商 +void RepairView::InitBasicdata() { + if (versionLabel_ != nullptr) { + } + if (downLabel_ != nullptr) { + } +} + +//更新信号值与下载进度 +void RepairView::UpdateRepairView(int date) { + if (downingLabel_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "ResourceCheckView::downingLabel_ is null"); + return; + } + //显示下载中 + if (downingLabel_->IsVisible() == false) { + downingLabel_->SetVisible(true); + } + std::string display = "downing"; + // 检查状态并更新提示文本 + if (date >= 0 && date <= 60) { + int progress = date % 4; + display.append(progress, '.'); // 添加进度标记点 + downingLabel_->SetText(display.c_str()); + } else { + switch (date) { + //下载修复文件成功 + case 61: + downingLabel_->SetText("Repair file download success!"); + break; + case -1: + //下载修复文件失败 + downingLabel_->SetText("Repair file download failed!"); + break; + default: + downingLabel_->SetText("Unknown status..."); + break; + } + } +} +} // namespace OHOS \ No newline at end of file -- 2.17.1