From 3ee1d369f9ceb48af9c159a452b161879ce0ae42 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Wed, 17 Jul 2024 16:20:22 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E8=A1=A8=E7=9B=98=E7=94=B5?= =?utf8?q?=E9=87=8F=E5=8A=A8=E6=80=81=E5=8F=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../main/include/dial/DialBoxProgressView.h | 39 ++++++++---- .../main/src/dial/DialBoxProgressView.cpp | 61 ++++++++++++++++--- 2 files changed, 79 insertions(+), 21 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialBoxProgressView.h b/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialBoxProgressView.h index b77772284..068a9cd5c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialBoxProgressView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialBoxProgressView.h @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-05-30 15:59:37 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-07-17 15:01:17 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/main/include/dial/DialBoxProgressView.h + */ /* * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ @@ -8,19 +14,26 @@ #include "DialView.h" #include "components/ui_box_progress.h" -namespace OHOS { -class DialBoxProgressView : public UIBoxProgress, public DialView { -public: - DialBoxProgressView(); - ~DialBoxProgressView() override; - static DialBoxProgressView* GetInstance() +namespace OHOS +{ + class DialBoxProgressView : public UIBoxProgress, public DialView { - static DialBoxProgressView instance; - return &instance; - } - void HandleFloatData(float data) override; -private: - int32_t value_ = -1; -}; + public: + DialBoxProgressView(); + ~DialBoxProgressView() override; + static DialBoxProgressView *GetInstance() + { + static DialBoxProgressView instance; + return &instance; + } + void HandleFloatData(float data) override; + void UpdataChargColor(); + void UpdateBatteryColor(); + void SetViewColor(int64_t color); + + private: + int32_t value_ = -1; + int64_t color_ = Color::White().full; + }; } #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialBoxProgressView.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialBoxProgressView.cpp index ce5c7569b..da4911a2c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialBoxProgressView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialBoxProgressView.cpp @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-04-15 10:55:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-07-17 14:54:10 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/main/src/dial/DialBoxProgressView.cpp + */ /* * Copyright (c) @CompanyNameMagicTag. 2023. All rights reserved. */ @@ -7,10 +13,15 @@ #include "battery_hal.h" extern uint8_t battery_get_voltage(float *voltage); +// 定义电量宏 +#define BATTERY_LOW_THRESHOLD 10 +#define BATTERY_MEDIUM_THRESHOLD 20 + namespace OHOS { DialBoxProgressView::DialBoxProgressView(void) { + value_ = 0; } DialBoxProgressView::~DialBoxProgressView(void) @@ -20,7 +31,7 @@ namespace OHOS void DialBoxProgressView::HandleFloatData(float data) { float ratio = data; - //WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DialBoxProgressView:%d", data); + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DialBoxProgressView:%d", data); if (ratio > 1.0f) { ratio = 1.0f; @@ -30,17 +41,51 @@ namespace OHOS ratio = 0.0f; } int32_t value = ratio * (GetRangeMax() - GetRangeMin()); + + // 更新电池颜色 + UpdateBatteryColor(); + if (value_ == value) { return; } -#if 1 - // 获取电池电压值 - float voltage = 0.0F; - value = battery_get_voltage(&voltage); + value_ = value; -#endif - //WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"battery_get_value:%d", value_); SetValue(value_); } -} + + void DialBoxProgressView::UpdateBatteryColor() + { + bool isCharging = get_charge_stat(); // 获取充电状态 + + if (isCharging) + { + SetViewColor(Color::Green().full); // 充电状态为绿色 + return; + } + else + { + if (value_ <= BATTERY_LOW_THRESHOLD) + { + SetViewColor(Color::Red().full); + } + else if (BATTERY_LOW_THRESHOLD < value_ && value_ <= BATTERY_MEDIUM_THRESHOLD) + { + SetViewColor(Color::Yellow().full); + } + else + { + SetViewColor(Color::White().full); + } + } + } + void DialBoxProgressView::SetViewColor(int64_t color) + { + if (color == color_) + { + return; + } + color_ = color; + SetForegroundStyle(STYLE_BACKGROUND_COLOR, color_); + } +} \ No newline at end of file -- 2.17.1