From 941485c1f93c52aa5ca9f9ef9cde39b7f18e8ec0 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Thu, 27 Mar 2025 14:50:33 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=A0=E7=BB=9F=E8=93=9D=E7=89=99slice?= =?utf8?q?=E5=90=88=E5=B9=B6=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../BluetoothServiceOptionsPresenter.h | 43 ++ .../include/BluetoothServiceOptionsView.h | 90 ++++ .../include/ClassicBlueToothModel.h | 20 + .../include/ClassicBlueToothPresenter.h | 44 ++ .../include/ClassicBlueToothView.h | 71 +++ .../src/BluetoothServiceOptionsPresenter.cpp | 171 +++++++ .../src/BluetoothServiceOptionsView.cpp | 462 ++++++++++++++++++ .../src/ClassicBlueToothModel.cpp | 14 + .../src/ClassicBlueToothPresenter.cpp | 177 +++++++ .../src/ClassicBlueToothView.cpp | 311 ++++++++++++ 10 files changed, 1403 insertions(+) create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/BluetoothServiceOptionsPresenter.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/BluetoothServiceOptionsView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/ClassicBlueToothModel.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/ClassicBlueToothPresenter.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/ClassicBlueToothView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothModel.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/BluetoothServiceOptionsPresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/BluetoothServiceOptionsPresenter.h new file mode 100644 index 000000000..36134ba16 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/BluetoothServiceOptionsPresenter.h @@ -0,0 +1,43 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-02-20 10:27:30 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-09-03 10:29:03 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/BluetoothServiceOptionsPresenter.h + */ +#ifndef BLUETOOTH_SERVICE_OPTIONS_PRESENTER_H +#define BLUETOOTH_SERVICE_OPTIONS_PRESENTER_H + +#include "Presenter.h" +#include "View.h" + +namespace OHOS +{ + class BluetoothServiceOptionsView; + class BluetoothServiceOptionsPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener, + public RootView::OnKeyActListener + { + public: + BluetoothServiceOptionsPresenter(); + virtual ~BluetoothServiceOptionsPresenter(); + + virtual void OnStart() override; + virtual void OnPause() override; + virtual void OnResume() override; + virtual void OnStop() override; + + static BluetoothServiceOptionsPresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; + bool X_DRAG_FLAG{false}; + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/BluetoothServiceOptionsView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/BluetoothServiceOptionsView.h new file mode 100644 index 000000000..6030a1836 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/BluetoothServiceOptionsView.h @@ -0,0 +1,90 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-25 11:49:58 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-05-06 15:00:23 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/BluetoothServiceOptionsView.h + */ + +#ifndef BLUETOOTH_SERVICE_OPTIONS_VIEW_H +#define BLUETOOTH_SERVICE_OPTIONS_VIEW_H + +#include "View.h" +#include "components/root_view.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_button.h" +#include "components/ui_image_view.h" +#include "components/ui_toggle_button.h" + +#ifdef FD230_650 +#include "aivoice/include/AiVoiceConnectingView.h" +#endif + +namespace OHOS +{ + // 返回setting视图界面 + class BluetoothServiceOptionsPresenter; + class BluetoothServiceOptionsView : public View + { + public: + struct LabelConfig + { + int16_t left; + int16_t top; + int16_t width; + int16_t height; + int16_t fontSize; // 字体大小 + int16_t lineHeigh; // 行高 + // const char *text; // 文本 + uint16_t textId; + uint8_t lineBreakMode; // 断行模式。 + }; + + typedef enum + { + CONNECT_HFP = 0, + DISCONNECT_HFP, + CONNECT_A2DP, + DISCONNECT_A2DP, + } BluetoothServiceOptionsView_state; + + BluetoothServiceOptionsView(); + virtual ~BluetoothServiceOptionsView(); + static BluetoothServiceOptionsView *GetInstance(void); + void BluetoothServiceOptionsViewInit(void); + void ClearAll(void); + UIToggleButton *GetHFP_ToggleButton(void); + UIToggleButton *GetA2DP_ToggleButton(void); + void show_connecting_view(bool data); + void Button_UPdata(void); + bool init_connect_timer(uint8_t type); + bool get_connectview_Visible(void); + + public: + virtual void OnStart() override; + + private: + bool SetUpBlueToothScrollView(void); + UILabelExt *SetBluetoothServiceOptionsViewLabel(LabelConfig &labelconfig); + bool SetUpBlueToothLabel(void); + bool SetUpBlueToothToggleButton(void); + bool SetUpBlueToothImageView(void); + UIScrollView *BlueToothScrollView = nullptr; + UILabelExt *Title = nullptr; + UILabelExt *HFP_Label{nullptr}; + UILabelExt *A2DP_Label{nullptr}; + UIImageView *HFP_Image{nullptr}; + UIImageView *A2DP_Image{nullptr}; + UIToggleButton *HFP_ToggleButton{nullptr}; // HFP + UIToggleButton *A2DP_ToggleButton{nullptr}; // A2DP + UIScrollView *connectingScrollView{nullptr}; + +#ifdef FD230_650 + AiVoiceConnectingView *p_AiVoiceConnectingView{nullptr}; +#endif + + bool initViewStatus{false}; + }; +} +#endif diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/ClassicBlueToothModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/ClassicBlueToothModel.h new file mode 100644 index 000000000..070a985c9 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/ClassicBlueToothModel.h @@ -0,0 +1,20 @@ +#ifndef CLASSIC_BLUETOOTH_MODEL_H +#define CLASSIC_BLUETOOTH_MODEL_H + +#include "wearable_log.h" +#include "ConfigModel.h" +namespace OHOS +{ + class ClassicBlueToothModel + { + public: + static ClassicBlueToothModel *GetInstance(void); + + private: + ClassicBlueToothModel(); + ClassicBlueToothModel(const ClassicBlueToothModel &) = delete; + ClassicBlueToothModel &operator=(const ClassicBlueToothModel &) = delete; + virtual ~ClassicBlueToothModel(); + }; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/ClassicBlueToothPresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/ClassicBlueToothPresenter.h new file mode 100644 index 000000000..0404af427 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/ClassicBlueToothPresenter.h @@ -0,0 +1,44 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-25 11:50:51 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-07-23 10:15:46 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothPresenter.h + */ +#ifndef CLASSIC_BLUETOOTH_PRESENTER_H +#define CLASSIC_BLUETOOTH_PRESENTER_H +#include "Presenter.h" +#include "View.h" +#include "classicbluetooth/include/ClassicBlueToothView.h" + +namespace OHOS +{ + class ClassicBlueToothView; + class ClassicBlueToothPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener, + public RootView::OnKeyActListener, + public UICheckBox::OnChangeListener + { + public: + ClassicBlueToothPresenter(); + virtual ~ClassicBlueToothPresenter(); + static ClassicBlueToothPresenter *GetInstance(); + + virtual void OnStart() override; + virtual void OnPause() override; + virtual void OnResume() override; + virtual void OnStop() override; + + private: + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; + bool OnChange(UICheckBox::UICheckBoxState state) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; + + bool X_DRAG_FLAG{false}; + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/ClassicBlueToothView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/ClassicBlueToothView.h new file mode 100644 index 000000000..2d878fda8 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/include/ClassicBlueToothView.h @@ -0,0 +1,71 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-25 11:51:04 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-06-17 18:08:27 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothView.h + */ +#ifndef CLASSIC_BLUETOOTH_VIEW_H +#define CLASSIC_BLUETOOTH_VIEW_H + + +#include "View.h" +#include "components/root_view.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_label_button_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_toggle_button.h" +#include "wearable_log.h" +namespace OHOS +{ + static constexpr const char *BLUETOOTHEARPHONEBUTTON = "BlueToothEarPhoneButton"; // 蓝牙耳机按钮ID + static constexpr const char *TRADIONALBLUETOOTHBUTTON = "TradionalBluetoothButton"; // 传统蓝牙服按钮ID + static constexpr const char *BLUETOOTHSERVICEOPTIONSBUTTON = "BluetoothServiceOptionsButton"; // 蓝牙服务选项按钮ID + // 返回setting视图界面 + class ClassicBlueToothPresenter; + class ClassicBlueToothView : public View + { + public: + struct LabelConfig + { + int16_t left; + int16_t top; + int16_t width; + int16_t height; + int16_t fontSize; // 字体大小 + int16_t lineHeigh; // 行高 + //const char *text; // 文本 + uint16_t textId; + uint8_t lineBreakMode; // 断行模式。 + }; + ClassicBlueToothView(); + virtual ~ClassicBlueToothView(); + static ClassicBlueToothView *GetInstance(void); + void ClassicBlueToothViewInit(void); + void ClearAll(void); + UIToggleButton * GetTradionalBlueToothToggleButton(void); + + public: + virtual void OnStart() override; + + private: + bool SetUpBlueToothScrollView(void); + UILabelExt *SetClassicBlueToothViewLabel(LabelConfig &labelconfig); + bool SetUpBlueToothLabel(void); + bool SetUpBlueToothButton(void); + bool SetUpBlueToothToggleButton(void); + UIScrollView *BlueToothScrollView = nullptr; + UILabelExt *Title = nullptr; + UILabelButtonExt *BlueToothEarPhoneButton = nullptr; // 蓝牙耳机按钮 + UILabelButtonExt *TradionalBlueToothButton = nullptr; // 传统蓝牙按钮 + UILabelButtonExt *BluetoothServiceOptionsButton = nullptr; // 蓝牙服务选项按钮 + UILabelExt *BlueToothEarPhoneLabel = nullptr; // 蓝牙耳机 + UILabelExt *TradionalBlueToothLabel = nullptr; // 传统蓝牙 + UILabelExt *BluetoothServiceOptionsLabel = nullptr; // 蓝牙服务选项 + UILabelExt *AttentionLabel = nullptr; + UIToggleButton *TradionalBlueToothToggleButton = nullptr; + bool initViewStatus{false}; + }; +} +#endif diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp new file mode 100644 index 000000000..84f0d949b --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp @@ -0,0 +1,171 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "common/key_code.h" +#include +#include +#include "wearable_log.h" +#include "ConfigModel.h" +#include "iostream" +#include "map" +#include "classicbluetooth/include/BluetoothServiceOptionsPresenter.h" +#include "classicbluetooth/include/BluetoothServiceOptionsView.h" +#include "BluetoothModel.h" +#include "PhoneService.h" +#include "bts_le_gap.h" +namespace OHOS +{ + // 当前Presenter属性实例化的内存指针 + static BluetoothServiceOptionsPresenter *g_pBluetoothServiceOptionsPresenter = nullptr; + + BluetoothServiceOptionsPresenter::BluetoothServiceOptionsPresenter() + { + g_pBluetoothServiceOptionsPresenter = this; + } + + BluetoothServiceOptionsPresenter::~BluetoothServiceOptionsPresenter() + { + g_pBluetoothServiceOptionsPresenter = nullptr; + } + + BluetoothServiceOptionsPresenter *BluetoothServiceOptionsPresenter::GetInstance() + { + return g_pBluetoothServiceOptionsPresenter; + } + + void BluetoothServiceOptionsPresenter::OnStart() + { + } + + void BluetoothServiceOptionsPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void BluetoothServiceOptionsPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void BluetoothServiceOptionsPresenter::OnStop(void) + { + } + + bool BluetoothServiceOptionsPresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::OnClick"); + BluetoothServiceOptionsView *classicBlueToothView = BluetoothServiceOptionsView::GetInstance(); + if (classicBlueToothView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::GetInstance"); + return false; + } + + std::map buttonMap = { + {classicBlueToothView->GetHFP_ToggleButton(), "HFP"}, + { + classicBlueToothView->GetA2DP_ToggleButton(), + "A2DP", + }, + }; + + auto it = buttonMap.find(&view); + if (it != buttonMap.end()) + { + UIToggleButton *toggleButton = dynamic_cast(&view); + if (toggleButton != nullptr) + { + classicBlueToothView->show_connecting_view(true); + if (toggleButton->GetState() == true) + { + if (it->second == "HFP") + { + ConfigModel::GetInstance()->SetHFPState(true); +#ifdef FD230_650 + uapi_hfp_connect(); +#endif + classicBlueToothView->init_connect_timer(BluetoothServiceOptionsView::CONNECT_HFP); + } + else if (it->second == "A2DP") + { + ConfigModel::GetInstance()->SetA2DPState(true); +#ifdef FD230_650 + uapi_a2dp_snk_connect(); +#endif + classicBlueToothView->init_connect_timer(BluetoothServiceOptionsView::CONNECT_A2DP); + } + } + else + { + if (it->second == "HFP") + { + ConfigModel::GetInstance()->SetHFPState(false); +#ifdef FD230_650 + uapi_hfp_disconnect(); +#endif + classicBlueToothView->init_connect_timer(BluetoothServiceOptionsView::DISCONNECT_HFP); + } + else if (it->second == "A2DP") + { + + ConfigModel::GetInstance()->SetA2DPState(false); +#ifdef FD230_650 + uapi_a2dp_snk_disconnect(); +#endif + classicBlueToothView->init_connect_timer(BluetoothServiceOptionsView::DISCONNECT_A2DP); + } + } + } + } + return true; + } + + bool BluetoothServiceOptionsPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + UNUSED(event); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + { + int16_t deltaX; + int16_t deltaY; + deltaX = event.GetDeltaX(); + deltaY = event.GetDeltaY(); + if (MATH_ABS(deltaX) >= MATH_ABS(deltaY) && MATH_ABS(deltaX) > 30) + { + // MainAlarmView::GetInstance()->DropView(view); + X_DRAG_FLAG = true; + } + } + return true; + } + + bool BluetoothServiceOptionsPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsPresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) + { + if (!BluetoothServiceOptionsView::GetInstance()->get_connectview_Visible()) + NativeAbility::GetInstance().Back(); + X_DRAG_FLAG = false; + } + + return true; + } + + bool BluetoothServiceOptionsPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16 keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + if (!BluetoothServiceOptionsView::GetInstance()->get_connectview_Visible()) + NativeAbility::GetInstance().Back(); + } + return true; + } +} diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp new file mode 100644 index 000000000..38c639cec --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp @@ -0,0 +1,462 @@ +#include "classicbluetooth/include/BluetoothServiceOptionsView.h" +#include "classicbluetooth/include/BluetoothServiceOptionsPresenter.h" +#include "ConfigModel.h" +#include "UiConfig.h" +#include "wearable_log.h" +#include "PhoneService.h" +#include "phoneservice/include/PhoneService.h" +#include "BluetoothModel.h" +#include "ui_resource_string.h" +#include "cmsis_os2.h" +#include "graphic_service.h" +#include "ConfigModelC.h" +namespace OHOS +{ + static BluetoothServiceOptionsView *g_pBluetoothServiceOptionsView{nullptr}; + + BluetoothServiceOptionsView::BluetoothServiceOptionsView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::BluetoothServiceOptionsView"); + g_pBluetoothServiceOptionsView = this; + } + + BluetoothServiceOptionsView::~BluetoothServiceOptionsView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~BluetoothServiceOptionsView::BluetoothServiceOptionsView"); + ClearAll(); + g_pBluetoothServiceOptionsView = nullptr; + } + + BluetoothServiceOptionsView *BluetoothServiceOptionsView::GetInstance() + { + return g_pBluetoothServiceOptionsView; + } + + void BluetoothServiceOptionsView::ClearAll() + { + if (initViewStatus == true) + { + if (BlueToothScrollView != nullptr) + { + BlueToothScrollView->RemoveAll(); + + if (Title != nullptr) + { + delete Title; + Title = nullptr; + } + if (HFP_Image != nullptr) + { + delete HFP_Image; + HFP_Image = nullptr; + } + if (A2DP_Image != nullptr) + { + delete A2DP_Image; + A2DP_Image = nullptr; + } + if (HFP_Label != nullptr) + { + delete HFP_Label; + HFP_Label = nullptr; + } + if (A2DP_Label != nullptr) + { + delete A2DP_Label; + A2DP_Label = nullptr; + } + if (HFP_ToggleButton != nullptr) + { + delete HFP_ToggleButton; + HFP_ToggleButton = nullptr; + } + if (A2DP_ToggleButton != nullptr) + { + delete A2DP_ToggleButton; + A2DP_ToggleButton = nullptr; + } +#ifdef FD230_650 + if (p_AiVoiceConnectingView) + { + delete p_AiVoiceConnectingView; + p_AiVoiceConnectingView = nullptr; + } +#endif + if (connectingScrollView) + { + delete connectingScrollView; + connectingScrollView = nullptr; + } + delete BlueToothScrollView; + BlueToothScrollView = nullptr; + } + } + } + + static osTimerId_t MG_TEST_timer = NULL; + static uint8_t button_state = 0; + static uint8_t count_num = 0; + static uint8_t connect_state = 0; + bool BluetoothServiceOptionsView::get_connectview_Visible(void) + { + return connectingScrollView->IsVisible(); + } + + static void connectTimerCallBackProc(int data) + { + + count_num++; + switch (button_state) + { + case BluetoothServiceOptionsView::CONNECT_HFP: +#ifdef FD230_650 + if (uapi_hfp_connect_state()) + { + if (cm_get_A2DP_switch() && uapi_a2dp_snk_get_device_connect_state()) + { + connect_state++; + } + else if (!cm_get_A2DP_switch()) + { + connect_state++; + } + } +#endif + break; + case BluetoothServiceOptionsView::DISCONNECT_HFP: + +#ifdef FD230_650 + if (!uapi_hfp_connect_state()) + { + { + connect_state++; + } + } +#endif + break; + case BluetoothServiceOptionsView::CONNECT_A2DP: +#ifdef FD230_650 + if (uapi_a2dp_snk_get_device_connect_state()) + { + connect_state++; + } +#endif + break; + case BluetoothServiceOptionsView::DISCONNECT_A2DP: +#ifdef FD230_650 + if (!uapi_a2dp_snk_get_device_connect_state()) + { + connect_state++; + } +#endif + break; + + default: + break; + } + if (count_num == 9 || connect_state >= 2) + { + if (BluetoothServiceOptionsView::GetInstance()) + BluetoothServiceOptionsView::GetInstance()->show_connecting_view(false); + osTimerStop(MG_TEST_timer); + osTimerDelete(MG_TEST_timer); + MG_TEST_timer = NULL; + } + else if (count_num == 2) + { + // 仅尝试重连一次 + switch (button_state) + { + case BluetoothServiceOptionsView::CONNECT_HFP: + // uapi_hfp_connect(); + break; + case BluetoothServiceOptionsView::DISCONNECT_HFP: + // uapi_hfp_disconnect(); + break; + case BluetoothServiceOptionsView::CONNECT_A2DP: + // uapi_a2dp_snk_connect(); + break; + case BluetoothServiceOptionsView::DISCONNECT_A2DP: + // uapi_a2dp_snk_disconnect(); + break; + default: + break; + } + } + } + + void connectTimerCallBack(int data) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(connectTimerCallBackProc, data)); + } + + bool BluetoothServiceOptionsView::init_connect_timer(uint8_t type) + { + uint32_t tick; + osStatus_t retTimer; + count_num = 0; + button_state = type; + + if (MG_TEST_timer) + { + osTimerStop(MG_TEST_timer); + osTimerDelete(MG_TEST_timer); + MG_TEST_timer = NULL; + } + MG_TEST_timer = osTimerNew((osTimerFunc_t)connectTimerCallBack, osTimerPeriodic, NULL, NULL); + tick = 500; + connect_state = 0; + + retTimer = osTimerStart(MG_TEST_timer, tick); + if (retTimer != osOK && MG_TEST_timer != NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StartCallTimer osTimerStart failed, ret = %lx!!", retTimer); + osTimerDelete(MG_TEST_timer); + MG_TEST_timer = NULL; + return false; + } + return true; + } + + bool BluetoothServiceOptionsView::SetUpBlueToothScrollView(void) + { + BlueToothScrollView = new UIScrollView(); + if (BlueToothScrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::BlueToothScrollView new fail!"); + return false; + } + BlueToothScrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + // BlueToothScrollView->SetScrollBlankSize(35); + // BlueToothScrollView->SetReboundSize(50); + BlueToothScrollView->SetDirection(1); + UIView::OnDragListener *draglistener = static_cast(BluetoothServiceOptionsPresenter::GetInstance()); + if (draglistener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::draglistener can not be nullptr!"); + return false; + } + BlueToothScrollView->SetOnDragListener(draglistener); + BlueToothScrollView->SetTouchable(true); + BlueToothScrollView->SetDraggable(true); + + return true; + } + + // 标签配置 + UILabelExt *BluetoothServiceOptionsView::SetBluetoothServiceOptionsViewLabel(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->SetRollSpeed(23); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); + return label; + } + + // 标签初始化 + bool BluetoothServiceOptionsView::SetUpBlueToothLabel(void) + { + LabelConfig labelconfig = { + .left = 93, + .top = 50, + .width = 280, + .height = 40, + .fontSize = 30, + .lineHeigh = 35, + .textId = STR_BLUETOOTH_SERVICE_OPTIONS, /*蓝牙服务选项*/ + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, + }; + Title = SetBluetoothServiceOptionsViewLabel(labelconfig); + if (nullptr == Title) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::Title is nullptr!"); + return false; + } + Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + /* -------------------------------------------------------------------------- */ + labelconfig = { + .left = 90, + .top = 153, + .width = 180, + .height = 40, + .fontSize = 30, + .lineHeigh = 35, + .textId = STR_HFP, /*通话蓝牙*/ + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, + }; + HFP_Label = SetBluetoothServiceOptionsViewLabel(labelconfig); + if (nullptr == HFP_Label) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::HFP_Label is nullptr!"); + return false; + } + labelconfig.top = 273; + labelconfig.textId = STR_A2DP; /*媒体蓝牙*/ + A2DP_Label = SetBluetoothServiceOptionsViewLabel(labelconfig); + if (nullptr == A2DP_Label) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::A2DP_Label is nullptr!"); + return false; + } + + return true; + } + + // ToggleButton初始化 + bool BluetoothServiceOptionsView::SetUpBlueToothToggleButton() + { + HFP_ToggleButton = new UIToggleButton(); + if (nullptr == HFP_ToggleButton) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " BluetoothServiceOptionsView::BlueToothEarPhoneButton new fail!"); + return false; + } + HFP_ToggleButton->SetPosition(298, 145, 100, 50); +#ifdef FD230_650 + HFP_ToggleButton->SetState(uapi_hfp_connect_state()); // ConfigModel::GetInstance()->GetHFPState()); +#endif + HFP_ToggleButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + HFP_ToggleButton->SetImages(PNG_TOGGLEBUTTON_ON_IMAGE, PNG_TOGGLEBUTTON_OFF_IMAGE); + /* -------------------------------------------------------------------------- */ + A2DP_ToggleButton = new UIToggleButton(); + if (A2DP_ToggleButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LanguageSwitchView::A2DP_ToggleButton is nullptr!"); + return false; + } + A2DP_ToggleButton->SetPosition(298, 265, 100, 50); +#ifdef FD230_650 + A2DP_ToggleButton->SetState(uapi_a2dp_snk_get_device_connect_state()); +#endif + A2DP_ToggleButton->SetStyle(STYLE_BACKGROUND_OPA, 0xffffffff); + A2DP_ToggleButton->SetImages(PNG_TOGGLEBUTTON_ON_IMAGE, PNG_TOGGLEBUTTON_OFF_IMAGE); + /* -------------------------------------------------------------------------- */ + UIView::OnClickListener *clickListener = static_cast(BluetoothServiceOptionsPresenter::GetInstance()); + if (nullptr == clickListener) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsPresenter::GetInstance fail!!"); + return false; + } + HFP_ToggleButton->SetOnClickListener(clickListener); + A2DP_ToggleButton->SetOnClickListener(clickListener); + + return true; + } + + // 图片初始化 + bool BluetoothServiceOptionsView::SetUpBlueToothImageView(void) + { + HFP_Image = new UIImageView(); + if (nullptr == HFP_Image) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " BluetoothServiceOptionsView::HFP_Image new fail!"); + return false; + } + HFP_Image->SetPosition(43, 120, 380, 100); + HFP_Image->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + HFP_Image->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + HFP_Image->SetStyle(STYLE_BORDER_RADIUS, 100); + /* -------------------------------------------------------------------------- */ + A2DP_Image = new UIImageView(); + if (nullptr == A2DP_Image) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " BluetoothServiceOptionsView::A2DP_Image new fail!"); + return false; + } + A2DP_Image->SetPosition(43, 240, 380, 100); + A2DP_Image->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + A2DP_Image->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + A2DP_Image->SetStyle(STYLE_BORDER_RADIUS, 100); + return true; + } + + UIToggleButton *BluetoothServiceOptionsView::GetHFP_ToggleButton(void) + { + return HFP_ToggleButton; + } + UIToggleButton *BluetoothServiceOptionsView::GetA2DP_ToggleButton(void) + { + return A2DP_ToggleButton; + } + + /// @brief 蓝牙界面初始化 + /// @param void + void BluetoothServiceOptionsView::BluetoothServiceOptionsViewInit(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::BluetoothServiceOptionsViewInit"); + if (!SetUpBlueToothScrollView() || !SetUpBlueToothImageView() || !SetUpBlueToothLabel() || !SetUpBlueToothToggleButton()) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::BluetoothServiceOptionsViewInit fail!!"); + return; + } + } + + void BluetoothServiceOptionsView::OnStart() + { + if (!initViewStatus) + { + BluetoothServiceOptionsViewInit(); + initViewStatus = true; + } + if (BlueToothScrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::BlueToothScrollView is nullptr!"); + return; + } + BlueToothScrollView->Add(Title); + BlueToothScrollView->Add(HFP_Image); + BlueToothScrollView->Add(A2DP_Image); + BlueToothScrollView->Add(HFP_Label); + BlueToothScrollView->Add(A2DP_Label); + BlueToothScrollView->Add(HFP_ToggleButton); + BlueToothScrollView->Add(A2DP_ToggleButton); +#ifdef FD230_650 + p_AiVoiceConnectingView = new AiVoiceConnectingView(); + if (p_AiVoiceConnectingView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::p_AiVoiceConnectingView new fail!"); + return; + } + connectingScrollView = p_AiVoiceConnectingView->CreateAiVoiceConnectingView(1); +#endif + connectingScrollView->SetVisible(false); + connectingScrollView->SetDraggable(false); + BlueToothScrollView->Add(connectingScrollView); + AddViewToRootContainer(BlueToothScrollView); + } + + void BluetoothServiceOptionsView::show_connecting_view(bool data) + { + if (connectingScrollView) + connectingScrollView->SetVisible(data); +#ifdef FD230_650 + if (data == false) + { + if (A2DP_ToggleButton) + A2DP_ToggleButton->SetState(uapi_a2dp_snk_get_device_connect_state()); + + if (HFP_ToggleButton) + HFP_ToggleButton->SetState(uapi_hfp_connect_state()); // ConfigModel::GetInstance()->GetHFPState()); + } +#endif + } + + void BluetoothServiceOptionsView::Button_UPdata(void) + { +#ifdef FD230_650 + if (A2DP_ToggleButton) + A2DP_ToggleButton->SetState(uapi_a2dp_snk_get_device_connect_state()); + + if (HFP_ToggleButton) + HFP_ToggleButton->SetState(uapi_hfp_connect_state()); // ConfigModel::GetInstance()->GetHFPState()); +#endif + } +} diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothModel.cpp new file mode 100644 index 000000000..746bcbe63 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothModel.cpp @@ -0,0 +1,14 @@ +#include "classicbluetooth/include/ClassicBlueToothModel.h" +namespace OHOS +{ + ClassicBlueToothModel::ClassicBlueToothModel() {} + + ClassicBlueToothModel::~ClassicBlueToothModel() {} + + ClassicBlueToothModel *ClassicBlueToothModel::GetInstance(void) + { + static ClassicBlueToothModel instance; + return &instance; + } + +} // namespace OHOS diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp new file mode 100644 index 000000000..d78175192 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp @@ -0,0 +1,177 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-25 11:50:57 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-11-05 11:47:17 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp + */ +#include "classicbluetooth/include/ClassicBlueToothPresenter.h" +#include "classicbluetooth/include/ClassicBlueToothView.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "custom_utils.h" +#include "common/key_code.h" +#include +#include "wearable_log.h" +#include "ConfigModel.h" +#include +#include "BluetoothModel.h" +#include "custom_runtime.h" +#include "ConfigModelC.h" +#include "PhoneService.h" +#include "NativeRegisterManager.h" +namespace OHOS +{ + REGIST_SLICE(VIEW_CLASSIC_BLUETOOTH, ClassicBlueToothView, ClassicBlueToothPresenter); + + // 当前Presenter属性实例化的内存指针 + static ClassicBlueToothPresenter *g_pClassicBlueToothPresenter = nullptr; + ClassicBlueToothPresenter::ClassicBlueToothPresenter() + { + g_pClassicBlueToothPresenter = this; + } + + ClassicBlueToothPresenter::~ClassicBlueToothPresenter() + { + g_pClassicBlueToothPresenter = nullptr; + } + + ClassicBlueToothPresenter *ClassicBlueToothPresenter::GetInstance() + { + return g_pClassicBlueToothPresenter; + } + + void ClassicBlueToothPresenter::OnStart() + { + } + + void ClassicBlueToothPresenter::OnPause(void) + { + Presenter::OnPause(); + } + + void ClassicBlueToothPresenter::OnResume(void) + { + Presenter::OnResume(); + } + + void ClassicBlueToothPresenter::OnStop(void) + { + } + + bool ClassicBlueToothPresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnClick"); + ClassicBlueToothView *classicBlueToothView = ClassicBlueToothView::GetInstance(); + if (classicBlueToothView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::GetInstance"); + return false; + } + + if (strcmp(view.GetViewId(), BLUETOOTHEARPHONEBUTTON) == 0) + { + NativeAbility::GetInstance().EnterSlice(VIEW_BLUETOOTH_EARPHONE); + } + else if (strcmp(view.GetViewId(), BLUETOOTHSERVICEOPTIONSBUTTON) == 0) + { + if (classicBlueToothView->GetTradionalBlueToothToggleButton()->GetState() == true) + { + NativeAbility::GetInstance().EnterSlice(VIEW_BLUETOOTH_SERVICE_OPTIONS); + } + } + + return true; + } + + bool ClassicBlueToothPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnDrag"); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + X_DRAG_FLAG = true; + } + return true; + } + + bool ClassicBlueToothPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) + { + NativeAbility::GetInstance().Back(); + X_DRAG_FLAG = false; + } + + return true; + } + + bool ClassicBlueToothPresenter::OnChange(UICheckBox::UICheckBoxState state) + { +#ifdef FD230_650 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnChange"); + bd_addr_t bdaddr = {0}; + switch (state) + { + case UICheckBox::SELECTED: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BlueTooth Capability Is Enabled"); + start_custom_ble_service(); // 主动开启蓝牙 + // 开启完增加回连 + + uapi_get_br_address(&bdaddr); + if (uapi_dev_runtime_get_bt_powerstat() && (cm_get_HFP_switch() || cm_get_A2DP_switch())) + { + if (cm_get_HFP_switch() && cm_get_A2DP_switch() && false == bt_is_acl_connected(&bdaddr) && !(bdaddr.addr[0] == 0 && bdaddr.addr[1] == 0 && bdaddr.addr[2] == 0 && bdaddr.addr[3] == 0 && bdaddr.addr[4] == 0 && bdaddr.addr[5] == 0)) + { + int ret = gap_reconnect_media_device(&bdaddr); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " gap_reconnect_media_device ret = %u %02x %02x %02x ", ret, bdaddr.addr[5], bdaddr.addr[4], bdaddr.addr[3]); + } + else + { + + if (cm_get_A2DP_switch()) + { + uapi_a2dp_snk_connect(); + } + if (cm_get_HFP_switch()) + { + uapi_hfp_connect(); + } + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_a2dp_snk_connect!!! \r\n"); + } + } + + ConfigModel::GetInstance()->SetClassicBlueToothState(true); + break; + case UICheckBox::UNSELECTED: + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BlueTooth Capability Is Disabled"); + + stop_custom_ble_service(); + + ConfigModel::GetInstance()->SetClassicBlueToothState(false); + break; + default: + break; + } +#endif + return true; + } + + bool ClassicBlueToothPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16 keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + NativeAbility::GetInstance().Back(); + } + return true; + } + +} diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp new file mode 100644 index 000000000..23f7e8e2b --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp @@ -0,0 +1,311 @@ +#include "classicbluetooth/include/ClassicBlueToothView.h" +#include "classicbluetooth/include/ClassicBlueToothPresenter.h" +#include "ConfigModel.h" +#include "UiConfig.h" +#include "ui_resource_string.h" +namespace OHOS +{ + static ClassicBlueToothView *g_pClassicBlueToothView{nullptr}; + + ClassicBlueToothView::ClassicBlueToothView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::ClassicBlueToothView"); + g_pClassicBlueToothView = this; + } + + ClassicBlueToothView::~ClassicBlueToothView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~ClassicBlueToothView::ClassicBlueToothView"); + ClearAll(); + g_pClassicBlueToothView = nullptr; + } + + ClassicBlueToothView *ClassicBlueToothView::GetInstance() + { + return g_pClassicBlueToothView; + } + + void ClassicBlueToothView::ClearAll() + { + if (initViewStatus == true) + { + if (BlueToothScrollView) + { + BlueToothScrollView->RemoveAll(); + if (Title != nullptr) + { + delete Title; + Title = nullptr; + } + if (BlueToothEarPhoneButton != nullptr) + { + delete BlueToothEarPhoneButton; + BlueToothEarPhoneButton = nullptr; + } + if (TradionalBlueToothButton != nullptr) + { + delete TradionalBlueToothButton; + TradionalBlueToothButton = nullptr; + } + if (BluetoothServiceOptionsButton != nullptr) + { + delete BluetoothServiceOptionsButton; + BluetoothServiceOptionsButton = nullptr; + } + if (BlueToothEarPhoneLabel != nullptr) + { + delete BlueToothEarPhoneLabel; + BlueToothEarPhoneLabel = nullptr; + } + if (TradionalBlueToothLabel != nullptr) + { + delete TradionalBlueToothLabel; + TradionalBlueToothLabel = nullptr; + } + if (BluetoothServiceOptionsLabel != nullptr) + { + delete BluetoothServiceOptionsLabel; + BluetoothServiceOptionsLabel = nullptr; + } + if (AttentionLabel != nullptr) + { + delete AttentionLabel; + AttentionLabel = nullptr; + } + if (TradionalBlueToothToggleButton != nullptr) + { + delete TradionalBlueToothToggleButton; + TradionalBlueToothToggleButton = nullptr; + } + delete BlueToothScrollView; + BlueToothScrollView = nullptr; + } + } + } + + bool ClassicBlueToothView::SetUpBlueToothScrollView(void) + { + BlueToothScrollView = new UIScrollView(); + if (BlueToothScrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::BlueToothScrollView new fail!"); + return false; + } + BlueToothScrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + BlueToothScrollView->SetScrollBlankSize(50); + BlueToothScrollView->SetReboundSize(50); + BlueToothScrollView->SetDirection(1); + BlueToothScrollView->RequestFocus(); + UIView::OnDragListener *draglistener = static_cast(ClassicBlueToothPresenter::GetInstance()); + if (draglistener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::draglistener can not be nullptr!"); + return false; + } + BlueToothScrollView->SetOnDragListener(draglistener); + BlueToothScrollView->SetTouchable(true); + BlueToothScrollView->SetDraggable(true); + + return true; + } + + // 标签配置 + UILabelExt *ClassicBlueToothView::SetClassicBlueToothViewLabel(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->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); + return label; + } + + // 标签初始化 + bool ClassicBlueToothView::SetUpBlueToothLabel(void) + { + LabelConfig labelconfig = { + .left = 93, + .top = 50, + .width = 300, + .height = 35, + .fontSize = 30, + .lineHeigh = 35, + .textId = STR_BLUETOOTH, /*蓝牙*/ + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, + }; + Title = SetClassicBlueToothViewLabel(labelconfig); + if (nullptr == Title) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::Title is nullptr!"); + return false; + } + Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + /* -------------------------------------------------------------------------- */ + labelconfig = { + .left = 90, + .top = 153, + .width = 180, + .height = 35, + .fontSize = 30, + .lineHeigh = 35, + .textId = STR_BLUETOOTH_HEADPHONES, /*蓝牙耳机*/ + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, + }; + BlueToothEarPhoneLabel = SetClassicBlueToothViewLabel(labelconfig); + if (nullptr == BlueToothEarPhoneLabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::BlueToothEarPhoneLabel is nullptr!"); + return false; + } + /* -------------------------------------------------------------------------- */ + labelconfig.top = 273; + labelconfig.textId = STR_TRADITIONAL_BLUETOOTH; /*传统蓝牙*/ + TradionalBlueToothLabel = SetClassicBlueToothViewLabel(labelconfig); + if (nullptr == TradionalBlueToothLabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::TradionalBlueToothLabel is nullptr!"); + return false; + } + /* -------------------------------------------------------------------------- */ + labelconfig.top = 393; + labelconfig.textId = STR_BLUETOOTH_SERVICE_OPTIONS; /*蓝牙服务选项*/ + BluetoothServiceOptionsLabel = SetClassicBlueToothViewLabel(labelconfig); + if (nullptr == BluetoothServiceOptionsLabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::BluetoothServiceOptionsLabel is nullptr!"); + return false; + } + /* -------------------------------------------------------------------------- */ + AttentionLabel = new UILabelExt(); + if (AttentionLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::AttentionLabel is nullptr!"); + return false; + } + AttentionLabel->SetPosition(53, 499, 360, 180); // 位置大小 + AttentionLabel->SetStyle(STYLE_TEXT_FONT, 20); // 字体大小 + AttentionLabel->SetStyle(STYLE_LINE_HEIGHT, 30); // 字体行高 + //.text = "注:开启后10分钟没连接成功会自动关闭,因为传统蓝牙长时间打开会增加电耗,建议在有需要的时候使用(该功能主要用于电话拨打/通知、音乐控制/传输等)", + // AttentionLabel->SetTextId(STR_AUTO_OFF_BLUETOOTH_NOTE); + //TODO:多国语言 + AttentionLabel->SetTextId(STR_AUTO_OFF_BLUETOOTH_NOTE2); + AttentionLabel->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); + AttentionLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + AttentionLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); // 断行模式。 + AttentionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); + /* -------------------------------------------------------------------------- */ + + return true; + } + + // 按钮初始化 + bool ClassicBlueToothView::SetUpBlueToothButton(void) + { + BlueToothEarPhoneButton = new UILabelButtonExt(); + if (BlueToothEarPhoneButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " ClassicBlueToothView::BlueToothEarPhoneButton new fail!"); + return false; + } + BlueToothEarPhoneButton->SetPosition(43, 120, 380, 100); + BlueToothEarPhoneButton->SetViewId(BLUETOOTHEARPHONEBUTTON); + BlueToothEarPhoneButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + BlueToothEarPhoneButton->SetImagePosition(326, 37); + BlueToothEarPhoneButton->SetImageSrc(PNG_SETTING_NEXT_IMAGE, PNG_SETTING_NEXT_IMAGE); + BlueToothEarPhoneButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); + /* -------------------------------------------------------------------------- */ + TradionalBlueToothButton = new UILabelButtonExt(); + if (TradionalBlueToothButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " ClassicBlueToothView::TradionalBlueToothButton new fail!"); + return false; + } + TradionalBlueToothButton->SetPosition(43, 240, 380, 100); + TradionalBlueToothButton->SetViewId(TRADIONALBLUETOOTHBUTTON); + TradionalBlueToothButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + TradionalBlueToothButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 16); + TradionalBlueToothButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED); + /* -------------------------------------------------------------------------- */ + BluetoothServiceOptionsButton = new UILabelButtonExt(); + if (BluetoothServiceOptionsButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " ClassicBlueToothView::BluetoothServiceOptionsButton new fail!"); + return false; + } + BluetoothServiceOptionsButton->SetPosition(43, 360, 380, 100); + BluetoothServiceOptionsButton->SetViewId(BLUETOOTHSERVICEOPTIONSBUTTON); + BluetoothServiceOptionsButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + BluetoothServiceOptionsButton->SetImagePosition(326, 37); + BluetoothServiceOptionsButton->SetImageSrc(PNG_SETTING_NEXT_IMAGE, PNG_SETTING_NEXT_IMAGE); + BluetoothServiceOptionsButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); + /* -------------------------------------------------------------------------- */ + BlueToothEarPhoneButton->SetOnClickListener(presenter_); + BluetoothServiceOptionsButton->SetOnClickListener(presenter_); + + return true; + } + + // 传统蓝牙开关按钮 + bool ClassicBlueToothView::SetUpBlueToothToggleButton() + { + TradionalBlueToothToggleButton = new UIToggleButton(); + if (nullptr == TradionalBlueToothToggleButton) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " ClassicBlueToothView::BlueToothEarPhoneButton new fail!"); + return false; + } + TradionalBlueToothToggleButton->SetPosition(298, 265, 100, 50); + TradionalBlueToothToggleButton->SetState(ConfigModel::GetInstance()->GetClassicBlueToothState()); + TradionalBlueToothToggleButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + TradionalBlueToothToggleButton->SetImages(PNG_TOGGLEBUTTON_ON_IMAGE, PNG_TOGGLEBUTTON_OFF_IMAGE); + TradionalBlueToothToggleButton->SetOnChangeListener(presenter_); + return true; + } + + UIToggleButton *ClassicBlueToothView::GetTradionalBlueToothToggleButton(void) + { + return TradionalBlueToothToggleButton; + } + + /// @brief 蓝牙界面初始化 + /// @param void + void ClassicBlueToothView::ClassicBlueToothViewInit(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::ClassicBlueToothViewInit"); + if (!SetUpBlueToothScrollView() || !SetUpBlueToothButton() || !SetUpBlueToothLabel() || !SetUpBlueToothToggleButton()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::ClassicBlueToothViewInit fail!!"); + return; + } + } + + void ClassicBlueToothView::OnStart() + { + if (!initViewStatus) + { + ClassicBlueToothViewInit(); + initViewStatus = true; + } + if(BlueToothScrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::BlueToothScrollView is nullptr!"); + return; + } + BlueToothScrollView->Add(Title); + BlueToothScrollView->Add(BlueToothEarPhoneButton); + BlueToothScrollView->Add(TradionalBlueToothButton); + BlueToothScrollView->Add(BluetoothServiceOptionsButton); + BlueToothScrollView->Add(BlueToothEarPhoneLabel); + BlueToothScrollView->Add(TradionalBlueToothLabel); + BlueToothScrollView->Add(BluetoothServiceOptionsLabel); + BlueToothScrollView->Add(AttentionLabel); + BlueToothScrollView->Add(TradionalBlueToothToggleButton); + AddViewToRootContainer(BlueToothScrollView); + } +} -- 2.17.1