增加训练强度介绍
authorCaisking <3449750381@qq.com>
Thu, 14 Dec 2023 09:25:20 +0000 (17:25 +0800)
committerCaisking <3449750381@qq.com>
Thu, 14 Dec 2023 09:25:20 +0000 (17:25 +0800)
13 files changed:
Resource/res/Training/bule.bin [new file with mode: 0644]
Resource/res/Training/green.bin [new file with mode: 0644]
Resource/res/Training/orange.bin [new file with mode: 0644]
Resource/res/Training/yellow.bin [new file with mode: 0644]
code/sdk/application/wearable/nativeapp/CMakeLists.txt
code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h
code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h
code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp
code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingStrongPresenter.h [new file with mode: 0644]
code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingStrongView.h [new file with mode: 0644]
code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingDataPresenter.cpp
code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingStrongPresenter.cpp [new file with mode: 0644]
code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingStrongView.cpp [new file with mode: 0644]

diff --git a/Resource/res/Training/bule.bin b/Resource/res/Training/bule.bin
new file mode 100644 (file)
index 0000000..808b898
Binary files /dev/null and b/Resource/res/Training/bule.bin differ
diff --git a/Resource/res/Training/green.bin b/Resource/res/Training/green.bin
new file mode 100644 (file)
index 0000000..03f2625
Binary files /dev/null and b/Resource/res/Training/green.bin differ
diff --git a/Resource/res/Training/orange.bin b/Resource/res/Training/orange.bin
new file mode 100644 (file)
index 0000000..cd6cef3
Binary files /dev/null and b/Resource/res/Training/orange.bin differ
diff --git a/Resource/res/Training/yellow.bin b/Resource/res/Training/yellow.bin
new file mode 100644 (file)
index 0000000..6ea0184
Binary files /dev/null and b/Resource/res/Training/yellow.bin differ
index 5e088c4..de4b55d 100755 (executable)
@@ -280,6 +280,8 @@ set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingGPSlackPresenter.cpp\r
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingGPSnoteView.cpp\r
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingGPSnotePresenter.cpp\r
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingStrongView.cpp\r
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingStrongPresenter.cpp\r
 \r
     #ָ����\r
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/compass/src/CompassControlView.cpp\r
index dffae12..c382a11 100755 (executable)
@@ -95,6 +95,7 @@ typedef enum : uint16_t
     VIEW_TRAININGGPS,                     // GPS训练\r
     VIEW_TRAININGGPSLACK,                 // 缺少GPS\r
     VIEW_TRAININGGPSNOTE,                 // 连接GPS提醒\r
+    VIEW_TRAININGSTRONG,                  // 训练强度介绍\r
     \r
     VIEW_TRAINING_RECORD,                 // 训练记录\r
     \r
index a256f1e..642d43c 100755 (executable)
@@ -68,6 +68,7 @@ public:
     void InitTraingNomalSlice(void);\r
     void InitTraingSetSlice(void);\r
     void InitTraingGPSSetSlice(void);\r
+    void InitTraingStrongSlice(void);\r
     void InitTraingSetTimeSlice(void);\r
     void InitTraingSetCaluliSlice(void);\r
     void InitTraingSetDistSlice(void);\r
index 5423a84..d80655c 100755 (executable)
 #include "traing/include/TraingGPSlackView.h"\r
 #include "traing/include/TraingGPSnotePresenter.h"\r
 #include "traing/include/TraingGPSnoteView.h"\r
+#include "traing/include/TraingStrongPresenter.h"\r
+#include "traing/include/TraingStrongView.h"\r
 #include "displaybrightness/include/DisplayBrightnessPresenter.h"\r
 #include "displaybrightness/include/DisplayBrightnessView.h"\r
 #include "bluetoothofsetting/include/BlueToothOfSettingPresenter.h"\r
@@ -301,6 +303,7 @@ static const AppViewMapper SLICE_MAPPER[] = {
     {VIEW_TRAININGGPS, &NativeLauncher::InitTraingGPSSlice},                    //GPS训练\r
     {VIEW_TRAININGGPSLACK, &NativeLauncher::InitTraingGPSlackSlice},            //GPS缺少\r
     {VIEW_TRAININGGPSNOTE, &NativeLauncher::InitTraingGPSnoteSlice},            //提醒连接GPS\r
+    {VIEW_TRAININGSTRONG, &NativeLauncher::InitTraingStrongSlice},            //训练强度介绍\r
 \r
 \r
     {VIEW_DISPLAY_BRIGHTNESS,&NativeLauncher::InitUIDisplayBrightnessSlice},    //显示与亮度的实例化地址\r
@@ -978,7 +981,11 @@ void NativeLauncher::InitTraingGPSnoteSlice(void)
     SliceProxy *traingGPSnoteview = new AbilitySliceProxy<TraingGPSnoteView, TraingGPSnotePresenter>;\r
     NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGGPSNOTE, traingGPSnoteview);\r
 }\r
-\r
+void NativeLauncher::InitTraingStrongSlice(void)\r
+{\r
+    SliceProxy *traingStrongview = new AbilitySliceProxy<TraingStrongView, TraingStrongPresenter>;\r
+    NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGSTRONG, traingStrongview);\r
+}\r
 //DisplayBrightness的实例化\r
 void NativeLauncher::InitUIDisplayBrightnessSlice(void)\r
 {\r
diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingStrongPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingStrongPresenter.h
new file mode 100644 (file)
index 0000000..b69a7c6
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef _TraingStrong_PRESENTER_H
+#define _TraingStrong_PRESENTER_H
+
+#include "Presenter.h"
+#include "TraingStrongView.h"
+
+namespace OHOS
+{
+    class TraingStrongView;
+
+    class TraingStrongPresenter : public Presenter<TraingStrongView>,
+                                 public UIView::OnClickListener,
+                                 public UIView::OnDragListener
+    {
+    public:
+        TraingStrongPresenter();
+        virtual ~TraingStrongPresenter();
+
+        void OnStart() override;
+        void OnPause() override;
+        void OnResume() override;
+        void OnStop() override;
+
+        static TraingStrongPresenter *GetInstance();
+
+    private:
+        // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承;
+        bool OnClick(UIView &view, const ClickEvent &event) override;
+        bool OnDrag(UIView &view, const DragEvent &event) override;
+    };
+} // namespace OHOS
+
+#endif // SLEEPDETAIL_PRESENTER_H
\ No newline at end of file
diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingStrongView.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingStrongView.h
new file mode 100644 (file)
index 0000000..8cf7ba9
--- /dev/null
@@ -0,0 +1,74 @@
+#ifndef _TraingStrong_VIEW_H
+#define _TraingStrong_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 "TraingStrongPresenter.h"
+namespace OHOS
+{
+#define BUTTONNO "button1"
+#define BUTTONYES "button2"
+
+    class TraingStrongPresenter;
+    class TraingStrongView : public View<TraingStrongPresenter>
+    {
+
+    public:
+        TraingStrongView();
+        virtual ~TraingStrongView();
+        static TraingStrongView *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);
+
+        // 通过函数改变
+        void SetLabel();
+        void SetButton();
+
+    private:
+        UIView::OnDragListener *draglistener{nullptr};
+        TraingStrongView(TraingStrongView &&) = delete;
+        TraingStrongView &operator=(TraingStrongView &&) = delete;
+
+        UIViewGroup *container_ = nullptr;
+        UIScrollView *scrollView1_ = nullptr;
+
+        UILabel *label1_ = nullptr;
+        UILabel *label2_ = nullptr;
+        UILabel *label3_ = nullptr;
+        UILabel *label4_ = nullptr;
+        UILabel *label5_ = nullptr;
+        UILabel *label6_ = nullptr;
+
+        UIImageView *image1_ = nullptr;
+        UIImageView *image2_ = nullptr;
+        UIImageView *image3_ = nullptr;
+        UIImageView *image4_ = nullptr;
+        UIImageView *image5_ = nullptr;
+        bool viewiInitStatus{false};
+    };
+} // namespace OHOS
+#endif // TraingStrong_PRESENTER_H
index 3e72cdd..24c59b3 100755 (executable)
@@ -76,7 +76,7 @@ namespace OHOS
         // 根据控件id查找是哪个控件触发了点击回调\r
         if (strcmp(view.GetViewId(), BUTTONNOTE) == 0)\r
         {\r
-            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL);\r
+            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGSTRONG);\r
         }\r
         return true;\r
     }\r
diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingStrongPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingStrongPresenter.cpp
new file mode 100644 (file)
index 0000000..f0fb44b
--- /dev/null
@@ -0,0 +1,81 @@
+#include "AppViewIDs.h"
+#include "NativeAbility.h"
+
+#include <iostream>
+#include <chrono>
+#include <thread>
+#include "traing/include/TraingStrongPresenter.h"
+// #include "TraingStrongView.h"
+
+namespace OHOS
+{
+
+    // 当前Presenter属性实例化的内存指针
+    static TraingStrongPresenter *g_pTraingStrongPresenter = nullptr;
+
+    TraingStrongPresenter::TraingStrongPresenter()
+    {
+
+        g_pTraingStrongPresenter = this;
+    }
+
+    TraingStrongPresenter::~TraingStrongPresenter()
+    {
+
+        g_pTraingStrongPresenter = nullptr;
+    }
+
+    TraingStrongPresenter *TraingStrongPresenter::GetInstance()
+    {
+
+        return g_pTraingStrongPresenter;
+    }
+
+    void TraingStrongPresenter::OnStart()
+    {
+
+        Presenter<TraingStrongView>::OnStart();
+    }
+
+    void TraingStrongPresenter::OnPause(void)
+    {
+
+        Presenter<TraingStrongView>::OnPause();
+    }
+
+    void TraingStrongPresenter::OnResume(void)
+    {
+
+        Presenter<TraingStrongView>::OnResume();
+    }
+
+    void TraingStrongPresenter::OnStop(void)
+    {
+
+        Presenter<TraingStrongView>::OnStop();
+    }
+
+    bool TraingStrongPresenter::OnDrag(UIView &view, const DragEvent &event)
+    {
+
+        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT &&
+            (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY()))))
+        {
+            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGDATA);
+        }
+        UNUSED(view);
+        return true;
+    }
+
+    bool TraingStrongPresenter::OnClick(UIView &view, const ClickEvent &event)
+    {
+        // 根据控件id查找是哪个控件触发了点击回调
+        if (strcmp(view.GetViewId(), "Remind") == 0)
+        {
+            // 模拟心率监测,等待20秒
+            // std::this_thread::sleep_for(std::chrono::seconds(20));
+            // NativeAbility::GetInstance().ChangeSlice(VIEW_TraingStrongREMIND);
+        }
+        return true;
+    }
+}
diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingStrongView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingStrongView.cpp
new file mode 100644 (file)
index 0000000..e9b58b8
--- /dev/null
@@ -0,0 +1,260 @@
+
+#include "traing/include/TraingStrongView.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
+{
+    static const char *imagePath_blue = "/user/res/Training/bule.bin";
+    static const char *imagePath_yellow = "/user/res/Training/yellow.bin";
+    static const char *imagePath_orange = "/user/res/Training/orange.bin";
+    static const char *imagePath_green = "/user/res/Training/green.bin";
+
+    static TraingStrongView *g_pTraingStrongView{nullptr};
+
+    TraingStrongView::TraingStrongView()
+    {
+        g_pTraingStrongView = this;
+    }
+
+    TraingStrongView::~TraingStrongView()
+    {
+        DeInit();
+        g_pTraingStrongView = nullptr;
+    }
+
+    TraingStrongView *TraingStrongView::GetInstance()
+    {
+
+        return g_pTraingStrongView;
+    }
+    /*
+    InitLabel:初始化标签
+    @param label 标签指针
+    @param left 标签左边位置
+    @param top 标签顶部位置
+    @param width 标签宽度
+    @param height 标签高度
+    @param viewId 标签的视图 ID
+    @param text 标签显示的文本
+    @param fontName 字体名称
+    @param fontSize 字体大小
+    */
+    void TraingStrongView::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(top, left);
+        label->Resize(width, height);
+        // 设置标签的视图 ID
+        label->SetViewId(viewId);
+        // 设置标签的样式
+        label->SetStyle(STYLE_LINE_HEIGHT, 40);
+        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 TraingStrongView::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);
+        // 设置按钮的点击事件监听器为 TraingStrongPresenter 的实例
+        button->SetOnClickListener(static_cast<UIView::OnClickListener *>(TraingStrongPresenter::GetInstance()));
+        // 设置按钮可见
+        button->SetVisible(true);
+    }
+    /*
+   InitImageView:初始化图片
+   @param imageView 图片指针
+   @param left 图片左边位置
+   @param top 图片顶部位置
+   @param width 图片宽度
+   @param height 图片高度
+   @param viewId 图片的视图 ID
+   @param imagePath 图片路径
+   */
+    void TraingStrongView::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(top, left);
+        imageView->Resize(width, height);
+        imageView->SetViewId(viewId);
+        imageView->SetSrc(imagePath);
+        imageView->SetVisible(true);
+    }
+    /* InitView:初始化界面*/
+    void TraingStrongView ::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);
+        scrollView1_->SetReboundSize(100);
+        scrollView1_->SetScrollBlankSize(52);
+        scrollView1_->SetHorizontalScrollState(false);
+        // Set additional property
+        // Add to rootView
+        container_->Add(scrollView1_);
+        scrollView1_->SetVisible(true);
+
+        // 初始化Lable
+        InitLabel(label1_, 52, 173, 120, 35, "label1", "训练强度", DEFAULT_VECTOR_FONT_FILENAME, 30);
+        InitLabel(label2_, 133, 33, 60, 35, "label2", "训练强度用于判断是否训练不足或\n者训练太过,到底使心率增加多少\n的运动强度才是最合适的。", DEFAULT_VECTOR_FONT_FILENAME, 26);
+        InitLabel(label3_, 305, 33, 69, 23, "label3", "该强度区间是对应靶心率(由个人\n基本资料计算得出)强弱的实时状\n态显示,有助于提高训练质量。", DEFAULT_VECTOR_FONT_FILENAME, 26);
+        InitLabel(label4_, 465, 33, 60, 35, "label4", "训练状态代表的意义:", DEFAULT_VECTOR_FONT_FILENAME, 26);
+        InitLabel(label5_, 505, 97, 60, 35, "label5", "较低强度-热身运动\n中等强度-燃脂区\n高等强度-提升心肺机能\n超高强度-专业运动员", DEFAULT_VECTOR_FONT_FILENAME, 26);
+        InitLabel(label6_, 740, 51, 60, 35, "label5", "注:该训练强度并非专业运动评\n估,数据仅供参考。", DEFAULT_VECTOR_FONT_FILENAME, 26);
+        label6_->SetTextColor(Color::GetColorFromRGBA(0xff, 0x8a, 0x36, 0xff));
+        scrollView1_->Add(label1_);
+        scrollView1_->Add(label2_);
+        scrollView1_->Add(label3_);
+        scrollView1_->Add(label4_);
+        scrollView1_->Add(label5_);
+        scrollView1_->Add(label6_);
+
+        // 初始化Image
+        InitImageView(image1_, 510, 60, 100, 100, "image1", imagePath_blue);
+        InitImageView(image2_, 550, 60, 100, 100, "image2", imagePath_green);
+        InitImageView(image3_, 590, 60, 100, 100, "image3", imagePath_orange);
+        InitImageView(image4_, 630, 60, 100, 100, "image4", imagePath_yellow);
+        scrollView1_->Add(image1_);
+        scrollView1_->Add(image2_);
+        scrollView1_->Add(image3_);
+        scrollView1_->Add(image4_);
+
+        // Add ImageView to App
+        if (image5_ == nullptr)
+        {
+            image5_ = new UIImageView();
+        }
+        image5_->SetPosition(183, 813); // widget's left position and top position
+        image5_->Resize(100, 100);      // widget's width and height
+        image5_->SetViewId("image3");   // Set style
+        // Set additional property
+        // Add to scrollView2
+        scrollView1_->Add(image5_);
+        image5_->SetVisible(true);
+    }
+    /* DeInit:删除组件 */
+    void TraingStrongView::DeInit()
+    {
+        UIView *view = static_cast<UIViewGroup *>(container_)->GetChildrenHead();
+        while (view != nullptr)
+        {
+            UIView *tempView = view;
+            view = view->GetNextSibling();
+            if (tempView->GetParent())
+            {
+                static_cast<UIViewGroup *>(tempView->GetParent())->Remove(tempView);
+            }
+            delete tempView;
+        }
+        delete container_;
+        container_ = nullptr;
+    }
+
+    void TraingStrongView::PreLoad(void)
+    {
+        if (!viewiInitStatus)
+        {
+            InitView();
+            viewiInitStatus = true;
+        }
+    }
+    void TraingStrongView::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 *>(TraingStrongPresenter::GetInstance());
+        if (draglistener == nullptr)
+        {
+            return;
+        }
+        container_->SetOnDragListener(draglistener);
+
+        container_->SetTouchable(true);
+        container_->SetDraggable(true);
+
+        PreLoad();
+        RootView::GetInstance()->Add(container_);
+    }
+
+    void TraingStrongView::OnSetUpView()
+    {
+
+        View<TraingStrongPresenter>::OnSetUpView();
+        Draw();
+    }
+
+    void TraingStrongView::OnTearDownView()
+    {
+
+        View<TraingStrongPresenter>::OnTearDownView();
+        return;
+    }
+
+    void TraingStrongView::OnStop()
+    {
+        View<TraingStrongPresenter>::OnStop();
+        RootView::GetInstance()->RemoveAll();
+        return;
+    }
+}