增加key事件监控打印
authorCaisking <3449750381@qq.com>
Tue, 3 Sep 2024 03:39:22 +0000 (11:39 +0800)
committerCaisking <3449750381@qq.com>
Tue, 3 Sep 2024 03:39:22 +0000 (11:39 +0800)
code/sdk/application/wearable/fd230app/nativeui/key/include/KeyInputListener.h
code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp

index 3e22e2c..9d3eb28 100644 (file)
@@ -23,16 +23,19 @@ namespace OHOS
         virtual ~KeyInputListener() {}\r
         bool OnKeyAct(UIView &view, const KeyEvent &event) override;\r
 \r
-private:\r
-    void OnKeyPress(void);\r
-    void OnKeyLongPress(const KeyEvent& event);\r
-    void OnKeyRelease(const KeyEvent& event);\r
-    void CallVolumeDipSwitchControl(VolumeChangeStatus status);\r
-    void PlayerVolumeDipSwitchControl(VolumeChangeStatus status);\r
-private:\r
-    int32 pressFlag{0};\r
-    int32 longPressFlag{0};\r
-    VolumeSliderEventListener *volumeSliderEventListener{nullptr};\r
-};\r
+    private:\r
+        void OnKeyPress(void);\r
+        void OnKeyLongPress(const KeyEvent &event);\r
+        void OnKeyRelease(const KeyEvent &event);\r
+        void CallVolumeDipSwitchControl(VolumeChangeStatus status);\r
+        void PlayerVolumeDipSwitchControl(VolumeChangeStatus status);\r
+        void HandlePowerKeyPress(uint16_t currentViewId);\r
+        void HandleFuncKeyPress(uint16_t currentViewId);\r
+\r
+    private:\r
+        int32 pressFlag{0};\r
+        int32 longPressFlag{0};\r
+        VolumeSliderEventListener *volumeSliderEventListener{nullptr};\r
+    };\r
 }\r
 #endif // KEY_INPUT_LISTENER_H
\ No newline at end of file
index f2cf080..7b8214e 100644 (file)
@@ -1,3 +1,9 @@
+/***
+ * @Date: 2024-08-31 09:50:49
+ * @LastEditors: Caisking 3449750381@qq.com
+ * @LastEditTime: 2024-09-03 11:29:32
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp
+ */
 /*
  * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved.
  * Description: KeyPresenter.cpp
 #include "secondaryfunction/include/SecondaryFunctionModel.h"
 #include "DialViewGroup.h"
 #include "ui_service.h"
+#include "custom_runtime.h"
+
+extern "C" uint8_t mcu_pms_is_screen_on(void);
+extern "C" uint8_t uapi_dev_runtime_get_lock_status(void);
 namespace OHOS
 {
     static bool IsNotifyCallStatus()
     {
         uint16_t notifyId = NotificationManager::GetInstance()->GetShowingNotifyId();
-        if (NotificationManager::GetInstance()->HasNotifyShowing() == true &&
-            (notifyId == TOPIC_EVENT_HFP_WATCH_ACTIVE ||
-             notifyId == TOPIC_EVENT_HFP_PHONE_TO_WATCH))
-        {
-            return true;
-        }
-        else
-        {
-            return false;
-        }
+        return NotificationManager::GetInstance()->HasNotifyShowing() &&
+               (notifyId == TOPIC_EVENT_HFP_WATCH_ACTIVE || notifyId == TOPIC_EVENT_HFP_PHONE_TO_WATCH);
     }
 
-    static void PressAlarmNotify()
+    static void HandleAlarmNotify()
     {
         uint16_t notifyId = NotificationManager::GetInstance()->GetShowingNotifyId();
-        if (NotificationManager::GetInstance()->HasNotifyShowing() == true && notifyId == TOPIC_EVENT_ALARM_RING)
+        if (NotificationManager::GetInstance()->HasNotifyShowing() && notifyId == TOPIC_EVENT_ALARM_RING)
         {
             AlarmClockModel::GetInstance()->AlarmGetClockNum();
             AlarmPopUpPresenter::GetInstance()->DelayAlarmRing();
@@ -50,67 +52,58 @@ namespace OHOS
         }
     }
 
-    void KeyInputListener::OnKeyPress(void)
+    void KeyInputListener::OnKeyPress()
     {
         pressFlag = 1; // 短按标志
-        return;
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnKeyPress: pressFlag = %d", pressFlag);
     }
 
     void KeyInputListener::OnKeyLongPress(const KeyEvent &event)
     {
         longPressFlag = 1; // 长按标志
-
         uint16 keyID = event.GetKeyId();
-        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER))
-        { // 电源按键
-          // 切换到关机/重启卡片
-        }
-        else if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_FUNC))
-        { // 功能按键
-          // 切换到查看系统版本卡片
-        }
-        return;
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnKeyLongPress: keyID = %d, longPressFlag = %d", keyID, longPressFlag);
     }
 
     void KeyInputListener::CallVolumeDipSwitchControl(VolumeChangeStatus status)
     {
-        if (MainCallingPresenter::GetInstance() != nullptr && CallerLogModel::GetInstance()->GetCallStatus())
+        auto *mainPresenter = MainCallingPresenter::GetInstance();
+        auto *callerLogModel = CallerLogModel::GetInstance();
+
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallVolumeDipSwitchControl: status = %d", status);
+
+        if (mainPresenter != nullptr && callerLogModel->GetCallStatus())
         {
-            if (CallerLogModel::GetInstance()->GetVolumeScreenStatus())
+            if (callerLogModel->GetVolumeScreenStatus())
             {
-                VolumeSettingView *settingView = MainCallingPresenter::GetInstance()->GetvolumeSetting();
-                if (settingView == nullptr)
-                {
-                    return;
-                }
-                volumeSliderEventListener = settingView->GetVolumeEventListener();
-                if (volumeSliderEventListener == nullptr)
+                if (auto *settingView = mainPresenter->GetvolumeSetting())
                 {
-                    return;
+                    if (auto *volumeSliderEventListener = settingView->GetVolumeEventListener())
+                    {
+                        volumeSliderEventListener->ChangeVolume(status);
+                        return;
+                    }
                 }
-                volumeSliderEventListener->ChangeVolume(status);
             }
             else
             {
-                MainCallingPresenter::GetInstance()->HonrsViewChange();
-                CallerLogModel::GetInstance()->SetVolumeScreenStatus(true);
+                mainPresenter->HonrsViewChange();
+                callerLogModel->SetVolumeScreenStatus(true);
             }
         }
+
         if (IsNotifyCallStatus())
         {
             if (NotificationManager::GetInstance()->GetVolumeScreenStatus())
             {
-                VolumeSettingView *settingView = GetvolumeSetting();
-                if (settingView == nullptr)
-                {
-                    return;
-                }
-                volumeSliderEventListener = settingView->GetVolumeEventListener();
-                if (volumeSliderEventListener == nullptr)
+                if (auto *settingView = GetvolumeSetting())
                 {
-                    return;
+                    if (auto *volumeSliderEventListener = settingView->GetVolumeEventListener())
+                    {
+                        volumeSliderEventListener->ChangeVolume(status);
+                        return;
+                    }
                 }
-                volumeSliderEventListener->ChangeVolume(status);
             }
             else
             {
@@ -120,148 +113,118 @@ namespace OHOS
         }
     }
 
-    extern "C"
-    {
-        uint32_t mcu_pm_lcd_on(uint8_t *para, uint32_t para_len);
-        uint32_t mcu_pm_lcd_off(uint8_t *para, uint32_t para_len);
-        uint8_t mcu_pms_is_screen_on(void);
-        uint8_t uapi_dev_runtime_get_lock_status(void);
-    }
     void KeyInputListener::OnKeyRelease(const KeyEvent &event)
     {
         uint16_t currentViewId = NativeAbility::GetInstance().GetCurSliceId();
         uint16 keyID = event.GetKeyId();
 
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnKeyRelease keyID %d , longPressFlag = %d , pressFlag = %d ", keyID, longPressFlag, pressFlag);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnKeyRelease: keyID = %d, currentViewId = %d, longPressFlag = %d, pressFlag = %d", keyID, currentViewId, longPressFlag, pressFlag);
 
-        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER)) // 如果按下的按键是电源键
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER))
         {
-            // 短按电源键
             if (longPressFlag == 0 && pressFlag == 1)
             {
-#if 0
-                // 如果当前页面是音量卡片或正在通话中,则执行音量+操作
-                if (currentViewId == VIEW_INCOMING_CALL )
-                || NotificationManager::GetInstance()->GetWatchCallStatus())
-
-                { // 音量卡片
-                    // 音量
-                    CallVolumeDipSwitchControl(VOLUMEUP);
-                    return;
-                }
-#endif
-                if (currentViewId != VIEW_MAIN) // 如果当前页面不是主表盘,如果屏幕亮起,则先处理闹钟通知再切换到主表盘页面
-                {
-                    if (mcu_pms_is_screen_on())
-                    {
-                        PressAlarmNotify();
-                        NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
-                        // NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN, TransitionType::TRANSITION_ZOOM);
-                    }
-                }
-                else // 如果当前页面是主表盘:
-                {
-                    if (mcu_pms_is_screen_on()) // 如果屏幕亮起,则先处理闹钟通知再切换到applist页面
-                    {
-                        PressAlarmNotify();
-                        if (!MainViewSample::GetInstance()->IsMainClockPage()) // 当前页面为主表盘的其他页面时,切换回主表盘页面
-                        {
-                            MainViewSample::GetInstance()->SwitchToClockPage();
-                        }
-                        else
-                        {
-                            /*密码锁上锁*/
-                            if (uapi_dev_runtime_get_lock_status())
-                            {
-                                NativeAbility::GetInstance().ChangeSlice(VIEW_CODED_LOCK);
-                            }
-                            else
-                            {
-                                NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST);
-                            }
-
-                            // NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_ZOOM);
-                            // NativeAbility::GetInstance().EnterSlice(VIEW_APPLIST, TransitionType::TRANSITION_ZOOM);
-                        }
-                    }
-                    else
-                    {
-                        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " mcu_pms_is_screen_on = off ");
-                    }
-                }
+                HandlePowerKeyPress(currentViewId);
             }
         }
-        else if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_FUNC)) // 如果按下的按键是功能键
+        else if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_FUNC))
         {
-            // 检查是否是短按功能键
             if (longPressFlag == 0 && pressFlag == 1)
             {
-#if 0
-                // 如果当前页面是音量卡片或正在通话中,则执行音量+操作
-                if (currentViewId == VIEW_INCOMING_CALL )
+                HandleFuncKeyPress(currentViewId);
+            }
+        }
+
+        // 重置标志
+        pressFlag = 0;
+        longPressFlag = 0;
+    }
 
-                || NotificationManager::GetInstance()->GetWatchCallStatus())
+    void KeyInputListener::HandlePowerKeyPress(uint16_t currentViewId)
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HandlePowerKeyPress: currentViewId = %d", currentViewId);
 
-                { // 音量卡片
-                    // 音量-
-                    CallVolumeDipSwitchControl(VOLUMEDOWN);
-                    return;
+        if (currentViewId != VIEW_MAIN)
+        {
+            if (mcu_pms_is_screen_on())
+            {
+                HandleAlarmNotify();
+                NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
+            }
+        }
+        else // 当前页面是主表盘
+        {
+            if (mcu_pms_is_screen_on())
+            {
+                HandleAlarmNotify();
+                if (!MainViewSample::GetInstance()->IsMainClockPage())
+                {
+                    MainViewSample::GetInstance()->SwitchToClockPage();
                 }
-#endif
-                if (currentViewId != VIEW_MAIN) // 如果当前页面不是主表盘,如果屏幕亮起,则先处理闹钟通知再切换到主表盘页面。
+                else
                 {
-                    if (mcu_pms_is_screen_on())
+                    if (uapi_dev_runtime_get_lock_status())
                     {
-                        PressAlarmNotify();
-                        // NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN, TransitionType::TRANSITION_ZOOM);
+                        NativeAbility::GetInstance().ChangeSlice(VIEW_CODED_LOCK);
                     }
-                }
-                else // 如果当前页面是主表盘,如果屏幕亮起,则先处理闹钟通知再切换到用户配置的快捷卡片
-                {
-                    if (mcu_pms_is_screen_on())
+                    else
                     {
-                        PressAlarmNotify(); // 当前为闹钟通知页面时,先处理闹钟再切换页面
-                        // if (SecondaryFunctionModel::GetInstance()->GetHeartRateOrBloodOxygenQuickAccessSwitch() == true)
-                        // {
-                        //     NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_ZOOM);
-                        // }
-                        // else
-                        // {
-                        //     // 之后需要将VIEW_APPLIST改成心率的SliceID
-                        //     NativeAbility::GetInstance().ChangeSlice(VIEW_BLOODOXY, TransitionType::TRANSITION_ZOOM);
-                        // }
+                        NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST);
                     }
                 }
             }
+            else
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Screen is off");
+            }
         }
+    }
 
-        pressFlag = 0;
-        longPressFlag = 0;
-        return;
+    void KeyInputListener::HandleFuncKeyPress(uint16_t currentViewId)
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HandleFuncKeyPress: currentViewId = %d", currentViewId);
+
+        if (currentViewId != VIEW_MAIN)
+        {
+            if (mcu_pms_is_screen_on())
+            {
+                HandleAlarmNotify();
+            }
+        }
+        else // 当前页面是主表盘
+        {
+            if (mcu_pms_is_screen_on())
+            {
+                HandleAlarmNotify();
+                // 这里可以添加切换到用户配置的快捷卡片的逻辑
+            }
+        }
     }
 
     bool KeyInputListener::OnKeyAct(UIView &view, const KeyEvent &event)
     {
         UNUSED(view);
-
         uint8 state = event.GetState();
 
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnKeyAct: state = %d", state);
+
         switch (state)
         {
-        case InputDevice::STATE_PRESS: // 短按
+        case InputDevice::STATE_PRESS:
             OnKeyPress();
             break;
 #ifdef __LITEOS_M__
-        case InputDevice::STATE_LONG_PRESS: // 长按
+        case InputDevice::STATE_LONG_PRESS:
             OnKeyLongPress(event);
             break;
 #endif
-        case InputDevice::STATE_RELEASE: // 释放
+        case InputDevice::STATE_RELEASE:
             OnKeyRelease(event);
             break;
         default:
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnKeyAct: Unknown state = %d", state);
             break;
         }
         return true;
     }
-}
+}
\ No newline at end of file