From: Caisking <3449750381@qq.com> Date: Sun, 18 Feb 2024 11:33:04 +0000 (+0800) Subject: 增加充电监测 X-Git-Tag: release_V1.2.70_20241020_135402~1301^2~1 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=b32b52ae71c04b8eff4d91e4909e145f66364ef3;p=mirrors%2FFD230.git 增加充电监测 --- 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 000000000..467ba1ff6 Binary files /dev/null and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Battery/Battery_Charge.bin differ diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Battery/Icon.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Battery/Charge_Icon.bin similarity index 100% rename from code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Battery/Icon.bin rename to code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/Battery/Charge_Icon.bin