* Author:\r
* Create: 2021-10-13\r
*/\r
-#include "BluetoothOptionsView.h"\r
-#include "BluetoothModel.h"\r
+#include "bluetooth/include/BluetoothOptionsView.h"\r
+#include "bluetooth/include/BluetoothModel.h"\r
#include "wearable_log.h"\r
#include "UiConfig.h"\r
-#include "PlayersPresenter.h"\r
-#include "BluetoothPresenter.h"\r
-\r
-namespace OHOS {\r
-static BluetoothOptionsView *g_pBluetoothOptionsView{nullptr};\r
-\r
-BluetoothOptionsView::BluetoothOptionsView()\r
+#include "player/include/PlayersPresenter.h"\r
+#include "player/include/PlayersView.h"\r
+#include "bluetooth/include/BluetoothPresenter.h"\r
+#include "ui_resource_string.h"\r
+#include "ui_resource_image.h"\r
+namespace OHOS\r
{\r
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView::BluetoothOptionsView");\r
- g_pBluetoothOptionsView = this;\r
-}\r
+ static BluetoothOptionsView *g_pBluetoothOptionsView{nullptr};\r
\r
-BluetoothOptionsView::~BluetoothOptionsView()\r
-{\r
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView::~BluetoothOptionsView");\r
- group->RemoveAll();\r
- delete titleLabel;\r
- titleLabel = nullptr;\r
- delete connectStateLabel;\r
- connectStateLabel = nullptr;\r
- delete optionsOneButton;\r
- optionsOneButton = nullptr;\r
- delete unpairButton;\r
- unpairButton = nullptr;\r
- delete group;\r
- group = nullptr;\r
- g_pBluetoothOptionsView = nullptr;\r
-}\r
-\r
-BluetoothOptionsView *BluetoothOptionsView::GetInstance()\r
-{\r
- return g_pBluetoothOptionsView;\r
-}\r
+ BluetoothOptionsView::BluetoothOptionsView()\r
+ {\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView::BluetoothOptionsView");\r
+ g_pBluetoothOptionsView = this;\r
+ }\r
\r
-void BluetoothOptionsView::RefreshText(void)\r
-{\r
- // 刷新状态和文字\r
- BluetoothModel::GetInstance()->SetBtStatus();\r
- if (BluetoothModel::GetInstance()->GetAclConnected()) {\r
- connectStateLabel->SetText("已连接");\r
- optionsOneButton->SetText("断开连接");\r
- } else {\r
- connectStateLabel->SetText("已断开");\r
- optionsOneButton->SetText("重新连接");\r
+ BluetoothOptionsView::~BluetoothOptionsView()\r
+ {\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView::~BluetoothOptionsView");\r
+ if (group != nullptr)\r
+ {\r
+ group->RemoveAll();\r
+ if (titleLabel)\r
+ {\r
+ delete titleLabel;\r
+ titleLabel = nullptr;\r
+ }\r
+ if (btHeadsetIconUmage)\r
+ {\r
+ delete btHeadsetIconUmage;\r
+ btHeadsetIconUmage = nullptr;\r
+ }\r
+ if (EarPhoneDeviceName)\r
+ {\r
+ delete EarPhoneDeviceName;\r
+ EarPhoneDeviceName = nullptr;\r
+ }\r
+ if (pairState)\r
+ {\r
+ delete pairState;\r
+ pairState = nullptr;\r
+ }\r
+ if (unpairButton)\r
+ {\r
+ delete unpairButton;\r
+ unpairButton = nullptr;\r
+ }\r
+ if (connectStateLabel)\r
+ {\r
+ delete connectStateLabel;\r
+ connectStateLabel = nullptr;\r
+ }\r
+ if (optionsOneButton)\r
+ {\r
+ delete optionsOneButton;\r
+ optionsOneButton = nullptr;\r
+ }\r
+ delete group;\r
+ group = nullptr;\r
+ }\r
+ g_pBluetoothOptionsView = nullptr;\r
}\r
- BluetoothCaseInfo *caseInfo = BluetoothModel::GetInstance()->GetTempMacValue();\r
- titleLabel->SetText(reinterpret_cast<const char *>(caseInfo->deviceName));\r
- optionsOneButton->Invalidate();\r
-}\r
\r
-void BluetoothOptionsView::InItTitleLabel()\r
-{\r
- if (titleLabel == nullptr) {\r
- titleLabel = new UILabel();\r
- if (titleLabel == nullptr) {\r
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView titleLabel new fail");\r
- return;\r
+ BluetoothOptionsView *BluetoothOptionsView::GetInstance()\r
+ {\r
+ return g_pBluetoothOptionsView;\r
+ }\r
+\r
+ bool BluetoothOptionsView::CreateBluetoothOptionsLabelView(void)\r
+ {\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView::CreateBluetoothOptionsLabelView");\r
+ /* ------------------------------- titleLabel ------------------------------- */\r
+ if (titleLabel == nullptr)\r
+ {\r
+ titleLabel = new UILabelExt();\r
+ if (titleLabel == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel new fail");\r
+ return false;\r
+ }\r
+ }\r
+ titleLabel->SetPosition(83, 50, 300, 35);\r
+ titleLabel->SetStyle(STYLE_TEXT_FONT, 30);\r
+ titleLabel->SetStyle(STYLE_LINE_HEIGHT, 35);\r
+ titleLabel->SetTextId(STR_BLUETOOTH_HEADPHONES); /*蓝牙耳机*/\r
+ titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);\r
+ titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
+ titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
+ /* --------------------------- EarPhoneDeviceName --------------------------- */\r
+ if (EarPhoneDeviceName == nullptr)\r
+ {\r
+ EarPhoneDeviceName = new UILabelExt();\r
+ if (EarPhoneDeviceName == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EarPhoneDeviceName new fail");\r
+ return false;\r
+ }\r
}\r
- titleLabel->SetPosition(60, 100, 333, 45); // 60:x 100:y 333:width 45:height\r
+ EarPhoneDeviceName->SetPosition(53, 246, 360, 35);\r
+ EarPhoneDeviceName->SetStyle(STYLE_TEXT_FONT, 30);\r
+ EarPhoneDeviceName->SetStyle(STYLE_LINE_HEIGHT, 35);\r
BluetoothCaseInfo *caseInfo = BluetoothModel::GetInstance()->GetTempMacValue();\r
- titleLabel->SetText(reinterpret_cast<const char *>(caseInfo->deviceName));\r
- titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);\r
- titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_FORTY_SIZE);\r
- titleLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE);\r
- titleLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER);\r
- group->Add(titleLabel);\r
- }\r
- if (connectStateLabel == nullptr) {\r
- connectStateLabel = new UILabel();\r
- if (connectStateLabel == nullptr) {\r
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView connectStateLabel new fail");\r
- return;\r
+ EarPhoneDeviceName->SetText(reinterpret_cast<const char *>(caseInfo->deviceName));\r
+ EarPhoneDeviceName->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);\r
+ EarPhoneDeviceName->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
+ EarPhoneDeviceName->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
+ /* -------------------------------- pairState ------------------------------- */\r
+ if (pairState == nullptr)\r
+ {\r
+ pairState = new UILabelExt();\r
+ if (pairState == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "pairState new fail");\r
+ return false;\r
+ }\r
}\r
- connectStateLabel->SetPosition(60, 148, 333, 33); // 60:x 148:y 333:width 33:height\r
+ pairState->SetPosition(53, 284, 360, 35);\r
+ pairState->SetStyle(STYLE_TEXT_FONT, 30);\r
+ pairState->SetStyle(STYLE_LINE_HEIGHT, 35);\r
+ pairState->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f));\r
+ caseInfo = BluetoothModel::GetInstance()->GetTempMacValue();\r
+ pairState->SetTextId(STR_PAIRED);\r
+ pairState->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);\r
+ pairState->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
+ pairState->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
+ /* ---------------------------- connectStateLabel 注:暂时不用--------------------------- */\r
+ if (connectStateLabel == nullptr)\r
+ {\r
+ connectStateLabel = new UILabel();\r
+ if (connectStateLabel == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView connectStateLabel new fail");\r
+ return false;\r
+ }\r
+ }\r
+ connectStateLabel->SetPosition(60, 148, 333, 33);\r
connectStateLabel->SetText("已连接");\r
connectStateLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_THIRTY_SIZE);\r
connectStateLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE);\r
connectStateLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER);\r
- group->Add(connectStateLabel);\r
+ connectStateLabel->SetVisible(false);\r
+ /* -------------------------------------------------------------------------- */\r
+ return true;\r
}\r
-}\r
\r
-void BluetoothOptionsView::InItLabelButton()\r
-{\r
- UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::PlayersPresenter::GetInstance();\r
- UIView::OnClickListener *clickListener2 = (UIView::OnClickListener *)OHOS::BluetoothPresenter::GetInstance();\r
- if ((clickListener == nullptr) && (clickListener2 == nullptr)) {\r
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener GetInstance fail");\r
- return;\r
- }\r
- if (optionsOneButton == nullptr) {\r
- optionsOneButton = new UILabelButton();\r
- if (optionsOneButton == nullptr) {\r
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView optionsOneButton new fail");\r
- return;\r
+ bool BluetoothOptionsView::CreateBluetoothOptionsLabelButton(void)\r
+ {\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView::CreateBluetoothOptionsLabelButton");\r
+ UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::PlayersPresenter::GetInstance();\r
+ UIView::OnClickListener *clickListener2 = (UIView::OnClickListener *)OHOS::BluetoothPresenter::GetInstance();\r
+ if ((clickListener == nullptr) && (clickListener2 == nullptr))\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clickListener GetInstance fail");\r
+ return false;\r
+ }\r
+ /* ---------------------------- optionsOneButton 注:暂时不用---------------------------- */\r
+ if (optionsOneButton == nullptr)\r
+ {\r
+ optionsOneButton = new UILabelButtonExt();\r
+ if (optionsOneButton == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView optionsOneButton new fail");\r
+ return false;\r
+ }\r
}\r
optionsOneButton->SetPosition(157, 210, 139, 47); // 157:x, 210:y, 139:width 47:height\r
optionsOneButton->SetText("断开连接");\r
optionsOneButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_THIRTY_SIZE);\r
optionsOneButton->SetViewId(BLUETOOTH_OPTIONONE_BUTTON);\r
optionsOneButton->SetImageSrc(PNG_SELECTION_BOX, PNG_SELECTION_BOX);\r
- if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) {\r
+ if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS)\r
+ {\r
optionsOneButton->SetTextColor(Color::Red());\r
optionsOneButton->SetOnClickListener(clickListener);\r
- } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) {\r
+ }\r
+ else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING)\r
+ {\r
optionsOneButton->SetTextColor(Color::Blue());\r
optionsOneButton->SetOnClickListener(clickListener2);\r
}\r
- group->Add(optionsOneButton);\r
- }\r
- if (unpairButton == nullptr) {\r
- unpairButton = new UILabelButton();\r
- if (unpairButton == nullptr) {\r
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView unpairButton new fail");\r
- return;\r
- }\r
- unpairButton->SetPosition(157, 284, 139, 47); // 157:x, 284:y, 139:width 47:height\r
- unpairButton->SetText("取消配对");\r
- unpairButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_THIRTY_SIZE);\r
+ optionsOneButton->SetVisible(false);\r
+ /* ------------------------------ unpairButton ------------------------------ */\r
+ if (unpairButton == nullptr)\r
+ {\r
+ unpairButton = new UILabelButtonExt();\r
+ if (unpairButton == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView unpairButton new fail");\r
+ return false;\r
+ }\r
+ }\r
+ unpairButton->SetPosition(0, 366, 466, 100);\r
+ unpairButton->SetTextId(STR_UNPAIR); // 取消配对\r
+ unpairButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
unpairButton->SetViewId(BLUETOOTH_UNPAIR_BUTTON);\r
- unpairButton->SetImageSrc(PNG_SELECTION_BOX, PNG_SELECTION_BOX);\r
- if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) {\r
- unpairButton->SetTextColor(Color::Red());\r
+ unpairButton->SetImageSrc(PNG_BUTTON_466x100_IMAGE, PNG_BUTTON_466x100_IMAGE);\r
+ unpairButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0x00, UIButton::PRESSED);\r
+ unpairButton->SetTextColor(Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff));\r
+ if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS)\r
+ {\r
unpairButton->SetOnClickListener(clickListener);\r
- } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) {\r
- unpairButton->SetTextColor(Color::Blue());\r
+ }\r
+ else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING)\r
+ {\r
unpairButton->SetOnClickListener(clickListener2);\r
}\r
- group->Add(unpairButton);\r
+ return true;\r
}\r
-}\r
\r
-UIViewGroup *BluetoothOptionsView::InitShowUpView()\r
-{\r
- // 获取currentBdAddr db值 model待开发\r
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView init");\r
- if (group == nullptr) {\r
- group = new UIViewGroup();\r
- if (group == nullptr) {\r
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail");\r
- return nullptr;\r
+ bool BluetoothOptionsView::CreateBluetoothOptionsImageView(void)\r
+ {\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView::CreateBluetoothOptionsImageView");\r
+ /* --------------------------- btHeadsetIconUmage --------------------------- */\r
+ if (btHeadsetIconUmage == nullptr)\r
+ {\r
+ btHeadsetIconUmage = new UIImageView();\r
+ if (btHeadsetIconUmage == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "btHeadsetIconUmage new fail");\r
+ return false;\r
+ }\r
+ }\r
+ btHeadsetIconUmage->SetPosition(193, 134, 80, 80);\r
+ btHeadsetIconUmage->SetAutoEnable(false);\r
+ btHeadsetIconUmage->SetResizeMode(UIImageView::CENTER);\r
+ if (!PlayersView::LoadPlayerImage(btHeadsetIconUmage, PLAYER_EARPHONE))\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "btHeadsetIconUmage LoadPlayerImage fail");\r
+ return false;\r
}\r
- group->SetPosition(0, 0);\r
- group->SetWidth(HORIZONTAL_RESOLUTION);\r
- group->SetHeight(VERTICAL_RESOLUTION);\r
+ return true;\r
}\r
- InItLabelButton();\r
- InItTitleLabel();\r
- UIView::OnDragListener *earDragListener = (UIView::OnDragListener *)OHOS::PlayerOnDragListener::GetInstance();\r
- UIView::OnDragListener *earDragListener2 = (UIView::OnDragListener *)OHOS::BluetoothPresenter::GetInstance();\r
- if ((earDragListener == nullptr) && (earDragListener2 == nullptr)) {\r
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "earDragListener GetInstance fail");\r
- return nullptr;\r
+\r
+ // 刷新状态和文字\r
+ void BluetoothOptionsView::RefreshText(void)\r
+ {\r
+ BluetoothModel::GetInstance()->SetBtStatus();\r
+ if (BluetoothModel::GetInstance()->GetAclConnected())\r
+ {\r
+ connectStateLabel->SetText("已连接");\r
+ optionsOneButton->SetText("断开连接");\r
+ }\r
+ else\r
+ {\r
+ connectStateLabel->SetText("已断开");\r
+ optionsOneButton->SetText("重新连接");\r
+ }\r
+ BluetoothCaseInfo *caseInfo = BluetoothModel::GetInstance()->GetTempMacValue();\r
+ EarPhoneDeviceName->SetText(reinterpret_cast<const char *>(caseInfo->deviceName));\r
+ optionsOneButton->Invalidate();\r
}\r
- if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) {\r
- group->SetOnDragListener(earDragListener);\r
- } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) {\r
- group->SetOnDragListener(earDragListener2);\r
+\r
+ UIViewGroup *BluetoothOptionsView::CreateBluetoothOptionsView()\r
+ {\r
+ // 获取currentBdAddr db值 model待开发\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOptionsView init");\r
+ if (group == nullptr)\r
+ {\r
+ group = new UIViewGroup();\r
+ if (group == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail");\r
+ return nullptr;\r
+ }\r
+ group->SetPosition(0, 0);\r
+ group->SetWidth(HORIZONTAL_RESOLUTION);\r
+ group->SetHeight(VERTICAL_RESOLUTION);\r
+ }\r
+ UIView::OnDragListener *earDragListener = (UIView::OnDragListener *)OHOS::PlayerOnDragListener::GetInstance();\r
+ UIView::OnDragListener *earDragListener2 = (UIView::OnDragListener *)OHOS::BluetoothPresenter::GetInstance();\r
+ if ((earDragListener == nullptr) && (earDragListener2 == nullptr))\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "earDragListener GetInstance fail");\r
+ return nullptr;\r
+ }\r
+ if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS)\r
+ {\r
+ group->SetOnDragListener(earDragListener);\r
+ }\r
+ else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING)\r
+ {\r
+ group->SetOnDragListener(earDragListener2);\r
+ }\r
+ group->SetViewId(BLUETOOTH_OPTIONS_VIEW);\r
+ group->SetDraggable(true);\r
+ group->SetTouchable(true);\r
+ /* -------------------------------------------------------------------------- */\r
+ if (!CreateBluetoothOptionsLabelView() || !CreateBluetoothOptionsImageView() || !CreateBluetoothOptionsLabelButton())\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsFailMessageView::CreateTipsFailMessageView fail!!");\r
+ return nullptr;\r
+ }\r
+ /* ----------------------------------- Add ---------------------------------- */\r
+ group->Add(titleLabel);\r
+ group->Add(btHeadsetIconUmage);\r
+ group->Add(EarPhoneDeviceName);\r
+ group->Add(pairState);\r
+ group->Add(unpairButton);\r
+ group->Add(optionsOneButton);\r
+ group->Add(connectStateLabel);\r
+\r
+ return group;\r
}\r
- group->SetViewId(BLUETOOTH_OPTIONS_VIEW);\r
- group->SetDraggable(true);\r
- group->SetTouchable(true);\r
- return group;\r
-}\r
\r
-UILabelButton *BluetoothOptionsView::GetOptionsOneButton(void)\r
-{\r
- return optionsOneButton;\r
-}\r
+ UILabelButtonExt *BluetoothOptionsView::GetOptionsOneButton(void)\r
+ {\r
+ return optionsOneButton;\r
+ }\r
\r
-UILabelButton *BluetoothOptionsView::GetUnpairButton(void)\r
-{\r
- return unpairButton;\r
-}\r
+ UILabelButtonExt *BluetoothOptionsView::GetUnpairButton(void)\r
+ {\r
+ return unpairButton;\r
+ }\r
\r
+ /*\r
+ * @brief 获取蓝牙Model中的最后连接设备的地址,然后调用 gap_disconnect_remote_device 函数来断开与该远程设备的连接,并记录相关的日志信息。\r
+ *\r
+ * eg:比如之前连接的设备是一个蓝牙耳机,当用户主动触发断开操作时,该函数就会执行,断开与该耳机的连接。\r
+ */\r
+ void BluetoothOptionsView::SetBtDisconnect(void)\r
+ {\r
+ bd_addr_t *lastAddr = BluetoothModel::GetInstance()->GetLastConnedAddr();\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetBtDisconnect Addr: %02x%02x%02x%02x%02x%02x",\r
+ lastAddr->addr[5], lastAddr->addr[4], lastAddr->addr[3], /* mac下标 0 1 2 3 4 5 */\r
+ lastAddr->addr[2], lastAddr->addr[1], lastAddr->addr[0]); /* mac下标 0 1 2 3 4 5 */\r
+ errcode_t retVal = gap_disconnect_remote_device(lastAddr);\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "gap_disconnect_remote_device %d", retVal);\r
+ }\r
\r
-void BluetoothOptionsView::SetBtDisconnect(void)\r
-{\r
- bd_addr_t *lastAddr = BluetoothModel::GetInstance()->GetLastConnedAddr();\r
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetBtDisconnect Addr: %02x%02x%02x%02x%02x%02x",\r
- lastAddr->addr[5], lastAddr->addr[4], lastAddr->addr[3], /* mac下标 0 1 2 3 4 5 */\r
- lastAddr->addr[2], lastAddr->addr[1], lastAddr->addr[0]); /* mac下标 0 1 2 3 4 5 */\r
- errcode_t retVal = gap_disconnect_remote_device(lastAddr);\r
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "gap_disconnect_remote_device %d", retVal);\r
-}\r
-\r
-void BluetoothOptionsView::SetBtconnect(void)\r
-{\r
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetBtconnect currentAddr: %02x%02x%02x%02x%02x%02x",\r
- currentAddr.addr[5], currentAddr.addr[4], currentAddr.addr[3], /* mac下标 0 1 2 3 4 5 */\r
- currentAddr.addr[2], currentAddr.addr[1], currentAddr.addr[0]); /* mac下标 0 1 2 3 4 5 */\r
- errcode_t retVal = BluetoothModel::GetInstance()->ConnectRemoteDevice(¤tAddr);\r
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetBtconnect ConnectRemoteDevice %d", retVal);\r
-}\r
-\r
-void BluetoothOptionsView::SetUnpair(void)\r
-{\r
- bool ret;\r
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUnpair currentAddr: %02x%02x%02x%02x%02x%02x",\r
- currentAddr.addr[5], currentAddr.addr[4], currentAddr.addr[3], /* mac下标 0 1 2 3 4 5 */\r
- currentAddr.addr[2], currentAddr.addr[1], currentAddr.addr[0]); /* mac下标 0 1 2 3 4 5 */\r
- ret = gap_remove_pair(¤tAddr);\r
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUnpair gap_remove_pair %d", ret);\r
-}\r
+ /*\r
+ * @brief 记录当前要连接的设备地址的相关日志信息,然后通过蓝牙Model的 ConnectRemoteDevice 函数尝试连接该远程设备,并记录连接结果的日志。 \r
+ *\r
+ * 当用户选择连接一个新的蓝牙设备时,这个函数会被调用,尝试建立与该设备的连接。\r
+ */\r
+ void BluetoothOptionsView::SetBtconnect(void)\r
+ {\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetBtconnect currentAddr: %02x%02x%02x%02x%02x%02x",\r
+ currentAddr.addr[5], currentAddr.addr[4], currentAddr.addr[3], /* mac下标 0 1 2 3 4 5 */\r
+ currentAddr.addr[2], currentAddr.addr[1], currentAddr.addr[0]); /* mac下标 0 1 2 3 4 5 */\r
+ errcode_t retVal = BluetoothModel::GetInstance()->ConnectRemoteDevice(¤tAddr);\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetBtconnect ConnectRemoteDevice %d", retVal);\r
+ }\r
\r
+ /*\r
+ * @brief 记录当前设备地址的日志,然后调用 gap_remove_pair 函数来解除与该设备的配对,并记录操作结果的日志。\r
+ *\r
+ * 如果用户不再希望与某个已配对的蓝牙设备保持配对关系,例如一个旧手机,触发此操作时该函数执行。\r
+ */\r
+ void BluetoothOptionsView::SetUnpair(void)\r
+ {\r
+ bool ret;\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUnpair currentAddr: %02x%02x%02x%02x%02x%02x",\r
+ currentAddr.addr[5], currentAddr.addr[4], currentAddr.addr[3], /* mac下标 0 1 2 3 4 5 */\r
+ currentAddr.addr[2], currentAddr.addr[1], currentAddr.addr[0]); /* mac下标 0 1 2 3 4 5 */\r
+ ret = gap_remove_pair(¤tAddr);\r
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUnpair gap_remove_pair %d", ret);\r
+ }\r
\r
-void BluetoothOptionsView::SetCurrentAddr(bd_addr_t addr)\r
-{\r
- (void)memcpy_s(currentAddr.addr, BD_ADDR_LEN,\r
- addr.addr, BD_ADDR_LEN); // 源和目标内存长度一样,不做返回值判断\r
-}\r
+ /*\r
+ * @brief 使用 memcpy_s 函数将传入的地址 addr 复制到 currentAddr 中。\r
+ *\r
+ * 当获取到新的有效的蓝牙设备地址时,通过这个函数更新当前要操作的地址。\r
+ */\r
+ void BluetoothOptionsView::SetCurrentAddr(bd_addr_t addr)\r
+ {\r
+ (void)memcpy_s(currentAddr.addr, BD_ADDR_LEN,\r
+ addr.addr, BD_ADDR_LEN); // 源和目标内存长度一样,不做返回值判断\r
+ }\r
\r
-bd_addr_t BluetoothOptionsView::GetCurrentAddr(void)\r
-{\r
- return currentAddr;\r
-}\r
+ /*\r
+ * @brief 返回当前保存的蓝牙设备地址。\r
+ *\r
+ * 其他函数需要获取当前正在操作的蓝牙地址时,会调用这个函数来获取。\r
+ */\r
+ bd_addr_t BluetoothOptionsView::GetCurrentAddr(void)\r
+ {\r
+ return currentAddr;\r
+ }\r
}
\ No newline at end of file