From: Caisking <3449750381@qq.com> Date: Fri, 29 Mar 2024 11:41:54 +0000 (+0800) Subject: 增加其他运动列表并且适配多国语言 X-Git-Tag: release_V1.2.70_20241020_135402~1241^2~12 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=43c22becc7f8704f7ed197de176847b1f7ab0bbe;p=mirrors%2FFD230.git 增加其他运动列表并且适配多国语言 --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index fb590c274..0eb2c53b4 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -504,6 +504,13 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_list_aquatic/src/TraingAquaticItemView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_list_aquatic/src/TraingAquaticModel.cpp + #其他训练 + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_list_other/src/TraingOtherView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_list_other/src/TraingOtherPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_list_other/src/TraingOtherAdapter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_list_other/src/TraingOtherItemView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_list_other/src/TraingOtherModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_list_more/src/TraingMoreView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_list_more/src/TraingMorePresenter.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index 49fd0459d..10a3c047b 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -94,7 +94,7 @@ typedef enum : uint16_t VIEW_TRAININGREST, // 休闲运动列表 VIEW_TRAININGBALL, // 球类运动列表 VIEW_TRAININGAQUATIC, // 水上运动列表 - + VIEW_TRAININGOTHER, // 其他列表 /* ---------------------------------- GPS训练 --------------------------------- */ VIEW_TRAININGGPS, // GPS训练 VIEW_TRAININGGPSSET, // GPS训练目标(时长,距离,卡路里,步数) diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index 834460e0d..dddba6b0c 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -87,6 +87,7 @@ namespace OHOS void InitTraingRestSlice(void); // 休闲训练 void InitTraingBallSlice(void); // 球类训练 void InitTraingAquaticSlice(void); // 水上训练 + void InitTraingOtherSlice(void); // 其他训练 void InitTraingRecordSlice(void); // 训练记录 diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index a11d19074..e40352415 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -207,6 +207,8 @@ #include "traing/training_list_ball/include/TraingBallView.h" #include "traing/training_list_aquatic/include/TraingAquaticPresenter.h" #include "traing/training_list_aquatic/include/TraingAquaticView.h" +#include "traing/training_list_other/include/TraingOtherPresenter.h" +#include "traing/training_list_other/include/TraingOtherView.h" /* ---------------------------------- 主界面卡片 --------------------------------- */ #include "traing/training_card/include/TraingCardPresenter.h" #include "traing/training_card/include/TraingCardView.h" @@ -310,6 +312,7 @@ namespace OHOS {VIEW_TRAININGREST, &NativeLauncher::InitTraingRestSlice}, // 休闲训练 {VIEW_TRAININGBALL, &NativeLauncher::InitTraingBallSlice}, // 球类训练 {VIEW_TRAININGAQUATIC, &NativeLauncher::InitTraingAquaticSlice}, // 水上训练 + {VIEW_TRAININGOTHER, &NativeLauncher::InitTraingOtherSlice}, // 水上训练 /* -------------------------------------------------------------------------- */ #ifdef SUPPORT_ALIPAY_SEC @@ -1037,6 +1040,11 @@ namespace OHOS SliceProxy *TraingAquaticview = new AbilitySliceProxy; NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGAQUATIC, TraingAquaticview); } + void NativeLauncher::InitTraingOtherSlice(void) + { + SliceProxy *TraingOtherview = new AbilitySliceProxy; + NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGOTHER, TraingOtherview); + } /* -------------------------------------------------------------------------- */ // 省电模式 diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/include/TraingAquaticModel.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/include/TraingAquaticModel.h index 168e3cfa9..42060bbbf 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/include/TraingAquaticModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/include/TraingAquaticModel.h @@ -2,7 +2,7 @@ * @Author: Caisking 3449750381@qq.com * @Date: 2024-03-29 15:18:34 * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-03-29 18:03:00 + * @LastEditTime: 2024-03-29 19:23:48 * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/include/TraingAquaticModel.h * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/src/TraingAquaticPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/src/TraingAquaticPresenter.cpp index a92487ad6..c28beae13 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/src/TraingAquaticPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/src/TraingAquaticPresenter.cpp @@ -1,3 +1,11 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-03-26 09:46:17 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-03-29 19:24:43 + * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/src/TraingAquaticPresenter.cpp + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ /*** * @Author: Caisking 3449750381@qq.com * @Date: 2024-03-19 17:37:19 diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/src/TraingAquaticView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/src/TraingAquaticView.cpp index 8d2470969..7bc72eb48 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/src/TraingAquaticView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/src/TraingAquaticView.cpp @@ -61,7 +61,7 @@ namespace OHOS /* -------------------------------------------------------------------------- */ // 初始化Lable - TraingModel::GetInstance()->InitLabel(title, 173, 52, 200, 60, "label1", "极限运动", DEFAULT_VECTOR_FONT_FILENAME, 30); + TraingModel::GetInstance()->InitLabel(title, 173, 52, 200, 60, "label1", "冰上运动", DEFAULT_VECTOR_FONT_FILENAME, 30); scrollView->Add(title); // UIList 的适配器 p_TraingAquaticListAdapter = new TraingAquaticAdapter(); 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 0fc5b3b65..b04aa10d1 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 @@ -61,7 +61,7 @@ namespace OHOS /* -------------------------------------------------------------------------- */ // 初始化Lable - TraingModel::GetInstance()->InitLabel(title, 173, 52, 200, 60, "label1", "极限运动", DEFAULT_VECTOR_FONT_FILENAME, 30); + TraingModel::GetInstance()->InitLabel(title, 173, 52, 200, 60, "label1", "球类运动", DEFAULT_VECTOR_FONT_FILENAME, 30); scrollView->Add(title); // UIList 的适配器 p_TraingBallListAdapter = new TraingBallAdapter(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/src/TraingMorePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/src/TraingMorePresenter.cpp index c12be8fa8..597b51c3c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/src/TraingMorePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/src/TraingMorePresenter.cpp @@ -109,7 +109,7 @@ namespace OHOS } if (strcmp(view.GetViewId(), BUTTON_OTHER) == 0) { - NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGLIMIT); + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGOTHER); } if (strcmp(view.GetViewId(), BUTTON_REST) == 0) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingListOtherPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingListOtherPresenter.h deleted file mode 100644 index e69de29bb..000000000 diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingListOtherView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingListOtherView.h deleted file mode 100644 index e69de29bb..000000000 diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherAdapter.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherAdapter.h new file mode 100644 index 000000000..be700785f --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherAdapter.h @@ -0,0 +1,59 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-03-29 17:36:30 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-03-29 17:47:13 + * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/include/TraingOtherAapter.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ + +#ifndef TraingOther_ADAPTER_H +#define TraingOther_ADAPTER_H +#include +#include +#include "components/ui_list.h" +#include "components/abstract_adapter.h" +#include "components/ui_label.h" +#include "components/ui_label_ext.h" +#include "language/font/ui_resource_string.h" +#include "components/ui_checkbox.h" +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" + + +// 列表的适配器 +namespace OHOS +{ + + typedef struct + { + AppViewId id; + UIResourceTextId labelid; // 标签 + } TraingOtherItem; + + class TraingOtherAdapter : public AbstractAdapter + { + public: + explicit TraingOtherAdapter(); + virtual ~TraingOtherAdapter(); + + void SetData(std::list &data); + + virtual uint16_t GetCount(void) override; + + virtual UIView *GetView(UIView *inView, int16_t index) override; + + virtual void AddItem(const TraingOtherItem &item); + + void SetItemClickListener(UIView::OnClickListener *itemclicklistener) + { + itemClickListener = itemclicklistener; + } + + private: + std::list listData; + UIView::OnClickListener *itemClickListener{nullptr}; + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherItemView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherItemView.h new file mode 100644 index 000000000..e8fa67530 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherItemView.h @@ -0,0 +1,39 @@ + +#ifndef TraingOther_ITEM_VIEW_H +#define TraingOther_ITEM_VIEW_H + +#include "components/ui_label.h" +#include "components/ui_label_ext.h" +#include "language/font/ui_resource_string.h" +#include "components/ui_view_group.h" +#include "components/ui_checkbox.h" +#include "components/ui_image_view.h" +#include "traing/training_list_other/include/TraingOtherAdapter.h" +#include "components/ui_label_button.h" +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include "language/font/ui_resource_string.h" +#include "ohos_types.h" + +namespace OHOS +{ + class TraingOtherItemView : public UIViewGroup + { + public: + explicit TraingOtherItemView(); + virtual ~TraingOtherItemView(); + virtual void SetItemInfo(const TraingOtherItem itemInfo); + virtual void SetUpChild(); + AppViewId GetTraingOtherIndex(); + UIResourceTextId GetTraingOtherId(); + + private: + TraingOtherItemView(const TraingOtherItemView &); + UIImageView sbackground; // 背景 + UIImageView sicon; // 箭头 + UILabelExt sLabel; // 标签 + TraingOtherItem sItemInfo = {VIEW_INVALID, STR_EXERCISE_GENERAL}; + }; + +} +#endif \ No newline at end of file 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 new file mode 100644 index 000000000..01d634c4c --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherModel.h @@ -0,0 +1,55 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-03-29 19:21:24 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-03-29 19:33:05 + * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherModel.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-03-29 15:18:34 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-03-29 18:03:00 + * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherModel.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ + +#ifndef TraingOther_MODEL_H +#define TraingOther_MODEL_H + +#include +#include +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include "language/font/ui_resource_string.h" +#include "components/ui_label_ext.h" +#include "language/font/ui_resource_string.h" +#include "UiConfig.h" +#include "TraingOtherPresenter.h" +#include "traing/training_list_other/include/TraingOtherAdapter.h" + +namespace OHOS +{ + class TraingOtherModel + { + public: + static TraingOtherModel &GetInstance(void); + void InitTraingOtherListItem(); + const TraingOtherItem *GetTraingOtherlistItems() const; + uint8_t GetTraingOtherListNum() const; + // const std::map &GetTraingOtherIdToViewId() const; + + private: + TraingOtherModel(); + TraingOtherModel(const TraingOtherModel &); + TraingOtherModel &operator=(const TraingOtherModel &); + virtual ~TraingOtherModel(); + static const uint16_t TraingOtherListMaxNum = 9; + TraingOtherItem TraingOthers[TraingOtherListMaxNum] = {VIEW_INVALID, STR_EXERCISE_GENERAL}; + // std::map TraingOtherIdToViewId; + bool btConnectStatus{false}; + }; +} + +#endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherPresenter.h new file mode 100644 index 000000000..257a8c18c --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherPresenter.h @@ -0,0 +1,45 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-03-19 17:37:18 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-03-29 19:23:56 + * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_limit/include/TraingOtherPresenter.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ + +#ifndef _TraingOther_PRESENTER_H +#define _TraingOther_PRESENTER_H + +#include "Presenter.h" +#include "TraingOtherView.h" + +namespace OHOS +{ + class TraingOtherView; + class TraingOtherModel; + class TraingOtherPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + TraingOtherPresenter(); + virtual ~TraingOtherPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static TraingOtherPresenter *GetInstance(); + + private: + // 因为继承了OnClickener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; + + TraingOtherModel *p_TraingOtherModel{nullptr}; + }; +} // namespace OHOS + +#endif // SLEEPDETAIL_PRESENTER_H \ No newline at end of file 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 new file mode 100644 index 000000000..426a6a05d --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherView.h @@ -0,0 +1,61 @@ +/*** + * @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 + */ + +#ifndef TraingOther_VIEW_H +#define TraingOther_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_list.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"language/font/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}; + }; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingListOtherPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingListOtherPresenter.cpp deleted file mode 100644 index e69de29bb..000000000 diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingListOtherView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingListOtherView.cpp deleted file mode 100644 index e69de29bb..000000000 diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherAdapter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherAdapter.cpp new file mode 100644 index 000000000..f8da3b528 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherAdapter.cpp @@ -0,0 +1,95 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-03-29 19:21:41 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-03-29 19:24:17 + * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherAdapter.cpp + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +#include "traing/training_list_other/include/TraingOtherAdapter.h" +#include "traing/training_list_other/include/TraingOtherModel.h" +#include "traing/training_list_other/include/TraingOtherItemView.h" + +#include "wearable_log.h" + +namespace OHOS +{ + TraingOtherAdapter::TraingOtherAdapter() {} + + TraingOtherAdapter::~TraingOtherAdapter() + { + listData.clear(); + } + + uint16_t TraingOtherAdapter::GetCount(void) + { + return listData.size(); + } + + void TraingOtherAdapter::SetData(std::list &data) + { + if (!listData.empty()) + { + listData.clear(); + } + std::list::iterator it; + for (it = data.begin(); it != data.end(); it++) + { + listData.push_back(*it); + } + } + + /// @brief 为列表的每一项创建一个视图 + /// @param inView 一个指向已存在的视图对象的指 + /// @param index 要创建的视图在列表中的索引l。 + /// @return 返回该视图对象 + UIView *TraingOtherAdapter::GetView(UIView *inView, int16_t index) + { + + // 1.先检查列表数据是否为空,若为空则返回空指针 + if (listData.empty()) + { + return nullptr; + } + // 2.接着检查索引是否小于0,若小于0则返回空指针 + if (index < 0) + { + return nullptr; + } + // 3.检查是否超出列表数据大小,若超出则返回空指针 + size_t uindex = index; + if (uindex >= listData.size()) + { + return nullptr; + } + // 4.通过迭代器访问列表中指定索引位置的元素,将其赋值给itemData变量 + std::list::iterator it = listData.begin(); + for (int i = 0; i < index; i++) + { + it++; + } + TraingOtherItem itemData = *it; + TraingOtherItemView *item = nullptr; + /* + 5.根据传入的inView参数是否已经存在一个视图对象, + 若为空则创建一个新的MessageItemView对象, + 否则将inView转换成MessageItemView类型的指针 + */ + if (inView == nullptr) + { + item = new TraingOtherItemView(); + } + else + { + item = static_cast(inView); + } + item->SetItemInfo(itemData); + item->SetOnClickListener(itemClickListener); + return item; + } + + void TraingOtherAdapter::AddItem(const TraingOtherItem &item) + { + listData.push_back(item); + } +} // namespace OHOS 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 new file mode 100644 index 000000000..2edca4b9f --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherItemView.cpp @@ -0,0 +1,73 @@ +/*** + * @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 "traing/include/TraingModel.h" +#include "traing/Training_UiConfig.h" +#include "components/ui_label_ext.h" +#include "language/font/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(50, 10, 300, 80); + 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 TraingOtherItemView::GetTraingOtherIndex() + { + return sItemInfo.id; + } + UIResourceTextId TraingOtherItemView::GetTraingOtherId() + { + return sItemInfo.labelid; + } +} \ 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 new file mode 100644 index 000000000..177413566 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherModel.cpp @@ -0,0 +1,61 @@ + +/*** + * @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_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 "common/image_cache_manager.h" +#include "components/ui_label_ext.h" +#include "language/font/ui_resource_string.h" +#include "UiConfig.h" +#include "ui_resource_image.h" +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include "language/font/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 diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherPresenter.cpp new file mode 100644 index 000000000..68da86f0d --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherPresenter.cpp @@ -0,0 +1,118 @@ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-03-19 17:37:19 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-03-26 19:51:06 + * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherPresenter.cpp + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +/*** + * @Author: Caisking 3449750381@qq.com + * @Date: 2024-03-19 17:37:19 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-03-26 14:23:32 + * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/src/TraingOtherPresenter.cpp + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ + +#include "AppViewIDs.h" +#include "components/ui_label_ext.h" +#include "language/font/ui_resource_string.h" +#include "NativeAbility.h" + +#include +#include +#include +#include "traing/training_list_other/include/TraingOtherItemView.h" +#include "traing/training_list_other/include/TraingOtherPresenter.h" +#include "traing/training_list_other/include/TraingOtherView.h" +#include "traing/include/TraingModel.h" +// #include "TraingOtherView.h" + +namespace OHOS +{ + extern const char *Other_buttons[]; + extern char *Other_text[]; + + // 当前Presenter属性实例化的内存指针 + static TraingOtherPresenter *g_pTraingOtherPresenter = nullptr; + + TraingOtherPresenter::TraingOtherPresenter() + { + p_TraingOtherModel = &TraingOtherModel::GetInstance(); + g_pTraingOtherPresenter = this; + } + + TraingOtherPresenter::~TraingOtherPresenter() + { + + g_pTraingOtherPresenter = nullptr; + } + + TraingOtherPresenter *TraingOtherPresenter::GetInstance() + { + + return g_pTraingOtherPresenter; + } + + void TraingOtherPresenter::OnStart() + { + p_TraingOtherModel->InitTraingOtherListItem(); + Presenter::OnStart(); + } + + void TraingOtherPresenter::OnPause(void) + { + Presenter::OnPause(); + } + + void TraingOtherPresenter::OnResume(void) + { + if (view_ == nullptr) + { + return; + } + const TraingOtherItem *itemInfo = p_TraingOtherModel->GetTraingOtherlistItems(); + for (int i = 0; i < p_TraingOtherModel->GetTraingOtherListNum(); i++) + { + view_->AddToTraingOtherList(itemInfo[i]); + } + Presenter::OnResume(); + } + + void TraingOtherPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + bool TraingOtherPresenter::OnDrag(UIView &view, const DragEvent &event) + { + return true; + } + bool TraingOtherPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE); + } + UNUSED(view); + return true; + } + + bool TraingOtherPresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + TraingOtherItemView *itemView = static_cast(&view); + AppViewId viewId = itemView->GetTraingOtherIndex(); + UIResourceTextId sportid = itemView->GetTraingOtherId(); + TraingModel::GetInstance()->SetSportEvent(sportid); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId); + if (viewId < VIEW_MAX_INTER_APP) + { + NativeAbility::GetInstance().ChangeSlice(viewId); + return true; + } + return false; + } + +} 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 new file mode 100644 index 000000000..348950d33 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherView.cpp @@ -0,0 +1,154 @@ +#include "traing/training_list_other/include/TraingOtherView.h" +#include "traing/training_list_other/include/TraingOtherPresenter.h" +#include "traing/include/TraingModel.h" +#include "traing/Training_UiConfig.h" + +#include "components/ui_label_ext.h" +#include "language/font/ui_resource_string.h" +#include "UiConfig.h" +#include "wearable_log.h" + +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; + } + + TraingOtherView::~TraingOtherView() + { + if (viewInitStatus == true) + { + DeInitView(); + } + g_pTraingOtherView = nullptr; + } + + TraingOtherView *TraingOtherView::GetInstance() + { + return g_pTraingOtherView; + } + /// @param item + void TraingOtherView::AddToTraingOtherList(const TraingOtherItem &item) + { + p_TraingOtherListAdapter->AddItem(item); + } + void TraingOtherView::InitView() + { + if (scrollView == nullptr) + { + scrollView = new UIScrollView(); + } + scrollView->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + // scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollView->SetScrollBlankSize(20); + // scrollView->SetReboundSize(100); + scrollView->SetTouchable(true); + scrollView->SetDraggable(true); + scrollView->SetDirection(1); + draglistener = static_cast(TraingOtherPresenter::GetInstance()); + scrollView->SetOnDragListener(draglistener); + + /* -------------------------------------------------------------------------- */ + // 初始化Lable + TraingModel::GetInstance()->InitLabel(title, 173, 52, 200, 60, "label1", "其他运动", DEFAULT_VECTOR_FONT_FILENAME, 30); + scrollView->Add(title); + // UIList 的适配器 + p_TraingOtherListAdapter = new TraingOtherAdapter(); + p_TraingOtherListAdapter->SetItemClickListener(presenter_); + if (TraingOtherList == nullptr) + { + TraingOtherList = new UIList(); + } + TraingOtherList->SetPosition(Other_LIST_POSITION_X, Other_LIST_POSITION_Y); + TraingOtherList->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + // TraingOtherList->SetScrollBlankSize(Other_SCROLLBLANKSIZE); + TraingOtherList->SetSelectPosition(HORIZONTAL_RESOLUTION / SNUM_2); // middle position + TraingOtherList->SetDraggable(true); + TraingOtherList->SetThrowDrag(false); + TraingOtherList->EnableAutoAlign(true); + TraingOtherList->SetElastic(true); // 设置回弹效果 + TraingOtherList->SetMaxScrollDistance(MAX_SCR_DIS); + TraingOtherList->SetYScrollBarVisible(true); // 设置滑动滚动条 + + // 增加表冠控制 + TraingOtherList->SetRotateFactor(2); + TraingOtherList->RequestFocus(); + } + UIList *TraingOtherView::GetList() + { + return TraingOtherList; + } + void TraingOtherView::DeInitView() + { + // scrollView-> RemoveAll(); + RemoveAll(); + delete title; + title = nullptr; + + delete TraingOtherList; + TraingOtherList = nullptr; + + delete scrollView; + scrollView = nullptr; + + delete draglistener; + draglistener = nullptr; + } + + void TraingOtherView::PreLoad(void) + { + if (!viewInitStatus) + { + InitView(); + viewInitStatus = true; + } + } + + /// @brief 页面启动时需要执行的代码逻辑 + void TraingOtherView::OnStart() + { + View::OnStart(); + BaseView::RootView(Color::Black().full); + PreLoad(); + } + + /// @brief 创建页面的视图。 + void TraingOtherView::OnSetUpView() + { + View::OnSetUpView(); + scrollView->Add(title); + scrollView->Add(TraingOtherList); + scrollView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + RootView::GetInstance()->Add(scrollView); + TraingOtherList->SetAdapter(p_TraingOtherListAdapter); + // TraingOtherList->RefreshList(); // 刷新列表 + Draw(); + } + + /// @brief 销毁页面的视图。 + void TraingOtherView::OnTearDownView() + { + View::OnTearDownView(); + return; + } + + /// @brief 页面结束时需要执行的销毁逻辑。 + void TraingOtherView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + RootView::GetInstance()->ClearFocus(); + return; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_rest/src/TraingRestView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_rest/src/TraingRestView.cpp index 78c646fe3..4abce772f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_rest/src/TraingRestView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_rest/src/TraingRestView.cpp @@ -61,7 +61,7 @@ namespace OHOS /* -------------------------------------------------------------------------- */ // 初始化Lable - TraingModel::GetInstance()->InitLabel(title, 173, 52, 200, 60, "label1", "极限运动", DEFAULT_VECTOR_FONT_FILENAME, 30); + TraingModel::GetInstance()->InitLabel(title, 173, 52, 200, 60, "label1", "休闲运动", DEFAULT_VECTOR_FONT_FILENAME, 30); scrollView->Add(title); // UIList 的适配器 p_TraingRestListAdapter = new TraingRestAdapter();