From bd3f3ed93096a359bca57a2914b2620e5e151c81 Mon Sep 17 00:00:00 2001 From: Caisking Date: Wed, 17 Sep 2025 12:13:06 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E9=9B=B7=E9=B8=9F=E6=B5=8B?= =?utf8?q?=E8=AF=95Slice?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativelauncher/include/AppViewIDs.h | 1 + .../include/ThunderBirdRecordPresenter.h | 29 +++ .../include/ThunderBirdRecordView.h | 54 +++++ .../src/ThunderBirdRecordPresenter.cpp | 127 ++++++++++ .../thunderbird/src/ThunderBirdRecordView.cpp | 216 ++++++++++++++++++ 5 files changed, 427 insertions(+) create mode 100644 code/sdk/application/wearable/n9/nativeapp/nativeui/thunderbird/include/ThunderBirdRecordPresenter.h create mode 100644 code/sdk/application/wearable/n9/nativeapp/nativeui/thunderbird/include/ThunderBirdRecordView.h create mode 100644 code/sdk/application/wearable/n9/nativeapp/nativeui/thunderbird/src/ThunderBirdRecordPresenter.cpp create mode 100644 code/sdk/application/wearable/n9/nativeapp/nativeui/thunderbird/src/ThunderBirdRecordView.cpp diff --git a/code/sdk/application/wearable/n9/nativeapp/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/n9/nativeapp/nativelauncher/include/AppViewIDs.h index 24edf3aa2..b105dcfc0 100644 --- a/code/sdk/application/wearable/n9/nativeapp/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/n9/nativeapp/nativelauncher/include/AppViewIDs.h @@ -125,6 +125,7 @@ typedef enum : uint16_t VIEW_SLEEPMODE, // sleep mode VIEW_SET_DESKTOP, // 设置主题 VIEW_THUNDER_BIRD, //雷鸟 + VIEW_THUNDER_RECORD, //雷鸟录音 /* ---------------------------- 650-0723patch 合并 ---------------------------- */ VIEW_MAIN_BREATHEASE, VIEW_FLASHLIGHT_0723, // 手电筒; diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/thunderbird/include/ThunderBirdRecordPresenter.h b/code/sdk/application/wearable/n9/nativeapp/nativeui/thunderbird/include/ThunderBirdRecordPresenter.h new file mode 100644 index 000000000..089dbae94 --- /dev/null +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/thunderbird/include/ThunderBirdRecordPresenter.h @@ -0,0 +1,29 @@ +#ifndef THUNDERBIRD_RECORD_PRESENTER_H_ +#define THUNDERBIRD_RECORD_PRESENTER_H_ + +#include "Presenter.h" +#include "thunderbird/include/ThunderBirdRecordView.h" +#include "thunderbird/include/ThunderBirdModel.h" + +namespace OHOS +{ + class ThunderBirdRecordPresenter : public Presenter + { + public: + ThunderBirdRecordPresenter(); + virtual ~ThunderBirdRecordPresenter(); + static ThunderBirdRecordPresenter *GetInstance(void); + + // 重写Presenter的虚函数 + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnKeyEvent(UIView &view, const KeyEvent &event) override; + + private: + void HandleRecordButtonClick(); + void HandleVolumeUpButtonClick(); + void HandleVolumeDownButtonClick(); + }; +} + +#endif diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/thunderbird/include/ThunderBirdRecordView.h b/code/sdk/application/wearable/n9/nativeapp/nativeui/thunderbird/include/ThunderBirdRecordView.h new file mode 100644 index 000000000..c4c242abd --- /dev/null +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/thunderbird/include/ThunderBirdRecordView.h @@ -0,0 +1,54 @@ +#ifndef THUNDERBIRD_RECORD_VIEW_H_ +#define THUNDERBIRD_RECORD_VIEW_H_ + +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_label_button.h" + +namespace OHOS +{ + class ThunderBirdRecordView + { + public: + ThunderBirdRecordView(); + virtual ~ThunderBirdRecordView(); + static ThunderBirdRecordView *GetInstance(void); + UIViewGroup *ThunderBirdRecordViewInit(void); + void ClearAll(void); + void Show(int16_t showView); + + // 更新文本标签 + void UpdateTextLabel(const char* text); + void UpdateVolumeText(int volume); + + // 获取按键引用(供Presenter使用) + UILabelButton* GetRecordButton() { return RecordButton; } + UILabelButton* GetVolumeUpButton() { return VolumeUpButton; } + UILabelButton* GetVolumeDownButton() { return VolumeDownButton; } + + // 获取状态 + bool IsRecording() const { return isRecording; } + int GetCurrentVolume() const { return currentVolume; } + + // 设置状态 + void SetRecording(bool recording); + void SetVolume(int volume); + + private: + UIViewGroup *group{nullptr}; + UILabelExt *TextLabel{nullptr}; // 主文本标签 + UILabelExt *VolumeLabel{nullptr}; // 音量显示标签 + UILabelButton *RecordButton{nullptr}; // 录音按键 + UILabelButton *VolumeUpButton{nullptr}; // 音量加按键 + UILabelButton *VolumeDownButton{nullptr}; // 音量减按键 + UIImageView *RecordIcon{nullptr}; // 录音图标 + + // 状态变量 + bool isRecording{false}; + int currentVolume{50}; // 音量范围 0-100 + }; +} + +#endif diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/thunderbird/src/ThunderBirdRecordPresenter.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/thunderbird/src/ThunderBirdRecordPresenter.cpp new file mode 100644 index 000000000..650d3574f --- /dev/null +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/thunderbird/src/ThunderBirdRecordPresenter.cpp @@ -0,0 +1,127 @@ +#include "thunderbird/include/ThunderBirdRecordPresenter.h" +#include "thunderbird/include/ThunderBirdRecordView.h" +#include "thunderbird/include/ThunderBirdModel.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "wearable_log.h" + +namespace OHOS +{ + static ThunderBirdRecordPresenter *g_pThunderBirdRecordPresenter{nullptr}; + + REGIST_SLICE(VIEW_THUNDER_RECORD, ThunderBirdRecordView, ThunderBirdRecordPresenter); + + ThunderBirdRecordPresenter::ThunderBirdRecordPresenter() + { + g_pThunderBirdRecordPresenter = this; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdRecordPresenter::ThunderBirdRecordPresenter"); + } + + ThunderBirdRecordPresenter::~ThunderBirdRecordPresenter() + { + g_pThunderBirdRecordPresenter = nullptr; + } + + ThunderBirdRecordPresenter *ThunderBirdRecordPresenter::GetInstance(void) + { + return g_pThunderBirdRecordPresenter; + } + + bool ThunderBirdRecordPresenter::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdRecordPresenter::OnClick"); + + const char* viewId = view.GetViewId(); + if (viewId == nullptr) { + return false; + } + + if (strcmp(viewId, "RECORD_BUTTON") == 0) { + HandleRecordButtonClick(); + return true; + } else if (strcmp(viewId, "VOLUME_UP_BUTTON") == 0) { + HandleVolumeUpButtonClick(); + return true; + } else if (strcmp(viewId, "VOLUME_DOWN_BUTTON") == 0) { + HandleVolumeDownButtonClick(); + return true; + } + + return false; + } + + bool ThunderBirdRecordPresenter::OnDrag(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdRecordPresenter::OnDrag"); + // 可以在这里处理拖拽事件,比如返回上一页 + return false; + } + + bool ThunderBirdRecordPresenter::OnKeyEvent(UIView &view, const KeyEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdRecordPresenter::OnKeyEvent"); + // 可以在这里处理物理按键事件 + return false; + } + + void ThunderBirdRecordPresenter::HandleRecordButtonClick() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HandleRecordButtonClick"); + + ThunderBirdRecordView* view = ThunderBirdRecordView::GetInstance(); + if (view == nullptr) { + return; + } + + bool isRecording = view->IsRecording(); + + if (!isRecording) + { + // 开始录音 + ThunderBirdModel::GetInstance()->StartRecording(); + view->SetRecording(true); + } + else + { + // 停止录音 + ThunderBirdModel::GetInstance()->StopRecording(); + view->SetRecording(false); + } + } + + void ThunderBirdRecordPresenter::HandleVolumeUpButtonClick() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HandleVolumeUpButtonClick"); + + ThunderBirdRecordView* view = ThunderBirdRecordView::GetInstance(); + if (view == nullptr) { + return; + } + + int currentVolume = view->GetCurrentVolume(); + if (currentVolume < 100) + { + int newVolume = currentVolume + 10; + if (newVolume > 100) newVolume = 100; + view->SetVolume(newVolume); + } + } + + void ThunderBirdRecordPresenter::HandleVolumeDownButtonClick() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HandleVolumeDownButtonClick"); + + ThunderBirdRecordView* view = ThunderBirdRecordView::GetInstance(); + if (view == nullptr) { + return; + } + + int currentVolume = view->GetCurrentVolume(); + if (currentVolume > 0) + { + int newVolume = currentVolume - 10; + if (newVolume < 0) newVolume = 0; + view->SetVolume(newVolume); + } + } +} diff --git a/code/sdk/application/wearable/n9/nativeapp/nativeui/thunderbird/src/ThunderBirdRecordView.cpp b/code/sdk/application/wearable/n9/nativeapp/nativeui/thunderbird/src/ThunderBirdRecordView.cpp new file mode 100644 index 000000000..8bc77110f --- /dev/null +++ b/code/sdk/application/wearable/n9/nativeapp/nativeui/thunderbird/src/ThunderBirdRecordView.cpp @@ -0,0 +1,216 @@ +#include "thunderbird/include/ThunderBirdRecordView.h" +#include "thunderbird/include/ThunderBirdModel.h" +#include "wearable_log.h" +#include + +namespace OHOS +{ + static ThunderBirdRecordView *g_pThunderBirdRecordView{nullptr}; + + ThunderBirdRecordView::ThunderBirdRecordView() + { + g_pThunderBirdRecordView = this; + currentVolume = 50; // 初始化音量为50 + isRecording = false; + } + + ThunderBirdRecordView::~ThunderBirdRecordView() + { + g_pThunderBirdRecordView = nullptr; + ClearAll(); + } + + ThunderBirdRecordView *ThunderBirdRecordView::GetInstance(void) + { + return g_pThunderBirdRecordView; + } + + void ThunderBirdRecordView::ClearAll(void) + { + if (group != nullptr) + { + group->RemoveAll(); + delete group; + group = nullptr; + } + if (TextLabel != nullptr) { delete TextLabel; TextLabel = nullptr; } + if (VolumeLabel != nullptr) { delete VolumeLabel; VolumeLabel = nullptr; } + if (RecordButton != nullptr) { delete RecordButton; RecordButton = nullptr; } + if (VolumeUpButton != nullptr) { delete VolumeUpButton; VolumeUpButton = nullptr; } + if (VolumeDownButton != nullptr) { delete VolumeDownButton; VolumeDownButton = nullptr; } + if (RecordIcon != nullptr) { delete RecordIcon; RecordIcon = nullptr; } + } + + UIViewGroup *ThunderBirdRecordView::ThunderBirdRecordViewInit(void) + { + group = new UIViewGroup(); + if (group == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ThunderBirdRecordView::group null!"); + return nullptr; + } + + // 设置组的基本属性 + group->SetPosition(0, 0, 240, 240); + group->SetStyle(STYLE_BACKGROUND_OPA, 0); + + // 创建主文本标签 + TextLabel = new UILabelExt(); + if (TextLabel != nullptr) + { + TextLabel->SetPosition(20, 30, 200, 40); + TextLabel->SetText("录音控制面板"); + TextLabel->SetFont("HarmonyOS_Sans_SC_Regular_16"); + TextLabel->SetStyle(STYLE_TEXT_COLOR, Color::White()); + TextLabel->SetAlign(TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER); + group->Add(TextLabel); + } + + // 创建音量显示标签 + VolumeLabel = new UILabelExt(); + if (VolumeLabel != nullptr) + { + VolumeLabel->SetPosition(20, 80, 200, 30); + char volumeText[32]; + snprintf(volumeText, sizeof(volumeText), "音量: %d%%", currentVolume); + VolumeLabel->SetText(volumeText); + VolumeLabel->SetFont("HarmonyOS_Sans_SC_Regular_14"); + VolumeLabel->SetStyle(STYLE_TEXT_COLOR, Color::White()); + VolumeLabel->SetAlign(TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER); + group->Add(VolumeLabel); + } + + // 创建录音按键 + RecordButton = new UILabelButton(); + if (RecordButton != nullptr) + { + RecordButton->SetPosition(70, 130, 100, 40); + RecordButton->SetText("开始录音"); + RecordButton->SetFont("HarmonyOS_Sans_SC_Regular_14"); + RecordButton->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue()); + RecordButton->SetStyle(STYLE_TEXT_COLOR, Color::White()); + RecordButton->SetAlign(TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER); + + // 设置按键ID,供Presenter识别 + RecordButton->SetViewId("RECORD_BUTTON"); + + group->Add(RecordButton); + } + + // 创建音量加按键 + VolumeUpButton = new UILabelButton(); + if (VolumeUpButton != nullptr) + { + VolumeUpButton->SetPosition(20, 190, 60, 30); + VolumeUpButton->SetText("音量+"); + VolumeUpButton->SetFont("HarmonyOS_Sans_SC_Regular_12"); + VolumeUpButton->SetStyle(STYLE_BACKGROUND_COLOR, Color::Green()); + VolumeUpButton->SetStyle(STYLE_TEXT_COLOR, Color::White()); + VolumeUpButton->SetAlign(TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER); + + // 设置按键ID,供Presenter识别 + VolumeUpButton->SetViewId("VOLUME_UP_BUTTON"); + + group->Add(VolumeUpButton); + } + + // 创建音量减按键 + VolumeDownButton = new UILabelButton(); + if (VolumeDownButton != nullptr) + { + VolumeDownButton->SetPosition(160, 190, 60, 30); + VolumeDownButton->SetText("音量-"); + VolumeDownButton->SetFont("HarmonyOS_Sans_SC_Regular_12"); + VolumeDownButton->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red()); + VolumeDownButton->SetStyle(STYLE_TEXT_COLOR, Color::White()); + VolumeDownButton->SetAlign(TEXT_ALIGN_CENTER, TEXT_ALIGN_CENTER); + + // 设置按键ID,供Presenter识别 + VolumeDownButton->SetViewId("VOLUME_DOWN_BUTTON"); + + group->Add(VolumeDownButton); + } + + // 创建录音图标 + RecordIcon = new UIImageView(); + if (RecordIcon != nullptr) + { + RecordIcon->SetPosition(100, 50, 40, 40); + // 这里可以设置录音图标,暂时使用背景色表示 + RecordIcon->SetStyle(STYLE_BACKGROUND_COLOR, Color::Gray()); + RecordIcon->SetVisible(false); // 初始隐藏 + group->Add(RecordIcon); + } + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ThunderBirdRecordView init completed"); + return group; + } + + void ThunderBirdRecordView::Show(int16_t showView) + { + if (group != nullptr) + { + group->SetVisible(true); + } + } + + void ThunderBirdRecordView::SetRecording(bool recording) + { + isRecording = recording; + + if (RecordButton != nullptr) + { + if (recording) + { + RecordButton->SetText("停止录音"); + RecordButton->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red()); + } + else + { + RecordButton->SetText("开始录音"); + RecordButton->SetStyle(STYLE_BACKGROUND_COLOR, Color::Blue()); + } + } + + if (RecordIcon != nullptr) + { + RecordIcon->SetVisible(recording); + } + + if (recording) + { + UpdateTextLabel("正在录音..."); + } + else + { + UpdateTextLabel("录音已停止"); + } + } + + void ThunderBirdRecordView::SetVolume(int volume) + { + if (volume >= 0 && volume <= 100) + { + currentVolume = volume; + UpdateVolumeText(currentVolume); + } + } + + void ThunderBirdRecordView::UpdateTextLabel(const char* text) + { + if (TextLabel != nullptr && text != nullptr) + { + TextLabel->SetText(text); + } + } + + void ThunderBirdRecordView::UpdateVolumeText(int volume) + { + if (VolumeLabel != nullptr) + { + char volumeText[32]; + snprintf(volumeText, sizeof(volumeText), "音量: %d%%", volume); + VolumeLabel->SetText(volumeText); + } + } +} -- 2.17.1