查看已连接的蓝牙耳机视图UI修改
authorluozheng <1732036298@qq.com>
Thu, 15 Aug 2024 06:27:31 +0000 (14:27 +0800)
committerluozheng <1732036298@qq.com>
Thu, 15 Aug 2024 06:27:31 +0000 (14:27 +0800)
code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothItemView.h
code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModel.h
code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothOptionsView.h
code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothPresenter.h
code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothModel.cpp
code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothOptionsView.cpp
code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/MainBluetoothView.cpp
code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/TipsFailMessageView.cpp
code/sdk/application/wearable/fd230app/nativeui/player/src/PlayersPresenter.cpp

index 602897b..bfddc3f 100644 (file)
@@ -1,10 +1,12 @@
 /*\r
- * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved.\r
- * Description: BluetoothItem view\r
- * Author:\r
- * Create: 2021-10-13\r
+ * @Author: luozheng 1732036298@qq.com\r
+ * @Date: 2024-08-05 15:20:01\r
+ * @LastEditors: luozheng 1732036298@qq.com\r
+ * @LastEditTime: 2024-08-15 14:19:01\r
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothItemView.h\r
  */\r
 \r
+\r
 #ifndef BLUETOOTH_ITEM_VIEW_H\r
 #define BLUETOOTH_ITEM_VIEW_H\r
 \r
@@ -35,9 +37,9 @@ private:
     ImageAnimatorInfo connectImageInfo[BLUETOOTH_CONNECT_IMAGE_NUM];\r
     UIImageView image;\r
     UIButton button;\r
-    UILabel connectStateLabel;\r
+    UILabel connectStateLabel;/*连接状态标签*/\r
     UILabel namelabel;\r
-    UIImageAnimatorView connectionAnimator;\r
+    UIImageAnimatorView connectionAnimator; /*连接动画*/\r
     BluetoothCaseInfo itemInfo_{};\r
     void BtConnectImageAnimator();\r
 };\r
index 1857e05..86ba575 100644 (file)
@@ -24,10 +24,11 @@ typedef enum : uint16_t {
     CALLERPLAYERS,\r
 } CallerFactor;\r
 \r
+/*整合和存储与蓝牙设备相关的各种信息*/\r
 typedef struct {\r
     unsigned char deviceName[BD_NAME_LEN]; /* Name of the device record, must be in UTF-8 */\r
-    unsigned char addr[BD_ADDR_LEN];\r
-    int16_t index;\r
+    unsigned char addr[BD_ADDR_LEN]; /*存储蓝牙设备的地址*/\r
+    int16_t index;/*用于表示设备在某个特定列表或数据结构中的索引位置。*/\r
     int16_t connIndex;\r
     int16_t temp;\r
 } BluetoothCaseInfo;\r
@@ -94,8 +95,8 @@ private:
     void SetUpListCase();\r
     void SetUpConnedDevicesList();\r
     bool FindNameByAddr(BluetoothCaseInfo &listInfo, BluetoothCaseInfo *caseInfo);\r
-    bool aclConnected{false};\r
-    BluetoothCaseInfo tempMacValue{};\r
+    bool aclConnected{false};/*ACL(Asynchronous Connectionless,异步无连接)连接状态*/\r
+    BluetoothCaseInfo tempMacValue{};/*临时蓝牙设备地址*/\r
     bd_addr_t lastConnedAddr{};\r
     bd_addr_t remoteConnectAddr{0};\r
     BluetoothItemView *selectItemView{nullptr};\r
index 7a6d174..2f52947 100644 (file)
@@ -1,8 +1,10 @@
 /*\r
- * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved.\r
- * Description: BluetoothOptions view\r
- * Author:\r
- * Create: 2021-10-13\r
+ * @Author: luozheng 1732036298@qq.com\r
+ * @Date: 2024-08-05 15:20:01\r
+ * @LastEditors: luozheng 1732036298@qq.com\r
+ * @LastEditTime: 2024-08-15 10:18:02\r
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothOptionsView.h\r
+ * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE\r
  */\r
 #ifndef BLUETOOTH_OPTIONS_VIEW_H\r
 #define BLUETOOTH_OPTIONS_VIEW_H\r
 #include "components/ui_view_group.h"\r
 #include "components/ui_label.h"\r
 #include "components/ui_label_ext.h"\r
-#include "components/ui_label_button.h"\r
+#include "components/ui_label_button_ext.h"\r
 #include "components/ui_image_animator.h"\r
 #include "BluetoothCaseListAdapter.h"\r
 \r
-namespace OHOS {\r
-class BluetoothOptionsView {\r
-public:\r
-    BluetoothOptionsView();\r
-    ~BluetoothOptionsView();\r
-    static BluetoothOptionsView *GetInstance();\r
-    UIViewGroup *InitShowUpView(void);\r
-    UILabelButton *GetOptionsOneButton(void);\r
-    UILabelButton *GetUnpairButton(void);\r
-    void SetUnpair(void);\r
-    void SetBtconnect(void);\r
-    void SetBtDisconnect(void);\r
-    void SetCurrentAddr(bd_addr_t addr);\r
-    bd_addr_t GetCurrentAddr(void);\r
-    void RefreshText(void);\r
-private:\r
-    void InItTitleLabel(void);\r
-    void InItLabelButton(void);\r
-    UILabelButton *optionsOneButton{nullptr};\r
-    UILabelButton *unpairButton{nullptr};\r
-    UILabel *titleLabel{nullptr};\r
-    UILabel *connectStateLabel{nullptr};\r
-    UIViewGroup *group{nullptr};\r
-    bd_addr_t currentAddr;\r
-};\r
+namespace OHOS\r
+{\r
+    // 已连接的蓝牙耳机设备视图\r
+    class BluetoothOptionsView\r
+    {\r
+    public:\r
+        BluetoothOptionsView();\r
+        ~BluetoothOptionsView();\r
+        static BluetoothOptionsView *GetInstance();\r
+        UIViewGroup *CreateBluetoothOptionsView(void);\r
+        UILabelButtonExt *GetOptionsOneButton(void);\r
+        UILabelButtonExt *GetUnpairButton(void);\r
+        void SetUnpair(void);\r
+        void SetBtconnect(void);\r
+        void SetBtDisconnect(void);\r
+        void SetCurrentAddr(bd_addr_t addr);\r
+        bd_addr_t GetCurrentAddr(void);\r
+        void RefreshText(void);\r
+\r
+    private:\r
+        bool CreateBluetoothOptionsLabelView(void);\r
+        bool CreateBluetoothOptionsLabelButton(void);\r
+        bool CreateBluetoothOptionsImageView(void);\r
+\r
+        void InItTitleLabel(void);\r
+        void InItLabelButton(void);\r
+        UIViewGroup *group{nullptr};\r
+        UILabelExt *titleLabel{nullptr};          /*标题:蓝牙耳机*/\r
+        UIImageView *btHeadsetIconUmage{nullptr}; // 绿色耳机图标\r
+        UILabelExt *EarPhoneDeviceName{nullptr};  // 蓝牙耳机设备名\r
+        UILabelExt *pairState{nullptr};           // 已配对或者未配对\r
+        UILabelButtonExt *unpairButton{nullptr};     // 取消配对按钮\r
+        bd_addr_t currentAddr;\r
+\r
+        /*下面两个组件暂时设为不可见待到需要时使用*/\r
+        UILabelButtonExt *optionsOneButton{nullptr}; /*重新连接和断开连接按钮*/\r
+        UILabel *connectStateLabel{nullptr};      /*已连接或未连接标签*/\r
+        };\r
 } // namespace OHOS\r
 #endif // BLUETOOTH_OPTIONS_VIEW_H
\ No newline at end of file
index 05f0502..c4ef734 100644 (file)
@@ -25,8 +25,8 @@ enum BluetoothPresenterNum : uint8_t {
         BLUETOOTHEARPHONEVIEW = 0,\r
         BLUETOOTHEARLISTVIEW,\r
         BLUETOOTHDEVICELISTVIEW,\r
-        BLUETOOTHEOPTIONSVIEW,\r
-        BLUETOOTHRECONNECTVIEW,\r
+        BLUETOOTHEOPTIONSVIEW,/*已连接的蓝牙耳机设备视图*/\r
+        BLUETOOTHRECONNECTVIEW,/*蓝牙重新连接视图*/\r
         TIPSSUCCMESSAGEVIEW,\r
         TIPSCONNFAILMESSAGEVIEW,\r
         TIPSFAILMESSAGEVIEW,\r
index 9981e57..325e748 100644 (file)
@@ -415,6 +415,11 @@ List<BluetoothCaseInfo>& BluetoothModel::GetConnedDevicesCase()
     return *btConnedDevicesList_;\r
 }\r
 \r
+/*\r
+* @brief 用于检查特定蓝牙设备(其地址存储在 tempMacValue 中)是否处于 ACL 连接状态。\r
+*\r
+*eg:如果是在控制与手机配对的蓝牙手环,通过这个函数就能确定手环当前与手机的连接情况。\r
+*/\r
 void BluetoothModel::SetBtStatus(void)\r
 {\r
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetBtStatus tempMacValue: %02x%02x%02x%02x%02x%02x",\r
index a2c3671..050556d 100644 (file)
  * 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(&currentAddr);\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(&currentAddr);\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(&currentAddr);\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(&currentAddr);\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
index 18b5bae..878c2e2 100644 (file)
@@ -136,6 +136,7 @@ void BluetoothPresenter::ClickUnpairButton(void)
     view_->ChangeView(BLUETOOTHEOPTIONSVIEW, BLUETOOTHDEVICELISTVIEW);\r
 }\r
 \r
+/*已连接的蓝牙耳机设备视图中【重新连接或断开连接】按钮*/\r
 void BluetoothPresenter::ClickOptionsOneButton(void)\r
 {\r
     WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_OPTIONONE_BUTTON");\r
@@ -147,7 +148,7 @@ void BluetoothPresenter::ClickOptionsOneButton(void)
     bluetoothMode_->SetBtStatus();\r
     if (bluetoothMode_->GetAclConnected()) {\r
         bluetoothMode_->SetTagConnectNew(false);\r
-        bluetoothOptionsView->SetBtDisconnect();\r
+        bluetoothOptionsView->SetBtDisconnect();/*断开与该远程设备的连接*/\r
         view_->ChangeView(BLUETOOTHEOPTIONSVIEW, BLUETOOTHDEVICELISTVIEW);\r
     } else {\r
         bluetoothMode_->SetTagReconnectJump(true);\r
@@ -224,7 +225,7 @@ bool BluetoothPresenter::OnKeyAct(UIView &view, const KeyEvent &event)
     uint16 keyID = event.GetKeyId();\r
     uint16 keyState = event.GetState();\r
     // 如果是power键就返回上一级\r
-    if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)\r
+    if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0)\r
     {\r
         NativeAbility::GetInstance().Back();\r
     }\r
index 3c641a1..27846c3 100644 (file)
@@ -281,7 +281,7 @@ bool MainBluetoothView::ChangeBluetoothOptionsView(int16_t hideView, int16_t thi
             return false;\r
         }\r
         // init view\r
-        UIViewGroup *group = bluetoothOptionsView->InitShowUpView();\r
+        UIViewGroup *group = bluetoothOptionsView->CreateBluetoothOptionsView();\r
         if (group == nullptr) {\r
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail");\r
             return false;\r
index 56222c9..49982ff 100644 (file)
@@ -119,7 +119,7 @@ namespace OHOS
             btIconImage->SetResizeMode(UIImageView::CENTER);\r
             if (!PlayersView::LoadPlayerImage(btIconImage, PLAYER_BLUETOOTH_GRAY))\r
             {\r
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "phoneImage LoadPlayerImage fail");\r
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "btIconImage LoadPlayerImage fail");\r
                 return false;\r
             }\r
         }\r
index 32fbe75..2190639 100644 (file)
@@ -185,7 +185,7 @@ bool JumpView::ChangeBluetoothOptionsView(int16_t hideView, int16_t thisView)
             return false;\r
         }\r
         // init view\r
-        UIViewGroup *group = bluetoothOptionsView->InitShowUpView();\r
+        UIViewGroup *group = bluetoothOptionsView->CreateBluetoothOptionsView();\r
         if (group == nullptr) {\r
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail");\r
             return false;\r