From 884381ee72005ad1045425b62e109da932a53259 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Sat, 5 Oct 2024 13:14:47 +0800 Subject: [PATCH] =?utf8?q?=E8=AE=AD=E7=BB=83=EF=BC=9A=E4=BF=AE=E6=94=B9?= =?utf8?q?=E2=80=9C=E5=85=B6=E4=BB=96=E2=80=9D=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../include/TraingOtherModel.h | 2 +- .../include/TraingOtherView.h | 89 +++--- .../src/TraingOtherItemView.cpp | 181 ++++++----- .../src/TraingOtherModel.cpp | 93 +++--- .../src/TraingOtherView.cpp | 290 ++++++++---------- 5 files changed, 314 insertions(+), 341 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherModel.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherModel.h index e257b5b38..7edbb1c09 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherModel.h @@ -45,7 +45,7 @@ namespace OHOS TraingOtherModel(const TraingOtherModel &); TraingOtherModel &operator=(const TraingOtherModel &); virtual ~TraingOtherModel(); - static const uint16_t TraingOtherListMaxNum = 9; + static const uint16_t TraingOtherListMaxNum = 11; TraingOtherItem TraingOthers[TraingOtherListMaxNum] = {VIEW_INVALID, STR_EXERCISE_GENERAL}; // std::map TraingOtherIdToViewId; bool btConnectStatus{false}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherView.h index b16ec28ed..adeec2605 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherView.h @@ -1,10 +1,12 @@ -/*** +/*** * @Author: Caisking 3449750381@qq.com * @Date: 2024-03-19 17:37:18 * @LastEditors: Caisking 3449750381@qq.com * @LastEditTime: 2024-03-27 11:15:59 - * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherView.h - * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + * @FilePath: + * /sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherView.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 + * 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ #ifndef TraingOther_VIEW_H @@ -12,50 +14,47 @@ #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_other/include/TraingOtherAdapter.h" #include "traing/training_list_other/include/TraingOtherModel.h" -#include "components/ui_label_button_ext.h" -#include "components/ui_label_ext.h" -#include"ui_resource_string.h" - -namespace OHOS -{ - class TraingOtherPresenter; - class TraingOtherModel; - class TraingOtherView : public View, public UIViewGroup - { - - public: - TraingOtherView(); - virtual ~TraingOtherView(); - static TraingOtherView *GetInstance(void); - - void OnStart() override; - void OnSetUpView() override; - void OnTearDownView() override; - void OnStop() override; - - UIList *GetList(); - void AddToTraingOtherList(const TraingOtherItem &item); - - private: - void InitView(void); - void DeInitView(void); - void PreLoad(void); - - private: - UIScrollView *scrollView = nullptr; - UILabelExt *title{nullptr}; - TraingOtherAdapter *p_TraingOtherListAdapter{nullptr}; - UIList *TraingOtherList = nullptr; - UIView::OnDragListener *draglistener{nullptr}; - - TraingOtherPresenter *g_TraingOtherPresenter{nullptr}; - TraingOtherModel *g_TraingOtherModel{nullptr}; - bool viewInitStatus{false}; - }; +#include "ui_resource_string.h" + +namespace OHOS { +class TraingOtherPresenter; +class TraingOtherModel; +class TraingOtherView : public View, public UIViewGroup { + +public: + TraingOtherView(); + virtual ~TraingOtherView(); + static TraingOtherView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + UIList *GetList(); + void AddToTraingOtherList(const TraingOtherItem &item); + +private: + void InitView(void); + void DeInitView(void); + void InitList(); + void InitScrollView(); + void SetKeyActListener(void); + void PreLoad(void); + +private: + UIScrollView *scrollView = nullptr; + TraingOtherAdapter *p_TraingOtherListAdapter{nullptr}; + UIList *TraingOtherList = 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_other/src/TraingOtherItemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherItemView.cpp index b33393acc..4015ee595 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherItemView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherItemView.cpp @@ -1,80 +1,105 @@ -/*** - * @Date: 2024-04-15 10:55:58 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-09-07 11:28:23 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherItemView.cpp - */ -/*** - * @Author: Caisking 3449750381@qq.com - * @Date: 2024-03-29 17:42:13 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-03-29 17:52:02 - * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherItem.cpp - * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE - */ - -#include "traing/training_list_other/include/TraingOtherItemView.h" +#include "UiConfig.h" +#include "traing/Training_UiConfig.h" #include "traing/include/TraingModel.h" +#include "traing/training_list_other/include/TraingOtherItemView.h" #include "uicomponents/UIComponents.h" -#include "traing/Training_UiConfig.h" -#include "components/ui_label_ext.h" -#include "ui_resource_string.h" -#include "UiConfig.h" -namespace OHOS -{ - - TraingOtherItemView::TraingOtherItemView() - { - SetPosition(0, 0, 380, 120); // 每一个itemview宽高要配置好,因为加到list都是以这个视图为基准 - SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - SetStyle(STYLE_BACKGROUND_OPA, 255); - SetTouchable(true); - SetUpChild(); - Add(&sbackground); - Add(&sicon); - Add(&sLabel); - } - - TraingOtherItemView::~TraingOtherItemView() - { - Remove(&sbackground); - Remove(&sicon); - Remove(&sLabel); - } - - /// @brief 设置item的信息 - /// @param itemInfo - void TraingOtherItemView::SetItemInfo(const TraingOtherItem itemInfo) - { - sItemInfo = itemInfo; - sLabel.SetTextId(itemInfo.labelid); - } - - /// @brief 设置每一个itemview上的组件 - void TraingOtherItemView::SetUpChild() - { - sbackground.SetSrc(PNG_SETTING_BACKGROUND_IMAGE); - - sicon.SetPosition(330, 40); - sicon.SetSrc(ICON_IMAGE); - sicon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); - - sLabel.SetPosition(40, 33, 240, 35); - sLabel.SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); - sLabel.SetRollSpeed(70); -//sLabel.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - - sLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - } - - /// @brief 获取list的中每个组件的在list的下标 - /// @return 返回下标 - AppViewId TraingOtherItemView::GetTraingOtherIndex() - { - return sItemInfo.id; - } - UIResourceTextId TraingOtherItemView::GetTraingOtherId() - { - return sItemInfo.labelid; - } -} \ No newline at end of file + +namespace OHOS { + +TraingOtherItemView::TraingOtherItemView() { + SetPosition( + 0, 0, 380, + 120); // 每一个itemview宽高要配置好,因为加到list都是以这个视图为基准 + SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SetStyle(STYLE_BACKGROUND_OPA, 255); + SetTouchable(true); + SetUpChild(); + Add(&sbackground); + Add(&sicon); + Add(&sLabel); +} + +TraingOtherItemView::~TraingOtherItemView() { + Remove(&sbackground); + Remove(&sicon); + Remove(&sLabel); +} + +/// @brief 设置item的信息 +/// @param itemInfo +void TraingOtherItemView::SetItemInfo(const TraingOtherItem itemInfo) { + sItemInfo = itemInfo; + + // 先设置所有视图的可见性 + bool isVisible = false; + bool label_isVisible = false; + uint32_t color = Color::White().full; + SetTouchable(false); // 默认不触摸 + + switch (itemInfo.labelid) { + case STR_OTHER_LIST: + sLabel.SetTextId(itemInfo.labelid); + sLabel.SetPosition(90, 50, 200, 35); + isVisible = false; + label_isVisible = true; // 只有label可见 + color = Color::Green().full; // 设置label为绿色 + SetHeight(120); + break; + + case STR_MAX_ID: + isVisible = false; // 全部不可见 + label_isVisible = false; + SetHeight(60); + break; + + default: + sLabel.SetTextId(itemInfo.labelid); + sLabel.SetPosition(40, 33, 240, 35); + isVisible = true; // 所有元素可见 + label_isVisible = true; + SetHeight(120); + SetTouchable(true); + break; + } + + // 设置各个组件的可见性 + sLabel.SetVisible(label_isVisible); + sicon.SetVisible(isVisible); + sbackground.SetVisible(isVisible); + sLabel.SetStyle(STYLE_TEXT_COLOR, color); + + // 调整对齐方式 + if (itemInfo.labelid == STR_OTHER_LIST) { + sLabel.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + } else { + sLabel.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + } +} + +/// @brief 设置每一个itemview上的组件 +void TraingOtherItemView::SetUpChild() { + sbackground.SetSrc(PNG_SETTING_BACKGROUND_IMAGE); + + sicon.SetPosition(330, 40); + sicon.SetSrc(ICON_IMAGE); + sicon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + + sLabel.SetPosition(40, 33, 240, 35); + sLabel.SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + sLabel.SetRollSpeed(70); + sLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); +} + +/// @brief 获取list中每个组件的下标 +/// @return 返回下标 +AppViewId TraingOtherItemView::GetTraingOtherIndex() { + return sItemInfo.id; +} + +/// @brief 获取list中每个组件的运动Id +/// @return 返回下标 +UIResourceTextId TraingOtherItemView::GetTraingOtherId() { + return sItemInfo.labelid; +} + +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherModel.cpp index 14df81ab3..55d623fe8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherModel.cpp @@ -4,58 +4,55 @@ * @Date: 2024-03-29 15:51:45 * @LastEditors: Caisking 3449750381@qq.com * @LastEditTime: 2024-03-29 17:56:44 - * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherModel.cpp - * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + * @FilePath: + * /sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherModel.cpp + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 + * 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ #include "traing/training_list_other/include/TraingOtherModel.h" +#include "AppViewIDs.h" +#include "UiConfig.h" #include "common/image_cache_manager.h" #include "components/ui_label_ext.h" -#include "ui_resource_string.h" -#include "UiConfig.h" #include "ui_resource_image.h" -#include "AppViewIDs.h" -#include "components/ui_label_ext.h" #include "ui_resource_string.h" -namespace OHOS -{ - - TraingOtherModel::TraingOtherModel() {} - - TraingOtherModel::~TraingOtherModel() {} - - TraingOtherModel &TraingOtherModel::GetInstance() - { - static TraingOtherModel instance; - return instance; - } - - void TraingOtherModel::InitTraingOtherListItem() - { - TraingOtherItem defaultItems[] = { - {VIEW_TRAININGNOMAL, STR_OTHER_ELEVATOR}, - {VIEW_TRAININGNOMAL, STR_OTHER_ESCALATOR}, - {VIEW_TRAININGNOMAL, STR_OTHER_GARDENING}, - {VIEW_TRAININGNOMAL, STR_OTHER_HORSEWORK}, - {VIEW_TRAININGNOMAL, STR_OTHER_INVEHICLE}, - {VIEW_TRAININGNOMAL, STR_OTHER_MEDITATION}, - {VIEW_TRAININGNOMAL, STR_OTHER_STILL}, - {VIEW_TRAININGNOMAL, STR_OTHER_TILTING}, - {VIEW_TRAININGNOMAL, STR_OTHER_WHEELCHAIR}}; - - for (int i = 0; i < TraingOtherListMaxNum; i++) - { - TraingOthers[i] = defaultItems[i]; - } - } - - const TraingOtherItem *TraingOtherModel::GetTraingOtherlistItems() const - { - return TraingOthers; - } - uint8_t TraingOtherModel::GetTraingOtherListNum() const - { - return TraingOtherListMaxNum; - } - -} \ No newline at end of file +namespace OHOS { + +TraingOtherModel::TraingOtherModel() {} + +TraingOtherModel::~TraingOtherModel() {} + +TraingOtherModel &TraingOtherModel::GetInstance() { + static TraingOtherModel instance; + return instance; +} + +TraingOtherItem defaultItems[] = { + {VIEW_TRAININGNOMAL, STR_OTHER_LIST}, + {VIEW_TRAININGNOMAL, STR_OTHER_ELEVATOR}, + {VIEW_TRAININGNOMAL, STR_OTHER_ESCALATOR}, + {VIEW_TRAININGNOMAL, STR_OTHER_GARDENING}, + {VIEW_TRAININGNOMAL, STR_OTHER_HORSEWORK}, + {VIEW_TRAININGNOMAL, STR_OTHER_INVEHICLE}, + {VIEW_TRAININGNOMAL, STR_OTHER_MEDITATION}, + {VIEW_TRAININGNOMAL, STR_OTHER_STILL}, + {VIEW_TRAININGNOMAL, STR_OTHER_TILTING}, + {VIEW_TRAININGNOMAL, STR_OTHER_WHEELCHAIR}, + {VIEW_TRAININGNOMAL, STR_MAX_ID}, +}; +void TraingOtherModel::InitTraingOtherListItem() { + + for (int i = 0; i < TraingOtherListMaxNum; i++) { + TraingOthers[i] = defaultItems[i]; + } +} + +const TraingOtherItem *TraingOtherModel::GetTraingOtherlistItems() const { + return TraingOthers; +} +uint8_t TraingOtherModel::GetTraingOtherListNum() const { + return TraingOtherListMaxNum; +} + +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherView.cpp index f2169771e..db1929697 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherView.cpp @@ -1,187 +1,139 @@ -#include "traing/training_list_other/include/TraingOtherView.h" -#include "traing/training_list_other/include/TraingOtherPresenter.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_other/include/TraingOtherPresenter.h" +#include "traing/training_list_other/include/TraingOtherView.h" #include "ui_resource_string.h" -#include "UiConfig.h" +#include "uicomponents/UIComponents.h" #include "wearable_log.h" +#include -namespace OHOS -{ - static constexpr uint8_t NUM_2 = 2; - static TraingOtherView *g_pTraingOtherView{nullptr}; - /* --------------------------------- List --------------------------------- */ - static constexpr int16_t Other_LIST_POSITION_X = 43; - static constexpr int16_t Other_LIST_POSITION_Y = 120; - static constexpr int16_t Other_SCROLLBLANKSIZE = 35; // 设置此滚动视图的空白大小。 - static constexpr int16 MAX_SCR_DIS = 1000; - static constexpr int16 LIST_POS = 20; - static constexpr int16 SNUM_2 = 2; - - TraingOtherView::TraingOtherView() - { - g_pTraingOtherView = this; - } +namespace OHOS { +static TraingOtherView *g_pTraingOtherView{nullptr}; - TraingOtherView::~TraingOtherView() - { - if (viewInitStatus == true) - { - DeInitView(); - } - g_pTraingOtherView = nullptr; - } +TraingOtherView::TraingOtherView() { g_pTraingOtherView = this; } - TraingOtherView *TraingOtherView::GetInstance() - { - return g_pTraingOtherView; - } - /// @param item - void TraingOtherView::AddToTraingOtherList(const TraingOtherItem &item) - { - p_TraingOtherListAdapter->AddItem(item); - } +TraingOtherView::~TraingOtherView() { g_pTraingOtherView = nullptr; } - static void SetKeyActListener() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener"); - // 增加按键监听 - RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingOtherPresenter::GetInstance(); - RootView::GetInstance()->SetOnKeyActListener(keyactListener); - } - void TraingOtherView::InitView() - { - if (scrollView == nullptr) - { - scrollView = new UIScrollView(); - scrollView = new UIScrollView(); - if (scrollView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView new fail!"); - return; - } - scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - scrollView->SetScrollBlankSize(50); - // scrollView->SetReboundSize(35); - scrollView->SetHorizontalScrollState(false); - scrollView->RequestFocus(); - scrollView->SetRotateFactor(1.0); - scrollView->SetMaxScrollDistance(1000); - scrollView->SetDragACCLevel(5); - scrollView->SetSwipeACCLevel(800); /*设置手指抬起屏幕后的补偿距离。*/ - scrollView->SetTouchable(true); - scrollView->SetDraggable(true); - container_->Add(scrollView); - } - /* -------------------------------------------------------------------------- */ - // 初始化Lable 暂时不添加 - if (title == nullptr) - { - InitLabelExt(title, 135, 52, 200, 60, "label1", STR_OTHER_LIST, DEFAULT_VECTOR_FONT_FILENAME, 30); - title->SetStyle(STYLE_TEXT_COLOR, Color::Green().full); - scrollView->Add(title); - } - // UIList 的适配器 - if (p_TraingOtherListAdapter == nullptr) - { - p_TraingOtherListAdapter = new TraingOtherAdapter(); - p_TraingOtherListAdapter->SetItemClickListener(presenter_); - } - // 初始化列表 - if (TraingOtherList == nullptr) - { - TraingOtherList = new UIList(); - TraingOtherList->SetPosition(43, 120, 466, 466); - TraingOtherList->SetThrowDrag(true); - TraingOtherList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - TraingOtherList->SetMaxScrollDistance(1000); - TraingOtherList->SetSwipeACCLevel(800); - TraingOtherList->SetDragACCLevel(5); - // 增加表冠控制 - TraingOtherList->SetRotateFactor(2); - TraingOtherList->RequestFocus(); - } - } - UIList *TraingOtherView::GetList() - { - return TraingOtherList; - } - void TraingOtherView::DeInitView() - { - scrollView->RemoveAll(); - // RemoveAll(); - delete title; - title = nullptr; +TraingOtherView *TraingOtherView::GetInstance() { + return g_pTraingOtherView; +} - delete TraingOtherList; - TraingOtherList = nullptr; +void TraingOtherView::AddToTraingOtherList(const TraingOtherItem &item) { + if (p_TraingOtherListAdapter) { + p_TraingOtherListAdapter->AddItem(item); + } +} - delete scrollView; - scrollView = nullptr; +void TraingOtherView::SetKeyActListener() { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener"); + auto keyActListener = static_cast( + TraingOtherPresenter::GetInstance()); + RootView::GetInstance()->SetOnKeyActListener(keyActListener); +} - delete draglistener; - draglistener = nullptr; - } +void TraingOtherView::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 TraingOtherView::PreLoad(void) - { - if (!viewInitStatus) - { - InitView(); - viewInitStatus = true; - } - } +void TraingOtherView::InitList() { + if (p_TraingOtherListAdapter == nullptr) { + p_TraingOtherListAdapter = new TraingOtherAdapter(); + } + p_TraingOtherListAdapter->SetItemClickListener(presenter_); - /// @brief 页面启动时需要执行的代码逻辑 - void TraingOtherView::OnStart() - { - View::OnStart(); - BaseView::RootView(Color::Black().full); - SetContainerView(new UIViewGroup()); - container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - container_->SetOnDragListener(presenter_); - container_->SetTouchable(true); - container_->SetDraggable(true); - PreLoad(); - RootView::GetInstance()->SetOnKeyActListener(presenter_); - } + if (TraingOtherList == nullptr) { + TraingOtherList = new UIList(); + } + TraingOtherList->SetPosition(43, 0, HORIZONTAL_RESOLUTION, + VERTICAL_RESOLUTION); + TraingOtherList->SetThrowDrag(true); + TraingOtherList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + TraingOtherList->SetMaxScrollDistance(1000); + TraingOtherList->SetSwipeACCLevel(800); + TraingOtherList->SetDragACCLevel(5); + TraingOtherList->SetRotateFactor(1); + TraingOtherList->RequestFocus(); +} - /// @brief 创建页面的视图。 - void TraingOtherView::OnSetUpView() - { - View::OnSetUpView(); - if (TraingOtherList != nullptr && p_TraingOtherListAdapter != nullptr) - { - scrollView->Add(TraingOtherList); - scrollView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - RootView::GetInstance()->Add(scrollView); - TraingOtherList->SetAdapter(p_TraingOtherListAdapter); +void TraingOtherView::InitView() { + InitScrollView(); + InitList(); + SetKeyActListener(); +} + +void TraingOtherView::DeInitView() { + if (viewInitStatus) { + if (container_) { + container_->RemoveAll(); + if (scrollView) { + scrollView->RemoveAll(); + if (p_TraingOtherListAdapter) { + delete p_TraingOtherListAdapter; + p_TraingOtherListAdapter = nullptr; + } + if (TraingOtherList) { + delete TraingOtherList; + TraingOtherList = nullptr; } - Draw(); + delete scrollView; + scrollView = nullptr; + } } + delete container_; + container_ = nullptr; + } +} - /// @brief 销毁页面的视图。 - void TraingOtherView::OnTearDownView() - { - View::OnTearDownView(); - return; - } +void TraingOtherView::PreLoad() { + if (!viewInitStatus) { + InitView(); + viewInitStatus = true; + } +} - /// @brief 页面结束时需要执行的销毁逻辑。 - void TraingOtherView::OnStop() - { - View::OnStop(); - if (container_ != nullptr) - { - container_->RemoveAll(); - delete container_; - container_ = nullptr; - } - RootView::GetInstance()->ClearOnKeyActListener(); - RootView::GetInstance()->RemoveAll(); - return; +void TraingOtherView::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 TraingOtherView::OnSetUpView() { + View::OnSetUpView(); + if (scrollView && TraingOtherList) { + scrollView->Add(TraingOtherList); + scrollView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + container_->Add(scrollView); + if (p_TraingOtherListAdapter) { + TraingOtherList->SetAdapter(p_TraingOtherListAdapter); } -} \ No newline at end of file + Draw(); + } +} + +void TraingOtherView::OnTearDownView() { + View::OnTearDownView(); +} + +void TraingOtherView::OnStop() { + View::OnStop(); + RootView::GetInstance()->ClearOnKeyActListener(); + DeInitView(); + RootView::GetInstance()->RemoveAll(); +} +} // namespace OHOS \ No newline at end of file -- 2.17.1