From abd273b765ad30c32e65cee6c097c8e6c44aeef1 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Thu, 15 Aug 2024 14:27:31 +0800 Subject: [PATCH] =?utf8?q?=E6=9F=A5=E7=9C=8B=E5=B7=B2=E8=BF=9E=E6=8E=A5?= =?utf8?q?=E7=9A=84=E8=93=9D=E7=89=99=E8=80=B3=E6=9C=BA=E8=A7=86=E5=9B=BEU?= =?utf8?q?I=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../bluetooth/include/BluetoothItemView.h | 14 +- .../bluetooth/include/BluetoothModel.h | 9 +- .../bluetooth/include/BluetoothOptionsView.h | 75 ++- .../bluetooth/include/BluetoothPresenter.h | 4 +- .../nativeui/bluetooth/src/BluetoothModel.cpp | 5 + .../bluetooth/src/BluetoothOptionsView.cpp | 513 ++++++++++++------ .../bluetooth/src/BluetoothPresenter.cpp | 5 +- .../bluetooth/src/MainBluetoothView.cpp | 2 +- .../bluetooth/src/TipsFailMessageView.cpp | 2 +- .../nativeui/player/src/PlayersPresenter.cpp | 2 +- 10 files changed, 408 insertions(+), 223 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothItemView.h b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothItemView.h index 602897b2a..bfddc3f49 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothItemView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothItemView.h @@ -1,10 +1,12 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: BluetoothItem view - * Author: - * Create: 2021-10-13 + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-08-05 15:20:01 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-15 14:19:01 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothItemView.h */ + #ifndef BLUETOOTH_ITEM_VIEW_H #define BLUETOOTH_ITEM_VIEW_H @@ -35,9 +37,9 @@ private: ImageAnimatorInfo connectImageInfo[BLUETOOTH_CONNECT_IMAGE_NUM]; UIImageView image; UIButton button; - UILabel connectStateLabel; + UILabel connectStateLabel;/*连接状态标签*/ UILabel namelabel; - UIImageAnimatorView connectionAnimator; + UIImageAnimatorView connectionAnimator; /*连接动画*/ BluetoothCaseInfo itemInfo_{}; void BtConnectImageAnimator(); }; diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModel.h b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModel.h index 1857e0547..86ba57544 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModel.h @@ -24,10 +24,11 @@ typedef enum : uint16_t { CALLERPLAYERS, } CallerFactor; +/*整合和存储与蓝牙设备相关的各种信息*/ typedef struct { unsigned char deviceName[BD_NAME_LEN]; /* Name of the device record, must be in UTF-8 */ - unsigned char addr[BD_ADDR_LEN]; - int16_t index; + unsigned char addr[BD_ADDR_LEN]; /*存储蓝牙设备的地址*/ + int16_t index;/*用于表示设备在某个特定列表或数据结构中的索引位置。*/ int16_t connIndex; int16_t temp; } BluetoothCaseInfo; @@ -94,8 +95,8 @@ private: void SetUpListCase(); void SetUpConnedDevicesList(); bool FindNameByAddr(BluetoothCaseInfo &listInfo, BluetoothCaseInfo *caseInfo); - bool aclConnected{false}; - BluetoothCaseInfo tempMacValue{}; + bool aclConnected{false};/*ACL(Asynchronous Connectionless,异步无连接)连接状态*/ + BluetoothCaseInfo tempMacValue{};/*临时蓝牙设备地址*/ bd_addr_t lastConnedAddr{}; bd_addr_t remoteConnectAddr{0}; BluetoothItemView *selectItemView{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothOptionsView.h b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothOptionsView.h index 7a6d17469..2f5294741 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothOptionsView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothOptionsView.h @@ -1,8 +1,10 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: BluetoothOptions view - * Author: - * Create: 2021-10-13 + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-08-05 15:20:01 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-15 10:18:02 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothOptionsView.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ #ifndef BLUETOOTH_OPTIONS_VIEW_H #define BLUETOOTH_OPTIONS_VIEW_H @@ -10,34 +12,47 @@ #include "components/ui_view_group.h" #include "components/ui_label.h" #include "components/ui_label_ext.h" -#include "components/ui_label_button.h" +#include "components/ui_label_button_ext.h" #include "components/ui_image_animator.h" #include "BluetoothCaseListAdapter.h" -namespace OHOS { -class BluetoothOptionsView { -public: - BluetoothOptionsView(); - ~BluetoothOptionsView(); - static BluetoothOptionsView *GetInstance(); - UIViewGroup *InitShowUpView(void); - UILabelButton *GetOptionsOneButton(void); - UILabelButton *GetUnpairButton(void); - void SetUnpair(void); - void SetBtconnect(void); - void SetBtDisconnect(void); - void SetCurrentAddr(bd_addr_t addr); - bd_addr_t GetCurrentAddr(void); - void RefreshText(void); -private: - void InItTitleLabel(void); - void InItLabelButton(void); - UILabelButton *optionsOneButton{nullptr}; - UILabelButton *unpairButton{nullptr}; - UILabel *titleLabel{nullptr}; - UILabel *connectStateLabel{nullptr}; - UIViewGroup *group{nullptr}; - bd_addr_t currentAddr; -}; +namespace OHOS +{ + // 已连接的蓝牙耳机设备视图 + class BluetoothOptionsView + { + public: + BluetoothOptionsView(); + ~BluetoothOptionsView(); + static BluetoothOptionsView *GetInstance(); + UIViewGroup *CreateBluetoothOptionsView(void); + UILabelButtonExt *GetOptionsOneButton(void); + UILabelButtonExt *GetUnpairButton(void); + void SetUnpair(void); + void SetBtconnect(void); + void SetBtDisconnect(void); + void SetCurrentAddr(bd_addr_t addr); + bd_addr_t GetCurrentAddr(void); + void RefreshText(void); + + private: + bool CreateBluetoothOptionsLabelView(void); + bool CreateBluetoothOptionsLabelButton(void); + bool CreateBluetoothOptionsImageView(void); + + void InItTitleLabel(void); + void InItLabelButton(void); + UIViewGroup *group{nullptr}; + UILabelExt *titleLabel{nullptr}; /*标题:蓝牙耳机*/ + UIImageView *btHeadsetIconUmage{nullptr}; // 绿色耳机图标 + UILabelExt *EarPhoneDeviceName{nullptr}; // 蓝牙耳机设备名 + UILabelExt *pairState{nullptr}; // 已配对或者未配对 + UILabelButtonExt *unpairButton{nullptr}; // 取消配对按钮 + bd_addr_t currentAddr; + + /*下面两个组件暂时设为不可见待到需要时使用*/ + UILabelButtonExt *optionsOneButton{nullptr}; /*重新连接和断开连接按钮*/ + UILabel *connectStateLabel{nullptr}; /*已连接或未连接标签*/ + }; } // namespace OHOS #endif // BLUETOOTH_OPTIONS_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothPresenter.h index 05f05028e..c4ef7346d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothPresenter.h @@ -25,8 +25,8 @@ enum BluetoothPresenterNum : uint8_t { BLUETOOTHEARPHONEVIEW = 0, BLUETOOTHEARLISTVIEW, BLUETOOTHDEVICELISTVIEW, - BLUETOOTHEOPTIONSVIEW, - BLUETOOTHRECONNECTVIEW, + BLUETOOTHEOPTIONSVIEW,/*已连接的蓝牙耳机设备视图*/ + BLUETOOTHRECONNECTVIEW,/*蓝牙重新连接视图*/ TIPSSUCCMESSAGEVIEW, TIPSCONNFAILMESSAGEVIEW, TIPSFAILMESSAGEVIEW, 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 9981e57cf..325e7484b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp @@ -415,6 +415,11 @@ List& BluetoothModel::GetConnedDevicesCase() return *btConnedDevicesList_; } +/* +* @brief 用于检查特定蓝牙设备(其地址存储在 tempMacValue 中)是否处于 ACL 连接状态。 +* +*eg:如果是在控制与手机配对的蓝牙手环,通过这个函数就能确定手环当前与手机的连接情况。 +*/ void BluetoothModel::SetBtStatus(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetBtStatus tempMacValue: %02x%02x%02x%02x%02x%02x", diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothOptionsView.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothOptionsView.cpp index a2c367198..050556df8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothOptionsView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothOptionsView.cpp @@ -4,224 +4,385 @@ * Author: * Create: 2021-10-13 */ -#include "BluetoothOptionsView.h" -#include "BluetoothModel.h" +#include "bluetooth/include/BluetoothOptionsView.h" +#include "bluetooth/include/BluetoothModel.h" #include "wearable_log.h" #include "UiConfig.h" -#include "PlayersPresenter.h" -#include "BluetoothPresenter.h" - -namespace OHOS { -static BluetoothOptionsView *g_pBluetoothOptionsView{nullptr}; - -BluetoothOptionsView::BluetoothOptionsView() +#include "player/include/PlayersPresenter.h" +#include "player/include/PlayersView.h" +#include "bluetooth/include/BluetoothPresenter.h" +#include "ui_resource_string.h" +#include "ui_resource_image.h" +namespace OHOS { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView::BluetoothOptionsView"); - g_pBluetoothOptionsView = this; -} + static BluetoothOptionsView *g_pBluetoothOptionsView{nullptr}; -BluetoothOptionsView::~BluetoothOptionsView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView::~BluetoothOptionsView"); - group->RemoveAll(); - delete titleLabel; - titleLabel = nullptr; - delete connectStateLabel; - connectStateLabel = nullptr; - delete optionsOneButton; - optionsOneButton = nullptr; - delete unpairButton; - unpairButton = nullptr; - delete group; - group = nullptr; - g_pBluetoothOptionsView = nullptr; -} - -BluetoothOptionsView *BluetoothOptionsView::GetInstance() -{ - return g_pBluetoothOptionsView; -} + BluetoothOptionsView::BluetoothOptionsView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView::BluetoothOptionsView"); + g_pBluetoothOptionsView = this; + } -void BluetoothOptionsView::RefreshText(void) -{ - // 刷新状态和文字 - BluetoothModel::GetInstance()->SetBtStatus(); - if (BluetoothModel::GetInstance()->GetAclConnected()) { - connectStateLabel->SetText("已连接"); - optionsOneButton->SetText("断开连接"); - } else { - connectStateLabel->SetText("已断开"); - optionsOneButton->SetText("重新连接"); + BluetoothOptionsView::~BluetoothOptionsView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView::~BluetoothOptionsView"); + if (group != nullptr) + { + group->RemoveAll(); + if (titleLabel) + { + delete titleLabel; + titleLabel = nullptr; + } + if (btHeadsetIconUmage) + { + delete btHeadsetIconUmage; + btHeadsetIconUmage = nullptr; + } + if (EarPhoneDeviceName) + { + delete EarPhoneDeviceName; + EarPhoneDeviceName = nullptr; + } + if (pairState) + { + delete pairState; + pairState = nullptr; + } + if (unpairButton) + { + delete unpairButton; + unpairButton = nullptr; + } + if (connectStateLabel) + { + delete connectStateLabel; + connectStateLabel = nullptr; + } + if (optionsOneButton) + { + delete optionsOneButton; + optionsOneButton = nullptr; + } + delete group; + group = nullptr; + } + g_pBluetoothOptionsView = nullptr; } - BluetoothCaseInfo *caseInfo = BluetoothModel::GetInstance()->GetTempMacValue(); - titleLabel->SetText(reinterpret_cast(caseInfo->deviceName)); - optionsOneButton->Invalidate(); -} -void BluetoothOptionsView::InItTitleLabel() -{ - if (titleLabel == nullptr) { - titleLabel = new UILabel(); - if (titleLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView titleLabel new fail"); - return; + BluetoothOptionsView *BluetoothOptionsView::GetInstance() + { + return g_pBluetoothOptionsView; + } + + bool BluetoothOptionsView::CreateBluetoothOptionsLabelView(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView::CreateBluetoothOptionsLabelView"); + /* ------------------------------- titleLabel ------------------------------- */ + if (titleLabel == nullptr) + { + titleLabel = new UILabelExt(); + if (titleLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel new fail"); + return false; + } + } + titleLabel->SetPosition(83, 50, 300, 35); + titleLabel->SetStyle(STYLE_TEXT_FONT, 30); + titleLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + titleLabel->SetTextId(STR_BLUETOOTH_HEADPHONES); /*蓝牙耳机*/ + titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* --------------------------- EarPhoneDeviceName --------------------------- */ + if (EarPhoneDeviceName == nullptr) + { + EarPhoneDeviceName = new UILabelExt(); + if (EarPhoneDeviceName == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EarPhoneDeviceName new fail"); + return false; + } } - titleLabel->SetPosition(60, 100, 333, 45); // 60:x 100:y 333:width 45:height + EarPhoneDeviceName->SetPosition(53, 246, 360, 35); + EarPhoneDeviceName->SetStyle(STYLE_TEXT_FONT, 30); + EarPhoneDeviceName->SetStyle(STYLE_LINE_HEIGHT, 35); BluetoothCaseInfo *caseInfo = BluetoothModel::GetInstance()->GetTempMacValue(); - titleLabel->SetText(reinterpret_cast(caseInfo->deviceName)); - titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); - 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); - } - if (connectStateLabel == nullptr) { - connectStateLabel = new UILabel(); - if (connectStateLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView connectStateLabel new fail"); - return; + EarPhoneDeviceName->SetText(reinterpret_cast(caseInfo->deviceName)); + EarPhoneDeviceName->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + EarPhoneDeviceName->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + EarPhoneDeviceName->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* -------------------------------- pairState ------------------------------- */ + if (pairState == nullptr) + { + pairState = new UILabelExt(); + if (pairState == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "pairState new fail"); + return false; + } } - connectStateLabel->SetPosition(60, 148, 333, 33); // 60:x 148:y 333:width 33:height + pairState->SetPosition(53, 284, 360, 35); + pairState->SetStyle(STYLE_TEXT_FONT, 30); + pairState->SetStyle(STYLE_LINE_HEIGHT, 35); + pairState->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); + caseInfo = BluetoothModel::GetInstance()->GetTempMacValue(); + pairState->SetTextId(STR_PAIRED); + pairState->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + pairState->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + pairState->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* ---------------------------- connectStateLabel 注:暂时不用--------------------------- */ + if (connectStateLabel == nullptr) + { + connectStateLabel = new UILabel(); + if (connectStateLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView connectStateLabel new fail"); + return false; + } + } + connectStateLabel->SetPosition(60, 148, 333, 33); connectStateLabel->SetText("已连接"); connectStateLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_THIRTY_SIZE); connectStateLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); connectStateLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); - group->Add(connectStateLabel); + connectStateLabel->SetVisible(false); + /* -------------------------------------------------------------------------- */ + return true; } -} -void BluetoothOptionsView::InItLabelButton() -{ - UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::PlayersPresenter::GetInstance(); - UIView::OnClickListener *clickListener2 = (UIView::OnClickListener *)OHOS::BluetoothPresenter::GetInstance(); - if ((clickListener == nullptr) && (clickListener2 == nullptr)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener GetInstance fail"); - return; - } - if (optionsOneButton == nullptr) { - optionsOneButton = new UILabelButton(); - if (optionsOneButton == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView optionsOneButton new fail"); - return; + bool BluetoothOptionsView::CreateBluetoothOptionsLabelButton(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView::CreateBluetoothOptionsLabelButton"); + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::PlayersPresenter::GetInstance(); + UIView::OnClickListener *clickListener2 = (UIView::OnClickListener *)OHOS::BluetoothPresenter::GetInstance(); + if ((clickListener == nullptr) && (clickListener2 == nullptr)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener GetInstance fail"); + return false; + } + /* ---------------------------- optionsOneButton 注:暂时不用---------------------------- */ + if (optionsOneButton == nullptr) + { + optionsOneButton = new UILabelButtonExt(); + if (optionsOneButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView optionsOneButton new fail"); + return false; + } } optionsOneButton->SetPosition(157, 210, 139, 47); // 157:x, 210:y, 139:width 47:height optionsOneButton->SetText("断开连接"); optionsOneButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_THIRTY_SIZE); optionsOneButton->SetViewId(BLUETOOTH_OPTIONONE_BUTTON); optionsOneButton->SetImageSrc(PNG_SELECTION_BOX, PNG_SELECTION_BOX); - if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { + if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) + { optionsOneButton->SetTextColor(Color::Red()); optionsOneButton->SetOnClickListener(clickListener); - } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) { + } + else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) + { optionsOneButton->SetTextColor(Color::Blue()); optionsOneButton->SetOnClickListener(clickListener2); } - group->Add(optionsOneButton); - } - if (unpairButton == nullptr) { - unpairButton = new UILabelButton(); - if (unpairButton == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView unpairButton new fail"); - return; - } - unpairButton->SetPosition(157, 284, 139, 47); // 157:x, 284:y, 139:width 47:height - unpairButton->SetText("取消配对"); - unpairButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_THIRTY_SIZE); + optionsOneButton->SetVisible(false); + /* ------------------------------ unpairButton ------------------------------ */ + if (unpairButton == nullptr) + { + unpairButton = new UILabelButtonExt(); + if (unpairButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView unpairButton new fail"); + return false; + } + } + unpairButton->SetPosition(0, 366, 466, 100); + unpairButton->SetTextId(STR_UNPAIR); // 取消配对 + unpairButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); unpairButton->SetViewId(BLUETOOTH_UNPAIR_BUTTON); - unpairButton->SetImageSrc(PNG_SELECTION_BOX, PNG_SELECTION_BOX); - if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { - unpairButton->SetTextColor(Color::Red()); + unpairButton->SetImageSrc(PNG_BUTTON_466x100_IMAGE, PNG_BUTTON_466x100_IMAGE); + unpairButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0x00, UIButton::PRESSED); + unpairButton->SetTextColor(Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff)); + if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) + { unpairButton->SetOnClickListener(clickListener); - } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) { - unpairButton->SetTextColor(Color::Blue()); + } + else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) + { unpairButton->SetOnClickListener(clickListener2); } - group->Add(unpairButton); + return true; } -} -UIViewGroup *BluetoothOptionsView::InitShowUpView() -{ - // 获取currentBdAddr db值 model待开发 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView init"); - if (group == nullptr) { - group = new UIViewGroup(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); - return nullptr; + bool BluetoothOptionsView::CreateBluetoothOptionsImageView(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView::CreateBluetoothOptionsImageView"); + /* --------------------------- btHeadsetIconUmage --------------------------- */ + if (btHeadsetIconUmage == nullptr) + { + btHeadsetIconUmage = new UIImageView(); + if (btHeadsetIconUmage == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "btHeadsetIconUmage new fail"); + return false; + } + } + btHeadsetIconUmage->SetPosition(193, 134, 80, 80); + btHeadsetIconUmage->SetAutoEnable(false); + btHeadsetIconUmage->SetResizeMode(UIImageView::CENTER); + if (!PlayersView::LoadPlayerImage(btHeadsetIconUmage, PLAYER_EARPHONE)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "btHeadsetIconUmage LoadPlayerImage fail"); + return false; } - group->SetPosition(0, 0); - group->SetWidth(HORIZONTAL_RESOLUTION); - group->SetHeight(VERTICAL_RESOLUTION); + return true; } - InItLabelButton(); - InItTitleLabel(); - 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; + + // 刷新状态和文字 + void BluetoothOptionsView::RefreshText(void) + { + BluetoothModel::GetInstance()->SetBtStatus(); + if (BluetoothModel::GetInstance()->GetAclConnected()) + { + connectStateLabel->SetText("已连接"); + optionsOneButton->SetText("断开连接"); + } + else + { + connectStateLabel->SetText("已断开"); + optionsOneButton->SetText("重新连接"); + } + BluetoothCaseInfo *caseInfo = BluetoothModel::GetInstance()->GetTempMacValue(); + EarPhoneDeviceName->SetText(reinterpret_cast(caseInfo->deviceName)); + optionsOneButton->Invalidate(); } - if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { - group->SetOnDragListener(earDragListener); - } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) { - group->SetOnDragListener(earDragListener2); + + UIViewGroup *BluetoothOptionsView::CreateBluetoothOptionsView() + { + // 获取currentBdAddr db值 model待开发 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView init"); + 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); + } + 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); + } + group->SetViewId(BLUETOOTH_OPTIONS_VIEW); + group->SetDraggable(true); + group->SetTouchable(true); + /* -------------------------------------------------------------------------- */ + if (!CreateBluetoothOptionsLabelView() || !CreateBluetoothOptionsImageView() || !CreateBluetoothOptionsLabelButton()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsFailMessageView::CreateTipsFailMessageView fail!!"); + return nullptr; + } + /* ----------------------------------- Add ---------------------------------- */ + group->Add(titleLabel); + group->Add(btHeadsetIconUmage); + group->Add(EarPhoneDeviceName); + group->Add(pairState); + group->Add(unpairButton); + group->Add(optionsOneButton); + group->Add(connectStateLabel); + + return group; } - group->SetViewId(BLUETOOTH_OPTIONS_VIEW); - group->SetDraggable(true); - group->SetTouchable(true); - return group; -} -UILabelButton *BluetoothOptionsView::GetOptionsOneButton(void) -{ - return optionsOneButton; -} + UILabelButtonExt *BluetoothOptionsView::GetOptionsOneButton(void) + { + return optionsOneButton; + } -UILabelButton *BluetoothOptionsView::GetUnpairButton(void) -{ - return unpairButton; -} + UILabelButtonExt *BluetoothOptionsView::GetUnpairButton(void) + { + return unpairButton; + } + /* + * @brief 获取蓝牙Model中的最后连接设备的地址,然后调用 gap_disconnect_remote_device 函数来断开与该远程设备的连接,并记录相关的日志信息。 + * + * eg:比如之前连接的设备是一个蓝牙耳机,当用户主动触发断开操作时,该函数就会执行,断开与该耳机的连接。 + */ + void BluetoothOptionsView::SetBtDisconnect(void) + { + bd_addr_t *lastAddr = BluetoothModel::GetInstance()->GetLastConnedAddr(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetBtDisconnect Addr: %02x%02x%02x%02x%02x%02x", + lastAddr->addr[5], lastAddr->addr[4], lastAddr->addr[3], /* mac下标 0 1 2 3 4 5 */ + lastAddr->addr[2], lastAddr->addr[1], lastAddr->addr[0]); /* mac下标 0 1 2 3 4 5 */ + errcode_t retVal = gap_disconnect_remote_device(lastAddr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "gap_disconnect_remote_device %d", retVal); + } -void BluetoothOptionsView::SetBtDisconnect(void) -{ - bd_addr_t *lastAddr = BluetoothModel::GetInstance()->GetLastConnedAddr(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetBtDisconnect Addr: %02x%02x%02x%02x%02x%02x", - lastAddr->addr[5], lastAddr->addr[4], lastAddr->addr[3], /* mac下标 0 1 2 3 4 5 */ - lastAddr->addr[2], lastAddr->addr[1], lastAddr->addr[0]); /* mac下标 0 1 2 3 4 5 */ - errcode_t retVal = gap_disconnect_remote_device(lastAddr); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "gap_disconnect_remote_device %d", retVal); -} - -void BluetoothOptionsView::SetBtconnect(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetBtconnect currentAddr: %02x%02x%02x%02x%02x%02x", - currentAddr.addr[5], currentAddr.addr[4], currentAddr.addr[3], /* mac下标 0 1 2 3 4 5 */ - currentAddr.addr[2], currentAddr.addr[1], currentAddr.addr[0]); /* mac下标 0 1 2 3 4 5 */ - errcode_t retVal = BluetoothModel::GetInstance()->ConnectRemoteDevice(¤tAddr); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetBtconnect ConnectRemoteDevice %d", retVal); -} - -void BluetoothOptionsView::SetUnpair(void) -{ - bool ret; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUnpair currentAddr: %02x%02x%02x%02x%02x%02x", - currentAddr.addr[5], currentAddr.addr[4], currentAddr.addr[3], /* mac下标 0 1 2 3 4 5 */ - currentAddr.addr[2], currentAddr.addr[1], currentAddr.addr[0]); /* mac下标 0 1 2 3 4 5 */ - ret = gap_remove_pair(¤tAddr); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUnpair gap_remove_pair %d", ret); -} + /* + * @brief 记录当前要连接的设备地址的相关日志信息,然后通过蓝牙Model的 ConnectRemoteDevice 函数尝试连接该远程设备,并记录连接结果的日志。 + * + * 当用户选择连接一个新的蓝牙设备时,这个函数会被调用,尝试建立与该设备的连接。 + */ + void BluetoothOptionsView::SetBtconnect(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetBtconnect currentAddr: %02x%02x%02x%02x%02x%02x", + currentAddr.addr[5], currentAddr.addr[4], currentAddr.addr[3], /* mac下标 0 1 2 3 4 5 */ + currentAddr.addr[2], currentAddr.addr[1], currentAddr.addr[0]); /* mac下标 0 1 2 3 4 5 */ + errcode_t retVal = BluetoothModel::GetInstance()->ConnectRemoteDevice(¤tAddr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetBtconnect ConnectRemoteDevice %d", retVal); + } + /* + * @brief 记录当前设备地址的日志,然后调用 gap_remove_pair 函数来解除与该设备的配对,并记录操作结果的日志。 + * + * 如果用户不再希望与某个已配对的蓝牙设备保持配对关系,例如一个旧手机,触发此操作时该函数执行。 + */ + void BluetoothOptionsView::SetUnpair(void) + { + bool ret; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUnpair currentAddr: %02x%02x%02x%02x%02x%02x", + currentAddr.addr[5], currentAddr.addr[4], currentAddr.addr[3], /* mac下标 0 1 2 3 4 5 */ + currentAddr.addr[2], currentAddr.addr[1], currentAddr.addr[0]); /* mac下标 0 1 2 3 4 5 */ + ret = gap_remove_pair(¤tAddr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUnpair gap_remove_pair %d", ret); + } -void BluetoothOptionsView::SetCurrentAddr(bd_addr_t addr) -{ - (void)memcpy_s(currentAddr.addr, BD_ADDR_LEN, - addr.addr, BD_ADDR_LEN); // 源和目标内存长度一样,不做返回值判断 -} + /* + * @brief 使用 memcpy_s 函数将传入的地址 addr 复制到 currentAddr 中。 + * + * 当获取到新的有效的蓝牙设备地址时,通过这个函数更新当前要操作的地址。 + */ + void BluetoothOptionsView::SetCurrentAddr(bd_addr_t addr) + { + (void)memcpy_s(currentAddr.addr, BD_ADDR_LEN, + addr.addr, BD_ADDR_LEN); // 源和目标内存长度一样,不做返回值判断 + } -bd_addr_t BluetoothOptionsView::GetCurrentAddr(void) -{ - return currentAddr; -} + /* + * @brief 返回当前保存的蓝牙设备地址。 + * + * 其他函数需要获取当前正在操作的蓝牙地址时,会调用这个函数来获取。 + */ + bd_addr_t BluetoothOptionsView::GetCurrentAddr(void) + { + return currentAddr; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothPresenter.cpp index 18b5baebf..878c2e22a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothPresenter.cpp @@ -136,6 +136,7 @@ void BluetoothPresenter::ClickUnpairButton(void) view_->ChangeView(BLUETOOTHEOPTIONSVIEW, BLUETOOTHDEVICELISTVIEW); } +/*已连接的蓝牙耳机设备视图中【重新连接或断开连接】按钮*/ void BluetoothPresenter::ClickOptionsOneButton(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_OPTIONONE_BUTTON"); @@ -147,7 +148,7 @@ void BluetoothPresenter::ClickOptionsOneButton(void) bluetoothMode_->SetBtStatus(); if (bluetoothMode_->GetAclConnected()) { bluetoothMode_->SetTagConnectNew(false); - bluetoothOptionsView->SetBtDisconnect(); + bluetoothOptionsView->SetBtDisconnect();/*断开与该远程设备的连接*/ view_->ChangeView(BLUETOOTHEOPTIONSVIEW, BLUETOOTHDEVICELISTVIEW); } else { bluetoothMode_->SetTagReconnectJump(true); @@ -224,7 +225,7 @@ bool BluetoothPresenter::OnKeyAct(UIView &view, const KeyEvent &event) uint16 keyID = event.GetKeyId(); uint16 keyState = event.GetState(); // 如果是power键就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0) + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) { NativeAbility::GetInstance().Back(); } 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 3c641a141..27846c3f6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/MainBluetoothView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/MainBluetoothView.cpp @@ -281,7 +281,7 @@ bool MainBluetoothView::ChangeBluetoothOptionsView(int16_t hideView, int16_t thi return false; } // init view - UIViewGroup *group = bluetoothOptionsView->InitShowUpView(); + UIViewGroup *group = bluetoothOptionsView->CreateBluetoothOptionsView(); if (group == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); return false; diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/TipsFailMessageView.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/TipsFailMessageView.cpp index 56222c913..49982ff0e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/TipsFailMessageView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/TipsFailMessageView.cpp @@ -119,7 +119,7 @@ namespace OHOS btIconImage->SetResizeMode(UIImageView::CENTER); if (!PlayersView::LoadPlayerImage(btIconImage, PLAYER_BLUETOOTH_GRAY)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneImage LoadPlayerImage fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "btIconImage LoadPlayerImage fail"); return false; } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp index 32fbe7540..2190639a0 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp @@ -185,7 +185,7 @@ bool JumpView::ChangeBluetoothOptionsView(int16_t hideView, int16_t thisView) return false; } // init view - UIViewGroup *group = bluetoothOptionsView->InitShowUpView(); + UIViewGroup *group = bluetoothOptionsView->CreateBluetoothOptionsView(); if (group == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); return false; -- 2.17.1