From 00a756801a97e1ce4d09e58ba1d0aa1a4e6fee72 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Sat, 5 Oct 2024 11:01:41 +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=81=A5=E8=BA=AB=E7=B1=BB=E2=80=9D=E5=88=97=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../include/TraingFitnessItemView.h | 49 +++-- .../include/TraingFitnessModel.h | 2 +- .../include/TraingFitnessView.h | 2 +- .../src/TraingFitnessItemView.cpp | 166 +++++++++------- .../src/TraingFitnessModel.cpp | 177 +++++++++-------- .../src/TraingFitnessView.cpp | 30 +-- .../src/TraingMoreItemView.cpp | 179 +++++++++++------- 7 files changed, 340 insertions(+), 265 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/include/TraingFitnessItemView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/include/TraingFitnessItemView.h index 57c780581..ca58ea178 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/include/TraingFitnessItemView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/include/TraingFitnessItemView.h @@ -3,35 +3,34 @@ #ifndef TraingFitness_ITEM_VIEW_H #define TraingFitness_ITEM_VIEW_H -#include "components/ui_label.h" -#include "components/ui_label_ext.h" -#include "ui_resource_string.h" -#include "components/ui_view_group.h" +#include "AppViewIDs.h" #include "components/ui_checkbox.h" #include "components/ui_image_view.h" -#include "traing/training_list_fitness/include/TraingFitnessAdapter.h" +#include "components/ui_label.h" #include "components/ui_label_button.h" -#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include "components/ui_view_group.h" #include "ohos_types.h" +#include "traing/training_list_fitness/include/TraingFitnessAdapter.h" +#include "ui_resource_string.h" + +namespace OHOS { +class TraingFitnessItemView : public UIViewGroup { +public: + explicit TraingFitnessItemView(); + virtual ~TraingFitnessItemView(); + virtual void SetItemInfo(const TraingFitnessItem itemInfo); + virtual void SetUpChild(); + AppViewId GetTraingFitnessIndex(); + UIResourceTextId GetTraingFitnessId(); -namespace OHOS -{ - class TraingFitnessItemView : public UIViewGroup - { - public: - explicit TraingFitnessItemView(); - virtual ~TraingFitnessItemView(); - virtual void SetItemInfo(const TraingFitnessItem itemInfo); - virtual void SetUpChild(); - AppViewId GetTraingFitnessIndex(); - UIResourceTextId GetTraingFitnessId(); - private: - TraingFitnessItemView(const TraingFitnessItemView &); - UIImageView sbackground; // 背景 - UIImageView sicon; // 箭头 - UILabelExt sLabel; // 标签 - TraingFitnessItem sItemInfo = {VIEW_INVALID, STR_EXERCISE_GENERAL}; - }; +private: + TraingFitnessItemView(const TraingFitnessItemView &); + UIImageView sbackground; // 背景 + UIImageView sicon; // 箭头 + UILabelExt sLabel; // 标签 + TraingFitnessItem sItemInfo = {VIEW_INVALID, STR_EXERCISE_GENERAL}; +}; -} +} // namespace OHOS #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/include/TraingFitnessModel.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/include/TraingFitnessModel.h index 5221662ca..28f683763 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/include/TraingFitnessModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/include/TraingFitnessModel.h @@ -31,7 +31,7 @@ namespace OHOS TraingFitnessModel(const TraingFitnessModel &); TraingFitnessModel &operator=(const TraingFitnessModel &); virtual ~TraingFitnessModel(); - static const uint16_t TraingFitnessListMaxNum = 57; + static const uint16_t TraingFitnessListMaxNum = 59; TraingFitnessItem TraingFitnesss[TraingFitnessListMaxNum] = {VIEW_INVALID, STR_EXERCISE_GENERAL}; // std::map TraingFitnessIdToViewId; diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/include/TraingFitnessView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/include/TraingFitnessView.h index ef2bda153..8ce359299 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/include/TraingFitnessView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/include/TraingFitnessView.h @@ -50,7 +50,7 @@ namespace OHOS private: UIScrollView *scrollView = nullptr; - UILabelExt *title{nullptr}; + // UILabelExt *title{nullptr}; TraingFitnessAdapter *p_TraingFitnessListAdapter{nullptr}; UIList *TraingFitnessList = nullptr; UIView::OnDragListener *draglistener{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/src/TraingFitnessItemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/src/TraingFitnessItemView.cpp index c9172ce22..99737ab35 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/src/TraingFitnessItemView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/src/TraingFitnessItemView.cpp @@ -1,67 +1,105 @@ - #include "traing/training_list_fitness/include/TraingFitnessItemView.h" +#include "UiConfig.h" +#include "traing/Training_UiConfig.h" #include "traing/include/TraingModel.h" #include "uicomponents/UIComponents.h" -#include "traing/Training_UiConfig.h" -#include "UiConfig.h" -namespace OHOS -{ - - TraingFitnessItemView::TraingFitnessItemView() - { - 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); - } - - TraingFitnessItemView::~TraingFitnessItemView() - { - Remove(&sbackground); - Remove(&sicon); - Remove(&sLabel); - } - - /// @brief 设置item的信息 - /// @param itemInfo - void TraingFitnessItemView::SetItemInfo(const TraingFitnessItem itemInfo) - { - sItemInfo = itemInfo; - sLabel.SetTextId(itemInfo.labelid); - } - - /// @brief 设置每一个itemview上的组件 - void TraingFitnessItemView::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 TraingFitnessItemView::GetTraingFitnessIndex() - { - return sItemInfo.id; - } - - /// @brief 获取list的中每个组件的在list的运动Id - /// @return 返回下标 - UIResourceTextId TraingFitnessItemView::GetTraingFitnessId() - { - return sItemInfo.labelid; - } -} \ No newline at end of file + +namespace OHOS { + +TraingFitnessItemView::TraingFitnessItemView() { + 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); +} + +TraingFitnessItemView::~TraingFitnessItemView() { + Remove(&sbackground); + Remove(&sicon); + Remove(&sLabel); +} + +/// @brief 设置item的信息 +/// @param itemInfo +void TraingFitnessItemView::SetItemInfo(const TraingFitnessItem itemInfo) { + sItemInfo = itemInfo; + + // 先设置所有视图的可见性 + bool isVisible = false; + bool label_isVisible = false; + uint32_t color = Color::White().full; + SetTouchable(false); // 默认不触摸 + + switch (itemInfo.labelid) { + case STR_EXERCISE_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_EXERCISE_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_EXERCISE_TITLE) { + sLabel.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + } else { + sLabel.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + } +} + +/// @brief 设置每一个itemview上的组件 +void TraingFitnessItemView::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 TraingFitnessItemView::GetTraingFitnessIndex() { + return sItemInfo.id; +} + +/// @brief 获取list中每个组件的运动Id +/// @return 返回下标 +UIResourceTextId TraingFitnessItemView::GetTraingFitnessId() { + return sItemInfo.labelid; +} + +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/src/TraingFitnessModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/src/TraingFitnessModel.cpp index 2685852f8..cf580c3f7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/src/TraingFitnessModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/src/TraingFitnessModel.cpp @@ -3,102 +3,101 @@ * @Date: 2024-03-26 18:34:15 * @LastEditors: Caisking 3449750381@qq.com * @LastEditTime: 2024-03-26 18:36:25 - * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/src/TraingFitnessModel.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_fitness/src/TraingFitnessModel.cpp + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 + * 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ #include "traing/training_list_fitness/include/TraingFitnessModel.h" -#include "common/image_cache_manager.h" +#include "AppViewIDs.h" #include "UiConfig.h" +#include "common/image_cache_manager.h" #include "ui_resource_image.h" -#include "AppViewIDs.h" -namespace OHOS -{ +namespace OHOS { - TraingFitnessModel::TraingFitnessModel() {} +TraingFitnessModel::TraingFitnessModel() {} - TraingFitnessModel::~TraingFitnessModel() {} +TraingFitnessModel::~TraingFitnessModel() {} - TraingFitnessModel &TraingFitnessModel::GetInstance() - { - static TraingFitnessModel instance; - return instance; - } - UIResourceTextId text[] = { - STR_EXERCISE_OUTDOORWALKING, - STR_EXERCISE_OUTDOORRUNNING, - STR_EXERCISE_OUTDOORBIKING, - STR_EXERCISE_GENERAL, - STR_EXERCISE_FREETRAINING, - STR_EXERCISE_RESISTANCETRAINING, - STR_EXERCISE_SPINBIKE, - STR_EXERCISE_TREADMILL, - STR_EXERCISE_STROLLMACHINE, - STR_EXERCISE_HIIT, - STR_EXERCISE_CROSSFIT, - STR_EXERCISE_GROUPCALISTHENICS, - STR_EXERCISE_YOGA, - STR_EXERCISE_YOGACAT, - STR_EXERCISE_YOGACOW, - STR_EXERCISE_YOGACOBRA, - STR_EXERCISE_YOGAHERO1, - STR_EXERCISE_YOGAHERO2, - STR_EXERCISE_YOGAHERO3, - STR_EXERCISE_YOGAROLLING, - STR_EXERCISE_INDOORWALKING, - STR_EXERCISE_INDOORRUNNING, - STR_EXERCISE_JUMPINGROPE, - STR_EXERCISE_PILATES, - STR_EXERCISE_CROSS_FIT, - STR_EXERCISE_FUNCTIONALTRAINING, - STR_EXERCISE_PHYSICALTRAINING, - STR_EXERCISE_TAEKWONDO, - STR_EXERCISE_BOXING, - STR_EXERCISE_KICKBOXING, - STR_EXERCISE_KARATE, - STR_EXERCISE_FENCING, - STR_EXERCISE_CORETRAINING, - STR_EXERCISE_BODYCOMBAT, - STR_EXERCISE_KENDO, - STR_EXERCISE_HORIZONTALBAR, - STR_EXERCISE_PARALLELBARS, - STR_EXERCISE_CIRCUIT, - STR_EXERCISE_AEROBICS, - STR_EXERCISE_CALISTHENICE, - STR_EXERCISE_P90X, - STR_EXERCISE_KETTLEBELLTRAINING, - STR_EXERCISE_MIXEDMARTIALARTS, - STR_EXERCISE_STAIRCLIMBINGMACHINE, - STR_EXERCISE_WEIGHTLIFTING, - STR_EXERCISE_BARRE, - STR_EXERCISE_HANDCYCLING, - STR_EXERCISE_TRACKFIELD, - STR_EXERCISE_WRESTLING, - STR_EXERCISE_MINDBODY, - STR_EXERCISE_FLEXIBILITY, - STR_EXERCISE_MIXEDCARDIO, - STR_EXERCISE_TRADITIONALSTRENGTHTRAINING, - STR_EXERCISE_CROSSTRAINING, - STR_EXERCISE_GYMNASTICS, - STR_EXERCISE_STEPTRAINING, - STR_EXERCISE_ELLIPTICALTRAINER, - STR_EXERCISE_ROWINGMACHINE, - }; +TraingFitnessModel &TraingFitnessModel::GetInstance() { + static TraingFitnessModel instance; + return instance; +} +UIResourceTextId text[] = { + STR_EXERCISE_TITLE, // title 健身运动 + STR_EXERCISE_OUTDOORWALKING, + STR_EXERCISE_OUTDOORRUNNING, + STR_EXERCISE_OUTDOORBIKING, + STR_EXERCISE_GENERAL, + STR_EXERCISE_FREETRAINING, + STR_EXERCISE_RESISTANCETRAINING, + STR_EXERCISE_SPINBIKE, + STR_EXERCISE_TREADMILL, + STR_EXERCISE_STROLLMACHINE, + STR_EXERCISE_HIIT, + STR_EXERCISE_CROSSFIT, + STR_EXERCISE_GROUPCALISTHENICS, + STR_EXERCISE_YOGA, + STR_EXERCISE_YOGACAT, + STR_EXERCISE_YOGACOW, + STR_EXERCISE_YOGACOBRA, + STR_EXERCISE_YOGAHERO1, + STR_EXERCISE_YOGAHERO2, + STR_EXERCISE_YOGAHERO3, + STR_EXERCISE_YOGAROLLING, + STR_EXERCISE_INDOORWALKING, + STR_EXERCISE_INDOORRUNNING, + STR_EXERCISE_JUMPINGROPE, + STR_EXERCISE_PILATES, + STR_EXERCISE_CROSS_FIT, + STR_EXERCISE_FUNCTIONALTRAINING, + STR_EXERCISE_PHYSICALTRAINING, + STR_EXERCISE_TAEKWONDO, + STR_EXERCISE_BOXING, + STR_EXERCISE_KICKBOXING, + STR_EXERCISE_KARATE, + STR_EXERCISE_FENCING, + STR_EXERCISE_CORETRAINING, + STR_EXERCISE_BODYCOMBAT, + STR_EXERCISE_KENDO, + STR_EXERCISE_HORIZONTALBAR, + STR_EXERCISE_PARALLELBARS, + STR_EXERCISE_CIRCUIT, + STR_EXERCISE_AEROBICS, + STR_EXERCISE_CALISTHENICE, + STR_EXERCISE_P90X, + STR_EXERCISE_KETTLEBELLTRAINING, + STR_EXERCISE_MIXEDMARTIALARTS, + STR_EXERCISE_STAIRCLIMBINGMACHINE, + STR_EXERCISE_WEIGHTLIFTING, + STR_EXERCISE_BARRE, + STR_EXERCISE_HANDCYCLING, + STR_EXERCISE_TRACKFIELD, + STR_EXERCISE_WRESTLING, + STR_EXERCISE_MINDBODY, + STR_EXERCISE_FLEXIBILITY, + STR_EXERCISE_MIXEDCARDIO, + STR_EXERCISE_TRADITIONALSTRENGTHTRAINING, + STR_EXERCISE_CROSSTRAINING, + STR_EXERCISE_GYMNASTICS, + STR_EXERCISE_STEPTRAINING, + STR_EXERCISE_ELLIPTICALTRAINER, + STR_EXERCISE_ROWINGMACHINE, + STR_EXERCISE_LIST, //健身类 +}; - void TraingFitnessModel::InitTraingFitnessListItem() - { - for (int i = 0; i < 57; ++i) // 更新循环以适应 57 个元素 - { - TraingFitnesss[i] = {VIEW_TRAININGNOMAL, text[i]}; - } - } - const TraingFitnessItem *TraingFitnessModel::GetTraingFitnesslistItems() const - { - return TraingFitnesss; - } - uint8_t TraingFitnessModel::GetTraingFitnessListNum() const - { - return TraingFitnessListMaxNum; - } +void TraingFitnessModel::InitTraingFitnessListItem() { + for (int i = 0; i < 59; ++i) // 更新循环以适应 57 个元素 + { + TraingFitnesss[i] = {VIEW_TRAININGNOMAL, text[i]}; + } +} +const TraingFitnessItem *TraingFitnessModel::GetTraingFitnesslistItems() const { + return TraingFitnesss; +} +uint8_t TraingFitnessModel::GetTraingFitnessListNum() const { + return TraingFitnessListMaxNum; +} -} \ 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_fitness/src/TraingFitnessView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/src/TraingFitnessView.cpp index c05f827a9..c7225b950 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/src/TraingFitnessView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/src/TraingFitnessView.cpp @@ -61,11 +61,11 @@ namespace OHOS return; } scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - scrollView->SetScrollBlankSize(50); - // scrollView->SetReboundSize(35); + // scrollView->SetScrollBlankSize(50); + // // scrollView->SetReboundSize(35); scrollView->SetHorizontalScrollState(false); - scrollView->RequestFocus(); - scrollView->SetRotateFactor(1.0); + // scrollView->RequestFocus(); + // scrollView->SetRotateFactor(1.0); scrollView->SetMaxScrollDistance(1000); scrollView->SetDragACCLevel(5); scrollView->SetSwipeACCLevel(800); /*设置手指抬起屏幕后的补偿距离。*/ @@ -74,13 +74,13 @@ namespace OHOS container_->Add(scrollView); } /* -------------------------------------------------------------------------- */ - // 初始化Lable 暂时不添加 - if (title == nullptr) - { - InitLabelExt(title, 135, 52, 200, 60, "label1", STR_EXERCISE_TITLE, DEFAULT_VECTOR_FONT_FILENAME, 30); - title->SetStyle(STYLE_TEXT_COLOR, Color::Green().full); - scrollView->Add(title); - } + // // 初始化Lable 暂时不添加 + // if (title == nullptr) + // { + // InitLabelExt(title, 135, 52, 200, 60, "label1", STR_EXERCISE_TITLE, DEFAULT_VECTOR_FONT_FILENAME, 30); + // title->SetStyle(STYLE_TEXT_COLOR, Color::Green().full); + // scrollView->Add(title); + // } // UIList 的适配器 if (p_TraingFitnessListAdapter == nullptr) { @@ -91,14 +91,14 @@ namespace OHOS if (TraingFitnessList == nullptr) { TraingFitnessList = new UIList(); - TraingFitnessList->SetPosition(43, 120, 466, 466); + TraingFitnessList->SetPosition(43, 0, 466, 466); TraingFitnessList->SetThrowDrag(true); TraingFitnessList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); TraingFitnessList->SetMaxScrollDistance(1000); TraingFitnessList->SetSwipeACCLevel(800); TraingFitnessList->SetDragACCLevel(5); // 增加表冠控制 - TraingFitnessList->SetRotateFactor(2); + TraingFitnessList->SetRotateFactor(1.0); TraingFitnessList->RequestFocus(); } } @@ -115,8 +115,8 @@ namespace OHOS // scrollView-> RemoveAll(); scrollView->RemoveAll(); - delete title; - title = nullptr; + // delete title; + // title = nullptr; delete TraingFitnessList; TraingFitnessList = nullptr; diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/src/TraingMoreItemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/src/TraingMoreItemView.cpp index dd80467de..6f7698e44 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/src/TraingMoreItemView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/src/TraingMoreItemView.cpp @@ -3,78 +3,117 @@ * @Date: 2024-03-27 11:13:16 * @LastEditors: Caisking 3449750381@qq.com * @LastEditTime: 2024-03-29 11:47:02 - * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_more/src/TraingMoreItemView.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_more/src/TraingMoreItemView.cpp + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 + * 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ #include "traing/training_list_more/include/TraingMoreItemView.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 "ui_resource_string.h" -#include "UiConfig.h" -namespace OHOS -{ - - TraingMoreItemView::TraingMoreItemView() - { - 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); - Add(&slogo); - } - - TraingMoreItemView::~TraingMoreItemView() - { - Remove(&sbackground); - Remove(&sicon); - Remove(&sLabel); - Remove(&slogo); - } - - /// @brief 设置item的信息 - /// @param itemInfo - void TraingMoreItemView::SetItemInfo(const TraingMoreItem itemInfo) - { - sItemInfo = itemInfo; - sLabel.SetTextId(itemInfo.labelid); - slogo.SetSrc(itemInfo.logo); - } - - /// @brief 设置每一个itemview上的组件 - void TraingMoreItemView::SetUpChild() - { - sbackground.SetSrc(PNG_SETTING_BACKGROUND_IMAGE); - - slogo.SetPosition(40, 32); - slogo.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); - - sicon.SetPosition(330, 40); - sicon.SetSrc(ICON_IMAGE); - sicon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); - - sLabel.SetPosition(105, 33, 200, 35); - sLabel.SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); - // sLabel.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - sLabel.SetRollSpeed(0); - sLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - } - - /// @brief 获取list的中每个组件的在list的下标 - /// @return 返回下标 - AppViewId TraingMoreItemView::GetTraingMoreIndex() - { - return sItemInfo.id; - } - - UIResourceTextId TraingMoreItemView::GetTraingMoreId() - { - return sItemInfo.labelid; - } -} \ No newline at end of file +#include "uicomponents/UIComponents.h" +namespace OHOS { + +TraingMoreItemView::TraingMoreItemView() { + 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); + Add(&slogo); +} + +TraingMoreItemView::~TraingMoreItemView() { + Remove(&sbackground); + Remove(&sicon); + Remove(&sLabel); + Remove(&slogo); +} + +/// @brief 设置item的信息 +/// @param itemInfo +void TraingMoreItemView::SetItemInfo(const TraingMoreItem itemInfo) { + sItemInfo = itemInfo; + + // 先设置所有视图的可见性 + bool isVisible = false; + bool label_isVisible = false; + SetTouchable(false); // 默认不触摸 + + switch (itemInfo.id) { + case VIEW_TRAININGMORE: + sLabel.SetTextId(STR_TRAINING); + sLabel.SetPosition(90, 50, 200, 35); + isVisible = false; + label_isVisible = true; // 只有label可见 + SetHeight(120); + break; + + case VIEW_INVALID: + isVisible = false; // 全部不可见 + label_isVisible = false; + SetHeight(60); + break; + + default: + sLabel.SetTextId(itemInfo.labelid); + slogo.SetSrc(itemInfo.logo); + sLabel.SetPosition(105, 33, 200, 35); + isVisible = true; // 所有元素可见 + label_isVisible = true; + SetHeight(120); + SetTouchable(true); + break; + } + + // 设置各个组件的可见性 + sLabel.SetVisible(label_isVisible); + sicon.SetVisible(isVisible); + sbackground.SetVisible(isVisible); + slogo.SetVisible(isVisible); + + // 调整对齐方式 + if (itemInfo.id == VIEW_INVALID) { + sLabel.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + } else if (itemInfo.id == VIEW_TRAININGMORE) { + sLabel.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + } else { + sLabel.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + } +} + +/// @brief 设置每一个itemview上的组件 +void TraingMoreItemView::SetUpChild() { + sbackground.SetSrc(PNG_SETTING_BACKGROUND_IMAGE); + + slogo.SetPosition(40, 32); + slogo.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + + sicon.SetPosition(330, 40); + sicon.SetSrc(ICON_IMAGE); + sicon.SetStyle(STYLE_IMAGE_OPA, OPA_OPAQUE); + + sLabel.SetPosition(105, 33, 200, 35); + sLabel.SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + // sLabel.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + sLabel.SetRollSpeed(70); + sLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); +} + +/// @brief 获取list的中每个组件的在list的下标 +/// @return 返回下标 +AppViewId TraingMoreItemView::GetTraingMoreIndex() { return sItemInfo.id; } + +UIResourceTextId TraingMoreItemView::GetTraingMoreId() { + return sItemInfo.labelid; +} +} // namespace OHOS -- 2.17.1