训练记录增加按键回退适配
authorCaisking <3449750381@qq.com>
Mon, 15 Jul 2024 03:26:27 +0000 (11:26 +0800)
committerCaisking <3449750381@qq.com>
Mon, 15 Jul 2024 03:26:27 +0000 (11:26 +0800)
code/sdk/application/wearable/fd230app/nativeui/traingrecord/include/TraingRecordPresenter.h
code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/traingrecord/src/TraingRecordView.cpp

index 6b9c102..6fbed41 100644 (file)
@@ -1,4 +1,10 @@
-/*** 
+/***
+ * @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
@@ -23,7 +29,8 @@ namespace OHOS
 
     class TraingRecordPresenter : public Presenter<TraingRecordView>,
                                   public UIView::OnClickListener,
-                                  public UIView::OnDragListener
+                                  public UIView::OnDragListener,
+                                  public RootView::OnKeyActListener
     {
     public:
         TraingRecordPresenter();
@@ -40,6 +47,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; // 增加按键事件
 
         TraingRecordModel *p_TraingRecordModel{nullptr};
     };
index a5de12b..65ff88b 100644 (file)
@@ -16,6 +16,9 @@
 #include "traingrecord/include/TraingRecordModel.h"
 #include "traing/include/TraingEnddataView.h"
 
+#include "KeyInputListener.h"
+#include "custom_utils.h"
+#include "common/key_code.h"
 // #include "TraingRecordView.h"
 
 namespace OHOS
@@ -118,4 +121,17 @@ namespace OHOS
         }
         return false;
     }
+    // 增加按键事件
+    bool TraingRecordPresenter::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);
+        }
+        return true;
+    }
 }
index 83adffa..5363fc6 100644 (file)
@@ -275,6 +275,10 @@ namespace OHOS
         ShowRecordView();
         PreLoad();
         RootView::GetInstance()->Add(container_);
+        SetContainerView(container_);
+        // 增加按键监听
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingRecordPresenter::GetInstance();
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);
     }
     void TraingRecordView::AddToTraingRecordList(const TraingRecordItem &item)
     {