#include "components/ui_image_view.h"
#include "components/ui_label.h"
#include "components/ui_label_ext.h"
-#include "components/ui_label_button_ext.h"
+#include "components/ui_label_button_ext.h"
#ifdef SUPPORT_BATTERY_SERVICE
#include "battery_service.h"
#include "battery_hal.h"
#include "uicomponents/UIComponents.h"
#include "charge_notification.h"
-//#include "ui_resource_string.h"
+// #include "ui_resource_string.h"
namespace OHOS
{
UIImageView *imageCharge = nullptr;
- UIViewGroup *UIViewGroup_lowpower=nullptr;
- UIImageView *alarm_img=nullptr;
- UILabelExt *alarm_UILabel=nullptr;
- UILabelButtonExt *alarm_labelbutton=nullptr;
- UIViewGroup *group=nullptr;
- UIImageAnimatorView *ShutDownImageAnimatorView=nullptr;
- static constexpr char *ShutDownPaths = "/user/res/RebootAndShutDown/ShutDown/"; //关机图片路径
- #define SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES 30 // 图片帧数
- static int16_t SHUTDOWN_IMAGE_ANIMATOR_TIME = 130; // 图片更新间隔
-
+ UIViewGroup *UIViewGroup_lowpower = nullptr;
+ UIImageView *alarm_img = nullptr;
+ UILabelExt *alarm_UILabel = nullptr;
+ UILabelButtonExt *alarm_labelbutton = nullptr;
+ UIViewGroup *group = nullptr;
+ UIImageAnimatorView *ShutDownImageAnimatorView = nullptr;
+ static constexpr char *ShutDownPaths = "/user/res/RebootAndShutDown/ShutDown/"; // 关机图片路径
+ #define SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES 30 // 图片帧数
+ static int16_t SHUTDOWN_IMAGE_ANIMATOR_TIME = 130; // 图片更新间隔
+
static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_X = 0;
static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_Y = 0;
static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_W = 466;
static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_H = 466;
- const ImageInfo **ShutDownInfoArray{nullptr}; // 关机图片路径数组
+ const ImageInfo **ShutDownInfoArray{nullptr}; // 关机图片路径数组
ImageAnimatorInfo ShutDownImageInfo[SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; // 关机图像的信息
#define LOW_POWER_BUTTON "LOW_POWER_BUTTON"
#define CHARGE_GROUP "UIViewGroup_charge"
- // GILROY_BOLD_FONT
- //充电中 UI
- UIViewGroup *UIViewGroup_charge =nullptr;
+ // GILROY_BOLD_FONT
+ // 充电中 UI
+ UIViewGroup *UIViewGroup_charge = nullptr;
UICircleProgress *batteryprogress = nullptr;
UIImageView *image_circle = nullptr;
- UIImageView *image_lightning=nullptr;
-
- UILabelExt *UILabel_time=nullptr;
- UILabelExt *UILabel_power=nullptr;
- UILabelExt *UILabel_Chargeing=nullptr;
+ UIImageView *image_lightning = nullptr;
+
+ UILabelExt *UILabel_time = nullptr;
+ UILabelExt *UILabel_power = nullptr;
+ UILabelExt *UILabel_Chargeing = nullptr;
- osTimerId_t Chargeing_timer= NULL;
+ osTimerId_t Chargeing_timer = NULL;
+ static OHOS::RootView::OnKeyActListener *g_onKeyActListener = nullptr;
// 刷新回调
- void Chargeing_Timer_CallBack(int data) {
- if (UIViewGroup_charge == nullptr || UILabel_Chargeing == nullptr ||
- UILabel_power == nullptr || UILabel_time == nullptr ||
- batteryprogress== nullptr) {
- return;
- }
-
- float voltage = 0.0F;
- uint8_t power = 0;
- #ifdef SUPPORT_BATTERY_SERVICE
- power = battery_get_voltage(&voltage);
- #endif
-
- // 使用 std::to_string 生成电池电量字符串
- std::string powerstr = std::to_string(power) + "%";
-
- // 获取当前时间
- time_t seconds = time(nullptr);
- struct tm pTM;
- localtime_r(&seconds, &pTM); // 使用 localtime_r 以确保线程安全
-
- // 解析时间并格式化为字符串
- std::string stringtime =
- (pTM.tm_hour < 10 ? "0" : "") + std::to_string(pTM.tm_hour) + ":" +
- (pTM.tm_min < 10 ? "0" : "") + std::to_string(pTM.tm_min);
-
- // 更新充电状态标签
- if (UILabel_Chargeing) {
- if (power == 100) {
- UILabel_Chargeing->SetTextId(STR_CHARG_DOWN); // TODO: 增加多国语言
- } else {
- UILabel_Chargeing->SetTextId(STR_CHAEGING);
- // UILabel_Chargeing->SetTextId(STR_CHARGE);
+ void Chargeing_Timer_CallBack(int data)
+ {
+ if (UIViewGroup_charge == nullptr || UILabel_Chargeing == nullptr ||
+ UILabel_power == nullptr || UILabel_time == nullptr ||
+ batteryprogress == nullptr)
+ {
+ return;
+ }
+
+ float voltage = 0.0F;
+ uint8_t power = 0;
+#ifdef SUPPORT_BATTERY_SERVICE
+ power = battery_get_voltage(&voltage);
+#endif
+
+ // 使用 std::to_string 生成电池电量字符串
+ std::string powerstr = std::to_string(power) + "%";
+
+ // 获取当前时间
+ time_t seconds = time(nullptr);
+ struct tm pTM;
+ localtime_r(&seconds, &pTM); // 使用 localtime_r 以确保线程安全
+
+ // 解析时间并格式化为字符串
+ std::string stringtime =
+ (pTM.tm_hour < 10 ? "0" : "") + std::to_string(pTM.tm_hour) + ":" +
+ (pTM.tm_min < 10 ? "0" : "") + std::to_string(pTM.tm_min);
+
+ // 更新充电状态标签
+ if (UILabel_Chargeing)
+ {
+ if (power == 100)
+ {
+ UILabel_Chargeing->SetTextId(STR_CHARG_DOWN); // TODO: 增加多国语言
+ }
+ else
+ {
+ UILabel_Chargeing->SetTextId(STR_CHAEGING);
+ // UILabel_Chargeing->SetTextId(STR_CHARGE);
+ }
+ UILabel_Chargeing->Invalidate();
+ }
+
+ // 刷新时间标签
+ if (UILabel_time)
+ {
+ UILabel_time->SetText(stringtime.c_str());
+ UILabel_time->Invalidate();
+ }
+
+ // 刷新电池百分比标签
+ if (UILabel_power)
+ {
+ UILabel_power->SetText(powerstr.c_str());
+ UILabel_power->Invalidate();
+ }
+
+ // 刷新进度条
+ if (batteryprogress)
+ {
+ batteryprogress->SetValue(power);
+ batteryprogress->Invalidate();
}
- UILabel_Chargeing->Invalidate();
- }
-
- // 刷新时间标签
- if (UILabel_time) {
- UILabel_time->SetText(stringtime.c_str());
- UILabel_time->Invalidate();
- }
-
- // 刷新电池百分比标签
- if (UILabel_power) {
- UILabel_power->SetText(powerstr.c_str());
- UILabel_power->Invalidate();
- }
-
- // 刷新进度条
- if (batteryprogress) {
- batteryprogress->SetValue(power);
- batteryprogress->Invalidate();
- }
}
bool is_UIViewGroup_charge(void)
{
- if(UIViewGroup_charge != nullptr)
+ if (UIViewGroup_charge != nullptr)
{
return true;
}
void FreeChargePower(void)
{
- if (UIViewGroup_charge != nullptr)
- {
-
- if(Chargeing_timer)
+ if (UIViewGroup_charge != nullptr)
{
- osTimerStop(Chargeing_timer);
- osTimerDelete(Chargeing_timer);
- Chargeing_timer = NULL;
- }
- UIViewGroup_charge->RemoveAll();
+ if (Chargeing_timer)
+ {
+ osTimerStop(Chargeing_timer);
+ osTimerDelete(Chargeing_timer);
+ Chargeing_timer = NULL;
+ }
- if (batteryprogress) {
- delete batteryprogress;
- batteryprogress = nullptr;
- }
- if(image_lightning)
- {
- delete image_lightning;
- image_lightning = nullptr;
- }
+ UIViewGroup_charge->RemoveAll();
- if(UILabel_time)
- {
- delete UILabel_time;
- UILabel_time = nullptr;
- }
+ if (batteryprogress)
+ {
+ delete batteryprogress;
+ batteryprogress = nullptr;
+ }
+ if (image_lightning)
+ {
+ delete image_lightning;
+ image_lightning = nullptr;
+ }
- if(UILabel_power)
- {
- delete UILabel_power;
- UILabel_power = nullptr;
+ if (UILabel_time)
+ {
+ delete UILabel_time;
+ UILabel_time = nullptr;
+ }
- }
- if(UILabel_Chargeing)
- {
- delete UILabel_Chargeing;
- UILabel_Chargeing = nullptr;
+ if (UILabel_power)
+ {
+ delete UILabel_power;
+ UILabel_power = nullptr;
+ }
+ if (UILabel_Chargeing)
+ {
+ delete UILabel_Chargeing;
+ UILabel_Chargeing = nullptr;
+ }
- }
-
-
- RootView::GetInstance()->Remove(UIViewGroup_charge);
- delete UIViewGroup_charge;
- UIViewGroup_charge = nullptr;
+ RootView::GetInstance()->SetOnKeyActListener(g_onKeyActListener);
+ RootView::GetInstance()->Remove(UIViewGroup_charge);
+ delete UIViewGroup_charge;
+ UIViewGroup_charge = nullptr;
}
}
- UIViewGroup * ShowChargeingView(void)
+ UIViewGroup *ShowChargeingView(void)
{
-
- if (UIViewGroup_charge == nullptr)
+
+ if (UIViewGroup_charge == nullptr)
{
UIViewGroup_charge = new UIViewGroup();
UIViewGroup_charge->SetPosition(0, 0, 466, 466);
- //UIViewGroup_charge->SetStyle(STYLE_BACKGROUND_OPA, 0);
+ // 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;
- #ifdef SUPPORT_BATTERY_SERVICE
+#ifdef SUPPORT_BATTERY_SERVICE
power = battery_get_voltage(&voltage);
- #endif
-
- char buf[16]={0};
- sprintf(buf,"%d%c",power,'%');
- //printf("power:%s\r\n",buf);
+#endif
+
+ 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);
+ char time_buf[16] = {0};
+ sprintf_s(time_buf, 16, "%02d:%02d", timeinfo->tm_hour, timeinfo->tm_min);
- if (batteryprogress == nullptr) {
- batteryprogress = new UICircleProgress();
+ if (batteryprogress == nullptr)
+ {
+ batteryprogress = new UICircleProgress();
}
batteryprogress->SetPosition(
- 123, 123); // widget's left position and top position
- batteryprogress->Resize(224, 222); // widget's width and height
+ 123, 123); // widget's left position and top position
+ batteryprogress->Resize(224, 222); // widget's width and height
batteryprogress->SetViewId("circleProgress1"); // Set style
batteryprogress->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
batteryprogress->SetVisible(true);
// batteryprogress->SetCapType(CAP_ROUND); 不使用圆形边缘
- if (image_lightning == nullptr) {
- image_lightning = new UIImageView();
+ 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->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";
+ char *image2imagesPath = "/user/res/solar-energy_1.bin";
image_lightning->SetSrc(image2imagesPath);
image_lightning->SetVisible(true);
-
- if (image_circle == nullptr) {
+ 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->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) {
+ 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->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->SetRollSpeed(0);
UILabel_power->SetFont(GILROY_BOLD_FONT, 40);
UILabel_power->SetVisible(true);
-
- if (UILabel_Chargeing == nullptr) {
+ 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->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->SetTextId(STR_CHARGE);
UILabel_Chargeing->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30);
UILabel_Chargeing->SetVisible(true);
-
- if (UILabel_time == nullptr) {
+ 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->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);
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) {
+ retTimer = osTimerStart(Chargeing_timer, 1000 * 1);
+ if (retTimer != osOK && Chargeing_timer != NULL)
+ {
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
- "StartCallTimer osTimerStart failed, ret = %lx!!", retTimer);
+ "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(UILabel_power);
UIViewGroup_charge->Add(UILabel_Chargeing);
+ g_onKeyActListener = RootView::GetInstance()->GetOnKeyActListener();
+ RootView::GetInstance()->SetOnKeyActListener(lowppowrViewEventListener::GetInstance());
NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeChargePower);
return UIViewGroup_charge;
}
-
void ShowUpShutDownAnimatorView()
{
group = new UIViewGroup();
if (group == nullptr)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail");
- return ;
+ return;
}
group->SetPosition(0, 0, 466, 466);
if (ShutDownImageAnimatorView == nullptr)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView new ShutDownImageAnimatorView fail");
- return ;
+ return;
}
-
+
for (uint8_t i = 0; i < SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++)
{
ShutDownImageInfo[i].imageInfo = (ShutDownInfoArray[i]);
ShutDownImageAnimatorView->SetImageAnimatorSrc(ShutDownImageInfo, SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, SHUTDOWN_IMAGE_ANIMATOR_TIME);
ShutDownImageAnimatorView->SetRepeat(false);
ShutDownImageAnimatorView->SetRepeatTimes(1);
-
}
- UIImageAnimatorView::AnimatorStopListener *stoplistener = static_cast<UIImageAnimatorView::AnimatorStopListener *>(lowppowrAnimatorStopListener::GetInstance());
+ UIImageAnimatorView::AnimatorStopListener *stoplistener = static_cast<UIImageAnimatorView::AnimatorStopListener *>(lowppowrAnimatorStopListener::GetInstance());
ShutDownImageAnimatorView->SetAnimatorStopListener(stoplistener);
if (stoplistener == nullptr)
{
}
ShutDownImageAnimatorView->SetVisible(true);
- //ShutDownImageAnimatorView->Start();
+ // ShutDownImageAnimatorView->Start();
group->SetVisible(false);
group->Add(ShutDownImageAnimatorView);
- return ;
+ return;
}
- static uint8_t battery_falg=0;
+ static uint8_t battery_falg = 0;
void set_lowpower_falg(uint8_t falg)
{
- battery_falg=falg;
+ battery_falg = falg;
}
- osTimerId_t low_power_timer= NULL;
- void FreelowPower(void)
+ osTimerId_t low_power_timer = NULL;
+ void FreelowPower(void)
{
- if (UIViewGroup_lowpower != nullptr)
- {
- UIViewGroup_lowpower->RemoveAll();
- if(alarm_img)
- {
- delete alarm_img;
- alarm_img = nullptr;
- }
- if(alarm_UILabel)
- {
- delete alarm_UILabel;
- alarm_UILabel = nullptr;
- }
- if(alarm_labelbutton)
- {
- delete alarm_labelbutton;
- alarm_labelbutton = nullptr;
- }
- if(group)
+ if (UIViewGroup_lowpower != nullptr)
{
- group->RemoveAll();
- ShutDownImageAnimatorView->Stop();
- if(ShutDownImageAnimatorView)
+ UIViewGroup_lowpower->RemoveAll();
+ if (alarm_img)
+ {
+ delete alarm_img;
+ alarm_img = nullptr;
+ }
+ if (alarm_UILabel)
+ {
+ delete alarm_UILabel;
+ alarm_UILabel = nullptr;
+ }
+ if (alarm_labelbutton)
+ {
+ delete alarm_labelbutton;
+ alarm_labelbutton = nullptr;
+ }
+ if (group)
{
- delete ShutDownImageAnimatorView;
- ShutDownImageAnimatorView = nullptr;
+ group->RemoveAll();
+ ShutDownImageAnimatorView->Stop();
+ if (ShutDownImageAnimatorView)
+ {
+ delete ShutDownImageAnimatorView;
+ ShutDownImageAnimatorView = nullptr;
+ }
+ FreeImageInfoArray(ShutDownInfoArray, ShutDownPaths, SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
+ delete group;
+ group = nullptr;
}
- FreeImageInfoArray(ShutDownInfoArray,ShutDownPaths,SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
- delete group;
- group = nullptr;
+ // FreeImagePathsArray(ShutDownPathsArray,SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
- }
- //FreeImagePathsArray(ShutDownPathsArray,SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
-
- RootView::GetInstance()->Remove(UIViewGroup_lowpower);
- delete UIViewGroup_lowpower;
- UIViewGroup_lowpower = nullptr;
+ RootView::GetInstance()->Remove(UIViewGroup_lowpower);
+ delete UIViewGroup_lowpower;
+ UIViewGroup_lowpower = nullptr;
}
}
- static uint8_t timer_falg_low_power=6;
+ static uint8_t timer_falg_low_power = 6;
void low_power_TimerCallBack(int data)
{
- //uapi_poweroff_device(); // 关机
- if(timer_falg_low_power)
+ // uapi_poweroff_device(); // 关机
+ if (timer_falg_low_power)
{
timer_falg_low_power--;
- // char buf[34]={0};
+ // char buf[34]={0};
// sprintf(buf,"电量过低%ds后将自动关机",timer_falg_low_power);
// alarm_UILabel->GetText();
// printf("%s\r\n",alarm_UILabel);
UpdateLabel(alarm_UILabel, timer_falg_low_power, STR_LOW_POWER_NOTIF_2);
alarm_UILabel->Invalidate();
- if(timer_falg_low_power==0)
+ if (timer_falg_low_power == 0)
{
alarm_UILabel->SetVisible(false);
- #ifdef SUPPORT_BATTERY_SERVICE
+#ifdef SUPPORT_BATTERY_SERVICE
low_power_play_toUI(3);
- #endif
+#endif
}
-
}
-
}
void low_power_play()
{
- //uapi_poweroff_device(); // 关机
-
- //osTimerStop(low_power_timer);
+ // uapi_poweroff_device(); // 关机
+
+ // osTimerStop(low_power_timer);
group->SetVisible(true);
- UIImageAnimatorView::AnimatorStopListener *stoplistener = static_cast<UIImageAnimatorView::AnimatorStopListener *>(lowppowrAnimatorStopListener::GetInstance());
+ UIImageAnimatorView::AnimatorStopListener *stoplistener = static_cast<UIImageAnimatorView::AnimatorStopListener *>(lowppowrAnimatorStopListener::GetInstance());
ShutDownImageAnimatorView->SetAnimatorStopListener(stoplistener);
if (stoplistener == nullptr)
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to Create stoplistener!!");
- return ;
+ return;
}
ShutDownImageAnimatorView->Start();
- #ifdef SUPPORT_BATTERY_SERVICE
- set_lowpower_show(1,0);
- #endif
-
-
-
+#ifdef SUPPORT_BATTERY_SERVICE
+ set_lowpower_show(1, 0);
+#endif
}
UIViewGroup *lowPowerShow()
{
- if (UIViewGroup_lowpower == nullptr) {
+ if (UIViewGroup_lowpower == nullptr)
+ {
UIViewGroup_lowpower = new UIViewGroup();
UIViewGroup_lowpower->SetPosition(0, 0, 466, 466);
- //UIViewGroup_lowpower->SetStyle(STYLE_BACKGROUND_OPA, 0);
+ // UIViewGroup_lowpower->SetStyle(STYLE_BACKGROUND_OPA, 0);
}
// Add ImageView to App
- if (alarm_img == nullptr) {
+ if (alarm_img == nullptr)
+ {
alarm_img = new UIImageView();
}
- alarm_img->SetPosition(171, 155); // widget's left position and top position
- alarm_img->Resize(100, 100); // widget's width and height
- alarm_img->SetViewId("image1");// Set style
+ alarm_img->SetPosition(171, 155); // widget's left position and top position
+ alarm_img->Resize(100, 100); // widget's width and height
+ alarm_img->SetViewId("image1"); // Set style
// Set additional property
const char *imageimagesPath = "/user/res/lowpower.bin";
alarm_img->SetVisible(true);
// Add Label to App
- if (alarm_UILabel == nullptr) {
+ if (alarm_UILabel == nullptr)
+ {
alarm_UILabel = new UILabelExt();
}
- alarm_UILabel->SetPosition(101, 215); // widget's left position and top position
- alarm_UILabel->Resize(466, 212); // widget's width and height
- alarm_UILabel->SetViewId("label1");// Set style
+ alarm_UILabel->SetPosition(101, 215); // widget's left position and top position
+ alarm_UILabel->Resize(466, 212); // widget's width and height
+ alarm_UILabel->SetViewId("label1"); // Set style
alarm_UILabel->SetStyle(STYLE_TEXT_FONT, 30);
// Set additional property
- if(battery_falg==0)
+ if (battery_falg == 0)
{
- alarm_UILabel->SetPosition(110, 252); // widget's left position and top position
- alarm_UILabel->Resize(245, 70); // widget's width and height
+ alarm_UILabel->SetPosition(110, 252); // widget's left position and top position
+ alarm_UILabel->Resize(245, 70); // widget's width and height
// alarm_UILabel->SetText("当前电量低于10%请及时充电");
alarm_UILabel->SetTextId(STR_LOW_POWER_NOTIF_1);
-
+
alarm_UILabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
alarm_UILabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
alarm_UILabel->SetRollSpeed(0);
alarm_UILabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
- #ifdef SUPPORT_BATTERY_SERVICE
- set_lowpower_show(0,0);
- #endif
+#ifdef SUPPORT_BATTERY_SERVICE
+ set_lowpower_show(0, 0);
+#endif
}
// Set additional property
- if(battery_falg==1)
+ if (battery_falg == 1)
{
alarm_UILabel->SetPosition(110, 252);
- alarm_UILabel->Resize(245, 70); // widget's width and height
- //alarm_UILabel->SetText("当前电量低于5%,将自动关机");
+ alarm_UILabel->Resize(245, 70); // widget's width and height
+ // alarm_UILabel->SetText("当前电量低于5%,将自动关机");
alarm_UILabel->SetTextId(STR_LOW_POWER_NOTIF_2);
UpdateLabel(alarm_UILabel, 5, STR_LOW_POWER_NOTIF_2);
alarm_UILabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
alarm_UILabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
osStatus_t retTimer;
low_power_timer = osTimerNew((osTimerFunc_t)low_power_TimerCallBack, osTimerPeriodic, NULL, NULL);
- retTimer = osTimerStart(low_power_timer, 1000*1);
- if (retTimer != osOK && low_power_timer != NULL) {
+ retTimer = osTimerStart(low_power_timer, 1000 * 1);
+ if (retTimer != osOK && low_power_timer != NULL)
+ {
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
- "StartCallTimer osTimerStart failed, ret = %lx!!", retTimer);
+ "StartCallTimer osTimerStart failed, ret = %lx!!", retTimer);
osTimerDelete(low_power_timer);
low_power_timer = NULL;
}
- timer_falg_low_power=5;
-
-
+ timer_falg_low_power = 5;
}
-
+
// Add to rootView
UIViewGroup_lowpower->Add(alarm_UILabel);
alarm_UILabel->SetVisible(true);
-
+
// Add LabelButtonExt to App
- if (alarm_labelbutton == nullptr) {
+ if (alarm_labelbutton == nullptr)
+ {
alarm_labelbutton = new UILabelButtonExt();
}
// alarm_labelbutton->SetPosition(165, 378); // widget's left position and top position
// alarm_labelbutton->Resize(135, 88); // widget's width and height
- alarm_labelbutton->SetViewId(LOW_POWER_BUTTON);// Set style
+ alarm_labelbutton->SetViewId(LOW_POWER_BUTTON); // Set style
alarm_labelbutton->SetPosition(0, 366, 466, 100);
const char *ImgSrc = "/user/res/466x100button.bin";
alarm_labelbutton->SetImageSrc(ImgSrc, ImgSrc);
alarm_labelbutton->SetTouchable(true);
ShowUpShutDownAnimatorView();
- if(group)
- UIViewGroup_lowpower->Add(group);
- if(battery_falg>=3)
+ if (group)
+ UIViewGroup_lowpower->Add(group);
+ if (battery_falg >= 3)
{
group->SetVisible(true);
ShutDownImageAnimatorView->Start();
ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 关机动画已经开始了不能息屏
-
}
NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreelowPower);
return &lowppowrViewEventListene_t;
}
- bool lowppowrViewEventListener::OnClick(UIView& view, const ClickEvent& event)
+ bool lowppowrViewEventListener::OnClick(UIView &view, const ClickEvent &event)
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnClick.....");
- if(strcmp(view.GetViewId(),LOW_POWER_BUTTON)==0)
+ if (strcmp(view.GetViewId(), LOW_POWER_BUTTON) == 0)
{
- if(battery_falg)
+ if (battery_falg)
{
osTimerStop(low_power_timer);
low_power_play();
-
}
else
{
NotificationManager::GetInstance()->StopNotify();
}
-
}
- if(strcmp(view.GetViewId(),CHARGE_GROUP)==0)
+ if (strcmp(view.GetViewId(), CHARGE_GROUP) == 0)
{
NotificationManager::GetInstance()->StopNotify();
}
void lowppowrAnimatorStopListener::OnAnimatorStop(UIView &view)
{
- //UNUSED(view);
- // NotificationManager::GetInstance()->StopNotify();//hcj改动
+ // UNUSED(view);
+ // NotificationManager::GetInstance()->StopNotify();//hcj改动
msleep(500);
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "xxxxxxxxxxxxxxxxxxxxOnAnimatorStop");
- if(battery_falg==4)
- shutdown_reboot_prejobs(REBOOT_TYPE);
+ if (battery_falg == 4)
+ shutdown_reboot_prejobs(REBOOT_TYPE);
else
- shutdown_reboot_prejobs(SHUTDOWN_TYPE);
- // uapi_poweroff_device(); // 关机
-
-
+ shutdown_reboot_prejobs(SHUTDOWN_TYPE);
+ // uapi_poweroff_device(); // 关机
- //NotificationManager::GetInstance()->StopNotify();
+ // NotificationManager::GetInstance()->StopNotify();
//
- // if(strcmp(view.GetViewId(),LOW_POWER_BUTTON)!=0)
- // {
-
+ // if(strcmp(view.GetViewId(),LOW_POWER_BUTTON)!=0)
+ // {
+
// }
-
}
+ bool lowppowrViewEventListener::OnKeyAct(UIView &view, const KeyEvent &event)
+ {
+ unsigned short keyID = event.GetKeyId();
+ unsigned short keyState = event.GetState();
+ // 如果是power键,且是亮屏状态,按键释放就返回上一级
+ if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0)
+ {
+ NotificationManager::GetInstance()->StopNotify();
+ }
+ return true;
+ }
}