/*低电量提醒*/
void MsgCenterNotifyLowPowerAlarmProc(const Topic topic, Request* req)
{
-WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyProc:: LowPower Alarm !");
-uint8 *x= (uint8 *)(req->data);
-const power_display_svr_api_t *display_api = power_display_svr_get_api();
-// if(*x==3)
-// {
-// if (display_api->get_screen_state() != SCREEN_ON)
-// {
-// display_api->turn_on_screen();
-// }
-// display_api->set_screen_set_keepon_timeout(1000*5);
-// //倒计时结束后,直接执行关机动画
-// low_power_play();
-// }
-if(*x==0)
-{
- //提醒低电充电
- if (display_api->get_screen_state() != SCREEN_ON)
- {
- display_api->turn_on_screen();
+ if (req == NULL || req->data == NULL) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "低电量提醒: 请求数据为空");
+ return;
}
- display_api->set_screen_set_keepon_timeout(1000*5);
- set_lowpower_falg(0);
- if (CheckPriority(topic))
+ uint8 *x = (uint8 *)(req->data);
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 收到事件 topic=%u, alarm_type=%u", topic, *x);
+
+ const power_display_svr_api_t *display_api = power_display_svr_get_api();
+ if (display_api == NULL) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "低电量提醒: 获取display_api失败");
+ return;
+ }
+
+ if (*x == 0)
{
- NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO);
- NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true);
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 提醒低电充电");
+ if (display_api->get_screen_state() != SCREEN_ON)
+ {
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 屏幕未亮, 先亮屏");
+ display_api->turn_on_screen();
+ }
+ display_api->set_screen_set_keepon_timeout(1000 * 5);
+
+ set_lowpower_falg(0);
+ if (CheckPriority(topic))
+ {
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 优先级检查通过, 显示充电提醒弹窗");
+ NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO);
+ NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true);
+ }
+ else
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "低电量提醒: 优先级检查未通过, 不显示充电提醒弹窗");
+ }
}
-}
-else
-{
- //电量过低,直接提醒关机
- if (display_api->get_screen_state() != SCREEN_ON)
- {
- display_api->turn_on_screen();
+ else if (*x == 3)
+ {
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 倒计时结束, 执行关机动画 alarm_type=%u", *x);
+ if (display_api->get_screen_state() != SCREEN_ON)
+ {
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 屏幕未亮, 先亮屏");
+ display_api->turn_on_screen();
+ }
+ /* 倒计时弹窗 UI 已存在,直接播放关机动画,勿 StopNotify/ShowNotify 否则会重置倒计时 */
+ OHOS::low_power_play();
}
- display_api->set_screen_set_keepon_timeout(1000*10);
- set_lowpower_falg(1);
- if (NotificationManager::GetInstance()->HasNotifyShowing())
- NotificationManager::GetInstance()->StopNotify();
- if (CheckPriority(topic))
+ else
{
- NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE);
- NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true);
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 电量过低, 提醒关机 alarm_type=%u", *x);
+ if (display_api->get_screen_state() != SCREEN_ON)
+ {
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 屏幕未亮, 先亮屏");
+ display_api->turn_on_screen();
+ }
+ display_api->set_screen_set_keepon_timeout(1000 * 10);
+ set_lowpower_falg(1);
+ if (NotificationManager::GetInstance()->HasNotifyShowing()) {
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 关闭当前弹窗");
+ NotificationManager::GetInstance()->StopNotify();
+ }
+ if (CheckPriority(topic))
+ {
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "低电量提醒: 优先级检查通过, 显示关机提醒弹窗");
+ NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE);
+ NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true);
+ }
+ else
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "低电量提醒: 优先级检查未通过, 不显示关机提醒弹窗");
+ }
}
}
-}
- //TODO: 亮屏弹窗倒计时5秒关机(不需要取消,强制关机)
- // DialModelCharge::GetInstance()->UpdatechargeStatus(0);
- // SaveEleModel::GetInstance()->SetChargeStatus(0);
-
- // testCHANINGView *t=testCHANINGView::GetInstance();
- // if(t!=NULL)
- // {
- // t->ChangeViewcolor(false);
- // }
#ifdef SUPPORT_CAT1_MODEM
void MsgCenterNotifyHfpIncomingProc(const Topic topic, Request* req)
{
batteryprogress = new UICircleProgress();
}
- batteryprogress->SetPosition(
- 123, 123); // widget's left position and top position
- batteryprogress->Resize(224, 222); // widget's width and height
- batteryprogress->SetViewId("circleProgress1"); // Set style
+ batteryprogress->SetPosition(123, 123,224,222);
+ batteryprogress->SetViewId("circleProgress1");
batteryprogress->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
// Set additional property
{
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);
+ image_lightning->Resize(70, 60);
+ image_lightning->SetViewId("image2");
image_lightning->SetStyle(STYLE_BORDER_COLOR, 0xff191919);
char *image2imagesPath = "/user/res/solar-energy_1.bin";
image_lightning->SetSrc(image2imagesPath);
{
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
+ image_circle->SetPosition(126, 125);
+ image_circle->Resize(194, 194);
+ image_circle->SetViewId("image1");
char *image1imagesPath = "/user/res/Ellipse_37.bin";
image_circle->SetSrc(image1imagesPath);
image_circle->SetVisible(true);
{
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);
+ UILabel_power->Resize(200, 60);
+ UILabel_power->SetViewId("label5");
UILabel_power->SetStyle(STYLE_TEXT_FONT, 40);
UILabel_power->SetText(buf);
{
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);
+ UILabel_Chargeing->Resize(200, 60);
+ UILabel_Chargeing->SetViewId("label4");
UILabel_Chargeing->SetStyle(STYLE_TEXT_FONT, 30);
// UILabel_Chargeing->SetText("正在充电");
// UILabel_Chargeing->SetTextId(STR_CHARGE);
{
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);
+ UILabel_time->Resize(120, 48);
+ UILabel_time->SetViewId("label3");
UILabel_time->SetStyle(STYLE_TEXT_FONT, 40);
// Set additional property
UILabel_time->SetText(time_buf);
}
osTimerId_t low_power_timer = NULL;
+ static uint8_t timer_falg_low_power = 6;
void FreelowPower(void)
{
+ if (low_power_timer != NULL) {
+ osTimerStop(low_power_timer);
+ osTimerDelete(low_power_timer);
+ low_power_timer = NULL;
+ }
+ timer_falg_low_power = 6;
if (UIViewGroup_lowpower != nullptr)
{
UIViewGroup_lowpower->RemoveAll();
UIViewGroup_lowpower = nullptr;
}
}
- static uint8_t timer_falg_low_power = 6;
+
void low_power_TimerCallBack(int data)
{
- // uapi_poweroff_device(); // 关机
- if (timer_falg_low_power)
+ if (timer_falg_low_power == 0) {
+ return;
+ }
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "关机倒计时:%d", timer_falg_low_power);
+ timer_falg_low_power--;
+ UpdateLabel(alarm_UILabel, timer_falg_low_power, STR_LOW_POWER_NOTIF_2);
+ alarm_UILabel->Invalidate();
+ if (timer_falg_low_power == 0)
{
- timer_falg_low_power--;
- // 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)
- {
- alarm_UILabel->SetVisible(false);
+ alarm_UILabel->SetVisible(false);
+ if (low_power_timer != NULL) {
+ osTimerStop(low_power_timer);
+ osTimerDelete(low_power_timer);
+ low_power_timer = NULL;
+ }
+ WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "关机倒计时: 结束, 触发关机动画");
#ifdef SUPPORT_BATTERY_SERVICE
- low_power_play_toUI(3);
+ low_power_play_toUI(3);
#endif
- }
}
+ UNUSED(data);
}
void low_power_play()
{
- // uapi_poweroff_device(); // 关机
-
- // osTimerStop(low_power_timer);
+ if (group == nullptr || ShutDownImageAnimatorView == nullptr) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "low_power_play: group or animator is null");
+ return;
+ }
+ if (low_power_timer != NULL) {
+ osTimerStop(low_power_timer);
+ osTimerDelete(low_power_timer);
+ low_power_timer = NULL;
+ }
+ if (alarm_labelbutton != nullptr) {
+ alarm_labelbutton->SetVisible(false);
+ }
group->SetVisible(true);
UIImageAnimatorView::AnimatorStopListener *stoplistener = static_cast<UIImageAnimatorView::AnimatorStopListener *>(lowppowrAnimatorStopListener::GetInstance());
ShutDownImageAnimatorView->SetAnimatorStopListener(stoplistener);
return;
}
ShutDownImageAnimatorView->Start();
+ ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON);
#ifdef SUPPORT_BATTERY_SERVICE
set_lowpower_show(1, 0);
#endif
}
+ // 低电量提醒
UIViewGroup *lowPowerShow()
{
-
if (UIViewGroup_lowpower == nullptr)
{
UIViewGroup_lowpower = new UIViewGroup();
+ if (UIViewGroup_lowpower == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lowPowerShow: UIViewGroup_lowpower is null");
+ return nullptr;
+ }
UIViewGroup_lowpower->SetPosition(0, 0, 466, 466);
- // UIViewGroup_lowpower->SetStyle(STYLE_BACKGROUND_OPA, 0);
}
- // Add ImageView to App
if (alarm_img == nullptr)
{
alarm_img = new UIImageView();
+ if (alarm_img == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lowPowerShow: alarm_img is null");
+ return nullptr;
+ }
}
- 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
+ alarm_img->SetPosition(171, 155);
+ alarm_img->Resize(100, 100);
const char *imageimagesPath = "/user/res/lowpower.bin";
alarm_img->SetSrc(imageimagesPath);
-
- // Add to rootView
- UIViewGroup_lowpower->Add(alarm_img);
alarm_img->SetVisible(true);
-
- // Add Label to App
+ UIViewGroup_lowpower->Add(alarm_img);
+ /* -------------------------------------------------------------------------- */
if (alarm_UILabel == nullptr)
{
alarm_UILabel = new UILabelExt();
+ if (alarm_UILabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lowPowerShow: alarm_UILabel is null");
+ return nullptr;
+ }
}
- 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);
+ alarm_UILabel->Resize(466, 212);
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);
+ alarm_UILabel->Resize(245, 70);
// alarm_UILabel->SetText("当前电量低于10%请及时充电");
alarm_UILabel->SetTextId(STR_LOW_POWER_NOTIF_1);
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->Resize(245, 70);
// alarm_UILabel->SetText("当前电量低于5%,将自动关机");
alarm_UILabel->SetTextId(STR_LOW_POWER_NOTIF_2);
UpdateLabel(alarm_UILabel, 5, STR_LOW_POWER_NOTIF_2);
alarm_UILabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
alarm_UILabel->SetRollSpeed(0);
alarm_UILabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ if (low_power_timer != NULL) {
+ osTimerStop(low_power_timer);
+ osTimerDelete(low_power_timer);
+ low_power_timer = NULL;
+ }
osStatus_t retTimer;
low_power_timer = osTimerNew((osTimerFunc_t)low_power_TimerCallBack, osTimerPeriodic, NULL, NULL);
retTimer = osTimerStart(low_power_timer, 1000 * 1);
}
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)
{
alarm_labelbutton = new UILabelButtonExt();
+ if (alarm_labelbutton == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "lowPowerShow: alarm_labelbutton is null");
+ return nullptr;
+ }
}
- // 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);
alarm_labelbutton->SetPosition(0, 366, 466, 100);
const char *ImgSrc = "/user/res/466x100button.bin";
alarm_labelbutton->SetImageSrc(ImgSrc, ImgSrc);
- // Set additional property
// alarm_labelbutton->SetText("确认");
alarm_labelbutton->SetTextId(STR_KONW);
alarm_labelbutton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
alarm_labelbutton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);
-
UIView::OnClickListener *button1Click = static_cast<UIView::OnClickListener *>(lowppowrViewEventListener::GetInstance());
alarm_labelbutton->SetOnClickListener(button1Click);
-
- // Add to rootView
UIViewGroup_lowpower->Add(alarm_labelbutton);
alarm_labelbutton->SetVisible(true);
UIViewGroup_lowpower->SetTouchable(true);
ShutDownImageAnimatorView->Start();
ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 关机动画已经开始了不能息屏
}
-
NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreelowPower);
return UIViewGroup_lowpower;
}
lowppowrViewEventListener::lowppowrViewEventListener()
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "lowppowrViewEventListener :%p", this);
}
lowppowrViewEventListener::~lowppowrViewEventListener()
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~lowppowrViewEventListener");
}
lowppowrViewEventListener *lowppowrViewEventListener::GetInstance(void)
{
if (battery_falg)
{
- osTimerStop(low_power_timer);
+ if(low_power_timer != NULL)
+ {
+ osTimerStop(low_power_timer);
+ osTimerDelete(low_power_timer);
+ low_power_timer = NULL;
+ }
low_power_play();
}
else
NotificationManager::GetInstance()->StopNotify();
}
return true;
- UNUSED(event);
}
void lowppowrAnimatorStopListener::OnAnimatorStop(UIView &view)
shutdown_reboot_prejobs(REBOOT_TYPE);
else
shutdown_reboot_prejobs(SHUTDOWN_TYPE);
- // uapi_poweroff_device(); // 关机
-
- // NotificationManager::GetInstance()->StopNotify();
- //
- // if(strcmp(view.GetViewId(),LOW_POWER_BUTTON)!=0)
- // {
-
- // }
}