-/*\r
- * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved.\r
- * Description: KeyPresenter.cpp\r
- * Author:\r
- * Create: 2021-09-18\r
- */\r
-\r
-#include "KeyInputListener.h"\r
-#include "common/key_code.h"\r
-#include "AppViewIDs.h"\r
-#include "View.h"\r
-#include "MainViewSample.h"\r
-#include "wearable_log.h"\r
-#include "UiConfig.h"\r
-#include "dock/input_device.h"\r
-#include "notification_manager.h"\r
-#include "AlarmPopUpPresenter.h"\r
-#include "CallerLogModel.h"\r
-#include "MainCallingPresenter.h"\r
-\r
-namespace OHOS {\r
-static bool IsCallingNotify()\r
-{\r
- uint16_t notifyId = NotificationManager::GetInstance()->GetShowingNotifyId();\r
- if (NotificationManager::GetInstance()->hasNotifyShowing() == true &&\r
- (notifyId == TOPIC_EVENT_HFP_INCOMMING ||\r
- notifyId == TOPIC_EVENT_HFP_WATCH_ACTIVE ||\r
- notifyId == TOPIC_EVENT_HFP_PHONE_TO_WATCH)) {\r
- return true;\r
- } else {\r
- return false;\r
- }\r
-}\r
-\r
-static void PressAlarmNotify()\r
-{\r
- uint16_t notifyId = NotificationManager::GetInstance()->GetShowingNotifyId();\r
- if (NotificationManager::GetInstance()->hasNotifyShowing() == true && notifyId == TOPIC_EVENT_ALARM_RING) {\r
- AlarmClockModel::GetInstance()->AlarmGetClockNum();\r
- AlarmPopUpPresenter::GetInstance()->DelayAlarmRing();\r
- NotificationManager::GetInstance()->StopNotify();\r
- }\r
-}\r
-\r
-void KeyInputListener::OnKeyPress(void)\r
-{\r
- pressFlag = 1; // 短按标志\r
- return;\r
-}\r
-\r
-void KeyInputListener::OnKeyLongPress(const KeyEvent& event)\r
-{\r
- longPressFlag = 1; // 长按标志\r
-\r
- uint16 keyID = event.GetKeyId();\r
- if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER)) { // 电源按键\r
- // 切换到关机/重启卡片\r
- NativeAbility::GetInstance().ChangeSlice(VIEW_REBOOT);\r
- } else if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_FUNC)) { // 功能按键\r
- // 切换到查看系统版本卡片\r
- }\r
- return;\r
-}\r
-\r
-void KeyInputListener::CallVolumeDipSwitchControl(uint8_t model)\r
-{\r
- if (MainCallingPresenter::GetInstance() != nullptr && CallerLogModel::GetInstance()->GetCallStatus()) {\r
- if (CallerLogModel::GetInstance()->GetVolumeScreenStatus() == true) {\r
- volumeSliderEventListener = VolumeSliderEventListener::GetInstance();\r
- if (volumeSliderEventListener == nullptr) {\r
- return;\r
- }\r
- volumeSliderEventListener->ChangeVolume(model);\r
- } else {\r
- MainCallingPresenter::GetInstance()->HonrsViewChange();\r
- CallerLogModel::GetInstance()->SetVolumeScreenStatus(true);\r
- }\r
- }\r
-}\r
-\r
-void KeyInputListener::OnKeyRelease(const KeyEvent& event)\r
-{\r
- uint16_t currentViewId = NativeAbility::GetInstance().GetCurSliceId();\r
- uint16 keyID = event.GetKeyId();\r
- if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER)) { // 电源按键\r
- if (longPressFlag == 0 && pressFlag == 1) { // 短按电源键\r
- if (currentViewId == VIEW_MAEKPHONE_SAMPLE || IsCallingNotify() == true) { // 音量卡片\r
- // 音量+\r
- CallVolumeDipSwitchControl(1);\r
- } else if (currentViewId != VIEW_MAIN_SAMPLE) { // 主表盘\r
- PressAlarmNotify(); // 当前为闹钟通知页面时,先处理闹钟再切换页面\r
- NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE, TRANSITION_ZOOM);\r
- } else {\r
- PressAlarmNotify(); // 当前为闹钟通知页面时,先处理闹钟再切换页面\r
- if (!MainViewSample::GetInstance()->IsMainView()) { // 当前页面为主表盘的其他页面时,切换回主表盘页面\r
- NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE);\r
- } else {\r
- NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TRANSITION_ZOOM);\r
- }\r
- }\r
- }\r
- } else if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_FUNC)) { // 功能按键\r
- if (longPressFlag == 0 && pressFlag == 1) { // 短按功能键\r
- if (currentViewId == VIEW_MAEKPHONE_SAMPLE || IsCallingNotify() == true) { // 音量卡片\r
- // 音量-\r
- CallVolumeDipSwitchControl(0);\r
- } else {\r
- // 切换到用户配置的快捷卡片\r
- }\r
- }\r
- }\r
-\r
- pressFlag = 0;\r
- longPressFlag = 0;\r
- return;\r
-}\r
-\r
-bool KeyInputListener::OnKeyAct(UIView& view, const KeyEvent& event)\r
-{\r
- UNUSED(view);\r
-\r
- uint8 state = event.GetState();\r
-\r
- switch (state) {\r
- case InputDevice::STATE_PRESS: // 短按\r
- OnKeyPress();\r
- break;\r
-#ifdef __LITEOS_M__\r
- case InputDevice::STATE_LONG_PRESS: // 长按\r
- OnKeyLongPress(event);\r
- break;\r
-#endif\r
- case InputDevice::STATE_RELEASE: // 释放\r
- OnKeyRelease(event);\r
- break;\r
- default:\r
- break;\r
- }\r
- return true;\r
-}\r
-}\r
+/*
+ * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved.
+ * Description: KeyPresenter.cpp
+ * Author:
+ * Create: 2021-09-18
+ */
+
+#include "KeyInputListener.h"
+#include "common/key_code.h"
+#include "AppViewIDs.h"
+#include "View.h"
+#include "MainViewSample.h"
+#include "wearable_log.h"
+#include "UiConfig.h"
+#include "dock/input_device.h"
+#include "notification_manager.h"
+#include "AlarmPopUpPresenter.h"
+#include "CallerLogModel.h"
+#include "MainCallingPresenter.h"
+
+namespace OHOS {
+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 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::OnKeyLongPress(const KeyEvent& event)
+{
+ longPressFlag = 1; // 长按标志
+
+ uint16 keyID = event.GetKeyId();
+ WEARABLE_LOGD("","into key! keyID %u\n",keyID);
+ if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER)) { // 电源按键
+ // 切换到关机/重启卡片
+ NativeAbility::GetInstance().ChangeSlice(VIEW_REBOOT);
+ } else if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_FUNC)) { // 功能按键
+ // 切换到查看系统版本卡片
+ }
+ 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);
+ }
+ }
+}
+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_MAEKPHONE_SAMPLE || IsCallingNotify() == true) { // 音量卡片
+ // 音量+
+ CallVolumeDipSwitchControl(1);
+ }else if (currentViewId != VIEW_MAIN_SAMPLE) { // 主表盘
+ PressAlarmNotify(); // 当前为闹钟通知页面时,先处理闹钟再切换页面
+ NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE, TRANSITION_ZOOM);
+ } else {
+ PressAlarmNotify(); // 当前为闹钟通知页面时,先处理闹钟再切换页面
+ if (!MainViewSample::GetInstance()->IsMainView()) { // 当前页面为主表盘的其他页面时,切换回主表盘页面
+ NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE);
+ } else {
+ //power键要进入休眠
+ if(mcu_pms_is_screen_on()){
+ mcu_pm_lcd_off(NULL,0);
+ }else{
+ mcu_pm_lcd_on(NULL,0);
+ }
+ }
+ }
+ }
+ } else if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_FUNC)) { // 功能按键
+ if (longPressFlag == 0 && pressFlag == 1) { // 短按功能键
+ if (currentViewId == VIEW_MAEKPHONE_SAMPLE || IsCallingNotify() == true) { // 音量卡片
+ // 音量-
+ CallVolumeDipSwitchControl(0);
+ } else if (currentViewId != VIEW_MAIN_SAMPLE) { // 主表盘
+ PressAlarmNotify(); // 当前为闹钟通知页面时,先处理闹钟再切换页面
+ NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE, TRANSITION_ZOOM);
+ } else {
+ PressAlarmNotify(); // 当前为闹钟通知页面时,先处理闹钟再切换页面
+ if (!MainViewSample::GetInstance()->IsMainView()) { // 当前页面为主表盘的其他页面时,切换回主表盘页面
+ NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE);
+ } else {
+ NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TRANSITION_ZOOM);
+ }
+ }
+ }
+ }
+
+ pressFlag = 0;
+ longPressFlag = 0;
+ return;
+}
+
+bool KeyInputListener::OnKeyAct(UIView& view, const KeyEvent& event)
+{
+ UNUSED(view);
+
+ uint8 state = event.GetState();
+
+ switch (state) {
+ case InputDevice::STATE_PRESS: // 短按
+ OnKeyPress();
+ break;
+#ifdef __LITEOS_M__
+ case InputDevice::STATE_LONG_PRESS: // 长按
+ OnKeyLongPress(event);
+ break;
+#endif
+ case InputDevice::STATE_RELEASE: // 释放
+ OnKeyRelease(event);
+ break;
+ default:
+ break;
+ }
+ return true;
+}
+}