TrainingSlice适配按键事件 588/2
authorCaisking <3449750381@qq.com>
Fri, 26 Jul 2024 04:04:48 +0000 (12:04 +0800)
committerCaisking <3449750381@qq.com>
Fri, 26 Jul 2024 04:04:48 +0000 (12:04 +0800)
51 files changed:
code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingEnddataPresenter.h
code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h
code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingNomalPresenter.h
code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingNomalView.h
code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingPresenter.h
code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingSetPresenter.h
code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingSetView.h
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingEnddataPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingEnddataView.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingNomalPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingNomalView.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetView.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingView.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TrainingDataView.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/Training_CardPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/include/TraingAquaticPresenter.h
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/src/TraingAquaticModel.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/src/TraingAquaticPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/src/TraingAquaticView.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/include/TraingBallPresenter.h
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/src/TraingBallPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/src/TraingBallView.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_dance/include/TraingDancePresenter.h
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_dance/src/TraingDancePresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_dance/src/TraingDanceView.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/include/TraingFitnessPresenter.h
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/src/TraingFitnessPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/src/TraingFitnessView.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ice/include/TraingIcePresenter.h
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ice/src/TraingIcePresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ice/src/TraingIceView.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_limit/include/TraingLimitPresenter.h
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_limit/src/TraingLimitPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_limit/src/TraingLimitView.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/include/TraingMoreModel.h
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/include/TraingMorePresenter.h
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/src/TraingMoreModel.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/src/TraingMorePresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/src/TraingMoreView.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/include/TraingOtherPresenter.h
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_other/src/TraingOtherView.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_rest/include/TraingRestPresenter.h
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_rest/src/TraingRestPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traing/training_list_rest/src/TraingRestView.cpp
code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordPresenter.h
code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordPresenter.cpp

index 197d95d..9f2c02f 100644 (file)
@@ -1,3 +1,9 @@
+/***
+ * @Date: 2024-07-05 18:15:38
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-07-25 18:17:08
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingEnddataPresenter.h
+ */
 /***
  * @Date: 2024-04-15 10:55:58
  * @LastEditors: Caisking 3449750381@qq.com
@@ -28,6 +34,7 @@ namespace OHOS
         void OnPause() override;
         void OnResume() override;
         void OnStop() override;
+        void NavigateBack(); // 返回函数
         static TraingEnddataPresenter *GetInstance();
 
     private:
index 1599148..40b8501 100644 (file)
@@ -164,6 +164,11 @@ namespace OHOS
         VERY_HIGH_INTENSITY
     };
 
+    enum ENTEYTYPE
+    {
+        MAIN_ENTER = 0,
+        APPLIST_ENTER,
+    };
     struct SportData
     {
         uint32 starttime;         // 开始时间时间戳
@@ -297,7 +302,7 @@ namespace OHOS
         int CalculateAverageHeartRate(int newHeartRate);
         /*显示心率计算*/
         int CalculateFilteredHeartRate(int newHeartRate);
-        
+
         int Averageheartrate(int newHeartRate);
 
         /*保存训练记录到json文件*/
@@ -327,6 +332,10 @@ namespace OHOS
         /*保存数据*/
         void RecordSportData();
 
+        /*进入训练方式*/
+        void SetEntryType(ENTEYTYPE type);
+        ENTEYTYPE GetEntryType();
+
     private:
         TraingModel(const TraingModel &) = delete;
         TraingModel &operator=(const TraingModel &) = delete;
@@ -337,6 +346,8 @@ namespace OHOS
         ExerciseState sportState_ = ExerciseState::General;      // 训练状态
         ExerciseTag sportTagType_ = ExerciseTag::UNKNOW;         // 训练目标类型
 
+        ENTEYTYPE entey_type = ENTEYTYPE::MAIN_ENTER; // 进入方式
+
         int sportTag_ = 0; // 训练目标
         int freq = 0;      // 训练发送数据频率
 
index cb7e898..cc6134c 100644 (file)
@@ -1,9 +1,3 @@
-/***
- * @Date: 2024-04-15 10:55:58
- * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-04-17 14:18:05
- * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingNomalPresenter.h
- */
 
 #ifndef _TraingNomal_PRESENTER_H
 #define _TraingNomal_PRESENTER_H
@@ -28,6 +22,7 @@ namespace OHOS
         void OnPause() override;
         void OnResume() override;
         void OnStop() override;
+        void NavigateBack();
 
         static TraingNomalPresenter *GetInstance();
 
index 5c7c58c..3930b10 100644 (file)
@@ -1,4 +1,10 @@
 /*** 
+ * @Date: 2024-04-15 10:55:58
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-07-25 17:40:40
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingNomalView.h
+ */
+/***
  * @Date: 2024-04-15 10:55:58
  * @LastEditors: Caisking 3449750381@qq.com
  * @LastEditTime: 2024-04-23 20:29:54
@@ -51,6 +57,7 @@ namespace OHOS
 
         void InitList();
         void PreLoad(void);
+        void UpdateTraingTag(); // 更新训练目标
 
     private:
         UIView::OnDragListener *draglistener{nullptr};
index 50dc637..db1adc5 100644 (file)
@@ -1,3 +1,9 @@
+/*** 
+ * @Date: 2024-04-15 10:55:58
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-07-25 18:44:38
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingPresenter.h
+ */
 /***
  * @Date: 2024-04-15 10:55:58
  * @LastEditors: Caisking 3449750381@qq.com
@@ -28,6 +34,7 @@ namespace OHOS
         void OnPause() override;
         void OnResume() override;
         void OnStop() override;
+        void NavigateBack();
 
         static TraingPresenter *GetInstance();
 
index 9d43f68..b963678 100644 (file)
@@ -1,3 +1,9 @@
+/***
+ * @Date: 2024-07-24 09:45:49
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-07-25 17:28:43
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingSetPresenter.h
+ */
 /***
  * @Date: 2024-04-15 10:55:58
  * @LastEditors: Caisking 3449750381@qq.com
@@ -42,6 +48,7 @@ namespace OHOS
         const char *GetButtonIdFromCard(int cardID);
         int GetTagFromCard(int cardID);
         ExerciseTag GetExerciseTagFromCard(int cardID);
+        void NavigateBack();
 
     private:
         // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承;
index a508bd9..edbe7dc 100644 (file)
@@ -65,6 +65,7 @@ namespace OHOS
         bool ChangeSetDurationView(int16_t thisview);
         bool ClickFunc(int16_t interface);
         void ChangeView(int16_t hideView, int16_t showView);
+    
         void SetCurrentViewId(int viewId)
         {
             CurrentViewId = viewId;
index e19a922..2546414 100644 (file)
@@ -1,21 +1,3 @@
-/***
- * @Date: 2024-06-12 11:24:16
- * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-06-13 15:08:56
- * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingEnddataPresenter.cpp
- */
-/***
- * @Date: 2024-04-15 14:19:47
- * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-06-11 15:34:57
- * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingEnddataPresenter.cpp
- */
-/***
- * @Date: 2024-04-15 14:19:47
- * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-04-17 14:59:43
- * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingEnddataPresenter.cpp
- */
 #include "AppViewIDs.h"
 #include "components/ui_label_ext.h"
 #include "ui_resource_string.h"
 
 namespace OHOS
 {
-
     // 当前Presenter属性实例化的内存指针
     static TraingEnddataPresenter *g_pTraingEnddataPresenter = nullptr;
 
     TraingEnddataPresenter::TraingEnddataPresenter()
     {
-
         g_pTraingEnddataPresenter = this;
     }
 
     TraingEnddataPresenter::~TraingEnddataPresenter()
     {
-
         g_pTraingEnddataPresenter = nullptr;
     }
 
     TraingEnddataPresenter *TraingEnddataPresenter::GetInstance()
     {
-
         return g_pTraingEnddataPresenter;
     }
 
     void TraingEnddataPresenter::OnStart()
     {
-
         Presenter<TraingEnddataView>::OnStart();
     }
 
-    void TraingEnddataPresenter::OnPause(void)
+    void TraingEnddataPresenter::OnPause()
     {
-
         Presenter<TraingEnddataView>::OnPause();
     }
 
-    void TraingEnddataPresenter::OnResume(void)
+    void TraingEnddataPresenter::OnResume()
     {
-
         Presenter<TraingEnddataView>::OnResume();
     }
 
-    void TraingEnddataPresenter::OnStop(void)
+    void TraingEnddataPresenter::OnStop()
     {
-
         Presenter<TraingEnddataView>::OnStop();
     }
 
+    void TraingEnddataPresenter::NavigateBack()
+    {
+        uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();
+
+        // 根据前一界面切换
+        if (preSlice == VIEW_TRAINING_RECORD)
+        {
+            NativeAbility::GetInstance().Back(TransitionType::TRANSITION_ZOOM);
+        }
+        else if (preSlice == VIEW_TRAININGCRAD)
+        {
+            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE, TransitionType::TRANSITION_ZOOM);
+        }
+    }
+
     bool TraingEnddataPresenter::OnDrag(UIView &view, const DragEvent &event)
     {
-        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
+        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT &&
+            event.GetDeltaX() > X_DRAG_OFFSET &&
+            event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))
         {
-            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAINING_RECORD);
+            NavigateBack();
         }
         UNUSED(view);
         return true;
@@ -90,23 +81,23 @@ namespace OHOS
 
     bool TraingEnddataPresenter::OnClick(UIView &view, const ClickEvent &event)
     {
-        // 根据控件id查找是哪个控件触发了点击回调
-        if (strcmp(view.GetViewId(), BUTTONBACK) == 0)
+        if (view.GetViewId() == BUTTONBACK)
         {
-            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE);
+            NavigateBack();
         }
         return true;
     }
+
     bool TraingEnddataPresenter::OnKeyAct(UIView &view, const KeyEvent &event)
     {
         unsigned short keyID = event.GetKeyId();
         unsigned short keyState = event.GetState();
+
         // 如果是power键,且是亮屏状态,按键释放就返回上一级
         if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)
         {
-            // 回退
-            NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_ZOOM);
+            NavigateBack();
         }
         return true;
     }
-}
+}
\ No newline at end of file
index 4e4efdd..184885e 100644 (file)
@@ -360,7 +360,14 @@ namespace OHOS
 
         printf("TraingEnddataView data initialization complete.\r\n");
     }
-
+    // 设置按键监听
+    static void SetKeyActListener()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener");
+        // 增加按键监听
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingEnddataPresenter::GetInstance();
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);
+    }
     void TraingEnddataView::OnStart()
     {
         container_ = new UIViewGroup();
@@ -386,10 +393,7 @@ namespace OHOS
         PreLoad();
         InitData();
         RootView::GetInstance()->Add(container_);
-
-        // 增加按键监听
-        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingEnddataPresenter::GetInstance();
-        RootView::GetInstance()->SetOnKeyActListener(keyactListener);
+        SetKeyActListener();
     }
 
     void TraingEnddataView::OnSetUpView()
@@ -409,6 +413,10 @@ namespace OHOS
     void TraingEnddataView::OnStop()
     {
         View<TraingEnddataPresenter>::OnStop();
+
+
+        RootView::GetInstance()->ClearOnKeyActListener();
+        //FocusManager::GetInstance()->ClearFocus();
         RootView::GetInstance()->RemoveAll();
         return;
     }
index 06f1576..d93cb4b 100644 (file)
@@ -419,13 +419,12 @@ namespace OHOS
         }
 
         sportdata->heart = cyweeInfo->hrs;
-
+        SetIntensity(sportdata->heart); // 设置训练强度
         if (cyweeInfo->hrs > 50)
         {
             // sportdata->heart = CalculateFilteredHeartRate(cyweeInfo->hrs);   // 处理显示心率
             // sportdata->avgheart = CalculateAverageHeartRate(cyweeInfo->hrs); // 处理正常的平均心率
             sportdata->avgheart = Averageheartrate(sportdata->heart);
-            SetIntensity(sportdata->heart); // 设置训练强度
         }
 
         // 达到最高心率进行心率提醒弹窗
@@ -836,7 +835,7 @@ namespace OHOS
             totalHeartRate = newHeartRate;
         }
         totalHeartRate = (totalHeartRate + newHeartRate) / 2;
-        
+
         return totalHeartRate;
     }
     // 设置训练目标类型以及训练目标
@@ -873,6 +872,7 @@ namespace OHOS
         // 将 heart 转换为 double 以避免整数除法
         double heartRateAsDouble = static_cast<double>(heart);
         double intensityPercentage = (heartRateAsDouble / (double)maxHeartRate) * 100;
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "intensityPercentage is %d", intensityPercentage);
 
         if (intensityPercentage < LOW_INTENSITY_THRESHOLD)
         {
@@ -1116,7 +1116,16 @@ namespace OHOS
         return true;
         // delete data;
     }
-
+    /*设置进入方式*/
+    void TraingModel::SetEntryType(ENTEYTYPE type)
+    {
+        entey_type = type;
+    }
+    /*获取进入方式*/
+    ENTEYTYPE TraingModel::GetEntryType()
+    {
+        return entey_type;
+    }
     /*设置开启方式*/
     void TraingModel::SetSportOpenWay(bool way)
     {
index 628e33e..140290d 100644 (file)
@@ -8,12 +8,12 @@
 #include "custom_utils.h"\r
 #include "common/key_code.h"\r
 \r
-\r
 #include <iostream>\r
 #include <chrono>\r
 #include <thread>\r
 #include "traing/include/TraingNomalPresenter.h"\r
 #include "traing/training_card/include/TraingCardPresenter.h"\r
+#include "MainModel.h"\r
 // #include "TraingNomalView.h"\r
 \r
 namespace OHOS\r
@@ -63,14 +63,26 @@ namespace OHOS
 \r
         Presenter<TraingNomalView>::OnStop();\r
     }\r
+    // 回退逻辑\r
+    void TraingNomalPresenter::NavigateBack()\r
+    {\r
+        /*\r
+            准备训练界面进入:\r
+            1.[主界面] 进入\r
+            2.[traing] 进入\r
+            3.[更多]->[具体训练项]进入\r
+            4.[设置训练目标]进入 {不返回}\r
+        */\r
+        NativeAbility::GetInstance().Back(TransitionType::TRANSITION_ZOOM);\r
+    }\r
     bool TraingNomalPresenter::OnDrag(UIView &view, const DragEvent &event)\r
     {\r
-        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)\r
+        UNUSED(view);\r
+        if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) &&\r
+            (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY()))))\r
         {\r
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"TraingNomalPresenter OnDrag!\r\rn");\r
-            NativeAbility::GetInstance().Back(); // 返回函数\r
+            NavigateBack();\r
         }\r
-        UNUSED(view);\r
         return true;\r
     }\r
 \r
@@ -79,11 +91,14 @@ namespace OHOS
         // 根据控件id查找是哪个控件触发了点击回调\r
         if (strcmp(view.GetViewId(), BUTTONSET) == 0)\r
         {\r
+            // 训练准备 -> 训练设置\r
             NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGSET);\r
         }\r
         if (strcmp(view.GetViewId(), BUTTONGO) == 0)\r
         {\r
+            // 开始训练 ->不返回\r
             NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGCRAD);\r
+\r
             // 获取运动项目\r
             ExerciseClass type = TraingModel::GetInstance()->GetSportId();\r
             // 开启对应的运动\r
@@ -100,8 +115,7 @@ namespace OHOS
         // 如果是power键,且是亮屏状态,按键释放就返回上一级\r
         if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)\r
         {\r
-            // 回退\r
-            NativeAbility::GetInstance().Back();\r
+            NavigateBack();\r
         }\r
         return true;\r
     }\r
index fd263b4..aba0611 100644 (file)
@@ -53,6 +53,7 @@ namespace OHOS
         // Set additional property
         buttonGo_->SetImageSrc(GO_1_IMAGE, GO_1_IMAGE);
 
+        // 显示设置目标
         InitButtonExt(buttonSet_, 160, 370, 150, 50, BUTTONSET, STR_SET_GOALS, 30);
         buttonSet_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); // 设置为透明按键
         buttonSet_->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
@@ -82,12 +83,7 @@ namespace OHOS
             delete buttonSet_;
             buttonSet_ = nullptr;
         }
-        if (container_ != nullptr)
-        {
-            container_->RemoveAll();
-            delete container_;
-            container_ = nullptr;
-        }
+
     }
 
     void TraingNomalView::PreLoad(void)
@@ -98,6 +94,14 @@ namespace OHOS
             viewiInitStatus = true;
         }
     }
+    // 设置按键监听
+    static void SetKeyActListener()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener");
+        // 增加按键监听
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingNomalPresenter::GetInstance();
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);
+    }
     void TraingNomalView::OnStart()
     {
         container_ = new UIViewGroup();
@@ -122,12 +126,12 @@ namespace OHOS
 
         PreLoad();
         RootView::GetInstance()->Add(container_);
-
-        // 增加按键监听
-        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingNomalPresenter::GetInstance();
-        RootView::GetInstance()->SetOnKeyActListener(keyactListener);
+        SetKeyActListener();
     }
 
+    // 更新训练目标 [考虑 通用目标 特殊目标]
+    void TraingNomalView::UpdateTraingTag() {}
+
     void TraingNomalView::OnSetUpView()
     {
 
@@ -146,6 +150,9 @@ namespace OHOS
     {
         View<TraingNomalPresenter>::OnStop();
         RootView::GetInstance()->RemoveAll();
+
+        RootView::GetInstance()->ClearOnKeyActListener();
+        //FocusManager::GetInstance()->ClearFocus();
         return;
     }
 }
index 4bc39d0..8ee5565 100644 (file)
@@ -61,6 +61,12 @@ namespace OHOS
     {
         Presenter<TraingView>::OnStop();
     }
+    // 回退函数 [ Slice 的 traingview {右滑只能回到applist}]
+    void TraingPresenter::NavigateBack()
+    {
+        NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_ZOOM);
+        NativeAbility::GetInstance().ClearSliceIdStack(); // 清空所有SLiceId栈元素
+    }
     bool TraingPresenter::OnDrag(UIView &view, const DragEvent &event)
     {
         return true;
@@ -69,10 +75,7 @@ namespace OHOS
     {
         UNUSED(view);
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
-        {
-            // NativeAbility::GetInstance().Back();
-            NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST);
-        }
+            NavigateBack();
         return true;
     }
 
@@ -108,11 +111,10 @@ namespace OHOS
         unsigned short keyID = event.GetKeyId();
         unsigned short keyState = event.GetState();
         // 如果是power键,且是亮屏状态,按键释放就返回上一级
-        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)
-        {
-            // 回退
-            NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_ZOOM);
-        }
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) &&
+            keyState == 0 && uapi_get_screen_state() == 0)
+            NavigateBack();
+
         return true;
     }
 }
index 91af3e3..676be20 100644 (file)
@@ -69,54 +69,50 @@ namespace OHOS
 \r
         Presenter<TraingSetView>::OnStop();\r
     }\r
-\r
-    bool TraingSetPresenter::OnDrag(UIView &view, const DragEvent &event)\r
+    void TraingSetPresenter::NavigateBack()\r
     {\r
-        return true;\r
+        int CardID = TraingSetView::GetInstance()->GetCurrentViewId();\r
+        // 不在设置页面 返回设置列表\r
+        if (CardID != SET_VIEW)\r
+        {\r
+            TraingSetView::GetInstance()->ChangeView(CardID, SET_VIEW);\r
+        }\r
+        else\r
+        {\r
+            NativeAbility::GetInstance().Back();\r
+        }\r
     }\r
     // 增加按键事件\r
     bool TraingSetPresenter::OnKeyAct(UIView &view, const KeyEvent &event)\r
     {\r
-        int CardID = TraingSetView::GetInstance()->GetCurrentViewId();\r
         unsigned short keyID = event.GetKeyId();\r
         unsigned short keyState = event.GetState();\r
         // 如果是power键,且是亮屏状态,按键释放就返回上一级\r
         if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)\r
         {\r
-            // 不在设置页面\r
-            if (CardID != SET_VIEW)\r
-            {\r
-                TraingSetView::GetInstance()->ChangeView(CardID, SET_VIEW);\r
-            }\r
-            else\r
-            {\r
-                NativeAbility::GetInstance().Back();\r
-            }\r
+            NavigateBack();\r
         }\r
         return true;\r
     }\r
+    bool TraingSetPresenter::OnDrag(UIView &view, const DragEvent &event)\r
+    {\r
+        return true;\r
+    }\r
     bool TraingSetPresenter::OnDragEnd(UIView &view, const DragEvent &event)\r
     {\r
         int CardID = TraingSetView::GetInstance()->GetCurrentViewId();\r
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)\r
         {\r
-            // 不在设置页面\r
-            if (CardID != SET_VIEW)\r
-            {\r
-                TraingSetView::GetInstance()->ChangeView(CardID, SET_VIEW);\r
-            }\r
-            else\r
-            {\r
-                NativeAbility::GetInstance().Back();\r
-            }\r
+            NavigateBack();\r
         }\r
         UNUSED(view);\r
         return true;\r
     }\r
-\r
+    /* --------------------------------- 设置目标项处理 -------------------------------- */\r
     bool TraingSetPresenter::OnClick(UIView &view, const ClickEvent &event)\r
     {\r
         int CardID = TraingSetView::GetInstance()->GetCurrentViewId();\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CardID[%d]", CardID);\r
         switch (CardID)\r
         {\r
         case SET_VIEW:\r
@@ -145,19 +141,23 @@ namespace OHOS
             {\r
                 // 获取训练目标值\r
                 int tag = GetTagFromCard(CardID);\r
+                // 配置训练项\r
                 TraingModel::GetInstance()->SetSportTag(GetExerciseTagFromCard(CardID), tag);\r
 #if TAGTEST\r
                 TraingModel::GetInstance()->SetSportTag(ExerciseTag::STEP, 10); // 测试\r
 #endif\r
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"GetButtonIdFromCard:%d tag:%d \r\n", CardID, tag);\r
-                // 切换到训练卡片\r
-                NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGCRAD);\r
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetButtonIdFromCard:%d tag:%d \r\n", CardID, tag);\r
+\r
+                // 回退到训练准备\r
+                NativeAbility::GetInstance().Back();\r
+#if 0\r
                 // 获取训练项目\r
                 ExerciseClass type = TraingModel::GetInstance()->GetSportId();\r
                 // 开启cywee\r
                 TraingCardPresenter::GetInstance()->OpenSensor(type);\r
                 // 设置为手表开启运动\r
                 TraingModel::GetInstance()->SetSportOpenWay(false);\r
+#endif\r
             }\r
             break;\r
         default:\r
index 7aae6a1..58abcb7 100644 (file)
@@ -374,6 +374,14 @@ namespace OHOS
             viewiInitStatus = true;\r
         }\r
     }\r
+    // 设置按键监听\r
+    static void SetKeyActListener()\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener");\r
+        // 增加按键监听\r
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingSetPresenter::GetInstance();\r
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);\r
+    }\r
     void TraingSetView::OnStart()\r
     {\r
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TraingSetView::OnStart");\r
@@ -402,6 +410,7 @@ namespace OHOS
         group->SetDraggable(true);\r
 \r
         PreLoad();\r
+        SetKeyActListener();\r
         // RootView::GetInstance()->Add(SetTagScrollView[SET_VIEW]);\r
         // SetCurrentViewId(SET_VIEW); // 设置当前页面ID\r
     }\r
@@ -429,13 +438,10 @@ namespace OHOS
     {\r
         View<TraingSetPresenter>::OnStop();\r
 \r
-        if (container_ != nullptr)\r
-        {\r
-            container_->RemoveAll();\r
-            delete container_;\r
-            container_ = nullptr;\r
-        }\r
+\r
         group->RemoveAll();\r
+        RootView::GetInstance()->ClearOnKeyActListener();\r
+        //FocusManager::GetInstance()->ClearFocus();\r
         RootView::GetInstance()->RemoveAll();\r
         return;\r
     }\r
index 9f6440d..8d8f941 100644 (file)
@@ -1,5 +1,6 @@
 \r
 #include "traing/include/TraingView.h"\r
+#include "traing/include/TraingModel.h"\r
 #include <iostream>\r
 #include <string>\r
 namespace OHOS\r
@@ -50,6 +51,7 @@ namespace OHOS
     TraingView::TraingView()\r
     {\r
         g_pTraingView = this;\r
+        TraingModel::GetInstance()->SetEntryType(APPLIST_ENTER);\r
     }\r
 \r
     TraingView::~TraingView()\r
@@ -234,7 +236,14 @@ namespace OHOS
         InitView();\r
         return container_;\r
     }\r
-\r
+    // 设置按键监听\r
+    static void SetKeyActListener()\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener");\r
+        // 增加按键监听\r
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingPresenter::GetInstance();\r
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);\r
+    }\r
     void TraingView::OnStart()\r
     {\r
 #if 0\r
@@ -269,8 +278,7 @@ namespace OHOS
         RootView::GetInstance()->Add(container_);\r
         SetContainerView(container_);\r
         // 增加按键监听\r
-        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingPresenter::GetInstance();\r
-        RootView::GetInstance()->SetOnKeyActListener(keyactListener);\r
+        SetKeyActListener();\r
     }\r
 \r
     void TraingView::OnSetUpView()\r
@@ -288,6 +296,10 @@ namespace OHOS
     void TraingView::OnStop()\r
     {\r
         View<TraingPresenter>::OnStop();\r
+\r
+\r
+        RootView::GetInstance()->ClearOnKeyActListener();\r
+        //FocusManager::GetInstance()->ClearFocus();\r
         RootView::GetInstance()->RemoveAll();\r
         return;\r
     }\r
index e611044..e4085cd 100644 (file)
@@ -22,6 +22,7 @@
 #include "vibrator_service.h"\r
 #include <iomanip>\r
 #include <sstream>\r
+#include <unordered_map>\r
 \r
 extern "C" void do_cywee_service_check_msg(int cmd, int data[]);\r
 extern "C" void custom_VibratorFunc(OHOS::VibratorType vibratorType);\r
@@ -203,7 +204,7 @@ namespace OHOS
         {\r
             distanceStr = DEFAULT_DASH;\r
         }\r
-        // std::string durationStr = std::to_string(sportdata->duration);\r
+\r
         std::string heartStr = (sportdata->heart != 0) ? std::to_string(sportdata->heart) : DEFAULT_DASH;\r
         std::string stepsStr = (sportdata->steps != 0) ? std::to_string(sportdata->steps) : DEFAULT_DASH;\r
         std::string calorieStr = (sportdata->calories != 0) ? std::to_string(sportdata->calories) : DEFAULT_DASH;\r
@@ -215,69 +216,76 @@ namespace OHOS
         TrainingDetailView::GetInstance()->GetCalorieLabel()->SetText(calorieStr.c_str()); // 卡路里\r
         TrainingDetailView::GetInstance()->GetMileLabel()->SetText(distanceStr.c_str());   // 距离\r
         TrainingDetailView::GetInstance()->GetStepLabel()->SetText(stepsStr.c_str());      // 步数\r
-        // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[Calories: %s, Distance: %s, Steps: %s]", calorieStr.c_str(), distanceStr.c_str(), stepsStr.c_str());\r
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[Calories: %s, Distance: %s, Steps: %s Intensityid: %d]", calorieStr.c_str(), distanceStr.c_str(), stepsStr.c_str(), intensityid);\r
         // 释放sportdata内存\r
     }\r
-    /*刷新time和data*/\r
+    /*刷新 time 和 data */\r
     void TraingCardPresenter::Notify(void)\r
     {\r
+        // 未开启训练 直接退出\r
         if (TraingModel::GetInstance()->GetSportState() == ExerciseState::General)\r
             return;\r
+        // 刷新训练数据界面 时间\r
         TrainingDataView::GetInstance()->UpdataTime();\r
+        // 刷新训练数据界面 心率 卡路里 距离 步数 训练强度 目标完成度\r
         RefreshData();\r
     }\r
-\r
-    /* -------------------------------------------------------------------------- */\r
+    /* --------------------------------- 点击事件处理 --------------------------------- */\r
     bool TraingCardPresenter::OnClick(UIView &view, const ClickEvent &event)\r
     {\r
-        // 点击暂停按键\r
-        if (strcmp(view.GetViewId(), BUTTONSTOP) == 0)\r
+        const std::string viewId = view.GetViewId();\r
+\r
+        // 定义点击事件映射\r
+        static const std::unordered_map<std::string, std::function<void()>> actionMap = {\r
+            {BUTTONSTOP, [&]()\r
+             {\r
+                 auto currentState = TraingModel::GetInstance()->GetSportState();\r
+                 if (currentState == ExerciseState::Continue || currentState == ExerciseState::Start)\r
+                 {\r
+                     handlePauseState();\r
+                 }\r
+                 else if (currentState == ExerciseState::Pause)\r
+                 {\r
+                     handleContinueState();\r
+                 }\r
+             }},\r
+            {BUTTONEND, [&]()\r
+             {\r
+                 ControlSensor(ExerciseState::Pause);\r
+                 TraingCardView::GetInstance()->SetPopupViewStatus(EndPopup, true);\r
+                 TraingCardView::GetInstance()->RefreshEndView();\r
+             }},\r
+            {BUTTONEXIT, [&]()\r
+             {\r
+                 handleEndState();\r
+             }},\r
+            {BUTTONBACK, [&]()\r
+             {\r
+                 ControlSensor(ExerciseState::Continue);\r
+                 TraingCardView::GetInstance()->SetPopupViewStatus(EndPopup, false);\r
+             }},\r
+            {BUTTONWINOK, [&]()\r
+             {\r
+                 TraingCardView::GetInstance()->SetPopupViewStatus(GetTagPopup, false);\r
+                 TraingCardView::GetInstance()->GetAnimator()->Stop();\r
+             }},\r
+            {BUTTONNOTE, [&]()\r
+             {\r
+                 TraingCardView::GetInstance()->SetPopupViewStatus(HeartPopup, false);\r
+             }},\r
+        };\r
+\r
+        // 查找并执行对应的操作\r
+        auto it = actionMap.find(viewId);\r
+        if (it != actionMap.end())\r
         {\r
-            // 进行状态\r
-            if (TraingModel::GetInstance()->GetSportState() == ExerciseState::Continue || TraingModel::GetInstance()->GetSportState() == ExerciseState::Start)\r
-            {\r
-                handlePauseState();\r
-            }\r
-            // 暂停状态\r
-            else if (TraingModel::GetInstance()->GetSportState() == ExerciseState::Pause)\r
-            {\r
-                handleContinueState();\r
-            }\r
+            it->second(); // 执行操作\r
             return true;\r
         }\r
-        // 点击结束按键,弹窗显示\r
-        if (strcmp(view.GetViewId(), BUTTONEND) == 0)\r
-        {\r
-            ControlSensor(ExerciseState::Pause);\r
-            // 弹窗显示是否结束\r
-            TraingCardView::GetInstance()->SetPopupViewStatus(EndPopup, true);\r
-            TraingCardView::GetInstance()->RefreshEndView();\r
-        }\r
-        // 退出按键\r
-        if (strcmp(view.GetViewId(), BUTTONEXIT) == 0)\r
-        {\r
-            handleEndState();\r
-        }\r
-        // 返回按键\r
-        if (strcmp(view.GetViewId(), BUTTONBACK) == 0)\r
-        {\r
-            ControlSensor(ExerciseState::Continue);\r
-            TraingCardView::GetInstance()->SetPopupViewStatus(EndPopup, false);\r
-        }\r
-        // 达到目标退出按键\r
-        if (strcmp(view.GetViewId(), BUTTONWINOK) == 0)\r
-        {\r
-            TraingCardView::GetInstance()->SetPopupViewStatus(GetTagPopup, false);\r
-            TraingCardView::GetInstance()->GetAnimator()->Stop();\r
-        }\r
-        // 心率警告退出按键\r
-        if (strcmp(view.GetViewId(), BUTTONNOTE) == 0)\r
-        {\r
-            TraingCardView::GetInstance()->SetPopupViewStatus(HeartPopup, false);\r
-        }\r
-        return true;\r
-    }\r
 \r
+        return false; // 没有匹配的操作\r
+    }\r
+    /* -------------------------------- 协议发起运动处理 -------------------------------- */\r
     bool TraingCardPresenter::send_sport_cmd(training_ble *cmd)\r
     {\r
         if (cmd == nullptr)\r
@@ -365,13 +373,18 @@ namespace OHOS
         NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGENDDATA);\r
         return;\r
 #endif\r
+        // 是否达到训练目标\r
         if (TraingModel::GetInstance()->GetMomentum())\r
         {\r
+            // 进入训练详情\r
             NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGENDDATA);\r
+            NativeAbility::GetInstance().ClearSliceIdStack(); // 清空所有SLiceId栈元素\r
         }\r
         else\r
         {\r
+            // 进入训练记录\r
             NativeAbility::GetInstance().ChangeSlice(VIEW_TRAINING_RECORD);\r
+            NativeAbility::GetInstance().ClearSliceIdStack(); // 清空所有SLiceId栈元素\r
         }\r
     }\r
 \r
index 0a6c792..77987e0 100644 (file)
@@ -167,6 +167,5 @@ namespace OHOS
         // 将时间和日期转换为字符串
         std::string stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute);
         curtimelabel->SetText(stringtime.c_str());
-        // PRINT("curtimelabel!\r\n");
     }
 }
index 90e24bc..d1b958d 100644 (file)
@@ -1,3 +1,9 @@
+/***
+ * @Date: 2024-07-19 15:43:37
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-07-26 09:29:24
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/Training_CardPresenter.cpp
+ */
 /***
  * @Date: 2024-04-15 10:55:58
  * @LastEditors: Caisking 3449750381@qq.com
@@ -7,6 +13,7 @@
 
 #include "traing/training_card/include/Training_CardPresenter.h"
 #include "traing/training_card/include/Training_CardView.h"
+#include "traing/include/TraingModel.h"
 
 #include "AppViewIDs.h"
 #include "components/ui_label_ext.h"
@@ -18,6 +25,7 @@
 #include "wearable_log.h"
 #include "traing/include/TraingModel.h"
 #include "uicomponents/UIComponents.h"
+#include "MainModel.h"
 
 namespace OHOS
 {
@@ -57,6 +65,11 @@ namespace OHOS
         }
         // 快捷训练都属于健身类
         TraingModel::GetInstance()->SetSportType(Exercisetype::FITNESS);
+
+        // 配置主界面回退界面
+        MainModel::GetInstance().SetFromSetCardView(true);
+        MainModel::GetInstance().SetFromCardId(TRAINING);
+        TraingModel::GetInstance()->SetEntryType(MAIN_ENTER);
         return true;
     }
 } // namespace OHOS
\ No newline at end of file
index 9492706..ce02a9b 100644 (file)
@@ -1,4 +1,10 @@
 /*** 
+ * @Date: 2024-04-15 10:55:58
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-07-26 09:57:18
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/include/TraingAquaticPresenter.h
+ */
+/***
  * @Author: Caisking 3449750381@qq.com
  * @Date: 2024-03-19 17:37:18
  * @LastEditors: Caisking 3449750381@qq.com
@@ -18,8 +24,9 @@ namespace OHOS
     class TraingAquaticView;
     class TraingAquaticModel;
     class TraingAquaticPresenter : public Presenter<TraingAquaticView>,
-                                 public UIView::OnClickListener,
-                                 public UIView::OnDragListener
+                                   public UIView::OnClickListener,
+                                   public RootView::OnKeyActListener,
+                                   public UIView::OnDragListener
     {
     public:
         TraingAquaticPresenter();
@@ -37,6 +44,7 @@ namespace OHOS
         bool OnClick(UIView &view, const ClickEvent &event) override;
         bool OnDrag(UIView &view, const DragEvent &event) override;
         bool OnDragEnd(UIView &view, const DragEvent &event) override;
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
 
         TraingAquaticModel *p_TraingAquaticModel{nullptr};
     };
index b63f709..48f915a 100644 (file)
@@ -1,12 +1,4 @@
 
-/***
- * @Author: Caisking 3449750381@qq.com
- * @Date: 2024-03-29 15:51:45
- * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-03-29 17:56:44
- * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/src/TraingAquaticModel.cpp
- * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
- */
 
 #include "traing/training_list_aquatic/include/TraingAquaticModel.h"
 #include "common/image_cache_manager.h"
index 3a180ea..0486265 100644 (file)
@@ -1,33 +1,14 @@
-/***
- * @Author: Caisking 3449750381@qq.com
- * @Date: 2024-03-26 09:46:17
- * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-03-29 19:24:43
- * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/src/TraingAquaticPresenter.cpp
- * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
- */
-/***
- * @Author: Caisking 3449750381@qq.com
- * @Date: 2024-03-19 17:37:19
- * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-03-26 19:51:06
- * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/training_list_aquatic/src/TraingAquaticPresenter.cpp
- * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
- */
-/***
- * @Author: Caisking 3449750381@qq.com
- * @Date: 2024-03-19 17:37:19
- * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-03-26 14:23:32
- * @FilePath: /sdk/application/wearable/fd230app/nativeui/traing/src/TraingAquaticPresenter.cpp
- * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
- */
+
 
 #include "AppViewIDs.h"
 #include "components/ui_label_ext.h"
 #include "ui_resource_string.h"
 #include "NativeAbility.h"
 
+#include "KeyInputListener.h"
+#include "custom_utils.h"
+#include "common/key_code.h"
+
 #include <iostream>
 #include <chrono>
 #include <thread>
@@ -102,7 +83,7 @@ namespace OHOS
     {
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
         {
-            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE);
+            NativeAbility::GetInstance().Back();
         }
         UNUSED(view);
         return true;
@@ -119,10 +100,22 @@ namespace OHOS
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId);
         if (viewId < VIEW_MAX_INTER_APP)
         {
-            NativeAbility::GetInstance().ChangeSlice(viewId);
+            NativeAbility::GetInstance().EnterSlice(viewId);
             return true;
         }
         return false;
     }
+    bool TraingAquaticPresenter::OnKeyAct(UIView &view, const KeyEvent &event)
+    {
+        unsigned short keyID = event.GetKeyId();
+        unsigned short keyState = event.GetState();
+
+        // 如果是power键,且是亮屏状态,按键释放就返回上一级
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)
+        {
+            NativeAbility::GetInstance().Back();
+        }
+        return true;
+    }
 
 }
index dcdd3ff..db9f090 100644 (file)
@@ -44,7 +44,14 @@ namespace OHOS
     {
         p_TraingAquaticListAdapter->AddItem(item);
     }
-   void TraingAquaticView::InitView()
+    static void SetKeyActListener()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener");
+        // 增加按键监听
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingAquaticPresenter::GetInstance();
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);
+    }
+    void TraingAquaticView::InitView()
     {
         if (scrollView == nullptr)
         {
@@ -85,8 +92,10 @@ namespace OHOS
         TraingAquaticList->SetYScrollBarVisible(true); // 设置滑动滚动条
 
         // 增加表冠控制
-        //TraingAquaticList->SetRotateFactor(2);
-        //TraingAquaticList->RequestFocus();
+        TraingAquaticList->SetRotateFactor(2);
+        TraingAquaticList->RequestFocus();
+
+        SetKeyActListener();
     }
     UIList *TraingAquaticView::GetList()
     {
@@ -150,8 +159,12 @@ namespace OHOS
     void TraingAquaticView::OnStop()
     {
         View<TraingAquaticPresenter>::OnStop();
+
+
+        RootView::GetInstance()->ClearOnKeyActListener();
+        //FocusManager::GetInstance()->ClearFocus();
         RootView::GetInstance()->RemoveAll();
-       // RootView::GetInstance()->ClearFocus();
+        // RootView::GetInstance()->ClearFocus();
         return;
     }
 }
\ No newline at end of file
index c9716be..236e251 100644 (file)
@@ -1,4 +1,10 @@
 /*** 
+ * @Date: 2024-04-15 10:55:58
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-07-26 09:49:56
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_ball/include/TraingBallPresenter.h
+ */
+/***
  * @Author: Caisking 3449750381@qq.com
  * @Date: 2024-03-19 17:37:18
  * @LastEditors: Caisking 3449750381@qq.com
@@ -18,8 +24,9 @@ namespace OHOS
     class TraingBallView;
     class TraingBallModel;
     class TraingBallPresenter : public Presenter<TraingBallView>,
-                                 public UIView::OnClickListener,
-                                 public UIView::OnDragListener
+                                public UIView::OnClickListener,
+                                public RootView::OnKeyActListener,
+                                public UIView::OnDragListener
     {
     public:
         TraingBallPresenter();
@@ -37,7 +44,8 @@ namespace OHOS
         bool OnClick(UIView &view, const ClickEvent &event) override;
         bool OnDrag(UIView &view, const DragEvent &event) override;
         bool OnDragEnd(UIView &view, const DragEvent &event) override;
-
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
+       
         TraingBallModel *p_TraingBallModel{nullptr};
     };
 } // namespace OHOS
index 08e659b..6ef37b4 100644 (file)
@@ -5,6 +5,10 @@
 #include "ui_resource_string.h"
 #include "NativeAbility.h"
 
+#include "KeyInputListener.h"
+#include "custom_utils.h"
+#include "common/key_code.h"
+
 #include <iostream>
 #include <chrono>
 #include <thread>
@@ -79,7 +83,7 @@ namespace OHOS
     {
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
         {
-            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE);
+            NativeAbility::GetInstance().Back();
         }
         UNUSED(view);
         return true;
@@ -89,17 +93,29 @@ namespace OHOS
     {
         UNUSED(event);
         TraingBallItemView *itemView = static_cast<TraingBallItemView *>(&view);
-        //传递训练项目
+        // 传递训练项目
         AppViewId viewId = itemView->GetTraingBallIndex();
         UIResourceTextId sportid = itemView->GetTraingBallId();
         TraingModel::GetInstance()->SetSportEvent(sportid);
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId);
         if (viewId < VIEW_MAX_INTER_APP)
         {
-            NativeAbility::GetInstance().ChangeSlice(viewId);
+            NativeAbility::GetInstance().EnterSlice(viewId);
             return true;
         }
         return false;
     }
 
+    bool TraingBallPresenter::OnKeyAct(UIView &view, const KeyEvent &event)
+    {
+        unsigned short keyID = event.GetKeyId();
+        unsigned short keyState = event.GetState();
+
+        // 如果是power键,且是亮屏状态,按键释放就返回上一级
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)
+        {
+            NativeAbility::GetInstance().Back();
+        }
+        return true;
+    }
 }
index 738dcd3..3d2b07a 100644 (file)
@@ -44,7 +44,14 @@ namespace OHOS
     {
         p_TraingBallListAdapter->AddItem(item);
     }
-   void TraingBallView::InitView()
+    static void SetKeyActListener()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener");
+        // 增加按键监听
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingBallPresenter::GetInstance();
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);
+    }
+    void TraingBallView::InitView()
     {
         if (scrollView == nullptr)
         {
@@ -85,8 +92,10 @@ namespace OHOS
         TraingBallList->SetYScrollBarVisible(true); // 设置滑动滚动条
 
         // 增加表冠控制
-        //TraingBallList->SetRotateFactor(2);
-        //TraingBallList->RequestFocus();
+        TraingBallList->SetRotateFactor(2);
+        TraingBallList->RequestFocus();
+
+        SetKeyActListener();
     }
     UIList *TraingBallView::GetList()
     {
@@ -150,8 +159,12 @@ namespace OHOS
     void TraingBallView::OnStop()
     {
         View<TraingBallPresenter>::OnStop();
+
+
+        RootView::GetInstance()->ClearOnKeyActListener();
+        //FocusManager::GetInstance()->ClearFocus();
         RootView::GetInstance()->RemoveAll();
-       // RootView::GetInstance()->ClearFocus();
+        // RootView::GetInstance()->ClearFocus();
         return;
     }
 }
\ No newline at end of file
index 5549caa..9994802 100644 (file)
@@ -1,4 +1,4 @@
-/*** 
+/***
  * @Author: Caisking 3449750381@qq.com
  * @Date: 2024-03-26 09:44:11
  * @LastEditors: Caisking 3449750381@qq.com
@@ -7,7 +7,6 @@
  * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  */
 
-
 #ifndef _TraingDance_PRESENTER_H
 #define _TraingDance_PRESENTER_H
 
@@ -20,6 +19,7 @@ namespace OHOS
     class TraingDanceModel;
     class TraingDancePresenter : public Presenter<TraingDanceView>,
                                  public UIView::OnClickListener,
+                                 public RootView::OnKeyActListener,
                                  public UIView::OnDragListener
     {
     public:
@@ -38,6 +38,7 @@ namespace OHOS
         bool OnClick(UIView &view, const ClickEvent &event) override;
         bool OnDrag(UIView &view, const DragEvent &event) override;
         bool OnDragEnd(UIView &view, const DragEvent &event) override;
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
 
         TraingDanceModel *p_TraingDanceModel{nullptr};
     };
index 5884373..9972a62 100644 (file)
@@ -5,6 +5,10 @@
 #include "ui_resource_string.h"
 #include "NativeAbility.h"
 
+#include "KeyInputListener.h"
+#include "custom_utils.h"
+#include "common/key_code.h"
+
 #include <iostream>
 #include <chrono>
 #include <thread>
@@ -78,7 +82,7 @@ namespace OHOS
     {
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
         {
-            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE);
+            NativeAbility::GetInstance().Back();
         }
         UNUSED(view);
         return true;
@@ -95,10 +99,22 @@ namespace OHOS
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId);
         if (viewId < VIEW_MAX_INTER_APP)
         {
-            NativeAbility::GetInstance().ChangeSlice(viewId);
+            NativeAbility::GetInstance().EnterSlice(viewId);
             return true;
         }
         return false;
     }
 
+    bool TraingDancePresenter::OnKeyAct(UIView &view, const KeyEvent &event)
+    {
+        unsigned short keyID = event.GetKeyId();
+        unsigned short keyState = event.GetState();
+
+        // 如果是power键,且是亮屏状态,按键释放就返回上一级
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)
+        {
+            NativeAbility::GetInstance().Back();
+        }
+        return true;
+    }
 }
index 2611e9b..25eec3a 100644 (file)
@@ -44,7 +44,14 @@ namespace OHOS
     {
         p_TraingDanceListAdapter->AddItem(item);
     }
-   void TraingDanceView::InitView()
+    static void SetKeyActListener()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener");
+        // 增加按键监听
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingDancePresenter::GetInstance();
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);
+    }
+    void TraingDanceView::InitView()
     {
         if (scrollView == nullptr)
         {
@@ -85,8 +92,10 @@ namespace OHOS
         TraingDanceList->SetYScrollBarVisible(true); // 设置滑动滚动条
 
         // 增加表冠控制
-        //TraingDanceList->SetRotateFactor(2);
-        //TraingDanceList->RequestFocus();
+        TraingDanceList->SetRotateFactor(2);
+        TraingDanceList->RequestFocus();
+
+        SetKeyActListener();
     }
     UIList *TraingDanceView::GetList()
     {
@@ -150,8 +159,12 @@ namespace OHOS
     void TraingDanceView::OnStop()
     {
         View<TraingDancePresenter>::OnStop();
+
+
+        RootView::GetInstance()->ClearOnKeyActListener();
+        //FocusManager::GetInstance()->ClearFocus();
         RootView::GetInstance()->RemoveAll();
-       // RootView::GetInstance()->ClearFocus();
+        // RootView::GetInstance()->ClearFocus();
         return;
     }
 }
\ No newline at end of file
index 63bed01..709a443 100644 (file)
@@ -1,3 +1,9 @@
+/***
+ * @Date: 2024-04-15 10:55:58
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-07-26 10:00:13
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_fitness/include/TraingFitnessPresenter.h
+ */
 /***
  * @Author: Caisking 3449750381@qq.com
  * @Date: 2024-03-26 09:40:03
@@ -28,7 +34,8 @@ namespace OHOS
     class TraingFitnessPresenter : public Presenter<TraingFitnessView>,
                                    public UIView::OnClickListener,
                                    public UIView::OnDragListener,
-                                   public UIView::OnTouchListener
+                                   public RootView::OnKeyActListener
+
     {
     public:
         TraingFitnessPresenter();
@@ -46,7 +53,7 @@ namespace OHOS
         bool OnClick(UIView &view, const ClickEvent &event) override;
         bool OnDrag(UIView &view, const DragEvent &event) override;
         bool OnDragEnd(UIView &view, const DragEvent &event) override;
-        bool OnPress(UIView &view, const PressEvent &event) override;
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
 
         TraingFitnessModel *p_TraingFitnessModel{nullptr};
     };
index a68645f..f411950 100644 (file)
 #include "AppViewIDs.h"
 #include "NativeAbility.h"
 
+#include "KeyInputListener.h"
+#include "custom_utils.h"
+#include "common/key_code.h"
+
 #include <iostream>
 #include <chrono>
 #include <thread>
@@ -91,7 +95,7 @@ namespace OHOS
     {
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
         {
-            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE);
+            NativeAbility::GetInstance().Back();
         }
         UNUSED(view);
         return true;
@@ -107,12 +111,25 @@ namespace OHOS
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId);
         if (viewId < VIEW_MAX_INTER_APP)
         {
-            NativeAbility::GetInstance().ChangeSlice(viewId);
+            NativeAbility::GetInstance().EnterSlice(viewId);
             return true;
         }
         return false;
     }
 
+    bool TraingFitnessPresenter::OnKeyAct(UIView &view, const KeyEvent &event)
+    {
+        unsigned short keyID = event.GetKeyId();
+        unsigned short keyState = event.GetState();
+
+        // 如果是power键,且是亮屏状态,按键释放就返回上一级
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)
+        {
+            NativeAbility::GetInstance().Back();
+        }
+        return true;
+    }
+#if 0
     bool TraingFitnessPresenter::OnPress(UIView &view, const PressEvent &event)
     {
         if (&view == TraingFitnessView::GetInstance()->GetScrollView())
@@ -127,4 +144,5 @@ namespace OHOS
         }
         return false;
     }
+#endif
 }
index 169713b..e7daa04 100644 (file)
@@ -42,7 +42,15 @@ namespace OHOS
     {
         p_TraingFitnessListAdapter->AddItem(item);
     }
-   void TraingFitnessView::InitView()
+
+    static void SetKeyActListener()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener");
+        // 增加按键监听
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingFitnessPresenter::GetInstance();
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);
+    }
+    void TraingFitnessView::InitView()
     {
         if (scrollView == nullptr)
         {
@@ -83,8 +91,10 @@ namespace OHOS
         TraingFitnessList->SetYScrollBarVisible(true); // 设置滑动滚动条
 
         // 增加表冠控制
-        //TraingFitnessList->SetRotateFactor(2);
-        //TraingFitnessList->RequestFocus();
+        TraingFitnessList->SetRotateFactor(2);
+        TraingFitnessList->RequestFocus();
+
+        SetKeyActListener();
     }
     UIList *TraingFitnessView::GetList()
     {
@@ -97,7 +107,8 @@ namespace OHOS
     void TraingFitnessView::DeInitView()
     {
         // scrollView-> RemoveAll();
-        RemoveAll();
+        scrollView->RemoveAll();
+
         delete title;
         title = nullptr;
 
@@ -152,8 +163,12 @@ namespace OHOS
     void TraingFitnessView::OnStop()
     {
         View<TraingFitnessPresenter>::OnStop();
+
+
+        RootView::GetInstance()->ClearOnKeyActListener();
+        //FocusManager::GetInstance()->ClearFocus();
         RootView::GetInstance()->RemoveAll();
-       // RootView::GetInstance()->ClearFocus();
+        // RootView::GetInstance()->ClearFocus();
         return;
     }
 }
\ No newline at end of file
index 58935d6..51d7f65 100644 (file)
@@ -1,4 +1,4 @@
-/*** 
+/***
  * @Author: Caisking 3449750381@qq.com
  * @Date: 2024-03-26 09:44:11
  * @LastEditors: Caisking 3449750381@qq.com
@@ -7,7 +7,6 @@
  * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  */
 
-
 #ifndef _TraingIce_PRESENTER_H
 #define _TraingIce_PRESENTER_H
 
@@ -19,8 +18,9 @@ namespace OHOS
     class TraingIceView;
     class TraingIceModel;
     class TraingIcePresenter : public Presenter<TraingIceView>,
-                                 public UIView::OnClickListener,
-                                 public UIView::OnDragListener
+                               public UIView::OnClickListener,
+                               public RootView::OnKeyActListener,
+                               public UIView::OnDragListener
     {
     public:
         TraingIcePresenter();
@@ -38,6 +38,7 @@ namespace OHOS
         bool OnClick(UIView &view, const ClickEvent &event) override;
         bool OnDrag(UIView &view, const DragEvent &event) override;
         bool OnDragEnd(UIView &view, const DragEvent &event) override;
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
 
         TraingIceModel *p_TraingIceModel{nullptr};
     };
index e018d4a..455947b 100644 (file)
@@ -5,6 +5,10 @@
 #include "ui_resource_string.h"
 #include "NativeAbility.h"
 
+#include "KeyInputListener.h"
+#include "custom_utils.h"
+#include "common/key_code.h"
+
 #include <iostream>
 #include <chrono>
 #include <thread>
@@ -78,7 +82,7 @@ namespace OHOS
     {
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
         {
-            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE);
+            NativeAbility::GetInstance().Back();
         }
         UNUSED(view);
         return true;
@@ -94,10 +98,22 @@ namespace OHOS
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId);
         if (viewId < VIEW_MAX_INTER_APP)
         {
-            NativeAbility::GetInstance().ChangeSlice(viewId);
+            NativeAbility::GetInstance().EnterSlice(viewId);
             return true;
         }
         return false;
     }
 
+    bool TraingIcePresenter::OnKeyAct(UIView &view, const KeyEvent &event)
+    {
+        unsigned short keyID = event.GetKeyId();
+        unsigned short keyState = event.GetState();
+
+        // 如果是power键,且是亮屏状态,按键释放就返回上一级
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)
+        {
+            NativeAbility::GetInstance().Back();
+        }
+        return true;
+    }
 }
index 450535e..295fa7a 100644 (file)
@@ -52,6 +52,13 @@ namespace OHOS
     {
         p_TraingIceListAdapter->AddItem(item);
     }
+    static void SetKeyActListener()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener");
+        // 增加按键监听
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingIcePresenter::GetInstance();
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);
+    }
     void TraingIceView::InitView()
     {
         if (scrollView == nullptr)
@@ -93,8 +100,10 @@ namespace OHOS
         TraingIceList->SetYScrollBarVisible(true); // 设置滑动滚动条
 
         // 增加表冠控制
-        //scrollView->SetRotateFactor(2);
-        //scrollView->RequestFocus();
+        scrollView->SetRotateFactor(2);
+        scrollView->RequestFocus();
+
+        SetKeyActListener();
     }
     UIList *TraingIceView::GetList()
     {
@@ -102,8 +111,8 @@ namespace OHOS
     }
     void TraingIceView::DeInitView()
     {
-        // scrollView-> RemoveAll();
-        RemoveAll();
+        scrollView->RemoveAll();
+        // RemoveAll();
         delete title;
         title = nullptr;
 
@@ -158,8 +167,11 @@ namespace OHOS
     void TraingIceView::OnStop()
     {
         View<TraingIcePresenter>::OnStop();
+
+        RootView::GetInstance()->ClearOnKeyActListener();
+        //FocusManager::GetInstance()->ClearFocus();
         RootView::GetInstance()->RemoveAll();
-       // RootView::GetInstance()->ClearFocus();
+        // RootView::GetInstance()->ClearFocus();
         return;
     }
 }
\ No newline at end of file
index 06c2e84..4ab2cd3 100644 (file)
@@ -1,4 +1,4 @@
-/*** 
+/***
  * @Author: Caisking 3449750381@qq.com
  * @Date: 2024-03-19 17:37:18
  * @LastEditors: Caisking 3449750381@qq.com
@@ -19,6 +19,7 @@ namespace OHOS
     class TraingLimitModel;
     class TraingLimitPresenter : public Presenter<TraingLimitView>,
                                  public UIView::OnClickListener,
+                                 public RootView::OnKeyActListener,
                                  public UIView::OnDragListener
     {
     public:
@@ -37,6 +38,7 @@ namespace OHOS
         bool OnClick(UIView &view, const ClickEvent &event) override;
         bool OnDrag(UIView &view, const DragEvent &event) override;
         bool OnDragEnd(UIView &view, const DragEvent &event) override;
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
 
         TraingLimitModel *p_TraingLimitModel{nullptr};
     };
index 7da6d4d..6e43f47 100644 (file)
@@ -4,6 +4,10 @@
 #include "ui_resource_string.h"\r
 #include "NativeAbility.h"\r
 \r
+#include "KeyInputListener.h"\r
+#include "custom_utils.h"\r
+#include "common/key_code.h"\r
+\r
 #include <iostream>\r
 #include <chrono>\r
 #include <thread>\r
@@ -94,10 +98,21 @@ namespace OHOS
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId);\r
         if (viewId < VIEW_MAX_INTER_APP)\r
         {\r
-            NativeAbility::GetInstance().ChangeSlice(viewId);\r
+            NativeAbility::GetInstance().EnterSlice(viewId);\r
             return true;\r
         }\r
         return false;\r
     }\r
+    bool TraingLimitPresenter::OnKeyAct(UIView &view, const KeyEvent &event)\r
+    {\r
+        unsigned short keyID = event.GetKeyId();\r
+        unsigned short keyState = event.GetState();\r
 \r
+        // 如果是power键,且是亮屏状态,按键释放就返回上一级\r
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)\r
+        {\r
+            NativeAbility::GetInstance().Back();\r
+        }\r
+        return true;\r
+    }\r
 }\r
index bebe036..4ff5003 100644 (file)
@@ -44,6 +44,14 @@ namespace OHOS
     {\r
         p_TraingLimitListAdapter->AddItem(item);\r
     }\r
+\r
+    static void SetKeyActListener()\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener");\r
+        // 增加按键监听\r
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingLimitPresenter::GetInstance();\r
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);\r
+    }\r
     void TraingLimitView::InitView()\r
     {\r
         if (scrollView == nullptr)\r
@@ -85,8 +93,10 @@ namespace OHOS
         TraingLimitList->SetYScrollBarVisible(true); // 设置滑动滚动条\r
 \r
         // 增加表冠控制\r
-        //TraingLimitList->SetRotateFactor(2);\r
-        //TraingLimitList->RequestFocus();\r
+        TraingLimitList->SetRotateFactor(2);\r
+        TraingLimitList->RequestFocus();\r
+\r
+        SetKeyActListener();\r
     }\r
     UIList *TraingLimitView::GetList()\r
     {\r
@@ -94,8 +104,8 @@ namespace OHOS
     }\r
     void TraingLimitView::DeInitView()\r
     {\r
-        // scrollView-> RemoveAll();\r
-        RemoveAll();\r
+        scrollView->RemoveAll();\r
+        // RemoveAll();\r
         delete title;\r
         title = nullptr;\r
 \r
@@ -150,8 +160,11 @@ namespace OHOS
     void TraingLimitView::OnStop()\r
     {\r
         View<TraingLimitPresenter>::OnStop();\r
+\r
+        RootView::GetInstance()->ClearOnKeyActListener();\r
+        //FocusManager::GetInstance()->ClearFocus();\r
         RootView::GetInstance()->RemoveAll();\r
-       // RootView::GetInstance()->ClearFocus();\r
+        // RootView::GetInstance()->ClearFocus();\r
         return;\r
     }\r
 }
\ No newline at end of file
index fc9a3c1..ef1f6c6 100644 (file)
@@ -1,3 +1,9 @@
+/*** 
+ * @Date: 2024-04-15 10:55:58
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-07-25 16:01:16
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/include/TraingMoreModel.h
+ */
 
 #ifndef TraingMore_MODEL_H
 #define TraingMore_MODEL_H
@@ -29,7 +35,7 @@ namespace OHOS
         TraingMoreModel(const TraingMoreModel &);
         TraingMoreModel &operator=(const TraingMoreModel &);
         virtual ~TraingMoreModel();
-        static const uint16_t TraingMoreListMaxNum = 8;
+        static const uint16_t TraingMoreListMaxNum = 7;
         TraingMoreItem TraingMores[TraingMoreListMaxNum] = {VIEW_INVALID, STR_ICE_SPORTS, nullptr};
         // std::map<int, AppViewId> TraingMoreIdToViewId;
         bool btConnectStatus{false};
index 161b922..20f1123 100644 (file)
@@ -1,4 +1,10 @@
 /*** 
+ * @Date: 2024-04-15 10:55:58
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-07-26 09:44:33
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/include/TraingMorePresenter.h
+ */
+/***
  * @Author: Caisking 3449750381@qq.com
  * @Date: 2024-03-26 09:44:11
  * @LastEditors: Caisking 3449750381@qq.com
@@ -7,7 +13,6 @@
  * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  */
 
-
 #ifndef _TraingMore_PRESENTER_H
 #define _TraingMore_PRESENTER_H
 
@@ -19,8 +24,9 @@ namespace OHOS
     class TraingMoreView;
     class TraingMoreModel;
     class TraingMorePresenter : public Presenter<TraingMoreView>,
-                                 public UIView::OnClickListener,
-                                 public UIView::OnDragListener
+                                public UIView::OnClickListener,
+                                public RootView::OnKeyActListener,
+                                public UIView::OnDragListener
     {
     public:
         TraingMorePresenter();
@@ -30,6 +36,7 @@ namespace OHOS
         void OnPause() override;
         void OnResume() override;
         void OnStop() override;
+        void NavigateBack();
 
         static TraingMorePresenter *GetInstance();
 
@@ -38,7 +45,7 @@ namespace OHOS
         bool OnClick(UIView &view, const ClickEvent &event) override;
         bool OnDrag(UIView &view, const DragEvent &event) override;
         bool OnDragEnd(UIView &view, const DragEvent &event) override;
-
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
         TraingMoreModel *p_TraingMoreModel{nullptr};
     };
 } // namespace OHOS
index fe4664f..4caa87e 100644 (file)
@@ -1,3 +1,9 @@
+/*** 
+ * @Date: 2024-04-15 10:55:58
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-07-25 16:00:57
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/traing/training_list_more/src/TraingMoreModel.cpp
+ */
 /***
  * @Author: Caisking 3449750381@qq.com
  * @Date: 2024-03-26 18:34:15
@@ -36,10 +42,10 @@ namespace OHOS
         TraingMores[1] = {VIEW_TRAININGDANCE, STR_DANCING_LIST, DANCE_IMAGE};
         TraingMores[2] = {VIEW_TRAININGREST, STR_RECREATIONAL_LIST, REST_IMAGE};
         TraingMores[3] = {VIEW_TRAININGBALL, STR_BALL_LIST, BALL_IMAGE};
-        TraingMores[4] = {VIEW_TRAININGAQUATIC, STR_WATER_LIST, SWIMMING_IMAGE};
-        TraingMores[5] = {VIEW_TRAININGICE, STR_ICE_LIST, ICE_IMAGE};
-        TraingMores[6] = {VIEW_TRAININGLIMIT, STR_EXTREME_LIST, LIMIT_IMAGE};
-        TraingMores[7] = {VIEW_TRAININGOTHER, STR_OTHER_LIST, OTHER_IMAGE};
+        // TraingMores[4] = {VIEW_TRAININGAQUATIC, STR_WATER_LIST, SWIMMING_IMAGE};水上运动
+        TraingMores[4] = {VIEW_TRAININGICE, STR_ICE_LIST, ICE_IMAGE};
+        TraingMores[5] = {VIEW_TRAININGLIMIT, STR_EXTREME_LIST, LIMIT_IMAGE};
+        TraingMores[6] = {VIEW_TRAININGOTHER, STR_OTHER_LIST, OTHER_IMAGE};
     }
 
     const TraingMoreItem *TraingMoreModel::GetTraingMorelistItems() const
index b45cbb6..5e9a99b 100644 (file)
@@ -5,6 +5,10 @@
 #include "ui_resource_string.h"\r
 #include "NativeAbility.h"\r
 \r
+#include "KeyInputListener.h"\r
+#include "custom_utils.h"\r
+#include "common/key_code.h"\r
+\r
 #include <iostream>\r
 #include <chrono>\r
 #include <thread>\r
@@ -13,6 +17,7 @@
 #include "traing/training_list_more/include/TraingMoreView.h"\r
 #include "traing/include/TraingModel.h"\r
 #include "uicomponents/UIComponents.h"\r
+#include "traing/include/TraingModel.h"\r
 // #include "TraingMoreView.h"\r
 \r
 namespace OHOS\r
@@ -71,6 +76,26 @@ namespace OHOS
 \r
         Presenter<TraingMoreView>::OnStop();\r
     }\r
+    void TraingMorePresenter::NavigateBack()\r
+    {\r
+        uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();\r
+\r
+        // 根据前一界面切换\r
+        if (preSlice == VIEW_TRAININGENDDATA)\r
+        {\r
+            if (TraingModel::GetInstance()->GetEntryType() == APPLIST_ENTER)\r
+                NativeAbility::GetInstance().ChangeSlice(VIEW_TRAINING, TransitionType::TRANSITION_ZOOM);\r
+            else\r
+            {\r
+                NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN, TransitionType::TRANSITION_ZOOM);\r
+                NativeAbility::GetInstance().ClearSliceIdStack(); // 清空所有SLiceId栈元素\r
+            }\r
+        }\r
+        else\r
+        {\r
+            NativeAbility::GetInstance().Back(TransitionType::TRANSITION_ZOOM);\r
+        }\r
+    }\r
     bool TraingMorePresenter::OnDrag(UIView &view, const DragEvent &event)\r
     {\r
         return true;\r
@@ -79,7 +104,7 @@ namespace OHOS
     {\r
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)\r
         {\r
-            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAINING);\r
+            NavigateBack();\r
         }\r
         UNUSED(view);\r
         return true;\r
@@ -122,21 +147,34 @@ namespace OHOS
         case VIEW_TRAININGBALL:\r
             TraingModel::GetInstance()->SetSportType(Exercisetype::BALL);\r
             break;\r
-        case VIEW_TRAININGAQUATIC:\r
-            TraingModel::GetInstance()->SetSportType(Exercisetype::WATER);\r
-            break;\r
         case VIEW_TRAININGOTHER:\r
             TraingModel::GetInstance()->SetSportType(Exercisetype::OTHER);\r
             break;\r
+#if 0\r
+        case VIEW_TRAININGAQUATIC:\r
+            TraingModel::GetInstance()->SetSportType(Exercisetype::WATER);\r
+            break;\r
+#endif\r
         default:\r
             break;\r
         }\r
         if (viewId < VIEW_MAX_INTER_APP)\r
         {\r
-            NativeAbility::GetInstance().ChangeSlice(viewId);\r
+            NativeAbility::GetInstance().EnterSlice(viewId);\r
             return true;\r
         }\r
         return false;\r
     }\r
+    bool TraingMorePresenter::OnKeyAct(UIView &view, const KeyEvent &event)\r
+    {\r
+        unsigned short keyID = event.GetKeyId();\r
+        unsigned short keyState = event.GetState();\r
 \r
+        // 如果是power键,且是亮屏状态,按键释放就返回上一级\r
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)\r
+        {\r
+            NavigateBack();\r
+        }\r
+        return true;\r
+    }\r
 }\r
index 3c9a6a3..e6d283b 100644 (file)
@@ -49,6 +49,13 @@ namespace OHOS
     {\r
         p_TraingMoreListAdapter->AddItem(item);\r
     }\r
+    static void SetKeyActListener()\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener");\r
+        // 增加按键监听\r
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingMorePresenter::GetInstance();\r
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);\r
+    }\r
     void TraingMoreView::InitView()\r
     {\r
         if (scrollView == nullptr)\r
@@ -90,8 +97,10 @@ namespace OHOS
         scrollView->SetYScrollBarVisible(true); // 设置滑动滚动条\r
 \r
         // 增加表冠控制\r
-        //TraingMoreList->SetRotateFactor(2);\r
-        //TraingMoreList->RequestFocus();\r
+        TraingMoreList->SetRotateFactor(2);\r
+        TraingMoreList->RequestFocus();\r
+\r
+        SetKeyActListener();\r
     }\r
     UIList *TraingMoreView::GetList()\r
     {\r
@@ -155,8 +164,12 @@ namespace OHOS
     void TraingMoreView::OnStop()\r
     {\r
         View<TraingMorePresenter>::OnStop();\r
+\r
+\r
+        RootView::GetInstance()->ClearOnKeyActListener();\r
+        //FocusManager::GetInstance()->ClearFocus();\r
         RootView::GetInstance()->RemoveAll();\r
-        //RootView::GetInstance()->ClearFocus();\r
+        // RootView::GetInstance()->ClearFocus();\r
         return;\r
     }\r
 }
\ No newline at end of file
index 257a8c1..5e301bd 100644 (file)
@@ -1,4 +1,4 @@
-/*** 
+/***
  * @Author: Caisking 3449750381@qq.com
  * @Date: 2024-03-19 17:37:18
  * @LastEditors: Caisking 3449750381@qq.com
@@ -19,6 +19,7 @@ namespace OHOS
     class TraingOtherModel;
     class TraingOtherPresenter : public Presenter<TraingOtherView>,
                                  public UIView::OnClickListener,
+                                 public RootView::OnKeyActListener,
                                  public UIView::OnDragListener
     {
     public:
@@ -37,6 +38,7 @@ namespace OHOS
         bool OnClick(UIView &view, const ClickEvent &event) override;
         bool OnDrag(UIView &view, const DragEvent &event) override;
         bool OnDragEnd(UIView &view, const DragEvent &event) override;
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
 
         TraingOtherModel *p_TraingOtherModel{nullptr};
     };
index 6be7b64..4ad1fd7 100644 (file)
 #include "ui_resource_string.h"
 #include "NativeAbility.h"
 
+#include "KeyInputListener.h"
+#include "custom_utils.h"
+#include "common/key_code.h"
+
 #include <iostream>
 #include <chrono>
 #include <thread>
@@ -94,7 +98,7 @@ namespace OHOS
     {
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
         {
-            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE);
+            NativeAbility::GetInstance().Back();
         }
         UNUSED(view);
         return true;
@@ -110,10 +114,22 @@ namespace OHOS
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId);
         if (viewId < VIEW_MAX_INTER_APP)
         {
-            NativeAbility::GetInstance().ChangeSlice(viewId);
+            NativeAbility::GetInstance().EnterSlice(viewId);
             return true;
         }
         return false;
     }
+    bool TraingOtherPresenter::OnKeyAct(UIView &view, const KeyEvent &event)
+    {
+        unsigned short keyID = event.GetKeyId();
+        unsigned short keyState = event.GetState();
+
+        // 如果是power键,且是亮屏状态,按键释放就返回上一级
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)
+        {
+            NativeAbility::GetInstance().Back();
+        }
+        return true;
+    }
 
 }
index 00e8722..5d02e5f 100644 (file)
@@ -44,7 +44,15 @@ namespace OHOS
     {
         p_TraingOtherListAdapter->AddItem(item);
     }
-   void TraingOtherView::InitView()
+
+    static void SetKeyActListener()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener");
+        // 增加按键监听
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingOtherPresenter::GetInstance();
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);
+    }
+    void TraingOtherView::InitView()
     {
         if (scrollView == nullptr)
         {
@@ -85,8 +93,10 @@ namespace OHOS
         TraingOtherList->SetYScrollBarVisible(true); // 设置滑动滚动条
 
         // 增加表冠控制
-        //TraingOtherList->SetRotateFactor(2);
-        //TraingOtherList->RequestFocus();
+        TraingOtherList->SetRotateFactor(2);
+        TraingOtherList->RequestFocus();
+
+        SetKeyActListener();
     }
     UIList *TraingOtherView::GetList()
     {
@@ -94,8 +104,8 @@ namespace OHOS
     }
     void TraingOtherView::DeInitView()
     {
-        // scrollView-> RemoveAll();
-        RemoveAll();
+        scrollView->RemoveAll();
+        // RemoveAll();
         delete title;
         title = nullptr;
 
@@ -150,8 +160,11 @@ namespace OHOS
     void TraingOtherView::OnStop()
     {
         View<TraingOtherPresenter>::OnStop();
+
+        RootView::GetInstance()->ClearOnKeyActListener();
+        //FocusManager::GetInstance()->ClearFocus();
         RootView::GetInstance()->RemoveAll();
-        //RootView::GetInstance()->ClearFocus();
+        // RootView::GetInstance()->ClearFocus();
         return;
     }
 }
\ No newline at end of file
index 6cb26a7..3821dea 100644 (file)
@@ -1,4 +1,4 @@
-/*** 
+/***
  * @Author: Caisking 3449750381@qq.com
  * @Date: 2024-03-19 17:37:18
  * @LastEditors: Caisking 3449750381@qq.com
@@ -18,8 +18,9 @@ namespace OHOS
     class TraingRestView;
     class TraingRestModel;
     class TraingRestPresenter : public Presenter<TraingRestView>,
-                                 public UIView::OnClickListener,
-                                 public UIView::OnDragListener
+                                public UIView::OnClickListener,
+                                public RootView::OnKeyActListener,
+                                public UIView::OnDragListener
     {
     public:
         TraingRestPresenter();
@@ -37,6 +38,7 @@ namespace OHOS
         bool OnClick(UIView &view, const ClickEvent &event) override;
         bool OnDrag(UIView &view, const DragEvent &event) override;
         bool OnDragEnd(UIView &view, const DragEvent &event) override;
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
 
         TraingRestModel *p_TraingRestModel{nullptr};
     };
index 2cee340..3a560e5 100644 (file)
@@ -4,6 +4,10 @@
 #include "ui_resource_string.h"
 #include "NativeAbility.h"
 
+#include "KeyInputListener.h"
+#include "custom_utils.h"
+#include "common/key_code.h"
+
 #include <iostream>
 #include <chrono>
 #include <thread>
@@ -78,7 +82,7 @@ namespace OHOS
     {
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
         {
-            NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE);
+            NativeAbility::GetInstance().Back();
         }
         UNUSED(view);
         return true;
@@ -94,10 +98,22 @@ namespace OHOS
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistPresenter::OnClick viewid = %d\n", viewId);
         if (viewId < VIEW_MAX_INTER_APP)
         {
-            NativeAbility::GetInstance().ChangeSlice(viewId);
+            NativeAbility::GetInstance().EnterSlice(viewId);
             return true;
         }
         return false;
     }
 
+    bool TraingRestPresenter::OnKeyAct(UIView &view, const KeyEvent &event)
+    {
+        unsigned short keyID = event.GetKeyId();
+        unsigned short keyState = event.GetState();
+
+        // 如果是power键,且是亮屏状态,按键释放就返回上一级
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)
+        {
+            NativeAbility::GetInstance().Back();
+        }
+        return true;
+    }
 }
index 61da697..349a0ed 100644 (file)
@@ -44,6 +44,14 @@ namespace OHOS
     {
         p_TraingRestListAdapter->AddItem(item);
     }
+
+    static void SetKeyActListener()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener");
+        // 增加按键监听
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingRestPresenter::GetInstance();
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);
+    }
     void TraingRestView::InitView()
     {
         if (scrollView == nullptr)
@@ -85,8 +93,10 @@ namespace OHOS
         TraingRestList->SetYScrollBarVisible(true); // 设置滑动滚动条
 
         // 增加表冠控制
-        //TraingRestList->SetRotateFactor(2);
-        //TraingRestList->RequestFocus();
+        TraingRestList->SetRotateFactor(2);
+        TraingRestList->RequestFocus();
+
+        SetKeyActListener();
     }
     UIList *TraingRestView::GetList()
     {
@@ -94,8 +104,8 @@ namespace OHOS
     }
     void TraingRestView::DeInitView()
     {
-        // scrollView-> RemoveAll();
-        RemoveAll();
+        scrollView->RemoveAll();
+        // RemoveAll();
         delete title;
         title = nullptr;
 
@@ -150,8 +160,11 @@ namespace OHOS
     void TraingRestView::OnStop()
     {
         View<TraingRestPresenter>::OnStop();
+
+        RootView::GetInstance()->ClearOnKeyActListener();
+        //FocusManager::GetInstance()->ClearFocus();
         RootView::GetInstance()->RemoveAll();
-        //RootView::GetInstance()->ClearFocus();
+        // RootView::GetInstance()->ClearFocus();
         return;
     }
 }
\ No newline at end of file
index 6fbed41..f084c08 100644 (file)
@@ -1,21 +1,4 @@
-/***
- * @Date: 2024-05-20 19:40:41
- * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-07-15 11:08:58
- * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordPresenter.h
- */
-/***
- * @Date: 2024-05-20 19:40:41
- * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-07-06 16:36:57
- * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordPresenter.h
- */
-/***
- * @Date: 2024-05-20 19:40:41
- * @LastEditors: Caisking 3449750381@qq.com
- * @LastEditTime: 2024-06-08 10:11:44
- * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordPresenter.h
- */
+
 #ifndef _TraingRecord_PRESENTER_H
 #define _TraingRecord_PRESENTER_H
 
@@ -41,6 +24,7 @@ namespace OHOS
         void OnResume() override;
         void OnStop() override;
         static TraingRecordPresenter *GetInstance();
+        void NavigateBack();
 
     private:
         // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承;
index 65ff88b..3e714fc 100644 (file)
@@ -15,6 +15,7 @@
 #include "traingrecord/include/TraingRecordPresenter.h"
 #include "traingrecord/include/TraingRecordModel.h"
 #include "traing/include/TraingEnddataView.h"
+#include "traing/include/TraingModel.h"
 
 #include "KeyInputListener.h"
 #include "custom_utils.h"
@@ -74,7 +75,25 @@ namespace OHOS
     {
         Presenter<TraingRecordView>::OnStop();
     }
-
+    void TraingRecordPresenter::NavigateBack()
+    {
+        uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();
+        // 根据前一界面切换 {训练结束失败}
+        if (preSlice == VIEW_TRAININGCRAD)
+        {
+            if (TraingModel::GetInstance()->GetEntryType() == APPLIST_ENTER)
+                NativeAbility::GetInstance().ChangeSlice(VIEW_TRAINING, TransitionType::TRANSITION_ZOOM);
+            else
+            {
+                NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN, TransitionType::TRANSITION_ZOOM);
+                NativeAbility::GetInstance().ClearSliceIdStack(); // 清空所有SLiceId栈元素
+            }
+        }
+        else
+        {
+            NativeAbility::GetInstance().Back(TransitionType::TRANSITION_ZOOM);
+        }
+    }
     bool TraingRecordPresenter::OnDrag(UIView &view, const DragEvent &event)
     {
         return true;
@@ -83,7 +102,7 @@ namespace OHOS
     {
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
         {
-            NativeAbility::GetInstance().Back();
+            NavigateBack();
         }
         return true;
     }
@@ -113,7 +132,7 @@ namespace OHOS
                 // 选择点击按键的历史数据
                 int arraynum = sportDataVector.size() - 1;
                 SportData sportData = sportDataVector[arraynum - index]; // 显示是倒序 id同理
-                NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGENDDATA);
+                NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGENDDATA);
                 TraingModel::GetInstance()->SetSportdata(&sportData);
                 return true;
             }
@@ -129,8 +148,7 @@ namespace OHOS
         // 如果是power键,且是亮屏状态,按键释放就返回上一级
         if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)
         {
-            // 回退
-            NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_ZOOM);
+            NavigateBack();
         }
         return true;
     }