1.增加运动计时以及数据卡片;
authorCaisking <3449750381@qq.com>
Tue, 9 Apr 2024 10:36:04 +0000 (18:36 +0800)
committerCaisking <3449750381@qq.com>
Tue, 9 Apr 2024 10:36:04 +0000 (18:36 +0800)
2.实现训练time功能
3.配置训练运动状态

14 files changed:
code/sdk/application/wearable/fd230app/CMakeLists.txt
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/main/src/MainModel.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TraingCardPresenter.h
code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TraingCardView.h
code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TrainingControlView.h
code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TrainingDataView.h
code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardView.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TrainingControlView.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TrainingDataView.cpp

index fca48d5..c4e6b86 100644 (file)
@@ -491,7 +491,8 @@ set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_card/src/TraingCardView.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_card/src/TraingCardPresenter.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_card/src/TrainingControlView.cpp
-    
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_card/src/TrainingDataView.cpp
+
     #训练记录
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traingrecord/src/TraingRecordView.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traingrecord/src/TraingRecordPresenter.cpp
index bbf6d1a..f1d2c5c 100644 (file)
 #include "product_adapter.h"
 #endif
 
-namespace OHOS {
-struct AppViewMapper
+namespace OHOS
 {
-    AppViewId id;
-    void (NativeLauncher::*func)(void);
-};
+    struct AppViewMapper
+    {
+        AppViewId id;
+        void (NativeLauncher::*func)(void);
+    };
 
     struct ViewIdToString
     {
@@ -343,14 +344,14 @@ struct AppViewMapper
 #ifdef SUPPORT_ALIPAY_SEC
         {VIEW_MAIN_ALIPAY, &NativeLauncher::InitMainAlipaySlice},
 #endif
-       {VIEW_SET_DESKTOP, &NativeLauncher::InitSetDesktopSlice},
-    {VIEW_SET_CARD, &NativeLauncher::InitSetCardSlice},
-    {VIEW_ADD_CARD, &NativeLauncher::InitAddCardSlice},
-    {VIEW_SET_DIAL, &NativeLauncher::InitSetDialSlice},
+        {VIEW_SET_DESKTOP, &NativeLauncher::InitSetDesktopSlice},
+        {VIEW_SET_CARD, &NativeLauncher::InitSetCardSlice},
+        {VIEW_ADD_CARD, &NativeLauncher::InitAddCardSlice},
+        {VIEW_SET_DIAL, &NativeLauncher::InitSetDialSlice},
+        {VIEW_MAIN_TEMP, &NativeLauncher::InitMainTempSlice},
 #if 0
         {VIEW_MAIN_ACTIVITY, &NativeLauncher::InitActivitySlice},
         {VIEW_OFFLINEVOICE, &NativeLauncher::InitOfflineVoice},
-        {VIEW_MAIN_TEMP, &NativeLauncher::InitMainTempSlice},
         {VIEW_UISAMPLE, &NativeLauncher::InitUISampleSlice}
 #endif
     };
@@ -383,8 +384,8 @@ struct AppViewMapper
 
     void NativeLauncher::InitNativeLauncher()
     {
-       #ifdef JS_ENABLE
-    ACELite::ProductAdapter::SetScreenSize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
+#ifdef JS_ENABLE
+        ACELite::ProductAdapter::SetScreenSize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
 #endif
         ConfigModel::GetInstance()->Init();
         // 初始化语言
@@ -403,7 +404,7 @@ struct AppViewMapper
         PresenterTask::GetInstance()->Init();
         PlayersModel::GetInstance()->AudioInit();
         ActivityModel::GetInstance()->Init();
-         ScreenModels::GetInstance()->InitKvStorage();
+        ScreenModels::GetInstance()->InitKvStorage();
         VocassistModel::GetInstance()->Init();
         HeartModel::GetInstance()->Init();
         BluetoothModel::GetInstance()->Init();
index a0feae8..45db99d 100644 (file)
@@ -39,14 +39,16 @@ namespace OHOS
         {VIEW_MAIN_STOPWATCH, PNG_APPLIST_STOPWATCH_IMAGE, PNG_APPLIST_STOPWATCH_IMAGE, "秒表", nullptr},
         {VIEW_MAIN_COUNTDOWN, PNG_APPLIST_COUNTDOWN_IMAGE, PNG_APPLIST_COUNTDOWN_IMAGE, "计时器", nullptr},
         {VIEW_CONNECT_PHONE, PNG_CONNECT_PHONE_IMAGE, PNG_CONNECT_PHONE_IMAGE, "连接手机", nullptr},
-        {VIEW_SET_DESKTOP, PNG_APPLIST_ALARM_IMAGE, PNG_APPLIST_ALARM_IMAGE, "主题样式", nullptr},
-        {VIEW_SET_CARD, PNG_APPLIST_SETTING_IMAGE, PNG_APPLIST_SETTING_IMAGE, "卡片管理", nullptr},
+        {VIEW_SET_DESKTOP, PNG_SETTTING_REBOOT_IMAGE, PNG_SETTTING_REBOOT_IMAGE, "主题样式", nullptr},
+        {VIEW_SET_CARD, PNG_SETTTING_SHUTDOWN_IMAGE, PNG_SETTTING_SHUTDOWN_IMAGE, "卡片管理", nullptr},
         {VIEW_SET_DIAL, PNG_APPLIST_UI_SAMPLE_IMAGE, PNG_APPLIST_UI_SAMPLE_IMAGE, "切换表盘", nullptr},
-    //{VIEW_LANGUAGE_SWITCH, PNG_CONNECT_PHONE_IMAGE, PNG_CONNECT_PHONE_IMAGE, "语言切换", nullptr},
+        {VIEW_MAIN_TEMP, PNG_APPLIST_TEMP_IMAGE, PNG_APPLIST_TEMP_IMAGE, "体温", nullptr},
+
 #ifdef SUPPORT_ALIPAY_SEC
         {VIEW_MAIN_ALIPAY, PNG_APPLIST_ALIPAY_IMAGE, PNG_APPLIST_ALIPAY_IMAGE, "支付宝", nullptr},
 #endif
 #if 0
+        {VIEW_LANGUAGE_SWITCH, PNG_CONNECT_PHONE_IMAGE, PNG_CONNECT_PHONE_IMAGE, "语言切换", nullptr},
         {VIEW_MAIN_TEMP, PNG_APPLIST_TEMP_IMAGE, PNG_APPLIST_TEMP_IMAGE, "体温", nullptr},
         {VIEW_OFFLINEVOICE, PNG_APPLIST_VOCASSIST_IMAGE, PNG_APPLIST_VOCASSIST_IMAGE, "语音助手", nullptr},
         {VIEW_UISAMPLE, PNG_APPLIST_UI_SAMPLE_IMAGE, PNG_APPLIST_UI_SAMPLE_IMAGE, "示例", nullptr},
index 4d50ad9..fec1e64 100644 (file)
@@ -27,7 +27,7 @@ namespace OHOS
     };\r
 \r
     const DialInfo dialInfoMap[] = {\r
-        {DIAL_CLOCK, "KUMI", PNG_SET_DIAL_CLOCK, DEFAULT_TASK_PERIOD},\r
+        {DIAL_CLOCK, "KUMI", DEFAULT_DIALPER_PATH, DEFAULT_TASK_PERIOD},\r
     };\r
 \r
     MainModel::MainModel() {}\r
index eb86b43..1b7e1c1 100644 (file)
@@ -58,6 +58,15 @@ struct QuickTraining
 
 namespace OHOS
 {
+    // 运动状态
+    enum class ExerciseState
+    {
+        General = 0,
+        Start,
+        End,
+        Pause,
+        Continue
+    };
     class TraingModel
     {
     public:
@@ -70,23 +79,26 @@ namespace OHOS
         bool InitButtonExt(UILabelButtonExt *&button, int left, int top, int width, int height, const char *viewId, UIResourceTextId id, int fontSize);
         bool InitImageView(UIImageView *&imageView, int left, int top, int width, int height, const char *viewId, const char *imagePath);
         void InitList();
-
         void SetQuickTraining(QuickTraining *quickTraining);
         QuickTraining *GetQuickTraining() const;
-        /* ----------------------------------- 定时器 ---------------------------------- */
-        void StartTimer(uint32_t interval);
-        void StopTimer(void);
-        char *ShowTimer(void);
-
+        /*定时器 */
+        std::string DisplayMotionDuration();
+        /*设置运动项目*/
         void SetSportEvent(UIResourceTextId id);
+        /*获取运动项目*/
         UIResourceTextId GetSportEvent();
+        /*设置运动状态*/
+        void SetSportState(ExerciseState state);
+        /*获取运动状态*/
+        ExerciseState GetSportState();
 
     private:
         TraingModel(const TraingModel &) = delete;
         TraingModel &operator=(const TraingModel &) = delete;
 
-        std::string trainingTimer_;                     // 训练时长
-        UIResourceTextId sportId_ = STR_EXTREME_SPORTS; // 训练项目
+        std::string motionDuration;                         // 训练时长
+        UIResourceTextId sportId_ = STR_EXTREME_SPORTS;     // 训练项目
+        ExerciseState sportstate_ = ExerciseState::General; // 训练状态
     };
 }
 
index 584fde2..22e8710 100644 (file)
 #include <iomanip>
 #include <string>
 #include "cmsis_os.h"
+#include "traing/training_card/include/TraingCardPresenter.h"
 
-#define TIMER 0
+#define TIMER 1
 #define CHECK 0
 namespace OHOS
 {
 
 #if TIMER
     // 声明定时器变量
-    static osTimerId_t g_timer = NULL;
-    static int g_trainingTimer = {0};
+    static osTimerId_t g_startCounting = NULL; // 定时器
+    static constexpr uint64_t MS_ONE_SECONDS = 1000;
+    static int g_motionTimes{0};
     static constexpr int32 NUM_TEN = 10;
     static constexpr int16 ERROR = 0;
     static constexpr int16 SUCCESS = 1;
@@ -256,104 +258,116 @@ namespace OHOS
     }
 
 #if TIMER
-    /*
-     * @brief 在这里添加定时器到期后的处理逻辑
-     */
-    static void TimerCallbackProc(int data)
+    /* 时间显示 */
+    std::string TraingModel::DisplayMotionDuration()
     {
-        g_trainingTimer++;
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "g_trainingTimer:%d\n", g_trainingTimer);
+        motionDuration.clear();
 
-        if (ShowTimer() == nullptr)
+        if (g_motionTimes >= NUM_TIME_DAY)
         {
-            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[Recording_TimerCallbackProc] DisplaytrainingTimer is NULL");
-            return;
+            g_motionTimes = 0;
         }
 
-        // RecordGoingView::GetInstance()->GetRecordingDurationLabel()->SetText(RecordingModel::GetInstance()->DisplaytrainingTimer());
-    }
+        int hour = g_motionTimes / NUM_TIME_HOUR;
+        int min = (g_motionTimes % NUM_TIME_HOUR) / NUM_TIME_MIN;
+        int sec = (g_motionTimes % NUM_TIME_HOUR) % NUM_TIME_MIN;
 
-    /*
-     * @brief 运动计时回调函数
-     */
-    static void TimerCallback(int data)
-    {
-        GraphicService::GetInstance()->PostGraphicEvent(std::bind(TimerCallbackProc, data));
+        std::ostringstream oss;
+        oss << std::setfill('0') << std::setw(2) << hour << ":" << std::setw(2) << min << ":" << std::setw(2) << sec;
+
+        motionDuration = oss.str();
+        return motionDuration;
     }
-    /**
-     * @brief 开启定时器函数
-     * @param interval 时间间隔,单位ms
-     */
-    void TraingModel::StartTimer(uint32_t interval)
+#ifdef __cplusplus
+    extern "C"
     {
-        // 检查定时器是否已经存在,如果存在则返回
-        if (g_timer != NULL)
-        {
-            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TraingModel::Recording_StartTimer Timer already exists!!");
-            return;
-        }
-
-        // 创建定时器
-        g_timer = osTimerNew((osTimerFunc_t)TimerCallback, osTimerPeriodic, NULL, NULL);
-        if (g_timer == NULL)
+#endif
+        /* 定时器回调函数 */
+        void TraingTimerCallback()
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingModel Timer create failed!!");
-            return;
+            g_motionTimes++;
+            TraingCardPresenter *gTraingCardPresenter = TraingCardPresenter::GetInstance();
+            if (gTraingCardPresenter == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingTimerCallback::gTraingCardPresenter new fail");
+                return;
+            }
+            gTraingCardPresenter->ModifiesTime();
         }
 
-        // 将毫秒转换为系统时钟节拍数
-        int tick = osMs2Tick(interval);
-
-        // 启动定时器
-        osStatus_t ret = osTimerStart(g_timer, tick);
-
-        if (ret != osOK)
+        /* 开启定时器 */
+        void InitTraingTimer()
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingModel osTimerStart failed, ret = %lx!!", ret);
-            if (g_timer != NULL)
+            if (g_startCounting != NULL)
+            {
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TraingModel::TraingTimer already exists!!");
+                return;
+            }
+            g_startCounting = osTimerNew((osTimerFunc_t)TraingTimerCallback, osTimerPeriodic, NULL, NULL);
+            if (g_startCounting == NULL)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingModel::TraingTimer osTimerNew failed!!");
+                return;
+            }
+            int tick = osMs2Tick(MS_ONE_SECONDS);
+            osStatus_t retTimer = osTimerStart(g_startCounting, tick);
+            if (retTimer != osOK)
             {
-                osTimerDelete(g_timer);
-                g_timer = NULL;
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingModel::TraingTimer osTimerStart failed, ret = %lx!!", retTimer);
+                if (g_startCounting != NULL)
+                {
+                    retTimer = osTimerDelete(g_startCounting);
+                    if (retTimer != osOK)
+                    {
+                        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingModel::osTimerDelete failed, ret = %lx!!", retTimer);
+                        return;
+                    }
+                    g_startCounting = NULL;
+                }
+                return;
             }
-            return;
         }
-    }
-
-    /**
-     * @brief 停止定时器
-     */
-    void TraingModel::StopTimer()
-    {
-        // 检查定时器是否存在
-        if (g_timer != NULL)
+        /* 关闭定时器 */
+        void DisableTraingTimer()
         {
-            // 删除定时器并置为 NULL
-            osStatus_t ret = osTimerDelete(g_timer);
-            if (ret != osOK)
+            if (g_startCounting != NULL)
             {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingModel::Recording_StopTimer osTimerDelete failed, ret = %lx!!", ret);
+                osStatus_t ret = osTimerDelete(g_startCounting);
+                if (ret != osOK)
+                {
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret);
+                    return;
+                }
+                g_startCounting = NULL;
+                g_motionTimes = 0;
             }
-            g_timer = NULL;
-            g_trainingTimer = 0;
         }
+
+#ifdef __cplusplus
     }
-    // 显示计时时间
-    char *TraingModel::ShowTimer()
+#endif
+    /*设置运动状态*/
+    void TraingModel::SetSportState(ExerciseState state)
     {
-        trainingTimer.erase();
-
-        int hour = g_trainingTimer / NUM_TIME_HOUR;
-        int min = (g_trainingTimer % NUM_TIME_HOUR) / NUM_TIME_MIN;
-        int sec = (g_trainingTimer % NUM_TIME_HOUR) % NUM_TIME_MIN;
-
-        std::ostringstream oss;
-        oss << std::setw(2) << std::setfill('0') << hour << ":"
-            << std::setw(2) << std::setfill('0') << min << ":"
-            << std::setw(2) << std::setfill('0') << sec;
-
-        trainingTimer = oss.str();
+        sportstate_ = state;
+    }
+    /*获取运动状态*/
+    ExerciseState TraingModel::GetSportState()
+    {
+        return sportstate_;
+    }
+#if 0
+    // 打开传感器
+    bool TraingModel::OpenDistancesSensor(void)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TraingModel::OpenDistancesSensor!!");
+        return true;
+    }
 
-        return (char *)trainingTimer.c_str();
+    bool TraingModel::CloseDistancesSensor(void)
+    {
+        return true;
     }
 #endif
+#endif
 }
\ No newline at end of file
index 2d8fcc6..9ac2030 100644 (file)
@@ -1,4 +1,4 @@
-/*** \r
+/***\r
  * @Author: Caisking 3449750381@qq.com\r
  * @Date: 2024-03-19 17:37:18\r
  * @LastEditors: Caisking 3449750381@qq.com\r
 \r
 #include "Presenter.h"\r
 #include "TraingCardView.h"\r
-\r
+#include "traing/training_card/include/TrainingControlView.h"\r
+#include "traing/training_card/include/TrainingDataView.h"\r
 namespace OHOS\r
 {\r
     class TraingCardView;\r
-\r
+    class TrainingControlView;\r
+    class TrainingDataView;\r
     class TraingCardPresenter : public Presenter<TraingCardView>,\r
-                                 public UIView::OnClickListener,\r
-                                 public UIView::OnDragListener\r
+                                public UIView::OnClickListener,\r
+                                public UIView::OnDragListener\r
     {\r
     public:\r
         TraingCardPresenter();\r
@@ -31,11 +33,13 @@ namespace OHOS
         void OnStop() override;\r
         static TraingCardPresenter *GetInstance();\r
 \r
+        void ModifiesTime();\r
+\r
     private:\r
         // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承;\r
         bool OnClick(UIView &view, const ClickEvent &event) override;\r
         bool OnDrag(UIView &view, const DragEvent &event) override;\r
-        //bool OnDragEnd(UIView& view, const DragEvent& event) override;\r
+        // bool OnDragEnd(UIView& view, const DragEvent& event) override;\r
     };\r
 } // namespace OHOS\r
 \r
index dfb8790..26a577c 100644 (file)
 \r
 #include "PlayersView.h"\r
 #include "traing/training_card/include/TrainingControlView.h"\r
-#include "traing/include/TraingDataView.h"\r
+#include "traing/training_card/include/TrainingDataView.h"\r
 \r
 namespace OHOS\r
 {\r
     enum Control_Card\r
     {\r
         CONTROL = 0,\r
-        // DATA,\r
+        DATA,\r
         MUSIC\r
     };\r
 \r
     class TraingCardPresenter;\r
     class TrainingControlView;\r
+    class TrainingDataView;\r
     class TraingCardView : public View<TraingCardPresenter>\r
     {\r
 \r
@@ -62,11 +63,8 @@ namespace OHOS
         void DeInit();\r
         void InitList();\r
         void PreLoad(void);\r
-\r
-        // 通过函数改变\r
-        void SetLabel();\r
-        void SetButton();\r
-\r
+        \r
+        int GetCurrentPageId();\r
     private:\r
         UIView::OnDragListener *draglistener{nullptr};\r
         TraingCardView(TraingCardView &&) = delete;\r
@@ -75,7 +73,7 @@ namespace OHOS
         UISwipeView *swipe_ = nullptr;\r
 \r
         TrainingControlView *ControlView{nullptr};\r
-        TraingDataView *DataVIew{nullptr};\r
+        TrainingDataView *DataVIew{nullptr};\r
         PlayersView *MusicView{nullptr};\r
 \r
         bool viewiInitStatus{false};\r
index adbda5f..bfe13d9 100644 (file)
@@ -42,8 +42,11 @@ namespace OHOS
         void PreLoad(void) override;
         void UnLoad(void) override;
 
-        void SetButton();
-        void SetLabel();
+        // 通过函数改变
+        UILabelExt *GetLabel();
+        UIButton *GetButton();
+
+        UILabelExt *GetTimeLabel();
 
     private:
         UIView::OnDragListener *draglistener{nullptr};
index e69de29..44d55b7 100644 (file)
@@ -0,0 +1,73 @@
+#ifndef _TrainingData_VIEW_H
+#define _TrainingData_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_label_ext.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 "traing/include/TraingModel.h"
+#include "traing/Training_UiConfig.h"
+
+#include "traing/include/TraingModel.h"
+#include "traing/Training_UiConfig.h"
+
+#include "traing/training_card/include/TrainingDataView.h"
+#include "traing/training_card/include/TraingCardPresenter.h"
+namespace OHOS
+{
+#define BUTTONNOTE "button1"
+
+    class TrainingDataView : public UICardPage
+    {
+    public:
+        TrainingDataView();
+        virtual ~TrainingDataView();
+        static TrainingDataView *GetInstance(void);
+
+        void InitView();
+        void DeInit();
+
+        void PreLoad(void) override;
+        void UnLoad(void) override;
+        UILabelExt *GetTimeLabel();
+
+    private:
+        UIView::OnDragListener *draglistener{nullptr};
+        TrainingDataView(TrainingDataView &&) = delete;
+        TrainingDataView &operator=(TrainingDataView &&) = delete;
+
+        UIViewGroup *container_ = nullptr;
+
+        UILabelExt *curtimelabel = nullptr;  // 当前时间
+        UILabelExt *sportlabel = nullptr;    // 运动项目名称
+        UILabelExt *timerlabel = nullptr;    // 计时
+        UILabelExt *heartlabel = nullptr;    // 运动实时心率
+        UILabelExt *strengthlabel = nullptr; // 运动强度
+
+        UIImageView *image_progress = nullptr;
+        UIImageView *image_arrows = nullptr;
+        UIImageView *image_lowIntensity = nullptr;       // 低等强度
+        UIImageView *image_mediumIntensity = nullptr;    // 中等强度
+        UIImageView *image_highIntensity = nullptr;      // 高等强度
+        UIImageView *image_superHighIntensity = nullptr; // 超高等强度
+
+        UIImageView *image_iconup = nullptr;
+        UIImageView *image_iconpoint = nullptr;
+
+        UIButton *buttonNote = nullptr; // 注意事项按键
+        bool viewiInitStatus{false};
+    };
+} // namespace OHOS
+#endif // TraingData_PRESENTER_H
index 9e41843..d70b5ec 100644 (file)
@@ -13,7 +13,6 @@
 \r
 namespace OHOS\r
 {\r
-\r
     // 当前Presenter属性实例化的内存指针\r
     static TraingCardPresenter *g_pTraingCardPresenter = nullptr;\r
 \r
@@ -60,23 +59,68 @@ namespace OHOS
 \r
     bool TraingCardPresenter::OnDrag(UIView &view, const DragEvent &event)\r
     {\r
-\r
-        if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP)\r
+        uint8_t viewid = TraingCardView::GetInstance()->GetCurrentPageId();\r
+        // const char *viewid = view.GetViewId();\r
+        if (viewid == Control_Card::DATA)\r
         {\r
-            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL);\r
+            if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP)\r
+            {\r
+                NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGDETAIL);\r
+            }\r
+            return true;\r
         }\r
         UNUSED(view);\r
-        return true;\r
+        return false;\r
     }\r
 \r
     bool TraingCardPresenter::OnClick(UIView &view, const ClickEvent &event)\r
     {\r
-        // 根据控件id查找是哪个控件触发了点击回调\r
-        // if (strcmp(view.GetViewId(), BUTTONSTOP) == 0)\r
-        // {\r
-        //     NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL);\r
-        //     NativeAbility::GetInstance().\r
-        // }\r
+        // 点击暂停按键\r
+        if (strcmp(view.GetViewId(), BUTTONSTOP) == 0)\r
+        {\r
+            // 开始状态\r
+            if (TraingModel::GetInstance()->GetSportState() == ExerciseState::Start)\r
+            {\r
+                TrainingControlView::GetInstance()->GetLabel()->SetText("继续");\r
+                TrainingControlView::GetInstance()->GetButton()->SetImageSrc(SPORT_CONTINUE_IMAGE, nullptr);\r
+                // 设置为暂停状态\r
+                TraingModel::GetInstance()->SetSportState(ExerciseState::Pause);\r
+                return true;\r
+            }\r
+            // 暂停状态\r
+            if (TraingModel::GetInstance()->GetSportState() == ExerciseState::Pause)\r
+            {\r
+                TrainingControlView::GetInstance()->GetLabel()->SetText("暂停");\r
+                TrainingControlView::GetInstance()->GetButton()->SetImageSrc(SPORT_PAUSE_IMAGE, nullptr);\r
+                // 设置为开始状态\r
+                TraingModel::GetInstance()->SetSportState(ExerciseState::Start);\r
+                return true;\r
+            }\r
+        }\r
+        // 点击结束按键\r
+        if (strcmp(view.GetViewId(), BUTTONEND) == 0)\r
+        {\r
+            // 弹窗显示是否结束\r
+        }\r
         return true;\r
     }\r
+\r
+    // 计时器更新\r
+    void TraingCardPresenter::ModifiesTime()\r
+    {\r
+        std ::string TimeStr = TraingModel::GetInstance()->DisplayMotionDuration();\r
+        if (TimeStr.empty())\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingModel::GetInstance()->DisplayMotionDuration() nullptr");\r
+            return;\r
+        }\r
+        if (TrainingControlView::GetInstance()->GetTimeLabel() != nullptr)\r
+        {\r
+            TrainingControlView::GetInstance()->GetTimeLabel()->SetText(TimeStr.c_str());\r
+        }\r
+        if (TrainingDataView::GetInstance()->GetTimeLabel() != nullptr)\r
+        {\r
+            TrainingDataView::GetInstance()->GetTimeLabel()->SetText(TimeStr.c_str());\r
+        }\r
+    }\r
 }\r
index fb89d38..b3007a5 100644 (file)
 #include "components/ui_label.h"\r
 #include "components/ui_label_ext.h"\r
 #include "font/ui_font.h"\r
+\r
+#include "traing/include/TraingModel.h"\r
+\r
+extern "C"\r
+{\r
+    void InitTraingTimer();\r
+    void DisableTraingTimer();\r
+}\r
+\r
 namespace OHOS\r
 {\r
     static const uint16_t LABEL_FONT_SIZE = 200;\r
@@ -24,17 +33,24 @@ namespace OHOS
     TraingCardView::TraingCardView()\r
     {\r
         g_pTraingCardView = this;\r
+        // 开启计时器\r
+        InitTraingTimer();\r
+        // 设置运动状态为开始\r
+        TraingModel::GetInstance()->SetSportState(ExerciseState::Start);\r
     }\r
 \r
     TraingCardView::~TraingCardView()\r
     {\r
         DeInit();\r
         g_pTraingCardView = nullptr;\r
+        // 关闭计时器\r
+        DisableTraingTimer();\r
+        // 设置运动状态为结束\r
+        TraingModel::GetInstance()->SetSportState(ExerciseState::End);\r
     }\r
 \r
     TraingCardView *TraingCardView::GetInstance()\r
     {\r
-\r
         return g_pTraingCardView;\r
     }\r
 \r
@@ -51,12 +67,14 @@ namespace OHOS
         }\r
 \r
         InitControlPage();\r
+        InitDataPage();\r
         InitMusicPage();\r
 \r
         swipe_->Add(ControlView);\r
+        swipe_->Add(DataVIew);\r
         swipe_->Add(MusicView);\r
 \r
-        swipe_->SetCurrentPage(Control_Card::MUSIC);\r
+        swipe_->SetCurrentPage(Control_Card::CONTROL);\r
 \r
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitPage over");\r
     }\r
@@ -76,6 +94,12 @@ namespace OHOS
             delete ControlView;\r
             ControlView = nullptr;\r
         }\r
+        if (DataVIew != nullptr)\r
+        {\r
+            DataVIew->RemoveAll();\r
+            delete DataVIew;\r
+            DataVIew = nullptr;\r
+        }\r
         if (MusicView != nullptr)\r
         {\r
             MusicView->RemoveAll();\r
@@ -94,7 +118,17 @@ namespace OHOS
         }\r
         return ControlView;\r
     }\r
-    UICardPage *TraingCardView::InitDataPage(void) {}\r
+    UICardPage *TraingCardView::InitDataPage(void)\r
+    {\r
+        DataVIew = new TrainingDataView();\r
+        DataVIew->PreLoad();\r
+        if (DataVIew == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DataVIew new fail");\r
+            return nullptr;\r
+        }\r
+        return DataVIew;\r
+    }\r
     UICardPage *TraingCardView::InitMusicPage(void)\r
     {\r
         MusicView = new PlayersView();\r
@@ -160,4 +194,8 @@ namespace OHOS
         return;\r
     }\r
 \r
+    int TraingCardView::GetCurrentPageId()\r
+    {\r
+        return swipe_->GetCurrentPage();\r
+    }\r
 }\r
index fbe032d..a4e665a 100644 (file)
@@ -67,34 +67,14 @@ namespace OHOS
     }
 
     /******************************************************************************************************/
-    void TrainingControlView::SetLabel()
+    UILabelExt *TrainingControlView::GetLabel()
     {
-#if 0
-        if (TraingCardPresenter::GetInstance()->test == "继续")
-        {
-            labelstop->SetText("继续");
-        }
-        else
-        {
-            labelstop->SetText("暂停");
-        }
-#endif
+        return labelstop;
     }
 
-    void TrainingControlView::SetButton()
+    UIButton *TrainingControlView::GetButton()
     {
-#if 0
-        if (TraingCardPresenter::GetInstance()->test == "继续")
-        {
-            // buttonStop->SetViewId(BUTTONCONTINUE);
-            buttonStop->SetImageSrc(SPORT_CONTINUE_IMAGE, nullptr);
-        }
-        if (TraingCardPresenter::GetInstance()->test == "暂停")
-        {
-            // buttonStop->SetViewId(BUTTONPAUSE);
-            buttonStop->SetImageSrc(SPORT_PAUSE_IMAGE, nullptr);
-        }
-#endif
+        return buttonStop;
     }
     /******************************************************************************************************/
 
@@ -152,4 +132,9 @@ namespace OHOS
     }
 
     void TrainingControlView::UnLoad(void) {}
+
+    UILabelExt *TrainingControlView::GetTimeLabel()
+    {
+        return labeltimer;
+    }
 }
index e69de29..b43cdd1 100644 (file)
@@ -0,0 +1,140 @@
+
+#include "traing/training_card/include/TrainingDataView.h"
+#include "traing/training_card/include/TraingCardView.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 <ui_scroll_view.h>
+#include "components/ui_button.h"
+#include "traing/include/TraingModel.h"
+#include "traing/Training_UiConfig.h"
+
+namespace OHOS
+{
+
+    static TrainingDataView *g_pTrainingDataView{nullptr};
+
+    TrainingDataView::TrainingDataView()
+    {
+        SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
+        g_pTrainingDataView = this;
+    }
+
+    TrainingDataView::~TrainingDataView()
+    {
+        RemoveAll();
+        DeInit();
+        g_pTrainingDataView = nullptr;
+    }
+
+    TrainingDataView *TrainingDataView::GetInstance()
+    {
+        return g_pTrainingDataView;
+    }
+
+    /* InitView:初始化界面*/
+    void TrainingDataView ::InitView()
+    {
+        // 初始化Image
+        TraingModel::GetInstance()->InitImageView(image_progress, 13, 13, 440, 386, "image1", PROGRESS_IMAGE);
+        TraingModel::GetInstance()->InitImageView(image_arrows, 208, 297, 20, 20, "image2", ARROWS_IMAGE);
+        TraingModel::GetInstance()->InitImageView(image_lowIntensity, 98, 314, 270, 20, "image3", SPORT_STRENGTH_IMAGE);
+        TraingModel::GetInstance()->InitImageView(image_iconup, 225, 396, 16, 10, "image4", INCO_UP_IMAGE);
+        TraingModel::GetInstance()->InitImageView(image_iconpoint, 193, 421, 80, 20, "image5", DATA_POINT_IMAGE);
+        Add(image_progress);
+        Add(image_arrows);
+        Add(image_lowIntensity);
+        Add(image_iconup);
+        Add(image_iconpoint);
+        // 初始化Lable
+        TraingModel::GetInstance()->InitLabel(curtimelabel, 185, 60, 90, 35, "label1", "23:54", DEFAULT_VECTOR_FONT_FILENAME, 40);
+        TraingModel::GetInstance()->InitLabel(sportlabel, 158, 120, 150, 35, "label2", "跳绳运动中", DEFAULT_VECTOR_FONT_FILENAME, 30);
+        TraingModel::GetInstance()->InitLabel(timerlabel, 90, 175, 60, 40, "label3", "00:00:00", DEFAULT_VECTOR_FONT_FILENAME, 80);
+        TraingModel::GetInstance()->InitLabel(heartlabel, 150, 276, 60, 40, "label4", "144", DEFAULT_VECTOR_FONT_FILENAME, 23);
+        TraingModel::GetInstance()->InitLabel(strengthlabel, 167, 350, 60, 40, "label4", "中等强度", DEFAULT_VECTOR_FONT_FILENAME, 26);
+        Add(curtimelabel);
+        Add(sportlabel);
+        Add(timerlabel);
+        Add(heartlabel);
+        Add(strengthlabel);
+        //  初始化Button
+        TraingModel::GetInstance()->InitButton(buttonNote, 275, 350, 26, 26, BUTTONNOTE);
+        // Set additional property
+        buttonNote->SetImageSrc(NOTE_IMAGE, NOTE_IMAGE);
+        buttonNote->SetOnClickListener(static_cast<UIView::OnClickListener *>(TraingCardPresenter::GetInstance()));
+        Add(buttonNote);
+    }
+
+    /* DeInit:删除组件 */
+    void TrainingDataView::DeInit()
+    {
+        RemoveAll();
+        if (curtimelabel != nullptr)
+        {
+            curtimelabel = nullptr;
+        }
+        if (sportlabel != nullptr)
+        {
+            delete sportlabel;
+            sportlabel = nullptr;
+        }
+        if (timerlabel != nullptr)
+        {
+            delete timerlabel;
+            timerlabel = nullptr;
+        }
+        if (heartlabel != nullptr)
+        {
+            delete heartlabel;
+            heartlabel = nullptr;
+        }
+        if (strengthlabel != nullptr)
+        {
+            delete strengthlabel;
+            strengthlabel = nullptr;
+        }
+        // 删除button
+        if (buttonNote != nullptr)
+        {
+            delete buttonNote;
+            buttonNote = nullptr;
+        }
+
+        // 删除Image
+        if (image_lowIntensity != nullptr)
+        {
+            delete image_lowIntensity;
+            image_lowIntensity = nullptr;
+        }
+        if (image_iconup != nullptr)
+        {
+            delete image_iconup;
+            image_iconup = nullptr;
+        }
+        if (image_iconpoint != nullptr)
+        {
+            delete image_iconpoint;
+            image_iconpoint = nullptr;
+        }
+    }
+
+    void TrainingDataView::PreLoad(void)
+    {
+        if (!viewiInitStatus)
+        {
+            InitView();
+            viewiInitStatus = true;
+        }
+    }
+
+    void TrainingDataView::UnLoad(void) {}
+
+    UILabelExt *TrainingDataView::GetTimeLabel()
+    {
+        return timerlabel;
+    }
+
+}