From e72088741ac5a5eb2e7f618babfeaf67fb9451f3 Mon Sep 17 00:00:00 2001 From: Caisking Date: Mon, 28 Jul 2025 20:19:53 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E7=9C=81=E7=94=B5=E6=A8=A1?= =?utf8?q?=E5=BC=8FUI?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/saveele/include/SaveBatView.h | 2 + .../nativeui/saveele/include/SaveEleView.h | 1 - .../nativeui/saveele/src/SaveBatView.cpp | 55 ++++++------ .../nativeui/saveele/src/SaveEleView.cpp | 89 ++++++++----------- 4 files changed, 69 insertions(+), 78 deletions(-) diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveBatView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveBatView.h index 149604c00..22d3a70ac 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveBatView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveBatView.h @@ -113,6 +113,8 @@ namespace OHOS SaveBatView(SaveBatView &&) = delete; SaveBatView &operator=(SaveBatView &&) = delete; + + UIViewGroup *group_ = nullptr; /*省电界面*/ UILabel *timelabel = nullptr; // 时间 UILabel *datelabel = nullptr; // 日期标签 diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveEleView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveEleView.h index 6a1469ca7..1a86f7fd5 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveEleView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/include/SaveEleView.h @@ -43,7 +43,6 @@ namespace OHOS UIButton *buttonno = nullptr; UIImageView *iamgeicon = nullptr; UIScrollView *scrollview_ = nullptr; - UIScrollView *SaveEleView_ = nullptr; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveBatView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveBatView.cpp index f4b23c3da..63f34ba17 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveBatView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveBatView.cpp @@ -10,9 +10,7 @@ #include #include #include - #include "battery_hal.h" - #include "string" #include "custom_utils.h" #include "UiConfig.h" @@ -336,6 +334,8 @@ namespace OHOS /* 关闭省电模式 */ uapi_exit_power_saving_mode(); + // UIViewGroup *tmpGroup = dynamic_cast(group_); + // UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup); // 释放所有动态分配的成员变量 if (timelabel) { @@ -401,7 +401,10 @@ namespace OHOS delete restart_; restart_ = nullptr; } - + if (group_) { + delete group_; + group_ = nullptr; + } if (label_) { delete label_; label_ = nullptr; @@ -463,8 +466,6 @@ namespace OHOS float voltage = 0.0F; uint8_t value = battery_get_voltage(&voltage); - - // 更新界面组件 timelabel->SetText(stringtime.c_str()); datelabel->SetText(dateStr.c_str()); @@ -512,9 +513,9 @@ namespace OHOS batterylabel->SetTextColor(Color::White()); batteryprogress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xffffc300); - AddViewToRootContainer(batteryiamge); - AddViewToRootContainer(batterylabel); - AddViewToRootContainer(batteryprogress); + group_->Add(batteryiamge); + group_->Add(batterylabel); + group_->Add(batteryprogress); } void SaveBatView::InitTimeView() { @@ -535,7 +536,7 @@ namespace OHOS timelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); timelabel->SetRollSpeed(0); timelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 100); - AddViewToRootContainer(timelabel); + group_->Add(timelabel); /*日期*/ datelabel = new UILabel(); @@ -555,7 +556,7 @@ namespace OHOS datelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); datelabel->SetRollSpeed(0); datelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30); - AddViewToRootContainer(datelabel); + group_->Add(datelabel); } void SaveBatView::InitButtonView() { @@ -576,7 +577,7 @@ namespace OHOS button_exit->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); button_exit->SetOnTouchListener(presenter_); - AddViewToRootContainer(button_exit); + group_->Add(button_exit); } void SaveBatView::InitShowBackView() { @@ -607,7 +608,7 @@ namespace OHOS curren_label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); curren_label->SetRollSpeed(0); curren_label->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 40); - AddViewToRootContainer(curren_label); + group_->Add(curren_label); curren_label->SetVisible(false); #if ANIMATION_TEST // 圆形进度条 @@ -631,7 +632,7 @@ namespace OHOS backprogress->SetRadius(90); backprogress->SetEndAngle(359); backprogress->SetValue(0); - AddViewToRootContainer(backprogress); + group_->Add(backprogress); backprogress->SetVisible(false); // 手表image @@ -645,7 +646,7 @@ namespace OHOS wathchiamge->Resize(100, 100); wathchiamge->SetViewId("image1"); wathchiamge->SetSrc(SAVE_WATHCH); - AddViewToRootContainer(wathchiamge); + group_->Add(wathchiamge); wathchiamge->SetVisible(false); // 倒计时 @@ -664,7 +665,7 @@ namespace OHOS countlabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); countlabel->SetRollSpeed(0); countlabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 40); - AddViewToRootContainer(countlabel); + group_->Add(countlabel); countlabel->SetVisible(false); #else if (canvas_ == nullptr) @@ -673,7 +674,7 @@ namespace OHOS } canvas_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); canvas_->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - AddViewToRootContainer(canvas_); + group_->Add(canvas_); canvas_->SetVisible(false); if (label_ == nullptr) @@ -682,7 +683,7 @@ namespace OHOS } label_->SetPosition(LABEL_X, LABEL_Y, 180, 120); label_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - AddViewToRootContainer(label_); + group_->Add(label_); label_->SetVisible(false); PaintExt paint; @@ -832,23 +833,25 @@ namespace OHOS void SaveBatView::OnStart() { - + group_ = new UIViewGroup(); + if (group_ == nullptr) + { + return; + } - GetRootContainer()->SetPosition(0, 0); - GetRootContainer()->SetWidth(Screen::GetInstance().GetWidth()); - GetRootContainer()->SetHeight(Screen::GetInstance().GetHeight()); - GetRootContainer()->SetTouchable(true); - GetRootContainer()->SetDraggable(true); + group_->SetPosition(0, 0); + group_->SetWidth(Screen::GetInstance().GetWidth()); + group_->SetHeight(Screen::GetInstance().GetHeight()); + group_->SetTouchable(true); + group_->SetDraggable(true); InitBatteryView(); InitTimeView(); InitButtonView(); InitShowBackView(); - Draw(); - + AddViewToRootContainer(group_); RootView::GetInstance()->SetOnKeyActListener(presenter_); } - } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveEleView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveEleView.cpp index 6556815a0..d1560ead8 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveEleView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/saveele/src/SaveEleView.cpp @@ -16,7 +16,6 @@ #include "ui_resource_image.h" #include "ui_resource_string.h" #include "uicomponents/UIComponents.h" -#include "components/ui_scroll_view.h" namespace OHOS { @@ -31,49 +30,43 @@ SaveEleView::SaveEleView() { g_pSaveEleView = this; } SaveEleView::~SaveEleView() { - if (scrollview_ != nullptr) { scrollview_->RemoveAll(); - if (labeltitle) { - delete labeltitle; - labeltitle = nullptr; - } - if (labelnote) { - delete labelnote; - labelnote = nullptr; - } - if (labelkown) { - delete labelkown; - labelkown = nullptr; - } - if (iamgeicon) { - delete iamgeicon; - iamgeicon = nullptr; - } - if (buttonno) { - delete buttonno; - buttonno = nullptr; - } - if (buttonok) { - delete buttonok; - buttonok = nullptr; - } - delete scrollview_; + if (labeltitle) { + delete labeltitle; + labeltitle = nullptr; + } + if (labelnote) { + delete labelnote; + labelnote = nullptr; + } + if (labelkown) { + delete labelkown; + labelkown = nullptr; + } + if (iamgeicon) { + delete iamgeicon; + iamgeicon = nullptr; + } + if (buttonno) { + delete buttonno; + buttonno = nullptr; + } + if (buttonok) { + delete buttonok; + buttonok = nullptr; + } + delete scrollview_; scrollview_ = nullptr; } - + g_pSaveEleView = nullptr; } SaveEleView *SaveEleView::GetInstance() { return g_pSaveEleView; } void SaveEleView::InitView() { - - SaveEleView_ = new UIScrollView(); - SaveEleView_->SetPosition(0, 0, 466, 466); - SaveEleView_->SetStyle(STYLE_BACKGROUND_OPA, 0); - /*初始化label*/ InitRollLabel(labeltitle, 83, 50, 300, 35, "labletitle", STR_POWER_SAVE_MODE, @@ -103,33 +96,30 @@ void SaveEleView::InitView() { buttonok->SetImageSrc(butokImgPath, butokImgPath); buttonok->SetOnClickListener(presenter_); - SaveEleView_->Add(labeltitle); - SaveEleView_->Add(labelnote); - SaveEleView_->Add(labelkown); - SaveEleView_->Add(iamgeicon); - SaveEleView_->Add(buttonno); - SaveEleView_->Add(buttonok); - scrollview_->Add(SaveEleView_); - + scrollview_->Add(labeltitle); + scrollview_->Add(labelnote); + scrollview_->Add(labelkown); + scrollview_->Add(iamgeicon); + scrollview_->Add(buttonno); + scrollview_->Add(buttonok); } void SaveEleView::OnStart() { View::OnStart(); - + scrollview_ = new UIScrollView(); if (scrollview_ == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollview_ new fail"); return; } - // scrollview_->SetScrollBlankSize(35); - // scrollview_->SetReboundSize(50); + scrollview_->SetScrollBlankSize(35); + scrollview_->SetReboundSize(50); scrollview_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), - Screen::GetInstance().GetHeight()); + Screen::GetInstance().GetHeight()); - - scrollview_->SetHorizontalScrollState(false); // 设置水平滚动失效 - scrollview_->SetDirection(1); + scrollview_->SetHorizontalScrollState(false); // 设置水平滚动失效 + scrollview_->SetDirection(1); scrollview_->SetOnDragListener(presenter_); scrollview_->SetOnRotateListener(presenter_); @@ -140,12 +130,9 @@ void SaveEleView::OnStart() { scrollview_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR); scrollview_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - AddViewToRootContainer(scrollview_); InitView(); RootView::GetInstance()->SetOnKeyActListener(presenter_); - } - } // namespace OHOS -- 2.17.1