From: luozheng <1732036298@qq.com> Date: Wed, 28 Feb 2024 02:27:09 +0000 (+0800) Subject: 修改短按OnKeyRelease函数 X-Git-Tag: release_V1.2.70_20241020_135402~1298^2~1 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=5c1e9353bb6e82adb5dd2880f51943cd8c2375cb;p=mirrors%2FFD230.git 修改短按OnKeyRelease函数 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/key/include/KeyInputListener.h b/code/sdk/application/wearable/fd230app/nativeui/key/include/KeyInputListener.h index b9724f9dd..a5bd57cc4 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/key/include/KeyInputListener.h +++ b/code/sdk/application/wearable/fd230app/nativeui/key/include/KeyInputListener.h @@ -14,23 +14,26 @@ #include "events/key_event.h" #include "ohos_types.h" -namespace OHOS { -class KeyInputListener : public RootView::OnKeyActListener { -public: - explicit KeyInputListener() {} - virtual ~KeyInputListener() {} - bool OnKeyAct(UIView& view, const KeyEvent& event) override; +namespace OHOS +{ + class KeyInputListener : public RootView::OnKeyActListener + { + public: + explicit KeyInputListener() {} + virtual ~KeyInputListener() {} + bool OnKeyAct(UIView &view, const KeyEvent &event) override; -private: - void OnKeyPress(void); - void OnKeyLongPress(const KeyEvent& event); - void OnKeyRelease(const KeyEvent& event); - void CallVolumeDipSwitchControl(uint8_t status); - void PlayerVolumeDipSwitchControl(uint8_t model); -private: - int32 pressFlag{0}; - int32 longPressFlag{0}; - VolumeSliderEventListener *volumeSliderEventListener{nullptr}; -}; + private: + void OnKeyPress(void); + void OnKeyLongPress(const KeyEvent &event); + void OnKeyRelease(const KeyEvent &event); + void CallVolumeDipSwitchControl(uint8_t status); + void PlayerVolumeDipSwitchControl(uint8_t model); + + private: + int32 pressFlag{0}; // 按下标志 + int32 longPressFlag{0}; // 长按标志 + VolumeSliderEventListener *volumeSliderEventListener{nullptr}; + }; } #endif // KEY_INPUT_LISTENER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp b/code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp index 80522d2e0..a3cb9d00d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/key/src/KeyInputListener.cpp @@ -18,143 +18,206 @@ #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(ZliteKeyCode::ZLITE_KEY_POWER)) { // 电源按键 - // 切换到关机/重启卡片 - NativeAbility::GetInstance().ChangeSlice(VIEW_SHUTDOWN_OR_REBOOT); - } else if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_FUNC)) { // 功能按键 - // 切换到查看系统版本卡片 + uint16 keyID = event.GetKeyId(); + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER)) + { // 电源按键 + // 切换到关机/重启卡片 + NativeAbility::GetInstance().ChangeSlice(VIEW_SHUTDOWN_OR_REBOOT); + } + else if (keyID == static_cast(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(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(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(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(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; -} }