From: luozheng <1732036298@qq.com> Date: Sat, 14 Mar 2026 07:35:21 +0000 (+0800) Subject: 充电弹窗优化可以按键销毁弹窗 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=b01aa5cffab5f81175c8f9235f1c105caba9a2bf;p=mirrors%2FFD230.git 充电弹窗优化可以按键销毁弹窗 --- diff --git a/code/sdk/application/wearable/n9/service/msg_center/include/notify/charge_notification.h b/code/sdk/application/wearable/n9/service/msg_center/include/notify/charge_notification.h index b37d65be5..9827724ae 100644 --- a/code/sdk/application/wearable/n9/service/msg_center/include/notify/charge_notification.h +++ b/code/sdk/application/wearable/n9/service/msg_center/include/notify/charge_notification.h @@ -1,6 +1,7 @@ #ifndef CHARGE_NOTIFICATION_H #define CHARGE_NOTIFICATION_H #include "components/ui_image_animator.h" +#include "key/include/KeyInputListener.h" namespace OHOS { @@ -42,6 +43,7 @@ namespace OHOS class lowppowrViewEventListener : public OHOS::UIView::OnClickListener, public OHOS::UIView::OnLongPressListener, public OHOS::UIView::OnTouchListener, + public RootView::OnKeyActListener, public OHOS::UIView::OnDragListener { public: @@ -75,6 +77,7 @@ public: { return true; } + bool OnKeyAct(UIView &view, const KeyEvent &event) ; }; }; #endif /* CHARGE_NOTIFICATION_H */ \ No newline at end of file diff --git a/code/sdk/application/wearable/n9/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/n9/service/msg_center/src/msg_center_customer.cpp index 1463e8c42..079621246 100644 --- a/code/sdk/application/wearable/n9/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/n9/service/msg_center/src/msg_center_customer.cpp @@ -424,14 +424,10 @@ do_cywee_service_check_msg(CYWEE_SERVICE_CMD_RESET_DAILY_DATA, NULL); - // SendMsgToUIService(UI_UPDATE_GOAL, 0, nullptr, 0); + SendMsgToUIService(UI_UPDATE_GOAL, 0, nullptr, 0); printf("sport end\n"); #endif - #if defined(BOARD_W9) - printf("******nextday is begin******\r\n"); - BPModel::GetInstance()->CleanBPData(); - printf("w9 nextday is end******\r\n"); - #endif + } void MsgCenterNotifyONtimeProc(const Topic topic, Request* req) { @@ -674,60 +670,55 @@ } /*低电量提醒*/ - void MsgCenterNotifyLowPowerAlarmProc(const Topic topic, Request* req) - { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifyProc:: LowPower Alarm !"); - #if 1 - 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(); - } - else if(*x==0) - { - //提醒低电充电 - if (display_api->get_screen_state() != SCREEN_ON) - { - display_api->turn_on_screen(); - } - display_api->set_screen_set_keepon_timeout(1000*5); - - set_lowpower_falg(0); - if (CheckPriority(topic)) - { - NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); - NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true); - } - } - else - { - //电量过低,直接提醒关机 - if (display_api->get_screen_state() != SCREEN_ON) - { - display_api->turn_on_screen(); - } - display_api->set_screen_set_keepon_timeout(1000*10); - - set_lowpower_falg(1); - if (NotificationManager::GetInstance()->HasNotifyShowing()) - NotificationManager::GetInstance()->StopNotify(); - if (CheckPriority(topic)) - { - NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE); - NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true); - } - } - - #endif - } +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(); + } + display_api->set_screen_set_keepon_timeout(1000*5); + + set_lowpower_falg(0); + if (CheckPriority(topic)) + { + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); + NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true); + } + } + else + { + //电量过低,直接提醒关机 + if (display_api->get_screen_state() != SCREEN_ON) + { + display_api->turn_on_screen(); + } + display_api->set_screen_set_keepon_timeout(1000*10); + set_lowpower_falg(1); + if (NotificationManager::GetInstance()->HasNotifyShowing()) + NotificationManager::GetInstance()->StopNotify(); + if (CheckPriority(topic)) + { + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_ONE); + NotificationManager::GetInstance()->ShowNotify(showlowpowerNotify, (uint16_t)topic, true); + } + } +} //TODO: 亮屏弹窗倒计时5秒关机(不需要取消,强制关机) // DialModelCharge::GetInstance()->UpdatechargeStatus(0); // SaveEleModel::GetInstance()->SetChargeStatus(0); @@ -1042,29 +1033,7 @@ static_cast(topic), true); } #endif - - //每日活动 - void MsgCenterNotifygoalnotificationviewProc(const Topic topic, Request* req) - { - unused(req); - if (CheckPriority(topic)) { - - uint8_t* data=(uint8_t*)req->data; - - if(get_Is_show_flag(data[0])) - { - set_goal_flag_view(data[0]); - set_Is_show_flag(0,data[0]); - - uapi_set_screen_on_api(); - - NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); - NotificationManager::GetInstance()->ShowNotify(ShowGoalNotify, static_cast(topic), true); - } - - } - - } + static uint8_t goal_type=0; void MsgCenterNotifystepProc(const Topic topic, Request* req) { @@ -1352,6 +1321,7 @@ NotificationManager::GetInstance()->ShowNotify(showDebugOutputNotify, (uint16_t)topic, true); } } + //运动目标通知 void MsgCenterNotifyGoalShowViewProc(const Topic topic, Request* req) { unused(req); @@ -1555,7 +1525,7 @@ {TOPIC_EVENT_INACTIVITY_UPDATE, MsgCenterNotifyInactivityProc}, // {TOPIC_EVENT_INACTIVITY_ACCUMULATE_TIME_UPDATE, MsgCenterNotifyInactivityAccumulateTimeProc}, #endif - // {TOPIC_EVENT_GOAL_SHOW_VIEW, MsgCenterNotifygoalnotificationviewProc},//编译不过 + {TOPIC_EVENT_GOAL_SHOW_VIEW, MsgCenterNotifyGoalShowViewProc}, {TOPIC_EVENT_BLE_TRANSMIT, MsgCenterNotifybleTransmit}, {TOPIC_EVENT_CHARGE_PLUG, MsgCenterNotifyChargePlugProc}, diff --git a/code/sdk/application/wearable/n9/service/msg_center/src/notify/charge_notification.cpp b/code/sdk/application/wearable/n9/service/msg_center/src/notify/charge_notification.cpp index 45155ee8f..55b885a82 100644 --- a/code/sdk/application/wearable/n9/service/msg_center/src/notify/charge_notification.cpp +++ b/code/sdk/application/wearable/n9/service/msg_center/src/notify/charge_notification.cpp @@ -5,7 +5,7 @@ #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" @@ -18,105 +18,115 @@ #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; } @@ -125,93 +135,92 @@ namespace OHOS 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(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); @@ -234,34 +243,36 @@ namespace OHOS 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); @@ -270,14 +281,14 @@ namespace OHOS 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); @@ -288,13 +299,13 @@ namespace OHOS 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); @@ -306,15 +317,14 @@ namespace OHOS 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); @@ -325,18 +335,19 @@ namespace OHOS 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); @@ -349,9 +360,9 @@ namespace OHOS 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]); @@ -367,9 +378,8 @@ namespace OHOS ShutDownImageAnimatorView->SetImageAnimatorSrc(ShutDownImageInfo, SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, SHUTDOWN_IMAGE_ANIMATOR_TIME); ShutDownImageAnimatorView->SetRepeat(false); ShutDownImageAnimatorView->SetRepeatTimes(1); - } - UIImageAnimatorView::AnimatorStopListener *stoplistener = static_cast(lowppowrAnimatorStopListener::GetInstance()); + UIImageAnimatorView::AnimatorStopListener *stoplistener = static_cast(lowppowrAnimatorStopListener::GetInstance()); ShutDownImageAnimatorView->SetAnimatorStopListener(stoplistener); if (stoplistener == nullptr) { @@ -378,122 +388,118 @@ namespace OHOS } 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(lowppowrAnimatorStopListener::GetInstance()); + UIImageAnimatorView::AnimatorStopListener *stoplistener = static_cast(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"; @@ -504,37 +510,38 @@ namespace OHOS 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); @@ -543,29 +550,29 @@ namespace OHOS 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); @@ -585,14 +592,13 @@ namespace OHOS 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); @@ -615,24 +621,22 @@ namespace OHOS 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(); } @@ -642,28 +646,36 @@ namespace OHOS 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(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + NotificationManager::GetInstance()->StopNotify(); + } + return true; + } }