From a81473d2780c96f627f0b9ef22077fabecf4eae5 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Tue, 3 Sep 2024 19:08:14 +0800 Subject: [PATCH] =?utf8?q?=E9=9F=B3=E4=B9=90=E7=95=8C=E9=9D=A2=E4=BC=98?= =?utf8?q?=E5=8C=96=EF=BC=8C=E8=B0=83=E6=95=B4=E4=BA=86=E8=93=9D=E7=89=99?= =?utf8?q?=E8=80=B3=E6=9C=BA=E8=BF=9E=E6=8E=A5=E7=8A=B6=E6=80=81=E6=A0=87?= =?utf8?q?=E7=AD=BE=E7=9A=84=E5=AD=97=E4=BD=93=E5=A4=A7=E5=B0=8F=E4=B8=8Ef?= =?utf8?q?igma=E4=B8=80=E8=87=B4=20=E8=93=9D=E7=89=99=E8=80=B3=E6=9C=BA=20?= =?utf8?q?=EF=BC=9A=E6=90=9C=E7=B4=A2=E8=AE=BE=E5=A4=87=E7=95=8C=E9=9D=A2?= =?utf8?q?=E5=8A=A8=E7=94=BB=E4=BF=AE=E6=94=B9=E4=B8=BAfigma=E4=B8=80?= =?utf8?q?=E8=87=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../aivoice/src/AiVoiceConnectingView.cpp | 5 +- .../bluetooth/include/BluetoothEarPhoneView.h | 4 +- .../bluetooth/src/BluetoothEarPhoneView.cpp | 481 ++++++++++-------- .../bluetooth/src/MainBluetoothView.cpp | 4 +- .../player/src/MusicPlayerSourceView.cpp | 48 +- .../nativeui/player/src/PlayersModel.cpp | 25 +- 6 files changed, 311 insertions(+), 256 deletions(-) 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 daab2695c..c7ba00106 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-08-03 11:10:08 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-09-03 10:18:56 + * @LastEditTime: 2024-09-03 19:06:26 * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp */ #include "aivoice/include/AiVoiceConnectingView.h" @@ -11,7 +11,7 @@ #include "ui_resource_string.h" #include "common/image_cache_manager.h" #include "uicomponents/UIComponents.h" - +#include "uiservice/include/ui_service.h" namespace OHOS { static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_X = 183; @@ -302,6 +302,7 @@ namespace OHOS } connectingAnimatorView->SetPosition(183, 183); connectingAnimatorView->Invalidate(); + ScreenTurnOn(30*1000);//亮屏30s scrollView->Add(connectingAnimatorView); return scrollView; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothEarPhoneView.h b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothEarPhoneView.h index c42ee950b..4af2a23f0 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothEarPhoneView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothEarPhoneView.h @@ -18,6 +18,7 @@ #define BLUETOOTH_SEARCH_IMAGE_NUM 8 namespace OHOS { +static constexpr int16_t CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 60; // 图片帧数 class BluetoothEarPhoneView { public: BluetoothEarPhoneView(); @@ -33,8 +34,9 @@ public: private: ImageAnimatorInfo searchImageInfo[BLUETOOTH_SEARCH_IMAGE_NUM]; UIViewGroup *group{nullptr}; - UILabel *titleLabel{nullptr}; UIImageAnimatorView *imageAnimator{nullptr}; + const ImageInfo **connectPathsArray{nullptr}; + ImageAnimatorInfo connectImageInfo[CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; bool scanStart{0}; void BtScanImageAnimator(); }; diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothEarPhoneView.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothEarPhoneView.cpp index eee47cb07..6f75591b0 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothEarPhoneView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothEarPhoneView.cpp @@ -14,267 +14,304 @@ #include "SettingModel.h" #include "common/image_cache_manager.h" #include "graphic_service.h" +#include "uicomponents/UIComponents.h" +#include "uiservice/include/ui_service.h" -namespace OHOS { -static BluetoothEarPhoneView *g_pBluetoothEarPhoneView{nullptr}; +namespace OHOS +{ + static BluetoothEarPhoneView *g_pBluetoothEarPhoneView{nullptr}; #define BLUETOOTH_IMAGE_X 175 #define BLUETOOTH_IMAGE_Y 175 #define BLUETOOTH_IMAGE_WIDTH 104 #define BLUETOOTH_IMAGE_HEIGHT 104 #define BLUETOOTH_DELAY 200 -osTimerId_t g_stopScanHandle = nullptr; -static constexpr uint64_t MS_SCAN_TIME = 25000; - -BluetoothEarPhoneView::BluetoothEarPhoneView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BluetoothEarPhoneView"); - g_pBluetoothEarPhoneView = this; -} + osTimerId_t g_stopScanHandle = nullptr; + static constexpr uint64_t MS_SCAN_TIME = 25000; -BluetoothEarPhoneView::~BluetoothEarPhoneView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::~BluetoothEarPhoneView"); - group->RemoveAll(); - delete titleLabel; - titleLabel = nullptr; - delete imageAnimator; - imageAnimator = nullptr; - delete group; - group = nullptr; - g_pBluetoothEarPhoneView = nullptr; -} + static constexpr int16_t CONNECTING_IMAGE_ANIMATOR_VIEW_X = 183; + static constexpr int16_t CONNECTING_IMAGE_ANIMATOR_VIEW_Y = 153; + static constexpr int16_t CONNECTING_IMAGE_ANIMATOR_VIEW_W = 100; + static constexpr int16_t CONNECTING_IMAGE_ANIMATOR_VIEW_H = 120; + static constexpr int16_t CONNECTING_IMAGE_ANIMATOR_DELAY = 50; // 图片更新间隔 + static constexpr const char *connectImagePaths = "/user/res/connect/"; + BluetoothEarPhoneView::BluetoothEarPhoneView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BluetoothEarPhoneView"); + g_pBluetoothEarPhoneView = this; + } -BluetoothEarPhoneView *BluetoothEarPhoneView::GetInstance() -{ - return g_pBluetoothEarPhoneView; -} + BluetoothEarPhoneView::~BluetoothEarPhoneView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::~BluetoothEarPhoneView"); + if (group) + { + group->RemoveAll(); + if (imageAnimator) + { + imageAnimator->Stop(); + delete imageAnimator; + imageAnimator = nullptr; + FreeImageInfoArray(connectPathsArray, connectImagePaths, CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + } + delete group; + group = nullptr; + } + g_pBluetoothEarPhoneView = nullptr; + } -void BluetoothEarPhoneView::BtScanImageAnimator() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtScanImageAnimator init"); - const char *searchImagePath[BLUETOOTH_SEARCH_IMAGE_NUM] = { - PNG_A019_080_IMAGE_PATH, - PNG_A019_081_IMAGE_PATH, - PNG_A019_082_IMAGE_PATH, - PNG_A019_083_IMAGE_PATH, - PNG_A019_084_IMAGE_PATH, - PNG_A019_085_IMAGE_PATH, - PNG_A019_086_IMAGE_PATH, - PNG_A019_087_IMAGE_PATH, - }; + BluetoothEarPhoneView *BluetoothEarPhoneView::GetInstance() + { + return g_pBluetoothEarPhoneView; + } - if (imageAnimator == nullptr) { - imageAnimator = new UIImageAnimatorView(); - if (imageAnimator == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView new imageAnimator fail"); - return; - } - for (uint8_t i = 0; i < BLUETOOTH_SEARCH_IMAGE_NUM; i++) { - searchImageInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(searchImagePath[i]); - searchImageInfo[i].imageType = IMG_SRC_IMAGE_INFO; - searchImageInfo[i].pos.x = BLUETOOTH_IMAGE_X; - searchImageInfo[i].pos.y = BLUETOOTH_IMAGE_Y; - searchImageInfo[i].width = BLUETOOTH_IMAGE_WIDTH; - searchImageInfo[i].height = BLUETOOTH_IMAGE_HEIGHT; + // 扫描动画创建 + void BluetoothEarPhoneView::BtScanImageAnimator() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtScanImageAnimator init"); + connectPathsArray = CreateImageInfoArray(connectImagePaths, CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + if (imageAnimator == nullptr) + { + imageAnimator = new UIImageAnimatorView(); + if (imageAnimator == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceUnBindingView]imageAnimator new fail"); + return; + } + for (uint8_t i = 0; i < CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++) + { + connectImageInfo[i].imageInfo = (connectPathsArray[i]); + connectImageInfo[i].imageType = IMG_SRC_IMAGE_INFO; + connectImageInfo[i].pos.x = CONNECTING_IMAGE_ANIMATOR_VIEW_X; + connectImageInfo[i].pos.y = CONNECTING_IMAGE_ANIMATOR_VIEW_Y; + connectImageInfo[i].width = CONNECTING_IMAGE_ANIMATOR_VIEW_W; + connectImageInfo[i].height = CONNECTING_IMAGE_ANIMATOR_VIEW_H; + } + imageAnimator->SetPosition(CONNECTING_IMAGE_ANIMATOR_VIEW_X, CONNECTING_IMAGE_ANIMATOR_VIEW_Y, CONNECTING_IMAGE_ANIMATOR_VIEW_W, CONNECTING_IMAGE_ANIMATOR_VIEW_H); + imageAnimator->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + imageAnimator->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + imageAnimator->SetImageAnimatorSrc(connectImageInfo, CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, CONNECTING_IMAGE_ANIMATOR_DELAY); + imageAnimator->SetRepeat(true); + imageAnimator->SetSizeFixed(true); + group->Add(imageAnimator); } - imageAnimator->SetPosition(175, 175, 104, 104); // 175:x 175:y 104:width 104:height - imageAnimator->SetImageAnimatorSrc(searchImageInfo, BLUETOOTH_SEARCH_IMAGE_NUM, BLUETOOTH_DELAY); - imageAnimator->SetRepeat(true); - group->Add(imageAnimator); } -} -void BluetoothEarPhoneView::BtAnimatorStart(void) -{ - imageAnimator->Start(); -} + // 动画开始 + void BluetoothEarPhoneView::BtAnimatorStart(void) + { + imageAnimator->Start(); + } -void BluetoothEarPhoneView::BtAnimatorStop(void) -{ - imageAnimator->Stop(); -} + // 动画停止 + void BluetoothEarPhoneView::BtAnimatorStop(void) + { + imageAnimator->Stop(); + } -UIViewGroup *BluetoothEarPhoneView::InitShowUpView() -{ - // 获取currentBdAddr db值 待开发 - if (group == nullptr) { - group = new UIViewGroup(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); - return nullptr; + UIViewGroup *BluetoothEarPhoneView::InitShowUpView() + { + // 获取currentBdAddr db值 待开发 + if (group == nullptr) + { + group = new UIViewGroup(); + if (group == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); + return nullptr; + } } - } - group->SetPosition(0, 0); - group->SetWidth(HORIZONTAL_RESOLUTION); - group->SetHeight(VERTICAL_RESOLUTION); - if (titleLabel == nullptr) { - titleLabel = new UILabel(); - if (titleLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView titleLabel new fail"); + group->SetPosition(0, 0); + group->SetWidth(HORIZONTAL_RESOLUTION); + group->SetHeight(VERTICAL_RESOLUTION); + + UIView::OnDragListener *earDragListener = (UIView::OnDragListener *)OHOS::PlayerOnDragListener::GetInstance(); + UIView::OnDragListener *earDragListener2 = (UIView::OnDragListener *)OHOS::BluetoothPresenter::GetInstance(); + if ((earDragListener == nullptr) && (earDragListener2 == nullptr)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "earDragListener GetInstance fail"); return nullptr; } - titleLabel->SetPosition(135, 35, 183, 53); // 135:x 35:y 183:width 53:height - titleLabel->SetText("正在搜索"); - titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_FORTY_SIZE); - titleLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); - titleLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, - UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); - group->Add(titleLabel); - } - UIView::OnDragListener *earDragListener = (UIView::OnDragListener *)OHOS::PlayerOnDragListener::GetInstance(); - UIView::OnDragListener *earDragListener2 = (UIView::OnDragListener *)OHOS::BluetoothPresenter::GetInstance(); - if ((earDragListener == nullptr) && (earDragListener2 == nullptr)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "earDragListener GetInstance fail"); - return nullptr; - } - if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { - group->SetOnDragListener(earDragListener); - } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) { - group->SetOnDragListener(earDragListener2); + if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) + { + group->SetOnDragListener(earDragListener); + } + else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) + { + group->SetOnDragListener(earDragListener2); + } + group->SetViewId(BLUETOOTH_EAR_PHONE_VIEW); + // 动画 + BtScanImageAnimator(); + group->SetDraggable(true); + group->SetTouchable(true); + return group; } - group->SetViewId(BLUETOOTH_EAR_PHONE_VIEW); - // 动画 - BtScanImageAnimator(); - group->SetDraggable(true); - group->SetTouchable(true); - return group; -} -static void CancelBrScanHandle(void) -{ - if (g_stopScanHandle != nullptr) { - osStatus_t ret = osTimerDelete(g_stopScanHandle); - if (ret != osOK) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret); - return; + // 取消br扫描处理 + static void CancelBrScanHandle(void) + { + /* ---------------------------------- 取消定时器 --------------------------------- */ + if (g_stopScanHandle != nullptr) + { + osStatus_t ret = osTimerDelete(g_stopScanHandle); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret); + return; + } + g_stopScanHandle = nullptr; } - g_stopScanHandle = nullptr; + /* -------------------------------------------------------------------------- */ + bool results = gap_br_cancel_discovery(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CancelBtDiscovery results %d", results); } - bool results = gap_br_cancel_discovery(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CancelBtDiscovery results %d", results); -} -static void EndScanHandle(void) -{ - if (BluetoothModel::GetInstance()->GetCase().size() == 0) { - BluetoothEarPhoneView *bluetoothEarPhoneView = BluetoothEarPhoneView::GetInstance(); - if (bluetoothEarPhoneView == nullptr) { // 暂停动画 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothEarPhoneView nullptr"); - return; - } - bluetoothEarPhoneView->BtAnimatorStop(); - if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { - JumpView *jumpView = JumpView::GetInstance(); - if (jumpView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jumpView GetInstance fail"); + // 结束扫描处理 + static void EndScanHandle(void) + { + if (BluetoothModel::GetInstance()->GetCase().size() == 0) + { + BluetoothEarPhoneView *bluetoothEarPhoneView = BluetoothEarPhoneView::GetInstance(); + if (bluetoothEarPhoneView == nullptr) + { // 暂停动画 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothEarPhoneView nullptr"); return; } - jumpView->ChangeView(JumpView::BluetoothJumpViewNum::BLUETOOTHEARPHONEVIEW, - JumpView::BluetoothJumpViewNum::TIPSFAILMESSAGEVIEW); - } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) { - MainBluetoothView *mainBluetoothView = MainBluetoothView::GetInstance(); - if (mainBluetoothView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainBluetoothView GetInstance fail"); - return; + bluetoothEarPhoneView->BtAnimatorStop(); + if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) + { + JumpView *jumpView = JumpView::GetInstance(); + if (jumpView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jumpView GetInstance fail"); + return; } - mainBluetoothView->ChangeView(BLUETOOTHEARPHONEVIEW, TIPSFAILMESSAGEVIEW); - } - } else { - // 按rssi信息重新排序 - BluetoothModel::GetInstance()->SortScansCaseRssi(); - // 刷新 - BluetoothEarListView *bluetoothEarListView = BluetoothEarListView::GetInstance(); - if (bluetoothEarListView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothEarListView nullptr"); - return; + jumpView->ChangeView(JumpView::BluetoothJumpViewNum::BLUETOOTHEARPHONEVIEW, + JumpView::BluetoothJumpViewNum::TIPSFAILMESSAGEVIEW); + } + else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) + { + MainBluetoothView *mainBluetoothView = MainBluetoothView::GetInstance(); + if (mainBluetoothView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainBluetoothView GetInstance fail"); + return; + } + mainBluetoothView->ChangeView(BLUETOOTHEARPHONEVIEW, TIPSFAILMESSAGEVIEW); + } } - if (bluetoothEarListView->GetScanUIList() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetScanUIList nullptr"); - return; + else + { + // 按rssi信息重新排序 + BluetoothModel::GetInstance()->SortScansCaseRssi(); + // 刷新 + BluetoothEarListView *bluetoothEarListView = BluetoothEarListView::GetInstance(); + if (bluetoothEarListView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothEarListView nullptr"); + return; + } + if (bluetoothEarListView->GetScanUIList() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetScanUIList nullptr"); + return; + } + bluetoothEarListView->GetScanUIList()->RefreshList(); + // 扫描完成 + bluetoothEarListView->SetTitleLabel("扫描完成"); + bluetoothEarListView->SetNewEquipmentButtonAdd(); + RootView::GetInstance()->Invalidate(); } - bluetoothEarListView->GetScanUIList()->RefreshList(); - // 扫描完成 - bluetoothEarListView->SetTitleLabel("扫描完成"); - bluetoothEarListView->SetNewEquipmentButtonAdd(); - RootView::GetInstance()->Invalidate(); } -} -// 定时器回调函数 -static void ScanTimerCallbackProc(int data) -{ - (void)data; - CancelBrScanHandle(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Bt scan end jumpView"); - EndScanHandle(); -} - -static void ScanTimerCallback(int data) -{ - GraphicService::GetInstance()->PostGraphicEvent(std::bind(ScanTimerCallbackProc, data)); -} - -// 蓝牙start -void BluetoothEarPhoneView::BtEnable() -{ - bool ret; - bool results; - // 经典蓝牙扫描 - setScanStatus(true); // 开始扫描标记 - // BluetoothModel::GetInstance()->SetCaseListClear(); // 扫描list清空 - BluetoothModel::GetInstance()->Init(); //清空list,获取paired devicelist - ret = is_bt_discovering(BT_TRANSPORT_BR_EDR); - if (ret) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable Bt is Discovering"); - return; - } else { - results = gap_br_start_discovery(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable StartBtDiscovery results %d", results); + // 定时器回调函数 + static void ScanTimerCallbackProc(int data) + { + (void)data; + CancelBrScanHandle(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Bt scan end jumpView"); + EndScanHandle(); } - if (g_stopScanHandle != nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable g_stopScanHandle != nullptr"); - return; - } - g_stopScanHandle = osTimerNew((osTimerFunc_t)ScanTimerCallback, osTimerPeriodic, nullptr, nullptr); - if (g_stopScanHandle == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable osTimerNew failed!!"); - return; + + static void ScanTimerCallback(int data) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(ScanTimerCallbackProc, data)); } - uint32 tick = osMs2Tick(MS_SCAN_TIME); - osStatus_t retTimer = osTimerStart(g_stopScanHandle, tick); - if (retTimer != osOK) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable osTimerStart failed, ret = %lx!!", retTimer); - if (g_stopScanHandle != nullptr) { - retTimer = osTimerDelete(g_stopScanHandle); - if (retTimer != osOK) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable osTimerDelete ret = %lx!!", retTimer); - return; + + // 蓝牙start + void BluetoothEarPhoneView::BtEnable() + { + bool ret; + bool results; + // 经典蓝牙扫描 + setScanStatus(true); // 开始扫描标记 + // BluetoothModel::GetInstance()->SetCaseListClear(); // 扫描list清空 + BluetoothModel::GetInstance()->Init(); // 清空list,获取paired devicelist + ret = is_bt_discovering(BT_TRANSPORT_BR_EDR); + if (ret) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable Bt is Discovering"); + return; + } + else + { + results = gap_br_start_discovery(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable StartBtDiscovery results %d", results); + } + /* -------------------------------------------------------------------------- */ + ScreenTurnOn(MS_SCAN_TIME); + /* -------------------------------------------------------------------------- */ + /*开启定时器*/ + if (g_stopScanHandle != nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable g_stopScanHandle != nullptr"); + return; + } + g_stopScanHandle = osTimerNew((osTimerFunc_t)ScanTimerCallback, osTimerPeriodic, nullptr, nullptr); + if (g_stopScanHandle == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable osTimerNew failed!!"); + return; + } + uint32 tick = osMs2Tick(MS_SCAN_TIME); + osStatus_t retTimer = osTimerStart(g_stopScanHandle, tick); + if (retTimer != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable osTimerStart failed, ret = %lx!!", retTimer); + if (g_stopScanHandle != nullptr) + { + retTimer = osTimerDelete(g_stopScanHandle); + if (retTimer != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable osTimerDelete ret = %lx!!", retTimer); + return; + } + g_stopScanHandle = nullptr; } - g_stopScanHandle = nullptr; + return; } return; } - return; -} -void BluetoothEarPhoneView::StopBtDiscovery(void) -{ - bool ret = is_bt_discovering(BT_TRANSPORT_BR_EDR); - if (!ret) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Bt is not Discovering"); + void BluetoothEarPhoneView::StopBtDiscovery(void) + { + bool ret = is_bt_discovering(BT_TRANSPORT_BR_EDR); + if (!ret) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Bt is not Discovering"); + return; + } + CancelBrScanHandle(); return; } - CancelBrScanHandle(); - return; -} -void BluetoothEarPhoneView::setScanStatus(bool value) -{ - scanStart = value; -} -bool BluetoothEarPhoneView::getScanStatus(void) -{ - return scanStart; -} + void BluetoothEarPhoneView::setScanStatus(bool value) + { + scanStart = value; + } + bool BluetoothEarPhoneView::getScanStatus(void) + { + return scanStart; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/MainBluetoothView.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/MainBluetoothView.cpp index 0259db4c5..0013ba634 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/MainBluetoothView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/MainBluetoothView.cpp @@ -77,9 +77,9 @@ void MainBluetoothView::OnStart() int16_t unusedValue = BLUETOOTHEVIEW_MAX; bool ret = bluetoothCaseList.IsEmpty(); if (!ret) { - ChangeView(unusedValue, BLUETOOTHDEVICELISTVIEW); + ChangeView(unusedValue, BLUETOOTHDEVICELISTVIEW); //已连接设备列表不为空 ->切换到“已连接过的蓝牙设备列表视图” } else { - ChangeView(unusedValue, BLUETOOTHEARPHONEVIEW); + ChangeView(unusedValue, BLUETOOTHEARPHONEVIEW);//若一个都没有连接过就进行搜索 } RootView::GetInstance()->Invalidate(); return; diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/src/MusicPlayerSourceView.cpp b/code/sdk/application/wearable/fd230app/nativeui/player/src/MusicPlayerSourceView.cpp index 3935378da..faed4a9b5 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/MusicPlayerSourceView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/MusicPlayerSourceView.cpp @@ -65,25 +65,27 @@ namespace OHOS { PlayersModel::GetInstance()->SetMusicSource(true); UpdateBluetoothHeadSetViewIsVisible(); - // 1.a2dp未连接,向手机发起a2dp连接 // 如果蓝牙没连接直接是跳转到蓝牙连接失败视图,连接了就有一个主动去连手机的a2dp过程,5秒超市 - - if (!phonebluetoothcon) - { - playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUSIC_BLUETOOTH_DISCONN_VIEW); - } - else if (phonebluetoothcon && !a2dp) // 如果手机蓝牙已连接但手表与手机的a2dp未连接手表主动去连接a2dp - { - /* -------------------------------------------------------------------------- */ - uapi_a2dp_snk_connect(); // 切换通道主动连接atdp - /* -------------------------------------------------------------------------- */ - playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUISC_CONNECTING); - } - else if (phonebluetoothcon && a2dp) - { - playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MAIN_MUSICPLAYER_VIEW); - } + // if (!phonebluetoothcon) + // { + // playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUSIC_BLUETOOTH_DISCONN_VIEW); + // } + // else if (phonebluetoothcon && !a2dp) // 如果手机蓝牙已连接但手表与手机的a2dp未连接手表主动去连接a2dp + // { + // /* -------------------------------------------------------------------------- */ + // uapi_a2dp_snk_connect(); // 切换通道主动连接atdp + // /* -------------------------------------------------------------------------- */ + // playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUISC_CONNECTING); + // } + // else if (phonebluetoothcon && a2dp) + // { + // playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MAIN_MUSICPLAYER_VIEW); + // } + /* -------------------------------------------------------------------------- */ + uapi_a2dp_snk_connect(); // 切换通道主动连接atdp + /* -------------------------------------------------------------------------- */ + playersView->ChangeView(PlayersView::MUSIC_SOURCE_VIEW, PlayersView::MUISC_CONNECTING); } else // 如果已经选择了手机音乐,再次点击就回到 “音乐播放器主视图” { @@ -342,6 +344,8 @@ namespace OHOS } /* ---------------------- bluetoothHeadsetConnectState ---------------------- */ labelConfig.top = 413; + labelConfig.fontSize = 23; + labelConfig.lineHeigh = 27; labelConfig.textId = (SettingModel::GetInstance().GetEarPhoneConnectStatus()) ? STR_PAIRED : STR_NOT_PAIRED; bluetoothHeadsetConnectState = MusicPlayerSourceViewLabelInit(labelConfig); if (nullptr == bluetoothHeadsetConnectState) @@ -510,7 +514,15 @@ namespace OHOS if (bluetoothHeadsetConnectState) { bool state = SettingModel::GetInstance().GetEarPhoneConnectStatus(); - bluetoothHeadsetConnectState->SetTextId(state ? STR_PAIRED : STR_NOT_PAIRED); + List &bluetoothCaseList = BluetoothModel::GetInstance()->GetConnedDevicesCase(); + if (bluetoothCaseList.IsEmpty()) // 如果已连接设备列表为空,则显示未配对 + { + bluetoothHeadsetConnectState->SetTextId(STR_NOT_PAIRED); + } + else // 否则则显示连接状态 + { + bluetoothHeadsetConnectState->SetTextId(state ? STR_CONNECTED : STR_DISCONNECTED); + } bluetoothHeadsetConnectState->SetTextColor(state ? Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff) : Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); bluetoothHeadsetConnectState->Invalidate(); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp index 66bf5feda..00c775092 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersModel.cpp @@ -19,6 +19,7 @@ #include #include #include "MainViewSample.h" +#include "settings/include/SettingModel.h" namespace OHOS { static constexpr int VOLUME_MAXIMUM = 100; @@ -821,19 +822,21 @@ bool PlayersModel::GetCurrentMusicIsPlaying(void) } bool type = PlayersModel::GetInstance()->GetMusicSource(); if(type) { - if(g_PlayerTimes < 0) /*5秒超时*/ - { - playersView->ChangeView(PlayersView::MUISC_CONNECTING, PlayersView::MUSIC_BT_CONNECTFAILED_VIEW); - } - else + bool phonebluetoothcon = SettingModel::GetInstance().GetPhoneConnectStatus(); // 获取手机连接状态 + bool a2dp = uapi_a2dp_snk_get_device_connect_state(); // 获取a2dp连接状态 + if(g_PlayerTimes < 2) /*3秒切换时间*/ { - if(g_PlayerTimes < 2) /*3秒切换时间*/ + if (!phonebluetoothcon) + { + playersView->ChangeView(PlayersView::MUISC_CONNECTING, PlayersView::MUSIC_BLUETOOTH_DISCONN_VIEW); + } + else if (phonebluetoothcon && !a2dp) // 如果手机蓝牙已连接但手表与手机的a2dp未连接手表主动去连接a2dp + { + playersView->ChangeView(PlayersView::MUISC_CONNECTING, PlayersView::MUSIC_BT_CONNECTFAILED_VIEW); + } + else if (phonebluetoothcon && a2dp) { - bool a2dp = uapi_a2dp_snk_get_device_connect_state();// 获取a2dp连接状态 - if(a2dp) - { - playersView->ChangeView(PlayersView::MUISC_CONNECTING, PlayersView::MUSIC_SOURCE_VIEW); - } + playersView->ChangeView(PlayersView::MUISC_CONNECTING, PlayersView::MAIN_MUSICPLAYER_VIEW); } } } -- 2.17.1