From ce67c9091f66023b3cf5d31c953351909842c9e4 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Fri, 6 Feb 2026 09:58:17 +0800 Subject: [PATCH] =?utf8?q?=E4=BD=8E=E7=94=B5=E9=87=8F=E5=BC=B9=E7=AA=97ui?= =?utf8?q?=E4=BF=AE=E6=94=B9=EF=BC=8C=E5=88=A0=E9=99=A4=E6=97=A0=E7=94=A8?= =?utf8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../msg_center/src/msg_center_customer.cpp | 103 +++--- .../src/notify/charge_notification.cpp | 349 +++++++----------- 2 files changed, 189 insertions(+), 263 deletions(-) diff --git a/code/sdk/application/wearable/fd272/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/fd272/service/msg_center/src/msg_center_customer.cpp index 0c6312739..af70adfe2 100644 --- a/code/sdk/application/wearable/fd272/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/fd272/service/msg_center/src/msg_center_customer.cpp @@ -674,60 +674,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); diff --git a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/charge_notification.cpp b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/charge_notification.cpp index aa8edc0d2..6747b5f1e 100644 --- a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/charge_notification.cpp +++ b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/charge_notification.cpp @@ -74,12 +74,11 @@ namespace OHOS osTimerId_t Chargeing_timer= NULL; // 实际的UI更新逻辑(在图形线程中执行) - static void Chargeing_Timer_CallBackProc(int data) { - // 检查必要的UI组件是否存在(batteryprogress可能为nullptr,不影响更新) + static void Chargeing_Timer_CallBackProc(int data) + { if (UIViewGroup_charge == nullptr || UILabel_power == nullptr || UILabel_time == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Chargeing_Timer_CallBackProc: UI组件为空,跳过更新"); return; } @@ -123,7 +122,8 @@ namespace OHOS } // 定时器回调函数(通过PostGraphicEvent投递到图形线程) - void Chargeing_Timer_CallBack(int data) { + void Chargeing_Timer_CallBack(int data) + { GraphicService::GetInstance()->PostGraphicEvent( std::bind(Chargeing_Timer_CallBackProc, data)); } @@ -141,137 +141,119 @@ namespace OHOS { if (UIViewGroup_charge != nullptr) { - - if(Chargeing_timer) - { - osTimerStop(Chargeing_timer); - osTimerDelete(Chargeing_timer); - Chargeing_timer = NULL; - } - - UIViewGroup_charge->RemoveAll(); - - // if (batteryprogress) { - // delete batteryprogress; - // batteryprogress = 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 (chargeAnimatorView) - { - chargeAnimatorView->Stop(); - delete chargeAnimatorView; - chargeAnimatorView = nullptr; - } - if (ChargeAnimationInfoArray) - { - FreeImageInfoArray(ChargeAnimationInfoArray, ChargeAnimationPaths, - CHARGE_ANIMATION_VIEW_NUM_FRAMES); - ChargeAnimationInfoArray = nullptr; - } - - RootView::GetInstance()->SetOnKeyActListener(g_onKeyActListener); - // if(UILabel_Chargeing) - // { - // delete UILabel_Chargeing; - // UILabel_Chargeing = nullptr; - - // } - - - RootView::GetInstance()->Remove(UIViewGroup_charge); - delete UIViewGroup_charge; - UIViewGroup_charge = nullptr; + if(Chargeing_timer) + { + osTimerStop(Chargeing_timer); + osTimerDelete(Chargeing_timer); + Chargeing_timer = NULL; + } + UIViewGroup_charge->RemoveAll(); + 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 (chargeAnimatorView) + { + chargeAnimatorView->Stop(); + delete chargeAnimatorView; + chargeAnimatorView = nullptr; + } + if (ChargeAnimationInfoArray) + { + FreeImageInfoArray(ChargeAnimationInfoArray, ChargeAnimationPaths, + CHARGE_ANIMATION_VIEW_NUM_FRAMES); + ChargeAnimationInfoArray = nullptr; + } + RootView::GetInstance()->SetOnKeyActListener(g_onKeyActListener); + 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); + if(UIViewGroup_charge == nullptr) + { + printf("UIViewGroup_charge is null\r\n"); + return nullptr; + } } + UIViewGroup_charge->SetPosition(0, 0, 466, 466); 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 power = battery_get_voltage(&voltage); #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); - - - - if (UILabel_power == nullptr) { + /* -------------------------------------------------------------------------- */ + if (UILabel_power == nullptr) + { UILabel_power = new UILabelExt(); + if(UILabel_power == nullptr) + { + printf("UILabel_power is null\r\n"); + return nullptr; + } } - UILabel_power->SetPosition(133, 202); // 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, 202); + UILabel_power->Resize(200, 60); 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_time == nullptr) { + UIViewGroup_charge->Add(UILabel_power); + /* -------------------------------------------------------------------------- */ + if (UILabel_time == nullptr) + { UILabel_time = new UILabelExt(); + if(UILabel_time == nullptr) + { + printf("UILabel_time is null\r\n"); + return nullptr; + } } - 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->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); - + UIViewGroup_charge->Add(UILabel_time); + /* -------------------------------------------------------------------------- */ osStatus_t retTimer; Chargeing_timer = osTimerNew((osTimerFunc_t)Chargeing_Timer_CallBack, osTimerPeriodic, NULL, NULL); retTimer = osTimerStart(Chargeing_timer, 1000*1); @@ -281,19 +263,23 @@ namespace OHOS osTimerDelete(Chargeing_timer); Chargeing_timer = NULL; } - - - - // 充电动画初始化与添加 - if (chargeAnimatorView == nullptr) { + if (chargeAnimatorView == nullptr) + { chargeAnimatorView = new UIImageAnimatorView(); + if(chargeAnimatorView == nullptr) + { + printf("chargeAnimatorView is null\r\n"); + return nullptr; + } } - if (ChargeAnimationInfoArray == nullptr) { + if (ChargeAnimationInfoArray == nullptr) + { // 加载 /user/res/charge/ 目录中的帧序列:1.bin ... N.bin ChargeAnimationInfoArray = CreateImageInfoArray(ChargeAnimationPaths, CHARGE_ANIMATION_VIEW_NUM_FRAMES); } - if (ChargeAnimationInfoArray != nullptr && chargeAnimatorView != nullptr) { + if (ChargeAnimationInfoArray != nullptr && chargeAnimatorView != nullptr) + { for (uint8_t i = 0; i < CHARGE_ANIMATION_VIEW_NUM_FRAMES; i++) { ChargeAnimationInfo[i].imageInfo = (ChargeAnimationInfoArray[i]); ChargeAnimationInfo[i].imageType = IMG_SRC_IMAGE_INFO; @@ -314,19 +300,14 @@ namespace OHOS chargeAnimatorView->Start(); UIViewGroup_charge->Add(chargeAnimatorView); } - g_onKeyActListener = RootView::GetInstance()->GetOnKeyActListener(); RootView::GetInstance()->SetOnKeyActListener(lowppowrViewEventListener::GetInstance()); - - UIViewGroup_charge->Add(UILabel_time); - UIViewGroup_charge->Add(UILabel_power); - NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreeChargePower); return UIViewGroup_charge; } -/////////////////////////////////////////////////////////////////////////////////// -//低电量弹窗 + + //低电量弹窗 void ShowUpShutDownAnimatorView() { group = new UIViewGroup(); @@ -336,10 +317,8 @@ namespace OHOS return ; } group->SetPosition(0, 0, 466, 466); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ShutDownAnimatorView::ShowUpShutDownAnimatorView"); ShutDownInfoArray = CreateImageInfoArray(ShutDownPaths, SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); - if (ShutDownImageAnimatorView == nullptr) { ShutDownImageAnimatorView = new UIImageAnimatorView(); @@ -373,7 +352,6 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to Create stoplistener!!"); return; } - ShutDownImageAnimatorView->SetVisible(true); //ShutDownImageAnimatorView->Start(); group->SetVisible(false); @@ -392,41 +370,39 @@ namespace OHOS { 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) - { - 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 ShutDownImageAnimatorView; - ShutDownImageAnimatorView = nullptr; + delete alarm_labelbutton; + alarm_labelbutton = nullptr; } - FreeImageInfoArray(ShutDownInfoArray,ShutDownPaths,SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); - delete group; - group = nullptr; + if(group) + { + group->RemoveAll(); + ShutDownImageAnimatorView->Stop(); + if(ShutDownImageAnimatorView) + { + delete ShutDownImageAnimatorView; + ShutDownImageAnimatorView = nullptr; + } + FreeImageInfoArray(ShutDownInfoArray,ShutDownPaths,SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + delete group; + group = nullptr; - } - //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; @@ -456,68 +432,54 @@ namespace OHOS void low_power_play() { - //uapi_poweroff_device(); // 关机 - - //osTimerStop(low_power_timer); + if(group) group->SetVisible(true); UIImageAnimatorView::AnimatorStopListener *stoplistener = static_cast(lowppowrAnimatorStopListener::GetInstance()); - ShutDownImageAnimatorView->SetAnimatorStopListener(stoplistener); - if (stoplistener == nullptr) + if(ShutDownImageAnimatorView) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to Create stoplistener!!"); - return ; - } + ShutDownImageAnimatorView->SetAnimatorStopListener(stoplistener); ShutDownImageAnimatorView->Start(); + } #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->SetTouchable(true); } - // 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 - - // 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 - if (alarm_UILabel == nullptr) { + UIViewGroup_lowpower->Add(alarm_img); + /* -------------------------------------------------------------------------- */ + 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); + alarm_UILabel->Resize(466, 212); alarm_UILabel->SetStyle(STYLE_TEXT_FONT, 30); - - // Set additional property + alarm_UILabel->SetVisible(true); + UIViewGroup_lowpower->Add(alarm_UILabel); + /* -------------------------------------------------------------------------- */ 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); - alarm_UILabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); alarm_UILabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); alarm_UILabel->SetRollSpeed(0); @@ -526,7 +488,6 @@ namespace OHOS set_lowpower_show(0,0); #endif } - // Set additional property if(battery_falg==1) { alarm_UILabel->SetPosition(110, 252); @@ -548,39 +509,24 @@ namespace OHOS low_power_timer = NULL; } 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->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(lowppowrViewEventListener::GetInstance()); alarm_labelbutton->SetOnClickListener(button1Click); - - // Add to rootView - UIViewGroup_lowpower->Add(alarm_labelbutton); alarm_labelbutton->SetVisible(true); - UIViewGroup_lowpower->SetTouchable(true); + UIViewGroup_lowpower->Add(alarm_labelbutton); alarm_labelbutton->SetTouchable(true); - ShowUpShutDownAnimatorView(); if(group) UIViewGroup_lowpower->Add(group); @@ -589,9 +535,7 @@ namespace OHOS group->SetVisible(true); ShutDownImageAnimatorView->Start(); ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 关机动画已经开始了不能息屏 - } - NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(FreelowPower); return UIViewGroup_lowpower; } @@ -639,26 +583,13 @@ namespace OHOS void lowppowrAnimatorStopListener::OnAnimatorStop(UIView &view) { - //UNUSED(view); - // NotificationManager::GetInstance()->StopNotify();//hcj改动 msleep(500); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "xxxxxxxxxxxxxxxxxxxxOnAnimatorStop"); - if(battery_falg==4) 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) - // { - - // } - } bool lowppowrViewEventListener::OnKeyAct(UIView &view, const KeyEvent &event) -- 2.17.1