From: luozheng <1732036298@qq.com> Date: Sat, 24 Aug 2024 07:11:15 +0000 (+0800) Subject: 添加按键拦截功能(目前只在function键双击添加),若intercept_slice_ids数组中有给定的VIEWID则不触发该事件 X-Git-Tag: release_V1.2.70_20241020_135402~563^2~34 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=40956abb535ae0f8117cf53debac2d2d541cd3db;p=mirrors%2FFD230.git 添加按键拦截功能(目前只在function键双击添加),若intercept_slice_ids数组中有给定的VIEWID则不触发该事件 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp index d3a7c6563..2f89e3b17 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-07-18 14:55:27 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-22 20:02:18 + * @LastEditTime: 2024-08-24 14:48:41 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp */ @@ -24,6 +24,15 @@ extern "C" uint8_t uapi_dev_runtime_get_lock_status(void); namespace OHOS { + static uint16_t intercept_slice_ids[] = { + VIEW_INVALID, + VIEW_SAVEBAT, // 省电模式界面 + VIEW_BLOOD_CHECK, // 血氧检测界面 + VIEW_HEART_CHECK, // 心率检测界面 + VIEW_TRAININGCRAD, // 训练控制卡片 + VIEW_TEST, // 产测测试界面 + }; + RebootAndShutdownModel::RebootAndShutdownModel() {} RebootAndShutdownModel::~RebootAndShutdownModel() {} @@ -91,12 +100,6 @@ namespace OHOS GraphicService::GetInstance()->PostGraphicEvent(std::bind(PowerKeyLongPressCallBack)); } - static void SOSKeyLongPress(void) - { - start_SOS_phone_dail(); - } - - /*注册电源键的长按事件*/ bool RebootAndShutdownModel::RegisterPowerKeyLongPressEvent(void) { @@ -107,12 +110,6 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register PowerKey LongPress Event error, ret = %d", ret); return false; } - ret = uapi_button_register_event_cb(SOSKeyLongPress, BUTTON1_LONGPRESS_8S); - if (ret != ERRCODE_SUCC) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register PowerKey LongPress Event error, ret = %d", ret); - return false; - } return true; } @@ -274,19 +271,24 @@ namespace OHOS } } + static void SOSKeyLongPress(void) + { + start_SOS_phone_dail(); + } + static void HandFuncKeyOnLongPress(void) { - GraphicService::GetInstance()->PostGraphicEvent(std::bind(FuncKeyOnLongPressCallBack)); + GraphicService::GetInstance()->PostGraphicEvent(std::bind(SOSKeyLongPress)); } - /*注册功能键的长按(2s)事件*/ + /*注册功能键的长按(8s)事件*/ bool RebootAndShutdownModel::RegisterFuncKeyLongPressEvent(void) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RebootAndShutdownModel::RegisterFuncKeyLongPressEvent"); - int32_t ret = uapi_button_register_event_cb(HandFuncKeyOnLongPress, BUTTON1_LONGPRESS_2S); + int32_t ret = uapi_button_register_event_cb(SOSKeyLongPress, BUTTON1_LONGPRESS_8S); if (ret != ERRCODE_SUCC) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register FuncKey LongPress Event error, ret = %d", ret); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Register PowerKey LongPress Event error, ret = %d", ret); return false; } return true; @@ -381,6 +383,14 @@ namespace OHOS return; } + uint16_t current_slice_id = OHOS::NativeAbility::GetInstance().GetCurSliceId(); + for (uint16_t i = 0; i < sizeof(intercept_slice_ids) / sizeof(intercept_slice_ids); i++) + { + if (intercept_slice_ids[i] == current_slice_id) + { + return; + } + } const power_display_svr_api_t *display_api = power_display_svr_get_api(); if (!display_api) { @@ -438,7 +448,7 @@ namespace OHOS RegisterPowerKeyDoubleClickEvent(); RegisterPowerKeyLongPressEvent(); RegisterFuncKeyPressEvent(); - // RegisterFuncKeyLongPressEvent(); + RegisterFuncKeyLongPressEvent(); // RegisterFuncKeyClickEvent(); RegisterFuncKeyDoubleClickEvent(); }