From 77cfaf7b0d0f4864250e8a724fbefcd9b2a4c5cf Mon Sep 17 00:00:00 2001 From: xue <2144439972@qq.com> Date: Wed, 26 Nov 2025 10:16:14 +0800 Subject: [PATCH] =?utf8?q?=E8=93=9D=E7=89=99UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../thunderbird/include/ThunderBirdBlueView.h | 54 ++ .../thunderbird/src/ThunderBirdBlueView.cpp | 577 ++++++++++++++++++ 2 files changed, 631 insertions(+) create mode 100644 code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdBlueView.h create mode 100644 code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueView.cpp diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdBlueView.h b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdBlueView.h new file mode 100644 index 000000000..0248641f5 --- /dev/null +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/include/ThunderBirdBlueView.h @@ -0,0 +1,54 @@ +#ifndef THUNDERBIRD_BLUE_VIEW_H_ +#define THUNDERBIRD_BLUE_VIEW_H_ + +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_label_ext.h" +#include "components/ui_label_ext_with_shadow.h" +#include "components/ui_image_view.h" +#include "components/ui_list.h" +#include "UiConfig.h" + +namespace OHOS +{ + class ThunderBirdBlueView + { + public: + ThunderBirdBlueView(); + virtual ~ThunderBirdBlueView(); + static ThunderBirdBlueView *GetInstance(void); + bool EnsureNetAnimator(); + UIViewGroup *ThunderBirdBlueViewInit(void); + void ClearAll(void); + void Show(int16_t showView); + void UpdateTaskReminderText(const char* text); + enum : int16_t { + THUNDERBIRD_BULEVIEW_ENTER = 0, // 进入配对 + THUNDERBIRD_BULEVIEW_SREACHING, // 寻找设备 + THUNDERBIRD_BULEVIEW_SREACHING_FAILED, // 搜索失败(原变量名修正拼写:v→VIEW) + THUNDERBIRD_BULEVIEW_CONNECT_FAILED, // 连接失败 + THUNDERBIRD_BULEVIEW_DEVICE_LIST, // 蓝牙列表 + THUNDERBIRD_BULEVIEW_CONNECT_SUCCESS, // 连接成功 + THUNDERBIRD_BULEVIEW_DISCONNECT_CONFIRM, // 断连确认 + THUNDERBIRD_BULEVIEW_DISCONNECT_SUCCESS, // 断连成功 + THUNDERBIRD_BULEVIEW_DISCONNECT_FAILED // 断连失败 + }; + + private: + UIViewGroup *group{nullptr}; + UILabelExt *TextLabel{nullptr}; + UILabelExt *TextLabel_2{nullptr}; + UILabelExt *RemindLabel{nullptr}; + UILabelExt *RemindLabel_2{nullptr}; + UILabelExt *RemindLabel_3{nullptr}; + UIImageView *BackGround{nullptr}; + UIImageView *RemindIcon{nullptr}; + UIImageView *RemindIcon1{nullptr}; + UIImageView *RemindIcon2{nullptr}; + UIImageView *RemindIcon3{nullptr}; + UIList *DeviceList{nullptr}; + }; +} + +#endif + diff --git a/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueView.cpp b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueView.cpp new file mode 100644 index 000000000..dfcbd8f1a --- /dev/null +++ b/code/sdk/application/wearable/ln/nativeapp/nativeui/thunderbird/src/ThunderBirdBlueView.cpp @@ -0,0 +1,577 @@ +#include "thunderbird/include/ThunderBirdBlueView.h" +#include "thunderbird/include/ThunderBirdMainView.h" +#include "wearable_log.h" +#include "common/image_cache_manager.h" +#include "custom_utils.h" +#include "vibrator_service.h" + + +namespace OHOS +{ + + static ThunderBirdBlueView *g_pThunderBirdBlueView{nullptr}; + + ThunderBirdBlueView::ThunderBirdBlueView() + { + g_pThunderBirdBlueView = this; + } + + ThunderBirdBlueView::~ThunderBirdBlueView() + { + g_pThunderBirdBlueView = nullptr; + ClearAll(); + } + + ThunderBirdBlueView *ThunderBirdBlueView::GetInstance(void) + { + return g_pThunderBirdBlueView; + } + + void ThunderBirdBlueView::ClearAll(void) + { + if (group != nullptr) + { + group->RemoveAll(); + delete group; + group = nullptr; + } + if (TextLabel != nullptr) { delete TextLabel; TextLabel = nullptr; } + if (TextLabel_2 != nullptr) { delete TextLabel_2; TextLabel_2 = nullptr; } + if (RemindLabel != nullptr) { delete RemindLabel; RemindLabel = nullptr; } + if (RemindLabel_2 != nullptr) { delete RemindLabel_2; RemindLabel_2 = nullptr; } + if (RemindLabel_3 != nullptr) { delete RemindLabel_3; RemindLabel_3 = nullptr; } + if (RemindIcon != nullptr) { delete RemindIcon; RemindIcon = nullptr; } + if (RemindIcon1 != nullptr) { delete RemindIcon1; RemindIcon1 = nullptr; } + if (RemindIcon2 != nullptr) { delete RemindIcon2; RemindIcon2 = nullptr; } + if (RemindIcon3 != nullptr) { delete RemindIcon3; RemindIcon3 = nullptr; } + if (BackGround != nullptr) { delete BackGround; BackGround = nullptr; } + if (DeviceList != nullptr) { delete DeviceList; DeviceList = nullptr; } + } + + bool ThunderBirdBlueView::EnsureNetAnimator() + { + // No animator defined in header; keep as stub for compatibility + return true; + } + + UIViewGroup *ThunderBirdBlueView::ThunderBirdBlueViewInit(void) + { + group = new UIViewGroup(); + if (group == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdBlueView::group null!"); + return nullptr; + } + group->SetPosition(0, 0, 360, 360); + + // 公共控件 + BackGround = new UIImageView(); + if (BackGround) + { + BackGround->SetAutoEnable(false); + BackGround->SetPosition(0, 0, 360, 360); + BackGround->SetSrc("/user/res/yellowbg.bin"); + BackGround->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + BackGround->SetResizeMode(UIImageView::CONTAIN); + BackGround->SetVisible(true); + group->Add(BackGround); + } + if(!EnsureNetAnimator()) + { + return nullptr; + } + TextLabel = new UILabelExt(); + if (TextLabel) + { + TextLabel->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_LEFT); + TextLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + TextLabel->SetVisible(false); + group->Add(TextLabel); + } + TextLabel_2 = new UILabelExt(); + if (TextLabel_2) + { + TextLabel_2->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_LEFT); + TextLabel_2->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 24); + TextLabel_2->SetVisible(false); + group->Add(TextLabel_2); + } + RemindIcon = new UIImageView(); + if (RemindIcon) + { + RemindIcon->SetAutoEnable(false); + RemindIcon->SetVisible(false); + RemindIcon->SetResizeMode(UIImageView::CONTAIN); + group->Add(RemindIcon); + } + RemindIcon1 = new UIImageView(); + if (RemindIcon1) + { + RemindIcon1->SetAutoEnable(false); + RemindIcon1->SetVisible(false); + RemindIcon1->SetResizeMode(UIImageView::CONTAIN); + group->Add(RemindIcon1); + } + RemindIcon2 = new UIImageView(); + if (RemindIcon2) + { + RemindIcon2->SetAutoEnable(false); + RemindIcon2->SetVisible(false); + RemindIcon2->SetResizeMode(UIImageView::CONTAIN); + group->Add(RemindIcon2); + } + RemindIcon3 = new UIImageView(); + if (RemindIcon3) + { + RemindIcon3->SetAutoEnable(false); + RemindIcon3->SetVisible(false); + RemindIcon3->SetResizeMode(UIImageView::CONTAIN); + group->Add(RemindIcon3); + } + RemindLabel = new UILabelExt(); + if (RemindLabel) + { + RemindLabel->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_LEFT); + RemindLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); + RemindLabel->SetVisible(false); + group->Add(RemindLabel); + } + RemindLabel_2 = new UILabelExt(); + if (RemindLabel_2) + { + RemindLabel_2->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_LEFT); + RemindLabel_2->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); + RemindLabel_2->SetVisible(false); + group->Add(RemindLabel_2); + } + RemindLabel_3 = new UILabelExt(); + if (RemindLabel_3) + { + RemindLabel_3->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_LEFT); + RemindLabel_3->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); + RemindLabel_3->SetVisible(false); + group->Add(RemindLabel_3); + } + // 初始化设备列表 + DeviceList = new UIList(UIList::VERTICAL); + if (DeviceList) + { + DeviceList->SetPosition(30, 160, 300, 100); + DeviceList->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + DeviceList->SetDragACCLevel(5); + DeviceList->SetSwipeACCLevel(200); + DeviceList->SetReboundSize(30); + DeviceList->SetVisible(false); + group->Add(DeviceList); + } + return group; + } + + void ThunderBirdBlueView::Show(int16_t showView) + { + if (group == nullptr) { return; } + if (TextLabel) { TextLabel->SetVisible(false);} + if (RemindLabel) { RemindLabel->SetVisible(false);} + if (RemindIcon) { RemindIcon->SetVisible(false); } + if (RemindIcon2) { RemindIcon2->SetVisible(false); } + if (RemindIcon1) { RemindIcon1->SetVisible(false); } + if (RemindIcon2) { RemindIcon2->SetVisible(false); } + if (RemindIcon3) { RemindIcon3->SetVisible(false); } + if (DeviceList) { DeviceList->SetVisible(false); } + switch (showView) + { + case THUNDERBIRD_BULEVIEW_ENTER: + { + if (TextLabel) + { + TextLabel->SetPosition(75, 182, 210, 42); + TextLabel->SetText("蓝牙配对准备中"); + TextLabel->SetVisible(true); + } + if (RemindLabel) + { + RemindLabel->SetPosition(80, 275, 200, 25); + RemindLabel->SetStyle(STYLE_TEXT_COLOR, 0xffffffff); + RemindLabel->SetText("按 取消 按 开始"); + RemindLabel->SetVisible(true); + } + if (RemindIcon) + { + RemindIcon->SetPosition(148, 102, 64, 64); + RemindIcon->SetSrc("/user/res/bluetooth.bin"); + RemindIcon->SetVisible(true); + } + if (RemindIcon1) + { + RemindIcon1->SetPosition(104, 277, 22, 22); + RemindIcon1->SetSrc("/user/res/volume_up.bin"); + RemindIcon1->SetVisible(true); + } + if (RemindIcon2) + { + RemindIcon2->SetPosition(216, 277, 22, 22); + RemindIcon2->SetSrc("/user/res/volume_up.bin"); + RemindIcon2->SetVisible(true); + } + break; + } + case THUNDERBIRD_BULEVIEW_SREACHING: + { + if (TextLabel) + { + TextLabel->SetPosition(60, 182, 240, 42); + TextLabel->SetText("正在寻找附近设备"); + TextLabel->SetVisible(true); + } + if (RemindLabel) + { + RemindLabel->SetPosition(55, 275, 250, 25); + RemindLabel->SetText("按 取消 长按 退出配对"); + RemindLabel->SetVisible(true); + } + if (RemindIcon) + { + RemindIcon->SetPosition(148, 102, 64, 64); + RemindIcon->SetSrc("/user/res/bluetooth.bin"); + RemindIcon->SetVisible(true); + } + if (RemindIcon1) + { + RemindIcon1->SetPosition(79, 277, 22, 22); + RemindIcon1->SetSrc("/user/res/volume_up.bin"); + RemindIcon1->SetVisible(true); + } + if (RemindIcon2) + { + RemindIcon2->SetPosition(207, 277, 22, 22); + RemindIcon2->SetSrc("/user/res/volume_up.bin"); + RemindIcon2->SetVisible(true); + } + break; + } + case THUNDERBIRD_BULEVIEW_SREACHING_FAILED: + { + if (TextLabel) + { + TextLabel->SetPosition(142, 124, 120, 42); + TextLabel->SetText("搜索异常"); + TextLabel->SetVisible(true); + } + if (TextLabel_2) + { + TextLabel_2->SetPosition(60, 184, 240, 28); + TextLabel_2->SetText("附近暂无可连接的蓝牙设备"); + TextLabel_2->SetVisible(true); + } + if (RemindLabel) + { + RemindLabel->SetPosition(55, 275, 250, 25); + RemindLabel->SetText("按 重试 长按 退出配对"); + RemindLabel->SetVisible(true); + } + if (RemindIcon) + { + RemindIcon->SetPosition(98, 127, 36, 36); + RemindIcon->SetSrc("/user/res/bluetooth.bin"); + RemindIcon->SetVisible(true); + } + if (RemindIcon1) + { + RemindIcon1->SetPosition(79, 277, 22, 22); + RemindIcon1->SetSrc("/user/res/volume_up.bin"); + RemindIcon1->SetVisible(true); + } + if (RemindIcon2) + { + RemindIcon2->SetPosition(207, 277, 22, 22); + RemindIcon2->SetSrc("/user/res/volume_up.bin"); + RemindIcon2->SetVisible(true); + } + break; + } + case THUNDERBIRD_BULEVIEW_CONNECT_FAILED: + { + if (TextLabel) + { + TextLabel->SetPosition(142, 124, 120, 42); + TextLabel->SetText("连接失败"); + TextLabel->SetVisible(true); + } + if (TextLabel_2) + { + TextLabel_2->SetPosition(30, 184, 300, 28); + TextLabel_2->SetText("请确保蓝牙设备在范围内并已开启"); + TextLabel_2->SetVisible(true); + } + if (RemindLabel) + { + RemindLabel->SetPosition(55, 275, 250, 25); + RemindLabel->SetText("按 重试 长按 退出配对"); + RemindLabel->SetVisible(true); + } + if (RemindIcon) + { + RemindIcon->SetPosition(90, 127, 36, 36); + RemindIcon->SetSrc("/user/res/bluetooth.bin"); + RemindIcon->SetVisible(true); + } + if (RemindIcon1) + { + RemindIcon1->SetPosition(79, 277, 22, 22); + RemindIcon1->SetSrc("/user/res/volume_up.bin"); + RemindIcon1->SetVisible(true); + } + if (RemindIcon2) + { + RemindIcon2->SetPosition(207, 277, 22, 22); + RemindIcon2->SetSrc("/user/res/volume_up.bin"); + RemindIcon2->SetVisible(true); + } + break; + } + case THUNDERBIRD_BULEVIEW_DEVICE_LIST: + { + if (TextLabel) + { + TextLabel->SetPosition(112, 60, 180, 42); + TextLabel->SetText("附近的设备"); + TextLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + TextLabel->SetVisible(true); + } + if (TextLabel_2) + { + TextLabel_2->SetVisible(false); + } + // 显示设备列表 + if (DeviceList) + { + DeviceList->SetPosition(30, 120, 300, 120); + DeviceList->SetVisible(true); + } + if (RemindLabel) + { + RemindLabel->SetPosition(44, 275, 272, 25); + RemindLabel->SetText("按 +/- 选择"); + RemindLabel->SetVisible(true); + } + if (RemindLabel_2) + { + RemindLabel_2->SetPosition(109, 310, 142, 25); + RemindLabel_2->SetText("按 确认"); + RemindLabel_2->SetVisible(true); + } + if (RemindLabel_3) + { + RemindLabel_3->SetPosition(109, 335, 142, 25); + RemindLabel_3->SetText("长按 退出配对"); + RemindLabel_3->SetVisible(true); + } + if (RemindIcon) + { + RemindIcon->SetVisible(false); + } + if (RemindIcon1) + { + RemindIcon1->SetPosition(68, 277, 22, 22); + RemindIcon1->SetSrc("/user/res/volume_up.bin"); + RemindIcon1->SetVisible(true); + } + if (RemindIcon2) + { + RemindIcon2->SetPosition(216, 277, 22, 22); + RemindIcon2->SetSrc("/user/res/volume_up.bin"); + RemindIcon2->SetVisible(true); + } + if (RemindIcon3) + { + RemindIcon3->SetPosition(151, 312, 22, 22); + RemindIcon3->SetSrc("/user/res/volume_up.bin"); + RemindIcon3->SetVisible(true); + } + break; + } + case THUNDERBIRD_BULEVIEW_CONNECT_SUCCESS: + { + if (TextLabel) + { + TextLabel->SetPosition(112, 124, 180, 42); + TextLabel->SetText("蓝牙连接成功"); + TextLabel->SetVisible(true); + } + if (TextLabel_2)//已连接到 + { + TextLabel_2->SetPosition(0, 184, 360, 28); + TextLabel_2->SetText("已连接到"); + TextLabel_2->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + TextLabel_2->SetVisible(true); + } + if (RemindLabel) + { + RemindLabel->SetPosition(44, 275, 272, 25); + RemindLabel->SetText("按 返回列表 长按 断开连接"); + RemindLabel->SetVisible(true); + } + if (RemindLabel_2) + { + RemindLabel_2->SetPosition(109, 310, 142, 25); + RemindLabel_2->SetText("长按 退出配对"); + RemindLabel_2->SetVisible(true); + } + if (RemindIcon) + { + RemindIcon->SetPosition(68, 127, 36, 36); + RemindIcon->SetSrc("/user/res/bluetooth.bin"); + RemindIcon->SetVisible(true); + } + if (RemindIcon1) + { + RemindIcon1->SetPosition(68, 277, 22, 22); + RemindIcon1->SetSrc("/user/res/volume_up.bin"); + RemindIcon1->SetVisible(true); + } + if (RemindIcon2) + { + RemindIcon2->SetPosition(216, 277, 22, 22); + RemindIcon2->SetSrc("/user/res/volume_up.bin"); + RemindIcon2->SetVisible(true); + } + if (RemindIcon3) + { + RemindIcon3->SetPosition(151, 312, 22, 22); + RemindIcon3->SetSrc("/user/res/volume_up.bin"); + RemindIcon3->SetVisible(true); + } + break; + } + case THUNDERBIRD_BULEVIEW_DISCONNECT_CONFIRM: + { + if (TextLabel) + { + TextLabel->SetPosition(30, 124, 300, 42); + TextLabel->SetText("确定要断开连接吗"); + TextLabel->SetVisible(true); + } + if (TextLabel_2)//已连接到 + { + TextLabel_2->SetPosition(0, 184, 360, 28); + TextLabel_2->SetText("已连接到"); + TextLabel_2->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + TextLabel_2->SetVisible(true); + } + if (RemindLabel) + { + RemindLabel->SetPosition(80, 275, 272, 25); + RemindLabel->SetText("按 返回列表 长按 确认"); + RemindLabel->SetVisible(true); + } + if (RemindLabel_2) + { + RemindLabel_2->SetPosition(109, 310, 142, 25); + RemindLabel_2->SetText("长按 退出配对"); + RemindLabel_2->SetVisible(true); + } + if (RemindIcon1) + { + RemindIcon1->SetPosition(68, 277, 22, 22); + RemindIcon1->SetSrc("/user/res/volume_up.bin"); + RemindIcon1->SetVisible(true); + } + if (RemindIcon2) + { + RemindIcon2->SetPosition(216, 277, 22, 22); + RemindIcon2->SetSrc("/user/res/volume_up.bin"); + RemindIcon2->SetVisible(true); + } + if (RemindIcon3) + { + RemindIcon3->SetPosition(151, 312, 22, 22); + RemindIcon3->SetSrc("/user/res/volume_up.bin"); + RemindIcon3->SetVisible(true); + } + break; + } + case THUNDERBIRD_BULEVIEW_DISCONNECT_SUCCESS: + { + if (TextLabel) + { + TextLabel->SetPosition(75, 182, 210, 42); + TextLabel->SetText("蓝牙连接已断开"); + TextLabel->SetVisible(true); + } + if (RemindLabel) + { + RemindLabel->SetPosition(136, 275, 88, 25); + RemindLabel->SetText("按 完成"); + RemindLabel->SetVisible(true); + } + if (RemindIcon) + { + RemindIcon->SetPosition(148, 102, 64, 64); + RemindIcon->SetSrc("/user/res/completed.bin"); + RemindIcon->SetVisible(true); + } + if (RemindIcon1) + { + RemindIcon1->SetPosition(160, 277, 22, 22); + RemindIcon1->SetSrc("/user/res/volume_up.bin"); + RemindIcon1->SetVisible(true); + } + break; + } + case THUNDERBIRD_BULEVIEW_DISCONNECT_FAILED: + { + if (TextLabel) + { + TextLabel->SetPosition(112, 148, 180, 42); + TextLabel->SetText("断开连接失败"); + TextLabel->SetVisible(true); + } + if (RemindLabel) + { + RemindLabel->SetPosition(80, 275, 272, 25); + RemindLabel->SetText("按 返回列表 长按 确认"); + RemindLabel->SetVisible(true); + } + if (RemindLabel_2) + { + RemindLabel_2->SetPosition(109, 310, 142, 25); + RemindLabel_2->SetText("长按 退出配对"); + RemindLabel_2->SetVisible(true); + } + if (RemindIcon) + { + RemindIcon->SetPosition(68, 151, 36, 36); + RemindIcon->SetSrc("/user/res/bluetooth.bin"); + RemindIcon->SetVisible(true); + } + if (RemindIcon1) + { + RemindIcon1->SetPosition(68, 277, 22, 22); + RemindIcon1->SetSrc("/user/res/volume_up.bin"); + RemindIcon1->SetVisible(true); + } + if (RemindIcon2) + { + RemindIcon2->SetPosition(216, 277, 22, 22); + RemindIcon2->SetSrc("/user/res/volume_up.bin"); + RemindIcon2->SetVisible(true); + } + if (RemindIcon3) + { + RemindIcon3->SetPosition(151, 312, 22, 22); + RemindIcon3->SetSrc("/user/res/volume_up.bin"); + RemindIcon3->SetVisible(true); + } + break; + } + default: + break; + } + } + void ThunderBirdBlueView::UpdateTaskReminderText(const char* text) + { + if (TextLabel) { TextLabel->SetText(text); } + } +} + + -- 2.17.1