From e897447de6fa51742c7ea41f952ba8dd1b301932 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Tue, 13 Jan 2026 16:23:23 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=20MoveChildByOffset=20?= =?utf8?q?=E5=87=BD=E6=95=B0=E4=B8=AD=E7=9A=84=E6=8C=AF=E5=8A=A8=E8=B0=83?= =?utf8?q?=E7=94=A8=E9=80=BB=E8=BE=91,=E5=87=8F=E5=B0=91=E9=9C=87=E5=8A=A8?= =?utf8?q?=E5=87=BD=E6=95=B0=E8=B0=83=E7=94=A8=E6=AC=A1=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../ui/frameworks/components/ui_list.cpp | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_list.cpp b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_list.cpp index 75d331ae9..ba279a811 100644 --- a/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_list.cpp +++ b/code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_list.cpp @@ -17,6 +17,9 @@ #include "components/ui_abstract_scroll_bar.h" #include "gfx_utils/graphic_log.h" +#if ENABLE_VIBRATOR +#include "hal_tick.h" +#endif namespace OHOS { UIList::Recycle::~Recycle() @@ -150,6 +153,11 @@ void UIList::Recycle::MoveAdapterItemsRelativeRect(int16_t x, int16_t y) UIList::UIList() : UIList(VERTICAL) {} +/* --------------------------------- 减少震动次数 --------------------------------- */ +static uint32_t lastVibratorTime_; +static constexpr uint32_t MIN_VIBRATOR_INTERVAL_MS = 100; // 最小振动间隔100毫秒 +/* -------------------------------------------------------------------------- */ + UIList::UIList(uint8_t direction) : onSelectedView_(nullptr), isLoopList_(false), @@ -171,6 +179,7 @@ UIList::UIList(uint8_t direction) #if ENABLE_VIBRATOR needVibration_ = false; vibratorType_ = VibratorType::VIBRATOR_TYPE_ONE; + lastVibratorTime_ = 0; #endif #if ENABLE_FOCUS_MANAGER focusable_ = true; @@ -707,6 +716,25 @@ void UIList::MoveChildByOffset(int16_t xOffset, int16_t yOffset) } } #if ENABLE_VIBRATOR + VibratorFunc vibratorFunc = VibratorManager::GetInstance()->GetVibratorFunc(); + if (isSelectViewFind && needVibration_ && vibratorFunc != nullptr) { + printf("isSelectViewFind = %d\n", isSelectViewFind); + uint32_t currentTime = HALTick::GetInstance().GetTime(); + // 只有在规定时间间隔后才允许调用振动(首次调用时lastVibratorTime_为0,允许调用) + bool canVibrate = (lastVibratorTime_ == 0) || + (HALTick::GetInstance().GetElapseTime(lastVibratorTime_) >= MIN_VIBRATOR_INTERVAL_MS); + if (canVibrate) { + if (!isLoopList_ && (onSelectedIndex_ == 0 || onSelectedIndex_ == recycle_.adapter_->GetCount() - 1)) { + vibratorFunc(VibratorType::VIBRATOR_TYPE_THREE); + GRAPHIC_LOGI("UIList::MoveChildByOffset calls TYPE_THREE vibrator"); + } else { + vibratorFunc(VibratorType::VIBRATOR_TYPE_TWO); + GRAPHIC_LOGI("UIList::MoveChildByOffset calls TYPE_TWO vibrator"); + } + lastVibratorTime_ = currentTime; + } + } + #if 0 VibratorFunc vibratorFunc = VibratorManager::GetInstance()->GetVibratorFunc(); if (isSelectViewFind && needVibration_ && vibratorFunc != nullptr) { if (!isLoopList_ && (onSelectedIndex_ == 0 || onSelectedIndex_ == recycle_.adapter_->GetCount() - 1)) { @@ -717,6 +745,7 @@ void UIList::MoveChildByOffset(int16_t xOffset, int16_t yOffset) GRAPHIC_LOGI("UIList::MoveChildByOffset calls TYPE_TWO vibrator"); } } + #endif #endif } view = view->GetNextSibling(); -- 2.17.1