--- /dev/null
+#ifndef _TraingMore_VIEW_H
+#define _TraingMore_VIEW_H
+
+#include "BaseView.h"
+#include "View.h"
+#include <ui_scroll_view.h>
+#include "components/ui_view_group.h"
+#include "components/ui_label.h"
+#include "components/ui_image_view.h"
+#include "components/ui_button.h"
+#include "components/ui_image_animator.h"
+#include "components/ui_label_button_ext.h"
+#include "components/ui_chart.h"
+#include "components/ui_list.h"
+#include "components/icon_adapter.h"
+#include "wearable_log.h"
+#include "ohos_types.h"
+#include "components/ui_card_page.h"
+
+#include "TraingMorePresenter.h"
+namespace OHOS
+{
+#define BUTTON_FITNESS "button1" // 健身
+#define BUTTON_DANCE "button2" // 舞蹈
+#define BUTTON_REST "button3" // 休闲运动
+#define BUTTON_BALL "button4" // 球类
+#define BUTTON_SWIMMING "button5" // 水上运动
+#define BUTTON_ICE "button6" // 冰上运动
+#define BUTTON_LIMIT "button7" // 极限运动
+#define BUTTON_OTHER "button8" // 其他
+
+ class TraingMorePresenter;
+ class TraingMoreView : public View<TraingMorePresenter>
+ {
+
+ public:
+ TraingMoreView();
+ virtual ~TraingMoreView();
+ static TraingMoreView *GetInstance(void);
+
+ void OnStart() override;
+ void OnSetUpView() override;
+ void OnTearDownView() override;
+ void OnStop() override;
+ void InitView();
+ void DeInit();
+ void InitLabel(UILabel *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize);
+ void InitButton(UIButton *&button, int left, int top, int width, int height, const char *viewId);
+ void InitImageView(UIImageView *&imageView, int left, int top, int width, int height, const char *viewId, const char *imagePath);
+ void InitList();
+ void PreLoad(void);
+
+ private:
+ UIView::OnDragListener *draglistener{nullptr};
+ TraingMoreView(TraingMoreView &&) = delete;
+ TraingMoreView &operator=(TraingMoreView &&) = delete;
+
+ UIViewGroup *container_ = nullptr;
+ UIScrollView *scrollView1_ = nullptr;
+ UILabel *label1_ = nullptr;
+ UIImageView *image1_ = nullptr;
+ UIImageView *image2_ = nullptr;
+ UIImageView *image3_ = nullptr;
+ UIImageView *image4_ = nullptr;
+ UIImageView *image5_ = nullptr;
+ UIImageView *image6_ = nullptr;
+ UIImageView *image7_ = nullptr;
+ UIImageView *image8_ = nullptr;
+ UIButton *button1_ = nullptr;
+ UIButton *button2_ = nullptr;
+ UIButton *button3_ = nullptr;
+ UIButton *button4_ = nullptr;
+ UIButton *button5_ = nullptr;
+ UIButton *button6_ = nullptr;
+ UIButton *button7_ = nullptr;
+ UIButton *button8_ = nullptr;
+ UIList *list1_ = nullptr;
+ IconAdapter *list1adapter_ = nullptr;
+ List<IconItemNode *> *list1data_ = nullptr;
+ bool viewiInitStatus{false};
+ };
+} // namespace OHOS
+#endif // TraingMore_PRESENTER_H
--- /dev/null
+
+#include "traing/include/TraingMoreView.h"
+
+#include "common/image_cache_manager.h"
+#include "UiConfig.h"
+#include "ui_resource_image.h"
+#include <ui_scroll_view.h>
+#include "components/ui_button.h"
+namespace OHOS
+{
+ // 定义全局变量
+ char *imagePaths[] = {"/user/res/Training/Fitness.bin",
+ "/user/res/Training/Dance.bin",
+ "/user/res/Training/Rest.bin",
+ "/user/res/Training/Ball.bin",
+ "/user/res/Training/Swimming.bin",
+ "/user/res/Training/Ice.bin",
+ "/user/res/Training/Limit.bin",
+ "/user/res/Training/Other.bin"};
+
+ char *text[] = {"健身类", "舞蹈类", "休闲运动", "球类", "水上运动", "冰上运动", "极限运动", "其他"};
+ const char *imagePath_iocn = "/user/res/Training/icon.bin";
+
+ static TraingMoreView *g_pTraingMoreView{nullptr};
+
+ TraingMoreView::TraingMoreView()
+ {
+ g_pTraingMoreView = this;
+ }
+
+ TraingMoreView::~TraingMoreView()
+ {
+ DeInit();
+ g_pTraingMoreView = nullptr;
+ }
+
+ TraingMoreView *TraingMoreView::GetInstance()
+ {
+
+ return g_pTraingMoreView;
+ }
+ /*
+ InitLabel:初始化标签
+ @param label 标签指针
+ @param left 标签左边位置
+ @param top 标签顶部位置
+ @param width 标签宽度
+ @param height 标签高度
+ @param viewId 标签的视图 ID
+ @param text 标签显示的文本
+ @param fontName 字体名称
+ @param fontSize 字体大小
+ */
+ void TraingMoreView::InitLabel(UILabel *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize)
+ {
+ // 检查标签指针是否为空
+ if (label == nullptr)
+ {
+ label = new UILabel();
+ }
+ // 设置标签的位置和大小
+ label->SetPosition(left, top);
+ label->Resize(width, height);
+ // 设置标签的视图 ID
+ label->SetViewId(viewId);
+ // 设置标签的样式
+ label->SetStyle(STYLE_TEXT_FONT, fontSize);
+ label->SetFont(fontName, fontSize);
+ // 设置标签的文本和其他属性
+ label->SetText(text);
+ label->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
+ label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ label->SetRollSpeed(0);
+ // 设置标签可见
+ label->SetVisible(true);
+ }
+ /*
+ InitButton:初始化按钮
+ @param button 按钮指针
+ @param left 按钮左边位置
+ @param top 按钮顶部位置
+ @param width 按钮宽度
+ @param height 按钮高度
+ @param viewId 按钮的视图 ID
+ */
+ void TraingMoreView::InitButton(UIButton *&button, int left, int top, int width, int height, const char *viewId)
+ {
+ // 设置按钮的背景颜色
+ uint32_t backgroundColor = 0xff191919; // 默认背景颜色
+ uint32_t pressedBackgroundColor = 0xff249115; // 按下时的背景颜色
+ uint32_t pressedBorderColor = 0xff0b1928; // 按下时的边框颜色
+ // 创建新按钮(如果当前按钮为空)
+ if (button == nullptr)
+ {
+ button = new UIButton();
+ }
+ button->SetPosition(left, top);
+ button->Resize(width, height);
+ button->SetViewId(viewId);
+ button->SetStyle(STYLE_BACKGROUND_COLOR, backgroundColor);
+ button->SetStyleForState(STYLE_BACKGROUND_COLOR, pressedBackgroundColor, UIButton::PRESSED);
+ button->SetStyleForState(STYLE_BORDER_COLOR, pressedBorderColor, UIButton::PRESSED);
+ // 设置按钮的点击事件监听器为 TraingMorePresenter 的实例
+ button->SetOnClickListener(static_cast<UIView::OnClickListener *>(TraingMorePresenter::GetInstance()));
+ // 设置按钮可见
+ button->SetVisible(true);
+ }
+
+ /*
+ InitImageView:初始化图片
+ @param imageView 图片指针
+ @param left 图片左边位置
+ @param top 图片顶部位置
+ @param width 图片宽度
+ @param height 图片高度
+ @param viewId 图片的视图 ID
+ @param imagePath 图片路径
+ */
+ void TraingMoreView::InitImageView(UIImageView *&imageView, int left, int top, int width, int height, const char *viewId, const char *imagePath)
+ {
+ if (imageView == nullptr)
+ {
+ imageView = new UIImageView();
+ }
+ imageView->SetPosition(left, top);
+ imageView->Resize(width, height);
+ imageView->SetViewId(viewId);
+ imageView->SetSrc(imagePath);
+ imageView->SetVisible(true);
+ }
+
+ /* Traing:初始化list */
+ void TraingMoreView::InitList()
+ {
+ // Add List to App
+ if (list1_ == nullptr)
+ {
+ list1_ = new UIList();
+ }
+ list1_->SetPosition(35, 110); // widget's left position and top position
+ list1_->Resize(300, 1100); // widget's width and height
+ list1_->SetViewId("list1"); // Set style
+ list1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
+ list1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
+
+ // Set additional property
+ if (list1data_ == nullptr)
+ {
+ list1data_ = new List<IconItemNode *>();
+ }
+
+ // 使用全局变量来初始化列表项
+ for (int i = 0; i < 8; ++i)
+ {
+ IconItemNode *listData = new IconItemNode();
+ listData->imagePath = imagePaths[i];
+ listData->txt = text[i];
+ list1data_->PushBack(listData);
+ }
+
+ if (list1adapter_ == nullptr)
+ {
+ list1adapter_ = new IconAdapter();
+ }
+ list1adapter_->SetItemSize(250, 120);
+ list1adapter_->SetImageSize(130, 120);
+ list1adapter_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ list1adapter_->SetData(list1data_);
+ list1_->SetAdapter(list1adapter_);
+
+ // Add to scrollView1
+ // scrollView1_->Add(list1_);
+ list1_->SetVisible(true);
+ }
+ /* InitView:初始化界面*/
+ void TraingMoreView ::InitView()
+ {
+ if (container_ == nullptr)
+ {
+ container_ = new UIViewGroup();
+ container_->SetPosition(0, 0, 466, 466);
+ container_->SetStyle(STYLE_BACKGROUND_OPA, 0);
+ }
+ // Add ScrollView to App
+ if (scrollView1_ == nullptr)
+ {
+ scrollView1_ = new UIScrollView();
+ }
+ scrollView1_->SetPosition(0, 0); // widget's left position and top position
+ scrollView1_->Resize(466, 466); // widget's width and height
+ scrollView1_->SetViewId("scrollView1"); // Set style
+ scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ // Add to rootView
+ container_->Add(scrollView1_);
+ scrollView1_->SetVisible(true);
+
+ // 初始化Lable
+ InitLabel(label1_, 203, 52, 200, 60, "label1", "训练", DEFAULT_VECTOR_FONT_FILENAME, 30);
+ scrollView1_->Add(label1_);
+ // 初始化Button
+ InitButton(button1_, 43, 120, 380, 100, BUTTON_FITNESS);
+ InitButton(button2_, 43, 240, 380, 100, BUTTON_DANCE);
+ InitButton(button1_, 43, 120, 380, 100, BUTTON_FITNESS);
+ InitButton(button2_, 43, 240, 380, 100, BUTTON_DANCE);
+ InitButton(button3_, 43, 360, 380, 100, BUTTON_REST);
+ InitButton(button4_, 43, 480, 380, 100, BUTTON_BALL);
+ InitButton(button5_, 43, 600, 380, 100, BUTTON_SWIMMING);
+ InitButton(button6_, 43, 720, 380, 100, BUTTON_ICE);
+ InitButton(button7_, 43, 840, 380, 100, BUTTON_LIMIT);
+ InitButton(button8_, 43, 960, 380, 100, BUTTON_OTHER);
+ scrollView1_->Add(button1_);
+ scrollView1_->Add(button2_);
+ scrollView1_->Add(button3_);
+ scrollView1_->Add(button4_);
+ scrollView1_->Add(button5_);
+ scrollView1_->Add(button6_);
+ scrollView1_->Add(button7_);
+ scrollView1_->Add(button8_);
+ // 初始化image
+ InitImageView(image1_, 360, 160, 100, 100, "image1", imagePath_iocn);
+ InitImageView(image2_, 360, 280, 100, 100, "image2", imagePath_iocn);
+ InitImageView(image3_, 360, 400, 100, 100, "image3", imagePath_iocn);
+ InitImageView(image4_, 360, 520, 100, 100, "image4", imagePath_iocn);
+ InitImageView(image5_, 360, 640, 100, 100, "image5", imagePath_iocn);
+ InitImageView(image6_, 360, 760, 100, 100, "image6", imagePath_iocn);
+ InitImageView(image7_, 360, 880, 100, 100, "image7", imagePath_iocn);
+ InitImageView(image8_, 360, 1000, 100, 100, "image8", imagePath_iocn);
+ scrollView1_->Add(image1_);
+ scrollView1_->Add(image2_);
+ scrollView1_->Add(image3_);
+ scrollView1_->Add(image4_);
+ scrollView1_->Add(image5_);
+ scrollView1_->Add(image6_);
+ scrollView1_->Add(image7_);
+ scrollView1_->Add(image8_);
+ // 初始化list
+ InitList();
+ scrollView1_->Add(list1_);
+ }
+ /* DeInit:删除组件*/
+ void TraingMoreView::DeInit()
+ {
+ if (label1_ != nullptr)
+ {
+ delete label1_;
+ label1_ = nullptr;
+ }
+ if (button1_ != nullptr)
+ {
+ delete button1_;
+ button1_ = nullptr;
+ }
+ if (button8_ != nullptr)
+ {
+ delete button8_;
+ button8_ = nullptr;
+ }
+ if (button7_ != nullptr)
+ {
+ delete button7_;
+ button7_ = nullptr;
+ }
+ if (button6_ != nullptr)
+ {
+ delete button6_;
+ button6_ = nullptr;
+ }
+ if (button5_ != nullptr)
+ {
+ delete button5_;
+ button5_ = nullptr;
+ }
+ if (button4_ != nullptr)
+ {
+ delete button4_;
+ button4_ = nullptr;
+ }
+ if (button3_ != nullptr)
+ {
+ delete button3_;
+ button3_ = nullptr;
+ }
+ if (button2_ != nullptr)
+ {
+ delete button2_;
+ button2_ = nullptr;
+ }
+ if (image1_ != nullptr)
+ {
+ delete image1_;
+ image1_ = nullptr;
+ }
+ if (image2_ != nullptr)
+ {
+ delete image2_;
+ image2_ = nullptr;
+ }
+ if (image3_ != nullptr)
+ {
+ delete image3_;
+ image3_ = nullptr;
+ }
+ if (image4_ != nullptr)
+ {
+ delete image4_;
+ image4_ = nullptr;
+ }
+ if (image5_ != nullptr)
+ {
+ delete image5_;
+ image5_ = nullptr;
+ }
+ if (image6_ != nullptr)
+ {
+ delete image6_;
+ image6_ = nullptr;
+ }
+ if (image7_ != nullptr)
+ {
+ delete image7_;
+ image7_ = nullptr;
+ }
+ if (image8_ != nullptr)
+ {
+ delete image8_;
+ image8_ = nullptr;
+ }
+ if (list1_ != nullptr)
+ {
+ delete list1_;
+ list1_ = nullptr;
+ }
+ if (list1adapter_ != nullptr)
+ {
+ delete list1adapter_;
+ list1adapter_ = nullptr;
+ }
+ if (list1data_ != nullptr)
+ {
+ list1data_->Clear();
+ delete list1data_;
+ list1data_ = nullptr;
+ }
+ if (scrollView1_ != nullptr)
+ {
+ delete scrollView1_;
+ scrollView1_ = nullptr;
+ }
+ if (container_ != nullptr)
+ {
+ container_->RemoveAll();
+ delete container_;
+ container_ = nullptr;
+ }
+ }
+
+ void TraingMoreView::PreLoad(void)
+ {
+ if (!viewiInitStatus)
+ {
+ InitView();
+ viewiInitStatus = true;
+ }
+ }
+ void TraingMoreView::OnStart()
+ {
+ container_ = new UIViewGroup();
+ if (container_ == nullptr)
+ {
+ return;
+ }
+ container_->SetPosition(0, 0);
+ container_->SetWidth(Screen::GetInstance().GetWidth());
+ container_->SetHeight(Screen::GetInstance().GetHeight());
+
+ // 创建 draglistener 实例并设置为拖动监听器
+ UIView::OnDragListener *draglistener = static_cast<UIView::OnDragListener *>(TraingMorePresenter::GetInstance());
+ if (draglistener == nullptr)
+ {
+ return;
+ }
+ container_->SetOnDragListener(draglistener);
+
+ container_->SetTouchable(true);
+ container_->SetDraggable(true);
+
+ PreLoad();
+ RootView::GetInstance()->Add(container_);
+ }
+
+ void TraingMoreView::OnSetUpView()
+ {
+
+ View<TraingMorePresenter>::OnSetUpView();
+ Draw();
+ }
+
+ void TraingMoreView::OnTearDownView()
+ {
+
+ View<TraingMorePresenter>::OnTearDownView();
+ return;
+ }
+
+ void TraingMoreView::OnStop()
+ {
+ View<TraingMorePresenter>::OnStop();
+ RootView::GetInstance()->RemoveAll();
+ return;
+ }
+}