From: xue <2144439972@qq.com> Date: Wed, 22 Oct 2025 03:56:53 +0000 (+0800) Subject: 增加按键息屏 X-Git-Tag: V1.0.9_20251128_194606_LN~184 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=4693f1e71b8172cb8693b79584d2d62224d098e5;p=mirrors%2FFD230.git 增加按键息屏 --- diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdPresenter.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdPresenter.h index aa5d4f07e..06b56f697 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdPresenter.h +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdPresenter.h @@ -36,6 +36,7 @@ namespace OHOS void timer_callback_toui_proc(); bool isDialogueing{false};//是否进入对话模式 + bool powerKeyPressed{false};//电源键按下标志位,防止重复触发 // FUNC键长按功能 void RegisterFuncKeyLongPressEvent(void); diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp index dd603ab08..43044cf1d 100644 --- a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdPresenter.cpp @@ -96,7 +96,7 @@ namespace OHOS // uapi_button_register_event_cb(func_button_callback_vendor_down_long_press_5s, BUTTON3_LONGPRESS_5S); // 注册 FUNC 键长按2秒事件 - int32_t ret = uapi_button_register_event_cb(HandleFuncKeyLongPressCallBack, BUTTON1_LONGPRESS_2S); + int32_t ret = uapi_button_register_event_cb(HandleFuncKeyLongPressCallBack, BUTTON1_LONGPRESS_1S); if (ret != ERRCODE_SUCC) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register FuncKey LongPress Event error, ret = %d", ret); @@ -213,19 +213,38 @@ namespace OHOS */ bool ThunderBirdPresenter::HandlePowerKey(uint16_t keyState, int16_t currentView, int16_t currentSubView, int screenState) { - // 长按关机键 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HandlePowerKey: keyState=%d, screenState=%d, isDialogueing=%d, powerKeyPressed=%d", + keyState, screenState, isDialogueing, powerKeyPressed); + + // 长按关机键 - 优先处理 if (keyState == InputDevice::STATE_LONG_PRESS) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HandlePowerKey: 长按关机键,进入关机界面"); + powerKeyPressed = false; // 重置标志位 NativeAbility::GetInstance().SwitchSlice(VIEW_REBOOT); return true; } - // 短按POWER键处理 + // 按下电源键 if (keyState == InputDevice::STATE_PRESS) { - if (screenState == 0) { - // 息屏状态下短按:亮屏(由系统自动处理) + powerKeyPressed = true; // 设置按下标志位 + + if (screenState == 1) { + // 息屏状态下按下:亮屏(由系统自动处理) return true; - } else if (screenState == 1) { - // 亮屏状态下短按:息屏 + } + } + + // 松开电源键 + //判断是否亮屏 + if (keyState == InputDevice::STATE_RELEASE) { + if (!powerKeyPressed) { + return true; + } + + powerKeyPressed = false; // 重置标志位 + + if (screenState == 0 && isDialogueing == false) {//对话模式下无效 + // 亮屏状态下松开:息屏 const power_display_svr_api_t *display_api = power_display_svr_get_api(); if (display_api && display_api->get_screen_state() == SCREEN_ON) { display_api->turn_off_screen();