增加正常训练初始界面;优化右滑;添加资源文件
authorCaisking <3449750381@qq.com>
Mon, 4 Dec 2023 03:36:00 +0000 (11:36 +0800)
committerCaisking <3449750381@qq.com>
Mon, 4 Dec 2023 03:36:00 +0000 (11:36 +0800)
12 files changed:
Resource/res/Training/Go.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/TraingNomalPresenter.h [new file with mode: 0644]
code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingNomalView.h [new file with mode: 0644]
code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingLimitPresenter.cpp
code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingMorePresenter.cpp
code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp [new file with mode: 0644]
code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalView.cpp [new file with mode: 0644]
code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingPresenter.cpp

diff --git a/Resource/res/Training/Go.bin b/Resource/res/Training/Go.bin
new file mode 100644 (file)
index 0000000..4ae9a38
Binary files /dev/null and b/Resource/res/Training/Go.bin differ
index bc57c5e..325abe8 100644 (file)
@@ -248,6 +248,8 @@ set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingMorePresenter.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingLimitView.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingLimitPresenter.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingNomalView.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingNomalPresenter.cpp
     #ָ����
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/compass/src/CompassControlView.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/compass/src/CompassCalibrationView.cpp
index 676b81e..15d9720 100644 (file)
@@ -79,6 +79,7 @@ typedef enum : uint16_t
     VIEW_TRAINING,                        // 训练
     VIEW_TRAININGMORE,                    // 更多训练
     VIEW_TRAININGLIMIT,                   // 极限运动子列表
+    VIEW_TRAININGNOMAL,                   // 正常训练开始界面(除骑行,健走,跑步外)
     VIEW_TRAINING_RECORD,                 // 训练记录
     
     VIEW_BLOODPRESSURE,                   // 昨日睡眠时间
index 1f2ba95..595d963 100644 (file)
@@ -65,6 +65,7 @@ public:
     void InitTraingSlice(void);
     void InitTraingMoreSlice(void);
     void InitTraingLimitSlice(void);
+    void InitTraingNomalSlice(void);
     void InitUIDisplayBrightnessSlice(void);     
     void InitBlueToothSettingSlice(void);        
     void InitBrightnessControlSlice(void);      
index 1592d61..8e9fb1b 100644 (file)
 #include "traing/include/TraingMoreView.h"
 #include "traing/include/TraingLimitPresenter.h"
 #include "traing/include/TraingLimitView.h"
+#include "traing/include/TraingNomalPresenter.h"
+#include "traing/include/TraingNomalView.h"
 #include "displaybrightness/include/DisplayBrightnessPresenter.h"
 #include "displaybrightness/include/DisplayBrightnessView.h"
 #include "bluetoothofsetting/include/BlueToothOfSettingPresenter.h"
@@ -230,6 +232,7 @@ static const AppViewMapper SLICE_MAPPER[] = {
     {VIEW_TRAINING, &NativeLauncher::InitTraingSlice},                          //训练
     {VIEW_TRAININGMORE, &NativeLauncher::InitTraingMoreSlice},                  //更多训练
     {VIEW_TRAININGLIMIT, &NativeLauncher::InitTraingLimitSlice},                //极限训练
+    {VIEW_TRAININGNOMAL, &NativeLauncher::InitTraingNomalSlice},                //正常训练初始界面
 
     {VIEW_DISPLAY_BRIGHTNESS,&NativeLauncher::InitUIDisplayBrightnessSlice},    //显示与亮度的实例化地址
     {VIEW_CONNECT_BLUETOOTH,&NativeLauncher::InitBlueToothSettingSlice},        //蓝牙设置的实例化地址
@@ -803,6 +806,11 @@ void NativeLauncher::InitTraingLimitSlice(void)
     SliceProxy *trainglimitview = new AbilitySliceProxy<TraingLimitView, TraingLimitPresenter>;
     NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGLIMIT, trainglimitview);
 }
+void NativeLauncher::InitTraingNomalSlice(void)
+{
+    SliceProxy *traingnomalview = new AbilitySliceProxy<TraingNomalView, TraingNomalPresenter>;
+    NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGNOMAL, traingnomalview);
+}
 //DisplayBrightness的实例化
 void NativeLauncher::InitUIDisplayBrightnessSlice(void)
 {
diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingNomalPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingNomalPresenter.h
new file mode 100644 (file)
index 0000000..9d3d9bb
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef _TraingNomal_PRESENTER_H
+#define _TraingNomal_PRESENTER_H
+
+#include "Presenter.h"
+#include "TraingNomalView.h"
+
+namespace OHOS
+{
+    class TraingNomalView;
+
+    class TraingNomalPresenter : public Presenter<TraingNomalView>,
+                                 public UIView::OnClickListener,
+                                 public UIView::OnDragListener
+    {
+    public:
+        TraingNomalPresenter();
+        virtual ~TraingNomalPresenter();
+
+        void OnStart() override;
+        void OnPause() override;
+        void OnResume() override;
+        void OnStop() override;
+
+        static TraingNomalPresenter *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/TraingNomalView.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingNomalView.h
new file mode 100644 (file)
index 0000000..0d6ba03
--- /dev/null
@@ -0,0 +1,60 @@
+#ifndef _TraingNomal_VIEW_H
+#define _TraingNomal_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 "TraingNomalPresenter.h"
+namespace OHOS
+{
+#define BUTTONGO "button1"
+#define BUTTONSET "button2"
+
+    class TraingNomalPresenter;
+    class TraingNomalView : public View<TraingNomalPresenter>
+    {
+
+    public:
+        TraingNomalView();
+        virtual ~TraingNomalView();
+        static TraingNomalView *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};
+        TraingNomalView(TraingNomalView &&) = delete;
+        TraingNomalView &operator=(TraingNomalView &&) = delete;
+
+        UIViewGroup *container_ = nullptr;
+        UILabel *label1_ = nullptr;
+        UILabel *label2_ = nullptr;
+        UIButton *button1_ = nullptr;
+        UIButton *button2_ = nullptr;
+        bool viewiInitStatus{false};
+    };
+} // namespace OHOS
+#endif // TraingNomal_PRESENTER_H
index 0c5da9f..4369a5e 100644 (file)
@@ -58,7 +58,8 @@ namespace OHOS
     bool TraingLimitPresenter::OnDrag(UIView &view, const DragEvent &event)
     {
 
-        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
+        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT &&
+            (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY()))))
         {
             NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE);
         }
@@ -69,9 +70,9 @@ namespace OHOS
     bool TraingLimitPresenter::OnClick(UIView &view, const ClickEvent &event)
     {
         // 根据控件id查找是哪个控件触发了点击回调
-        if (strcmp(view.GetViewId(), " ") == 0)
+        if (strcmp(view.GetViewId(), BUTTON1) == 0)
         {
-            NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST);
+            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL);
         }
         if (strcmp(view.GetViewId(), "Remind") == 0)
         {
index 80b3af6..44b6989 100644 (file)
@@ -58,7 +58,8 @@ namespace OHOS
     bool TraingMorePresenter::OnDrag(UIView &view, const DragEvent &event)
     {
 
-        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
+        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT &&
+            (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY()))))
         {
             NativeAbility::GetInstance().ChangeSlice(VIEW_TRAINING);
         }
diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp
new file mode 100644 (file)
index 0000000..fd81f3d
--- /dev/null
@@ -0,0 +1,85 @@
+#include "AppViewIDs.h"
+#include "NativeAbility.h"
+
+#include <iostream>
+#include <chrono>
+#include <thread>
+#include "traing/include/TraingNomalPresenter.h"
+// #include "TraingNomalView.h"
+
+namespace OHOS
+{
+
+    // 当前Presenter属性实例化的内存指针
+    static TraingNomalPresenter *g_pTraingNomalPresenter = nullptr;
+
+    TraingNomalPresenter::TraingNomalPresenter()
+    {
+
+        g_pTraingNomalPresenter = this;
+    }
+
+    TraingNomalPresenter::~TraingNomalPresenter()
+    {
+
+        g_pTraingNomalPresenter = nullptr;
+    }
+
+    TraingNomalPresenter *TraingNomalPresenter::GetInstance()
+    {
+
+        return g_pTraingNomalPresenter;
+    }
+
+    void TraingNomalPresenter::OnStart()
+    {
+
+        Presenter<TraingNomalView>::OnStart();
+    }
+
+    void TraingNomalPresenter::OnPause(void)
+    {
+
+        Presenter<TraingNomalView>::OnPause();
+    }
+
+    void TraingNomalPresenter::OnResume(void)
+    {
+
+        Presenter<TraingNomalView>::OnResume();
+    }
+
+    void TraingNomalPresenter::OnStop(void)
+    {
+
+        Presenter<TraingNomalView>::OnStop();
+    }
+
+    bool TraingNomalPresenter::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_TRAININGMORE);
+        }
+        UNUSED(view);
+        return true;
+    }
+
+    bool TraingNomalPresenter::OnClick(UIView &view, const ClickEvent &event)
+    {
+        // 根据控件id查找是哪个控件触发了点击回调
+        if (strcmp(view.GetViewId(), " ") == 0)
+        {
+            NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST);
+        }
+        if (strcmp(view.GetViewId(), "Remind") == 0)
+        {
+            // 模拟心率监测,等待20秒
+            // std::this_thread::sleep_for(std::chrono::seconds(20));
+            // NativeAbility::GetInstance().ChangeSlice(VIEW_TraingNomalREMIND);
+        }
+        return true;
+    }
+}
diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalView.cpp
new file mode 100644 (file)
index 0000000..2ace502
--- /dev/null
@@ -0,0 +1,206 @@
+
+#include "traing/include/TraingNomalView.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 TraingNomalView *g_pTraingNomalView{nullptr};
+
+    TraingNomalView::TraingNomalView()
+    {
+        g_pTraingNomalView = this;
+    }
+
+    TraingNomalView::~TraingNomalView()
+    {
+        DeInit();
+        g_pTraingNomalView = nullptr;
+    }
+
+    TraingNomalView *TraingNomalView::GetInstance()
+    {
+
+        return g_pTraingNomalView;
+    }
+    /*
+    InitLabel:初始化标签
+    @param label 标签指针
+    @param left 标签左边位置
+    @param top 标签顶部位置
+    @param width 标签宽度
+    @param height 标签高度
+    @param viewId 标签的视图 ID
+    @param text 标签显示的文本
+    @param fontName 字体名称
+    @param fontSize 字体大小
+    */
+    void TraingNomalView::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 TraingNomalView::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);
+        // 设置按钮的点击事件监听器为 TraingNomalPresenter 的实例
+        button->SetOnClickListener(static_cast<UIView::OnClickListener *>(TraingNomalPresenter::GetInstance()));
+        // 设置按钮可见
+        button->SetVisible(true);
+    }
+    /* InitView:初始化界面*/
+    void TraingNomalView ::InitView()
+    {
+        if (container_ == nullptr)
+        {
+            container_ = new UIViewGroup();
+            container_->SetPosition(0, 0, 466, 466);
+            container_->SetStyle(STYLE_BACKGROUND_OPA, 0);
+        }
+
+        // 初始化Lable
+        InitLabel(label1_, 137, 52, 195, 35, "label1", "高空弹跳/蹦极", DEFAULT_VECTOR_FONT_FILENAME, 30);
+        container_->Add(label1_);
+        InitLabel(label2_, 160, 370, 146, 35, "label2", "设定目标 >", DEFAULT_VECTOR_FONT_FILENAME, 30);
+        container_->Add(label2_);
+        // 初始化Button
+        InitButton(button1_, 133, 133, 200, 200, BUTTONGO);
+        // Set additional property
+        char *button1defaultImgSrc = "/user/res/Training/Go.bin";
+        char *button1triggeredImgSrc = nullptr;
+        button1_->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc);
+
+        InitButton(button2_, 160, 370, 146, 35, BUTTONSET);
+        button2_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);//设置为透明按键
+        button2_->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
+        button2_->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); // 设置按下时的透明度为半透明
+
+        container_->Add(button1_);
+        container_->Add(button2_);
+    }
+    /* DeInit:删除组件*/
+    void TraingNomalView::DeInit()
+    {
+        if (label1_ != nullptr)
+        {
+            delete label1_;
+            label1_ = nullptr;
+        }
+        if (button1_ != nullptr)
+        {
+            delete button1_;
+            button1_ = nullptr;
+        }
+        if (button2_ != nullptr)
+        {
+            delete button2_;
+            button2_ = nullptr;
+        }
+        if (container_ != nullptr)
+        {
+            container_->RemoveAll();
+            delete container_;
+            container_ = nullptr;
+        }
+    }
+
+    void TraingNomalView::PreLoad(void)
+    {
+        if (!viewiInitStatus)
+        {
+            InitView();
+            viewiInitStatus = true;
+        }
+    }
+    void TraingNomalView::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 *>(TraingNomalPresenter::GetInstance());
+        if (draglistener == nullptr)
+        {
+            return;
+        }
+        container_->SetOnDragListener(draglistener);
+
+        container_->SetTouchable(true);
+        container_->SetDraggable(true);
+
+        PreLoad();
+        RootView::GetInstance()->Add(container_);
+    }
+
+    void TraingNomalView::OnSetUpView()
+    {
+
+        View<TraingNomalPresenter>::OnSetUpView();
+        Draw();
+    }
+
+    void TraingNomalView::OnTearDownView()
+    {
+
+        View<TraingNomalPresenter>::OnTearDownView();
+        return;
+    }
+
+    void TraingNomalView::OnStop()
+    {
+        View<TraingNomalPresenter>::OnStop();
+        RootView::GetInstance()->RemoveAll();
+        return;
+    }
+}
index 27334e7..fb84c41 100644 (file)
@@ -5,7 +5,7 @@
 #include <chrono>
 #include <thread>
 #include "traing/include/TraingPresenter.h"
-//#include "TraingView.h"
+// #include "TraingView.h"
 
 namespace OHOS
 {
@@ -58,7 +58,8 @@ namespace OHOS
     bool TraingPresenter::OnDrag(UIView &view, const DragEvent &event)
     {
 
-        if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT)
+        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT &&
+            (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY()))))
         {
             NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST);
         }
@@ -76,8 +77,8 @@ namespace OHOS
         if (strcmp(view.GetViewId(), "Remind") == 0)
         {
             // 模拟心率监测,等待20秒
-            //std::this_thread::sleep_for(std::chrono::seconds(20));
-            //NativeAbility::GetInstance().ChangeSlice(VIEW_TraingREMIND);
+            // std::this_thread::sleep_for(std::chrono::seconds(20));
+            // NativeAbility::GetInstance().ChangeSlice(VIEW_TraingREMIND);
         }
         return true;
     }