#include "custom_utils.h"
#include "cmsis_os2.h"
#include "linux/delay.h"
+#include "components/ui_circle_progress.h"
+#include "battery_hal.h"
namespace OHOS
{
UIImageView *imageCharge = nullptr;
const char **ShutDownPathsArray{nullptr}; // 关机图片路径数组
ImageAnimatorInfo ShutDownImageInfo[SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; // 关机图像的信息
#define LOW_POWER_BUTTON "LOW_POWER_BUTTON"
- // UIViewGroup *ChargingStatuShow()
- // {
- // // Add ImageView to App
- // if (imageCharge == nullptr)
- // {
- // imageCharge = new UIImageView();
- // }
- // imageCharge->SetPosition(186, 55); // widget's left position and top position
- // imageCharge->Resize(100, 100); // widget's width and height
- // imageCharge->SetViewId("image1"); // Set style
-
- // // Set additional property
- // char *image1imagesPath = "/user/res/Battery/Charge_Icon.bin";
- // imageCharge->SetSrc(image1imagesPath);
-
- // // Add to rootView
- // RootView::GetInstance()->Add(imageCharge);
-
- // if (view_->GetHorCurrentPage() == WATCH_FACE)
- // {
- // imageCharge->SetVisible(true);
- // }
- // }
+ #define CHARGE_GROUP "UIViewGroup_charge"
+
+ // GILROY_BOLD_FONT
+ //充电中 UI
+ UIViewGroup *UIViewGroup_charge =nullptr;
+
+ UICircleProgress *circleProgress1_=nullptr;
+
+ UIImageView *image_circle = nullptr;
+ UIImageView *image_lightning=nullptr;
+
+ UILabelExt *UILabel_time=nullptr;
+ UILabelExt *UILabel_power=nullptr;
+ UILabelExt *UILabel_Chargeing=nullptr;
+
+ osTimerId_t Chargeing_timer= NULL;
+
+ void Chargeing_Timer_CallBack(int data)
+ {
+ float voltage = 0.0F;
+ uint8_t power = 0;
+ power = battery_get_voltage(&voltage);
+
+ char buf[16]={0};
+ sprintf(buf,"%d%c",power,'%');
+ //printf("power:%s\r\n",buf);
+ time_t currtime;
+ struct tm *timeinfo;
+ time(&currtime);
+ timeinfo = localtime(&currtime);
+
+ char time_buf[16]={0};
+ sprintf_s(time_buf,16,"%02d:%02d",timeinfo->tm_hour,timeinfo->tm_min);
+
+ if(UILabel_time)
+ UILabel_time->SetText(time_buf);
+ if(UILabel_power)
+ UILabel_power->SetText(buf);
+
+ RootView::GetInstance()->Invalidate();
+
+
+ }
+
+ void FreeChargePower(void)
+ {
+ if (UIViewGroup_charge != nullptr)
+ {
+ UIViewGroup_charge->RemoveAll();
+ if(circleProgress1_)
+ {
+ delete circleProgress1_;
+ circleProgress1_ = nullptr;
+ }
+ if(image_lightning)
+ {
+ delete image_lightning;
+ image_lightning = nullptr;
+ }
+
+ if(UILabel_time)
+ {
+ delete UILabel_time;
+ UILabel_time = nullptr;
+ }
+
+ if(UILabel_power)
+ {
+ delete UILabel_power;
+ UILabel_power = nullptr;
+
+ }
+ if(UILabel_Chargeing)
+ {
+ delete UILabel_Chargeing;
+ UILabel_Chargeing = nullptr;
+
+ }
+ if(Chargeing_timer)
+ {
+ osTimerStop(Chargeing_timer);
+ osTimerDelete(Chargeing_timer);
+ Chargeing_timer = NULL;
+ }
+
+ RootView::GetInstance()->Remove(UIViewGroup_charge);
+ delete UIViewGroup_charge;
+ UIViewGroup_charge = nullptr;
+ }
+ }
+
+ UIViewGroup * ShowChargeingView(void)
+ {
+
+ if (UIViewGroup_charge == nullptr)
+ {
+ UIViewGroup_charge = new UIViewGroup();
+ UIViewGroup_charge->SetPosition(0, 0, 466, 466);
+ //UIViewGroup_charge->SetStyle(STYLE_BACKGROUND_OPA, 0);
+ }
+ UIViewGroup_charge->SetViewId(CHARGE_GROUP);
+ UIViewGroup_charge->SetTouchable(true);
+ UIView::OnClickListener *UIViewGroup_charge_Click = static_cast<UIView::OnClickListener *>(lowppowrViewEventListener::GetInstance());
+ UIViewGroup_charge->SetOnClickListener(UIViewGroup_charge_Click);
+
+
+ float voltage = 0.0F;
+ uint8_t power = 0;
+ power = battery_get_voltage(&voltage);
+
+ char buf[16]={0};
+ sprintf(buf,"%d%c",power,'%');
+ //printf("power:%s\r\n",buf);
+
+ time_t currtime;
+ struct tm *timeinfo;
+ time(&currtime);
+ timeinfo = localtime(&currtime);
+
+ char time_buf[16]={0};
+ sprintf_s(time_buf,16,"%02d:%02d",timeinfo->tm_hour,timeinfo->tm_min);
+
+ if (circleProgress1_ == nullptr) {
+ circleProgress1_ = new UICircleProgress();
+ }
+ circleProgress1_->SetPosition(123, 123); // widget's left position and top position
+ circleProgress1_->Resize(224, 222); // widget's width and height
+ circleProgress1_->SetViewId("circleProgress1");// Set style
+ circleProgress1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
+
+ // Set additional property
+ // Set BackgroundStyle
+ circleProgress1_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
+ circleProgress1_->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 0x05);
+ circleProgress1_->SetBackgroundStyle(STYLE_BORDER_OPA, 0x07);
+ circleProgress1_->SetBackgroundStyle(STYLE_LINE_OPA, 0x07);
+ circleProgress1_->SetBackgroundStyle(STYLE_LINE_WIDTH, 22);
+ // Set ForegroundStyle
+ circleProgress1_->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xff2195F6);
+ circleProgress1_->SetForegroundStyle(STYLE_BORDER_COLOR, 0xff000000);
+ circleProgress1_->SetForegroundStyle(STYLE_LINE_COLOR, 0xff4FC34C);
+ circleProgress1_->SetForegroundStyle(STYLE_LINE_WIDTH, 22);
+ circleProgress1_->SetCenterPosition(111, 109);
+ circleProgress1_->SetRadius(108);
+ circleProgress1_->SetEndAngle(359);
+ circleProgress1_->SetValue(power);
+ circleProgress1_->SetVisible(true);
+ circleProgress1_->SetCapType(CAP_ROUND);
+
+
+ if (image_lightning == nullptr) {
+ image_lightning = new UIImageView();
+ }
+ image_lightning->SetPosition(207, 176); // widget's left position and top position
+ image_lightning->Resize(70, 60); // widget's width and height
+ image_lightning->SetViewId("image2");// Set style
+ image_lightning->SetStyle(STYLE_BORDER_COLOR, 0xff191919);
+ char* image2imagesPath = "/user/res/solar-energy 1.bin";
+ image_lightning->SetSrc(image2imagesPath);
+ image_lightning->SetVisible(true);
+
+
+ if (image_circle == nullptr) {
+ image_circle = new UIImageView();
+ }
+ image_circle->SetPosition(126, 125); // widget's left position and top position
+ image_circle->Resize(194, 194); // widget's width and height
+ image_circle->SetViewId("image1");// Set style
+ char* image1imagesPath = "/user/res/Ellipse 37.bin";
+ image_circle->SetSrc(image1imagesPath);
+ image_circle->SetVisible(true);
+
+ if (UILabel_power == nullptr) {
+ UILabel_power = new UILabelExt();
+ }
+ UILabel_power->SetPosition(133, 252); // widget's left position and top position
+ UILabel_power->Resize(200, 60); // widget's width and height
+ UILabel_power->SetViewId("label5");// Set style
+ UILabel_power->SetStyle(STYLE_TEXT_FONT, 40);
+
+ UILabel_power->SetText(buf);
+ UILabel_power->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
+ UILabel_power->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ UILabel_power->SetRollSpeed(0);
+ UILabel_power->SetFont(GILROY_BOLD_FONT, 40);
+ UILabel_power->SetVisible(true);
+
+
+ if (UILabel_Chargeing == nullptr) {
+ UILabel_Chargeing = new UILabelExt();
+ }
+ UILabel_Chargeing->SetPosition(133, 356); // widget's left position and top position
+ UILabel_Chargeing->Resize(200, 60); // widget's width and height
+ UILabel_Chargeing->SetViewId("label4");// Set style
+ UILabel_Chargeing->SetStyle(STYLE_TEXT_FONT, 30);
+ UILabel_Chargeing->SetText("正在充电");
+ UILabel_Chargeing->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
+ UILabel_Chargeing->SetTextColor(Color::GetColorFromRGBA(0x4F, 0xC3, 0x4C, 0xff));
+ UILabel_Chargeing->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ UILabel_Chargeing->SetRollSpeed(0);
+ UILabel_Chargeing->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ UILabel_Chargeing->SetVisible(true);
+
+
+ if (UILabel_time == nullptr) {
+ UILabel_time = new UILabelExt();
+ }
+ UILabel_time->SetPosition(173, 65); // widget's left position and top position
+ UILabel_time->Resize(120, 48); // widget's width and height
+ UILabel_time->SetViewId("label3");// Set style
+ UILabel_time->SetStyle(STYLE_TEXT_FONT, 40);
+ // Set additional property
+ UILabel_time->SetText(time_buf);
+ UILabel_time->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
+ UILabel_time->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ UILabel_time->SetRollSpeed(0);
+ UILabel_time->SetFont(GILROY_BOLD_FONT, 40);
+ UILabel_time->SetVisible(true);
+
+ osStatus_t retTimer;
+ Chargeing_timer = osTimerNew((osTimerFunc_t)Chargeing_Timer_CallBack, osTimerPeriodic, NULL, NULL);
+ retTimer = osTimerStart(Chargeing_timer, 1000*1);
+ if (retTimer != osOK && Chargeing_timer != NULL) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+ "StartCallTimer osTimerStart failed, ret = %lx!!", retTimer);
+ osTimerDelete(Chargeing_timer);
+ Chargeing_timer = NULL;
+ }
+
+
+
+ UIViewGroup_charge->Add(image_lightning);
+ UIViewGroup_charge->Add(image_circle);
+
+
+
+ UIViewGroup_charge->Add(circleProgress1_);
+
+ UIViewGroup_charge->Add(UILabel_time);
+ UIViewGroup_charge->Add(UILabel_power);
+ UIViewGroup_charge->Add(UILabel_Chargeing);
+
+ return UIViewGroup_charge;
+ }
+
static void FreeImagePathsArray(const char **imagePaths, const int numImages)
{
return ;
}
ShutDownImageAnimatorView->Start();
+
+ start_shutdown_or_reboot();
+ shutdown_reboot_prejobs();
}
{
group->SetVisible(true);
ShutDownImageAnimatorView->Start();
+ start_shutdown_or_reboot();
+ shutdown_reboot_prejobs();
}
return UIViewGroup_lowpower;
}
}
}
+ if(strcmp(view.GetViewId(),CHARGE_GROUP)==0)
+ {
+ NotificationManager::GetInstance()->StopNotify();
+ }
return true;
UNUSED(event);
}