From 67a120cac1e19bbb1ac0336032dc38aeb9e9d6c9 Mon Sep 17 00:00:00 2001 From: hcj <1224667075@qq.com> Date: Thu, 15 Aug 2024 14:43:44 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E8=BF=9E=E6=8E=A5=E4=B8=AD=20?= =?utf8?q?UI=20=E5=8F=8A=E9=83=A8=E5=88=86=E8=93=9D=E7=89=99=E9=97=AE?= =?utf8?q?=E9=A2=98=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../aivoice/include/AiVoiceConnectingView.h | 3 +- .../aivoice/src/AiVoiceConnectingView.cpp | 31 +++- .../nativeui/bluetooth/src/BluetoothModel.cpp | 14 +- .../include/BluetoothServiceOptionsView.h | 18 ++- .../src/BluetoothServiceOptionsPresenter.cpp | 14 +- .../src/BluetoothServiceOptionsView.cpp | 145 ++++++++++++++++++ .../nativeui/settings/src/SettingModel.cpp | 9 ++ .../ble_service/bleservice/bleService.c | 8 +- 8 files changed, 229 insertions(+), 13 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h index ec7cdbe14..28eb6ac65 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h @@ -56,7 +56,7 @@ namespace OHOS ~AiVoiceConnectingView(); static AiVoiceConnectingView *GetInstance(void); UIScrollView *CreateAiVoiceConnectingView(void); - + UIScrollView *CreateAiVoiceConnectingView(uint8_t); private: const char **CreateImagePathsArray(const char *basePath, const int numImages, const char *fileExtension = "bin"); void FreeImagePathsArray(const char **imagePaths, const int numImages); @@ -67,6 +67,7 @@ namespace OHOS bool CreateAiVoiceConnectingViewButton(void); bool CreateAivoiceConnectingImageAnimator(void); bool CreateAiVoiceConnectingScrollView(void); + bool CreateAiVoiceConnectingScrollView(uint8_t); void ClearAll(void); UIScrollView *scrollView{nullptr}; UILabelExt *title{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp index 790abdcea..29514a936 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp @@ -16,7 +16,7 @@ namespace OHOS static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_Y = 153; static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_W = 100; static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_H = 120; - static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_DELAY = 200; // 图片更新间隔 + static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_DELAY = 50; // 图片更新间隔 static constexpr const char *AIVoiceListeningImagePaths = "/user/res/connect/"; static AiVoiceConnectingView *g_pAiVoiceConnecting{nullptr}; @@ -283,6 +283,23 @@ namespace OHOS return true; } + bool AiVoiceConnectingView::CreateAiVoiceConnectingScrollView(uint8_t type) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingScrollView"); + scrollView = new UIScrollView(); + if (scrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::scrollView new fail!"); + return false; + } + scrollView->SetPosition(0, 0, 466, 466); + scrollView->SetTouchable(true); + scrollView->SetDraggable(true); + + return true; + } + + UIScrollView *AiVoiceConnectingView::CreateAiVoiceConnectingView(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingView"); @@ -299,4 +316,16 @@ namespace OHOS return scrollView; } + UIScrollView *AiVoiceConnectingView::CreateAiVoiceConnectingView(uint8_t type) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingView"); + if (!CreateAiVoiceConnectingScrollView(type) || !CreateAivoiceConnectingImageAnimator()|| !CreateAiVoiceConnectingViewLabel() ) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingView fail!!"); + return nullptr; + } + scrollView->Add(connectingAnimatorView); + return scrollView; + } + } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp index fb8597a7b..76f659e64 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp @@ -48,6 +48,7 @@ #endif #include "Bluetooyhpabpserver.h" #include "bletest.h" +#include "ConfigModelC.h" namespace OHOS { #define BT_SPP_TASK_STACK_SIZE 2048 @@ -755,20 +756,23 @@ void BtGapPairStatusChangedCallback(const bd_addr_t *bdAddr, int status) memcpy(&BtGapPair_bdAddr,bdAddr,sizeof(bd_addr_t)); // if(status == GAP_PAIR_PAIRED) // { + + + //} + //uapi_a2dp_snk_connect(); + //a2dp_snk_connect(bdAddr); if(cm_custom_ble_service_on_flag() && !get_ble_pair()) { + if(cm_get_A2DP_switch() || cm_get_HFP_switch()) uapi_a2dp_snk_connect(); + //uapi_reconnect(); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_a2dp_snk_connect"); } - - //} - //uapi_a2dp_snk_connect(); - //a2dp_snk_connect(bdAddr); - if (status == GAP_PAIR_PAIRED) { if (ConnectPhonePresenter::GetInstance() != nullptr) { NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); } + } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/BluetoothServiceOptionsView.h b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/BluetoothServiceOptionsView.h index eb20dde57..6b6db056d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/BluetoothServiceOptionsView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/BluetoothServiceOptionsView.h @@ -17,6 +17,7 @@ #include "components/ui_button.h" #include "components/ui_image_view.h" #include "components/ui_toggle_button.h" +#include "aivoice/include/AiVoiceConnectingView.h" namespace OHOS { // 返回setting视图界面 @@ -36,6 +37,15 @@ namespace OHOS 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); @@ -43,7 +53,10 @@ namespace OHOS 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; virtual void OnSetUpView() override; @@ -64,6 +77,9 @@ namespace OHOS UIImageView *A2DP_Image{nullptr}; UIToggleButton *HFP_ToggleButton{nullptr}; // HFP UIToggleButton *A2DP_ToggleButton{nullptr}; // A2DP + UIScrollView * connectingScrollView{nullptr}; + AiVoiceConnectingView* p_AiVoiceConnectingView{nullptr}; + bool initViewStatus{false}; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp index ce09b4c41..d5bfa9b33 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp @@ -78,31 +78,36 @@ namespace OHOS UIToggleButton *toggleButton = dynamic_cast(&view); if (toggleButton != nullptr) { + classicBlueToothView->show_connecting_view(true); if (toggleButton->GetState() == true) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s is enable!", it->second.c_str()); + //WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s is enable!", it->second.c_str()); if (it->second == "HFP") { ConfigModel::GetInstance()->SetHFPState(true); //enable_hfp_service(true); uapi_hfp_connect(); + classicBlueToothView->init_connect_timer(BluetoothServiceOptionsView::CONNECT_HFP); + } else if (it->second == "A2DP") { ConfigModel::GetInstance()->SetA2DPState(true); uapi_a2dp_snk_connect(); + classicBlueToothView->init_connect_timer(BluetoothServiceOptionsView::CONNECT_A2DP); //enable_a2dp_service(true); } } else { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s is disable!", it->second.c_str()); + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s is disable!", it->second.c_str()); if (it->second == "HFP") { ConfigModel::GetInstance()->SetHFPState(false); //enable_hfp_service(false); uapi_hfp_disconnect(); + classicBlueToothView->init_connect_timer(BluetoothServiceOptionsView::DISCONNECT_HFP); // errcode_t ret = gap_ble_set_ctkd_enable(false); // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "gap_ble_set_ctkd_enable ret = %u", ret); } @@ -111,8 +116,9 @@ namespace OHOS ConfigModel::GetInstance()->SetA2DPState(false); uapi_a2dp_snk_disconnect(); + classicBlueToothView->init_connect_timer(BluetoothServiceOptionsView::DISCONNECT_HFP); // uapi_hfp_disconnect(); - // uapi_disconnect_remote_device(); + //uapi_disconnect_remote_device(); // errcode_t ret = gap_ble_set_ctkd_enable(false); // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "gap_ble_set_ctkd_enable ret = %u", ret); //bluetooth_set_auto_reconnect(1); @@ -138,6 +144,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsPresenter::OnDragEnd"); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + if(! BluetoothServiceOptionsView::GetInstance()->get_connectview_Visible()) NativeAbility::GetInstance().Back(); } @@ -152,6 +159,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0) { + if(! BluetoothServiceOptionsView::GetInstance()->get_connectview_Visible()) NativeAbility::GetInstance().Back(); } return true; diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp index 7461ab113..b3570cb0b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp @@ -7,6 +7,8 @@ #include "phoneservice/include/PhoneService.h" #include "BluetoothModel.h" #include "ui_resource_string.h" +#include "cmsis_os2.h" + namespace OHOS { static BluetoothServiceOptionsView *g_pBluetoothServiceOptionsView{nullptr}; @@ -72,12 +74,128 @@ namespace OHOS delete A2DP_ToggleButton; A2DP_ToggleButton = nullptr; } + if(p_AiVoiceConnectingView) + { + delete p_AiVoiceConnectingView; + p_AiVoiceConnectingView=nullptr; + } + 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; + + bool BluetoothServiceOptionsView::get_connectview_Visible(void) + { + return connectingScrollView->IsVisible(); + } + + void connectTimerCallBack(int data) + { + bool connect_state=false; + count_num++; + switch (button_state) + { + case BluetoothServiceOptionsView::CONNECT_HFP: + if(uapi_hfp_connect_state()) + { + BluetoothServiceOptionsView::GetInstance()->show_connecting_view(false); + connect_state=true; + } + break; + case BluetoothServiceOptionsView::DISCONNECT_HFP: + if(!uapi_hfp_connect_state()) + { + BluetoothServiceOptionsView::GetInstance()->show_connecting_view(false); + connect_state=true; + } + break; + case BluetoothServiceOptionsView::CONNECT_A2DP: + if(uapi_a2dp_snk_get_device_connect_state()) + { + BluetoothServiceOptionsView::GetInstance()->show_connecting_view(false); + connect_state=true; + } + break; + case BluetoothServiceOptionsView::DISCONNECT_A2DP: + if(!uapi_a2dp_snk_get_device_connect_state()) + { + BluetoothServiceOptionsView::GetInstance()->show_connecting_view(false); + connect_state=true; + } + break; + + default: + break; + + } + if(count_num==3 || connect_state) + { + 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; + } + } + } + + 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 =1500; + 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(); @@ -262,6 +380,7 @@ namespace OHOS { BluetoothServiceOptionsViewInit(); initViewStatus = true; + } // 增加按键监听 @@ -269,6 +388,25 @@ namespace OHOS RootView::GetInstance()->SetOnKeyActListener(keyactListener); } + void BluetoothServiceOptionsView::show_connecting_view(bool data) + { + + connectingScrollView->SetVisible(data); + if(data==false) + { + A2DP_ToggleButton->SetState(uapi_a2dp_snk_get_device_connect_state()); + HFP_ToggleButton->SetState(uapi_hfp_connect_state()); // ConfigModel::GetInstance()->GetHFPState()); + } + } + + void BluetoothServiceOptionsView::Button_UPdata(void) + { + + A2DP_ToggleButton->SetState(uapi_a2dp_snk_get_device_connect_state()); + HFP_ToggleButton->SetState(uapi_hfp_connect_state()); // ConfigModel::GetInstance()->GetHFPState()); + + } + void BluetoothServiceOptionsView::OnSetUpView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::OnSetUpView"); @@ -280,6 +418,13 @@ namespace OHOS BlueToothScrollView->Add(A2DP_Label); BlueToothScrollView->Add(HFP_ToggleButton); BlueToothScrollView->Add(A2DP_ToggleButton); + p_AiVoiceConnectingView = new AiVoiceConnectingView(); + + connectingScrollView= p_AiVoiceConnectingView->CreateAiVoiceConnectingView(1); + connectingScrollView->SetVisible(false); + connectingScrollView->SetDraggable(false); + BlueToothScrollView->Add(connectingScrollView); + RootView::GetInstance()->Add(BlueToothScrollView); Draw(); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp index 19ba3ac47..f8fc69b0c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp @@ -8,6 +8,7 @@ #include "settings/include/SettingModel.h" #include "main/include/PullUpDownView.h" #include "ui_resource_string.h" +#include "classicbluetooth/include/BluetoothServiceOptionsView.h" namespace OHOS { SettingModel::SettingModel() {} @@ -80,6 +81,10 @@ namespace OHOS { PullUpDownView::GetInstance()->UpdateEarPhoneStatus(status); } + if(BluetoothServiceOptionsView::GetInstance()) + { + BluetoothServiceOptionsView::GetInstance()->Button_UPdata(); + } } // 更新蓝牙连接状态 @@ -90,5 +95,9 @@ namespace OHOS { PullUpDownView::GetInstance()->UpdateBlueToothStatus(status); } + if(BluetoothServiceOptionsView::GetInstance()) + { + BluetoothServiceOptionsView::GetInstance()->Button_UPdata(); + } } } diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c index 88c998976..0f4087425 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleService.c @@ -304,8 +304,10 @@ void svr_ble_connstate_change_cb(unsigned short conn_id, bd_addr_t *addr, gap_bl WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GAP_BLE_STATE_DISCONNECTED!!! \r\n"); // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GAP_BLE_STATE_DISCONNECTED!!! svr_alipay_get_adv_start_state %d alipay_get_binding_status:%d\r\n",svr_alipay_get_adv_start_state(),alipay_get_binding_status()); // if(AdverFlag == true){ - free_ble_data(); - svr_ble_adv_start(); + free_ble_data(); + if(cm_custom_ble_service_on_flag()) + svr_ble_adv_start(); + ble_disconnect_ok(); // } } else { @@ -363,6 +365,7 @@ void svr_pair_result_cbt_cb(uint16_t conn_id, const bd_addr_t *addr, errcode_t s }else{ + bd_addr_t bdaddr={0}; uapi_get_br_address(&bdaddr); if(false==(bt_is_acl_connected(&bdaddr))) @@ -372,6 +375,7 @@ void svr_pair_result_cbt_cb(uint16_t conn_id, const bd_addr_t *addr, errcode_t s } else { + if(cm_get_A2DP_switch() || cm_get_HFP_switch()) uapi_a2dp_snk_connect(); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_a2dp_snk_connect!!! \r\n"); } -- 2.17.1