--- /dev/null
+/*
+ * @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<BluetoothServiceOptionsView>,
+ 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
--- /dev/null
+/*
+ * @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<BluetoothServiceOptionsPresenter>
+ {
+ 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
--- /dev/null
+#ifndef CLASSIC_BLUETOOTH_MODEL_H\r
+#define CLASSIC_BLUETOOTH_MODEL_H\r
+\r
+#include "wearable_log.h"\r
+#include "ConfigModel.h"\r
+namespace OHOS\r
+{\r
+ class ClassicBlueToothModel\r
+ {\r
+ public:\r
+ static ClassicBlueToothModel *GetInstance(void);\r
+\r
+ private:\r
+ ClassicBlueToothModel();\r
+ ClassicBlueToothModel(const ClassicBlueToothModel &) = delete;\r
+ ClassicBlueToothModel &operator=(const ClassicBlueToothModel &) = delete;\r
+ virtual ~ClassicBlueToothModel();\r
+ };\r
+} // namespace OHOS\r
+#endif
\ No newline at end of file
--- /dev/null
+/*\r
+ * @Author: luozheng 1732036298@qq.com\r
+ * @Date: 2024-04-25 11:50:51\r
+ * @LastEditors: luozheng 1732036298@qq.com\r
+ * @LastEditTime: 2024-07-23 10:15:46\r
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothPresenter.h\r
+ */\r
+#ifndef CLASSIC_BLUETOOTH_PRESENTER_H\r
+#define CLASSIC_BLUETOOTH_PRESENTER_H\r
+#include "Presenter.h"\r
+#include "View.h"\r
+#include "classicbluetooth/include/ClassicBlueToothView.h"\r
+\r
+namespace OHOS\r
+{\r
+ class ClassicBlueToothView;\r
+ class ClassicBlueToothPresenter : public Presenter<ClassicBlueToothView>,\r
+ public UIView::OnClickListener,\r
+ public UIView::OnDragListener,\r
+ public RootView::OnKeyActListener,\r
+ public UICheckBox::OnChangeListener\r
+ {\r
+ public:\r
+ ClassicBlueToothPresenter();\r
+ virtual ~ClassicBlueToothPresenter();\r
+ static ClassicBlueToothPresenter *GetInstance();\r
+\r
+ virtual void OnStart() override;\r
+ virtual void OnPause() override;\r
+ virtual void OnResume() override;\r
+ virtual void OnStop() override;\r
+\r
+ private:\r
+ bool OnClick(UIView &view, const ClickEvent &event) override;\r
+ bool OnDrag(UIView &view, const DragEvent &event) override;\r
+ bool OnDragEnd(UIView &view, const DragEvent &event) override;\r
+ bool OnChange(UICheckBox::UICheckBoxState state) override;\r
+ bool OnKeyAct(UIView &view, const KeyEvent &event) override;\r
+\r
+ bool X_DRAG_FLAG{false};\r
+ };\r
+}\r
+\r
+#endif
\ No newline at end of file
--- /dev/null
+/*\r
+ * @Author: luozheng 1732036298@qq.com\r
+ * @Date: 2024-04-25 11:51:04\r
+ * @LastEditors: luozheng 1732036298@qq.com\r
+ * @LastEditTime: 2024-06-17 18:08:27\r
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothView.h\r
+ */\r
+#ifndef CLASSIC_BLUETOOTH_VIEW_H\r
+#define CLASSIC_BLUETOOTH_VIEW_H\r
+\r
+\r
+#include "View.h"\r
+#include "components/root_view.h"\r
+#include "components/ui_scroll_view.h"\r
+#include "components/ui_label_ext.h"\r
+#include "components/ui_label_button_ext.h"\r
+#include "components/ui_image_view.h"\r
+#include "components/ui_toggle_button.h"\r
+#include "wearable_log.h"\r
+namespace OHOS\r
+{\r
+ static constexpr const char *BLUETOOTHEARPHONEBUTTON = "BlueToothEarPhoneButton"; // 蓝牙耳机按钮ID\r
+ static constexpr const char *TRADIONALBLUETOOTHBUTTON = "TradionalBluetoothButton"; // 传统蓝牙服按钮ID\r
+ static constexpr const char *BLUETOOTHSERVICEOPTIONSBUTTON = "BluetoothServiceOptionsButton"; // 蓝牙服务选项按钮ID\r
+ // 返回setting视图界面\r
+ class ClassicBlueToothPresenter;\r
+ class ClassicBlueToothView : public View<ClassicBlueToothPresenter>\r
+ {\r
+ public:\r
+ struct LabelConfig\r
+ {\r
+ int16_t left;\r
+ int16_t top;\r
+ int16_t width;\r
+ int16_t height;\r
+ int16_t fontSize; // 字体大小\r
+ int16_t lineHeigh; // 行高\r
+ //const char *text; // 文本\r
+ uint16_t textId; \r
+ uint8_t lineBreakMode; // 断行模式。\r
+ };\r
+ ClassicBlueToothView();\r
+ virtual ~ClassicBlueToothView();\r
+ static ClassicBlueToothView *GetInstance(void);\r
+ void ClassicBlueToothViewInit(void);\r
+ void ClearAll(void);\r
+ UIToggleButton * GetTradionalBlueToothToggleButton(void);\r
+\r
+ public:\r
+ virtual void OnStart() override;\r
+\r
+ private:\r
+ bool SetUpBlueToothScrollView(void);\r
+ UILabelExt *SetClassicBlueToothViewLabel(LabelConfig &labelconfig);\r
+ bool SetUpBlueToothLabel(void);\r
+ bool SetUpBlueToothButton(void);\r
+ bool SetUpBlueToothToggleButton(void);\r
+ UIScrollView *BlueToothScrollView = nullptr;\r
+ UILabelExt *Title = nullptr;\r
+ UILabelButtonExt *BlueToothEarPhoneButton = nullptr; // 蓝牙耳机按钮\r
+ UILabelButtonExt *TradionalBlueToothButton = nullptr; // 传统蓝牙按钮\r
+ UILabelButtonExt *BluetoothServiceOptionsButton = nullptr; // 蓝牙服务选项按钮\r
+ UILabelExt *BlueToothEarPhoneLabel = nullptr; // 蓝牙耳机\r
+ UILabelExt *TradionalBlueToothLabel = nullptr; // 传统蓝牙\r
+ UILabelExt *BluetoothServiceOptionsLabel = nullptr; // 蓝牙服务选项\r
+ UILabelExt *AttentionLabel = nullptr;\r
+ UIToggleButton *TradionalBlueToothToggleButton = nullptr;\r
+ bool initViewStatus{false};\r
+ };\r
+}\r
+#endif\r
--- /dev/null
+#include "AppViewIDs.h"
+#include "NativeAbility.h"
+#include "common/key_code.h"
+#include <custom_utils.h>
+#include <ohos_types.h>
+#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<BluetoothServiceOptionsView>::OnPause();
+ }
+
+ void BluetoothServiceOptionsPresenter::OnResume(void)
+ {
+
+ Presenter<BluetoothServiceOptionsView>::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<UIView *, std::string> buttonMap = {
+ {classicBlueToothView->GetHFP_ToggleButton(), "HFP"},
+ {
+ classicBlueToothView->GetA2DP_ToggleButton(),
+ "A2DP",
+ },
+ };
+
+ auto it = buttonMap.find(&view);
+ if (it != buttonMap.end())
+ {
+ UIToggleButton *toggleButton = dynamic_cast<UIToggleButton *>(&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<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0)
+ {
+ if (!BluetoothServiceOptionsView::GetInstance()->get_connectview_Visible())
+ NativeAbility::GetInstance().Back();
+ }
+ return true;
+ }
+}
--- /dev/null
+#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<UIView::OnDragListener *>(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<UIView::OnClickListener *>(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
+ }
+}
--- /dev/null
+#include "classicbluetooth/include/ClassicBlueToothModel.h"\r
+namespace OHOS\r
+{\r
+ ClassicBlueToothModel::ClassicBlueToothModel() {}\r
+\r
+ ClassicBlueToothModel::~ClassicBlueToothModel() {}\r
+\r
+ ClassicBlueToothModel *ClassicBlueToothModel::GetInstance(void)\r
+ {\r
+ static ClassicBlueToothModel instance;\r
+ return &instance;\r
+ }\r
+\r
+} // namespace OHOS\r
--- /dev/null
+/*\r
+ * @Author: luozheng 1732036298@qq.com\r
+ * @Date: 2024-04-25 11:50:57\r
+ * @LastEditors: luozheng 1732036298@qq.com\r
+ * @LastEditTime: 2024-11-05 11:47:17\r
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp\r
+ */\r
+#include "classicbluetooth/include/ClassicBlueToothPresenter.h"\r
+#include "classicbluetooth/include/ClassicBlueToothView.h"\r
+#include "AppViewIDs.h"\r
+#include "NativeAbility.h"\r
+#include "custom_utils.h"\r
+#include "common/key_code.h"\r
+#include <ohos_types.h>\r
+#include "wearable_log.h"\r
+#include "ConfigModel.h"\r
+#include <UiConfig.h>\r
+#include "BluetoothModel.h"\r
+#include "custom_runtime.h"\r
+#include "ConfigModelC.h"\r
+#include "PhoneService.h"\r
+#include "NativeRegisterManager.h"\r
+namespace OHOS\r
+{\r
+ REGIST_SLICE(VIEW_CLASSIC_BLUETOOTH, ClassicBlueToothView, ClassicBlueToothPresenter);\r
+\r
+ // 当前Presenter属性实例化的内存指针\r
+ static ClassicBlueToothPresenter *g_pClassicBlueToothPresenter = nullptr;\r
+ ClassicBlueToothPresenter::ClassicBlueToothPresenter()\r
+ {\r
+ g_pClassicBlueToothPresenter = this;\r
+ }\r
+\r
+ ClassicBlueToothPresenter::~ClassicBlueToothPresenter()\r
+ {\r
+ g_pClassicBlueToothPresenter = nullptr;\r
+ }\r
+\r
+ ClassicBlueToothPresenter *ClassicBlueToothPresenter::GetInstance()\r
+ {\r
+ return g_pClassicBlueToothPresenter;\r
+ }\r
+\r
+ void ClassicBlueToothPresenter::OnStart()\r
+ {\r
+ }\r
+\r
+ void ClassicBlueToothPresenter::OnPause(void)\r
+ {\r
+ Presenter<ClassicBlueToothView>::OnPause();\r
+ }\r
+\r
+ void ClassicBlueToothPresenter::OnResume(void)\r
+ {\r
+ Presenter<ClassicBlueToothView>::OnResume();\r
+ }\r
+\r
+ void ClassicBlueToothPresenter::OnStop(void)\r
+ {\r
+ }\r
+\r
+ bool ClassicBlueToothPresenter::OnClick(UIView &view, const ClickEvent &event)\r
+ {\r
+ UNUSED(event);\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnClick");\r
+ ClassicBlueToothView *classicBlueToothView = ClassicBlueToothView::GetInstance();\r
+ if (classicBlueToothView == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::GetInstance");\r
+ return false;\r
+ }\r
+\r
+ if (strcmp(view.GetViewId(), BLUETOOTHEARPHONEBUTTON) == 0)\r
+ {\r
+ NativeAbility::GetInstance().EnterSlice(VIEW_BLUETOOTH_EARPHONE);\r
+ }\r
+ else if (strcmp(view.GetViewId(), BLUETOOTHSERVICEOPTIONSBUTTON) == 0)\r
+ {\r
+ if (classicBlueToothView->GetTradionalBlueToothToggleButton()->GetState() == true)\r
+ {\r
+ NativeAbility::GetInstance().EnterSlice(VIEW_BLUETOOTH_SERVICE_OPTIONS);\r
+ }\r
+ }\r
+\r
+ return true;\r
+ }\r
+\r
+ bool ClassicBlueToothPresenter::OnDrag(UIView &view, const DragEvent &event)\r
+ {\r
+ UNUSED(view);\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnDrag");\r
+ if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动\r
+ {\r
+ X_DRAG_FLAG = true;\r
+ }\r
+ return true;\r
+ }\r
+\r
+ bool ClassicBlueToothPresenter::OnDragEnd(UIView &view, const DragEvent &event)\r
+ {\r
+ UNUSED(view);\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnDragEnd");\r
+ if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG)\r
+ {\r
+ NativeAbility::GetInstance().Back();\r
+ X_DRAG_FLAG = false;\r
+ }\r
+\r
+ return true;\r
+ }\r
+\r
+ bool ClassicBlueToothPresenter::OnChange(UICheckBox::UICheckBoxState state)\r
+ {\r
+#ifdef FD230_650\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnChange");\r
+ bd_addr_t bdaddr = {0};\r
+ switch (state)\r
+ {\r
+ case UICheckBox::SELECTED:\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BlueTooth Capability Is Enabled");\r
+ start_custom_ble_service(); // 主动开启蓝牙\r
+ // 开启完增加回连\r
+\r
+ uapi_get_br_address(&bdaddr);\r
+ if (uapi_dev_runtime_get_bt_powerstat() && (cm_get_HFP_switch() || cm_get_A2DP_switch()))\r
+ {\r
+ 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))\r
+ {\r
+ int ret = gap_reconnect_media_device(&bdaddr);\r
+ 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]);\r
+ }\r
+ else\r
+ {\r
+\r
+ if (cm_get_A2DP_switch())\r
+ {\r
+ uapi_a2dp_snk_connect();\r
+ }\r
+ if (cm_get_HFP_switch())\r
+ {\r
+ uapi_hfp_connect();\r
+ }\r
+\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_a2dp_snk_connect!!! \r\n");\r
+ }\r
+ }\r
+\r
+ ConfigModel::GetInstance()->SetClassicBlueToothState(true);\r
+ break;\r
+ case UICheckBox::UNSELECTED:\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BlueTooth Capability Is Disabled");\r
+\r
+ stop_custom_ble_service();\r
+\r
+ ConfigModel::GetInstance()->SetClassicBlueToothState(false);\r
+ break;\r
+ default:\r
+ break;\r
+ }\r
+#endif\r
+ return true;\r
+ }\r
+\r
+ bool ClassicBlueToothPresenter::OnKeyAct(UIView &view, const KeyEvent &event)\r
+ {\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnKeyAct");\r
+ uint16 keyID = event.GetKeyId();\r
+ uint16 keyState = event.GetState();\r
+ // 如果是power键,且是亮屏状态,按键释放就返回上一级\r
+ if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0)\r
+ {\r
+ NativeAbility::GetInstance().Back();\r
+ }\r
+ return true;\r
+ }\r
+\r
+}\r
--- /dev/null
+#include "classicbluetooth/include/ClassicBlueToothView.h"\r
+#include "classicbluetooth/include/ClassicBlueToothPresenter.h"\r
+#include "ConfigModel.h"\r
+#include "UiConfig.h"\r
+#include "ui_resource_string.h"\r
+namespace OHOS\r
+{\r
+ static ClassicBlueToothView *g_pClassicBlueToothView{nullptr};\r
+\r
+ ClassicBlueToothView::ClassicBlueToothView()\r
+ {\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::ClassicBlueToothView");\r
+ g_pClassicBlueToothView = this;\r
+ }\r
+\r
+ ClassicBlueToothView::~ClassicBlueToothView()\r
+ {\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "~ClassicBlueToothView::ClassicBlueToothView");\r
+ ClearAll();\r
+ g_pClassicBlueToothView = nullptr;\r
+ }\r
+\r
+ ClassicBlueToothView *ClassicBlueToothView::GetInstance()\r
+ {\r
+ return g_pClassicBlueToothView;\r
+ }\r
+\r
+ void ClassicBlueToothView::ClearAll()\r
+ {\r
+ if (initViewStatus == true)\r
+ {\r
+ if (BlueToothScrollView)\r
+ {\r
+ BlueToothScrollView->RemoveAll();\r
+ if (Title != nullptr)\r
+ {\r
+ delete Title;\r
+ Title = nullptr;\r
+ }\r
+ if (BlueToothEarPhoneButton != nullptr)\r
+ {\r
+ delete BlueToothEarPhoneButton;\r
+ BlueToothEarPhoneButton = nullptr;\r
+ }\r
+ if (TradionalBlueToothButton != nullptr)\r
+ {\r
+ delete TradionalBlueToothButton;\r
+ TradionalBlueToothButton = nullptr;\r
+ }\r
+ if (BluetoothServiceOptionsButton != nullptr)\r
+ {\r
+ delete BluetoothServiceOptionsButton;\r
+ BluetoothServiceOptionsButton = nullptr;\r
+ }\r
+ if (BlueToothEarPhoneLabel != nullptr)\r
+ {\r
+ delete BlueToothEarPhoneLabel;\r
+ BlueToothEarPhoneLabel = nullptr;\r
+ }\r
+ if (TradionalBlueToothLabel != nullptr)\r
+ {\r
+ delete TradionalBlueToothLabel;\r
+ TradionalBlueToothLabel = nullptr;\r
+ }\r
+ if (BluetoothServiceOptionsLabel != nullptr)\r
+ {\r
+ delete BluetoothServiceOptionsLabel;\r
+ BluetoothServiceOptionsLabel = nullptr;\r
+ }\r
+ if (AttentionLabel != nullptr)\r
+ {\r
+ delete AttentionLabel;\r
+ AttentionLabel = nullptr;\r
+ }\r
+ if (TradionalBlueToothToggleButton != nullptr)\r
+ {\r
+ delete TradionalBlueToothToggleButton;\r
+ TradionalBlueToothToggleButton = nullptr;\r
+ }\r
+ delete BlueToothScrollView;\r
+ BlueToothScrollView = nullptr;\r
+ }\r
+ }\r
+ }\r
+\r
+ bool ClassicBlueToothView::SetUpBlueToothScrollView(void)\r
+ {\r
+ BlueToothScrollView = new UIScrollView();\r
+ if (BlueToothScrollView == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::BlueToothScrollView new fail!");\r
+ return false;\r
+ }\r
+ BlueToothScrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());\r
+ BlueToothScrollView->SetScrollBlankSize(50);\r
+ BlueToothScrollView->SetReboundSize(50);\r
+ BlueToothScrollView->SetDirection(1);\r
+ BlueToothScrollView->RequestFocus();\r
+ UIView::OnDragListener *draglistener = static_cast<UIView::OnDragListener *>(ClassicBlueToothPresenter::GetInstance());\r
+ if (draglistener == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::draglistener can not be nullptr!");\r
+ return false;\r
+ }\r
+ BlueToothScrollView->SetOnDragListener(draglistener);\r
+ BlueToothScrollView->SetTouchable(true);\r
+ BlueToothScrollView->SetDraggable(true);\r
+\r
+ return true;\r
+ }\r
+\r
+ // 标签配置\r
+ UILabelExt *ClassicBlueToothView::SetClassicBlueToothViewLabel(LabelConfig &labelconfig)\r
+ {\r
+ UILabelExt *label = new UILabelExt();\r
+ if (label == nullptr)\r
+ {\r
+ return nullptr;\r
+ }\r
+ label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); // 位置大小\r
+ label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); // 字体大小\r
+ label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); // 字体行高\r
+ label->SetTextId(labelconfig.textId);\r
+ label->SetLineBreakMode(labelconfig.lineBreakMode); // 断行模式。\r
+ label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize);\r
+ return label;\r
+ }\r
+\r
+ // 标签初始化\r
+ bool ClassicBlueToothView::SetUpBlueToothLabel(void)\r
+ {\r
+ LabelConfig labelconfig = {\r
+ .left = 93,\r
+ .top = 50,\r
+ .width = 300,\r
+ .height = 35,\r
+ .fontSize = 30,\r
+ .lineHeigh = 35,\r
+ .textId = STR_BLUETOOTH, /*蓝牙*/\r
+ .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION,\r
+ };\r
+ Title = SetClassicBlueToothViewLabel(labelconfig);\r
+ if (nullptr == Title)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::Title is nullptr!");\r
+ return false;\r
+ }\r
+ Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
+ /* -------------------------------------------------------------------------- */\r
+ labelconfig = {\r
+ .left = 90,\r
+ .top = 153,\r
+ .width = 180,\r
+ .height = 35,\r
+ .fontSize = 30,\r
+ .lineHeigh = 35,\r
+ .textId = STR_BLUETOOTH_HEADPHONES, /*蓝牙耳机*/\r
+ .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION,\r
+ };\r
+ BlueToothEarPhoneLabel = SetClassicBlueToothViewLabel(labelconfig);\r
+ if (nullptr == BlueToothEarPhoneLabel)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::BlueToothEarPhoneLabel is nullptr!");\r
+ return false;\r
+ }\r
+ /* -------------------------------------------------------------------------- */\r
+ labelconfig.top = 273;\r
+ labelconfig.textId = STR_TRADITIONAL_BLUETOOTH; /*传统蓝牙*/\r
+ TradionalBlueToothLabel = SetClassicBlueToothViewLabel(labelconfig);\r
+ if (nullptr == TradionalBlueToothLabel)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::TradionalBlueToothLabel is nullptr!");\r
+ return false;\r
+ }\r
+ /* -------------------------------------------------------------------------- */\r
+ labelconfig.top = 393;\r
+ labelconfig.textId = STR_BLUETOOTH_SERVICE_OPTIONS; /*蓝牙服务选项*/\r
+ BluetoothServiceOptionsLabel = SetClassicBlueToothViewLabel(labelconfig);\r
+ if (nullptr == BluetoothServiceOptionsLabel)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::BluetoothServiceOptionsLabel is nullptr!");\r
+ return false;\r
+ }\r
+ /* -------------------------------------------------------------------------- */\r
+ AttentionLabel = new UILabelExt();\r
+ if (AttentionLabel == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::AttentionLabel is nullptr!");\r
+ return false;\r
+ }\r
+ AttentionLabel->SetPosition(53, 499, 360, 180); // 位置大小\r
+ AttentionLabel->SetStyle(STYLE_TEXT_FONT, 20); // 字体大小\r
+ AttentionLabel->SetStyle(STYLE_LINE_HEIGHT, 30); // 字体行高\r
+ //.text = "注:开启后10分钟没连接成功会自动关闭,因为传统蓝牙长时间打开会增加电耗,建议在有需要的时候使用(该功能主要用于电话拨打/通知、音乐控制/传输等)",\r
+ // AttentionLabel->SetTextId(STR_AUTO_OFF_BLUETOOTH_NOTE);\r
+ //TODO:多国语言\r
+ AttentionLabel->SetTextId(STR_AUTO_OFF_BLUETOOTH_NOTE2);\r
+ AttentionLabel->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff));\r
+ AttentionLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
+ AttentionLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); // 断行模式。\r
+ AttentionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20);\r
+ /* -------------------------------------------------------------------------- */\r
+\r
+ return true;\r
+ }\r
+\r
+ // 按钮初始化\r
+ bool ClassicBlueToothView::SetUpBlueToothButton(void)\r
+ {\r
+ BlueToothEarPhoneButton = new UILabelButtonExt();\r
+ if (BlueToothEarPhoneButton == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " ClassicBlueToothView::BlueToothEarPhoneButton new fail!");\r
+ return false;\r
+ }\r
+ BlueToothEarPhoneButton->SetPosition(43, 120, 380, 100);\r
+ BlueToothEarPhoneButton->SetViewId(BLUETOOTHEARPHONEBUTTON);\r
+ BlueToothEarPhoneButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);\r
+ BlueToothEarPhoneButton->SetImagePosition(326, 37);\r
+ BlueToothEarPhoneButton->SetImageSrc(PNG_SETTING_NEXT_IMAGE, PNG_SETTING_NEXT_IMAGE);\r
+ BlueToothEarPhoneButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED);\r
+ /* -------------------------------------------------------------------------- */\r
+ TradionalBlueToothButton = new UILabelButtonExt();\r
+ if (TradionalBlueToothButton == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " ClassicBlueToothView::TradionalBlueToothButton new fail!");\r
+ return false;\r
+ }\r
+ TradionalBlueToothButton->SetPosition(43, 240, 380, 100);\r
+ TradionalBlueToothButton->SetViewId(TRADIONALBLUETOOTHBUTTON);\r
+ TradionalBlueToothButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);\r
+ TradionalBlueToothButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 16);\r
+ TradionalBlueToothButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED);\r
+ /* -------------------------------------------------------------------------- */\r
+ BluetoothServiceOptionsButton = new UILabelButtonExt();\r
+ if (BluetoothServiceOptionsButton == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " ClassicBlueToothView::BluetoothServiceOptionsButton new fail!");\r
+ return false;\r
+ }\r
+ BluetoothServiceOptionsButton->SetPosition(43, 360, 380, 100);\r
+ BluetoothServiceOptionsButton->SetViewId(BLUETOOTHSERVICEOPTIONSBUTTON);\r
+ BluetoothServiceOptionsButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);\r
+ BluetoothServiceOptionsButton->SetImagePosition(326, 37);\r
+ BluetoothServiceOptionsButton->SetImageSrc(PNG_SETTING_NEXT_IMAGE, PNG_SETTING_NEXT_IMAGE);\r
+ BluetoothServiceOptionsButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED);\r
+ /* -------------------------------------------------------------------------- */\r
+ BlueToothEarPhoneButton->SetOnClickListener(presenter_);\r
+ BluetoothServiceOptionsButton->SetOnClickListener(presenter_);\r
+\r
+ return true;\r
+ }\r
+\r
+ // 传统蓝牙开关按钮\r
+ bool ClassicBlueToothView::SetUpBlueToothToggleButton()\r
+ {\r
+ TradionalBlueToothToggleButton = new UIToggleButton();\r
+ if (nullptr == TradionalBlueToothToggleButton)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " ClassicBlueToothView::BlueToothEarPhoneButton new fail!");\r
+ return false;\r
+ }\r
+ TradionalBlueToothToggleButton->SetPosition(298, 265, 100, 50);\r
+ TradionalBlueToothToggleButton->SetState(ConfigModel::GetInstance()->GetClassicBlueToothState());\r
+ TradionalBlueToothToggleButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);\r
+ TradionalBlueToothToggleButton->SetImages(PNG_TOGGLEBUTTON_ON_IMAGE, PNG_TOGGLEBUTTON_OFF_IMAGE);\r
+ TradionalBlueToothToggleButton->SetOnChangeListener(presenter_);\r
+ return true;\r
+ }\r
+\r
+ UIToggleButton *ClassicBlueToothView::GetTradionalBlueToothToggleButton(void)\r
+ {\r
+ return TradionalBlueToothToggleButton;\r
+ }\r
+\r
+ /// @brief 蓝牙界面初始化\r
+ /// @param void\r
+ void ClassicBlueToothView::ClassicBlueToothViewInit(void)\r
+ {\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::ClassicBlueToothViewInit");\r
+ if (!SetUpBlueToothScrollView() || !SetUpBlueToothButton() || !SetUpBlueToothLabel() || !SetUpBlueToothToggleButton())\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::ClassicBlueToothViewInit fail!!");\r
+ return;\r
+ }\r
+ }\r
+\r
+ void ClassicBlueToothView::OnStart()\r
+ {\r
+ if (!initViewStatus)\r
+ {\r
+ ClassicBlueToothViewInit();\r
+ initViewStatus = true;\r
+ }\r
+ if(BlueToothScrollView == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::BlueToothScrollView is nullptr!");\r
+ return;\r
+ }\r
+ BlueToothScrollView->Add(Title);\r
+ BlueToothScrollView->Add(BlueToothEarPhoneButton);\r
+ BlueToothScrollView->Add(TradionalBlueToothButton);\r
+ BlueToothScrollView->Add(BluetoothServiceOptionsButton);\r
+ BlueToothScrollView->Add(BlueToothEarPhoneLabel);\r
+ BlueToothScrollView->Add(TradionalBlueToothLabel);\r
+ BlueToothScrollView->Add(BluetoothServiceOptionsLabel);\r
+ BlueToothScrollView->Add(AttentionLabel);\r
+ BlueToothScrollView->Add(TradionalBlueToothToggleButton);\r
+ AddViewToRootContainer(BlueToothScrollView);\r
+ }\r
+}\r