修改短按OnKeyRelease函数
authorluozheng <1732036298@qq.com>
Wed, 28 Feb 2024 02:27:09 +0000 (10:27 +0800)
committerluozheng <1732036298@qq.com>
Wed, 28 Feb 2024 02:27:09 +0000 (10:27 +0800)
code/sdk/application/wearable/fd230app/nativeui/key/include/KeyInputListener.h
code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp

index b9724f9..a5bd57c 100644 (file)
 #include "events/key_event.h"\r
 #include "ohos_types.h"\r
 \r
-namespace OHOS {\r
-class KeyInputListener : public RootView::OnKeyActListener {\r
-public:\r
-    explicit KeyInputListener() {}\r
-    virtual ~KeyInputListener() {}\r
-    bool OnKeyAct(UIView& view, const KeyEvent& event) override;\r
+namespace OHOS\r
+{\r
+    class KeyInputListener : public RootView::OnKeyActListener\r
+    {\r
+    public:\r
+        explicit KeyInputListener() {}\r
+        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(uint8_t status);\r
-    void PlayerVolumeDipSwitchControl(uint8_t model);\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(uint8_t status);\r
+        void PlayerVolumeDipSwitchControl(uint8_t model);\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 80522d2..a3cb9d0 100644 (file)
 #include "CallerLogModel.h"
 #include "MainCallingPresenter.h"
 #include "secondaryfunction/include/SecondaryFunctionModel.h"
-namespace OHOS {
-static bool IsCallingNotify()
+namespace OHOS
 {
-    uint16_t notifyId = NotificationManager::GetInstance()->GetShowingNotifyId();
-    if (NotificationManager::GetInstance()->hasNotifyShowing() == true &&
-        (notifyId == TOPIC_EVENT_HFP_INCOMMING ||
-         notifyId == TOPIC_EVENT_HFP_WATCH_ACTIVE ||
-         notifyId == TOPIC_EVENT_HFP_PHONE_TO_WATCH)) {
-        return true;
-    } else {
-        return false;
+    static bool IsCallingNotify()
+    {
+        uint16_t notifyId = NotificationManager::GetInstance()->GetShowingNotifyId();
+        if (NotificationManager::GetInstance()->hasNotifyShowing() == true &&
+            (notifyId == TOPIC_EVENT_HFP_INCOMMING ||
+             notifyId == TOPIC_EVENT_HFP_WATCH_ACTIVE ||
+             notifyId == TOPIC_EVENT_HFP_PHONE_TO_WATCH))
+        {
+            return true;
+        }
+        else
+        {
+            return false;
+        }
     }
-}
 
-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;
+    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;
+        }
     }
-}
 
-static void PressAlarmNotify()
-{
-    uint16_t notifyId = NotificationManager::GetInstance()->GetShowingNotifyId();
-    if (NotificationManager::GetInstance()->hasNotifyShowing() == true && notifyId == TOPIC_EVENT_ALARM_RING) {
-        AlarmClockModel::GetInstance()->AlarmGetClockNum();
-        AlarmPopUpPresenter::GetInstance()->DelayAlarmRing();
-        NotificationManager::GetInstance()->StopNotify();
+    static void PressAlarmNotify()
+    {
+        uint16_t notifyId = NotificationManager::GetInstance()->GetShowingNotifyId();
+        if (NotificationManager::GetInstance()->hasNotifyShowing() == true && notifyId == TOPIC_EVENT_ALARM_RING)
+        {
+            AlarmClockModel::GetInstance()->AlarmGetClockNum();
+            AlarmPopUpPresenter::GetInstance()->DelayAlarmRing();
+            NotificationManager::GetInstance()->StopNotify();
+        }
     }
-}
 
-void KeyInputListener::OnKeyPress(void)
-{
-    pressFlag = 1; // 短按标志
-    return;
-}
+    void KeyInputListener::OnKeyPress(void)
+    {
+        pressFlag = 1; // 短按标志
+        return;
+    }
 
-void KeyInputListener::OnKeyLongPress(const KeyEvent& event)
-{
-    longPressFlag = 1; // 长按标志
+    void KeyInputListener::OnKeyLongPress(const KeyEvent &event)
+    {
+        longPressFlag = 1; // 长按标志
 
-    uint16 keyID = event.GetKeyId();
-    if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER)) { // 电源按键
-        // 切换到关机/重启卡片
-        NativeAbility::GetInstance().ChangeSlice(VIEW_SHUTDOWN_OR_REBOOT);
-    } else if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_FUNC)) { // 功能按键
-        // 切换到查看系统版本卡片
+        uint16 keyID = event.GetKeyId();
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER))
+        { // 电源按键
+            // 切换到关机/重启卡片
+            NativeAbility::GetInstance().ChangeSlice(VIEW_SHUTDOWN_OR_REBOOT);
+        }
+        else if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_FUNC))
+        { // 功能按键
+          // 切换到查看系统版本卡片
+        }
+        return;
     }
-    return;
-}
 
-void KeyInputListener::CallVolumeDipSwitchControl(uint8_t model)
-{
-    if (MainCallingPresenter::GetInstance() != nullptr && CallerLogModel::GetInstance()->GetCallStatus()) {
-        if (CallerLogModel::GetInstance()->GetVolumeScreenStatus() == true) {
-            volumeSliderEventListener = VolumeSliderEventListener::GetInstance();
-            if (volumeSliderEventListener == nullptr) {
-                return;
+    void KeyInputListener::CallVolumeDipSwitchControl(uint8_t model)
+    {
+        if (MainCallingPresenter::GetInstance() != nullptr && CallerLogModel::GetInstance()->GetCallStatus())
+        {
+            if (CallerLogModel::GetInstance()->GetVolumeScreenStatus() == true)
+            {
+                volumeSliderEventListener = VolumeSliderEventListener::GetInstance();
+                if (volumeSliderEventListener == nullptr)
+                {
+                    return;
+                }
+                volumeSliderEventListener->ChangeVolume(model);
+            }
+            else
+            {
+                MainCallingPresenter::GetInstance()->HonrsViewChange();
+                CallerLogModel::GetInstance()->SetVolumeScreenStatus(true);
             }
-            volumeSliderEventListener->ChangeVolume(model);
-        } else {
-            MainCallingPresenter::GetInstance()->HonrsViewChange();
-            CallerLogModel::GetInstance()->SetVolumeScreenStatus(true);
         }
-    }
-    if (IsNotifyCallStatus() == true) {
-        if (NotificationManager::GetInstance()->GetVolumeScreenStatus() == true) {
-            volumeSliderEventListener = VolumeSliderEventListener::GetInstance();
-            if (volumeSliderEventListener == nullptr) {
-                return;
+        if (IsNotifyCallStatus() == true)
+        {
+            if (NotificationManager::GetInstance()->GetVolumeScreenStatus() == true)
+            {
+                volumeSliderEventListener = VolumeSliderEventListener::GetInstance();
+                if (volumeSliderEventListener == nullptr)
+                {
+                    return;
+                }
+                volumeSliderEventListener->ChangeVolume(model);
+            }
+            else
+            {
+                HonrsViewChange();
+                NotificationManager::GetInstance()->SetVolumeScreenStatus(true);
             }
-            volumeSliderEventListener->ChangeVolume(model);
-        } else {
-            HonrsViewChange();
-            NotificationManager::GetInstance()->SetVolumeScreenStatus(true);
         }
     }
-}
 
-void KeyInputListener::OnKeyRelease(const KeyEvent& event)
-{
-    uint16_t currentViewId = NativeAbility::GetInstance().GetCurSliceId();
-    uint16 keyID = event.GetKeyId();
-    if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER)) { // 电源按键
-        if (longPressFlag == 0 && pressFlag == 1) { // 短按电源键
-            if (currentViewId == VIEW_INCOMING_CALL || IsCallingNotify() == true) { // 音量卡片
-                // 音量+
-                CallVolumeDipSwitchControl(1);
-            } else if (currentViewId != VIEW_MAIN) { // 主表盘
-                PressAlarmNotify(); // 当前为闹钟通知页面时,先处理闹钟再切换页面
-                NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN, TRANSITION_ZOOM);
-            } else {
-                PressAlarmNotify(); // 当前为闹钟通知页面时,先处理闹钟再切换页面
-                if (!MainViewSample::GetInstance()->IsMainClockPage()) { // 当前页面为主表盘的其他页面时,切换回主表盘页面
-                    MainViewSample::GetInstance()->SwitchToClockPage();
-                } else {
-                    NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TRANSITION_ZOOM);
+    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);
+    }
+    void KeyInputListener::OnKeyRelease(const KeyEvent &event)
+    {
+        uint16_t currentViewId = NativeAbility::GetInstance().GetCurSliceId();
+        uint16 keyID = event.GetKeyId();
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER)) // 如果按下的按键是电源键
+        {
+            // 短按电源键
+            if (longPressFlag == 0 && pressFlag == 1)
+            {
+                // 如果当前页面是音量卡片或正在通话中,则执行音量+操作
+                if (currentViewId == VIEW_INCOMING_CALL || IsCallingNotify() == true) // 音量卡片
+                {
+                    CallVolumeDipSwitchControl(1); // 音量+
+                }
+                else if (currentViewId != VIEW_MAIN) // 如果当前页面不是主表盘,如果屏幕亮起,则先处理闹钟通知再切换到主表盘页面
+                {
+                    if (mcu_pms_is_screen_on())
+                    {
+                        PressAlarmNotify();
+                        NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN, TRANSITION_ZOOM);
+                    }
+                }
+                else // 如果当前页面是主表盘:
+                {
+                    if (mcu_pms_is_screen_on()) // 如果屏幕亮起,则先处理闹钟通知再切换到applist页面
+                    {
+                        PressAlarmNotify();
+                        if (!MainViewSample::GetInstance()->IsMainClockPage()) // 当前页面为主表盘的其他页面时,切换回主表盘页面
+                        {
+                            MainViewSample::GetInstance()->SwitchToClockPage();
+                        }
+                        else
+                        {
+                            NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TRANSITION_ZOOM);
+                        }
+                    }
                 }
             }
         }
-    } else if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_FUNC)) { // 功能按键
-        if (longPressFlag == 0 && pressFlag == 1) { // 短按功能键
-            if (currentViewId == VIEW_INCOMING_CALL || IsCallingNotify() == true) { // 音量卡片
-                // 音量-
-                CallVolumeDipSwitchControl(0);
-            } else {
-                // 切换到用户配置的快捷卡片
-                if(SecondaryFunctionModel::GetInstance()->GetHeartRateOrBloodOxygenQuickAccessSwitch() == true)
+        else if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_FUNC)) // 如果按下的按键是功能键
+        {
+            // 检查是否是短按功能键
+            if (longPressFlag == 0 && pressFlag == 1)
+            {
+                // 如果当前页面是音量卡片或正在通话中,则执行音量减操作
+                if (currentViewId == VIEW_INCOMING_CALL || IsCallingNotify() == true) // 音量卡片
+                {
+                    CallVolumeDipSwitchControl(0); // 音量-
+                }
+                else if (currentViewId != VIEW_MAIN) // 如果当前页面不是主表盘,如果屏幕亮起,则先处理闹钟通知再切换到主表盘页面。
                 {
-                    NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TRANSITION_ZOOM);
+                    if (mcu_pms_is_screen_on())
+                    {
+                        PressAlarmNotify();
+                        NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN, TRANSITION_ZOOM);
+                    }
                 }
-                else
+                else // 如果当前页面是主表盘,如果屏幕亮起,则先处理闹钟通知再切换到用户配置的快捷卡片
                 {
-                    //之后需要将VIEW_APPLIST改成心率的SliceID
-                    NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING, TRANSITION_ZOOM);
+                    if (mcu_pms_is_screen_on())
+                    {
+                        PressAlarmNotify(); // 当前为闹钟通知页面时,先处理闹钟再切换页面
+                        if (SecondaryFunctionModel::GetInstance()->GetHeartRateOrBloodOxygenQuickAccessSwitch() == true)
+                        {
+                            NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TRANSITION_ZOOM);
+                        }
+                        else
+                        {
+                            // 之后需要将VIEW_APPLIST改成心率的SliceID
+                            NativeAbility::GetInstance().ChangeSlice(VIEW_BLOODOXY, TRANSITION_ZOOM);
+                        }
+                    }
                 }
             }
         }
-    }
 
-    pressFlag = 0;
-    longPressFlag = 0;
-    return;
-}
+        pressFlag = 0;
+        longPressFlag = 0;
+        return;
+    }
 
-bool KeyInputListener::OnKeyAct(UIView& view, const KeyEvent& event)
-{
-    UNUSED(view);
+    bool KeyInputListener::OnKeyAct(UIView &view, const KeyEvent &event)
+    {
+        UNUSED(view);
 
-    uint8 state = event.GetState();
+        uint8 state = event.GetState();
 
-    switch (state) {
+        switch (state)
+        {
         case InputDevice::STATE_PRESS: // 短按
             OnKeyPress();
             break;
@@ -168,7 +231,7 @@ bool KeyInputListener::OnKeyAct(UIView& view, const KeyEvent& event)
             break;
         default:
             break;
+        }
+        return true;
     }
-    return true;
-}
 }