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() {}
// 电池进度更新的回调函数
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<unsigned int>(time(0)));
//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); // 更新界面
UIImageView *colon = nullptr;
UIImageView *minute1 = nullptr;
UIImageView *minute2 = nullptr;
+ UIImageView *charge = nullptr;
UILabel *timeLable = nullptr;
UILabel *dateLable = nullptr;
UILabel *weekLable = nullptr;
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;
};
batteryLable = nullptr;
delete progress;
progress = nullptr;
+ delete charge;
+ charge = nullptr;
/* -------------------------------------------------------------------------- */
if (timeLableanimator_ != nullptr)
{