From b32b52ae71c04b8eff4d91e4909e145f66364ef3 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Sun, 18 Feb 2024 19:33:04 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E5=85=85=E7=94=B5=E7=9B=91?= =?utf8?q?=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/dial/include/Digital_clockView.h | 42 +++++++++++------- .../nativeui/dial/src/Digital_clockView.cpp | 17 +++++-- .../fs/user/res/Battery/Battery_Charge.bin | Bin 0 -> 504 bytes .../res/Battery/{Icon.bin => Charge_Icon.bin} | Bin 4 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Battery/Battery_Charge.bin rename code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Battery/{Icon.bin => Charge_Icon.bin} (100%) diff --git a/code/sdk/application/wearable/fd230app/nativeui/dial/include/Digital_clockView.h b/code/sdk/application/wearable/fd230app/nativeui/dial/include/Digital_clockView.h index 2540a95a3..69630872e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/dial/include/Digital_clockView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/dial/include/Digital_clockView.h @@ -152,11 +152,12 @@ namespace OHOS class myProgressCallback : public AnimatorCallback { private: + UIImageView *charge{nullptr}; // 充电闪电图标 UIBoxProgress *progress{nullptr}; // 电池进度条控件指针 UILabel *batterylabel{nullptr}; // 显示电池百分比的文本控件指针 public: - explicit myProgressCallback(UIBoxProgress *progress, UILabel *batterylabel) : progress(progress), batterylabel(batterylabel) {} + explicit myProgressCallback(UIBoxProgress *progress, UILabel *batterylabel, UIImageView *charge) : progress(progress), batterylabel(batterylabel), charge(charge) {} ~myProgressCallback() {} // 电池进度更新的回调函数 @@ -166,6 +167,18 @@ namespace OHOS float voltage = 0.0F; uint8_t value = 0; value = battery_get_voltage(&voltage); + const char *progress1ForeImageSrc = nullptr; + const char *progress1BackImageSrc = nullptr; + if (get_charge_stat()) + { + char *imageimagesPath = "/user/res/Battery/Charge_Icon.bin"; + charge->SetSrc(imageimagesPath); + progress1ForeImageSrc = "/user/res/Battery/Battery_Charge.bin"; // 充电图片路径 + charge->SetVisible(true); + } + else + { + charge->SetVisible(false); #if 0 //设置种子 srand(static_cast(time(0))); @@ -174,21 +187,19 @@ namespace OHOS //printf("value:%d\n", value); //根据电池电量值选择相应的进度条前景图片 #endif - const char *progress1ForeImageSrc = nullptr; - const char *progress1BackImageSrc = nullptr; - if (value <= 10) - { - progress1ForeImageSrc = "/user/res/Battery/Battery_Limit.bin"; // 低电量图片路径 - } - else if (value <= 20) - { - progress1ForeImageSrc = "/user/res/Battery/Battery_Save.bin"; // 中等电量图片路径 - } - else - { - progress1ForeImageSrc = "/user/res/Battery/Battery_Nomoal.bin"; // 正常电量图片路径 + if (value <= 10) + { + progress1ForeImageSrc = "/user/res/Battery/Battery_Limit.bin"; // 低电量图片路径 + } + else if (value <= 20) + { + progress1ForeImageSrc = "/user/res/Battery/Battery_Save.bin"; // 中等电量图片路径 + } + else + { + progress1ForeImageSrc = "/user/res/Battery/Battery_Nomoal.bin"; // 正常电量图片路径 + } } - // 设置进度条的前景和背景图片,并更新进度值 progress->SetImage(progress1ForeImageSrc, progress1BackImageSrc); progress->SetValue(value); // 更新界面 @@ -344,6 +355,7 @@ namespace OHOS UIImageView *colon = nullptr; UIImageView *minute1 = nullptr; UIImageView *minute2 = nullptr; + UIImageView *charge = nullptr; UILabel *timeLable = nullptr; UILabel *dateLable = nullptr; UILabel *weekLable = nullptr; diff --git a/code/sdk/application/wearable/fd230app/nativeui/dial/src/Digital_clockView.cpp b/code/sdk/application/wearable/fd230app/nativeui/dial/src/Digital_clockView.cpp index b32341471..1b3cb24bf 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/dial/src/Digital_clockView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/dial/src/Digital_clockView.cpp @@ -639,13 +639,22 @@ namespace OHOS batteryLable->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); batteryLable->SetRollSpeed(0); batteryLable->SetFont(DEFAULT_VECTOR_FONT_FILENAME, fontsize); - // Add to rootView Add(batteryLable); // batteryLable->SetVisible(true); - progress1callback_ = new myProgressCallback(progress, batteryLable); - progress1animator_ = new Animator(progress1callback_, progress, 10000, true); + // Add ImageView to App + if (charge == nullptr) + { + charge = new UIImageView(); + } + charge->SetPosition(190, 27); // widget's left position and top position + charge->Resize(100, 100); // widget's width and height + charge->SetViewId("image1"); // Set style + Add(charge); + + progress1callback_ = new myProgressCallback(progress, batteryLable, charge); + progress1animator_ = new Animator(progress1callback_, progress, 1000, true); progress1animator_->Start(); return true; }; @@ -755,6 +764,8 @@ namespace OHOS batteryLable = nullptr; delete progress; progress = nullptr; + delete charge; + charge = nullptr; /* -------------------------------------------------------------------------- */ if (timeLableanimator_ != nullptr) { diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Battery/Battery_Charge.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Battery/Battery_Charge.bin new file mode 100644 index 0000000000000000000000000000000000000000..467ba1ff63ff04553a6169947733429397a2f969 GIT binary patch literal 504 zcmZQ@WMGhI5N7z#%pva+pvnLPj+x2_|Nj?vQJMBqzTyA>y?_4x2LmOgjT?P@{{JV$ zcWiY1ll*t)pa1oYAR}2EI|TxPX59yx$-?lT{|_PkBVFDxQwb4X&wu|#4-aQX*QDg* tGaC#U3>ega0gNsW4F7-0|7ZUD-v|tUU>rN1