From 74acffd5395ff4c6eaa3692fb26bbb8d3b461e79 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Sat, 5 Oct 2024 11:58:12 +0800 Subject: [PATCH] =?utf8?q?=E8=AE=AD=E7=BB=83:=E4=BF=AE=E5=A4=8D=E2=80=9C?= =?utf8?q?=E6=9B=B4=E5=A4=9A=E2=80=9D=E5=88=97=E8=A1=A8=E7=9A=84=E6=9E=90?= =?utf8?q?=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../include/TraingMoreView.h | 80 +++-- .../training_list_more/src/TraingMoreView.cpp | 297 ++++++++---------- 2 files changed, 165 insertions(+), 212 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/include/TraingMoreView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/include/TraingMoreView.h index 5eaa40dbf..e89eb12b3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/include/TraingMoreView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/include/TraingMoreView.h @@ -4,50 +4,46 @@ #include "BaseView.h" #include "View.h" -#include "components/ui_view_group.h" -#include "components/ui_scroll_view.h" +#include "components/ui_label_button_ext.h" +#include "components/ui_label_ext.h" #include "components/ui_list.h" +#include "components/ui_scroll_view.h" +#include "components/ui_view_group.h" #include "traing/training_list_more/include/TraingMoreAdapter.h" #include "traing/training_list_more/include/TraingMoreModel.h" -#include "components/ui_label_button_ext.h" -#include "components/ui_label_ext.h" -#include"ui_resource_string.h" - -namespace OHOS -{ - class TraingMorePresenter; - class TraingMoreModel; - class TraingMoreView : public View, public UIViewGroup - { - - public: - TraingMoreView(); - virtual ~TraingMoreView(); - static TraingMoreView *GetInstance(void); - - void OnStart() override; - void OnSetUpView() override; - void OnTearDownView() override; - void OnStop() override; - - UIList *GetList(); - void AddToTraingMoreList(const TraingMoreItem &item); - - private: - void InitView(void); - void DeInitView(void); - void PreLoad(void); - - private: - UIScrollView *scrollView = nullptr; - UILabelExt *title{nullptr}; - TraingMoreAdapter *p_TraingMoreListAdapter{nullptr}; - UIList *TraingMoreList = nullptr; - UIView::OnDragListener *draglistener{nullptr}; - - TraingMorePresenter *g_TraingMorePresenter{nullptr}; - TraingMoreModel *g_TraingMoreModel{nullptr}; - bool viewInitStatus{false}; - }; +#include "ui_resource_string.h" + +namespace OHOS { +class TraingMorePresenter; +class TraingMoreModel; +class TraingMoreView : public View, public UIViewGroup { + +public: + TraingMoreView(); + virtual ~TraingMoreView(); + static TraingMoreView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + UIList *GetList(); + void AddToTraingMoreList(const TraingMoreItem &item); + +private: + void InitView(void); + void InitList(); + void InitScrollView(); + void DeInitView(void); + void PreLoad(void); + void SetKeyActListener(void); + +private: + UIScrollView *scrollView = nullptr; + TraingMoreAdapter *p_TraingMoreListAdapter{nullptr}; + UIList *TraingMoreList = nullptr; + bool viewInitStatus{false}; +}; } // namespace OHOS #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/src/TraingMoreView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/src/TraingMoreView.cpp index 6625ec982..36e04b3d8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/src/TraingMoreView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/src/TraingMoreView.cpp @@ -1,180 +1,137 @@ -/*** - * @Author: Caisking 3449750381@qq.com - * @Date: 2024-03-26 09:46:17 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-03-29 12:06:57 - * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_more/src/TraingMoreView.cpp - * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE - */ #include "traing/training_list_more/include/TraingMoreView.h" -#include "traing/training_list_more/include/TraingMorePresenter.h" -#include "traing/include/TraingModel.h" -#include "uicomponents/UIComponents.h" -#include "traing/Training_UiConfig.h" - +#include "UiConfig.h" #include "components/ui_label_ext.h" +#include "traing/Training_UiConfig.h" +#include "traing/include/TraingModel.h" +#include "traing/training_list_more/include/TraingMorePresenter.h" #include "ui_resource_string.h" -#include "UiConfig.h" +#include "uicomponents/UIComponents.h" #include "wearable_log.h" - -namespace OHOS -{ - static constexpr uint8_t NUM_2 = 2; - static TraingMoreView *g_pTraingMoreView{nullptr}; - /* --------------------------------- List --------------------------------- */ - static constexpr int16_t More_LIST_POSITION_X = 43; - static constexpr int16_t More_LIST_POSITION_Y = 120; - static constexpr int16_t More_SCROLLBLANKSIZE = 35; // 设置此滚动视图的空白大小。 - static constexpr int16 MAX_SCR_DIS = 1000; - static constexpr int16 LIST_POS = 20; - static constexpr int16 SNUM_2 = 2; - - TraingMoreView::TraingMoreView() - { - g_pTraingMoreView = this; - } - - TraingMoreView::~TraingMoreView() - { - DeInitView(); - g_pTraingMoreView = nullptr; - } - - TraingMoreView *TraingMoreView::GetInstance() - { - return g_pTraingMoreView; - } - /// @param item - void TraingMoreView::AddToTraingMoreList(const TraingMoreItem &item) - { - p_TraingMoreListAdapter->AddItem(item); - } - static void SetKeyActListener() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener"); - // 增加按键监听 - RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingMorePresenter::GetInstance(); - RootView::GetInstance()->SetOnKeyActListener(keyactListener); - } - void TraingMoreView::InitView() - { - // 初始化 UIScrollView - if (scrollView == nullptr) - { - scrollView = new UIScrollView(); +#include + +namespace OHOS { +static TraingMoreView *g_pTraingMoreView{nullptr}; + +TraingMoreView::TraingMoreView() { g_pTraingMoreView = this; } + +TraingMoreView::~TraingMoreView() { g_pTraingMoreView = nullptr; } + +TraingMoreView *TraingMoreView::GetInstance() { return g_pTraingMoreView; } + +void TraingMoreView::AddToTraingMoreList(const TraingMoreItem &item) { + if (p_TraingMoreListAdapter) { + p_TraingMoreListAdapter->AddItem(item); + } +} + +void TraingMoreView::SetKeyActListener() { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener"); + auto keyActListener = static_cast( + TraingMorePresenter::GetInstance()); + RootView::GetInstance()->SetOnKeyActListener(keyActListener); +} + +void TraingMoreView::InitScrollView() { + if (scrollView == nullptr) { + scrollView = new UIScrollView(); + } + scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), + Screen::GetInstance().GetHeight()); + scrollView->SetTouchable(true); + scrollView->SetDraggable(true); + scrollView->SetDirection(1); + scrollView->SetHorizontalScrollState(false); + scrollView->SetOnDragListener(presenter_); + scrollView->SetYScrollBarVisible(true); +} + +void TraingMoreView::InitList() { + if (p_TraingMoreListAdapter == nullptr) { + p_TraingMoreListAdapter = new TraingMoreAdapter(); + } + p_TraingMoreListAdapter->SetItemClickListener(presenter_); + + if (TraingMoreList == nullptr) { + TraingMoreList = new UIList(); + } + TraingMoreList->SetPosition(43, 0, HORIZONTAL_RESOLUTION, + VERTICAL_RESOLUTION); + TraingMoreList->SetThrowDrag(true); + TraingMoreList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + TraingMoreList->SetMaxScrollDistance(1000); + TraingMoreList->SetSwipeACCLevel(800); + TraingMoreList->SetDragACCLevel(5); + TraingMoreList->SetRotateFactor(1); + TraingMoreList->RequestFocus(); +} + +void TraingMoreView::InitView() { + InitScrollView(); + InitList(); + SetKeyActListener(); +} + +void TraingMoreView::DeInitView() { + if (viewInitStatus) { + if (container_) { + container_->RemoveAll(); + if (scrollView) { + scrollView->RemoveAll(); + if (p_TraingMoreListAdapter) { + delete p_TraingMoreListAdapter; + p_TraingMoreListAdapter = nullptr; } - - // 设置 UIScrollView 属性 - scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - scrollView->SetTouchable(true); - scrollView->SetDraggable(true); - scrollView->SetDirection(1); - // scrollView->SetReboundSize(50); // 设置空白大小 - scrollView->SetScrollBlankSize(75); - scrollView->SetHorizontalScrollState(false); // 设置横向不可滑动 - - // 设置拖动监听器 - scrollView->SetOnDragListener(presenter_); - - // 初始化 label - InitLabelExt(title, 125, 52, 200, 60, "label1", STR_TRAINING, DEFAULT_VECTOR_FONT_FILENAME, 30); - scrollView->Add(title); - - // 初始化适配器 - p_TraingMoreListAdapter = new TraingMoreAdapter(); - p_TraingMoreListAdapter->SetItemClickListener(presenter_); - - // 初始化 UIList - if (TraingMoreList == nullptr) - { - TraingMoreList = new UIList(); + if (TraingMoreList) { + delete TraingMoreList; + TraingMoreList = nullptr; } - - TraingMoreList->SetPosition(More_LIST_POSITION_X, More_LIST_POSITION_Y, 466, 466); - TraingMoreList->SetThrowDrag(true); - TraingMoreList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - TraingMoreList->SetMaxScrollDistance(1000); - TraingMoreList->SetSwipeACCLevel(800); - TraingMoreList->SetDragACCLevel(5); - - // 设置滚动条可见性 - scrollView->SetYScrollBarVisible(true); - - // 增加表冠控制 - TraingMoreList->SetRotateFactor(2); - TraingMoreList->RequestFocus(); - - // 设置键盘事件监听 - SetKeyActListener(); - } - UIList *TraingMoreView::GetList() - { - return TraingMoreList; - } - void TraingMoreView::DeInitView() - { - // scrollView-> RemoveAll(); - scrollView->RemoveAll(); - delete title; - title = nullptr; - - TraingMoreList->RemoveAll(); - delete TraingMoreList; - TraingMoreList = nullptr; - delete scrollView; scrollView = nullptr; - - delete draglistener; - draglistener = nullptr; + } } - - void TraingMoreView::PreLoad(void) - { - if (!viewInitStatus) - { - InitView(); - viewInitStatus = true; - } - } - - /// @brief 页面启动时需要执行的代码逻辑 - void TraingMoreView::OnStart() - { - View::OnStart(); - BaseView::RootView(Color::Black().full); - PreLoad(); - } - - /// @brief 创建页面的视图。 - void TraingMoreView::OnSetUpView() - { - View::OnSetUpView(); - scrollView->Add(TraingMoreList); - scrollView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - RootView::GetInstance()->Add(scrollView); - TraingMoreList->SetAdapter(p_TraingMoreListAdapter); - // TraingMoreList->SetIntercept(true); - // TraingMoreList->RefreshList(); // 刷新列表 - Draw(); - } - - /// @brief 销毁页面的视图。 - void TraingMoreView::OnTearDownView() - { - View::OnTearDownView(); - return; - } - - /// @brief 页面结束时需要执行的销毁逻辑。 - void TraingMoreView::OnStop() - { - View::OnStop(); - - RootView::GetInstance()->ClearOnKeyActListener(); - // FocusManager::GetInstance()->ClearFocus(); - RootView::GetInstance()->RemoveAll(); - // RootView::GetInstance()->ClearFocus(); - return; + delete container_; + container_ = nullptr; + } +} + +void TraingMoreView::PreLoad() { + if (!viewInitStatus) { + InitView(); + viewInitStatus = true; + } +} + +void TraingMoreView::OnStart() { + View::OnStart(); + SetContainerView(new UIViewGroup()); + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), + Screen::GetInstance().GetHeight()); + BaseView::RootView(Color::Black().full); + PreLoad(); + SetContainerView(container_); +} + +void TraingMoreView::OnSetUpView() { + View::OnSetUpView(); + if (scrollView && TraingMoreList) { + scrollView->Add(TraingMoreList); + scrollView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + container_->Add(scrollView); + if (p_TraingMoreListAdapter) { + TraingMoreList->SetAdapter(p_TraingMoreListAdapter); } -} \ No newline at end of file + Draw(); + } +} + +void TraingMoreView::OnTearDownView() { + View::OnTearDownView(); +} + +void TraingMoreView::OnStop() { + View::OnStop(); + RootView::GetInstance()->ClearOnKeyActListener(); + DeInitView(); + RootView::GetInstance()->RemoveAll(); +} +} // namespace OHOS \ No newline at end of file -- 2.17.1