--- /dev/null
+#ifndef THUNDERBIRD_VIEW_H_
+#define THUNDERBIRD_VIEW_H_
+
+#include "BaseView.h"
+#include "View.h"
+#include "components/ui_scroll_view.h"
+#include "video_play_wrapper.h"
+#include "DialVideoView.h"
+#include "animator/animator_manager.h"
+#include "components/ui_view_group.h"
+#include "components/ui_image_animator.h"
+namespace OHOS
+{
+
+ class ThunderBirdPresenter;
+ class ThunderBirdView : public View<ThunderBirdPresenter>
+ {
+
+ public:
+ ThunderBirdView();
+ virtual ~ThunderBirdView();
+ static ThunderBirdView *GetInstance(void);
+
+ void OnStart() override;
+ void OnSetUpView() override;
+ void OnTearDownView() override;
+ void OnStop() override;
+
+ private:
+ void ThunderBirdViewInit(void);
+ void ClearAll(void);
+ UIViewGroup *group{nullptr};
+ UIImageView *curFace{nullptr};
+ DialVideoView* videoPlayer_ = nullptr;
+ UILiteSurfaceView *surfaceView_ = nullptr;
+ MediaVideoPlay *video_ = nullptr;
+ MediaVideoPlay *videoPlay_ = nullptr;
+ ColorType colorKey_;
+
+ };
+}
+#endif
\ No newline at end of file
--- /dev/null
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-04-16 14:36:45
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-06-18 15:19:37
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/ThunderBird/src/ThunderBirdPresenter.cpp
+ */
+#include "thunderbird/include/ThunderBirdPresenter.h"
+#include "AppViewIDs.h"
+#include "NativeAbility.h"
+#include "common/key_code.h"
+#include <custom_utils.h>
+namespace OHOS
+{
+
+ // 当前Presenter属性实例化的内存指针
+ static ThunderBirdPresenter *g_pThunderBirdPresenter = nullptr;
+
+ ThunderBirdPresenter::ThunderBirdPresenter()
+ {
+ g_pThunderBirdPresenter = this;
+ }
+
+ ThunderBirdPresenter::~ThunderBirdPresenter()
+ {
+ g_pThunderBirdPresenter = nullptr;
+ }
+
+ ThunderBirdPresenter *ThunderBirdPresenter::GetInstance()
+ {
+ return g_pThunderBirdPresenter;
+ }
+
+ void ThunderBirdPresenter::OnStart()
+ {
+ Presenter<ThunderBirdView>::OnStart();
+ }
+
+ void ThunderBirdPresenter::OnPause(void)
+ {
+ Presenter<ThunderBirdView>::OnPause();
+ }
+
+ void ThunderBirdPresenter::OnResume(void)
+ {
+ Presenter<ThunderBirdView>::OnResume();
+ }
+
+ void ThunderBirdPresenter::OnStop(void)
+ {
+ Presenter<ThunderBirdView>::OnStop();
+ }
+
+ bool ThunderBirdPresenter::OnClick(UIView &view, const ClickEvent &event)
+ {
+
+ return true;
+ }
+
+ bool ThunderBirdPresenter::OnDrag(UIView &view, const DragEvent &event)
+ {
+ UNUSED(view);
+ UNUSED(event);
+ return true;
+ }
+
+ bool ThunderBirdPresenter::OnDragEnd(UIView &view, const DragEvent &event)
+ {
+ UNUSED(view);
+ if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
+ {
+ NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+ }
+ return true;
+ }
+
+ bool ThunderBirdPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件
+ {
+ UNUSED(view);
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdPresenter::OnKeyAct");
+ 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)
+ {
+ NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+ }
+ return true;
+ }
+}
\ No newline at end of file
--- /dev/null
+#include "thunderbird/include/ThunderBirdView.h"
+#include "thunderbird/include/ThunderBirdPresenter.h"
+#include "wearable_log.h"
+#include "NativeAbility.h"
+#include "msg_center.h"
+#include "securec.h"
+#include "common/low_power_manager.h"
+#include "common/image_cache_manager.h"
+#include "screennotify/include/ui_screennotify.h"
+#include "custom_utils.h"
+
+namespace OHOS
+{
+ static constexpr int16_t VIDEO_WIDTH = 466;
+ static constexpr int16_t VIDEO_HEIGHT = 466;
+ static constexpr int16_t STRIDE_ALIGNMENT_VALUE = 128;
+ static constexpr int16_t JPEG_WIDTH_BYTE_ALIGNMENT = 128;
+ static constexpr int16_t JPEG_HEIGHT_BYTE_ALIGNMENT = 16;
+ static constexpr int16_t BUFFER_QUEUE_SIZE = 2;
+ static constexpr int16_t JPEG_HEIGHT_DIVISOR = 2;
+ static ThunderBirdView *g_pThunderBirdView{nullptr};
+
+ static MediaVideoPlay *g_videoPlay = nullptr;
+ static bool g_lastPlayed = false;
+ static void ScreenStatusNotify(ScreenStatus status)
+ {
+ if (g_videoPlay == nullptr)
+ {
+ return;
+ }
+
+ bool temp = g_videoPlay->isPlayed_;
+ if (status == SCREEN_STATUS_OFF && g_videoPlay->isPlayed_)
+ {
+ g_videoPlay->PauseVideoPlay();
+ }
+ else if (status == SCREEN_STATUS_ON)
+ {
+ if (g_lastPlayed && g_videoPlay->isPause_)
+ {
+ g_videoPlay->ResumeVideoPlay();
+ }
+ }
+ g_lastPlayed = temp;
+ }
+
+ ThunderBirdView::ThunderBirdView()
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdView::ThunderBirdView");
+ g_pThunderBirdView = this;
+ }
+
+ ThunderBirdView::~ThunderBirdView()
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdView::~ThunderBirdView");
+ g_pThunderBirdView = nullptr;
+ }
+
+ ThunderBirdView *ThunderBirdView::GetInstance()
+ {
+ return g_pThunderBirdView;
+ }
+
+ void ThunderBirdView::ClearAll(void)
+ {
+ g_videoPlay = nullptr;
+ deregisterNotifyScreenStatus(ScreenStatusNotify);
+ if (group != nullptr)
+ {
+ group->RemoveAll();
+ delete group;
+ group = nullptr;
+ }
+ if (curFace != nullptr)
+ {
+ delete curFace;
+ curFace = nullptr;
+ }
+ if (surfaceView_ != nullptr)
+ {
+ delete surfaceView_;
+ surfaceView_ = nullptr;
+ }
+ if (videoPlay_ != nullptr)
+ {
+ delete videoPlay_;
+ videoPlay_ = nullptr;
+ }
+ }
+
+ void ThunderBirdView::ThunderBirdViewInit(void)
+ {
+ if (group == nullptr)
+ {
+ group = new UIViewGroup();
+ if (group == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group null!");
+ return;
+ }
+ }
+ group->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
+ group->SetTouchable(true);
+ group->SetDraggable(true);
+ UIView::OnDragListener *dragListener = (UIView::OnDragListener *)OHOS::ThunderBirdPresenter::GetInstance();
+ group->SetOnDragListener(dragListener);
+ group->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue().full);
+
+ curFace = new UIImageView();
+ if (curFace == nullptr)
+ {
+ return;
+ }
+ curFace->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
+ curFace->SetSrc("/user/res/ThunderBird/hair.bin");
+
+
+ surfaceView_ = new UILiteSurfaceView();
+ if (surfaceView_ == nullptr)
+ {
+ GRAPHIC_LOGE("surfaceView is nullptr\n");
+ return;
+ }
+ colorKey_.full = 0xff202020;
+ surfaceView_->SetViewId("sur");
+ surfaceView_->SetPosition(0, 0, VIDEO_WIDTH, VIDEO_HEIGHT);
+ surfaceView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);
+ surfaceView_->SetSurfaceColorkey(colorKey_);
+
+ Surface *surface = surfaceView_->GetSurface();
+ surface->SetStrideAlignment(STRIDE_ALIGNMENT_VALUE);
+ surface->SetWidthAndHeight(VIDEO_WIDTH, VIDEO_HEIGHT);
+ surface->SetQueueSize(BUFFER_QUEUE_SIZE);
+ surface->SetFormat(PIXEL_FMT_YCBCR_420_SP);
+
+ // jpeg decoder output buffer size calculation formula
+ int32_t ySize = ALIGN_BYTE(VIDEO_WIDTH, JPEG_WIDTH_BYTE_ALIGNMENT) * VIDEO_HEIGHT;
+ int32_t uvSize = ALIGN_BYTE(VIDEO_WIDTH, JPEG_WIDTH_BYTE_ALIGNMENT) *
+ ALIGN_BYTE(VIDEO_HEIGHT, JPEG_HEIGHT_BYTE_ALIGNMENT) / JPEG_HEIGHT_DIVISOR;
+ int32_t bufferSize = ySize + uvSize;
+ surface->SetSize(bufferSize);
+ if (videoPlay_ == nullptr)
+ {
+ std::string uri("/user/video/thunderbird.mp4");
+ videoPlay_ = new MediaVideoPlay(surface, nullptr, uri, false);
+ if (videoPlay_ == nullptr)
+ {
+ GRAPHIC_LOGE("videoPlay_ is nullptr\n");
+ return;
+ }
+ g_videoPlay = videoPlay_;
+ registerNotifyScreenStatus(ScreenStatusNotify);
+ }
+ if (videoPlay_->isExited_ || !videoPlay_->isEntered_) {
+ videoPlay_->StartVideoPlay();
+ }
+ group->Add(surfaceView_);
+ group->Add(curFace);
+
+ container_->Add(group);
+ }
+
+ void ThunderBirdView::OnStart()
+ {
+ View<ThunderBirdPresenter>::OnStart();
+ SetContainerView(new UIViewGroup());
+ if (GetContainer() == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetContainerView fail!!");
+ return;
+ }
+ container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
+ container_->SetTouchable(true);
+ container_->SetDraggable(true);
+
+ ThunderBirdViewInit();
+ ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON);
+ }
+
+ void ThunderBirdView::OnSetUpView()
+ {
+ View<ThunderBirdPresenter>::OnSetUpView();
+ Draw();
+ }
+
+ void ThunderBirdView::OnTearDownView()
+ {
+
+ View<ThunderBirdPresenter>::OnTearDownView();
+ return;
+ }
+
+ void ThunderBirdView::OnStop()
+ {
+ View<ThunderBirdPresenter>::OnStop();
+ ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON);
+ if (container_ != nullptr)
+ {
+ ClearAll();
+ container_->RemoveAll();
+ delete container_;
+ container_ = nullptr;
+ }
+ RootView::GetInstance()->ClearOnKeyActListener();
+ return;
+ }
+}
\ No newline at end of file