From efa96c9e7f68e3bff8577c57bd776ce97b41df56 Mon Sep 17 00:00:00 2001 From: xue <2144439972@qq.com> Date: Fri, 12 Jun 2026 16:13:45 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E8=A1=80=E5=8E=8Becg=E4=BD=8E?= =?utf8?q?=E7=94=B5=E9=87=8F=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../bloodpressure/include/BPMainPresenter.h | 1 + .../bloodpressure/src/BPMainPresenter.cpp | 21 +++++++++ .../nativeui/ecg/include/ECGMainPresenter.h | 1 + .../nativeui/ecg/src/ECGMainPresenter.cpp | 12 +++++ .../nativeui/health/HealthMeasureBattery.cpp | 45 +++++++++++++++++++ .../nativeui/health/HealthMeasureBattery.h | 16 +++++++ .../src/notify/charge_notification.cpp | 19 ++++---- 7 files changed, 107 insertions(+), 8 deletions(-) create mode 100644 code/sdk/application/wearable/n9/nativeapp/nativeui/health/HealthMeasureBattery.cpp create mode 100644 code/sdk/application/wearable/n9/nativeapp/nativeui/health/HealthMeasureBattery.h diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/include/BPMainPresenter.h b/code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/include/BPMainPresenter.h index 039664eea..6f1b73a73 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/include/BPMainPresenter.h +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/include/BPMainPresenter.h @@ -47,6 +47,7 @@ private: void RequestStopConfirm(int16_t fromView); void StartMeasureFlow(BPMainView *mainView); void StartCalibrationFlow(BPMainView *mainView, uint8_t round); + bool BlockIfBatteryTooLow(); void StartProgressSession(BPProgressMode mode); void PauseProgressSession(); void ResumeProgressSession(); diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/src/BPMainPresenter.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/src/BPMainPresenter.cpp index 23f714f55..82386720c 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/src/BPMainPresenter.cpp +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/src/BPMainPresenter.cpp @@ -5,6 +5,7 @@ #include "bloodpressure/include/BPValueInputView.h" #include "bloodpressure/include/BPModel.h" #include "bloodpressure/include/BPViewClickIds.h" +#include "health/HealthMeasureBattery.h" #include "bloodpressure/include/BPCalibStopView.h" #include "bloodpressure/include/BPMeasuringView.h" #include "bloodpressure/include/BPAbnormalView.h" @@ -464,7 +465,18 @@ void BPMainPresenter::OnSwipe(UISwipeView &view) { } /** 开始测量流程 */ +bool BPMainPresenter::BlockIfBatteryTooLow() { + if (!IsBatteryTooLowForMeasure()) { + return false; + } + ShowHealthMeasureLowBatteryNotify(); + return true; +} + void BPMainPresenter::StartMeasureFlow(BPMainView *mainView) { + if (BlockIfBatteryTooLow()) { + return; + } int16_t hide = mainView->GetCurrentViewId(); mainView->ChangeView(hide, BP_MEASURING_VIEW); StartProgressSession(BPProgressMode::Measure); @@ -472,6 +484,9 @@ void BPMainPresenter::StartMeasureFlow(BPMainView *mainView) { /** 开始校准流程 */ void BPMainPresenter::StartCalibrationFlow(BPMainView *mainView, uint8_t round) { + if (BlockIfBatteryTooLow()) { + return; + } BPModel *model = BPModel::GetInstance(); model->SetCalibrationRound(round); model->ResetInputValues(); @@ -540,6 +555,9 @@ bool BPMainPresenter::OnClick(UIView &view, const ClickEvent &event) { } /** 处理值确认事件 */ if (viewId == BP_CLICK_VALUE_CONFIRM) { + if (BlockIfBatteryTooLow()) { + return true; + } if (model->GetInputSbp() > model->GetInputDbp()) { mainView->ChangeView(BP_VALUE_CONFIRM_VIEW, BP_CALIBRATING_VIEW); StartProgressSession(BPProgressMode::Calibrate); @@ -592,6 +610,9 @@ bool BPMainPresenter::OnClick(UIView &view, const ClickEvent &event) { if (viewId == BP_CLICK_RETRY) { if (current == BP_ABNORMAL_VIEW) { if (lastTimeoutMode_ == BPProgressMode::Calibrate) { + if (BlockIfBatteryTooLow()) { + return true; + } mainView->ChangeView(BP_ABNORMAL_VIEW, BP_CALIBRATING_VIEW); StartProgressSession(BPProgressMode::Calibrate); } else { diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/include/ECGMainPresenter.h b/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/include/ECGMainPresenter.h index 83fec2a0a..4ef9ce7dc 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/include/ECGMainPresenter.h +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/include/ECGMainPresenter.h @@ -44,6 +44,7 @@ private: bool HandleSwipeBack(); bool IsFlowSubPage(int16_t viewId) const; void StartMeasureFlow(ECGMainView *mainView); + bool BlockIfBatteryTooLow(); void ShowWaitContact(ECGMainView *mainView); void ShowContactGood(ECGMainView *mainView); bool IsWaitingContact(ECGMainView *mainView) const; diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/src/ECGMainPresenter.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/src/ECGMainPresenter.cpp index 4df441162..3b76b7d46 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/src/ECGMainPresenter.cpp +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/ecg/src/ECGMainPresenter.cpp @@ -6,6 +6,7 @@ #include "ecg/include/ECGMeasureCompleteView.h" #include "ecg/include/ECGModel.h" #include "ecg/include/ECGViewClickIds.h" +#include "health/HealthMeasureBattery.h" #include "NativeRegisterManager.h" #include "NativeAbility.h" #include "UiConfig.h" @@ -343,10 +344,21 @@ void ECGMainPresenter::OnMeasureTimerTick() { } void ECGMainPresenter::StartMeasureFlow(ECGMainView *mainView) { + if (BlockIfBatteryTooLow()) { + return; + } ShowWaitContact(mainView); StartMeasureTimer(); } +bool ECGMainPresenter::BlockIfBatteryTooLow() { + if (!IsBatteryTooLowForMeasure()) { + return false; + } + ShowHealthMeasureLowBatteryNotify(); + return true; +} + void ECGMainPresenter::FinishMeasuringFlow(ECGMainView *mainView) { if (measureDataReceived_ == false) { return; diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/health/HealthMeasureBattery.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/health/HealthMeasureBattery.cpp new file mode 100644 index 000000000..cfd45b8a0 --- /dev/null +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/health/HealthMeasureBattery.cpp @@ -0,0 +1,45 @@ +#include "health/HealthMeasureBattery.h" + +#include "broadcast_feature.h" +#include "custom_utils.h" +#include "graphic_service.h" +#include "msg_center.h" +#include "notification_manager.h" +#include "notify/charge_notification.h" + +#ifdef SUPPORT_BATTERY_SERVICE +#include "battery_hal.h" +#endif + +namespace OHOS { + +namespace { + +UIViewGroup *CreateHealthMeasureLowPowerNotifyView() { return lowPowerShow(); } + +void ShowHealthMeasureLowBatteryNotifyImpl() { + uapi_set_screen_on_api(); + set_lowpower_falg(0); + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); + NotificationManager::GetInstance()->ShowNotify( + CreateHealthMeasureLowPowerNotifyView, TOPIC_EVENT_LOWPOWER_ALARM, true); +} + +} // namespace + +bool IsBatteryTooLowForMeasure() { +#ifdef SUPPORT_BATTERY_SERVICE + float voltage = 0.0f; + int percent = battery_get_voltage(&voltage); + return percent < kHealthMeasureMinBatteryPercent; +#else + return false; +#endif +} + +void ShowHealthMeasureLowBatteryNotify() { + // 推迟到下一帧 UI 线程,避免在按钮 OnClick 栈里同步建 Notify 造成点击卡顿 + GraphicService::GetInstance()->PostGraphicEvent(ShowHealthMeasureLowBatteryNotifyImpl); +} + +} // namespace OHOS diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/health/HealthMeasureBattery.h b/code/sdk/application/wearable/n9/nativeapp/nativeui/health/HealthMeasureBattery.h new file mode 100644 index 000000000..187861475 --- /dev/null +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/health/HealthMeasureBattery.h @@ -0,0 +1,16 @@ +#ifndef HEALTH_MEASURE_BATTERY_H +#define HEALTH_MEASURE_BATTERY_H + +namespace OHOS { + +static constexpr int kHealthMeasureMinBatteryPercent = 80; + +/** 电量低于 10% 时不允许开始测量/校准 */ +bool IsBatteryTooLowForMeasure(); + +/** 复用系统低电量充电提醒弹窗(charge_notification::lowPowerShow) */ +void ShowHealthMeasureLowBatteryNotify(); + +} // namespace OHOS + +#endif diff --git a/code/sdk/application/wearable/n9/service/msg_center/src/notify/charge_notification.cpp b/code/sdk/application/wearable/n9/service/msg_center/src/notify/charge_notification.cpp index 64a41836c..9c56845e9 100644 --- a/code/sdk/application/wearable/n9/service/msg_center/src/notify/charge_notification.cpp +++ b/code/sdk/application/wearable/n9/service/msg_center/src/notify/charge_notification.cpp @@ -612,14 +612,17 @@ namespace OHOS UIViewGroup_lowpower->SetTouchable(true); alarm_labelbutton->SetTouchable(true); - ShowUpShutDownAnimatorView(); - if (group) - UIViewGroup_lowpower->Add(group); - if (battery_falg >= 3) - { - group->SetVisible(true); - ShutDownImageAnimatorView->Start(); - ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 关机动画已经开始了不能息屏 + // 充电提醒(flag=0)不需要关机动画资源,避免同步加载 30 帧导致卡顿 + if (battery_falg != 0) { + ShowUpShutDownAnimatorView(); + if (group) + UIViewGroup_lowpower->Add(group); + if (battery_falg >= 3) + { + group->SetVisible(true); + ShutDownImageAnimatorView->Start(); + ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 关机动画已经开始了不能息屏 + } } NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreelowPower); return UIViewGroup_lowpower; -- 2.17.1