From eb97dbf2f262a38e0e551a8de5a2be5504561b2a Mon Sep 17 00:00:00 2001 From: Caisking Date: Wed, 26 Mar 2025 16:36:33 +0800 Subject: [PATCH] =?utf8?q?=E8=AF=AD=E9=9F=B3=E5=8A=A9=E6=89=8B=EF=BC=9A?= =?utf8?q?=E5=A2=9E=E5=8A=A0=E8=AF=AD=E9=9F=B3=E5=8A=A9=E6=89=8BUI?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../assistant/include/AssistantAnswerView.h | 41 +++ .../assistant/include/AssistantBleView.h | 42 +++ .../assistant/include/AssistantHfpView.h | 52 +++ .../assistant/include/AssistantModel.h | 38 +++ .../assistant/include/AssistantPresenter.h | 39 +++ .../include/AssistantStartFailedView.h | 32 ++ .../assistant/include/AssistantView.h | 78 +++++ .../assistant/src/AssistantAnswerView.cpp | 320 ++++++++++++++++++ .../assistant/src/AssistantBleView.cpp | 261 ++++++++++++++ .../assistant/src/AssistantHfpView.cpp | 266 +++++++++++++++ .../nativeui/assistant/src/AssistantModel.cpp | 196 +++++++++++ .../assistant/src/AssistantPresenter.cpp | 135 ++++++++ .../src/AssistantStartFailedView.cpp | 120 +++++++ .../nativeui/assistant/src/AssistantView.cpp | 248 ++++++++++++++ 14 files changed, 1868 insertions(+) create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantAnswerView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantBleView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantHfpView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantModel.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantPresenter.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantStartFailedView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantAnswerView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantBleView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantHfpView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantModel.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantPresenter.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantStartFailedView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantView.cpp diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantAnswerView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantAnswerView.h new file mode 100644 index 000000000..e26cbefe5 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantAnswerView.h @@ -0,0 +1,41 @@ + +#ifndef AssistantAnswer_VIEW_H +#define AssistantAnswer_VIEW_H + + +#include "UiConfig.h" +#include "View.h" +#include "components/ui_button.h" +#include "components/ui_circle_progress.h" +#include "components/ui_image_animator.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_label_button_ext.h" +#include "components/ui_label_ext.h" +#include "components/ui_view_group.h" +#include "wearable_log.h" + +namespace OHOS { +class AssistantAnswerView { +public: + AssistantAnswerView(); + virtual ~AssistantAnswerView(); + static AssistantAnswerView *GetInstance(void); + + UIScrollView *AssistantAnswerViewInit(void); + void ClearAll(void); + + void InitScrollView(void); + void InitNoteLabel(void); + void InitImageAnimator(void); + void InitStopButton(void); + +private: + UIScrollView *scrollView{nullptr}; + UILabelExt *notelabel{nullptr}; + UIImageAnimatorView *imageAnimator{nullptr}; + UILabelButtonExt *stopButton{nullptr}; + bool initViewStatus{false}; +}; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantBleView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantBleView.h new file mode 100644 index 000000000..94d719928 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantBleView.h @@ -0,0 +1,42 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-08-12 11:31:35 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-09-03 20:13:24 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/player/include/AssistantBleView.cpp + */ +#ifndef AssistantBleView_VIEW_H +#define AssistantBleView_VIEW_H +#include "components/ui_label_ext.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_button.h" +namespace OHOS +{ + class AssistantBleView + { + public: + AssistantBleView(); + ~AssistantBleView(); + UIScrollView *CreateAssistantBleView(void); + + private: + bool CreateAssistantBleViewLabel(); + bool CreateAssistantBleViewButton(); + void ClearAll(); + void get_bt_name(void); + UIScrollView *scrollView{nullptr}; + UILabelExt *titleLabel{nullptr}; // 标题 + UILabelExt *IPoneLabel{nullptr}; + UILabelExt *AndroidLabel{nullptr}; + UILabelExt *BTNoteLabel1{nullptr}; + UILabelExt *BTNoteLabel2{nullptr}; + UILabelExt *BTNoteLabel3{nullptr}; + UILabelExt *CloseLabel{nullptr}; + UIButton *CloseButton{nullptr}; + UIView::OnDragListener *dragListener{nullptr}; + uint8_t ble_name[30]{0}; + }; + +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantHfpView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantHfpView.h new file mode 100644 index 000000000..243079eb8 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantHfpView.h @@ -0,0 +1,52 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-08-10 16:23:34 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-10 17:42:47 + * @FilePath: + * /FD230/code/sdk/application/wearable/fd230app/nativeui/player/include/AssistantHfpView.h + */ +#ifndef AssistantHfpView_VIEW_H +#define AssistantHfpView_VIEW_H +#include "components/ui_button.h" +#include "components/ui_image_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_scroll_view.h" +#include "components/ui_view_group.h" + +namespace OHOS { +class AssistantHfpView { +public: + struct LabelConfig { + int16_t left; + int16_t top; + int16_t width; + int16_t height; + int16_t fontSize; + int16_t lineHeigh; + uint16_t textId; + uint8_t lineBreakMode; + }; + AssistantHfpView(); + ~AssistantHfpView(); + UIScrollView *CreateAssistantHfpView(void); + +private: + UILabelExt *AssistantHfpViewLabelInit(LabelConfig &labelconfig); + bool CreateAssistantHfpViewLabel(void); + bool CreateAssistantHfpViewImage(void); + bool CreateAssistantHfpViewButton(void); + + void ClearAll(); + UIScrollView *scrollView{nullptr}; + UILabelExt *titleLabel{nullptr}; // 标题 + UIImageView *bluetoothImage{nullptr}; + UIImageView *image66{nullptr}; + UIImageView *image99{nullptr}; + UILabelExt *noteLabel{nullptr}; + UIButton *OkButton{nullptr}; + UILabelExt *OkLabel{nullptr}; + UIView::OnDragListener *dragListener{nullptr}; +}; +} +#endif diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantModel.h new file mode 100644 index 000000000..4ee1d8a32 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantModel.h @@ -0,0 +1,38 @@ + + +#ifndef Assistant_MODEL_H +#define Assistant_MODEL_H + +#include +#include +#include +#include + +namespace OHOS { + +class AssistantModel { +public: + // 获取单例实例 + AssistantModel(); + ~AssistantModel(); + static AssistantModel *GetInstance(); + + void Init(); + //获取状态[hfp] + bool GetHFPStatus(void); + //开启语音助手[soc] + bool StartAssistant(void); + //关闭语音助手 + void StopAssistant(void); + //跳转界面 + bool ChangeToMainView(void); + +private: + // 禁止拷贝构造和赋值操作 + AssistantModel(const AssistantModel &) = delete; + AssistantModel &operator=(const AssistantModel &) = delete; +}; + +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantPresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantPresenter.h new file mode 100644 index 000000000..4c729985e --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantPresenter.h @@ -0,0 +1,39 @@ + + +#ifndef _Assistant_PRESENTER_H +#define _Assistant_PRESENTER_H + +#include "AssistantView.h" +#include "ModelListenerSample.h" +#include "Presenter.h" + +namespace OHOS { + +static constexpr const char *WAKE_ASSISTANT = "wake_assistant"; +static constexpr const char *STOP_ASSISTANT = "stop_assistant"; +static constexpr const char *STOP_ASSISTANT_FAIL = "stop_assistant_fail"; +static constexpr const char *STOP_ASSISTANT_HFP_FAIL = "stop_assistant_hfp_fail"; +static constexpr const char *ASSISTANT_HFP_BLE = "stop_assistant_hfp_ble"; +static constexpr const char *ASSISTANT_BLE_NOTE = "assistant_ble_note"; + +class AssistantView; +class AssistantPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener, + public RootView::OnKeyActListener { +public: + AssistantPresenter(); + virtual ~AssistantPresenter(); + + + static AssistantPresenter *GetInstance(); + +private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 +}; +} // namespace OHOS + +#endif // SLEEPDETAIL_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantStartFailedView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantStartFailedView.h new file mode 100644 index 000000000..b75206038 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantStartFailedView.h @@ -0,0 +1,32 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-08-12 11:31:35 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-09-03 20:13:24 + * @FilePath: + * /FD230/code/sdk/application/wearable/fd230app/nativeui/player/include/AssistantStartFailedView.cpp + */ +#ifndef AssistantStartFailedView_VIEW_H +#define AssistantStartFailedView_VIEW_H +#include "components/ui_label_button_ext.h" +#include "components/ui_label_ext.h" +#include "components/ui_scroll_view.h" +#include "components/ui_view_group.h" +#include "components/ui_image_view.h" +namespace OHOS { +class AssistantStartFailedView { +public: + AssistantStartFailedView(); + ~AssistantStartFailedView(); + UIScrollView *CreateAssistantStartFailedView(void); + +private: + void ClearAll(); + UIScrollView *scrollView{nullptr}; + UILabelExt *Label{nullptr}; + UIImageView *ImageView{nullptr}; + UILabelButtonExt *LabelButton = nullptr; +}; + +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantView.h new file mode 100644 index 000000000..105dfaff0 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/include/AssistantView.h @@ -0,0 +1,78 @@ + +#ifndef ASSISTANT_VIEW_H +#define ASSISTANT_VIEW_H + + +#include "View.h" +#include "components/ui_button.h" +#include "components/ui_image_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_picker.h" +#include "components/ui_scroll_view.h" +#include "ui_resource_string.h" +#include +#include +#include + +#include "assistant/include/AssistantAnswerView.h" +#include "assistant/include/AssistantBleView.h" +#include "assistant/include/AssistantHfpView.h" +#include "assistant/include/AssistantStartFailedView.h" + +namespace OHOS { + +typedef enum { + /** 主界面 */ + ASSISTANT_MAIN_VIEW, + /** 功能界面 */ + ASSISTANT_ANSWER_VIEW, + /** HFP 唤醒失败 */ + ASSISTANT_HFP_FAIL_VIEW, + /** 蓝牙连接错误说明 */ + ASSISTANT_BLE_NOTE_VIEW, + /** 启动失败 */ + ASSISTANT_START_FAILED_VIEW, + /** 最大视图数,用于界限检查 */ + MAX_ASSISTANT_VIEWID, +} ASSISTANT_VIEWID; + +class AssistantPresenter; + +class AssistantView : public View { +public: + AssistantView(); + ~AssistantView(); + static AssistantView *GetInstance(void); + void OnStart() override; + + + bool ClickFunc(int16_t interface); + bool CheckViewParam(int16_t hideView, int16_t showView); + void ChangeView(int16_t hideView, int16_t showView); + + bool ChangeToMainView(int16_t thisView); + bool ChangeToAnswerView(int16_t thisView); + bool ChangeToHfpView(int16_t thisView); + bool ChangeToBleView(int16_t thisView); + bool ChangeToStartFailedView(int16_t thisView); + UIScrollView *GetAssistantScrollView(int ViewId); + + void InitView(); + +private: + AssistantView *p_MianView{nullptr}; + AssistantAnswerView *p_AnswerView{nullptr}; + AssistantHfpView *p_HfpView{nullptr}; + AssistantBleView *p_BleView{nullptr}; + AssistantStartFailedView *p_StartFailedView{nullptr}; + +private: + UILabelExt *noteLabel{nullptr}; + UIButton *wakeButton{nullptr}; + + UIScrollView *AssistantScrollView[MAX_ASSISTANT_VIEWID]{nullptr}; + AssistantView(AssistantView &&) = delete; + AssistantView &operator=(AssistantView &&) = delete; +}; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantAnswerView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantAnswerView.cpp new file mode 100644 index 000000000..3a7944836 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantAnswerView.cpp @@ -0,0 +1,320 @@ + + +#include "UiConfig.h" +#include "power_display_service.h" +#include "ui_image_animator.h" +#include "ui_resource_string.h" +#include "uicomponents/UIComponents.h" +#include "wearable_log.h" + +#include "assistant/include/AssistantAnswerView.h" +#include "assistant/include/AssistantPresenter.h" + +namespace OHOS { + +// 动态刷新设置 +static constexpr uint16_t IMAGE_SIZE_X = 396; +static constexpr uint16_t IMAGE_SIZE_Y = 176; +static constexpr uint16_t IMAGE_POSITION_X = 36; +static constexpr uint16_t IMAGE_POSITION_Y = 193; +static constexpr uint16_t DETECTION_IMAGE_ANIMATORVIEW_SIZE = 30; +static constexpr uint16_t DETECTION_IMAGE_ANIMATORVIEW_SPEED = 30; + +static ImageAnimatorInfo g_imageAnimatorInfo_assistant[30] = { + {PNG_VOICE_ASSISTANT_IMAGE_0, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_1, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_2, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_3, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_4, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_5, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_6, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_7, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_8, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_9, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_10, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_11, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_12, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_13, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_14, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_15, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_16, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_17, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_18, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_19, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_20, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_21, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_22, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_23, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_24, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_25, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_26, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_27, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_28, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, + {PNG_VOICE_ASSISTANT_IMAGE_29, + {IMAGE_POSITION_X, IMAGE_POSITION_Y}, + IMAGE_SIZE_X, + IMAGE_SIZE_Y, + IMG_SRC_FILE_PATH}, +}; +// 静态指针,用于获取单例实例 +static AssistantAnswerView *g_pAssistantAnswer{nullptr}; +AssistantAnswerView::AssistantAnswerView() { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "AssistantAnswerView::AssistantAnswerView"); + g_pAssistantAnswer = this; // 设置单例指针 +} +AssistantAnswerView::~AssistantAnswerView() { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "AssistantAnswerView::~AssistantAnswerView"); + ClearAll(); // 清理资源 + g_pAssistantAnswer = nullptr; // 释放单例指针 +} +AssistantAnswerView *AssistantAnswerView::GetInstance() { + return g_pAssistantAnswer; // 返回单例实例 +} +void AssistantAnswerView::ClearAll() { + + scrollView->RemoveAll(); + + delete notelabel; // 删除提示标签 + notelabel = nullptr; + + delete stopButton; // 删除按键 + stopButton = nullptr; + + if (imageAnimator) { + imageAnimator->Stop(); + delete imageAnimator; + imageAnimator = nullptr; + } + + delete scrollView; // 删除滚动视图 + scrollView = nullptr; +} + +UIScrollView *AssistantAnswerView::AssistantAnswerViewInit() { + if (scrollView == nullptr) { + scrollView = new UIScrollView(); + if (scrollView == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "AssistantAnswerView::新建滚动视图失败!"); + return nullptr; // 创建失败,返回空指针 + } + } + // 初始化滚动视图属性 + InitScrollView(); + + // 设置拖拽监听器 + UIView::OnDragListener *dragListener = + static_cast(AssistantPresenter::GetInstance()); + if (!dragListener) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "AssistantPresenter::获取实例失败!"); + return nullptr; // 获取失败,返回空指针 + } + scrollView->SetOnDragListener(dragListener); + + // 初始化提示标签 + InitNoteLabel(); + + // 初始化动画 + InitImageAnimator(); + + // 初始化按键 + InitStopButton(); + + // 添加视图到滚动视图中 + + scrollView->Add(imageAnimator); + scrollView->Add(stopButton); + scrollView->Add(notelabel); + + return scrollView; // 返回初始化后的滚动视图 +} + +void AssistantAnswerView::InitScrollView() { + // 设置滚动视图的初始位置和样式 + scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), + Screen::GetInstance().GetHeight()); + scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollView->SetScrollBlankSize(100); + scrollView->SetMaxScrollDistance(1000); + scrollView->SetThrowDrag(true); + scrollView->SetHorizontalScrollState(false); // 禁止水平滑动 + scrollView->SetVerticalScrollState(false); // 禁止垂直滑动 +} + +void AssistantAnswerView::InitImageAnimator() { + + imageAnimator = new UIImageAnimatorView(); + if (imageAnimator == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "AssistantAnswerView::new UIImageAnimatorView fail"); + return; + } + imageAnimator->SetImageAnimatorSrc(g_imageAnimatorInfo_assistant, + DETECTION_IMAGE_ANIMATORVIEW_SIZE, + DETECTION_IMAGE_ANIMATORVIEW_SPEED); + imageAnimator->SetRepeat(true); + imageAnimator->Start(); +} +void AssistantAnswerView::InitNoteLabel() { + notelabel = new UILabelExt(); + if (!notelabel) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "AssistantAnswerView::新建标题失败!"); + return; + } + // 设置标签的基本属性 + notelabel->SetPosition(43, 100); + notelabel->Resize(380, 60); + notelabel->SetViewId("notelabel"); + notelabel->SetStyle(STYLE_TEXT_FONT, 30); + // TODO:多国语言 + notelabel->SetTextId(STR_CALLSOMEONE); + // notelabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + notelabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + notelabel->SetRollSpeed(23); + notelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + notelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); +} +void AssistantAnswerView::InitStopButton() { + if (stopButton == nullptr) { + stopButton = new UILabelButtonExt(); + if (stopButton == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "stopButton new fail"); + return; + } + } + stopButton->SetPosition(0, 366, 466, 100); + stopButton->SetViewId(STOP_ASSISTANT); + stopButton->SetImageSrc(PNG_466x100BUTTON_IMAGE, PNG_466x100BUTTON_IMAGE); + stopButton->SetTextId(STR_STOP); + stopButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + stopButton->SetStyle(STYLE_LINE_HEIGHT, 35); + stopButton->SetTextColor(Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff)); + UIView::OnClickListener *buttonClick = + static_cast(AssistantPresenter::GetInstance()); + if (buttonClick == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "buttonClick new fail"); + return; + } + stopButton->SetOnClickListener(buttonClick); +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantBleView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantBleView.cpp new file mode 100644 index 000000000..c9015843e --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantBleView.cpp @@ -0,0 +1,261 @@ +#include "assistant/include/AssistantBleView.h" +#include "assistant/include/AssistantPresenter.h" +#include "player/include/PlayersView.h" +#include "ui_resource_string.h" +#include "uicomponents/UIComponents.h" +#include "wearable_log.h" +#include +namespace OHOS { +static constexpr const char *CLOSEBUTTON_VIEWID = "CLOSEButton"; +AssistantBleView::AssistantBleView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AssistantBleView::AssistantBleView"); +} + +AssistantBleView::~AssistantBleView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AssistantBleView::~AssistantBleView"); + ClearAll(); +} +void AssistantBleView::ClearAll() { + + if (scrollView != nullptr) { + scrollView->RemoveAll(); + if (titleLabel != nullptr) { + delete titleLabel; + titleLabel = nullptr; + } + if (IPoneLabel != nullptr) { + delete IPoneLabel; + IPoneLabel = nullptr; + } + if (AndroidLabel != nullptr) { + delete AndroidLabel; + AndroidLabel = nullptr; + } + if (BTNoteLabel1 != nullptr) { + delete BTNoteLabel1; + BTNoteLabel1 = nullptr; + } + if (BTNoteLabel2 != nullptr) { + delete BTNoteLabel2; + BTNoteLabel2 = nullptr; + } + if (BTNoteLabel3 != nullptr) { + delete BTNoteLabel3; + BTNoteLabel3 = nullptr; + } + if (CloseLabel != nullptr) { + delete CloseLabel; + CloseLabel = nullptr; + } + if (CloseButton != nullptr) { + delete CloseButton; + CloseButton = nullptr; + } + delete scrollView; + scrollView = nullptr; + } +} + +bool AssistantBleView::CreateAssistantBleViewLabel() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AssistantBleView::CreateAssistantBleViewLabel"); + /* ------------------------------- titleLabel ------------------------------- + */ + if (titleLabel == nullptr) { + titleLabel = new UILabelExt(); + if (titleLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel new fail"); + return false; + } + } + titleLabel->SetPosition(83, 50, 300, 35); + titleLabel->SetStyle(STYLE_TEXT_FONT, 30); + titleLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + titleLabel->SetTextId(STR_BLUETOOTH_CONNECTION_FAILED); // 蓝牙连接失败 + titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* ------------------------------- BTNoteLabel1 ------------------------------ + */ + if (BTNoteLabel1 == nullptr) { + BTNoteLabel1 = new UILabelExt(); + if (BTNoteLabel1 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BTNoteLabel1 new fail"); + return false; + } + } + BTNoteLabel1->SetPosition(53, 140, 360, 35); + BTNoteLabel1->SetStyle(STYLE_TEXT_FONT, 30); + BTNoteLabel1->SetStyle(STYLE_LINE_HEIGHT, 35); + BTNoteLabel1->SetTextId(STR_SOLUTION); + BTNoteLabel1->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + BTNoteLabel1->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* ------------------------------- IPoneLabel ------------------------------- + */ + if (IPoneLabel == nullptr) { + IPoneLabel = new UILabelExt(); + if (IPoneLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "IPoneLabel new fail"); + return false; + } + } + IPoneLabel->SetPosition( + 53, BTNoteLabel1->GetY() + BTNoteLabel1->GetTextHeight(), 360, 35); + IPoneLabel->SetStyle(STYLE_TEXT_FONT, 30); + IPoneLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + IPoneLabel->SetTextId(STR_IPHONE); + IPoneLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + IPoneLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* ------------------------------ BTNoteLabel2 ------------------------------ + */ + if (BTNoteLabel2 == nullptr) { + BTNoteLabel2 = new UILabelExt(); + if (BTNoteLabel2 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BTNoteLabel2 new fail"); + return false; + } + } + BTNoteLabel2->SetPosition( + 53, IPoneLabel->GetY() + IPoneLabel->GetTextHeight(), 360, 455); + BTNoteLabel2->SetStyle(STYLE_TEXT_FONT, 30); + BTNoteLabel2->SetStyle(STYLE_LINE_HEIGHT, 35); + BTNoteLabel2->SetTextId(STR_ENABLE_BLUETOOTH_CALL_NOTE_IPHONE); + UpdateLabel(BTNoteLabel2, (char *)ble_name, + STR_ENABLE_BLUETOOTH_CALL_NOTE_IPHONE); + BTNoteLabel2->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + BTNoteLabel2->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* ------------------------------- AndroidLabel + * ------------------------------- */ + if (AndroidLabel == nullptr) { + AndroidLabel = new UILabelExt(); + if (AndroidLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AndroidLabel new fail"); + return false; + } + } + AndroidLabel->SetPosition( + 53, BTNoteLabel2->GetY() + BTNoteLabel2->GetTextHeight() + 40, 360, 35); + AndroidLabel->SetStyle(STYLE_TEXT_FONT, 30); + AndroidLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + AndroidLabel->SetTextId(STR_ANDROID); + AndroidLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + AndroidLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* ------------------------------ BTNoteLabel3 ------------------------------ + */ + if (BTNoteLabel3 == nullptr) { + BTNoteLabel3 = new UILabelExt(); + if (BTNoteLabel3 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BTNoteLabel2 new fail"); + return false; + } + } + BTNoteLabel3->SetPosition( + 53, AndroidLabel->GetY() + AndroidLabel->GetTextHeight(), 360, 455); + BTNoteLabel3->SetStyle(STYLE_TEXT_FONT, 30); + BTNoteLabel3->SetStyle(STYLE_LINE_HEIGHT, 35); + BTNoteLabel3->SetTextId(STR_ENABLE_BLUETOOTH_CALL_NOTE_ANDROID); + UpdateLabel(BTNoteLabel3, (char *)ble_name, + STR_ENABLE_BLUETOOTH_CALL_NOTE_ANDROID); + BTNoteLabel3->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + BTNoteLabel3->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* ------------------------------- CloseLabel ------------------------------- + */ + if (CloseLabel == nullptr) { + CloseLabel = new UILabelExt(); + if (CloseLabel == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CloseLabel new fail"); + return false; + } + } + CloseLabel->SetPosition( + 83, BTNoteLabel3->GetY() + BTNoteLabel3->GetTextHeight() + 40 + 29, 300, + 35); + CloseLabel->SetStyle(STYLE_TEXT_FONT, 30); + CloseLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + CloseLabel->SetTextId(STR_CLOSE); // 关闭 + CloseLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + CloseLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + CloseLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + + return true; +} + +bool AssistantBleView::CreateAssistantBleViewButton() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AssistantBleView::CreateAssistantBleViewButton"); + if (CloseButton == nullptr) { + CloseButton = new UIButton(); + if (CloseButton == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CloseButton new fail!!"); + return false; + } + } + CloseButton->SetPosition( + 43, BTNoteLabel3->GetY() + BTNoteLabel3->GetTextHeight() + 40, 380, 100); + CloseButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + CloseButton->SetViewId(ASSISTANT_BLE_NOTE); + CloseButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff383838, + UIButton::PRESSED); + UIView::OnClickListener *buttonClick = + static_cast(AssistantPresenter::GetInstance()); + if (buttonClick == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "buttonClick new fail"); + return false; + } + CloseButton->SetOnClickListener(buttonClick); + return true; +} + +UIScrollView *AssistantBleView::CreateAssistantBleView(void) { + WEARABLE_LOGD( + WEARABLE_LOG_MODULE_APP, + "MusicPlayerBluetoothDisConView::CreateMusicPlayerBluetoothDisConView"); + /* -------------------------------------------------------------------------- + */ + if (scrollView == nullptr) { + scrollView = new UIScrollView(); + if (scrollView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView new fail"); + return nullptr; + } + } + scrollView->SetPosition(0, 0, 466, 466); + scrollView->SetScrollBlankSize(50); + scrollView->SetReboundSize(35); + scrollView->SetThrowDrag(true); + scrollView->SetMaxScrollDistance(1000); + scrollView->SetDirection(UIScrollView::VERTICAL); + // 设置拖拽监听器 + UIView::OnDragListener *dragListener = + static_cast(AssistantPresenter::GetInstance()); + if (!dragListener) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "AssistantPresenter::获取实例失败!"); + return nullptr; // 获取失败,返回空指针 + } + scrollView->SetOnDragListener(dragListener); + + /* --------------------------------- 获取蓝牙名称* + * --------------------------------- */ + get_bt_name(); + /* -------------------------------------------------------------------------- + */ + if (!CreateAssistantBleViewLabel() || !CreateAssistantBleViewButton()) { + return nullptr; + } + scrollView->Add(titleLabel); + scrollView->Add(BTNoteLabel1); + scrollView->Add(IPoneLabel); + scrollView->Add(AndroidLabel); + scrollView->Add(BTNoteLabel2); + scrollView->Add(BTNoteLabel3); + scrollView->Add(CloseButton); + scrollView->Add(CloseLabel); + return scrollView; +} + +void AssistantBleView::get_bt_name(void) { + uint32_t ble_name_len = sizeof(ble_name); + uapi_get_nv_btname(ble_name, &ble_name_len); +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantHfpView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantHfpView.cpp new file mode 100644 index 000000000..cc9745cb3 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantHfpView.cpp @@ -0,0 +1,266 @@ +#include "assistant/include/AssistantHfpView.h" +#include "assistant/include/AssistantPresenter.h" +#include "player/include/PlayersView.h" +#include "string.h" +#include "ui_resource_image.h" +#include "ui_resource_string.h" +#include "uicomponents/UIComponents.h" +#include "wearable_log.h" +namespace OHOS { + +static constexpr const char *OKBUTTON_VIEWID = "OkButton"; +AssistantHfpView::AssistantHfpView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AssistantHfpView::AssistantHfpView"); +} + +AssistantHfpView::~AssistantHfpView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AssistantHfpView::~AssistantHfpView"); + ClearAll(); +} +void AssistantHfpView::ClearAll() { + + if (scrollView != nullptr) { + scrollView->RemoveAll(); + if (titleLabel != nullptr) { + delete titleLabel; + titleLabel = nullptr; + } + if (bluetoothImage != nullptr) { + delete bluetoothImage; + bluetoothImage = nullptr; + } + if (image66 != nullptr) { + delete image66; + image66 = nullptr; + } + if (image99 != nullptr) { + delete image99; + image99 = nullptr; + } + if (noteLabel != nullptr) { + delete noteLabel; + noteLabel = nullptr; + } + if (OkButton != nullptr) { + delete OkButton; + OkButton = nullptr; + } + if (OkLabel != nullptr) { + delete OkLabel; + OkLabel = nullptr; + } + delete scrollView; + scrollView = nullptr; + } +} + +UILabelExt * +AssistantHfpView::AssistantHfpViewLabelInit(LabelConfig &labelconfig) { + UILabelExt *label = new UILabelExt(); + if (label == nullptr) { + return nullptr; + } + label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, + labelconfig.height); + label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); + label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); + label->SetTextId(labelconfig.textId); + label->SetLineBreakMode(labelconfig.lineBreakMode); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetRollSpeed(23); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); + return label; +} + +bool AssistantHfpView::CreateAssistantHfpViewLabel(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "AssistantHfpView::CreateAssistantHfpViewLabel"); + LabelConfig labelConfig = { + .left = 83, + .top = 50, + .width = 300, + .height = 35, + .fontSize = 30, + .lineHeigh = 35, + .textId = STR_BLUETOOTH_DISCONNECTED, /*蓝牙未连接*/ + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, + }; + titleLabel = AssistantHfpViewLabelInit(labelConfig); + if (nullptr == titleLabel) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel new fail!!"); + return false; + } + /* -------------------------------------------------------------------------- + */ + // labelConfig = { + // .left = 53, + // .top = 230, + // .width = 360, + // .height = 105, + // .fontSize = 30, + // .lineHeigh = 35, + // .textId = + // STR_MUSIC_PLAYER_SOURCE_NOTE, + // /*请从手表端应用界面进入“音乐”-“音乐来源”,设置为“手机模式”后重试*/ + // .lineBreakMode = UILabel::LINE_BREAK_WRAP, + // }; + // noteLabel = AssistantHfpViewLabelInit(labelConfig); + // if (nullptr == noteLabel) { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "noteLabel new fail!!"); + // return false; + // } + + // TODO:多国语言 + InitLabelExt(noteLabel, 53, 230, 360, 105, "label", STR_BLUENOTE, DEFAULT_VECTOR_FONT_FILENAME_EN, 30); + noteLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + noteLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + noteLabel->SetRollSpeed(23); + /* -------------------------------------------------------------------------- + */ + int16_t y = noteLabel->GetY() + noteLabel->GetTextHeight() + 30 + 33; + labelConfig = { + .left = 133, + .top = y, + .width = 200, + .height = 35, + .fontSize = 30, + .lineHeigh = 35, + .textId = STR_KONW, /*知道了*/ + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, + }; + OkLabel = AssistantHfpViewLabelInit(labelConfig); + if (nullptr == OkLabel) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OkLabel new fail!!"); + return false; + } + + return true; +} + +bool AssistantHfpView::CreateAssistantHfpViewImage(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "AssistantHfpView::CreateAssistantHfpViewImage"); + if (bluetoothImage == nullptr) { + bluetoothImage = new UIImageView(); + if (bluetoothImage == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); + return false; + } + bluetoothImage->SetPosition(209, 120, 48, 80); + // if (!PlayersView::LoadPlayerImage(bluetoothImage, PLAYER_BLUETOOTH_COLOR)) { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneImage LoadPlayerImage fail"); + // return false; + // } + } + + /* -------------------------------------------------------------------------- + */ + if (image66 == nullptr) { + image66 = new UIImageView(); + if (image66 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); + return false; + } + image66->SetPosition(33, 200, 74, 52); + // if (!PlayersView::LoadPlayerImage(image66, PLAYER_UP_66)) { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneImage LoadPlayerImage fail"); + // return false; + // } + image66->SetAutoEnable(false); + image66->SetResizeMode(UIImageView::CENTER); + } + + if (image99 == nullptr) { + image99 = new UIImageView(); + if (image99 == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); + return false; + } + image99->SetPosition( + 344, noteLabel->GetY() + noteLabel->GetTextHeight() - 35, 74, 52); + // if (!PlayersView::LoadPlayerImage(image99, PLAYER_DOWM_66)) { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneImage LoadPlayerImage fail"); + // return false; + // } + image99->SetAutoEnable(false); + image99->SetResizeMode(UIImageView::CENTER); + } + + return true; +} + +bool AssistantHfpView::CreateAssistantHfpViewButton(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "AssistantHfpView::CreateAssistantHfpViewButton"); + if (OkButton == nullptr) { + OkButton = new UIButton(); + if (OkButton == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OkButton new fail!!"); + return false; + } + } + OkButton->SetPosition(0, noteLabel->GetY() + noteLabel->GetTextHeight() + 30, + 466, 100); + OkButton->SetImageSrc(PNG_BUTTON_466x100_IMAGE, PNG_BUTTON_466x100_IMAGE); + OkButton->SetViewId(STOP_ASSISTANT_HFP_FAIL); + OkButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff383838, + UIButton::PRESSED); + UIView::OnClickListener *buttonClick = + static_cast(AssistantPresenter::GetInstance()); + if (buttonClick == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "buttonClick new fail"); + return false; + } + OkButton->SetOnClickListener(buttonClick); + return true; +} + +UIScrollView *AssistantHfpView::CreateAssistantHfpView(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "AssistantHfpView::CreateAssistantHfpView"); + /* -------------------------------------------------------------------------- + */ + if (scrollView == nullptr) { + scrollView = new UIScrollView(); + if (scrollView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView new fail"); + return nullptr; + } + } + scrollView->SetPosition(0, 0, 466, 466); + scrollView->SetScrollBlankSize(50); + scrollView->SetViewId(ASSISTANT_HFP_BLE); + scrollView->SetReboundSize(35); + scrollView->SetDirection(UIScrollView::VERTICAL); + //设置页面点击监听器 + UIView::OnClickListener *buttonClick = + static_cast(AssistantPresenter::GetInstance()); + if (buttonClick == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "buttonClick new fail"); + return nullptr; + } + scrollView->SetOnClickListener(buttonClick); + // 设置拖拽监听器 + UIView::OnDragListener *dragListener = + static_cast(AssistantPresenter::GetInstance()); + if (!dragListener) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "AssistantPresenter::获取实例失败!"); + return nullptr; // 获取失败,返回空指针 + } + scrollView->SetOnDragListener(dragListener); + + if (!CreateAssistantHfpViewLabel() || !CreateAssistantHfpViewImage() || + !CreateAssistantHfpViewButton()) { + return nullptr; + } + scrollView->Add(titleLabel); + scrollView->Add(bluetoothImage); + scrollView->Add(image66); + scrollView->Add(image99); + scrollView->Add(noteLabel); + scrollView->Add(OkButton); + scrollView->Add(OkLabel); + return scrollView; +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantModel.cpp new file mode 100644 index 000000000..26f2da765 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantModel.cpp @@ -0,0 +1,196 @@ + + +#include "assistant/include/AssistantModel.h" +#include "assistant/include/AssistantPresenter.h" +#include "assistant/include/AssistantView.h" + +#include "AppViewIDs.h" +#include "NativeAbility.h" + +// #include "bleEvent.h" +// #include "cat1_ctl.h" +// #include "cat1_server.h" +// #include "lwip/apps/http_client.h" +// #include "vibrator_service.h" + +#include "broadcast_feature.h" +#include "broadcast_service.h" + +#include "custom_runtime.h" +#include "custom_utils.h" + +#include "graphic_service.h" +#include "samgr_lite.h" +#include "tcxo.h" +#include "thread_adapter.h" +#include "thread_init.h" + +#include "wearable_log.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include + +// #include "PhoneService.h" +// #include "PhoneServiceC.h" + +extern "C" { +int uapi_open_voice_recognition(void); +int uapi_close_voice_recognition(void); +} + +#ifdef __cplusplus +extern "C" { +#endif +static void Notify(void *args, const Topic topic, Request *request); + +using namespace OHOS; + +Subscriber AssistantSubscirber = { + .identity = NULL, + .args = NULL, + .Notify = Notify, +}; +void AssistantSubscribeTopic(Topic topic) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "stepsubscribeTopic, topic=%u", topic); + BroadcastApi *broadcastApi = NULL; + IUnknown *api = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE_NAME, + BROADCAST_FEATURE_NAME); + if (api == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "stepsubscribeTopic, GetFeatureApi failed"); + return; + } + int result = + api->QueryInterface(api, DEFAULT_VERSION, (void **)&broadcastApi); + if (result != 0 || broadcastApi == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "stepsubscribeTopic, QueryInterface failed"); + return; + } + broadcastApi->SubscribeTopic((IUnknown *)broadcastApi, topic, + &AssistantSubscirber); + broadcastApi->Release((IUnknown *)broadcastApi); +} + +void AssistantUnsubscribeTopic(Topic topic) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AssistantUnsubscribeTopic, topic=%u", + topic); + BroadcastApi *broadcastApi = NULL; + IUnknown *api = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE_NAME, + BROADCAST_FEATURE_NAME); + if (api == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AssistantUnsubscribeTopic, GetFeatureApi failed"); + return; + } + int result = + api->QueryInterface(api, DEFAULT_VERSION, (void **)&broadcastApi); + if (result != 0 || broadcastApi == NULL) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AssistantUnsubscribeTopic, QueryInterface failed"); + return; + } + broadcastApi->UnsubscribeTopic((IUnknown *)broadcastApi, topic, + &AssistantSubscirber); + broadcastApi->Release((IUnknown *)broadcastApi); +} + +static void Notify(void *args, const Topic topic, Request *request) { + UNUSED(args); + UNUSED(topic); + if (request == NULL) { + return; + } + // 退出语音助手 + if (request->msgId == TOPIC_EVENT_ASSISTANT_NOTE) { + // 界面刷新 + GraphicService::GetInstance()->PostGraphicEvent(std::bind( + &AssistantModel::ChangeToMainView, AssistantModel::GetInstance())); + } +} +#ifdef __cplusplus +} +#endif + +namespace OHOS { + +// 启动 uapi_open_voice_recognition() +// hfp是否连接 uapi_hfp_connect_state() +// 关闭 uapi_close_voice_recognition() +// 断联 HFP_SCO_STATE_DISCONNECTING + +//取消订阅 + +AssistantModel::AssistantModel() {} +AssistantModel::~AssistantModel() { + AssistantUnsubscribeTopic(TOPIC_EVENT_ASSISTANT_NOTE); +} +AssistantModel *AssistantModel::GetInstance(void) { + static AssistantModel instance; + return &instance; +} +//进行语音助手订阅 +void AssistantModel::Init() { + AssistantSubscribeTopic(TOPIC_EVENT_ASSISTANT_NOTE); +} + +//获取状态[hfp] +bool AssistantModel::GetHFPStatus(void) { + // if (uapi_hfp_connect_state()) { + // WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "uapi_hfp_connect_state is ok"); + // return true; + // } + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "uapi_hfp_connect_state is failed"); + return false; +} +//开启语音助手[soc] +bool AssistantModel::StartAssistant(void) { + // if (uapi_open_voice_recognition() == 0) { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_open_voice_recognition is + // ok"); + // //成功开启语音助手 + // uapi_dev_runtime_set_voice_status(1); + // return true; + // } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "uapi_open_voice_recognition is failed"); + return false; +} +//关闭语音助手 +void AssistantModel::StopAssistant(void) { + // if (uapi_close_voice_recognition() == 0) { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + // "uapi_close_voice_recognition is ok"); + // } else { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + // "uapi_close_voice_recognition is failed"); + // } +} + +//语音回答界面->主界面 +bool AssistantModel::ChangeToMainView(void) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "退出语音助手\r\n"); + AssistantView *p_AssistantView = AssistantView::GetInstance(); + if (p_AssistantView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " AssistantView::GetInstance fail!"); + return false; + } + if ((p_AssistantView->GetAssistantScrollView(ASSISTANT_ANSWER_VIEW)) + ->IsVisible() == true && + p_AssistantView->GetAssistantScrollView(ASSISTANT_MAIN_VIEW) + ->IsVisible() == false) { + //设置退出状态 + // uapi_dev_runtime_set_voice_status(0); + p_AssistantView->ChangeView(ASSISTANT_ANSWER_VIEW, ASSISTANT_MAIN_VIEW); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "退出语音助手成功\r\n"); + } + return true; +} + +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantPresenter.cpp new file mode 100644 index 000000000..b83083c66 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantPresenter.cpp @@ -0,0 +1,135 @@ + +#include "AppViewIDs.h" +#include "KeyInputListener.h" +#include "NativeAbility.h" +#include "common/key_code.h" +#include "components/ui_label_ext.h" +#include "custom_utils.h" +#include "ui_resource_string.h" + +#include "broadcast_service.h" + +#include "NativeRegisterManager.h" +#include "assistant/include/AssistantModel.h" +#include "assistant/include/AssistantPresenter.h" +#include "custom_runtime.h" +#include "custom_utils.h" +#include "gfx_utils/mem_check.h" +#include "graphic_service.h" +namespace OHOS { + +REGIST_MENU_PRO(VIEW_OFFLINEVOICE, AssistantView, AssistantPresenter, + PNG_APPLIST_SMART_IMAGE_BIG, PNG_APPLIST_SMART_IMAGE, + PNG_APPLIST_SMART_IMAGE, "语音助手", STR_VOICE_ASSISTANT); + +// 当前Presenter属性实例化的内存指针 +static AssistantPresenter *g_pAssistantPresenter = nullptr; +AssistantPresenter::AssistantPresenter() { g_pAssistantPresenter = this; } + +AssistantPresenter::~AssistantPresenter() { g_pAssistantPresenter = nullptr; } + +AssistantPresenter *AssistantPresenter::GetInstance() { + + return g_pAssistantPresenter; +} + +bool AssistantPresenter::OnDrag(UIView &view, const DragEvent &event) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AssistantPresenter::OnDrag"); + AssistantView *p_AssistantView = AssistantView::GetInstance(); + if (p_AssistantView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " AssistantView::GetInstance fail!"); + return false; + } + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + (event.GetDeltaX() > 20) && + (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) { + /*在主界面进行退出*/ + if (&view == p_AssistantView->GetAssistantScrollView(ASSISTANT_MAIN_VIEW)) { + NativeAbility::GetInstance().Back( + TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } + /*在其他界面返回主界面*/ + if (&view == + p_AssistantView->GetAssistantScrollView(ASSISTANT_ANSWER_VIEW)) { + p_AssistantView->ChangeView(ASSISTANT_ANSWER_VIEW, ASSISTANT_MAIN_VIEW); + } + if (&view == + p_AssistantView->GetAssistantScrollView(ASSISTANT_HFP_FAIL_VIEW)) { + p_AssistantView->ChangeView(ASSISTANT_HFP_FAIL_VIEW, ASSISTANT_MAIN_VIEW); + } + if (&view == + p_AssistantView->GetAssistantScrollView(ASSISTANT_BLE_NOTE_VIEW)) { + p_AssistantView->ChangeView(ASSISTANT_BLE_NOTE_VIEW, + ASSISTANT_HFP_FAIL_VIEW); + } + if (&view == + p_AssistantView->GetAssistantScrollView(ASSISTANT_START_FAILED_VIEW)) { + p_AssistantView->ChangeView(ASSISTANT_START_FAILED_VIEW, + ASSISTANT_MAIN_VIEW); + } + } + return true; +} + +bool AssistantPresenter::OnClick(UIView &view, const ClickEvent &event) { + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AssistantPresenter::OnClick %s", + view.GetViewId()); + AssistantView *p_AssistantView = AssistantView::GetInstance(); + if (p_AssistantView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " AssistantView::GetInstance fail!"); + return false; + } + /*唤醒语音助手*/ + if (strcmp(view.GetViewId(), WAKE_ASSISTANT) == 0) { + + //校验hfp + if (AssistantModel::GetInstance()->GetHFPStatus()) { + //校验开启状态 + if (AssistantModel::GetInstance()->StartAssistant()) { + p_AssistantView->ChangeView(ASSISTANT_MAIN_VIEW, ASSISTANT_ANSWER_VIEW); + } else { + p_AssistantView->ChangeView(ASSISTANT_MAIN_VIEW, + ASSISTANT_START_FAILED_VIEW); + } + } else { + p_AssistantView->ChangeView(ASSISTANT_MAIN_VIEW, ASSISTANT_HFP_FAIL_VIEW); + } + } + /*停止语音助手*/ + if (strcmp(view.GetViewId(), STOP_ASSISTANT) == 0) { + p_AssistantView->ChangeView(ASSISTANT_ANSWER_VIEW, ASSISTANT_MAIN_VIEW); + AssistantModel::GetInstance()->StopAssistant(); + } + /*唤醒失败*/ + if (strcmp(view.GetViewId(), STOP_ASSISTANT_FAIL) == 0) { + p_AssistantView->ChangeView(ASSISTANT_START_FAILED_VIEW, + ASSISTANT_MAIN_VIEW); + } + /*hfp失败*/ + if (strcmp(view.GetViewId(), STOP_ASSISTANT_HFP_FAIL) == 0) { + p_AssistantView->ChangeView(ASSISTANT_HFP_FAIL_VIEW, ASSISTANT_MAIN_VIEW); + } + /*hfp->blenote*/ + if (strcmp(view.GetViewId(), ASSISTANT_HFP_BLE) == 0) { + p_AssistantView->ChangeView(ASSISTANT_MAIN_VIEW, ASSISTANT_BLE_NOTE_VIEW); + } + /*ble提醒*/ + if (strcmp(view.GetViewId(), ASSISTANT_BLE_NOTE) == 0) { + p_AssistantView->ChangeView(ASSISTANT_BLE_NOTE_VIEW, ASSISTANT_MAIN_VIEW); + } + return true; +} + +bool AssistantPresenter::OnKeyAct(UIView &view, const KeyEvent &event) { + unsigned short keyID = event.GetKeyId(); + unsigned short keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && + keyState == 1 && uapi_get_screen_state() == 0) { + NativeAbility::GetInstance().Back( + TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } + return true; +} +} // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantStartFailedView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantStartFailedView.cpp new file mode 100644 index 000000000..b06321a17 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantStartFailedView.cpp @@ -0,0 +1,120 @@ +#include "assistant/include/AssistantStartFailedView.h" +#include "assistant/include/AssistantPresenter.h" +#include "string.h" +#include "ui_resource_string.h" +#include "wearable_log.h" +namespace OHOS { + +static constexpr const char *OKBUTTON_VIEWID = "OkButton"; +AssistantStartFailedView::AssistantStartFailedView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AssistantStartFailedView::AssistantStartFailedView"); +} + +AssistantStartFailedView::~AssistantStartFailedView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AssistantStartFailedView::~AssistantStartFailedView"); + ClearAll(); +} +void AssistantStartFailedView::ClearAll() { + + if (scrollView != nullptr) { + scrollView->RemoveAll(); + if (Label != nullptr) { + delete Label; + Label = nullptr; + } + if (ImageView != nullptr) { + delete ImageView; + ImageView = nullptr; + } + if (LabelButton != nullptr) { + delete LabelButton; + LabelButton = nullptr; + } + delete scrollView; + scrollView = nullptr; + } +} + +UIScrollView *AssistantStartFailedView::CreateAssistantStartFailedView(void) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "View::ViewInit_BlueToothConnected"); + if (scrollView == nullptr) { + /* --------------------------- scrollView --------------------------- */ + if (scrollView == nullptr) { + scrollView = new UIScrollView(); + if (scrollView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView new fail"); + return nullptr; + } + } + scrollView->SetPosition(0, 0, 466, 466); + scrollView->SetScrollBlankSize(50); + scrollView->SetReboundSize(35); + scrollView->SetDirection(UIScrollView::VERTICAL); + // 设置拖拽监听器 + UIView::OnDragListener *dragListener = + static_cast( + AssistantPresenter::GetInstance()); + if (!dragListener) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, + "AssistantPresenter::获取实例失败!"); + return nullptr; // 获取失败,返回空指针 + } + scrollView->SetOnDragListener(dragListener); + /* ----------------------- ImageView ---------------------- */ + ImageView = new UIImageView(); + if (ImageView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "[ViewInit_BlueToothConnected] TitleLabel new fail!!"); + return nullptr; + } + ImageView->SetPosition(193, 120, 80, 80); + ImageView->SetSrc(PNG_ATTENTION_IMAGE); + /* ----------------------------- Label ----------------------------- */ + Label = new UILabelExt(); + if (Label == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "[CreateDeviceUnBindingView] Label new fail"); + return nullptr; + } + Label->SetPosition(53, 250, 360, 35); + Label->SetStyle(STYLE_TEXT_FONT, 30); + Label->SetStyle(STYLE_LINE_HEIGHT, 35); + Label->SetTextId(STR_VOICE_FAIL); //启用语音助手失败 TODO::多国语言 + Label->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + Label->SetTextColor(Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff)); + Label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + Label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* -------------------------- LabelButton -------------------------- */ + LabelButton = new UILabelButtonExt(); + if (LabelButton == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "[CreateDeviceUnBindingView] LabelButton new fail"); + return nullptr; + } + LabelButton->SetPosition(0, 366, 466, 100); + LabelButton->SetViewId(STOP_ASSISTANT_FAIL); + LabelButton->SetImageSrc(PNG_BUTTON_466x100_IMAGE, + PNG_BUTTON_466x100_IMAGE); + LabelButton->SetTextId(STR_CLOSE); //关闭 + LabelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + LabelButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, + UIButton::PRESSED); + UIView::OnClickListener *buttonClick = + static_cast( + AssistantPresenter::GetInstance()); + if (buttonClick == nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "buttonClick new fail"); + return nullptr; + } + LabelButton->SetOnClickListener(buttonClick); + /* ----------------------------------- Add + * ---------------------------------- */ + scrollView->Add(ImageView); + scrollView->Add(Label); + scrollView->Add(LabelButton); + } + return scrollView; +} +} // namespace OHOS diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantView.cpp new file mode 100644 index 000000000..24b85261d --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/assistant/src/AssistantView.cpp @@ -0,0 +1,248 @@ +#include "assistant/include/AssistantView.h" +#include "assistant/include/AssistantModel.h" +#include "assistant/include/AssistantPresenter.h" + +#include "UiConfig.h" +#include "common/image_cache_manager.h" +#include "components/ui_button.h" +#include "components/ui_scroll_view.h" +#include "custom_utils.h" +#include "ui_resource_image.h" +#include "ui_resource_string.h" +#include "uicomponents/UIComponents.h" +#include + +namespace OHOS { + +static AssistantView *g_pAssistantView{nullptr}; +static const uint32_t BACK_GROUND_COLOR = 0xfff6f6f6; +static const char *WAKE_IMAGE = "/user/res/assistant/assistant.bin"; + +AssistantView::AssistantView() { g_pAssistantView = this; } + +AssistantView::~AssistantView() { + + if (AssistantScrollView[ASSISTANT_MAIN_VIEW]) { + AssistantScrollView[ASSISTANT_MAIN_VIEW]->RemoveAll(); + if (noteLabel) { + delete noteLabel; + noteLabel = nullptr; + } + if (wakeButton) { + delete wakeButton; + wakeButton = nullptr; + } + delete AssistantScrollView[ASSISTANT_MAIN_VIEW]; + AssistantScrollView[ASSISTANT_MAIN_VIEW] = nullptr; + } + for (int i = 0; i < MAX_ASSISTANT_VIEWID; i++) { + if (AssistantScrollView[i]) { + AssistantScrollView[i] = nullptr; + } + } + if (p_MianView) { + delete p_MianView; + p_MianView = nullptr; + } + if (p_AnswerView) { + delete p_AnswerView; + p_AnswerView = nullptr; + } + if (p_BleView) { + delete p_BleView; + p_BleView = nullptr; + } + if (p_HfpView) { + delete p_HfpView; + p_HfpView = nullptr; + } + if (p_StartFailedView) { + delete p_StartFailedView; + p_StartFailedView = nullptr; + } + g_pAssistantView = nullptr; +} + +AssistantView *AssistantView::GetInstance() { return g_pAssistantView; } + +void AssistantView::InitView() { + if (AssistantScrollView[ASSISTANT_MAIN_VIEW] == nullptr) { + AssistantScrollView[ASSISTANT_MAIN_VIEW] = new UIScrollView(); + if (AssistantScrollView[ASSISTANT_MAIN_VIEW] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AssistantScrollView[ASSISTANT_MAIN_VIEW] new fail"); + return; + } + AssistantScrollView[ASSISTANT_MAIN_VIEW]->SetScrollBlankSize(35); + AssistantScrollView[ASSISTANT_MAIN_VIEW]->SetReboundSize(50); + AssistantScrollView[ASSISTANT_MAIN_VIEW]->SetPosition( + 0, 0, Screen::GetInstance().GetWidth(), + Screen::GetInstance().GetHeight()); + AssistantScrollView[ASSISTANT_MAIN_VIEW]->SetHorizontalScrollState(false); + AssistantScrollView[ASSISTANT_MAIN_VIEW]->SetOnDragListener(presenter_); + AssistantScrollView[ASSISTANT_MAIN_VIEW]->SetTouchable(true); + AssistantScrollView[ASSISTANT_MAIN_VIEW]->SetDraggable(true); + AssistantScrollView[ASSISTANT_MAIN_VIEW]->SetStyle(STYLE_BACKGROUND_COLOR, + BACK_GROUND_COLOR); + AssistantScrollView[ASSISTANT_MAIN_VIEW]->SetStyle(STYLE_BACKGROUND_COLOR, + Color::Black().full); + //初始化label TODO::多国语言 + InitRollLabel(noteLabel, 53, 339, 360, 35, "label", STR_WAKE_VOIVE, + DEFAULT_VECTOR_FONT_FILENAME_EN, 30); + //初始化button + InitButton(wakeButton, 128, 91, 210, 210, WAKE_ASSISTANT); + wakeButton->SetImageSrc(WAKE_IMAGE, WAKE_IMAGE); + wakeButton->SetOnClickListener(presenter_); + + AssistantScrollView[ASSISTANT_MAIN_VIEW]->Add(wakeButton); + AssistantScrollView[ASSISTANT_MAIN_VIEW]->Add(noteLabel); + } +} +/* -------------------------------------------------------------------------- */ +// 主视图 +bool AssistantView::ChangeToMainView(int16_t thisView) { + if (AssistantScrollView[thisView] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AssistantView::ChangeToMainView"); + AddViewToRootContainer(AssistantScrollView[thisView]); + } + return true; +} + +bool AssistantView::ChangeToAnswerView(int16_t thisView) { + if (AssistantScrollView[thisView] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AssistantView::ChangeToAnswerView"); + p_AnswerView = new AssistantAnswerView(); + if (p_AnswerView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AssistantView:: new scrollView[%d] fail", thisView); + return false; + } + AssistantScrollView[thisView] = p_AnswerView->AssistantAnswerViewInit(); + AddViewToRootContainer(AssistantScrollView[thisView]); + } + return true; +} + +bool AssistantView::ChangeToHfpView(int16_t thisView) { + if (AssistantScrollView[thisView] == nullptr) { + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AssistantView::ChangeToHfpView"); + p_HfpView = new AssistantHfpView(); + if (p_HfpView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AssistantView:: new scrollView[%d] fail", thisView); + return false; + } + AssistantScrollView[thisView] = p_HfpView->CreateAssistantHfpView(); + AddViewToRootContainer(AssistantScrollView[thisView]); + } + return true; +} + +bool AssistantView::ChangeToBleView(int16_t thisView) { + if (AssistantScrollView[thisView] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AssistantView::ChangeToBleView"); + p_BleView = new AssistantBleView(); + if (p_BleView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AssistantView:: new scrollView[%d] fail", thisView); + return false; + } + AssistantScrollView[thisView] = p_BleView->CreateAssistantBleView(); + AddViewToRootContainer(AssistantScrollView[thisView]); + } + return true; +} + +bool AssistantView::ChangeToStartFailedView(int16_t thisView) { + if (AssistantScrollView[thisView] == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AssistantView::ChangeToStartFailedView"); + p_StartFailedView = new AssistantStartFailedView(); + if (p_StartFailedView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AssistantView:: new scrollView[%d] fail", thisView); + return false; + } + AssistantScrollView[thisView] = + p_StartFailedView->CreateAssistantStartFailedView(); + AddViewToRootContainer(AssistantScrollView[thisView]); + } + return true; +} + +struct AssistantViewMapper { + const int16_t viewId; + bool (AssistantView::*func)(int16_t thisView); +}; + +static const AssistantViewMapper ViewMapper[] = { + {ASSISTANT_MAIN_VIEW, &AssistantView::ChangeToMainView}, + {ASSISTANT_ANSWER_VIEW, &AssistantView::ChangeToAnswerView}, + {ASSISTANT_HFP_FAIL_VIEW, &AssistantView::ChangeToHfpView}, + {ASSISTANT_BLE_NOTE_VIEW, &AssistantView::ChangeToBleView}, + {ASSISTANT_START_FAILED_VIEW, &AssistantView::ChangeToStartFailedView}, +}; + +// 根据传入的interface参数执行相应视图ID关联的成员函数。 +bool AssistantView::ClickFunc(int16_t interface) { + int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[ASSISTANT_MAIN_VIEW]); + for (int i = 0; i < funcSize; i++) { + if (interface == ViewMapper[i].viewId) { + bool jug = (this->*(ViewMapper[i].func))(interface); + if (jug == false) { + return false; + } + return true; + } + } + return false; +} + +/*检查传入的两个视图参数 hideView 和 showView 的有效性。*/ +bool AssistantView::CheckViewParam(int16_t hideView, int16_t showView) { + if (showView < 0 || showView >= MAX_ASSISTANT_VIEWID) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AssistantView::CheckViewParam showView err."); + return false; + } + + if (hideView < 0 || hideView > MAX_ASSISTANT_VIEWID) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AssistantView::CheckViewParam hideView err."); + return false; + } + + return true; +} + +// 切换视图 +void AssistantView::ChangeView(int16_t hideView, int16_t showView) { + if (!CheckViewParam(hideView, showView)) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "AssistantView::CheckViewParam failed."); + return; + } + AssistantScrollView[hideView]->SetVisible(false); + ClickFunc(showView); + AssistantScrollView[showView]->SetVisible(true); + Draw(); +} +UIScrollView *AssistantView::GetAssistantScrollView(int ViewId) { + if (AssistantScrollView[ViewId] == nullptr) { + return nullptr; + } + return AssistantScrollView[ViewId]; +} + +/* -------------------------------------------------------------------------- */ +void AssistantView::OnStart() { + View::OnStart(); + + InitView(); + + // RootView::GetInstance()->SetOnKeyActListener(presenter_); + AddViewToRootContainer(AssistantScrollView[ASSISTANT_MAIN_VIEW]); +} + +} // namespace OHOS \ No newline at end of file -- 2.17.1