修复applist训练图标消失
authorCaisking <Casiking@zhihuishixun.com>
Mon, 21 Jul 2025 09:48:47 +0000 (17:48 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Mon, 21 Jul 2025 09:48:47 +0000 (17:48 +0800)
code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/src/TraingPresenter.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/training_card/src/TraingCardPresenter.cpp

index 7c5dafa..a98635f 100644 (file)
  * @Date: 2024-04-15 10:55:58
  * @LastEditors: Caisking 3449750381@qq.com
  * @LastEditTime: 2024-04-16 17:33:11
- * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingPresenter.cpp
+ * @FilePath:
+ * /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingPresenter.cpp
  */
 
 #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 "NativeAbility.h"
 #include "common/key_code.h"
+#include "components/ui_label_ext.h"
+#include "custom_utils.h"
+#include "ui_resource_string.h"
 
-#include <iostream>
-#include <chrono>
-#include <thread>
-#include "traing/include/TraingPresenter.h"
 #include "traing/include/TraingModel.h"
+#include "traing/include/TraingPresenter.h"
 #include "uicomponents/UIComponents.h"
+#include <chrono>
+#include <iostream>
+#include <thread>
 // #include "TraingView.h"
+#include "NativeRegisterManager.h"
 #include "gfx_utils/mem_check.h"
-namespace OHOS
-{
+namespace OHOS {
+REGIST_MENU_PRO(VIEW_TRAINING, TraingView, TraingPresenter,
+                PNG_APPLIST_TRAINING_IMAGE_BIG, PNG_APPLIST_TRAINING_IMAGE,
+                PNG_APPLIST_TRAINING_IMAGE, "运动", STR_TRAINING);
 
-    // 当前Presenter属性实例化的内存指针
-    static TraingPresenter *g_pTraingPresenter = nullptr;
+// 当前Presenter属性实例化的内存指针
+static TraingPresenter *g_pTraingPresenter = nullptr;
 
-    TraingPresenter::TraingPresenter()
-    {
-        g_pTraingPresenter = this;
+TraingPresenter::TraingPresenter() {
+  g_pTraingPresenter = this;
 #ifdef MEM_CHECK
-        MemCheck::GetInstance()->EnableLeakCheck(true);
+  MemCheck::GetInstance()->EnableLeakCheck(true);
 #endif
-    }
+}
 
-    TraingPresenter::~TraingPresenter()
-    {
-        g_pTraingPresenter = nullptr;
+TraingPresenter::~TraingPresenter() {
+  g_pTraingPresenter = nullptr;
 #ifdef MEM_CHECK
-        MemCheck::GetInstance()->EnableLeakCheck(false);
+  MemCheck::GetInstance()->EnableLeakCheck(false);
 #endif
-    }
+}
 
-    TraingPresenter *TraingPresenter::GetInstance()
-    {
-        return g_pTraingPresenter;
-    }
+TraingPresenter *TraingPresenter::GetInstance() { return g_pTraingPresenter; }
 
-    void TraingPresenter::OnStart()
-    {
-        Presenter<TraingView>::OnStart();
-    }
+void TraingPresenter::OnStart() { Presenter<TraingView>::OnStart(); }
 
-    void TraingPresenter::OnPause(void)
-    {
-        Presenter<TraingView>::OnPause();
-    }
+void TraingPresenter::OnPause(void) { Presenter<TraingView>::OnPause(); }
 
-    void TraingPresenter::OnResume(void)
-    {
-        Presenter<TraingView>::OnResume();
-    }
+void TraingPresenter::OnResume(void) { Presenter<TraingView>::OnResume(); }
 
-    void TraingPresenter::OnStop(void)
-    {
-        Presenter<TraingView>::OnStop();
-    }
-    // 回退函数 [ Slice 的 traingview {右滑只能回到applist}]
-    void TraingPresenter::NavigateBack()
-    {
-        NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_BACK_TO_HEXAGONS);
-        NativeAbility::GetInstance().ClearSliceIdStack(); // 清空所有SLiceId栈元素
-    }
-    bool TraingPresenter::OnDrag(UIView &view, const DragEvent &event)
-    {
-        return true;
-    }
-    bool TraingPresenter::OnDragEnd(UIView &view, const DragEvent &event)
-    {
-        UNUSED(view);
-        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
-            NavigateBack();
-        return true;
-    }
+void TraingPresenter::OnStop(void) { Presenter<TraingView>::OnStop(); }
+// 回退函数 [ Slice 的 traingview {右滑只能回到applist}]
+void TraingPresenter::NavigateBack() {
+  NativeAbility::GetInstance().ChangeSlice(
+      VIEW_APPLIST, TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+  NativeAbility::GetInstance().ClearSliceIdStack(); // 清空所有SLiceId栈元素
+}
+bool TraingPresenter::OnDrag(UIView &view, const DragEvent &event) {
+  return true;
+}
+bool TraingPresenter::OnDragEnd(UIView &view, const DragEvent &event) {
+  UNUSED(view);
+  if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
+    NavigateBack();
+  return true;
+}
 
-    bool TraingPresenter::OnClick(UIView &view, const ClickEvent &event)
-    {
-        if (strcmp(view.GetViewId(), BUTTON1) == 0)
-        {
-            NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGNOMAL);
-            TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORWALKING);
-        }
-        if (strcmp(view.GetViewId(), BUTTON3) == 0)
-        {
-            NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGNOMAL);
-            TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORRUNNING);
-        }
-        if (strcmp(view.GetViewId(), BUTTONMORE) == 0)
-        {
-            NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGMORE);
-        }
-        if (strcmp(view.GetViewId(), BUTTON2) == 0) {
-          NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGNOMAL);
-          TraingModel::GetInstance()->SetSportEvent(
-              STR_EXERCISE_FREETRAINING); //修改为自由训练
-        }
-        TraingModel::GetInstance()->SetSportType(Exercisetype::FITNESS);
-        return true;
-    }
+bool TraingPresenter::OnClick(UIView &view, const ClickEvent &event) {
+  if (strcmp(view.GetViewId(), BUTTON1) == 0) {
+    NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGNOMAL);
+    TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORWALKING);
+  }
+  if (strcmp(view.GetViewId(), BUTTON3) == 0) {
+    NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGNOMAL);
+    TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORRUNNING);
+  }
+  if (strcmp(view.GetViewId(), BUTTONMORE) == 0) {
+    NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGMORE);
+  }
+  if (strcmp(view.GetViewId(), BUTTON2) == 0) {
+    NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGNOMAL);
+    TraingModel::GetInstance()->SetSportEvent(
+        STR_EXERCISE_FREETRAINING); //修改为自由训练
+  }
+  TraingModel::GetInstance()->SetSportType(Exercisetype::FITNESS);
+  return true;
+}
 
-    // 增加按键事件
-    bool TraingPresenter::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 == 1 && uapi_get_screen_state() == 0)
-            NavigateBack();
+// 增加按键事件
+bool TraingPresenter::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 == 1 && uapi_get_screen_state() == 0)
+    NavigateBack();
 
-        return true;
-    }
+  return true;
 }
+} // namespace OHOS
index fd10a79..0174323 100644 (file)
@@ -122,7 +122,7 @@ void TraingCardPresenter::ModifiesTime() {
     }\r
     if (TrainingDataView::GetInstance()->GetTimeLabel() != nullptr) {\r
       TrainingDataView::GetInstance()->GetTimeLabel()->SetText(TimeStr.c_str());\r
-    } \r
+    }\r
   }\r
   WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ModifiesTime end");\r
 }\r
@@ -289,7 +289,8 @@ void TraingCardPresenter::RefreshData(SportData *sportdata) {
 #if 1\r
 void TraingCardPresenter::Notify(void) {\r
   // 如果未开启训练,直接退出\r
-  if (TraingModel::GetInstance()->GetSportState() == ExerciseState::General || view_ == nullptr) {\r
+  if (TraingModel::GetInstance()->GetSportState() == ExerciseState::General ||\r
+      view_ == nullptr) {\r
     return;\r
   }\r
 \r