#include "MainCallingPresenter.h"
#include "ApplistModel.h"
-namespace OHOS {
-static bool IsNotifyCallStatus()
-{
- uint16_t notifyId = NotificationManager::GetInstance()->GetShowingNotifyId();
- if (NotificationManager::GetInstance()->HasNotifyShowing() &&
- (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() && notifyId == TOPIC_EVENT_ALARM_RING) {
- AlarmClockModel::GetInstance()->AlarmGetClockNum();
- AlarmPopUpPresenter::GetInstance()->DelayAlarmRing();
- NotificationManager::GetInstance()->StopNotify();
- }
-}
+#include "UiConfig.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 {
KeyInputListener* KeyInputListener::GetInstance()
{
static KeyInputListener instance;
return &instance;
}
-void KeyInputListener::OnKeyPress(void)
+void KeyInputListener::OnKeyPress(const KeyEvent &event)
{
pressFlag = 1; // 短按标志
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnKeyPress: pressFlag = %d", pressFlag);
+ 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)
+ {
+ HandlePowerKeyPress(currentViewId);
+ }
+ }
return;
}
void KeyInputListener::OnKeyLongPress(const KeyEvent& event)
{
longPressFlag = 1; // 长按标志
+ uint16 keyID = event.GetKeyId();
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnKeyLongPress: keyID = %d, longPressFlag = %d", keyID, longPressFlag);
+ return;
+}
+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)) { // 电源按键
- // 切换到关机/重启卡片
- NativeAbility::GetInstance().ChangeSlice(VIEW_REBOOT);
- } else if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_FUNC)) { // 功能按键
- // 切换到查看系统版本卡片
- }
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnKeyRelease: keyID = %d, currentViewId = %d, longPressFlag = %d, pressFlag = %d",
+ keyID, currentViewId, longPressFlag, pressFlag);
+ // 重置标志
+ pressFlag = 0;
+ longPressFlag = 0;
return;
}
-void KeyInputListener::CallVolumeDipSwitchControl(uint8_t status)
+//处理power键的按下逻辑
+void KeyInputListener::HandlePowerKeyPress(uint16_t currentViewId)
{
- VolumeSliderEventListener *volumeSliderEventListener = nullptr;
- if (MainCallingPresenter::GetInstance() != nullptr && CallerLogModel::GetInstance()->GetCallStatus()) {
- if (CallerLogModel::GetInstance()->GetVolumeScreenStatus()) {
- VolumeSettingView *settingView = MainCallingPresenter::GetInstance()->GetvolumeSetting();
- if (settingView == nullptr) {
- return;
- }
- volumeSliderEventListener = settingView->GetVolumeEventListener();
- if (volumeSliderEventListener == nullptr) {
- return;
- }
- volumeSliderEventListener->ChangeVolume(static_cast<VolumeChangeStatus>(status));
- } else {
- MainCallingPresenter::GetInstance()->HonrsViewChange();
- CallerLogModel::GetInstance()->SetVolumeScreenStatus(true);
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HandlePowerKeyPress: currentViewId = %d", currentViewId);
+
+ if (currentViewId != VIEW_MAIN)
+ {
+ if (mcu_pms_is_screen_on())
+ {
+ NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN,TransitionType::TRANSITION_ZOOM);
}
}
- if (IsNotifyCallStatus()) {
- if (NotificationManager::GetInstance()->GetVolumeScreenStatus()) {
- VolumeSettingView *settingView = GetvolumeSetting();
- if (settingView == nullptr) {
- return;
- }
- volumeSliderEventListener = settingView->GetVolumeEventListener();
- if (volumeSliderEventListener == nullptr) {
- return;
+ else // 当前页面是主表盘
+ {
+ if (mcu_pms_is_screen_on())
+ {
+ if (!MainViewSample::GetInstance()->IsMainClockPage())
+ {
+ if(MainViewSample::GetInstance()->IsPullUpViewPage() == PULLUP)
+ {
+ MainViewSample::GetInstance()->HandOnKeyEventSwitchMainPullDownView();
+ }
+ MainViewSample::GetInstance()->SwitchToClockPage(); //当前页面为主表盘的其他页面时,切换回主表盘页面
}
- volumeSliderEventListener->ChangeVolume(static_cast<VolumeChangeStatus>(status));
- } 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_MAEKPHONE_SAMPLE ||
- NotificationManager::GetInstance()->GetWatchCallStatus()) { // 音量卡片
- // 音量+
- CallVolumeDipSwitchControl(VOLUMEUP);
- } else if (currentViewId != VIEW_MAIN) { // 主表盘
- PressAlarmNotify(); // 当前为闹钟通知页面时,先处理闹钟再切换页面
- NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN, TransitionType::TRANSITION_ZOOM);
- } else {
- PressAlarmNotify(); // 当前为闹钟通知页面时,先处理闹钟再切换页面
- if (!MainViewSample::GetInstance()->IsMainClockPage()) { // 当前页面为主表盘的其他页面时,切换回主表盘页面
- MainViewSample::GetInstance()->SwitchToClockPage();
- } else {
+ else
+ {
+ if (uapi_dev_runtime_get_lock_status())
+ {
+ NativeAbility::GetInstance().ChangeSlice(VIEW_CODED_LOCK);
+ }
+ else
+ {
if (ApplistModel::GetInstance().GetCurrentStyle() == AppListStyle::WATERFALL_STYLE) {
NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_ENTER_WATERFALL);
} else {
}
}
}
- } else if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_FUNC)) { // 功能按键
- if (longPressFlag == 0 && pressFlag == 1) { // 短按功能键
- if (currentViewId == VIEW_MAEKPHONE_SAMPLE ||
- NotificationManager::GetInstance()->GetWatchCallStatus()) { // 音量卡片
- // 音量-
- CallVolumeDipSwitchControl(VOLUMEDOWN);
- } else {
- // 切换到用户配置的快捷卡片
- }
+ else
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Screen is off");
}
}
-
- pressFlag = 0;
- longPressFlag = 0;
- return;
}
bool KeyInputListener::OnKeyAct(UIView& view, const KeyEvent& event)
switch (state) {
case InputDevice::STATE_PRESS: // 短按
- OnKeyPress();
+ OnKeyPress(event);
break;
#ifdef __LITEOS_M__
case InputDevice::STATE_LONG_PRESS: // 长按