From 00c0fd19cbcf1c10e76b2576c826efe611da3aef Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Sat, 5 Oct 2024 13:13:23 +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=E7=90=83=E7=B1=BB=E8=BF=90=E5=8A=A8=E2=80=9D=E5=88=97?= =?utf8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../include/TraingBallModel.h | 2 +- .../include/TraingBallView.h | 88 +++--- .../src/TraingBallItemView.cpp | 169 +++++----- .../src/TraingBallModel.cpp | 122 ++++---- .../training_list_ball/src/TraingBallView.cpp | 288 ++++++++---------- 5 files changed, 322 insertions(+), 347 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/include/TraingBallModel.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/include/TraingBallModel.h index cebb1d934..7e71b6346 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/include/TraingBallModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/include/TraingBallModel.h @@ -37,7 +37,7 @@ namespace OHOS TraingBallModel(const TraingBallModel &); TraingBallModel &operator=(const TraingBallModel &); virtual ~TraingBallModel(); - static const uint16_t TraingBallListMaxNum = 29; + static const uint16_t TraingBallListMaxNum = 31; TraingBallItem TraingBalls[TraingBallListMaxNum] = {VIEW_INVALID, STR_EXERCISE_GENERAL}; // std::map TraingBallIdToViewId; bool btConnectStatus{false}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/include/TraingBallView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/include/TraingBallView.h index 510f30e4c..ccdded8d0 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/include/TraingBallView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/include/TraingBallView.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_ball/include/TraingBallView.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_ball/include/TraingBallView.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 + * 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ #ifndef TraingBall_VIEW_H @@ -12,50 +14,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_ball/include/TraingBallAdapter.h" #include "traing/training_list_ball/include/TraingBallModel.h" -#include "components/ui_label_button_ext.h" -#include "components/ui_label_ext.h" -#include"ui_resource_string.h" - -namespace OHOS -{ - class TraingBallPresenter; - class TraingBallModel; - class TraingBallView : public View, public UIViewGroup - { - - public: - TraingBallView(); - virtual ~TraingBallView(); - static TraingBallView *GetInstance(void); - - void OnStart() override; - void OnSetUpView() override; - void OnTearDownView() override; - void OnStop() override; - - UIList *GetList(); - void AddToTraingBallList(const TraingBallItem &item); - - private: - void InitView(void); - void DeInitView(void); - void PreLoad(void); - - private: - UIScrollView *scrollView = nullptr; - UILabelExt *title{nullptr}; - TraingBallAdapter *p_TraingBallListAdapter{nullptr}; - UIList *TraingBallList = nullptr; - UIView::OnDragListener *draglistener{nullptr}; - - TraingBallPresenter *g_TraingBallPresenter{nullptr}; - TraingBallModel *g_TraingBallModel{nullptr}; - bool viewInitStatus{false}; - }; +#include "ui_resource_string.h" + +namespace OHOS { +class TraingBallPresenter; +class TraingBallModel; +class TraingBallView : public View, public UIViewGroup { + +public: + TraingBallView(); + virtual ~TraingBallView(); + static TraingBallView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + UIList *GetList(); + void AddToTraingBallList(const TraingBallItem &item); + +private: + void InitView(void); + void InitList(); + void InitScrollView(); + void DeInitView(void); + void PreLoad(void); + void SetKeyActListener(void); + +private: + UIScrollView *scrollView = nullptr; + TraingBallAdapter *p_TraingBallListAdapter{nullptr}; + UIList *TraingBallList = 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_ball/src/TraingBallItemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/src/TraingBallItemView.cpp index 979257403..e7178afee 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/src/TraingBallItemView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/src/TraingBallItemView.cpp @@ -1,72 +1,103 @@ -/*** - * @Date: 2024-04-15 10:55:58 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-09-07 12:09:40 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/src/TraingBallItemView.cpp - */ - #include "traing/training_list_ball/include/TraingBallItemView.h" +#include "UiConfig.h" +#include "traing/Training_UiConfig.h" #include "traing/include/TraingModel.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 -{ - - TraingBallItemView::TraingBallItemView() - { - 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); - } - - TraingBallItemView::~TraingBallItemView() - { - Remove(&sbackground); - Remove(&sicon); - Remove(&sLabel); - } - - /// @brief 设置item的信息 - /// @param itemInfo - void TraingBallItemView::SetItemInfo(const TraingBallItem itemInfo) - { - sItemInfo = itemInfo; - sLabel.SetTextId(itemInfo.labelid); - } - - /// @brief 设置每一个itemview上的组件 - void TraingBallItemView::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 TraingBallItemView::GetTraingBallIndex() - { - return sItemInfo.id; - } - UIResourceTextId TraingBallItemView::GetTraingBallId() - { - return sItemInfo.labelid; - } -} \ No newline at end of file + +namespace OHOS { + +TraingBallItemView::TraingBallItemView() { + 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); +} + +TraingBallItemView::~TraingBallItemView() { + Remove(&sbackground); + Remove(&sicon); + Remove(&sLabel); +} + +/// @brief 设置item的信息 +/// @param itemInfo +void TraingBallItemView::SetItemInfo(const TraingBallItem itemInfo) { + sItemInfo = itemInfo; + + // 先设置所有视图的可见性 + bool isVisible = false; + bool label_isVisible = false; + uint32_t color = Color::White().full; + SetTouchable(false); // 默认不触摸 + + switch (itemInfo.labelid) { + case STR_BALL_LIST_TITLE: + 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_BALL_LIST: + 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_BALL_LIST_TITLE) { + sLabel.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + } else { + sLabel.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + } +} + +/// @brief 设置每一个itemview上的组件 +void TraingBallItemView::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 TraingBallItemView::GetTraingBallIndex() { return sItemInfo.id; } + +/// @brief 获取list中每个组件的运动Id +/// @return 返回下标 +UIResourceTextId TraingBallItemView::GetTraingBallId() { + return sItemInfo.labelid; +} + +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/src/TraingBallModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/src/TraingBallModel.cpp index a7f51f9ec..2b2348c00 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/src/TraingBallModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/src/TraingBallModel.cpp @@ -1,81 +1,77 @@ -/*** +/*** * @Author: Caisking 3449750381@qq.com * @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_ball/src/TraingBallModel.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_ball/src/TraingBallModel.cpp + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 + * 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ - #include "traing/training_list_ball/include/TraingBallModel.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 -{ +namespace OHOS { - TraingBallModel::TraingBallModel() {} +TraingBallModel::TraingBallModel() {} - TraingBallModel::~TraingBallModel() {} +TraingBallModel::~TraingBallModel() {} - TraingBallModel &TraingBallModel::GetInstance() - { - static TraingBallModel instance; - return instance; - } +TraingBallModel &TraingBallModel::GetInstance() { + static TraingBallModel instance; + return instance; +} - void TraingBallModel::InitTraingBallListItem() - { - TraingBallItem defaultItems[] = { - {VIEW_TRAININGNOMAL, STR_BALL_GAMES}, - {VIEW_TRAININGNOMAL, STR_BALL_BADMINTON}, - {VIEW_TRAININGNOMAL, STR_BALL_TABLETENNIS}, - {VIEW_TRAININGNOMAL, STR_BALL_TENNIS}, - {VIEW_TRAININGNOMAL, STR_BALL_BILLIARDS}, - {VIEW_TRAININGNOMAL, STR_BALL_BOWLING}, - {VIEW_TRAININGNOMAL, STR_BALL_VOLLEYBALL}, - {VIEW_TRAININGNOMAL, STR_BALL_SHUTTLECOCK}, - {VIEW_TRAININGNOMAL, STR_BALL_HANDBALL}, - {VIEW_TRAININGNOMAL, STR_BALL_BASEBALL}, - {VIEW_TRAININGNOMAL, STR_BALL_SOFTBALL}, - {VIEW_TRAININGNOMAL, STR_BALL_CRICKET}, - {VIEW_TRAININGNOMAL, STR_BALL_FOOTBALL}, - {VIEW_TRAININGNOMAL, STR_BALL_BEACHSOCCER}, - {VIEW_TRAININGNOMAL, STR_BALL_BEACHVOLLEYBALL}, - {VIEW_TRAININGNOMAL, STR_BALL_CROQUET}, - {VIEW_TRAININGNOMAL, STR_BALL_HOCKEY}, - {VIEW_TRAININGNOMAL, STR_BALL_SQUASH}, - {VIEW_TRAININGNOMAL, STR_BALL_SEPAKTAKRAW}, - {VIEW_TRAININGNOMAL, STR_BALL_DODGEBALL}, - {VIEW_TRAININGNOMAL, STR_BALL_BASKETBALL}, - {VIEW_TRAININGNOMAL, STR_BALL_SOCCER}, - {VIEW_TRAININGNOMAL, STR_BALL_GOLF}, - {VIEW_TRAININGNOMAL, STR_BALL_POLO}, - {VIEW_TRAININGNOMAL, STR_BALL_RACQUETBALL}, - {VIEW_TRAININGNOMAL, STR_BALL_RUGBY}, - {VIEW_TRAININGNOMAL, STR_BALL_GATEBALL}, - {VIEW_TRAININGNOMAL, STR_BALL_PICKLEBALL}, - {VIEW_TRAININGNOMAL, STR_BALL_LACROSSE}}; +void TraingBallModel::InitTraingBallListItem() { + TraingBallItem defaultItems[] = { + {VIEW_TRAININGNOMAL, STR_BALL_LIST_TITLE}, + {VIEW_TRAININGNOMAL, STR_BALL_GAMES}, + {VIEW_TRAININGNOMAL, STR_BALL_BADMINTON}, + {VIEW_TRAININGNOMAL, STR_BALL_TABLETENNIS}, + {VIEW_TRAININGNOMAL, STR_BALL_TENNIS}, + {VIEW_TRAININGNOMAL, STR_BALL_BILLIARDS}, + {VIEW_TRAININGNOMAL, STR_BALL_BOWLING}, + {VIEW_TRAININGNOMAL, STR_BALL_VOLLEYBALL}, + {VIEW_TRAININGNOMAL, STR_BALL_SHUTTLECOCK}, + {VIEW_TRAININGNOMAL, STR_BALL_HANDBALL}, + {VIEW_TRAININGNOMAL, STR_BALL_BASEBALL}, + {VIEW_TRAININGNOMAL, STR_BALL_SOFTBALL}, + {VIEW_TRAININGNOMAL, STR_BALL_CRICKET}, + {VIEW_TRAININGNOMAL, STR_BALL_FOOTBALL}, + {VIEW_TRAININGNOMAL, STR_BALL_BEACHSOCCER}, + {VIEW_TRAININGNOMAL, STR_BALL_BEACHVOLLEYBALL}, + {VIEW_TRAININGNOMAL, STR_BALL_CROQUET}, + {VIEW_TRAININGNOMAL, STR_BALL_HOCKEY}, + {VIEW_TRAININGNOMAL, STR_BALL_SQUASH}, + {VIEW_TRAININGNOMAL, STR_BALL_SEPAKTAKRAW}, + {VIEW_TRAININGNOMAL, STR_BALL_DODGEBALL}, + {VIEW_TRAININGNOMAL, STR_BALL_BASKETBALL}, + {VIEW_TRAININGNOMAL, STR_BALL_SOCCER}, + {VIEW_TRAININGNOMAL, STR_BALL_GOLF}, + {VIEW_TRAININGNOMAL, STR_BALL_POLO}, + {VIEW_TRAININGNOMAL, STR_BALL_RACQUETBALL}, + {VIEW_TRAININGNOMAL, STR_BALL_RUGBY}, + {VIEW_TRAININGNOMAL, STR_BALL_GATEBALL}, + {VIEW_TRAININGNOMAL, STR_BALL_PICKLEBALL}, + {VIEW_TRAININGNOMAL, STR_BALL_LACROSSE}, + {VIEW_TRAININGNOMAL, STR_BALL_LIST}, + }; - for (int i = 0; i < TraingBallListMaxNum; i++) - { - TraingBalls[i] = defaultItems[i]; - } - } + for (int i = 0; i < TraingBallListMaxNum; i++) { + TraingBalls[i] = defaultItems[i]; + } +} - const TraingBallItem *TraingBallModel::GetTraingBalllistItems() const - { - return TraingBalls; - } - uint8_t TraingBallModel::GetTraingBallListNum() const - { - return TraingBallListMaxNum; - } +const TraingBallItem *TraingBallModel::GetTraingBalllistItems() const { + return TraingBalls; +} +uint8_t TraingBallModel::GetTraingBallListNum() const { + return TraingBallListMaxNum; +} -} \ No newline at end of file +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/src/TraingBallView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/src/TraingBallView.cpp index af442310e..8582ff1da 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/src/TraingBallView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/src/TraingBallView.cpp @@ -1,187 +1,137 @@ -#include "traing/training_list_ball/include/TraingBallView.h" -#include "traing/training_list_ball/include/TraingBallPresenter.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_ball/include/TraingBallPresenter.h" +#include "traing/training_list_ball/include/TraingBallView.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 TraingBallView *g_pTraingBallView{nullptr}; - /* --------------------------------- List --------------------------------- */ - static constexpr int16_t Ball_LIST_POSITION_X = 43; - static constexpr int16_t Ball_LIST_POSITION_Y = 120; - static constexpr int16_t Ball_SCROLLBLANKSIZE = 35; // 设置此滚动视图的空白大小。 - static constexpr int16 MAX_SCR_DIS = 1000; - static constexpr int16 LIST_POS = 20; - static constexpr int16 SNUM_2 = 2; - - TraingBallView::TraingBallView() - { - g_pTraingBallView = this; - } +namespace OHOS { +static TraingBallView *g_pTraingBallView{nullptr}; - TraingBallView::~TraingBallView() - { - if (viewInitStatus == true) - { - DeInitView(); - } - g_pTraingBallView = nullptr; - } +TraingBallView::TraingBallView() { g_pTraingBallView = this; } - TraingBallView *TraingBallView::GetInstance() - { - return g_pTraingBallView; - } - /// @param item - void TraingBallView::AddToTraingBallList(const TraingBallItem &item) - { - p_TraingBallListAdapter->AddItem(item); - } - static void SetKeyActListener() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener"); - // 增加按键监听 - RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingBallPresenter::GetInstance(); - RootView::GetInstance()->SetOnKeyActListener(keyactListener); - } - void TraingBallView::InitView() - { - if (scrollView == nullptr) - { - 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_BALL_LIST_TITLE, DEFAULT_VECTOR_FONT_FILENAME, 30); - title->SetStyle(STYLE_TEXT_COLOR, Color::Green().full); - scrollView->Add(title); - } - // UIList 的适配器 - if (p_TraingBallListAdapter == nullptr) - { - p_TraingBallListAdapter = new TraingBallAdapter(); - p_TraingBallListAdapter->SetItemClickListener(presenter_); - } - // 初始化列表 - if (TraingBallList == nullptr) - { - TraingBallList = new UIList(); - TraingBallList->SetPosition(43, 120, 466, 466); - TraingBallList->SetThrowDrag(true); - TraingBallList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - TraingBallList->SetMaxScrollDistance(1000); - TraingBallList->SetSwipeACCLevel(800); - TraingBallList->SetDragACCLevel(5); - // 增加表冠控制 - TraingBallList->SetRotateFactor(2); - TraingBallList->RequestFocus(); - } - } - UIList *TraingBallView::GetList() - { - return TraingBallList; - } - void TraingBallView::DeInitView() - { - // scrollView-> RemoveAll(); - RemoveAll(); - delete title; - title = nullptr; +TraingBallView::~TraingBallView() { g_pTraingBallView = nullptr; } - delete TraingBallList; - TraingBallList = nullptr; +TraingBallView *TraingBallView::GetInstance() { return g_pTraingBallView; } - delete scrollView; - scrollView = nullptr; +void TraingBallView::AddToTraingBallList(const TraingBallItem &item) { + if (p_TraingBallListAdapter) { + p_TraingBallListAdapter->AddItem(item); + } +} - delete draglistener; - draglistener = nullptr; - } +void TraingBallView::SetKeyActListener() { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener"); + auto keyActListener = static_cast( + TraingBallPresenter::GetInstance()); + RootView::GetInstance()->SetOnKeyActListener(keyActListener); +} - void TraingBallView::PreLoad(void) - { - if (!viewInitStatus) - { - InitView(); - viewInitStatus = true; - } - } +void TraingBallView::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); +} - /// @brief 页面启动时需要执行的代码逻辑 - void TraingBallView::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_); - } +void TraingBallView::InitList() { + if (p_TraingBallListAdapter == nullptr) { + p_TraingBallListAdapter = new TraingBallAdapter(); + } + p_TraingBallListAdapter->SetItemClickListener(presenter_); + + if (TraingBallList == nullptr) { + TraingBallList = new UIList(); + } + TraingBallList->SetPosition(43, 0, HORIZONTAL_RESOLUTION, + VERTICAL_RESOLUTION); + TraingBallList->SetThrowDrag(true); + TraingBallList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + TraingBallList->SetMaxScrollDistance(1000); + TraingBallList->SetSwipeACCLevel(800); + TraingBallList->SetDragACCLevel(5); + TraingBallList->SetRotateFactor(1); + TraingBallList->RequestFocus(); +} + +void TraingBallView::InitView() { + InitScrollView(); + InitList(); + SetKeyActListener(); +} - /// @brief 创建页面的视图。 - void TraingBallView::OnSetUpView() - { - View::OnSetUpView(); - if (TraingBallList != nullptr && p_TraingBallListAdapter != nullptr) - { - scrollView->Add(TraingBallList); - scrollView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); - RootView::GetInstance()->Add(scrollView); - TraingBallList->SetAdapter(p_TraingBallListAdapter); +void TraingBallView::DeInitView() { + if (viewInitStatus) { + if (container_) { + container_->RemoveAll(); + if (scrollView) { + scrollView->RemoveAll(); + if (p_TraingBallListAdapter) { + delete p_TraingBallListAdapter; + p_TraingBallListAdapter = nullptr; } - Draw(); + if (TraingBallList) { + delete TraingBallList; + TraingBallList = nullptr; + } + delete scrollView; + scrollView = nullptr; + } } + delete container_; + container_ = nullptr; + } +} - /// @brief 销毁页面的视图。 - void TraingBallView::OnTearDownView() - { - View::OnTearDownView(); - return; - } +void TraingBallView::PreLoad() { + if (!viewInitStatus) { + InitView(); + viewInitStatus = true; + } +} - /// @brief 页面结束时需要执行的销毁逻辑。 - void TraingBallView::OnStop() - { - View::OnStop(); +void TraingBallView::OnStart() { + View::OnStart(); + SetContainerView(new UIViewGroup()); + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), + Screen::GetInstance().GetHeight()); + BaseView::RootView(Color::Black().full); + PreLoad(); + SetContainerView(container_); +} - if (container_ != nullptr) - { - container_->RemoveAll(); - delete container_; - container_ = nullptr; - } - RootView::GetInstance()->ClearOnKeyActListener(); - RootView::GetInstance()->RemoveAll(); - return; +void TraingBallView::OnSetUpView() { + View::OnSetUpView(); + if (scrollView && TraingBallList) { + scrollView->Add(TraingBallList); + scrollView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + container_->Add(scrollView); + if (p_TraingBallListAdapter) { + TraingBallList->SetAdapter(p_TraingBallListAdapter); } -} \ No newline at end of file + Draw(); + } +} + +void TraingBallView::OnTearDownView() { + View::OnTearDownView(); +} + +void TraingBallView::OnStop() { + View::OnStop(); + RootView::GetInstance()->ClearOnKeyActListener(); + DeInitView(); + RootView::GetInstance()->RemoveAll(); +} +} // namespace OHOS \ No newline at end of file -- 2.17.1