From: xue <2144439972@qq.com> Date: Sat, 30 Aug 2025 12:26:00 +0000 (+0800) Subject: 增加关机动画与逻辑 X-Git-Tag: leiniao_debug_1.0.0_20250922_020716~126 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=b74f4704b9e3f2fc14979c9fb4aafd78e2772c6b;p=mirrors%2FFD230.git 增加关机动画与逻辑 --- diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/thunderbird/include/ThunderBirdShutdownView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/thunderbird/include/ThunderBirdShutdownView.h new file mode 100644 index 000000000..f9a9e2c1e --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/thunderbird/include/ThunderBirdShutdownView.h @@ -0,0 +1,45 @@ +#ifndef THUNDERBIRD_SHUTDOWN_VIEW_H +#define THUNDERBIRD_SHUTDOWN_VIEW_H + +#include "components/ui_view_group.h" +#include "components/ui_image_animator.h" + +namespace OHOS +{ + static constexpr int16_t TB_SHUTDOWN_ANIM_X = 0; + static constexpr int16_t TB_SHUTDOWN_ANIM_Y = 0; + static constexpr int16_t TB_SHUTDOWN_ANIM_W = 466; + static constexpr int16_t TB_SHUTDOWN_ANIM_H = 466; + static constexpr int16_t TB_SHUTDOWN_ANIM_FRAMES = 95; + static constexpr int16_t TB_SHUTDOWN_ANIM_INTERVAL = 150; + static constexpr const char *TB_SHUTDOWN_ANIM_PATH = "/user/res/RebootAndShutDown/ShutDown/"; + + class ThunderBirdShutdownView : public UIImageAnimatorView::AnimatorStopListener + { + public: + ThunderBirdShutdownView(); + virtual ~ThunderBirdShutdownView(); + + static ThunderBirdShutdownView *GetInstance(); + + UIViewGroup *ThunderBirdShutdownViewInit(); + UIImageAnimatorView *GetAnimator(); + + void StartShutdownAnimation(); + + private: + void OnAnimatorStop(UIView &view) override; + void ClearAll(); + bool EnsureAnimator(); + + private: + UIViewGroup *group{nullptr}; + UIImageAnimatorView *shutdownAnimator{nullptr}; + ImageAnimatorInfo shutdownImageInfo[TB_SHUTDOWN_ANIM_FRAMES]; + const char **shutdownPathsArray{nullptr}; + }; +} + +#endif + + diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/thunderbird/src/ThunderBirdShutdownView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/thunderbird/src/ThunderBirdShutdownView.cpp new file mode 100644 index 000000000..38fe42680 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/thunderbird/src/ThunderBirdShutdownView.cpp @@ -0,0 +1,130 @@ +#include "thunderbird/include/ThunderBirdShutdownView.h" +#include "uicomponents/UIComponents.h" +#include "wearable_log.h" +#include "custom_runtime.h" +#include "custom_utils.h" +#include "uiservice/include/ui_service.h" +#include "vibrator_service.h" +#include "thunderbird/include/ThunderBirdMainView.h" + +namespace OHOS +{ + static ThunderBirdShutdownView *g_tbShutdownView{nullptr}; + + ThunderBirdShutdownView::ThunderBirdShutdownView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdShutdownView::ThunderBirdShutdownView"); + g_tbShutdownView = this; + } + + ThunderBirdShutdownView::~ThunderBirdShutdownView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdShutdownView::~ThunderBirdShutdownView"); + ClearAll(); + g_tbShutdownView = nullptr; + } + + ThunderBirdShutdownView *ThunderBirdShutdownView::GetInstance() + { + return g_tbShutdownView; + } + + void ThunderBirdShutdownView::ClearAll() + { + if (group != nullptr) + { + group->RemoveAll(); + if (shutdownAnimator != nullptr) + { + delete shutdownAnimator; + shutdownAnimator = nullptr; + } + FreeImagePathsArray(shutdownPathsArray, TB_SHUTDOWN_ANIM_FRAMES); + delete group; + group = nullptr; + } + } + + void ThunderBirdShutdownView::OnAnimatorStop(UIView &view) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdShutdownView::OnAnimatorStop"); + // 关机前释放 thunderbird 视频与相关资源 + if (ThunderBirdMainView::GetInstance()) + { + ThunderBirdMainView::GetInstance()->CloseVideo(); + } + shutdown_reboot_prejobs(SHUTDOWN_TYPE); + } + + bool ThunderBirdShutdownView::EnsureAnimator() + { + if (shutdownAnimator == nullptr) + { + shutdownPathsArray = CreateImagePathsArray(TB_SHUTDOWN_ANIM_PATH, TB_SHUTDOWN_ANIM_FRAMES); + shutdownAnimator = new UIImageAnimatorView(); + if (shutdownAnimator == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdShutdownView new UIImageAnimatorView fail"); + return false; + } + shutdownAnimator->SetAutoEnable(false); + for (uint8_t i = 0; i < TB_SHUTDOWN_ANIM_FRAMES; i++) + { + shutdownImageInfo[i].imagePath = (shutdownPathsArray[i]); + shutdownImageInfo[i].imageType = IMG_SRC_FILE_PATH; + shutdownImageInfo[i].pos.x = TB_SHUTDOWN_ANIM_X; + shutdownImageInfo[i].pos.y = TB_SHUTDOWN_ANIM_Y; + shutdownImageInfo[i].width = TB_SHUTDOWN_ANIM_W; + shutdownImageInfo[i].height = TB_SHUTDOWN_ANIM_H; + } + shutdownAnimator->SetPosition(TB_SHUTDOWN_ANIM_X, TB_SHUTDOWN_ANIM_Y, TB_SHUTDOWN_ANIM_W, TB_SHUTDOWN_ANIM_H); + shutdownAnimator->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + shutdownAnimator->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + shutdownAnimator->SetImageAnimatorSrc(shutdownImageInfo, TB_SHUTDOWN_ANIM_FRAMES, TB_SHUTDOWN_ANIM_INTERVAL); + shutdownAnimator->SetRepeat(false); + shutdownAnimator->SetRepeatTimes(1); + shutdownAnimator->SetResizeMode(UIImageView::COVER); + shutdownAnimator->SetAnimatorStopListener(this); + } + return true; + } + + UIViewGroup *ThunderBirdShutdownView::ThunderBirdShutdownViewInit() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdShutdownView::ThunderBirdShutdownViewInit"); + group = new UIViewGroup(); + if (group == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdShutdownView group new fail"); + return nullptr; + } + group->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + if (!EnsureAnimator()) + { + return nullptr; + } + group->Add(shutdownAnimator); + return group; + } + + UIImageAnimatorView *ThunderBirdShutdownView::GetAnimator() + { + return shutdownAnimator; + } + + void ThunderBirdShutdownView::StartShutdownAnimation() + { + if (!EnsureAnimator()) + { + return; + } + shutdownAnimator->Start(); + uapi_dev_runtime_set_shutting_down_status(1); + ScreenOffEnable(false); + uapi_set_screen_on_api(); + custom_VibratorFunc_int(0); + } +} + +