增加训练音乐卡片界面
authorCaisking <3449750381@qq.com>
Mon, 25 Mar 2024 09:47:57 +0000 (17:47 +0800)
committerCaisking <3449750381@qq.com>
Mon, 25 Mar 2024 09:47:57 +0000 (17:47 +0800)
code/sdk/application/wearable/fd230app/CMakeLists.txt
code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h
code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h
code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp
code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingMusicPresenter.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingMusicView.h
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingDataPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingMusicPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingMusicView.cpp

index 502c615..9648243 100644 (file)
@@ -440,6 +440,8 @@ set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingGPSbackView.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingWinView.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingWinPresenter.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingMusicView.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingMusicPresenter.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/traing_card/Traing_CardView.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/traing_card/Traing_CardPresenter.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traingrecord/src/TraingRecordView.cpp
index d9ad718..7145afe 100644 (file)
@@ -67,6 +67,7 @@ typedef enum : uint16_t
     VIEW_SAVEBAT,  // 省电模式界面
     /* ----------------------------------- 训练 ----------------------------------- */
     VIEW_TRAINING,          // 训练
+    VIEW_TRAININGMUSIC,       // 训练音乐
     VIEW_TRAININGMORE,      // 更多训练
     VIEW_RUNNING,           // 跑步训练之列表
     VIEW_TRAININGLIMIT,     // 极限运动子列表
index 242eb4f..e208918 100644 (file)
@@ -36,17 +36,12 @@ namespace OHOS
         void InitWeatherSlice(void);
         void InitFutureWeatherSlice(void);
         void InitGetWeatherDataErrorSlice(void);
-        /* -------------------------------------------------------------------------- */
         void InitSystemSlice(void);
-        /* -------------------------------------------------------------------------- */
         void InitSoundAndVibrationSlice(void);
         void InitSystemVolumeSlice(void);
         void InitCallVolumeSlice(void);
         void InitMediaVolumeSlice(void);
-        void InitMessageSlice(void);
-        /* -------------------------------------------------------------------------- */
         void InitDisplayBrightnessSlice(void);
-        /* --------------------------------- 经典蓝牙界面 --------------------------------- */
         void InitClassicBluetoothSlice(void);
         /* --------------------------------界面------------------------------------ */
         void InitRotateSlice(void);
@@ -56,8 +51,10 @@ namespace OHOS
         void InitDialUpdateSlice(void);
         void InitSaveEleSlice(void);
         void InitSaveBatSlice(void);
+        void InitMessageSlice(void);
         /* ----------------------------------- 训练 ----------------------------------- */
         void InitTraingSlice(void);
+        void InitTraingMusicSlice(void);
         void InitTraingMoreSlice(void);
         void InitTraingLimitSlice(void);
         void InitTraingNomalSlice(void);
index 81e4f02..0038c7d 100644 (file)
 #include "traing/include/TraingGPSbackView.h"
 #include "traing/include/TraingWinPresenter.h"
 #include "traing/include/TraingWinView.h"
+#include "traing/include/TraingMusicView.h"
+#include "traing/include/TraingMusicPresenter.h"
 
 #include "traingrecord/include/TraingRecordView.h"
 #include "traingrecord/include/TraingRecordPresenter.h"
@@ -251,11 +253,13 @@ namespace OHOS
         {VIEW_PHONERING, &NativeLauncher::InitPhoneRingSlice},
 
         {VIEW_TEST, &NativeLauncher::InittestSlice},
+
         /* ---------------------------------- 省电模式 ---------------------------------- */
         {VIEW_SAVEELE, &NativeLauncher::InitSaveEleSlice},
         {VIEW_SAVEBAT, &NativeLauncher::InitSaveBatSlice},
         /* ----------------------------------- 训练 ----------------------------------- */
         {VIEW_TRAINING, &NativeLauncher::InitTraingSlice},                   // 训练
+        {VIEW_TRAININGMUSIC, &NativeLauncher::InitTraingMusicSlice},         // 训练音乐卡片
         {VIEW_TRAININGMORE, &NativeLauncher::InitTraingMoreSlice},           // 更多训练
         {VIEW_TRAININGLIMIT, &NativeLauncher::InitTraingLimitSlice},         // 极限训练
         {VIEW_TRAININGNOMAL, &NativeLauncher::InitTraingNomalSlice},         // 正常训练初始界面
@@ -279,7 +283,6 @@ namespace OHOS
         {VIEW_TRAININGGPSLOST, &NativeLauncher::InitTraingGPSlostSlice},     // GPS断联
         {VIEW_TRAININGGPSBACK, &NativeLauncher::InitTraingGPSbackSlice},     // GPS回连
         {VIEW_TRAININGWIN, &NativeLauncher::InitTraingWinSlice},             // 训练目标达成
-
         {VIEW_TRAINING_RECORD, &NativeLauncher::InitTraingRecordSlice}, // 训练目标达成
     /* -------------------------------------------------------------------------- */
 
@@ -977,6 +980,11 @@ namespace OHOS
         SliceProxy *traingrecordview = new AbilitySliceProxy<TraingRecordView, TraingRecordPresenter>;
         NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAINING_RECORD, traingrecordview);
     }
+    void NativeLauncher::InitTraingMusicSlice(void)
+    {
+        SliceProxy *traingmusicview = new AbilitySliceProxy<TraingMusicView, TraingMusicPresenter>;
+        NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGMUSIC, traingmusicview);
+    }
     /* -------------------------------------------------------------------------- */
 
     // 省电模式
index cc03023..75f761b 100644 (file)
@@ -33,6 +33,7 @@ namespace OHOS
         {VIEW_RECORD, PNG_APPLIST_RECORD_IMAGE, PNG_APPLIST_RECORD_IMAGE, "录音", nullptr},
         {VIEW_CALLER_LOG, PNG_APPLIST_CALLLOG_IMAGE, PNG_APPLIST_CALLLOG_IMAGE, "通话记录", nullptr},
         {VIEW_PHONE, PNG_APPLIST_CALLER_IMAGE, PNG_APPLIST_CALLER_IMAGE, "电话", nullptr},
+        {VIEW_CONNECT_PHONE, PNG_CONNECT_PHONE_IMAGE, PNG_CONNECT_PHONE_IMAGE, "连接手机", nullptr},
 #ifdef SUPPORT_ALIPAY_SEC
         {VIEW_MAIN_ALIPAY, PNG_APPLIST_ALIPAY_IMAGE, PNG_APPLIST_ALIPAY_IMAGE, "支付宝", nullptr},
 #endif
diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingMusicPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingMusicPresenter.h
new file mode 100644 (file)
index 0000000..ac2fb70
--- /dev/null
@@ -0,0 +1,35 @@
+
+#ifndef _TraingMusic_PRESENTER_H
+#define _TraingMusic_PRESENTER_H
+
+#include "Presenter.h"
+#include "TraingMusicView.h"
+
+namespace OHOS
+{
+    class TraingMusicView;
+
+    class TraingMusicPresenter : public Presenter<TraingMusicView>,
+                                 public UIView::OnClickListener,
+                                 public UIView::OnDragListener
+    {
+    public:
+        TraingMusicPresenter();
+        virtual ~TraingMusicPresenter();
+
+        void OnStart() override;
+        void OnPause() override;
+        void OnResume() override;
+        void OnStop() override;
+
+        static TraingMusicPresenter *GetInstance();
+
+    private:
+        // 因为继承了OnClickListener,所以有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;
+    };
+} // namespace OHOS
+
+#endif // SLEEPDETAIL_PRESENTER_H
\ No newline at end of file
index e69de29..b256d94 100644 (file)
@@ -0,0 +1,50 @@
+
+#ifndef _TraingMusic_VIEW_H
+#define _TraingMusic_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 "PlayersView.h"
+#include "TraingMusicPresenter.h"
+namespace OHOS
+{
+    class TraingMusicPresenter;
+    class TraingMusicView : public View<TraingMusicPresenter>
+    {
+
+    public:
+        TraingMusicView();
+        virtual ~TraingMusicView();
+        static TraingMusicView *GetInstance(void);
+
+        void OnStart() override;
+        void OnSetUpView() override;
+        void OnTearDownView() override;
+        void OnStop() override;
+        void InitView();
+        void DeInit();
+        void PreLoad(void);
+
+    private:
+        UIView::OnDragListener *draglistener{nullptr};
+        TraingMusicView(TraingMusicView &&) = delete;
+        TraingMusicView &operator=(TraingMusicView &&) = delete;
+        PlayersView *playersView{nullptr};
+        UIViewGroup *container_ = nullptr;
+        bool viewiInitStatus{false};
+    };
+} // namespace OHOS
+#endif // TraingMusic_PRESENTER_H
index 52c7ec1..2d90da2 100644 (file)
@@ -1,4 +1,12 @@
-/*** \r
+/***\r
+ * @Author: Caisking 3449750381@qq.com\r
+ * @Date: 2024-03-19 17:37:19\r
+ * @LastEditors: Caisking 3449750381@qq.com\r
+ * @LastEditTime: 2024-03-25 16:44:36\r
+ * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/src/TraingDataPresenter.cpp\r
+ * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE\r
+ */\r
+/***\r
  * @Author: Caisking 3449750381@qq.com\r
  * @Date: 2024-03-19 17:37:19\r
  * @LastEditors: Caisking 3449750381@qq.com\r
@@ -70,6 +78,10 @@ namespace OHOS
         {\r
             NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGDETAIL);\r
         }\r
+        if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT)\r
+        {\r
+            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMUSIC);\r
+        }\r
         UNUSED(view);\r
         return true;\r
     }\r
index e69de29..487a9ff 100644 (file)
@@ -0,0 +1,72 @@
+#include "AppViewIDs.h"
+#include "NativeAbility.h"
+
+#include <iostream>
+#include <chrono>
+#include <thread>
+#include "traing/include/TraingMusicPresenter.h"
+// #include "TraingMusicView.h"
+
+namespace OHOS
+{
+
+    // 当前Presenter属性实例化的内存指针
+    static TraingMusicPresenter *g_pTraingMusicPresenter = nullptr;
+    TraingMusicPresenter::TraingMusicPresenter()
+    {
+        g_pTraingMusicPresenter = this;
+    }
+
+    TraingMusicPresenter::~TraingMusicPresenter()
+    {
+        g_pTraingMusicPresenter = nullptr;
+    }
+
+    TraingMusicPresenter *TraingMusicPresenter::GetInstance()
+    {
+        return g_pTraingMusicPresenter;
+    }
+
+    void TraingMusicPresenter::OnStart()
+    {
+
+        Presenter<TraingMusicView>::OnStart();
+    }
+
+    void TraingMusicPresenter::OnPause(void)
+    {
+
+        Presenter<TraingMusicView>::OnPause();
+    }
+
+    void TraingMusicPresenter::OnResume(void)
+    {
+
+        Presenter<TraingMusicView>::OnResume();
+    }
+
+    void TraingMusicPresenter::OnStop(void)
+    {
+
+        Presenter<TraingMusicView>::OnStop();
+    }
+    bool TraingMusicPresenter::OnDrag(UIView &view, const DragEvent &event)
+    {
+        return true;
+    }
+    bool TraingMusicPresenter::OnDragEnd(UIView &view, const DragEvent &event)
+    {
+
+        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
+        {
+            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGDATA);
+        }
+        UNUSED(view);
+        return true;
+    }
+
+    bool TraingMusicPresenter::OnClick(UIView &view, const ClickEvent &event)
+    {
+        return true;
+    }
+}
index e69de29..e93705b 100644 (file)
@@ -0,0 +1,121 @@
+
+#include "traing/include/TraingMusicView.h"
+#include <ui_scroll_view.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"
+#include "traing/include/TraingModel.h"
+#include "traing/Training_UiConfig.h"
+
+namespace OHOS
+{
+
+    static TraingMusicView *g_pTraingMusicView{nullptr};
+
+    TraingMusicView::TraingMusicView()
+    {
+        g_pTraingMusicView = this;
+    }
+
+    TraingMusicView::~TraingMusicView()
+    {
+        DeInit();
+        g_pTraingMusicView = nullptr;
+    }
+
+    TraingMusicView *TraingMusicView::GetInstance()
+    {
+        return g_pTraingMusicView;
+    }
+    /******************************************************************************************************/
+
+    /* DeInit:删除组件 */
+    void TraingMusicView::DeInit()
+    {
+        // 删除容器
+        if (playersView != nullptr)
+        {
+            playersView->RemoveAll(); // 移除容器中的所有组件
+            delete playersView;
+            playersView = nullptr;
+        }
+        if (container_ != nullptr)
+        {
+            container_->RemoveAll(); // 移除容器中的所有组件
+            delete container_;
+            container_ = nullptr;
+        }
+    }
+
+    void TraingMusicView::PreLoad(void)
+    {
+        if (!viewiInitStatus)
+        {
+            InitView();
+            viewiInitStatus = true;
+        }
+    }
+    void TraingMusicView ::InitView()
+    {
+        if (container_ == nullptr)
+        {
+            container_ = new UIViewGroup();
+            container_->SetPosition(0, 0, 466, 466);
+            container_->SetStyle(STYLE_BACKGROUND_OPA, 0);
+        }
+        playersView = new PlayersView();
+        if (playersView == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "playersView new fail");
+            return;
+        }
+        playersView->PreLoad();
+        container_->Add(playersView);
+    }
+    void TraingMusicView::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 *>(TraingMusicPresenter::GetInstance());
+        if (draglistener == nullptr)
+        {
+            return;
+        }
+        container_->SetOnDragListener(draglistener);
+        container_->SetTouchable(true);
+        container_->SetDraggable(true);
+        PreLoad();
+        RootView::GetInstance()->Add(container_);
+    }
+
+    void TraingMusicView::OnSetUpView()
+    {
+
+        View<TraingMusicPresenter>::OnSetUpView();
+        Draw();
+    }
+
+    void TraingMusicView::OnTearDownView()
+    {
+
+        View<TraingMusicPresenter>::OnTearDownView();
+        return;
+    }
+
+    void TraingMusicView::OnStop()
+    {
+        View<TraingMusicPresenter>::OnStop();
+        RootView::GetInstance()->RemoveAll();
+        return;
+    }
+}