From 771960a99e4d890c53f1a90d2761c9523631126a Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E8=A2=81=E6=B8=85=E6=A2=A6?= <3449750381@qq.com> Date: Wed, 7 May 2025 14:31:20 +0800 Subject: [PATCH] =?utf8?q?Revert=20"Revert=20"=E3=80=90=E8=93=9D=E7=89=99?= =?utf8?q?=E3=80=91UI=20""?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../include/BluetoothCaseListAdapter.h | 1 + .../include/BluetoothDeviceCaseListAdapter.h | 1 + .../include/BluetoothDeviceListView.h | 26 +- .../bluetooth/include/BluetoothEarListView.h | 12 +- .../bluetooth/include/BluetoothEarPhoneView.h | 14 +- .../bluetooth/include/BluetoothHeadsetEvent.h | 7 + .../bluetooth/include/BluetoothItemView.h | 22 +- .../bluetooth/include/BluetoothModel.h | 58 +- .../bluetooth/include/BluetoothModelC.h | 42 + .../bluetooth/include/BluetoothOptionsView.h | 77 +- .../bluetooth/include/BluetoothPresenter.h | 37 +- .../include/BluetoothReconnectView.h | 12 +- .../bluetooth/include/BluetoothWrapper.h | 1 + .../bluetooth/include/Bluetooyhpabpserver.h | 25 + .../bluetooth/include/MainBluetoothView.h | 1 + .../include/TipsConnFailMessageView.h | 22 +- .../bluetooth/include/TipsFailMessageView.h | 50 +- .../bluetooth/include/TipsSuccMessageView.h | 21 +- .../src/BluetoothCaseListAdapter.cpp | 93 +- .../src/BluetoothDeviceCaseListAdapter.cpp | 306 +++-- .../bluetooth/src/BluetoothDeviceListView.cpp | 380 ++++--- .../bluetooth/src/BluetoothEarListView.cpp | 409 ++++--- .../bluetooth/src/BluetoothEarPhoneView.cpp | 486 ++++---- .../bluetooth/src/BluetoothHeadsetEvent.cpp | 143 ++- .../bluetooth/src/BluetoothItemView.cpp | 400 ++++--- .../nativeui/bluetooth/src/BluetoothModel.cpp | 1004 ++++++++++++++--- .../bluetooth/src/BluetoothOptionsView.cpp | 541 ++++++--- .../bluetooth/src/BluetoothPresenter.cpp | 83 +- .../bluetooth/src/BluetoothReconnectView.cpp | 198 +++- .../bluetooth/src/BluetoothWrapper.cpp | 29 +- .../bluetooth/src/Bluetooyhpabpserver.cpp | 809 +++++++++++++ .../bluetooth/src/MainBluetoothView.cpp | 136 ++- .../bluetooth/src/TipsConnFailMessageView.cpp | 432 ++++--- .../bluetooth/src/TipsFailMessageView.cpp | 284 +++-- .../bluetooth/src/TipsSuccMessageView.cpp | 335 +++--- 35 files changed, 4673 insertions(+), 1824 deletions(-) create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothModelC.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/Bluetooyhpabpserver.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/Bluetooyhpabpserver.cpp diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothCaseListAdapter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothCaseListAdapter.h index 49a590a5b..5edaa1284 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothCaseListAdapter.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothCaseListAdapter.h @@ -10,6 +10,7 @@ #include #include "components/abstract_adapter.h" #include "components/ui_label.h" +#include "components/ui_label_ext.h" #include "components/ui_label_button.h" #include "PlayersPresenter.h" #include "BluetoothItemView.h" diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothDeviceCaseListAdapter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothDeviceCaseListAdapter.h index a2b0e2371..2f8784a46 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothDeviceCaseListAdapter.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothDeviceCaseListAdapter.h @@ -10,6 +10,7 @@ #include #include "components/abstract_adapter.h" #include "components/ui_label.h" +#include "components/ui_label_ext.h" #include "components/ui_label_button.h" #include "BluetoothItemView.h" diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothDeviceListView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothDeviceListView.h index 72b9b9871..03ebbe168 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothDeviceListView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothDeviceListView.h @@ -1,39 +1,41 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: BluetoothDeviceListView 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-10-10 10:05:27 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothDeviceListView.h */ #ifndef BLUETOOTH_DEVICE_LIST_VIEW_H #define BLUETOOTH_DEVICE_LIST_VIEW_H #include "components/ui_view_group.h" -#include "components/ui_label.h" -#include "components/ui_label_button.h" +#include "components/ui_label_ext.h" +#include "components/ui_label_button_ext.h" #include "components/ui_list.h" #include "BluetoothDeviceCaseListAdapter.h" - +#include "components/ui_scroll_view.h" namespace OHOS { class BluetoothDeviceCaseListAdapter; +//已连接过的蓝牙设备列表视图 class BluetoothDeviceListView { public: BluetoothDeviceListView(); ~BluetoothDeviceListView(); static BluetoothDeviceListView *GetInstance(); - UIViewGroup *InitShowUpView(void); + UIViewGroup *CreateBluetoothDeviceListView(void); UIViewGroup *GetGroup(void); UIList *GetDeviceUIList(void); - void RefreshText(void); + void RefreshBluetoothDeviceListView(void); private: void InitList(void); void InItEmptyLabel(); void InitNewEquipmentButton(); UIViewGroup *group{nullptr}; UIList *list{nullptr}; - UILabel *titleLabel{nullptr}; - UILabel *emptyLabel{nullptr}; + UILabelExt *titleLabel{nullptr}; /*标题:蓝牙耳机*/ + UILabelExt *emptyLabel{nullptr}; /*暂无已配对设备*/ BluetoothDeviceCaseListAdapter *adapterText{nullptr}; - UILabelButton *newEquipmentButton{nullptr}; + UILabelExt *newEquipmentButton{nullptr}; }; } // namespace OHOS #endif // BLUETOOTH_DEVICE_LIST_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothEarListView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothEarListView.h index 8a0dd9839..8106fc80e 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothEarListView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothEarListView.h @@ -9,7 +9,8 @@ #include "components/ui_view_group.h" #include "components/ui_label.h" -#include "components/ui_label_button.h" +#include "components/ui_label_ext.h" +#include "components/ui_label_button_ext.h" #include "components/ui_image_animator.h" #include "components/ui_list.h" #include "BluetoothCaseListAdapter.h" @@ -29,15 +30,18 @@ public: void SetNewEquipmentButtonRemove(void); void SetCancelConnedRequestButtonAdd(void); void SetCancelConnedRequestButtonRemove(void); + void RefreshBluetoothEarListView(void); + private: void InitList(void); void InitButten(UILabelButton **button, const char *text, const char* id); + void InitNewEquipmentButton(); UIViewGroup *group{nullptr}; UIList *list{nullptr}; - UILabel *titleLabel{nullptr}; + UILabelExt *titleLabel{nullptr}; BluetoothCaseListAdapter *adapterText{nullptr}; - UILabelButton *rescanButton{nullptr}; - UILabelButton *cancelConnedRequestButton{nullptr}; + UILabelExt *rescanButton{nullptr}; + UILabelButtonExt *cancelConnedRequestButton{nullptr}; }; } // namespace OHOS #endif // BLUETOOTH_EAR_LIST_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothEarPhoneView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothEarPhoneView.h index 3636a1af1..4af2a23f0 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothEarPhoneView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothEarPhoneView.h @@ -10,14 +10,15 @@ #include #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_image_animator.h" -#include "ohos_timer.h" -#include "graphic_timer.h" +#include "cmsis_os.h" #include "BluetoothModel.h" #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(); }; @@ -42,9 +44,9 @@ private: #ifdef __cplusplus extern "C" { #endif -void ScanTimerCallback(int data); -void CancelBrScanHandle(void); -void EndScanHandle(void); +// void ScanTimerCallback(int data); +// void CancelBrScanHandle(void); +// void EndScanHandle(void); #ifdef __cplusplus } #endif diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothHeadsetEvent.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothHeadsetEvent.h index 8e5341d74..43340472e 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothHeadsetEvent.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothHeadsetEvent.h @@ -31,12 +31,19 @@ typedef struct { profile_connect_state_t avrcp_srv_conn_stat; } BtAvrcpTgInf; +extern BtAvrcpTgInf g_avrcp_srv_inf; + +bd_addr_t *BtAvrcpSrvGetActiveAddr(void); + void UsingPressButtonStatusCallback(td_u32 keyOperation, td_u32 keyValue); void MediaStatusCallback(bt_avrcp_tg_evt_status_param *eventStatusParam); void PressButtonStatusCallback(td_u32 keyOperation, td_u32 keyValue); void ConnCtStateChangedCallback(const bd_addr_t *bdAddr, profile_connect_state_t state); void ConnectTgStateChangedCallback(const bd_addr_t *bdAddr, profile_connect_state_t state); void InitBtHeadsetEvent(void); +void BtAvrcpVolumeChangedSyncMedia(uint8_t a2dp_volume); +void user_avrcp_ct_press_button(const bd_addr_t *bd_addr, int32_t key_operation); +void user_avrcp_ct_get_element_attributes(const bd_addr_t *bd_addr); #ifdef __cplusplus } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothItemView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothItemView.h index 563fe825d..9ff78ba6d 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothItemView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothItemView.h @@ -1,14 +1,17 @@ /* - * 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-09-04 14:23:09 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothItemView.h */ + #ifndef BLUETOOTH_ITEM_VIEW_H #define BLUETOOTH_ITEM_VIEW_H #include "components/ui_label.h" +#include "components/ui_label_ext.h" #include "components/ui_view_group.h" #include "components/ui_image_view.h" #include "components/ui_label_button.h" @@ -26,17 +29,20 @@ public: void SetItemInfo(const BluetoothCaseInfo& itemInfo, bool isCaseList); BluetoothCaseInfo *GetItemInfo(void); void SetConnectionstatus(const BluetoothCaseInfo& infoData); + void SetPairingtatus(); + void SetViewOnClickListener(UIView::OnClickListener *listener); void SetUpChild(); void ConnectAnimatorStart(void); void ConnectAnimatorStop(void); bool IsConnectAnimator(void); private: ImageAnimatorInfo connectImageInfo[BLUETOOTH_CONNECT_IMAGE_NUM]; - UIImageView image; UIButton button; - UILabel connectStateLabel; - UILabel namelabel; - UIImageAnimatorView connectionAnimator; + UILabelExt connectStateLabel;/*连接状态标签*/ + UILabel namelabel;/*设备名*/ + UIImageView lineImage; + UIImageView noteImage; + UIImageAnimatorView connectionAnimator; /*连接动画*/ BluetoothCaseInfo itemInfo_{}; void BtConnectImageAnimator(); }; diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothModel.h index 3aef02c0e..161129070 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothModel.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothModel.h @@ -5,8 +5,8 @@ * Create: 2021-10-13 */ -#ifndef BLUETOOTH_MODEL_H -#define BLUETOOTH_MODEL_H +#ifndef BLUETOOTH_MODEL_H_ +#define BLUETOOTH_MODEL_H_ #include #include @@ -14,21 +14,37 @@ #include "bts_def.h" #include "bts_br_gap.h" - +#include namespace OHOS { + + + typedef enum : uint16_t { CALLERSETTING, 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; + +typedef struct { + uint8_t id; + uint32_t timetamp_begin; + uint32_t timetamp_end; + std::string titel; + std::string content; +}ScheduleInfo; + + + + class BluetoothItemView; class BluetoothModel { public: @@ -37,7 +53,6 @@ public: void Init(); int GetBluetoothCalleridStatus(void); void SetBluetoothCalleridStatus(int16_t value); - // ɨÃèÉ豸¶ÓÁгõʼ»¯ std::list& GetCase(); void AddCase(BluetoothCaseInfo caseInfo); void SetScansCaseRssi(const bd_addr_t *bdAddr, int rssi); @@ -81,6 +96,7 @@ public: int ConnectRemoteDevice(const bd_addr_t *addr); bool ConnectRemoteCheck(const bd_addr_t *addr); char* getWatchName(void); + void set_test_bt_falg(bool falg); private: BluetoothModel(); @@ -88,14 +104,13 @@ private: void SetUpListCase(); void SetUpConnedDevicesList(); bool FindNameByAddr(BluetoothCaseInfo &listInfo, BluetoothCaseInfo *caseInfo); - void InitBluetoothInfo(void); - bool aclConnected{false}; - BluetoothCaseInfo tempMacValue{}; - bd_addr_t lastConnedAddr{0}; + bool aclConnected{false};/*ACL(Asynchronous Connectionless,异步无连接)连接状态*/ + BluetoothCaseInfo tempMacValue{};/*临时蓝牙设备地址*/ + bd_addr_t lastConnedAddr{}; bd_addr_t remoteConnectAddr{0}; BluetoothItemView *selectItemView{nullptr}; - std::list btScansDevicesList_{}; - List *btConnedDevicesList_{nullptr}; + std::list btScansDevicesList_{}; //蓝牙扫描设备列表 + List *btConnedDevicesList_{nullptr}; //已连接设备列表 bool tagReconnectJump{0}; int16_t curView{0}; bool tagConnectView{true}; @@ -119,9 +134,28 @@ void BtRemoteNameChangedCallback(const bd_addr_t *bdAddr, const unsigned char *d void BtIsAcceptConnOnSafeModeCallback(const bd_addr_t *bd_addr, bool *res); void BtInitCallBacks(void); void BtInitCallBacksEx(void); +void BtA2dpInit(void); void BtInitGatts(void); void BtInitSpp(void); void BleAdvStart(void); +void bluetooth_init(void); +void InitBluetoothInfo(void); +void bluetooth_enable_all(void); +void bluetooth_close_all(void); +void bluetooth_set_auto_reconnect_closed(uint8_t flag); + +int uapi_a2dp_snk_get_device_connect_state(void); +int uapi_a2dp_snk_connect(void); +int uapi_a2dp_snk_disconnect(void); +int uapi_disconnect_remote_device(void); +int uapi_get_acl_connect_state(void); +int uapi_set_acl_connect_hfp(void); +void uapi_connect_pbap_pce(void); +int uapi_reconnect(void); +int uapi_set_acl_connect_A2DP(void); +void uapi_get_br_address(bd_addr_t *bdaddr); +void uapi_set_br_address(bd_addr_t *bdaddr); + #ifdef __cplusplus } #endif diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothModelC.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothModelC.h new file mode 100644 index 000000000..157c3002e --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothModelC.h @@ -0,0 +1,42 @@ +/* + * @Author: penglei 1624952103@qq.com + * @Date: 2024-08-23 10:50:37 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-12-02 19:24:01 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothModelC.h + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: BluetoothModel view + * Author: + * Create: 2021-10-13 + */ + +#ifndef C_BLUETOOTH_MODEL_H_ +#define C_BLUETOOTH_MODEL_H_ + + +#ifdef __cplusplus +extern "C" { +#endif + +int uapi_a2dp_snk_connect_(void); +int uapi_a2dp_snk_disconnect_(void); +int uapi_close_br_scan(void); +int uapi_open_br_scan(void); +//int uapi_disconnect_remote_device_(void); + +int32_t BtA2dpSnkAudioDestroy(void); + +int uapi_reconnect_(void); + +int get_BT_is_init(void); + +void cm_initBluetoothDeviceList(void); +#ifdef __cplusplus +} +#endif + + +#endif diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothOptionsView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothOptionsView.h index 836df4bcb..ae1157b6e 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothOptionsView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothOptionsView.h @@ -1,42 +1,59 @@ /* - * 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-10-09 19:52:58 + * @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 #include "components/ui_view_group.h" #include "components/ui_label.h" -#include "components/ui_label_button.h" +#include "components/ui_label_ext.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}; // 取消配对按钮 + UILabelExt *unpairLabel{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/fd230/nativeapp/nativeui/bluetooth/include/BluetoothPresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothPresenter.h index fa72f28f9..80289c1ec 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothPresenter.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothPresenter.h @@ -1,45 +1,55 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: BluetoothPresenter view - * Create: 2021-10-13 + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-08-05 15:20:01 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-09-28 18:06:32 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothPresenter.h */ #ifndef BLUETOOTH_PRESENTER_H #define BLUETOOTH_PRESENTER_H #include "Presenter.h" -#include "BluetoothModel.h" +#include "View.h" #include "MainBluetoothView.h" #include "components/ui_view.h" #include "components/ui_image_view.h" #include "components/ui_label_button.h" #include "components/ui_view_group.h" #include "VolumeSettingView.h" + #include "UiViewId.h" +#include "cmsis_os.h" +#include "common/key_code.h" namespace OHOS { enum BluetoothPresenterNum : uint8_t { - BLUETOOTHEARPHONEVIEW = 0, - BLUETOOTHEARLISTVIEW, - BLUETOOTHDEVICELISTVIEW, - BLUETOOTHEOPTIONSVIEW, - BLUETOOTHRECONNECTVIEW, - TIPSSUCCMESSAGEVIEW, - TIPSCONNFAILMESSAGEVIEW, - TIPSFAILMESSAGEVIEW, + BLUETOOTHEARPHONEVIEW = 0, // 搜索界面 + BLUETOOTHEARLISTVIEW, /*扫描出的耳机列表界面*/ + BLUETOOTHDEVICELISTVIEW,/*已连接过的蓝牙设备列表视图*/ + BLUETOOTHEOPTIONSVIEW, /*查看已连接过的蓝牙耳机设备视图*/ + BLUETOOTHRECONNECTVIEW,/*蓝牙重新连接视图*/ + TIPSSUCCMESSAGEVIEW,/*连接成功的提示视图*/ + TIPSCONNFAILMESSAGEVIEW,/*连接失败的提示*/ + TIPSFAILMESSAGEVIEW,/*未搜索到蓝牙耳机界面*/ BLUETOOTHEVIEW, BLUETOOTHEVIEW_MAX, }; class MainBluetoothView; -class BluetoothPresenter : public Presenter, public UIView::OnClickListener, +class BluetoothPresenter : public Presenter, public UIView::OnClickListener,public RootView::OnKeyActListener, public UIView::OnDragListener { public: BluetoothPresenter(); ~BluetoothPresenter(); bool OnClick(UIView &view, const ClickEvent &event) override; static BluetoothPresenter *GetInstance(); + bool OnDrag(UIView& view, const DragEvent& event) override; bool OnDragEnd(UIView& view, const DragEvent& event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; + void OnStart() override; + void OnPause() override; + void OnResume() override; void OnStop() override; void ClickRescanButton(void); void ClickNewEquipmentButton(void); @@ -51,6 +61,7 @@ public: void ClickConnfailBackButton(void); private: BluetoothModel *bluetoothMode_{nullptr}; + bool X_DRAG_FLAG{false}; }; } // namespace OHOS #endif diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothReconnectView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothReconnectView.h index a65be7016..e9683eba3 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothReconnectView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothReconnectView.h @@ -9,11 +9,12 @@ #include "components/ui_label.h" +#include "components/ui_label_ext.h" #include "components/ui_image_animator.h" #include "components/abstract_adapter.h" #include "components/ui_view_group.h" #include "bts_def.h" -#define BLUETOOTH_RECONNECT_IMAGE_NUM 8 +#define BLUETOOTH_RECONNECT_IMAGE_NUM 60 namespace OHOS { class BluetoothReconnectView { @@ -27,14 +28,19 @@ public: bd_addr_t GetcurrentBdAddr(void); void RefreshBluetoothNameLabel(); private: - ImageAnimatorInfo reconnetImageInfo[BLUETOOTH_RECONNECT_IMAGE_NUM]; + // ImageAnimatorInfo reconnetImageInfo[BLUETOOTH_RECONNECT_IMAGE_NUM]; void ShowUpTitleLabel(void); + void start_connect_timer(); + void stop_connect_timer(); UILabel *titleLabel{nullptr}; UILabel *bluetoothNameLabel{nullptr}; - UIImageAnimatorView *reconnectAnimator{nullptr}; + // UIImageAnimatorView *reconnectAnimator{nullptr}; UIViewGroup *group{nullptr}; bd_addr_t currentBdAddr; void BtReconnectImageAnimator(); + UIImageAnimatorView *reconnectAnimator{nullptr}; + const ImageInfo **reconnectPathsArray{nullptr}; + ImageAnimatorInfo reconnetImageInfo[BLUETOOTH_RECONNECT_IMAGE_NUM]; }; } // namespace OHOS #endif // BLUETOOTH_RECONNECT_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothWrapper.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothWrapper.h index 3c645feb1..94c990a6c 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothWrapper.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/BluetoothWrapper.h @@ -23,6 +23,7 @@ void wrapper_ble_register(void); errcode_t wrapper_gatts_register_server(bt_uuid_t *app_uuid, uint8_t *server_id); errcode_t wrapper_gatts_add_service(uint8_t server_id, bt_uuid_t *service_uuid, bool is_primary); void wrapper_gatts_service_start(void); +void wrapper_gatts_clear_service(void); #ifdef __cplusplus } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/Bluetooyhpabpserver.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/Bluetooyhpabpserver.h new file mode 100644 index 000000000..124f0cbe9 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/Bluetooyhpabpserver.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2022. All rights reserved. + * Description: This module include test functions of PBAP service. + */ +#ifndef PBAP_SERVICE_H +#define PBAP_SERVICE_H +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif +//void bt_pbap_service_sample_cmd(uint32_t cmd_id, const char **params, int32_t params_cnt); +void uapi_pbap_pce_reg_callback(void); +void uapi_pbap_cmd_start_client(void); + +void uapi_pbap_cmd_pull_phonebook(void); +void uapi_pbap_cmd_pull_vcard_listing(unsigned char *tell,uint8_t len); +void uapi_pbap_cmd_pull_vcard_entry(td_char *vcf_name); + + +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/MainBluetoothView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/MainBluetoothView.h index e564e2ced..e899d0813 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/MainBluetoothView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/MainBluetoothView.h @@ -34,6 +34,7 @@ public: ~MainBluetoothView() override; void OnStart() override; + void DropView(UIView& view); void ChangeView(int16_t hideView, int16_t showView); static MainBluetoothView *GetInstance(void); diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/TipsConnFailMessageView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/TipsConnFailMessageView.h index d0bcc4b06..ed015a08b 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/TipsConnFailMessageView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/TipsConnFailMessageView.h @@ -1,19 +1,23 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: TipsConnFailMessageView 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-09-05 16:13:55 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/TipsConnFailMessageView.h */ + #ifndef TIPS_CONN_FAIL_MESSAGE_VIEW_H #define TIPS_CONN_FAIL_MESSAGE_VIEW_H #include "components/ui_view_group.h" #include "components/ui_label.h" -#include "components/ui_label_button.h" +#include "components/ui_label_ext.h" +#include "components/ui_label_button_ext.h" #include "components/ui_image_view.h" #include "bts_def.h" namespace OHOS { +/*连接失败视图*/ class TipsConnFailMessageView { public: TipsConnFailMessageView(); @@ -25,11 +29,11 @@ private: void ShowUpButtonBack(void); void ShowUpTipLabel(void); void InitNameLabel(void); - UILabel *titleLabel{nullptr}; - UILabel *tipLabel{nullptr}; - UILabel *tipTwoLabel{nullptr}; + UILabelExt *titleLabel{nullptr}; + UILabelExt *conn_fail_Label{nullptr}; + UILabelExt *tipLabel{nullptr}; UILabel *bluetoothNameLabel{nullptr}; - UILabelButton *backButton{nullptr}; + UILabelButtonExt *backButton{nullptr}; UIImageView *tipImg{nullptr}; UIViewGroup *group{nullptr}; }; diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/TipsFailMessageView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/TipsFailMessageView.h index 3420d3e5f..fe11194a3 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/TipsFailMessageView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/TipsFailMessageView.h @@ -1,30 +1,42 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: TipsFailMessageView 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-10-10 10:19:05 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/TipsFailMessageView.h */ + #ifndef TIPS_FAIL_MESSAGE_VIEW_H #define TIPS_FAIL_MESSAGE_VIEW_H #include "components/ui_view_group.h" #include "components/ui_label.h" -#include "components/ui_label_button.h" +#include "components/ui_label_ext.h" +#include "components/ui_label_button_ext.h" #include "components/ui_image_view.h" -namespace OHOS { -class TipsFailMessageView { -public: - TipsFailMessageView(); - ~TipsFailMessageView(); - static TipsFailMessageView *GetInstance(); - UIViewGroup *ShowUpViewInit(void); -private: - int ShowUpButtonBack(void); - UILabel *titleLabel{nullptr}; - UILabelButton *backButton{nullptr}; - UIImageView *tipImg{nullptr}; - UIViewGroup *group{nullptr}; -}; +namespace OHOS +{ + /*蓝牙设备搜索不到视图*/ + class TipsFailMessageView + { + public: + TipsFailMessageView(); + ~TipsFailMessageView(); + static TipsFailMessageView *GetInstance(); + UIViewGroup *CreateTipsFailMessageView(void); + + private: + bool CreateTipsFailMessageLabelView(void); + bool CreateTipsFailMessageLabelButton(void); + bool CreateTipsFailMessageImageView(void); + + int ShowUpButtonBack(void); + UIViewGroup *group{nullptr}; + UILabelExt *titleLabel{nullptr}; /*标题:蓝牙耳机 */ + UIImageView *btIconImage{nullptr}; /*灰色的蓝牙图标*/ + UILabelExt *btHeadsetNotFoundLabel{nullptr}; /*当前搜索不到耳机蓝牙设备*/ + UILabelExt *rescanButton{nullptr}; /*重新搜索按钮*/ + }; } // namespace OHOS #endif // TIPS_FAIL_MESSAGE_VIEW_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/TipsSuccMessageView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/TipsSuccMessageView.h index 09ed3f255..7d0e64433 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/TipsSuccMessageView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/include/TipsSuccMessageView.h @@ -1,15 +1,17 @@ /* - * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. - * Description: TipsSuccMessage 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-09-05 11:13:11 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/TipsSuccMessageView.h */ #ifndef TIPS_SUCC_MESSAGE_VIEW_H #define TIPS_SUCC_MESSAGE_VIEW_H #include "components/ui_view_group.h" #include "components/ui_label.h" -#include "components/ui_label_button.h" +#include "components/ui_label_ext.h" +#include "components/ui_label_button_ext.h" #include "components/ui_image_view.h" #include "bts_def.h" @@ -22,11 +24,10 @@ public: UIViewGroup *ShowUpViewInit(void); void RefreshNameLabel(const bd_addr_t &bdAddr); private: - void ShowUpButtonBack(void); - void InitNameLabel(void); - UILabel *titleLabel{nullptr}; - UILabel *bluetoothNameLabel{nullptr}; - UILabelButton *backButton{nullptr}; + UILabelExt *titleLabel{nullptr}; + UILabelExt *bluetoothNameLabel{nullptr}; + UILabelExt *conn_succ_Label{nullptr}; + UILabelButtonExt *backButton{nullptr}; UIImageView *tipImg{nullptr}; UIViewGroup *group{nullptr}; }; diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothCaseListAdapter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothCaseListAdapter.cpp index 763f631ce..b5acb85a3 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothCaseListAdapter.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothCaseListAdapter.cpp @@ -12,6 +12,10 @@ #include "wearable_log.h" #include "UiConfig.h" #include "BluetoothModel.h" +#include "bluetooth/include/MainBluetoothView.h" +#include "CallerLogModel.h" +#include "custom_utils.h" +#include "notification_manager.h" namespace OHOS { BluetoothCaseListAdapter::~BluetoothCaseListAdapter() @@ -41,15 +45,15 @@ public: } bool OnClick(UIView& view, const ClickEvent& event) override { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothOnClickListListener"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothOnClickListListener"); UNUSED(event); BluetoothItemView *itemView = static_cast(&view); - // 二次点击不做响应 - bool ret = itemView->IsConnectAnimator(); - if (ret) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Block secondary clicks"); - return true; - } + // // 二次点击不做响应 + // bool ret = itemView->IsConnectAnimator(); + // if (ret) { + // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Block secondary clicks"); + // return true; + // } BluetoothCaseInfo *bluetoothInfo_ = itemView->GetItemInfo(); /* 点击事件 */ BluetoothModel::GetInstance()->SetTempMacValue(bluetoothInfo_); @@ -62,37 +66,55 @@ public: WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView bluetoothEarPhoneView == nullptr"); return false; } - bluetoothEarPhoneView->BtAnimatorStop(); - bluetoothEarPhoneView->StopBtDiscovery(); + bluetoothEarPhoneView->BtAnimatorStop();//搜索动画停止 + bluetoothEarPhoneView->StopBtDiscovery();//停止扫描 BluetoothModel::GetInstance()->SetTagScanDeviceClicked(true); - - // 刷新列表 - BluetoothEarListView *bluetoothEarListView = BluetoothEarListView::GetInstance(); - if (bluetoothEarListView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClickCancelConnedRequestButton bluetoothEarListView nullptr"); - return false; - } - if (bluetoothEarListView->GetScanUIList() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClickCancelConnedRequestButton GetScanUIList nullptr"); + MainBluetoothView *mainBluetoothView = MainBluetoothView::GetInstance(); + if (mainBluetoothView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceOnClick mainBluetoothView GetInstance fail"); return false; } - bluetoothEarListView->GetScanUIList()->RefreshList(); - bluetoothEarListView->SetNewEquipmentButtonRemove(); - bluetoothEarListView->SetCancelConnedRequestButtonAdd(); - RootView::GetInstance()->Invalidate(); + + // // 刷新列表 + // BluetoothEarListView *bluetoothEarListView = BluetoothEarListView::GetInstance(); + // if (bluetoothEarListView == nullptr) { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClickCancelConnedRequestButton bluetoothEarListView nullptr"); + // return false; + // } + // if (bluetoothEarListView->GetScanUIList() == nullptr) { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClickCancelConnedRequestButton GetScanUIList nullptr"); + // return false; + // } + // bluetoothEarListView->GetScanUIList()->RefreshList(); + // // bluetoothEarListView->SetNewEquipmentButtonRemove(); + // // bluetoothEarListView->SetCancelConnedRequestButtonAdd(); + // RootView::GetInstance()->Invalidate(); // 判断是否正在连接 - if (BluetoothModel::GetInstance()->GetBluetoothAclState()) { - bd_addr_t *lastAddr = BluetoothModel::GetInstance()->GetLastConnedAddr(); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "LastDevice addr: %02x%02x%02x%02x%02x%02x is connected", - lastAddr->addr[5], lastAddr->addr[4], lastAddr->addr[3], - lastAddr->addr[2], lastAddr->addr[1], lastAddr->addr[0]); - BluetoothModel::GetInstance()->SetTagConnectNew(true); - errcode_t retVal = gap_disconnect_remote_device(lastAddr); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Disconnect LastDevice retVal = %d", retVal); + bd_addr_t *lastAddr = BluetoothModel::GetInstance()->GetLastConnedAddr(); + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Disconnect LastDevice retVal = %02X %02X %02X * * *", + lastAddr->addr[0],lastAddr->addr[1],lastAddr->addr[2]); + + + bool ret = bt_is_acl_connected(lastAddr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Disconnect LastDevice retVal = ret %d %02X %02X %02X * * *", + ret, lastAddr->addr[0],lastAddr->addr[1],lastAddr->addr[2]); + + + if (!( lastAddr->addr[0] == 0 && lastAddr->addr[1] == 0 && lastAddr->addr[2] == 0 + && lastAddr->addr[3] == 0 && lastAddr->addr[4] == 0 && lastAddr->addr[5] == 0 ) && ret) { + BluetoothModel::GetInstance()->SetTagConnectNew(true); + errcode_t retVal = gap_disconnect_remote_device(lastAddr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Disconnect LastDevice retVal = %d %02X %02X %02X * * *", retVal, + lastAddr->addr[0],lastAddr->addr[1],lastAddr->addr[2]); + } + else + { + mainBluetoothView->ChangeView(BluetoothModel::GetInstance()->GetCurView(), BLUETOOTHRECONNECTVIEW); + errcode_t retVal = BluetoothModel::GetInstance()->ConnectRemoteDevice(&addr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ConnectRemoteDevice ret = %d", retVal); } - errcode_t retVal = BluetoothModel::GetInstance()->ConnectRemoteDevice(&addr); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ConnectRemoteDevice ret = %d", retVal); // 跳转可选页 return true; } @@ -129,7 +151,7 @@ UIView *BluetoothCaseListAdapter::GetView(UIView *inView, int16_t index) return nullptr; } if ((static_cast(index) > bluetoothCaseList.size() - 1) || (index < 0)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothCaseListAdapter::GetView %d %d", index, bluetoothCaseList.size()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothCaseListAdapter::GetView %d %d", index, bluetoothCaseList.size()); return nullptr; } std::list::iterator node = bluetoothCaseList.begin(); @@ -156,9 +178,10 @@ UIView *BluetoothCaseListAdapter::GetView(UIView *inView, int16_t index) (void)sprintf_s(addrTmp, sizeof(addrTmp), "%02x%02x%02x%02x%02x%02x", node->addr[0], node->addr[1], node->addr[2], node->addr[3], node->addr[4], node->addr[5]); // 没有%s类型,不做返回判断 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "addrTmp %s", addrTmp); - ClickAnimation(itemData, item); - item->SetItemInfo(itemData, true); + // ClickAnimation(itemData, item); item->SetViewIndex(index); + item->SetItemInfo(itemData, true); + item->SetPairingtatus(); return item; } } // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothDeviceCaseListAdapter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothDeviceCaseListAdapter.cpp index f2950ec01..5478357ef 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothDeviceCaseListAdapter.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothDeviceCaseListAdapter.cpp @@ -12,129 +12,217 @@ #include "wearable_log.h" #include "UiConfig.h" #include "BluetoothPresenter.h" +#include "CallerLogModel.h" +#include "custom_utils.h" +#include "notification_manager.h" -namespace OHOS { -BluetoothDeviceCaseListAdapter::~BluetoothDeviceCaseListAdapter() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceCaseListAdapter::~BluetoothDeviceCaseListAdapter"); - UIView::OnClickListener *click = item->GetOnClickListener(); - if (click != nullptr) { - delete click; - click = nullptr; - } -} +#ifdef SUPPORT_PHONE_SERVICE +#include "PhoneAGService.h" +#endif -uint16_t BluetoothDeviceCaseListAdapter::GetCount() +namespace OHOS { - return BluetoothModel::GetInstance()->GetConnedDevicesCase().Size(); -} - -class BluetoothDeviceOnClickListListener : public UIView::OnClickListener { -public: - BluetoothDeviceOnClickListListener(BluetoothCaseInfo *bluetoothInfo) + class BluetoothDeviceOnClickListListener; + static BluetoothDeviceOnClickListListener *g_btOnClickListListener = nullptr; + class BluetoothDeviceOnClickListListener : public UIView::OnClickListener { - if (bluetoothInfo != nullptr) { - (void)memcpy_s(addr.addr, BD_ADDR_LEN, - bluetoothInfo->addr, BD_ADDR_LEN); // 源和目标内存长度一样,不做返回值判断 - (void)memcpy_s(bluetoothInfo_.addr, BD_ADDR_LEN, - bluetoothInfo->addr, BD_ADDR_LEN); // 源和目标内存长度一样,不做返回值判断 - (void)memcpy_s(bluetoothInfo_.deviceName, BD_NAME_LEN, - bluetoothInfo->deviceName, BD_NAME_LEN); // 源和目标内存长度一样,不做返回值判断 - bluetoothInfo_.index = bluetoothInfo->index; - bluetoothInfo_.connIndex = bluetoothInfo->connIndex; + public: + BluetoothDeviceOnClickListListener() {} + ~BluetoothDeviceOnClickListListener() {} + void SetItemInfo(const BluetoothCaseInfo *bluetoothInfo) + { + if (bluetoothInfo != nullptr) + { + (void)memcpy_s(addr.addr, BD_ADDR_LEN, + bluetoothInfo->addr, BD_ADDR_LEN); // 源和目标内存长度一样,不做返回值判断 + (void)memcpy_s(bluetoothInfo_.addr, BD_ADDR_LEN, + bluetoothInfo->addr, BD_ADDR_LEN); // 源和目标内存长度一样,不做返回值判断 + (void)memcpy_s(bluetoothInfo_.deviceName, BD_NAME_LEN, + bluetoothInfo->deviceName, BD_NAME_LEN); // 源和目标内存长度一样,不做返回值判断 + bluetoothInfo_.index = bluetoothInfo->index; + bluetoothInfo_.connIndex = bluetoothInfo->connIndex; + } } - } - ~BluetoothDeviceOnClickListListener() {} - bool OnClick(UIView& view, const ClickEvent& event) override - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceOnClickListListener"); - UNUSED(view); - UNUSED(event); - /* 点击事件 */ - // 跳转可选页 - if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { - JumpView *jumpView = JumpView::GetInstance(); - if (jumpView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceOnClick jumpView GetInstance fail"); - return false; + bool OnClick(UIView &view, const ClickEvent &event) override + { + UNUSED(event); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothOnClickListListener"); + BluetoothItemView *itemView = static_cast(view.GetParent()); + BluetoothCaseInfo *g_BluetoothCaseInfo = itemView->GetItemInfo(); + SetItemInfo(g_BluetoothCaseInfo); // 保存点击的设备信息 + BluetoothModel::GetInstance()->SetTempMacValue(&bluetoothInfo_); + if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) + { + JumpView *jumpView = JumpView::GetInstance(); + if (jumpView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceOnClick jumpView GetInstance fail"); + return false; + } + jumpView->ChangeView(JumpView::BluetoothJumpViewNum::BLUETOOTHDEVICELISTVIEW, + JumpView::BluetoothJumpViewNum::BLUETOOTHEOPTIONSVIEW); } - jumpView->ChangeView(JumpView::BluetoothJumpViewNum::BLUETOOTHDEVICELISTVIEW, - JumpView::BluetoothJumpViewNum::BLUETOOTHEOPTIONSVIEW); - } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) { - MainBluetoothView *mainBluetoothView = MainBluetoothView::GetInstance(); - if (mainBluetoothView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceOnClick mainBluetoothView GetInstance fail"); - return false; + #ifdef SUPPORT_BT_SERVICE + else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) + { + MainBluetoothView *mainBluetoothView = MainBluetoothView::GetInstance(); + if (mainBluetoothView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceOnClick mainBluetoothView GetInstance fail"); + return false; + } + if (view.GetViewType() == UIViewType::UI_BUTTON) // 点击的是按钮 + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UIViewType::UI_BUTTON,%s", reinterpret_cast(bluetoothInfo_.deviceName)); + bd_addr_t *lastAddr = BluetoothModel::GetInstance()->GetLastConnedAddr(); + bool ret = bt_is_acl_connected(lastAddr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bt_is_acl_connected:%d lastAddr:%02X %02X %02X * * *", + ret, lastAddr->addr[0], lastAddr->addr[1], lastAddr->addr[2]); + + // 地址不是全0并且ret为真 + if(OHOS::CallerLogModel::GetInstance()->GetCallSource() == OHOS::CallerLogModel::CallSourceCat1 + && OHOS::NotificationManager::GetInstance()->GetWatchCallStatus()) + { + if (!(lastAddr->addr[0] == 0 && lastAddr->addr[1] == 0 && lastAddr->addr[2] == 0 && + lastAddr->addr[3] == 0 && lastAddr->addr[4] == 0 && lastAddr->addr[5] == 0) && + ret) + { + if(headset_Is_connect()) + { + if(headset_SCO_Is_connect_extend(lastAddr)) + { + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_CAT_HFP_DIS_SCO_CONNECT, nullptr, 0); + } + else + { + uint8_t time=200; + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_CAT_HFP_SCO_CONNECT, &time, sizeof(uint8_t)); + } + } + else + { + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_CONNECT_AG, nullptr, 0); + } + + } + else + { + mainBluetoothView->ChangeView(BluetoothModel::GetInstance()->GetCurView(), BLUETOOTHRECONNECTVIEW); + errcode_t retVal = BluetoothModel::GetInstance()->ConnectRemoteDevice(&addr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ConnectRemoteDevice] retVal = %d", retVal); + } + + } + else + { + if (!(lastAddr->addr[0] == 0 && lastAddr->addr[1] == 0 && lastAddr->addr[2] == 0 && + lastAddr->addr[3] == 0 && lastAddr->addr[4] == 0 && lastAddr->addr[5] == 0) && + ret) + { + BluetoothModel::GetInstance()->SetTagConnectNew(false); //主动断开连接不需要回连该设备 + errcode_t retVal = gap_disconnect_remote_device(lastAddr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[gap_disconnect_remote_device] retVal = %d", retVal); + } + else + { + mainBluetoothView->ChangeView(BluetoothModel::GetInstance()->GetCurView(), BLUETOOTHRECONNECTVIEW); + errcode_t retVal = BluetoothModel::GetInstance()->ConnectRemoteDevice(&addr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[ConnectRemoteDevice] retVal = %d", retVal); + } + } + + } + else if (view.GetViewType() == UIViewType::UI_IMAGE_VIEW) /*点击的是图片*/ + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UIViewType::UI_IMAGE_VIEW,%s", reinterpret_cast(bluetoothInfo_.deviceName)); + mainBluetoothView->ChangeView(BluetoothModel::GetInstance()->GetCurView(), BLUETOOTHEOPTIONSVIEW); + BluetoothOptionsView *bluetoothOptionsView = BluetoothOptionsView::GetInstance(); + if (bluetoothOptionsView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick bluetoothOptionsView new fail"); + return false; + } + bluetoothOptionsView->SetCurrentAddr(addr); + bluetoothOptionsView->RefreshText(); + } } - mainBluetoothView->ChangeView(BLUETOOTHDEVICELISTVIEW, BLUETOOTHEOPTIONSVIEW); - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceOnClickListListener addr: %02x%02x%02x%02x%02x%02x", - bluetoothInfo_.addr[5], bluetoothInfo_.addr[4], bluetoothInfo_.addr[3], /* mac下标 0 1 2 3 4 5 */ - bluetoothInfo_.addr[2], bluetoothInfo_.addr[1], bluetoothInfo_.addr[0]); /* mac下标 0 1 2 3 4 5 */ - BluetoothModel::GetInstance()->SetTempMacValue(&bluetoothInfo_); - // 用于查询连接状态 - BluetoothOptionsView *bluetoothOptionsView = BluetoothOptionsView::GetInstance(); - if (bluetoothOptionsView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick bluetoothOptionsView new fail"); - return false; - } - bluetoothOptionsView->SetCurrentAddr(addr); - bluetoothOptionsView->RefreshText(); - return true; - } + #endif -private: - BluetoothCaseInfo bluetoothInfo_{}; - bd_addr_t addr; -}; + return true; + } + private: + BluetoothCaseInfo bluetoothInfo_{}; + bd_addr_t addr; + }; -UIView *BluetoothDeviceCaseListAdapter::GetView(UIView *inView, int16_t index) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceCaseListAdapter GetView"); - List &bluetoothCaseList = BluetoothModel::GetInstance()->GetConnedDevicesCase(); - if (bluetoothCaseList.IsEmpty()) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothCaseList IsEmpty"); - return nullptr; - } - if ((index > bluetoothCaseList.Size() - 1) || (index < 0)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceCaseListAdapter::GetView err"); - return nullptr; + BluetoothDeviceCaseListAdapter::~BluetoothDeviceCaseListAdapter() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceCaseListAdapter::~BluetoothDeviceCaseListAdapter"); + if (g_btOnClickListListener != nullptr) + { + delete g_btOnClickListListener; + g_btOnClickListListener = nullptr; + } } - ListNode* node = bluetoothCaseList.Begin(); - for (uint16_t i = 0; i < index; i++) { - node = node->next_; + + uint16_t BluetoothDeviceCaseListAdapter::GetCount() + { + return BluetoothModel::GetInstance()->GetConnedDevicesCase().Size(); } - node->data_.index = index; - BluetoothCaseInfo itemData = node->data_; - if (inView == nullptr) { - item = new BluetoothItemView(); - if (item == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetView item err"); + + UIView *BluetoothDeviceCaseListAdapter::GetView(UIView *inView, int16_t index) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceCaseListAdapter GetView"); + List &bluetoothCaseList = BluetoothModel::GetInstance()->GetConnedDevicesCase(); + if (bluetoothCaseList.IsEmpty()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothCaseList IsEmpty"); return nullptr; } - } else { - item = static_cast(inView); - } - item->SetItemInfo(itemData, false); - item->SetConnectionstatus(itemData); + if ((index > bluetoothCaseList.Size() - 1) || (index < 0)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceCaseListAdapter::GetView err,%d,%d", index, bluetoothCaseList.Size()); + return nullptr; + } + ListNode *node = bluetoothCaseList.Begin(); + for (uint16_t i = 0; i < index; i++) + { + node = node->next_; + } + node->data_.index = index; + BluetoothCaseInfo itemData = node->data_; + if (inView == nullptr) + { + item = new BluetoothItemView(); + if (item == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetView item err"); + return nullptr; + } + } + else + { + item = static_cast(inView); + } + item->SetViewIndex(index); + item->SetItemInfo(itemData, false); + item->SetConnectionstatus(itemData); - listener = item->GetOnClickListener(); - if (listener != nullptr) { - delete listener; - listener = nullptr; - } - listener = new BluetoothDeviceOnClickListListener(&node->data_); - if (listener == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetView BluetoothDeviceOnClickListListener err"); - return nullptr; + if (g_btOnClickListListener == nullptr) + { + g_btOnClickListListener = new BluetoothDeviceOnClickListListener(); + if (g_btOnClickListListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceCaseListAdapter::GetView new fail"); + return nullptr; + } + } + listener = static_cast(g_btOnClickListListener); + item->SetViewOnClickListener(listener); + sprintf_s(addrTmp, sizeof(addrTmp), "%02x%02x%02x%02x%02x%02x", node->data_.addr[0], node->data_.addr[1], + node->data_.addr[2], node->data_.addr[3], node->data_.addr[4], node->data_.addr[5]); // 没有%s类型,不做返回判断 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "addrTmp %s", addrTmp); + return item; } - sprintf_s(addrTmp, sizeof(addrTmp), "%02x%02x%02x%02x%02x%02x", node->data_.addr[0], node->data_.addr[1], - node->data_.addr[2], node->data_.addr[3], node->data_.addr[4], node->data_.addr[5]); // 没有%s类型,不做返回判断 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "addrTmp %s", addrTmp); - - item->SetViewIndex(index); - item->SetOnClickListener(listener); - return item; -} } // namespace OHOS \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothDeviceListView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothDeviceListView.cpp index 94ef720d7..2dd40855a 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothDeviceListView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothDeviceListView.cpp @@ -10,186 +10,252 @@ #include "PlayersPresenter.h" #include "BluetoothPresenter.h" #include "BluetoothModel.h" - -namespace OHOS { -static BluetoothDeviceListView *g_pBluetoothDeviceListView{nullptr}; - -BluetoothDeviceListView::BluetoothDeviceListView() +#include "ui_resource_string.h" +namespace OHOS { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView::BluetoothDeviceListView"); - g_pBluetoothDeviceListView = this; -} + static BluetoothDeviceListView *g_pBluetoothDeviceListView{nullptr}; -BluetoothDeviceListView::~BluetoothDeviceListView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView::~BluetoothDeviceListView"); - group->RemoveAll(); - delete titleLabel; - titleLabel = nullptr; - delete adapterText; - adapterText = nullptr; - delete emptyLabel; - emptyLabel = nullptr; - delete list; - list = nullptr; - delete newEquipmentButton; - newEquipmentButton = nullptr; - delete group; - group = nullptr; - g_pBluetoothDeviceListView = nullptr; -} - -BluetoothDeviceListView *BluetoothDeviceListView::GetInstance() -{ - return g_pBluetoothDeviceListView; -} + BluetoothDeviceListView::BluetoothDeviceListView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView::BluetoothDeviceListView"); + g_pBluetoothDeviceListView = this; + } -void BluetoothDeviceListView::InitList() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView::InitList"); - // list type - if (adapterText == nullptr) { - adapterText = new BluetoothDeviceCaseListAdapter(); - if (adapterText == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView adapterText new fail"); - return; + BluetoothDeviceListView::~BluetoothDeviceListView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView::~BluetoothDeviceListView"); + if (group) + { + group->RemoveAll(); + if (titleLabel) + { + delete titleLabel; + titleLabel = nullptr; + } + if (emptyLabel) + { + delete emptyLabel; + emptyLabel = nullptr; + } + if (adapterText) + { + delete adapterText; + adapterText = nullptr; + } + if (list) + { + delete list; + list = nullptr; + } + if (newEquipmentButton) + { + delete newEquipmentButton; + newEquipmentButton = nullptr; + } + delete group; + group = nullptr; } + g_pBluetoothDeviceListView = nullptr; } - if (list == nullptr) { - list = new UIList(UIList::VERTICAL); - if (list == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView list new fail"); - return; + + BluetoothDeviceListView *BluetoothDeviceListView::GetInstance() + { + return g_pBluetoothDeviceListView; + } + + void BluetoothDeviceListView::InitList() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView::InitList"); + if (adapterText == nullptr) + { + adapterText = new BluetoothDeviceCaseListAdapter(); + if (adapterText == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView adapterText new fail"); + return; + } } - list->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - list->SetPosition(36, 118, HORIZONTAL_RESOLUTION, 241); // 36:x 118:y 454:width 241:height - list->SetStartIndex(0); // 0 : list start index - list->SetAdapter(adapterText); - group->Add(list); + if (list == nullptr) + { + list = new UIList(UIList::VERTICAL); + if (list == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView list new fail"); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "adapterText->GetCount = %d", adapterText->GetCount()); + list->SetPosition(43, 120, 380, 100); + list->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + list->SetStyle(STYLE_BORDER_RADIUS, 50); + list->SetDragACCLevel(5); + list->SetSwipeACCLevel(200); + list->SetReboundSize(30); + // list->SetScrollBlankSize(30); + list->SetAdapter(adapterText); + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView::InitList end"); } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView::InitList end"); -} -void BluetoothDeviceListView::InItEmptyLabel() // 暂无已配对设备 -{ - if (emptyLabel == nullptr) { - emptyLabel = new UILabel(); - if (emptyLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView emptyLabel new fail"); - return; + void BluetoothDeviceListView::InItEmptyLabel() + { + if (emptyLabel == nullptr) + { + emptyLabel = new UILabelExt(); + if (emptyLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView emptyLabel new fail"); + return; + } } + emptyLabel->SetPosition(83, 205, 300, 45); + emptyLabel->SetTextId(STR_NO_PAIRED_DEV); // 暂无已配对设备 + emptyLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); + emptyLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + emptyLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_FORTY_SIZE); + emptyLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + emptyLabel->SetVisible(false); } - emptyLabel->SetPosition(87, 205, 280, 45); // 87:x 205:y 280:width 45:height - emptyLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_FORTY_SIZE); - emptyLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); - emptyLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, - UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); - emptyLabel->SetText("暂无已配对设备"); -} -UIViewGroup *BluetoothDeviceListView::GetGroup() -{ - return group; -} + UIViewGroup *BluetoothDeviceListView::GetGroup() + { + return group; + } -UIList *BluetoothDeviceListView::GetDeviceUIList() -{ - return list; -} + /*获取蓝牙已连接设备列表*/ + UIList *BluetoothDeviceListView::GetDeviceUIList() + { + return list; + } -void BluetoothDeviceListView::InitNewEquipmentButton() -{ - if (newEquipmentButton == nullptr) { - newEquipmentButton = new UILabelButton(); - if (newEquipmentButton == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView newEquipmentButton new fail"); + void BluetoothDeviceListView::InitNewEquipmentButton() + { + if (newEquipmentButton == nullptr) + { + newEquipmentButton = new UILabelExt(); + if (newEquipmentButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView newEquipmentButton new fail"); + return; + } + } + newEquipmentButton->SetPosition(133, 390, 200, 40); + newEquipmentButton->SetTextId(STR_BT_HEADSET_RESCAN); // 重新搜索 + newEquipmentButton->SetViewId(BLUETOOTH_NEWEQUIPMENT_BUTTON); + newEquipmentButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + newEquipmentButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + // newEquipmentButton->SetImageSrc(PNG_466x100BUTTON_IMAGE, PNG_466x100BUTTON_IMAGE); + newEquipmentButton->SetTextColor(Color::GetColorFromRGBA(0x35, 0x49, 0xff, 0xff)); + // newEquipmentButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); + newEquipmentButton->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + newEquipmentButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + newEquipmentButton->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + newEquipmentButton->SetTouchable(true); + 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 (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) + { + newEquipmentButton->SetOnClickListener(clickListener); + } + else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) + { + newEquipmentButton->SetOnClickListener(clickListener2); + } } - newEquipmentButton->SetPosition(65, 359, 324, 101); // 65 : x, 359 : y, 324:width 101:height - newEquipmentButton->SetText("新设备"); - 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 (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { - newEquipmentButton->SetOnClickListener(clickListener); - newEquipmentButton->SetTextColor(Color::Red()); - } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) { - newEquipmentButton->SetOnClickListener(clickListener2); - newEquipmentButton->SetTextColor(Color::Blue()); - } - newEquipmentButton->SetImageSrc(PNG_NEW_DEVICE, PNG_NEW_DEVICE); - newEquipmentButton->SetViewId(BLUETOOTH_NEWEQUIPMENT_BUTTON); - newEquipmentButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_FORTY_SIZE); -} -UIViewGroup *BluetoothDeviceListView::InitShowUpView() -{ - // 获取currentBdAddr db值 待开发 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView init"); - if (group == nullptr) { - group = new UIViewGroup(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); - return nullptr; + UIViewGroup *BluetoothDeviceListView::CreateBluetoothDeviceListView() + { + // 获取currentBdAddr db值 待开发 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView 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); - if (titleLabel == nullptr) { - titleLabel = new UILabel(); - if (titleLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView titleLabel new fail"); + group->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + group->SetViewId(BLUETOOTH_DEVICE_LIST_VIEW); + group->SetDraggable(true); + group->SetTouchable(true); + 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); - InitNewEquipmentButton(); - InItEmptyLabel(); - // 加载列表 - InitList(); - group->Add(newEquipmentButton); - group->Add(titleLabel); - group->Add(emptyLabel); + if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) + { + group->SetOnDragListener(earDragListener); + } + else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) + { + group->SetOnDragListener(earDragListener2); + } + /* ------------------------------- titleLabel ------------------------------- */ + if (titleLabel == nullptr) + { + titleLabel = new UILabelExt(); + if (titleLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView titleLabel new fail"); + return nullptr; + } + } + titleLabel->SetPosition(83, 50, 300, 35); + titleLabel->SetTextId(STR_BLUETOOTH_HEADPHONES); + titleLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); + titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + titleLabel->SetStyle(STYLE_TEXT_FONT,30); + titleLabel->SetStyle(STYLE_LINE_HEIGHT,35); + titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + titleLabel->SetRollSpeed(23); + titleLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + InitList(); // 加载bt设备列表 + InitNewEquipmentButton(); + InItEmptyLabel(); + /* -------------------------------------------------------------------------- */ + group->Add(titleLabel); + group->Add(list); + group->Add(emptyLabel); + group->Add(newEquipmentButton); - 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); + return group; } - group->SetViewId(BLUETOOTH_DEVICE_LIST_VIEW); - group->SetDraggable(true); - group->SetTouchable(true); - return group; -} -void BluetoothDeviceListView::RefreshText(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView::RefreshText"); - List &bluetoothConnedList = BluetoothModel::GetInstance()->GetConnedDevicesCase(); - bool ret = bluetoothConnedList.IsEmpty(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView::RefreshText bluetoothConnedList.IsEmpty ret = %d", ret); - if (ret) { - emptyLabel->SetVisible(true); - } else { - emptyLabel->SetVisible(false); + /*刷新已连接过的蓝牙设备列表视图*/ + void BluetoothDeviceListView::RefreshBluetoothDeviceListView(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView::RefreshBluetoothDeviceListView"); + if (list && newEquipmentButton) + { + switch (BluetoothModel::GetInstance()->GetConnedDevicesCase().Size()) + { + case 0: + list->Resize(380, 0); + break; + case 1: + list->Resize(380, 100); + break; + case 2: + list->Resize(380, 200); + break; + default: + list->Resize(380, 250); + break; + } + // newEquipmentButton->SetY(list->GetY() + list->GetHeight() + 20); + list->RefreshList(); + list->Invalidate(); + // newEquipmentButton->Invalidate(); + } } -} } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothEarListView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothEarListView.cpp index daf4cf89d..2a68bf61a 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothEarListView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothEarListView.cpp @@ -11,175 +11,294 @@ #include "PlayersPresenter.h" #include "BluetoothPresenter.h" #include "SettingModel.h" +#include "ui_resource_string.h" -namespace OHOS { -static BluetoothEarListView *g_pBluetoothEarListView{nullptr}; - -BluetoothEarListView::BluetoothEarListView() +namespace OHOS { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarListView::BluetoothEarListView"); - g_pBluetoothEarListView = this; -} + static BluetoothEarListView *g_pBluetoothEarListView{nullptr}; -BluetoothEarListView::~BluetoothEarListView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarListView::~BluetoothEarListView"); - group->RemoveAll(); - delete titleLabel; - titleLabel = nullptr; - delete adapterText; - adapterText = nullptr; - delete list; - list = nullptr; - delete rescanButton; - rescanButton = nullptr; - delete group; - group = nullptr; - g_pBluetoothEarListView = nullptr; -} - -BluetoothEarListView *BluetoothEarListView::GetInstance() -{ - return g_pBluetoothEarListView; -} + BluetoothEarListView::BluetoothEarListView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarListView::BluetoothEarListView"); + g_pBluetoothEarListView = this; + } -void BluetoothEarListView::InitList() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarListView::InitList"); - // list type - if (adapterText == nullptr) { - adapterText = new BluetoothCaseListAdapter(); - if (adapterText == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarListView adapterText new fail"); - return; + BluetoothEarListView::~BluetoothEarListView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarListView::~BluetoothEarListView"); + if (group) + { + group->RemoveAll(); + if (titleLabel) + { + delete titleLabel; + titleLabel = nullptr; + } + if (adapterText) + { + delete adapterText; + adapterText = nullptr; + } + if (list) + { + delete list; + list = nullptr; + } + if (rescanButton) + { + delete rescanButton; + rescanButton = nullptr; + } + if (cancelConnedRequestButton) + { + delete cancelConnedRequestButton; + cancelConnedRequestButton = nullptr; + } + delete group; + group = nullptr; } + g_pBluetoothEarListView = nullptr; } - if (list == nullptr) { - list = new UIList(UIList::VERTICAL); - if (list == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarListView list new fail"); - return; + + BluetoothEarListView *BluetoothEarListView::GetInstance() + { + return g_pBluetoothEarListView; + } + + void BluetoothEarListView::InitList() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarListView::InitList"); + // list type + if (adapterText == nullptr) + { + adapterText = new BluetoothCaseListAdapter(); + if (adapterText == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarListView adapterText new fail"); + return; + } + } + if (list == nullptr) + { + list = new UIList(UIList::VERTICAL); + if (list == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarListView list new fail"); + return; + } + list->SetPosition(43, 120, 380, 300); + list->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + list->SetStyle(STYLE_BORDER_RADIUS, 50); + list->SetStartIndex(0); + // list->EnableAutoAlign(true); + // list->SetIntercept(true); + list->SetDragACCLevel(5); + list->SetSwipeACCLevel(200); + // list->SetReboundSize(30); + // list->SetScrollBlankSize(30); + list->SetAdapter(adapterText); + group->Add(list); } - list->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - list->SetPosition(36, 118, HORIZONTAL_RESOLUTION, 241); // 36:x 118:y 454:width 241:height - list->SetStartIndex(0); // 0 : list start index - list->SetAdapter(adapterText); - group->Add(list); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarListView::InitList end"); } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarListView::InitList end"); -} -UIViewGroup *BluetoothEarListView::GetGroup() -{ - return group; -} + UIViewGroup *BluetoothEarListView::GetGroup() + { + return group; + } -UIList *BluetoothEarListView::GetScanUIList() -{ - return list; -} + UIList *BluetoothEarListView::GetScanUIList() + { + return list; + } -void BluetoothEarListView::SetTitleLabel(const char *text) -{ - titleLabel->SetText(text); -} + void BluetoothEarListView::SetTitleLabel(const char *text) + { + // titleLabel->SetText(text); + } -void BluetoothEarListView::SetNewEquipmentButtonAdd(void) -{ - group->Add(rescanButton); -} + void BluetoothEarListView::SetNewEquipmentButtonAdd(void) + { + // group->Add(rescanButton); + } -void BluetoothEarListView::SetNewEquipmentButtonRemove(void) -{ - group->Remove(rescanButton); -} + void BluetoothEarListView::SetNewEquipmentButtonRemove(void) + { + // group->Remove(rescanButton); + } -void BluetoothEarListView::SetCancelConnedRequestButtonAdd(void) -{ - group->Add(cancelConnedRequestButton); -} + void BluetoothEarListView::SetCancelConnedRequestButtonAdd(void) + { + // group->Add(cancelConnedRequestButton); + } -void BluetoothEarListView::SetCancelConnedRequestButtonRemove(void) -{ - group->Remove(cancelConnedRequestButton); -} + void BluetoothEarListView::SetCancelConnedRequestButtonRemove(void) + { + // group->Remove(cancelConnedRequestButton); + } -void BluetoothEarListView::InitButten(UILabelButton **button, const char *text, const char* id) -{ - if (*button == nullptr) { - *button = new UILabelButton(); - if (*button == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarListView::InitButten new fail"); + void BluetoothEarListView::InitButten(UILabelButton **button, const char *text, const char *id) + { + if (*button == nullptr) + { + *button = new UILabelButton(); + if (*button == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarListView::InitButten new fail"); + return; + } + } + (*button)->SetPosition(65, 359, 324, 101); // 65 : x, 359 : y, 324:width 101:height + (*button)->SetText(text); + 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, "BluetoothEarListView::InitButten button GetInstance fail"); return; } + if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) + { + (*button)->SetOnClickListener(clickListener); + (*button)->SetTextColor(Color::Red()); + } + else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) + { + (*button)->SetOnClickListener(clickListener2); + (*button)->SetTextColor(Color::Blue()); + } + (*button)->SetImageSrc(PNG_NEW_DEVICE, PNG_NEW_DEVICE); + (*button)->SetViewId(id); + (*button)->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_FORTY_SIZE); } - (*button)->SetPosition(65, 359, 324, 101); // 65 : x, 359 : y, 324:width 101:height - (*button)->SetText(text); - 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, "BluetoothEarListView::InitButten button GetInstance fail"); - return; - } - if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { - (*button)->SetOnClickListener(clickListener); - (*button)->SetTextColor(Color::Red()); - } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) { - (*button)->SetOnClickListener(clickListener2); - (*button)->SetTextColor(Color::Blue()); - } - (*button)->SetImageSrc(PNG_NEW_DEVICE, PNG_NEW_DEVICE); - (*button)->SetViewId(id); - (*button)->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_FORTY_SIZE); -} -UIViewGroup *BluetoothEarListView::InitShowUpView() -{ - // 获取currentBdAddr db值 待开发 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarListView init"); - if (group == nullptr) { - group = new UIViewGroup(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); - return nullptr; + void BluetoothEarListView::InitNewEquipmentButton() + { + if (rescanButton == nullptr) + { + rescanButton = new UILabelExt(); + if (rescanButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView rescanButton new fail"); + return; + } + } + rescanButton->SetPosition(133, 390, 200, 40); + rescanButton->SetTextId(STR_BT_HEADSET_RESCAN); // 重新搜索 + rescanButton->SetViewId(BLUETOOTH_RESCAN_BUTTON); + rescanButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + rescanButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + rescanButton->SetTextColor(Color::GetColorFromRGBA(0x35, 0x49, 0xff, 0xff)); + // rescanButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); + rescanButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + rescanButton->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + rescanButton->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + rescanButton->SetTouchable(true); + group->Add(rescanButton); + 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 (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) + { + rescanButton->SetOnClickListener(clickListener); + } + else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) + { + rescanButton->SetOnClickListener(clickListener2); } } - 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, "BluetoothEarListView titleLabel new fail"); + + UIViewGroup *BluetoothEarListView::InitShowUpView() + { + // 获取currentBdAddr db值 待开发 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarListView 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); + /* -------------------------------------------------------------------------- */ + if (titleLabel == nullptr) + { + titleLabel = new UILabelExt(); + if (titleLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView titleLabel new fail"); + return nullptr; + } + } + titleLabel->SetPosition(83, 50, 300, 35); + titleLabel->SetTextId(STR_BLUETOOTH_HEADPHONES); + titleLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); + titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + titleLabel->SetStyle(STYLE_TEXT_FONT,30); + titleLabel->SetStyle(STYLE_LINE_HEIGHT,35); + titleLabel->SetRollSpeed(23); + titleLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + group->Add(titleLabel); + /* -------------------------------------------------------------------------- */ + // 加载列表 + InitList(); + // 按钮初始化 + // InitButten(&rescanButton, "重新扫描", BLUETOOTH_RESCAN_BUTTON); + // InitButten(&cancelConnedRequestButton, "取消", BLUETOOTH_CANCELCONNEDREQUEST_BUTTON); + InitNewEquipmentButton(); + + 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_EARLIST_VIEW); + group->SetDraggable(true); + group->SetTouchable(true); + return group; } - 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); - // 加载列表 - InitList(); - InitButten(&rescanButton, "重新扫描", BLUETOOTH_RESCAN_BUTTON); - InitButten(&cancelConnedRequestButton, "取消", BLUETOOTH_CANCELCONNEDREQUEST_BUTTON); - 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); + + // 刷新扫描出来的设备列表 + void BluetoothEarListView::RefreshBluetoothEarListView(void) + { + if (list) + { + switch (BluetoothModel::GetInstance()->GetCase().size())//根据扫描出的设备数量,设置扫描列表的高度,使其高度自适应 + { + case 0: + list->Resize(380, 0); + break; + case 1: + list->Resize(380, 100); + break; + case 2: + list->Resize(380, 200); + break; + default: + list->Resize(380, 250); + break; + } + list->RefreshList(); + list->Invalidate(); + } } - group->SetViewId(BLUETOOTH_EARLIST_VIEW); - group->SetDraggable(true); - group->SetTouchable(true); - return group; -} } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothEarPhoneView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothEarPhoneView.cpp index 7253ed754..3d246fcd3 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothEarPhoneView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothEarPhoneView.cpp @@ -14,260 +14,314 @@ #include "SettingModel.h" #include "common/image_cache_manager.h" #include "graphic_service.h" +#include "uicomponents/UIComponents.h" +#include "uiservice/include/ui_service.h" +#include -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 -GraphicTimer* 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"); + 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); + + 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_EAR_PHONE_VIEW); + // 动画 + BtScanImageAnimator(); + group->SetDraggable(true); + group->SetTouchable(true); + return group; } - 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"); - return nullptr; + + // 取消br扫描处理 + static void CancelBrScanHandle(void) + { + /* ---------------------------------- 取消定时器 --------------------------------- */ + if (g_stopScanHandle != nullptr) + { + osTimerStop(g_stopScanHandle); + 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; } - 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); + /* --------------------------------- 取消屏幕常亮 --------------------------------- */ + ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); + /* -------------------------------------------------------------------------- */ + bool results = gap_br_cancel_discovery(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CancelBtDiscovery results %d", results); } - 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; + + // 结束扫描处理 + static void EndScanHandle(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EndScanHandle"); + 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"); + 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); + } + } + 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(); + } } - if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { - group->SetOnDragListener(earDragListener); - } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) { - group->SetOnDragListener(earDragListener2); + + // 定时器回调函数 + static void ScanTimerCallbackProc(int data) + { + (void)data; + CancelBrScanHandle(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Bt scan end jumpView"); + EndScanHandle(); } - group->SetViewId(BLUETOOTH_EAR_PHONE_VIEW); - // 动画 - BtScanImageAnimator(); - group->SetDraggable(true); - group->SetTouchable(true); - return group; -} -void CancelBrScanHandle(void) -{ - if (g_stopScanHandle != nullptr) { - delete g_stopScanHandle; - g_stopScanHandle = nullptr; + static void ScanTimerCallback(int data) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(ScanTimerCallbackProc, data)); } - bool results = gap_br_cancel_discovery(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CancelBtDiscovery results %d", results); -} -void EndScanHandle(void) -{ - if (BluetoothModel::GetInstance()->GetCase().size() == 0) { - BluetoothEarPhoneView *bluetoothEarPhoneView = BluetoothEarPhoneView::GetInstance(); - if (bluetoothEarPhoneView == nullptr) { // 暂停动画 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothEarPhoneView nullptr"); + // 蓝牙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; } - bluetoothEarPhoneView->BtAnimatorStop(); - if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { - JumpView *jumpView = JumpView::GetInstance(); - if (jumpView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "jumpView GetInstance fail"); - 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); + else + { + results = gap_br_start_discovery(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable StartBtDiscovery results %d", results); } - } else { - // 按rssi信息重新排序 - BluetoothModel::GetInstance()->SortScansCaseRssi(); - // 刷新 - BluetoothEarListView *bluetoothEarListView = BluetoothEarListView::GetInstance(); - if (bluetoothEarListView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothEarListView nullptr"); + /* -------------------------------------------------------------------------- */ + // ScreenTurnOn(MS_SCAN_TIME); + /* --------------------------------- 设置屏幕为常亮 -------------------------------- */ + ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); + /* -------------------------------------------------------------------------- */ + /*开启定时器*/ + if (g_stopScanHandle != nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable g_stopScanHandle != nullptr"); return; } - if (bluetoothEarListView->GetScanUIList() == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetScanUIList nullptr"); + g_stopScanHandle = osTimerNew((osTimerFunc_t)ScanTimerCallback, osTimerPeriodic, nullptr, nullptr); + if (g_stopScanHandle == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable osTimerNew failed!!"); return; } - bluetoothEarListView->GetScanUIList()->RefreshList(); - // 扫描完成 - bluetoothEarListView->SetTitleLabel("扫描完成"); - bluetoothEarListView->SetNewEquipmentButtonAdd(); - RootView::GetInstance()->Invalidate(); - } -} - -// 定时器回调函数 -static void BluetoothScanTimerCallbackProc(void* data) -{ - (void)data; - CancelBrScanHandle(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Bt scan end jumpView"); - EndScanHandle(); -} - -void BluetoothScanTimerCallback(void* data) -{ - GraphicService::GetInstance()->PostGraphicEvent(std::bind(BluetoothScanTimerCallbackProc, data)); -} - -// 蓝牙start -void BluetoothEarPhoneView::BtEnable() -{ - bool ret; - bool results; - // 经典蓝牙扫描 - setScanStatus(true); // 开始扫描标记 - BluetoothModel::GetInstance()->SetCaseListClear(); // 扫描list清空 - ret = is_bt_discovering(BT_TRANSPORT_BR_EDR); - if (ret) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable Bt is Discovering"); - return; - } else { - results = gap_br_set_inquiry_paramters(DEVICE_MAJOR_CLASS_AUDIO_VIDEO, 0); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "gap_br_set_inquiry_paramters results %d", results); - results = gap_br_start_discovery(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "gap_br_start_discovery results %d", results); - } - if (g_stopScanHandle != nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable g_stopScanHandle != nullptr"); - return; - } - uint32 tick = GetOSTick(MS_SCAN_TIME); - g_stopScanHandle = new GraphicTimer(tick, BluetoothScanTimerCallback, nullptr, true); - if (g_stopScanHandle == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable new GraphicTimer failed!!"); - return; - } - bool retTimer = g_stopScanHandle->Start(); - if (!retTimer) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable Start failed"); - if (g_stopScanHandle != nullptr) { - delete g_stopScanHandle; - g_stopScanHandle = nullptr; + 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; + } + 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"); + } + CancelBrScanHandle(); return; } - CancelBrScanHandle(); - return; -} -void BluetoothEarPhoneView::setScanStatus(bool value) -{ - scanStart = value; -} -bool BluetoothEarPhoneView::getScanStatus(void) -{ - return scanStart; -} + /* + * @brief 设置是否已经开始扫描标记 + */ + 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/fd230/nativeapp/nativeui/bluetooth/src/BluetoothHeadsetEvent.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothHeadsetEvent.cpp index 6ac112db8..2b10bff3d 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothHeadsetEvent.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothHeadsetEvent.cpp @@ -5,11 +5,14 @@ * Create: 2022-3-22 */ -#include "BluetoothHeadsetEvent.h" +#include #include "bts_avrcp_target.h" #include "bts_avrcp_controller.h" #include "PlayersModel.h" +#include "service_id_define.h" #include "graphic_service.h" +#include +#include "notification_manager.h" using namespace OHOS; @@ -28,7 +31,7 @@ BtAvrcpTgInf g_avrcp_srv_inf; void BtAvrcpVolumeChangedSyncMedia(uint8_t a2dp_volume) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "[BtAvrcpVolumeChangedSyncMedia]::a2dp_volume = 0x%x\r\n", a2dp_volume); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[BtAvrcpVolumeChangedSyncMedia]::a2dp_volume = 0x%x\r\n", a2dp_volume); int32_t audio_volume = a2dp_volume * BT_A2DP_MEDIA_VOL_LEVEL / AVRCP_ABSOLUTE_VOLUME_PERCENTAGE_100; AudioManager::GetInstance().SetVolume(AUDIO_STREAM_A2DP_MUSIC, audio_volume); /* 设置增益音量 */ g_avrcp_tg_local_media_vol = a2dp_volume; @@ -95,13 +98,26 @@ void PressButtonStatusCallback(td_u32 keyOperation, td_u32 keyValue) void BtAvrcpTgNotifyVolumeChangedProc(uint8_t a2dp_volume) { int32_t audio_volume = a2dp_volume * BT_A2DP_MEDIA_VOL_LEVEL / AVRCP_ABSOLUTE_VOLUME_PERCENTAGE_100; - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "NotifyVolume = %d", audio_volume); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NotifyVolume = %d", audio_volume); AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, audio_volume); // 耳机连接手表场景调节手表音量 + /* ---------------------------- 若当前音乐播放器为手机音乐则同步更新音乐播放器的声音进度条 --------------------------- */ + if(PlayersModel::GetInstance()->GetMusicSource()) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(&OHOS::PlayersModel::UpdateVolumeValue, OHOS::PlayersModel::GetInstance())); + } + /* -------------------------------------------------------------------------- */ } +//根据传入的按键操作类型和值,执行相应的操作并通知媒体状态变化 void UsingPressButtonStatusCallback(td_u32 keyOperation, td_u32 keyValue) { + if(NotificationManager::GetInstance()->GetWatchCallStatus()) + { + return ; + } + bt_avrcp_tg_evt_status_param event; + // printf("keyOperation = %d, keyValue = %d\n"); switch (keyOperation) { case AVRCP_KEY_VOLUME_UP: // 耳机控制手表加减音量不走key_operation事件 case AVRCP_KEY_VOLUME_DOWN: // 减小音量 @@ -152,11 +168,11 @@ uint8_t BtAvrcpTgGetLocMediaVolume(void) if (g_avrcp_tg_local_media_vol == AVRCP_ABSOLUTE_VOLUME_INVALID) { int32_t audio_volume = AudioManager::GetInstance().GetVolume(AUDIO_STREAM_A2DP_MUSIC); uint8_t a2dp_volume = (uint8_t)(audio_volume * AVRCP_ABSOLUTE_VOLUME_PERCENTAGE_100 / BT_A2DP_MEDIA_VOL_LEVEL); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "audio_volume 0x%x, a2dp_volume 0x%x\n", audio_volume, a2dp_volume); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "audio_volume 0x%x, a2dp_volume 0x%x\n", audio_volume, a2dp_volume); g_avrcp_tg_local_media_vol = a2dp_volume; } - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "get local media volume, a2dp_volume = 0x%x", g_avrcp_tg_local_media_vol); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "get local media volume, a2dp_volume = 0x%x", g_avrcp_tg_local_media_vol); return g_avrcp_tg_local_media_vol; } @@ -206,7 +222,7 @@ void MediaStatusCallback(bt_avrcp_tg_evt_status_param *eventStatusParam) void ConnCtStateChangedCallback(const bd_addr_t *bdAddr, profile_connect_state_t state) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "avrcp ct update conn stat:%u", state); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "avrcp ct update conn stat:%u", state); if (bdAddr == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bdaddr nullptr"); return; @@ -218,14 +234,16 @@ void ConnCtStateChangedCallback(const bd_addr_t *bdAddr, profile_connect_state_t g_avrcp_srv_inf.avrcp_srv_conn_stat = state; } -static bd_addr_t *BtAvrcpSrvGetActiveAddr(void) +bd_addr_t *BtAvrcpSrvGetActiveAddr(void) { return &g_avrcp_srv_inf.bd_addr; } + + void ConnectTgStateChangedCallback(const bd_addr_t *bdAddr, profile_connect_state_t state) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "avrcp tg update conn stat:%u", state); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "avrcp tg update conn stat:%u", state); if (bdAddr == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bdaddr nullptr"); return; @@ -243,6 +261,43 @@ void ConnectTgStateChangedCallback(const bd_addr_t *bdAddr, profile_connect_stat } } +/* -------------------------------------------------------------------------- */ +void user_avrcp_ct_press_button(const bd_addr_t *bd_addr, int32_t key_operation) +{ + (void)avrcp_ct_press_button(bd_addr, key_operation); + uint8_t sleep_cnt = 0; + while (1) { //持续等待接收一个响应消息来确认按键按下操作已被正确处理 + osal_msleep(100); /* sleep 1000 ms */ + if (g_avrcp_srv_inf.avrcp_button_flag == AVRCP_SRV_PRESS_VALUE) { + (void)avrcp_ct_release_button(bd_addr, key_operation); + break; + } + sleep_cnt++; + if (sleep_cnt > 20) { /* sleep 20 times */ + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP,"not receive rsp press button msg\n"); + break; + } + } +} + +void user_avrcp_ct_get_element_attributes(const bd_addr_t *bd_addr) +{ + avrcp_ct_get_element_attr_para_t element_attr_param; + element_attr_param.attr_num = AVRCP_CT_ELEMENT_ATTR_TRACK_PLAYING_TIME; + element_attr_param.attr_id_list = (unsigned int *)(void *)malloc(sizeof(unsigned int) * element_attr_param.attr_num); + for (int i = 0; i < element_attr_param.attr_num; i++) + { + element_attr_param.attr_id_list[i] = (unsigned int)i + 1; + } + avrcp_ct_get_element_attributes(bd_addr, &element_attr_param); + if (element_attr_param.attr_id_list != NULL) + { + free(element_attr_param.attr_id_list); + element_attr_param.attr_id_list = NULL; + } +} +/* -------------------------------------------------------------------------- */ +//记录按下按钮的回调事件以及按键操作值 static void BtAvrcpCtPressButtonRspCallback(const bd_addr_t *bd_addr, int32_t key_operation) { if (bd_addr == nullptr) { @@ -294,10 +349,11 @@ static void BtAvrcpPressReleaseButtonLog(uint32_t key_operation) } } +//记录释放按钮的回调事件以及按键操作值 static void BtAvrcpCtReleaseButtonRspCallback(const bd_addr_t *bd_addr, int32_t key_operation) { UNUSED(bd_addr); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "avrcp ct release button cbk key:%d\n", key_operation); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "avrcp ct release button cbk key:%x\n", key_operation); if (g_avrcp_srv_inf.avrcp_button_flag == AVRCP_SRV_PRESS_VALUE) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "avrcp ct released button button_flag change:%u->%u\n", g_avrcp_srv_inf.avrcp_button_flag, AVRCP_SRV_RELEASED_VALUE); @@ -328,14 +384,14 @@ static void BtAvrcpCtSupportEventCallback(const bd_addr_t *bd_addr, avrcp_ct_sup for (uint8_t i = 0; i < event->event_num; i++) { if (event->event_id[i] == AVRCP_NOTIFY_EVENT_VOLUME_CHANGED) { int ret = avrcp_ct_register_notification(bd_addr, event->event_id[i], 0); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "register event_id: 0x%x, ret = 0x%x", event->event_id[i], ret); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "register event_id: 0x%x, ret = 0x%x", event->event_id[i], ret); } } for (uint8_t i = 0; i < event->event_num; i++) { if (event->event_id[i] != AVRCP_NOTIFY_EVENT_VOLUME_CHANGED) { int ret = avrcp_ct_register_notification(bd_addr, event->event_id[i], 0); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "register event_id: 0x%x, ret = 0x%x", event->event_id[i], ret); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "register event_id: 0x%x, ret = 0x%x", event->event_id[i], ret); } } } @@ -400,16 +456,29 @@ static void BtAvrcpCtGetPlayStatusCallback(const bd_addr_t *bd_addr, avrcp_ct_pl WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "null pointer\n"); return; } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "test get play status songlen:%u, songpos:%u, playstatus:%u:", - status->song_length, status->song_position, status->play_status); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BtAvrcpCtGetPlayStatusCallback] songlen:%u, songpos:%u, playstatus:%u:", + status->song_length, status->song_position, status->play_status); } static void BtAvrcpCtHdlNotifyVolumeRspCbk(avrcp_ct_notification_value_cb_t *notification) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "Set local volume: 0x%x\n", notification->volume); /* 注册事件后通知的音量 */ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[BtAvrcpCtHdlNotifyVolumeRspCbk] volume: 0x%x\n", + notification->volume); /* 注册事件后通知的音量 */ BtAvrcpTgNotifyVolumeChangedProc((uint8_t)notification->volume); } +static void BtAvrcpCtHdlNotifyPlaybackStatusChangedRspCbk(avrcp_ct_notification_value_cb_t *notification) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[BtAvrcpCtHdlNotifyPlaybackStatusChangedRspCbk] playback status changed :%u\n", + notification->play_status); + if(notification->play_status == AVRCP_PLAY_STATUS_PLAYING) { //AVRCP媒体playing状态 + PlayersModel::GetInstance()->set_player_state(true); //更新UI显示 + } else { + PlayersModel::GetInstance()->set_player_state(false); + } + return; +} +//收到来自TG返回的Notification时回调函数 static void BtAvrcpCtNotificationCallback( const bd_addr_t *bd_addr, avrcp_notify_event_t event_id, avrcp_ct_notification_value_cb_t *notification) { @@ -421,29 +490,37 @@ static void BtAvrcpCtNotificationCallback( WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ct notification cbk event_id:0x%x\n", event_id); bool notify_flag = true; switch (event_id) { - case AVRCP_NOTIFY_EVENT_PLAYBACK_STATUS_CHANGED: - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "tg notify ct playback status changed :%u\n", - notification->play_status); + case AVRCP_NOTIFY_EVENT_PLAYBACK_STATUS_CHANGED: //播放状态变更事件,从播放变为暂停、停止等状态,会触发这个事件 + // BtAvrcpCtHdlNotifyPlaybackStatusChangedRspCbk(notification); break; - case AVRCP_NOTIFY_EVENT_VOLUME_CHANGED: - BtAvrcpCtHdlNotifyVolumeRspCbk(notification); + case AVRCP_NOTIFY_EVENT_TRACK_CHANGED: //track状态变更事件,切换到下一首、上一首歌曲等情况,会触发此事件 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "track changed event_id:0x%x\n", event_id); break; - case AVRCP_NOTIFY_EVENT_NOW_PLAYING_CONTENT_CHANGED: - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "play conent changed event_id:0x%x\n", event_id); + case AVRCP_NOTIFY_EVENT_TRACK_REACHED_END: //track结束事件,当前播放的曲目播放到末尾时,触发这个事件 break; - case AVRCP_NOTIFY_EVENT_TRACK_CHANGED: - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "track changed event_id:0x%x\n", event_id); + case AVRCP_NOTIFY_EVENT_TRACK_REACHED_START: //track开始事件,当曲目开始播放时,触发这个事件 + break; + case AVRCP_NOTIFY_EVENT_PLAYBACK_POS_CHANGED: //播放位置改变事件,当播放进度的位置发生变化时,比如快进、快退等操作导致播放位置改变,会触发此事件 + break; + case AVRCP_NOTIFY_EVENT_BATT_STATUS_CHANGED: //电池状态变更事件,当蓝牙设备的电池状态发生变化时,电量降低、充电状态改变等,会触发这个事件 + break; + case AVRCP_NOTIFY_EVENT_SYSTEM_STATUS_CHANGED: //系统状态变更事件 + break; + case AVRCP_NOTIFY_EVENT_PLAYER_APPLICATION_SETTING_CHANGED: //播放器配置变更事件,如音效设置、播放模式设置等,会触发此事件 + break; + case AVRCP_NOTIFY_EVENT_NOW_PLAYING_CONTENT_CHANGED: //播放内容变更事件,当 “正在播放” 列表中的内容发生变化时,比如添加了新的曲目、删除了曲目等情况,会触发这个事件。 + break; + case AVRCP_NOTIFY_EVENT_AVAILABLE_PLAYERS_CHANGED: //可使用的播放器变更事件,当系统中可用于播放的播放器设备发生变化时,比如新的播放器设备连接到系统或者已有播放器设备断开连接,会触发此事件 + break; + case AVRCP_NOTIFY_EVENT_ADDRESSED_PLAYER_CHANGED: //播放地址变更事件 + break; + case AVRCP_NOTIFY_EVENT_UIDS_CHANGED: //UID 变更事件 + break; + case AVRCP_NOTIFY_EVENT_VOLUME_CHANGED: //TG 端音量变更事件 + BtAvrcpCtHdlNotifyVolumeRspCbk(notification); + break; + case AVRCP_NOTIFY_EVENT_RESERVED: //保留 break; - case AVRCP_NOTIFY_EVENT_TRACK_REACHED_END: - case AVRCP_NOTIFY_EVENT_TRACK_REACHED_START: - case AVRCP_NOTIFY_EVENT_PLAYBACK_POS_CHANGED: - case AVRCP_NOTIFY_EVENT_BATT_STATUS_CHANGED: - case AVRCP_NOTIFY_EVENT_SYSTEM_STATUS_CHANGED: - case AVRCP_NOTIFY_EVENT_PLAYER_APPLICATION_SETTING_CHANGED: - case AVRCP_NOTIFY_EVENT_AVAILABLE_PLAYERS_CHANGED: - case AVRCP_NOTIFY_EVENT_ADDRESSED_PLAYER_CHANGED: - case AVRCP_NOTIFY_EVENT_UIDS_CHANGED: - case AVRCP_NOTIFY_EVENT_RESERVED: default: notify_flag = false; WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "invalid event id event_id:0x%x\n", event_id); diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothItemView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothItemView.cpp index 676c0183e..a7a350c5c 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothItemView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothItemView.cpp @@ -8,16 +8,29 @@ #include "BluetoothItemView.h" #include "wearable_log.h" #include "UiConfig.h" -#include "common/image_cache_manager.h" +#include "player/include/PlayersView.h" +#include "ui_resource_image.h" +#include "ui_resource_string.h" +#include "CallerLogModel.h" +#include "custom_utils.h" +#include "notification_manager.h" -namespace OHOS { -constexpr uint16_t BUTTON_WIDTH = 351; -constexpr uint16_t BUTTON_HEIGHT = 81; -constexpr uint16_t IMAGE_WIDTH = 81; -constexpr uint16_t IMAGE_HEIGHT = 81; -constexpr uint16_t LABEL_HEIGHT = 81; -constexpr uint16_t LABEL_WIDTH = 189; -constexpr uint16_t BLELIST_BUTTON_HEIGHT = 81; +#ifdef SUPPORT_PHONE_SERVICE +#include "PhoneAGService.h" +#endif + +#include "ConfigModel.h" +#include "languagecode/LanguageInit.h" + +namespace OHOS +{ + constexpr uint16_t BUTTON_WIDTH = 351; + constexpr uint16_t BUTTON_HEIGHT = 81; + constexpr uint16_t IMAGE_WIDTH = 81; + constexpr uint16_t IMAGE_HEIGHT = 81; + constexpr uint16_t LABEL_HEIGHT = 81; + constexpr uint16_t LABEL_WIDTH = 189; + constexpr uint16_t BLELIST_BUTTON_HEIGHT = 81; #define BLUETOOTH_CONNECT_DELAY 200 #define BLUETOOTH_CONNECT_X 294 @@ -25,140 +38,267 @@ constexpr uint16_t BLELIST_BUTTON_HEIGHT = 81; #define BLUETOOTH_CONNECT_WIDTH 81 #define BLUETOOTH_CONNECT_HEIGHT 81 -BluetoothItemView::BluetoothItemView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothItemView::BluetoothItemView"); - SetPosition(53, 106, 375, 81); // 53:x 106:y 375:width 81:height - SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); - SetUpChild(); - SetTouchable(true); - - Add(&button); - Add(&connectStateLabel); - Add(&namelabel); - Add(&image); - Add(&connectionAnimator); -} + BluetoothItemView::BluetoothItemView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothItemView::BluetoothItemView"); + SetPosition(40, 21, 380, 100); + SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + SetStyle(STYLE_BACKGROUND_OPA, 0x00); + SetUpChild(); + SetTouchable(true); -BluetoothItemView::~BluetoothItemView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothItemView::~BluetoothItemView"); - Remove(&connectStateLabel); - Remove(&button); - Remove(&namelabel); - Remove(&image); - Remove(&connectionAnimator); -} + Add(&button); + Add(&namelabel); + Add(&connectStateLabel); + Add(&lineImage); + Add(¬eImage); + Add(&connectionAnimator); + } -void BluetoothItemView::SetUpChild() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothItemView::SetUpChild"); - button.Resize(BUTTON_WIDTH, BUTTON_HEIGHT); // 351:Width - button.SetImageSrc(PNG_BT_LIST, PNG_BT_LIST); // 跳转图片 - button.SetImagePosition(24, 0); // 24: lable x-coordinate - - namelabel.SetPosition(105, 0); // 105:x 0:y - namelabel.Resize(LABEL_WIDTH, LABEL_HEIGHT); - namelabel.SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); - namelabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30: means font size - namelabel.SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); - namelabel.SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, - UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); - - image.SetPosition(0, 0, IMAGE_WIDTH, IMAGE_HEIGHT); // 0:x 0:y - image.SetSrc(PNG_BLUETOOTHEAR); - BtConnectImageAnimator(); -} + BluetoothItemView::~BluetoothItemView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothItemView::~BluetoothItemView"); + Remove(&button); + Remove(&namelabel); + Remove(&connectStateLabel); + Remove(&lineImage); + Remove(¬eImage); + Remove(&connectionAnimator); + } -void BluetoothItemView::SetItemInfo(const BluetoothCaseInfo& itemInfo, bool isCaseList) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothItemView::SetItemInfo"); - itemInfo_ = itemInfo; - namelabel.SetText(reinterpret_cast(itemInfo_.deviceName)); - if (isCaseList) { - bool ret = BluetoothModel::GetInstance()->IsTagScanDeviceClicked(); - if ((!IsConnectAnimator()) && (ret)) { - namelabel.SetStyle(STYLE_TEXT_COLOR, Color::Gray().full); - button.SetTouchable(false); - SetTouchable(false); - } else { - namelabel.SetStyle(STYLE_TEXT_COLOR, Color::White().full); - button.SetTouchable(true); - SetTouchable(true); + void BluetoothItemView::SetUpChild() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothItemView::SetUpChild"); + button.SetPosition(40, 0, 250, 80); + button.SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + button.SetStyle(STYLE_BACKGROUND_OPA, 0x00); + button.SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); + + /*蓝牙设备名称*/ + namelabel.SetPosition(40, 21, 250, 35); + namelabel.SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + namelabel.SetStyle(STYLE_BACKGROUND_OPA, 0x00); + namelabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30); + namelabel.SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + namelabel.SetRollSpeed(100); + namelabel.SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + + /*线*/ + lineImage.SetPosition(35, 98, 310, 2); + lineImage.SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + lineImage.SetStyle(STYLE_BACKGROUND_OPA, 0x33); + lineImage.SetStyle(STYLE_BORDER_RADIUS, 100); + + BtConnectImageAnimator(); + } + + void BluetoothItemView::SetItemInfo(const BluetoothCaseInfo &itemInfo, bool isCaseList) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothItemView::SetItemInfo"); + itemInfo_ = itemInfo; + namelabel.SetText(reinterpret_cast(itemInfo_.deviceName)); + if (isCaseList) + { + bool ret = BluetoothModel::GetInstance()->IsTagScanDeviceClicked(); + if ((!IsConnectAnimator()) && (ret)) + { + button.SetTouchable(false); + SetTouchable(false); + } + else + { + button.SetTouchable(true); + SetTouchable(true); + } + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "index = %d", GetViewIndex()); + if(!isCaseList) + { + //已连接的耳机界面 + List &btConnedDevicesList_ = BluetoothModel::GetInstance()->GetConnedDevicesCase(); + if (GetViewIndex() == btConnedDevicesList_.Size() - 1) + { + lineImage.SetVisible(false); + } + else + { + lineImage.SetVisible(true); + } + } + else + { + //搜索出耳机的界面 + std::list &btScansDevicesList_ = BluetoothModel::GetInstance()->GetCase(); + if (GetViewIndex() == btScansDevicesList_.size() - 1) + { + lineImage.SetVisible(false); + } + else + { + lineImage.SetVisible(true); + } } } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "index = %d", GetViewIndex()); -} -BluetoothCaseInfo *BluetoothItemView::GetItemInfo(void) -{ - return &itemInfo_; -} + BluetoothCaseInfo *BluetoothItemView::GetItemInfo(void) + { + return &itemInfo_; + } -void BluetoothItemView::SetConnectionstatus(const BluetoothCaseInfo& infoData) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothItemView::SetConnectionstatus"); - connectStateLabel.SetPosition(105, 0); // 105:x 0:y - connectStateLabel.Resize(LABEL_WIDTH, LABEL_HEIGHT); - connectStateLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30: means font size - connectStateLabel.SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); - connectStateLabel.SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, - UITextLanguageAlignment::TEXT_ALIGNMENT_BOTTOM); - bool aclConnected = bt_is_acl_connected((const bd_addr_t*)&infoData.addr); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothItemView::SetConnectionstatus aclConnected %d", aclConnected); - if (aclConnected) { - connectStateLabel.SetText("已连接"); - } else { - connectStateLabel.SetText("已断开"); + /*连接状态设置*/ + void BluetoothItemView::SetConnectionstatus(const BluetoothCaseInfo &infoData) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothItemView::SetConnectionstatus"); + connectStateLabel.SetPosition(40, namelabel.GetY() + namelabel.GetHeight(), 250, 27); + connectStateLabel.SetStyle(STYLE_TEXT_FONT, 23); + connectStateLabel.SetStyle(STYLE_LINE_HEIGHT, 27); + connectStateLabel.SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, UITextLanguageAlignment::TEXT_ALIGNMENT_BOTTOM); + connectStateLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 23); + /* -------------------------------- noteImage ------------------------------- */ + noteImage.SetPosition(namelabel.GetX() + namelabel.GetWidth(), 0, 80, 80); + noteImage.SetAutoEnable(false); + noteImage.SetResizeMode(UIImageView::CENTER); + noteImage.SetTouchable(true); + if (!PlayersView::LoadPlayerImage(¬eImage, PLAYER_LOOK_CONNECTED_NOTE)) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "noteImage LoadPlayerImage fail"); + return; + } + /* ------------------------------ 检查ACL链路是否连接。 ------------------------------ */ + + { + #ifdef SUPPORT_BT_SERVICE + bool aclConnected = bt_is_acl_connected((const bd_addr_t *)&infoData.addr); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothItemView::SetConnectionstatus aclConnected %d", aclConnected); + #else + bool aclConnected = false; + #endif + + if (aclConnected) + { + connectStateLabel.SetTextColor(Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff)); + connectStateLabel.SetTextId(STR_CONNECTED); // 已连接 + if(OHOS::CallerLogModel::GetInstance()->GetCallSource() == OHOS::CallerLogModel::CallSourceCat1 + && OHOS::NotificationManager::GetInstance()->GetWatchCallStatus()) + { + #ifdef SUPPORT_BT_SERVICE + bool SCOConnected = headset_SCO_Is_connect_extend( (bd_addr_t *)&infoData.addr); + #else + bool SCOConnected = false; + #endif + + if(SCOConnected) + { + connectStateLabel.SetTextColor(Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff)); + if(ConfigModel::GetInstance()->GetLanguage() == ZH_CN) + { + connectStateLabel.SetText("蓝牙耳机通话已连接"); + } + else + { + connectStateLabel.SetText("Bluetooth headset call connected"); + } + + } + else + { + connectStateLabel.SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); + if(ConfigModel::GetInstance()->GetLanguage() == ZH_CN) + { + connectStateLabel.SetText("蓝牙耳机通话未连接"); + } + else + { + connectStateLabel.SetText("Bluetooth headset call is not connected"); + } + + } + + } + } + else + { + connectStateLabel.SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); + connectStateLabel.SetTextId(STR_DISCONNECTED); // 未连接 + } + + } + + + + + connectStateLabel.ForceResetText(); + connectStateLabel.Invalidate(); } - namelabel.SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, - UITextLanguageAlignment::TEXT_ALIGNMENT_TOP); - namelabel.Invalidate(); -} -void BluetoothItemView::ConnectAnimatorStart(void) -{ - connectionAnimator.SetVisible(true); - connectionAnimator.Start(); -} + void BluetoothItemView::SetPairingtatus() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothItemView::SetPairingtatus"); + connectStateLabel.SetPosition(40, namelabel.GetY() + namelabel.GetHeight(), 250, 27); + connectStateLabel.SetStyle(STYLE_TEXT_FONT, 23); + connectStateLabel.SetStyle(STYLE_LINE_HEIGHT, 27); + connectStateLabel.SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_LEFT, UITextLanguageAlignment::TEXT_ALIGNMENT_BOTTOM); + connectStateLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 23); + connectStateLabel.SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); + connectStateLabel.SetTextId(STR_NOT_PAIRED); // 未配对 + } -void BluetoothItemView::ConnectAnimatorStop(void) -{ - connectionAnimator.SetVisible(false); - connectionAnimator.Stop(); -} + void BluetoothItemView::SetViewOnClickListener(UIView::OnClickListener *listener) + { + if (listener) + { + button.SetOnClickListener(listener); + noteImage.SetOnClickListener(listener); + } + } -bool BluetoothItemView::IsConnectAnimator(void) -{ - return connectionAnimator.IsVisible(); -} + /*动画开始*/ + void BluetoothItemView::ConnectAnimatorStart(void) + { + connectionAnimator.SetVisible(true); + connectionAnimator.Start(); + } -void BluetoothItemView::BtConnectImageAnimator() -{ - const char *connectImagePath[BLUETOOTH_CONNECT_IMAGE_NUM] = { - PNG_A019_088_IMAGE_PATH, - PNG_A019_089_IMAGE_PATH, - PNG_A019_090_IMAGE_PATH, - PNG_A019_091_IMAGE_PATH, - PNG_A019_092_IMAGE_PATH, - PNG_A019_093_IMAGE_PATH, - PNG_A019_094_IMAGE_PATH, - PNG_A019_095_IMAGE_PATH, - }; - - for (uint8_t i = 0; i < BLUETOOTH_CONNECT_IMAGE_NUM; i++) { - connectImageInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(connectImagePath[i]); - connectImageInfo[i].imageType = IMG_SRC_IMAGE_INFO; - connectImageInfo[i].pos.x = BLUETOOTH_CONNECT_X; - connectImageInfo[i].pos.y = BLUETOOTH_CONNECT_Y; - connectImageInfo[i].width = BLUETOOTH_CONNECT_WIDTH; - connectImageInfo[i].height = BLUETOOTH_CONNECT_HEIGHT; + /*动画停止*/ + void BluetoothItemView::ConnectAnimatorStop(void) + { + connectionAnimator.SetVisible(false); + connectionAnimator.Stop(); } - connectionAnimator.SetImageAnimatorSrc(connectImageInfo, BLUETOOTH_CONNECT_IMAGE_NUM, BLUETOOTH_CONNECT_DELAY); - connectionAnimator.SetRepeat(true); - connectionAnimator.SetVisible(false); -} + /*连接动画是否可见*/ + bool BluetoothItemView::IsConnectAnimator(void) + { + return connectionAnimator.IsVisible(); + } + + /*蓝牙连接动画*/ + void BluetoothItemView::BtConnectImageAnimator() + { + const char *connectImagePath[BLUETOOTH_CONNECT_IMAGE_NUM] = { + PNG_A019_088_IMAGE_PATH, + PNG_A019_089_IMAGE_PATH, + PNG_A019_090_IMAGE_PATH, + PNG_A019_091_IMAGE_PATH, + PNG_A019_092_IMAGE_PATH, + PNG_A019_093_IMAGE_PATH, + PNG_A019_094_IMAGE_PATH, + PNG_A019_095_IMAGE_PATH, + }; + + for (uint8_t i = 0; i < BLUETOOTH_CONNECT_IMAGE_NUM; i++) + { + connectImageInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(connectImagePath[i]); + connectImageInfo[i].imageType = IMG_SRC_IMAGE_INFO; + connectImageInfo[i].pos.x = BLUETOOTH_CONNECT_X; + connectImageInfo[i].pos.y = BLUETOOTH_CONNECT_Y; + connectImageInfo[i].width = BLUETOOTH_CONNECT_WIDTH; + connectImageInfo[i].height = BLUETOOTH_CONNECT_HEIGHT; + } + + connectionAnimator.SetImageAnimatorSrc(connectImageInfo, BLUETOOTH_CONNECT_IMAGE_NUM, BLUETOOTH_CONNECT_DELAY); + connectionAnimator.SetRepeat(true); + connectionAnimator.SetVisible(false); + } } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothModel.cpp index 699e0b1c2..55b24f97c 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothModel.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothModel.cpp @@ -6,10 +6,12 @@ */ #include #include "BluetoothModel.h" +#include "BluetoothModelC.h" + #include "BluetoothWrapper.h" #include "BluetoothPresenter.h" #include "ConnectPhonePresenter.h" -#include "BluetoothView.h" +#include "MusicPlayerSourceView.h" #include "BluetoothItemView.h" #include "PlayersModel.h" #include "PhoneAudio.h" @@ -22,6 +24,9 @@ #include "bts_le_gap.h" #include "bts_spp.h" #include "osal_task.h" +#include "bts_pbap.h" +#include "ConfigModelC.h" +#include "custom_utils.h" #ifdef SUPPORT_ALIPAY_SEC #include "alipay_feature.h" #endif @@ -31,11 +36,37 @@ #include "audio_manager_c_wrapper.h" #include "bts_avrcp_target.h" #include "msg_center_msg.h" -#include "client/msg_center_client.h" -#include "msg_center_protocol.h" #include "dfx_channel.h" #include "tcxo.h" -#include "ui_service.h" +#include "custom_runtime.h" + +#ifdef SUPPORT_BLE_SERVICE +#include +#include "bleService.h" +#include "bletest.h" +#endif + +//#include "hfp_hf_service.h" +#include "uiservice/include/ui_service.h" +#include "PhoneService.h" +#ifdef SUPPORT_AT_OHOSFWK +#include "BluetoothWrapper.h" +#endif +#include "Bluetooyhpabpserver.h" + + + +#include "ConfigModelC.h" +#include "uiservice/include/ui_service.h" +#include "vibrator_service.h" +#include "ConfigModel.h" + +#ifdef SUPPORT_PHONE_SERVICE +#include "PhoneAGService.h" +#endif + +#include "custom_save_runtime.h" +#include "BluetoothHeadsetEvent.h" namespace OHOS { @@ -43,7 +74,7 @@ namespace OHOS { #define BT_SPP_TASK_PRI 20 #define TEN 10 -constexpr uint16_t BLUETOOTH_MAX_NUM = 20; +constexpr uint16_t BLUETOOTH_MAX_NUM = 20; /*已连接设备列表的大小*/ #define MEDIA_A2DP_SNK_INTERFACE 1 osal_timer g_a2dp_stream_accept_timer = {nullptr, nullptr, 0, 0}; @@ -52,7 +83,6 @@ AudioFormatConfig g_audio_format_config = {AUDIO_DEFAULT, 0, 0}; static uint16_t g_sample_svr_handle = 0; static uint16_t g_sample_characteristic_handle = 0; static uint16_t g_diag_characteristic_handle = 0; -static uint16_t g_diag_desc_handle = 0; constexpr uint16_t g_sample_adv_id = 2; static bd_addr_t g_bd_addr = { 0 }; @@ -82,76 +112,223 @@ char* BluetoothModel::getWatchName(void) return watchName; } -void BluetoothModel::InitBluetoothInfo(void) +void InitBluetoothInfo(void) { - errcode_t ret; + #ifdef SUPPORT_BLE_SERVICE unsigned char nameLen = BD_NAME_LEN; + uint8_t ble_name[BD_NAME_LEN] = {0}; + uint8_t ble_name_len = BD_NAME_LEN; + errcode_t ret = 0; + + ret = bluetooth_get_local_name(ble_name, &ble_name_len); + if (ret != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "gap_ble_get_local_name fail, name:%s,len:%u,ret:%u.", ble_name, ble_name_len, ret); + memset_s(ble_name, BD_NAME_LEN, 0, BD_NAME_LEN); + ble_name_len = strlen(BLE_DEFAULT_NAME) + 1; + memcpy_s(ble_name, BD_NAME_LEN,BLE_DEFAULT_NAME,ble_name_len); + } + unsigned char addr[6] = {0}; + unsigned int len = sizeof(addr); + memset(addr,0,6); + bluetooth_get_local_addr(&addr[0],len); + //如果蓝牙名称不正确,按照规则重命名 + char watchName[BD_NAME_LEN]= {0}; memset_s(watchName, sizeof(watchName), 0, sizeof(watchName)); - ret = bluetooth_get_local_name((unsigned char *)watchName, &nameLen); - // 为了实验室测试需要,客户需要自己修改 - if ((nameLen == strlen("WatchDemo") + 1) && (strcmp("WatchDemo", watchName) == 0)) { - uint32_t currentUs = uapi_tcxo_get_us(); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "currentUs 0x%x", currentUs); - // 设置蓝牙名称 - (void)sprintf_s(watchName, sizeof(watchName), "Watch%x", (currentUs & 0xFFFF)); - ret = bluetooth_set_local_name((unsigned char*)watchName, strlen((char*)watchName) + 1); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bluetooth_set_local_name %s ret = %u", watchName, ret); - - // 设置蓝牙地址 - bd_addr_t addr = {{0x1C, 0x1D, 0x2B, 0x0, 0x0, 0x0} ,0}; - addr.addr[3] = currentUs & 0xFF; - addr.addr[4] = (currentUs & 0XFF00) >> 8; - addr.addr[5] = currentUs & 0xFF; - ret = bluetooth_set_local_addr(addr.addr, BD_ADDR_LEN); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bluetooth_set_local_addr [0x%x:0x%x] ret = %u", addr.addr[0], addr.addr[1], ret); - } else { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "watchName: %s", watchName); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "nameLen: %u", nameLen); - } + (void)sprintf_s(watchName, sizeof(watchName), "%s %02X%02X",BLE_DEFAULT_NAME,addr[1],addr[0]); + int watch_name_len = strlen(watchName); + /**表名长度不对,或者内容不对,都要重命名*/ + if (watch_name_len != strlen((char*)ble_name) || strncmp((char*)ble_name,watchName,watch_name_len) != 0 ) + { + ret = bluetooth_set_local_name((unsigned char*)watchName, watch_name_len+1); + if (ret == ERRCODE_SUCC) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bt SetLocalName %s ", watchName); + }else{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bt SetLocalName %s ret = 0x%x", watchName,ret); + } + } + #endif + } +//1关 0开 +void bluetooth_set_auto_reconnect_closed(uint8_t flag) +{ + #ifdef SUPPORT_BLE_SERVICE -void BluetoothModel::Init() + bts_feature_t bts_feature = { 0 }; + bts_feature.bt_auto_reconnect_closed = flag; + errcode_t ret = bts_set_features(&bts_feature); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt bts_set_features ret = 0x%X", ret); + + #endif + +} + +static int g_bluetooth_initialled=0; +static int bluetooth_init_all(void) { + + #ifdef SUPPORT_BLE_SERVICE + + if (g_bluetooth_initialled == 1) return 1; #ifndef SUPPORT_AUTO_OTA errcode_t ret; - // 设置自动回连,ios一键双连依赖此配置 - bts_feature_t bts_feature = { 0 }; - bts_feature.bt_auto_reconnect_closed = 0; - ret = bts_set_features(&bts_feature); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt bts_set_features ret = %u", ret); + + bluetooth_set_auto_reconnect_closed(1); ret = enable_bt_stack(); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt enable_bt_stack ret = %u", ret); // 设置安全连接 + // gap_ble_sec_params_t sec_params = {0}; + // sec_params.bondable = 0x01; + // sec_params.io_capability = GAP_BLE_IO_CAPABILITY_NOINPUTNOOUTPUT;//最好选择没有输入输出IO能力 + // sec_params.sc_enable = 0x00; + // sec_params.sc_mode = GAP_BLE_GAP_SECURITY_MODE1_LEVEL2; + // ret = gap_ble_set_sec_param(&sec_params);//设置配对参数 发起配对弹窗 + gap_ble_sec_params_t sec_param = { 1, GAP_BLE_IO_CAPABILITY_NOINPUTNOOUTPUT, 1, GAP_BLE_GAP_SECURITY_MODE1_LEVEL3 }; + // gap_ble_sec_params_t sec_param = { 1, GAP_BLE_IO_CAPABILITY_NOINPUTNOOUTPUT, 0, GAP_BLE_GAP_SECURITY_MODE1_LEVEL2 }; ret = gap_ble_set_sec_param(&sec_param); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt gap_ble_set_sec_param ret = %u", ret); InitBluetoothInfo(); + + + /********************br init************************/ BtInitCallBacks(); + uapi_pbap_pce_reg_callback(); + BtA2dpInit(); + PhoneServiceInit(); + InitBtHeadsetEvent(); // 蓝牙ct和tg适配初始化 + + if(uapi_dev_runtime_get_safemode_flag()) + { + + gap_remove_all_pairs(); + + uapi_dev_runtime_atuoota_status_status(1); + + BtInitSpp(); + } + + /*******************ble init ****************/ wrapper_ble_register(); #ifdef SUPPORT_ALIPAY_SEC - svr_alipay_bluetooth_init(); + wrapper_gatts_clear_service(); //Alipay BLE +#endif + // svr_alipay_btcallback_reg(); + /***Custom BleService */ +#ifdef SUPPORT_ALIPAY_SEC + //Alipay BLE #endif - BtInitCallBacksEx(); - BtInitGatts(); - BtInitSpp(); - /* 实验室测试需要,开机开广播 */ - BleAdvStart(); + svr_ble_bluetooth_init(); //CUSTOM BLE + + // BtInitCallBacksEx(); //BLE + // BtInitGatts(); //BLE + - SetUpListCase(); - SetUpConnedDevicesList(); + //start reg ble server + wrapper_gatts_service_start(); + // do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_BLE_WRAPPERSTART,NULL,0); + + + /**开始ble广播*/ + // custom_ble_service_start(); + // BleAdvStart(); #endif + g_bluetooth_initialled = 1; + + #endif + + return 0; +} + + +void bluetooth_enable_all(void) +{ + //初始化过的则直接开启扫描即可 + + + if (bluetooth_init_all() == 1) + { + + errcode_t ret; + // 设置自动回连,ios一键双连依赖此配置 + // bts_feature_t bts_feature = { 0 }; + // bts_feature.bt_auto_reconnect_closed = 0; + // ret = bts_set_features(&bts_feature); + // WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt bts_set_features ret = %u", ret); + // gap_ble_sec_params_t sec_param = { 1, GAP_BLE_IO_CAPABILITY_NOINPUTNOOUTPUT, 1, GAP_BLE_GAP_SECURITY_MODE1_LEVEL3 }; + // // gap_ble_sec_params_t sec_param = { 1, GAP_BLE_IO_CAPABILITY_NOINPUTNOOUTPUT, 0, GAP_BLE_GAP_SECURITY_MODE1_LEVEL2 }; + // ret = gap_ble_set_sec_param(&sec_param); + // WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt gap_ble_set_sec_param ret = %u", ret); + + ret = gap_br_set_bt_scan_mode(GAP_SCAN_MODE_CONNECTABLE, 0); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt gap_br_set_bt_scan_mode ret = %u", ret); + /**开始ble广播*/ + // custom_ble_service_start(); + } +} + +void bluetooth_close_all(void) +{ + errcode_t ret; + + /**停止Ble广播,断开链接,清除协议缓存*/ + // custom_ble_service_stop(); + + /** 停止BR广播 */ + + ret = gap_br_set_bt_scan_mode(GAP_SCAN_MODE_NONE, 0); + + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bluetooth_close_all gap_br_set_bt_scan_mode ret = %u", ret); + + /**TODO: 停止BR扫描**/ + if(is_bt_discovering(BT_TRANSPORT_INVALID) || is_bt_discovering(BT_TRANSPORT_BR_EDR) || is_bt_discovering(BT_TRANSPORT_LE)) + { + gap_br_cancel_discovery(); + } + /**TODO: 关闭自动重连**/ + + // 设置自动回连,ios一键双连依赖此配置 + // bts_feature_t bts_feature = { 0 }; + // bts_feature.bt_auto_reconnect_closed = 1; + // bts_feature.bt_a2dp_snk_closed = 1; + // ret = bts_set_features(&bts_feature); + // WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt bts_set_features ret = %u", ret); + + /**TODO: 断开BR链接**/ + bd_addr_t bdaddr={0}; + uapi_get_br_address(&bdaddr); + if (bt_is_acl_connected(&bdaddr)) + { + ret = gap_disconnect_remote_device(&bdaddr); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bluetooth_close_all gap_disconnect_remote_device ret = %u", ret); + } + + //海思不建议使用 disable_bt_stack ,说可能影响 btcore 与 mcore通讯 + // ret = disable_bt_stack(); + // WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "bt disable_bt_stack ret = %u", ret); + } +void BluetoothModel::Init() +{ +// bluetooth_init(); +// InitBluetoothInfo(); +SetUpListCase(); +SetUpConnedDevicesList(); +} + +//清空这个扫描列表 void BluetoothModel::SetCaseListClear() { btScansDevicesList_.clear(); } +//检查给定的蓝牙设备信息是否已经存在于这个列表中 bool BluetoothModel::CheckExistScanList(BluetoothCaseInfo caseInfo) { std::list::iterator node = btScansDevicesList_.begin(); @@ -170,16 +347,19 @@ bool BluetoothModel::CheckExistScanList(BluetoothCaseInfo caseInfo) return false; } +//清空这个扫描列表 void BluetoothModel::SetUpListCase() { SetCaseListClear(); } +//返回这个列表的引用 std::list& BluetoothModel::GetCase() { return btScansDevicesList_; } +//向这个列表中添加蓝牙设备信息 void BluetoothModel::AddCase(BluetoothCaseInfo caseInfo) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AddCase::caseInfo addr: %02x%02x%02x%02x%02x%02x", @@ -190,9 +370,13 @@ void BluetoothModel::AddCase(BluetoothCaseInfo caseInfo) return; } else { btScansDevicesList_.push_back(caseInfo); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "btScansDevicesList_ num = %d",btScansDevicesList_.size()); + if(BluetoothEarListView::GetInstance()) //动态计算扫描出来的设备列表ui高度 + GraphicService::GetInstance()->PostGraphicEvent( + std::bind(&BluetoothEarListView::RefreshBluetoothEarListView, BluetoothEarListView::GetInstance())); } } - +//设置设备的信号强度 void BluetoothModel::SetScansCaseRssi(const bd_addr_t *bdAddr, int rssi) { for (auto it = btScansDevicesList_.begin(); it != btScansDevicesList_.end(); it++) { @@ -214,12 +398,14 @@ bool CompBuletoothInfo(const BluetoothCaseInfo& a, const BluetoothCaseInfo& b) return false; } +//按照信号强度进行排序 void BluetoothModel::SortScansCaseRssi() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothModel::SortScansCaseRssi"); btScansDevicesList_.sort(CompBuletoothInfo); } +//重置设备名称 void BluetoothModel::ResetScanDevicesCase(const BluetoothCaseInfo& caseInfo) { for (auto it = btScansDevicesList_.begin(); it != btScansDevicesList_.end(); it++) { @@ -233,7 +419,7 @@ void BluetoothModel::ResetScanDevicesCase(const BluetoothCaseInfo& caseInfo) } } -/* 已配对设备队列 */ +/* 清空已配对设备队列 */ void BluetoothModel::SetConnedDevicesListClear() { btConnedDevicesList_->Clear(); @@ -247,32 +433,35 @@ void BluetoothModel::SetUpConnedDevicesList() WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothModel btConnedDevicesList_ new fail"); return; } - SetConnedDevicesListClear(); - unsigned int connedDevicesNum = 0; - bool ret = gap_get_paired_devices_num(&connedDevicesNum); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Setup GetPariedDevicesNum ret = %d, num = %d", ret, connedDevicesNum); - - gap_paired_device_info_t *devInfo = (gap_paired_device_info_t*)malloc(sizeof(gap_paired_device_info_t) *connedDevicesNum); - if (devInfo == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DevInfo malloc failed %u", sizeof(gap_paired_device_info_t) *connedDevicesNum); - return; - } - ret = gap_get_paired_devices_list(devInfo, (int *)&connedDevicesNum); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUpConnedDevicesList gap_get_paired_devices_list ret = %d", ret); + + } + SetConnedDevicesListClear(); + unsigned int connedDevicesNum = 0; + int btpower = uapi_dev_runtime_get_bt_powerstat(); - BluetoothCaseInfo caseInfo{}; - for (int i = 0; i < static_cast(connedDevicesNum); ++i) { - if ((gap_get_device_class((const bd_addr_t *)devInfo[i].addr.addr) & 0x200) != 0) { - continue; - } - (void)memcpy_s(caseInfo.addr, BD_ADDR_LEN, - devInfo[i].addr.addr, BD_ADDR_LEN); - (void)memcpy_s(caseInfo.deviceName, BD_NAME_LEN, - devInfo[i].device_name, BD_NAME_LEN); - AddConnedDevicesCase(caseInfo); + bool ret = gap_get_paired_devices_num(&connedDevicesNum); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BT Power %s , Setup GetPariedDevicesNum ret = %d, num = %d", btpower==1?"On":"Off",ret, connedDevicesNum); + + gap_paired_device_info_t *devInfo = (gap_paired_device_info_t*)malloc(sizeof(gap_paired_device_info_t) *connedDevicesNum); + if (devInfo == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DevInfo malloc failed %u", sizeof(gap_paired_device_info_t) *connedDevicesNum); + return; + } + ret = gap_get_paired_devices_list(devInfo, (int *)&connedDevicesNum); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetUpConnedDevicesList gap_get_paired_devices_list ret = %d", ret); + + BluetoothCaseInfo caseInfo{}; + for (int i = 0; i < static_cast(connedDevicesNum); ++i) { + if ((gap_get_device_class((const bd_addr_t *)devInfo[i].addr.addr) & 0x200) != 0) { + continue; } - free(devInfo); + (void)memcpy_s(caseInfo.addr, BD_ADDR_LEN, + devInfo[i].addr.addr, BD_ADDR_LEN); + (void)memcpy_s(caseInfo.deviceName, BD_NAME_LEN, + devInfo[i].device_name, BD_NAME_LEN); + AddConnedDevicesCase(caseInfo); } + free(devInfo); } void BluetoothModel::AddConnedDevicesCase(BluetoothCaseInfo caseInfo) @@ -292,11 +481,17 @@ void BluetoothModel::AddConnedDevicesCase(BluetoothCaseInfo caseInfo) } } +/*返回指向已连接设备列表的引用,以便其他部分的代码可以直接访问和操作这个列表*/ 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", @@ -361,11 +556,13 @@ bool BluetoothModel::GetTagReconnectJump(void) return tagReconnectJump; } +/*设置当前哪个子视图是可见的*/ void BluetoothModel::SetCurView(int16_t viewNum) { curView = viewNum; } +/*获取当前哪个子视图是可见的*/ int BluetoothModel::GetCurView(void) { return curView; @@ -383,6 +580,7 @@ bool BluetoothModel::IsTagConnectView(void) return tagConnectView; } +//设置是否需要跳转连接失败界面 void BluetoothModel::SetTagDisconnectView(bool tag) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothModel::SetTagDisconnectView:%d", tag); @@ -395,29 +593,34 @@ bool BluetoothModel::IsTagDisconnectView(void) return tagDisconnectView; } -void BluetoothModel::SetTagConnectNew(bool tag) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothModel::SetTagConnectNew:%d", tag); - tagConnectNew = tag; -} + +//设置是否返回到已连接过的设备列表视图标志 void BluetoothModel::SetTagReturnToDeviceListView(bool tag) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothModel::SetTagReturnToDeviceListView:%d", tag); tagReturnToDeviceListView = tag; } +//是否返回到已连接过的设备列表视图 bool BluetoothModel::IsTagReturnToDeviceListView(void) { return tagReturnToDeviceListView; } -// 判断断开连接时是否需要马上连接新设备 +// 获取断开连接时是否需要马上连接新设备 bool BluetoothModel::IsTagConnectNew(void) { return tagConnectNew; } +// 设置断开连接时是否需要马上连接新设备 +void BluetoothModel::SetTagConnectNew(bool tag) +{ + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothModel::SetTagConnectNew:%d", tag); + tagConnectNew = tag; +} + void BluetoothModel::SetTagScanDeviceClicked(bool tag) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothModel::SetTagScanDeviceClicked:%d", tag); @@ -430,6 +633,7 @@ bool BluetoothModel::IsTagScanDeviceClicked(void) return tagScanDeviceClicked; } +//检查给定的 BluetoothCaseInfo 结构体实例 caseInfo 所代表的蓝牙设备是否已经存在于已连接设备列表中 bool BluetoothModel::CheckExistConnedList(BluetoothCaseInfo caseInfo) { ListNode *node = btConnedDevicesList_ ->Begin(); @@ -465,7 +669,8 @@ bool BluetoothModel::FindNameByAddr(BluetoothCaseInfo &listInfo, BluetoothCaseIn return false; } } - +//在已连接设备列表 btConnedDevicesList_ 和扫描设备列表 btScansDevicesList_ +//中查找与输入的 BluetoothCaseInfo 结构体实例 caseInfo 地址匹配的设备,并尝试获取该设备的名称 bool BluetoothModel::FindNameFromList(BluetoothCaseInfo *caseInfo) { ListNode *node = btConnedDevicesList_->Begin(); @@ -515,7 +720,6 @@ int BluetoothModel::ConnectRemoteDevice(const bd_addr_t *addr) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ConnectRemoteDevice gap_br_set_bt_scan_mode ret = 0x%x", ret); } errcode_t retVal = gap_connect_remote_device(addr); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ConnectRemoteDevice gap_connect_remote_device ret = 0x%x", retVal); (void)memcpy_s(&remoteConnectAddr, sizeof(bd_addr_t), addr, sizeof(bd_addr_t)); return retVal; } @@ -523,6 +727,11 @@ int BluetoothModel::ConnectRemoteDevice(const bd_addr_t *addr) bool BluetoothModel::ConnectRemoteCheck(const bd_addr_t *addr) { bool ret; + if ((remoteConnectAddr.addr[0] == 0) && (remoteConnectAddr.addr[1] == 0) && + (remoteConnectAddr.addr[2] == 0) && (remoteConnectAddr.addr[3] == 0) && + (remoteConnectAddr.addr[4] == 0) && (remoteConnectAddr.addr[5] == 0)) { + return true; + } if ((remoteConnectAddr.addr[0] == addr->addr[0]) && (remoteConnectAddr.addr[1] == addr->addr[1]) && (remoteConnectAddr.addr[2] == addr->addr[2]) && (remoteConnectAddr.addr[3] == addr->addr[3]) && (remoteConnectAddr.addr[4] == addr->addr[4]) && (remoteConnectAddr.addr[5] == addr->addr[5])) { @@ -563,7 +772,7 @@ static void ChangeScanView() WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothEarPhoneView nullptr"); return; } - bluetoothEarPhoneView->setScanStatus(false); + bluetoothEarPhoneView->setScanStatus(false);// 停止扫描标记 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Bt scan one jumpView"); if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { JumpView *jumpView = JumpView::GetInstance(); @@ -587,6 +796,7 @@ static void ChangeScanView() WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtAnimatorStop"); } +//用于处理蓝牙设备发现的结果 void BluetoothModel::BtGapDiscoveryResultCallbakHandle(const bd_addr_t &bdAddr) { BluetoothCaseInfo caseInfo{}; @@ -597,6 +807,7 @@ void BluetoothModel::BtGapDiscoveryResultCallbakHandle(const bd_addr_t &bdAddr) WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "gap_discovery_result_callback getNameRet(bool): %d nameLen: %d name:%s", getNameRet, nameLen, caseInfo.deviceName); + if (nameLen == 0) { // 过滤未扫描到名字的设备 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "nameLen == 0 return"); return; @@ -630,35 +841,79 @@ void BluetoothModel::BtGapDiscoveryResultCallbakHandle(const bd_addr_t &bdAddr) } WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bt BtGapDiscoveryResultCallback end"); } - +bd_addr_t BtGapPair_bdAddr={0}; void BtGapPairStatusChangedCallback(const bd_addr_t *bdAddr, int status) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtGapPairStatusChangedCallback addr: ****%02x%02x%02x%02x status: %d\n", + #ifdef SUPPORT_BLE_SERVICE + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BtGapPairStatusChangedCallback addr: ****%02x%02x%02x%02x status: %d\n", bdAddr->addr[3], bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0], status); /* addr下标 0 1 2 3 */ + + if(uapi_dev_runtime_get_atuoota_status()) + { + return; + } + + if ((gap_get_device_class(bdAddr) & 0x200) != 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BtGapPairStatusChangedCallback: Mobile Phone Device"); + if(status==GAP_PAIR_PAIRED) + memcpy(&BtGapPair_bdAddr,bdAddr,sizeof(bd_addr_t)); + + if(cm_custom_ble_service_on_flag() && !get_ble_pair()&& (status == GAP_PAIR_PAIRED)) + { + send_pair_succ((bd_addr_t*)bdAddr); + + hand_watch_first_time_Paired(); + + set_br_pair(1); + + } + if( status == GAP_PAIR_PAIRED ) + { + set_br_pair(1); + } + } + + + if (status == GAP_PAIR_PAIRED) { + if (ConnectPhonePresenter::GetInstance() != nullptr) { NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); } + } + + #endif } void BtGapPairRequestedCallback(const bd_addr_t *bdAddr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtGapPairRequestedCallback addr: ****%02x%02x%02x%02x\n", + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BtGapPairRequestedCallback addr: ****%02x%02x%02x%02x\n", bdAddr->addr[3], bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0]); /* addr下标 0 1 2 3 */ } void BtGapPairConfirmedCallback(const bd_addr_t *bdAddr, int req_type, int number) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtGapPairConfirmedCallback addr: ****%02x%02x%02x%02x req_type: %d number: %d\n", + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BtGapPairConfirmedCallback addr: ****%02x%02x%02x%02x req_type: %d number: %d\n", bdAddr->addr[3], bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0], /* addr下标 0 1 2 3 */ req_type, number); } + +static bool test_bt_falg=false; + + +void BluetoothModel::set_test_bt_falg(bool falg) +{ + test_bt_falg=falg; +} + // 回调:扫描结果处理/发现结果上报 -void BtGapDiscoveryResultCallback(const bd_addr_t *bdAddr) +void BtGapDiscoveryResultCallback(const bd_addr_t *bdAddr ) { - if ((gap_get_device_class(bdAddr) & DEVICE_MAJOR_CLASS_PHONE) != 0) { + if ((gap_get_device_class(bdAddr) & DEVICE_MAJOR_CLASS_PHONE) != 0 && test_bt_falg==false) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtGapDiscoveryResultCallback: Mobile Phone Device"); return; } @@ -712,6 +967,7 @@ void HandleBeforeChangeView() } } +//处理蓝牙耳机连接成功的UI操作 static void ACLConnectionSuss(const bd_addr_t &bdAddr) { // 判断是否已退出蓝牙模块(无需跳转) @@ -721,7 +977,7 @@ static void ACLConnectionSuss(const bd_addr_t &bdAddr) return; } // 成功提示 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GAP_ACL_STATE_CONNECTED"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "蓝牙耳机连接成功"); HandleBeforeChangeView(); if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { JumpView *jumpView = JumpView::GetInstance(); @@ -737,16 +993,24 @@ static void ACLConnectionSuss(const bd_addr_t &bdAddr) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainBluetoothView GetInstance fail"); return; } - mainBluetoothView->ChangeView(BluetoothModel::GetInstance()->GetCurView(), TIPSSUCCMESSAGEVIEW); + mainBluetoothView->ChangeView(BluetoothModel::GetInstance()->GetCurView(), TIPSSUCCMESSAGEVIEW);//跳转到连接成功视图 } TipsSuccMessageView *tipsSuccMessageView = TipsSuccMessageView::GetInstance(); if (tipsSuccMessageView == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ACLConnectionSuss tipsSuccMessageView GetInstance fail"); return; } - tipsSuccMessageView->RefreshNameLabel(bdAddr); + tipsSuccMessageView->RefreshNameLabel(bdAddr); //更新连接成功的提示视图的蓝牙名称 + /* -------------------------------------------------------------------------- */ + if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get())) + { + ui_api_vibrate_once_func(); + } + uapi_set_screen_on_api(); + /* -------------------------------------------------------------------------- */ } +//处理蓝牙耳机连接失败操作 static void ACLConnectionFail(const bd_addr_t &bdAddr) { // 判断是否已退出蓝牙模块(无需跳转) @@ -758,7 +1022,7 @@ static void ACLConnectionFail(const bd_addr_t &bdAddr) return; } // 失败提示页 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "conn fail"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "蓝牙耳机连接失败"); HandleBeforeChangeView(); if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { JumpView *jumpView = JumpView::GetInstance(); @@ -781,9 +1045,17 @@ static void ACLConnectionFail(const bd_addr_t &bdAddr) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ACLConnectionFail tipsConnFailMessageView GetInstance fail"); return; } - tipsConnFailMessageView->RefreshNameLabel(bdAddr); + tipsConnFailMessageView->RefreshNameLabel(bdAddr);//更新连接失败的提示视图的蓝牙名称 + /* -------------------------------------------------------------------------- */ + if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb() && (!uapi_sleep_mode_flag_get())) + { + ui_api_vibrate_once_func(); + } + uapi_set_screen_on_api(); + /* -------------------------------------------------------------------------- */ } +//处理断开蓝牙耳机连接的UI操作 static void DisconnectedHandle() { BluetoothModel::GetInstance()->SetTagDisconnectView(false); @@ -797,22 +1069,18 @@ static void DisconnectedHandle() WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisconnectedHandle deviceList nullptr"); return; } - deviceList->RefreshList(); - BluetoothOptionsView *bluetoothOptionsView = BluetoothOptionsView::GetInstance(); - if (bluetoothOptionsView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AclStateChangedCallback bluetoothOptionsView == nullptr"); - return; - } - bluetoothOptionsView->RefreshText(); + deviceList->RefreshList();//刷新列表 } void BluetoothModel::BtGapAclStateChangedHandle(gap_acl_state_t state, unsigned int reason, const bd_addr_t &bdAddr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP,"ACL回调,%d",state); bool tag = BluetoothModel::GetInstance()->IsTagScanDeviceClicked(); if ((reason == 0x13) || (reason == 0x14) || (reason == 0x15) || (reason == 0x3D) || (reason == 0x08 && (!tag))) { // 连接断开 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "The peer end is disconnected."); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "蓝牙设备主动断开与手表连接 reason is %x", reason); DisconnectedHandle(); } else if (reason == 0x16) { // 主动断开连接 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "手表主动断开与蓝牙设备连接,reason is%x", reason); DisconnectedHandle(); BluetoothCaseInfo *onClickBtCaseInfo = BluetoothModel::GetInstance()->GetTempMacValue(); if (BluetoothModel::GetInstance()->IsTagConnectNew()) { @@ -824,13 +1092,14 @@ void BluetoothModel::BtGapAclStateChangedHandle(gap_acl_state_t state, unsigned SetTagDisconnectView(false); } + BluetoothCaseInfo *onClickBtCaseInfo = GetTempMacValue(); + if ((state == GAP_ACL_STATE_CONNECTED) || (state == GAP_ACL_STATE_LE_CONNECTED)) { SetLastConnedAddr(&bdAddr); // 将数据存入设备列表 - BluetoothCaseInfo *info = GetTempMacValue(); - tag = CheckExistConnedList(*info); - if ((!tag) && (memcmp(info->addr, bdAddr.addr, BD_ADDR_LEN) == 0)) { - AddConnedDevicesCase(*info); + tag = CheckExistConnedList(*onClickBtCaseInfo); + if (!tag) { + AddConnedDevicesCase(*onClickBtCaseInfo); } } else { ACLConnectionFail(bdAddr); @@ -841,38 +1110,91 @@ void BluetoothModel::BtGapAclStateChangedHandle(gap_acl_state_t state, unsigned int32_t retA2dp = a2dp_src_connect(&bdAddr); if (retA2dp) { ACLConnectionFail(bdAddr); + #ifdef SUPPORT_CAT1_HFP_AG_SERV + errcode_t rethfp= hfp_ag_cmd_conn_hfp(&bdAddr); + if(!rethfp) + { + errcode_t retVal = ConnectRemoteDevice((const bd_addr_t *)&onClickBtCaseInfo->addr); + } + #endif + } + else + { + errcode_t retVal = ConnectRemoteDevice((const bd_addr_t *)&onClickBtCaseInfo->addr); } WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "a2dp_src_connect result 0x%x", retA2dp); + } else { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ingore a2dp_src_connect"); } + + } } +static uint8_t ALC_State_flag=0; + +static uint8_t ALC_connect_hfp_flag=0; + +static uint8_t ALC_connect_A2DP_flag=0; + +static bd_addr_t ACL_bdAdd; + +void uapi_set_ACL_br_address(const bd_addr_t * bdAddr) +{ + memcpy(&ACL_bdAdd,bdAddr,sizeof(bd_addr_t)); +} // 回调:ACL连接状态上报 void GapAclStateChangedCallback(const bd_addr_t *bdAddr, gap_acl_state_t state, unsigned int reason) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "bt GapAclStateChangedCallback state %d, reason %x succ or err", state, reason); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "addr: %02x%02x%02x%02x%02x%02x", + #ifdef SUPPORT_BLE_SERVICE + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bt GapAclStateChangedCallback state %d, reason %x succ or err", state, reason); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "addr: %02x%02x%02x%02x%02x%02x", bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* mac下标 0 1 2 3 4 5 */ bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0]); /* mac下标 0 1 2 3 4 5 */ - static bd_addr_t gapAclConnectAddr{0}; /* 连接后保存手机地址,手表清除手机配对后查询不到class比较手机地址 */ - if ((gap_get_device_class(bdAddr) & 0x200) != 0 || memcmp(gapAclConnectAddr.addr, bdAddr->addr, BD_ADDR_LEN) == 0) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GapAclStateChangedCallback: Mobile Phone Device"); + + if(uapi_dev_runtime_get_atuoota_status()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bt GapAclStateChangedCallback state %d, reason %x succ or err", state, reason); + return; + } + + if(!uapi_dev_runtime_get_bt_powerstat()) + { + gap_disconnect_remote_device(bdAddr); + } + + if ((gap_get_device_class(bdAddr) & 0x200) != 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GapAclStateChangedCallback: Mobile Phone Device"); if (state == GAP_ACL_STATE_DISCONNECTED) { /* 通知msg_center,ble状态仍用bt状态,此处不区分 */ - MsgCenterSendMsg(BT_DISCONNECTED_TO_MSGCENTER, 0, nullptr, 0); + SendMsgToMsgCenterService(BT_DISCONNECTED_TO_MSGCENTER, 0, nullptr, 0); SendMsgToUIService(BT_DISCONNECTED_TO_UI, 0, nullptr, 0); + + + + gap_br_set_bt_scan_mode(GAP_SCAN_MODE_CONNECTABLE, 0); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GAP_SCAN_MODE_CONNECTABLE"); + } else if (state == GAP_ACL_STATE_CONNECTED) { - (void)memcpy_s(gapAclConnectAddr.addr, BD_ADDR_LEN, bdAddr->addr, BD_ADDR_LEN); - MsgCenterSendMsg(BT_CONNECTED_TO_MSGCENTER, 0, nullptr, 0); + SendMsgToMsgCenterService(BT_CONNECTED_TO_MSGCENTER, 0, nullptr, 0); SendMsgToUIService(BT_CONNECTED_TO_UI, 0, nullptr, 0); + + uapi_set_ACL_br_address(bdAddr); + + gap_br_set_bt_scan_mode(GAP_SCAN_MODE_NONE, 0); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GAP_SCAN_MODE_NONE"); + } return; } - GraphicService::GetInstance()->PostGraphicEvent( std::bind(&BluetoothModel::BtGapAclStateChangedHandle, BluetoothModel::GetInstance(), state, reason, *bdAddr)); + + #endif + } // 回调:远端设备名称变化 @@ -914,7 +1236,7 @@ static void A2dpSrcConnectstateChanged(bd_addr_t *bdAddr, int connState) bdAddr->addr[5], bdAddr->addr[4], bdAddr->addr[3], /* 5 4 3 idx */ bdAddr->addr[2], bdAddr->addr[1], bdAddr->addr[0], connState); /* 2 1 0 idx */ if ((gap_get_device_class(bdAddr) & 0x200) != 0) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "a2dp_src_connectstateChangedCb: Mobile Phone Device"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "a2dp_src_connectstateChangedCb: Mobile Phone Device"); return; } if (connState == PROFILE_STATE_CONNECTED) { @@ -922,17 +1244,38 @@ static void A2dpSrcConnectstateChanged(bd_addr_t *bdAddr, int connState) WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "avrcp_ct_connect ret = 0x%x", ret); PhoneAudioManagerSetDeviceConnState(OUT_BLUETOOTH_A2DP, AUDIO_DEVICE_CONNECTED); GraphicService::GetInstance()->PostGraphicEvent(std::bind(ACLConnectionSuss, *bdAddr)); + + #ifdef SUPPORT_BLE_SERVICE + SendMsgToUIService(EARPHONE_CONNECTED_TO_UI, 0, nullptr, 0); + + + + uapi_dev_runtime_set_earphone_connect_stat(1); + uapi_save_runtime_log(RUNTIME_LOG_BR_CONNECT_A2DP_HEADSET); + if(headset_Is_connect() == false) + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_CONNECT_AG, nullptr, 0); + + #endif + } if (connState == PROFILE_STATE_DISCONNECTED) { PhoneAudioManagerSetDeviceConnState(OUT_BLUETOOTH_A2DP, AUDIO_DEVICE_DISCONNECTED); GraphicService::GetInstance()->PostGraphicEvent(std::bind(ACLConnectionFail, *bdAddr)); + + #ifdef SUPPORT_BLE_SERVICE + SendMsgToUIService(EARPHONE_DISCONNECTED_TO_UI, 0, nullptr, 0); + #endif + + uapi_save_runtime_log(RUNTIME_LOG_BR_DISCONNECT_A2DP_HEADSET); /* 实验室测试耳机回连场景,用户根据需要调整策略 */ bool ret = gap_br_set_bt_scan_mode(GAP_SCAN_MODE_CONNECTABLE_GENERAL_DISCOVERABLE, 60); // start scan if (!ret) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "a2dp disc: gap_br_set_bt_scan_mode ret = 0x%x", ret); } + uapi_dev_runtime_set_earphone_connect_stat(0); } + } static void A2dpSrcPlayingStateChanged(bd_addr_t *bdAddr, int playState) @@ -956,17 +1299,18 @@ static void A2dpSrcConfigureChanged(bd_addr_t *bdAddr, a2dp_codec_info_t *info) static void BleConnStateChangeCallback(unsigned short connId, bd_addr_t *addr, gap_ble_conn_state_t connState, gap_ble_pair_state_t pairState, gap_ble_disc_reason_t discReason) { + + #ifdef SUPPORT_BLE_SERVICE WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BleConnStateChangeCallback connId 0x%x, connState 0x%x, pairState 0x%x", connId, connState, pairState); if (GAP_BLE_STATE_DISCONNECTED == connState) { // restart ble adv when disconnected /* 通知msg_center,ble状态仍用bt状态,此处不区分 */ - MsgCenterSendMsg(BT_DISCONNECTED_TO_MSGCENTER, 0, nullptr, 0); - msg_center_set_ble_conn_state(GAP_BLE_STATE_DISCONNECTED); + SendMsgToMsgCenterService(BT_DISCONNECTED_TO_MSGCENTER, 0, nullptr, 0); } else { - MsgCenterSendMsg(BT_CONNECTED_TO_MSGCENTER, 0, nullptr, 0); - msg_center_set_ble_conn_state(GAP_BLE_STATE_CONNECTED); + SendMsgToMsgCenterService(BT_CONNECTED_TO_MSGCENTER, 0, nullptr, 0); (void)memcpy_s(&g_bd_addr, sizeof(bd_addr_t), addr, sizeof(bd_addr_t)); } + #endif } static void BleAdvStartCallback(uint8_t advId, adv_status_t status) @@ -988,8 +1332,9 @@ static void BleAdvStopCallback(uint8_t advId, adv_status_t status) static void BleAdvTerminateCallback(uint8_t advId, adv_status_t status) { if (g_sample_adv_id == advId) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BleAdvTerminateCallback advId: %d, status:%d\n", advId, status); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "?????????? BleAdvTerminateCallback advId: %d, status:%d\n", advId, status); BluetoothModel::GetInstance()->SetAdvStartState(false); + // 此处开广播是为了实验室测试需要,客户需要自己修改 BleAdvStart(); } @@ -997,11 +1342,11 @@ static void BleAdvTerminateCallback(uint8_t advId, adv_status_t status) static void BtGattsServiceAddCallback(uint8_t serverId, bt_uuid_t *uuid, uint16_t srvcHandle, errcode_t status) { - if ((uuid->uuid_len == sizeof(uint16_t)) && (*((uint16_t*)uuid->uuid) == 0xF01F)) { + if ((uuid->uuid_len == sizeof(uint16_t)) && (*((uint16_t*)uuid->uuid) == 0x1FF0)) { WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BtGattsServiceAddCallback 0x%x 0x%x 0x%x", status, serverId, srvcHandle); - uint16_t sample_id = 0xF11F; - uint16_t diag_id = 0xF21F; + uint16_t sample_id = 0x1FF1; + uint16_t diag_id = 0x1FF2; gatts_add_chara_info_t character; uint16_t value = 0; @@ -1019,7 +1364,7 @@ static void BtGattsServiceAddCallback(uint8_t serverId, bt_uuid_t *uuid, uint16_ character.chara_uuid.uuid_len = sizeof(diag_id); memcpy_s(character.chara_uuid.uuid, sizeof(character.chara_uuid.uuid), (char *)&diag_id, sizeof(diag_id)); character.permissions = GATT_ATTRIBUTE_PERMISSION_WRITE | GATT_ATTRIBUTE_PERMISSION_READ; - character.properties = GATT_CHARACTER_PROPERTY_BIT_WRITE | GATT_CHARACTER_PROPERTY_BIT_READ | GATT_CHARACTER_PROPERTY_BIT_NOTIFY; + character.properties = GATT_CHARACTER_PROPERTY_BIT_WRITE | GATT_CHARACTER_PROPERTY_BIT_READ; character.value_len = (uint16_t)sizeof(value); character.value = (uint8_t *)(&value); @@ -1032,30 +1377,17 @@ static void BtGattsServiceAddCallback(uint8_t serverId, bt_uuid_t *uuid, uint16_ static void BtGattsCharacteristicAddCallback(uint8_t serverId, bt_uuid_t *uuid, uint16_t srvcHandle, gatts_add_character_result_t *result, errcode_t status) { - if ((uuid->uuid_len == sizeof(uint16_t)) && (*((uint16_t*)uuid->uuid) == 0xF11F)) { + if ((uuid->uuid_len == sizeof(uint16_t)) && (*((uint16_t*)uuid->uuid) == 0x1FF1)) { g_sample_characteristic_handle = result->value_handle; WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BtGattsCharacteristicAddCallback 0x%x 0x%x 0x%x 0x%x", status, serverId, srvcHandle, g_sample_characteristic_handle); } - if ((uuid->uuid_len == sizeof(uint16_t)) && (*((uint16_t*)uuid->uuid) == 0xF21F)) { + if ((uuid->uuid_len == sizeof(uint16_t)) && (*((uint16_t*)uuid->uuid) == 0x1FF2)) { g_diag_characteristic_handle = result->value_handle; WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BtGattsCharacteristicAddCallback 0x%x 0x%x 0x%x 0x%x", status, serverId, srvcHandle, g_diag_characteristic_handle); - - uint8_t ccc_val[] = { 0x01, 0x00 }; - uint16_t diag_desc = 0x0229; - gatts_add_desc_info_t descriptor; - memset_s(&descriptor, sizeof(gatts_add_desc_info_t), 0, sizeof(gatts_add_desc_info_t)); - descriptor.desc_uuid.uuid_len = sizeof(diag_desc); - memcpy_s(descriptor.desc_uuid.uuid, sizeof(descriptor.desc_uuid.uuid), (char *)&diag_desc, sizeof(diag_desc)); - descriptor.permissions = GATT_ATTRIBUTE_PERMISSION_READ | GATT_ATTRIBUTE_PERMISSION_WRITE; - descriptor.value_len = (uint16_t)sizeof(ccc_val); - descriptor.value = ccc_val; - int ret = gatts_add_descriptor(serverId, srvcHandle, &descriptor); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "gatts_add_descriptor diag_desc ret 0x%x", ret); } - - if (g_sample_characteristic_handle != 0 && g_diag_characteristic_handle !=0 && g_diag_desc_handle != 0) { + if (g_sample_characteristic_handle != 0 && g_diag_characteristic_handle !=0) { int ret = gatts_start_service(serverId, srvcHandle); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "gatts_start_service ret 0x%x", ret); } @@ -1066,12 +1398,6 @@ static void BtGattsDescriptorAddCallback(uint8_t serverId, bt_uuid_t *uuid, uint if (g_sample_svr_handle == srvcHandle) { WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BtGattsDescriptorAddCallback 0x%x 0x%x 0x%x 0x%x", status, serverId, srvcHandle, descriptorHandle); - g_diag_desc_handle = descriptorHandle; - } - - if (g_sample_characteristic_handle != 0 && g_diag_characteristic_handle !=0 && g_diag_desc_handle != 0) { - int ret = gatts_start_service(serverId, srvcHandle); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "gatts_start_service ret 0x%x", ret); } } @@ -1094,16 +1420,16 @@ static void BtGattsServiceDeleteCallback(uint8_t serverId, errcode_t status) static void BtGattsRequestReadCallback(uint8_t serverId, uint16_t connId, gatts_req_read_cb_t *readCbPara, errcode_t status) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtGattsRequestReadCallback handle = %u", readCbPara->handle); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BtGattsRequestReadCallback"); } static void BtGattsRequestWriteCallback(uint8_t serverId, uint16_t connId, gatts_req_write_cb_t *writeCbPara, errcode_t status) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtGattsRequestWriteCallback handle = %u", writeCbPara->handle); if (g_sample_characteristic_handle == writeCbPara->handle) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtGattsRequestWriteCallback handle = %u", writeCbPara->handle); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BtGattsRequestWriteCallback"); if (writeCbPara->length == 9) { - if (memcmp("open ctkd", writeCbPara->value, writeCbPara->length) == 0) { + uint8_t ctkd[] = {'o', 'p', 'e', 'n', ' ', 'c', 't', 'k', 'd'}; + if (memcmp(ctkd, writeCbPara->value, writeCbPara->length) == 0) { WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "enable ctkd"); // 一键双连使能(依赖安全连接参数配置) errcode_t ret = gap_ble_set_ctkd_enable(true); @@ -1111,29 +1437,19 @@ static void BtGattsRequestWriteCallback(uint8_t serverId, uint16_t connId, gatts // 发起ble配对 ret = gap_ble_pair_remote_device(&g_bd_addr); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "gap_ble_pair_remote_device ret = %u ", ret); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "gap_ble_pair_remote_device ret = %u ", ret); } } else if (writeCbPara->length == 10) { - if (memcmp("close ctkd", writeCbPara->value, writeCbPara->length) == 0) { + uint8_t ctkd[] = {'c', 'l', 'o', 's', 'e', ' ', 'c', 't', 'k', 'd'}; + if (memcmp(ctkd, writeCbPara->value, writeCbPara->length) == 0) { // 一键双连去使能 errcode_t ret = gap_ble_set_ctkd_enable(false); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "gap_ble_set_ctkd_disable ret = %u", ret); } } } else if (g_diag_characteristic_handle == writeCbPara->handle) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "diag_gatt_write_req_cbk handle = %u", writeCbPara->handle); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "diag_gatt_write_req_cbk"); diag_gatt_write_req_cbk(serverId, connId, writeCbPara, status); - } else if (g_diag_desc_handle == writeCbPara->handle) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "diag_gatt_set_handle handle = %u", writeCbPara->handle); - if ((writeCbPara->length == 2) && (*(char*)(writeCbPara->value) == 1)) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "open gatt channel"); - diag_gatt_set_handle(serverId, connId, g_diag_characteristic_handle); - msg_center_set_trans_channel(DIAG_FRAME_FID_BT); - } else if ((writeCbPara->length == 2) && (*(char*)(writeCbPara->value) == 0)) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "close gatt channel"); - diag_gatt_set_handle(0, 0, 0); - msg_center_set_trans_channel(DIAG_FRAME_FID_PHONE); - } } } @@ -1141,6 +1457,21 @@ static void BtGattsMtuChangedCallback(uint8_t serverId, uint16_t connId, uint16_ { WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BtGattsMtuChangedCallback connId = %u mtuSize = %u", connId, mtuSize); } +/* 与设备建立A2DP连接 */ +static int wstp_a2dp_snk_connect(const bd_addr_t *bd_addr) +{ + int ret = a2dp_snk_connect(bd_addr); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP,"a2dp_snk_connect ret(int): %x\n", ret); + return ret; +} + +/* 与设备断开A2DP连接 */ +static int wstp_a2dp_snk_disconnect(const bd_addr_t *bd_addr) +{ + int ret = a2dp_snk_disconnect(bd_addr); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP,"a2dp_snk_disconnect ret(int): %x\n", ret); + return ret; +} static void BtA2dpSnkAcceptTimerStop(void) { @@ -1190,20 +1521,20 @@ static errcode_t BtA2dpSnkStartAcceptTimer(void) static int32_t BtA2dpSnkAudioCreate() { #if MEDIA_A2DP_SNK_INTERFACE - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "audioFormat %d channelCount %d sampleRate %d \n", + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "audioFormat %d channelCount %d sampleRate %d \n", g_audio_format_config.audioFormat, g_audio_format_config.channelCount, g_audio_format_config.sampleRate); int32_t ret = AudioManagerA2dpSinkSetParam(g_audio_format_config); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "AudioManagerA2dpSinkSetParam ret %x\n", ret); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AudioManagerA2dpSinkSetParam ret %x\n", ret); ret = AudioManagerA2dpSinkCreate(); - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "AudioManagerA2dpSinkCreate ret %x\n", ret); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AudioManagerA2dpSinkCreate ret %x\n", ret); #endif /* 起定时器接受音乐开始请求 */ (void)BtA2dpSnkStartAcceptTimer(); return 0; } -static int32_t BtA2dpSnkAudioDestroy() +int32_t BtA2dpSnkAudioDestroy(void) { #if MEDIA_A2DP_SNK_INTERFACE int32_t ret = AudioManagerA2dpSinkDestroy(); @@ -1212,10 +1543,68 @@ static int32_t BtA2dpSnkAudioDestroy() return 0; } +//a2dp sink端 状态改变回调 static void BtA2dpSnkConnectStateChangedCb(bd_addr_t *bd_addr, int conn_state) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "addr: ****%02x%02x%02x%02x conn_state: %x\n", + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "addr: ****%02x%02x%02x%02x conn_state: %x\n", bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0], conn_state); /* 3 2 1 0 idx */ + (void)memcpy_s(&g_bd_addr, sizeof(bd_addr_t), bd_addr, sizeof(bd_addr_t)); + if(conn_state==PROFILE_STATE_DISCONNECTING || conn_state==PROFILE_STATE_DISCONNECTED) + { + //if(0==uapi_a2dp_snk_get_device_connect_state() && 0==uapi_hfp_connect_state()) + { + #ifdef SUPPORT_BLE_SERVICE + SendMsgToUIService(BT_DISCONNECTED_TO_UI, 0, nullptr, 0); + SendMsgToMsgCenterService(BT_DISCONNECTED_TO_MSGCENTER, 0, nullptr, 0); + #endif + + } + + uapi_save_runtime_log(RUNTIME_LOG_BR_DISCONNECT_A2DP); + + + } + else if (conn_state==PROFILE_STATE_CONNECTING || conn_state==PROFILE_STATE_CONNECTED) + { +#ifdef BR_DISCONNECT + if(!cm_get_A2DP_switch()) + { + uapi_a2dp_snk_disconnect(); + return; + } + + if(cm_get_HFP_switch() && uapi_hfp_connect_state()==0) + { + uapi_hfp_connect(); + } +#endif + +#ifdef SUPPORT_BLE_SERVICE + SendMsgToUIService(BT_CONNECTED_TO_UI, 0, nullptr, 0); + SendMsgToMsgCenterService(BT_CONNECTED_TO_MSGCENTER, 0, nullptr, 0); + #endif + + + uapi_save_runtime_log(RUNTIME_LOG_BR_CONNECT_A2DP); + // if(pbap_pce_get_device_connect_state(bd_addr)==PROFILE_STATE_DISCONNECTING || + // pbap_pce_get_device_connect_state(bd_addr)==PROFILE_STATE_DISCONNECTED) + // uapi_pbap_cmd_start_client(); + // if(conn_state==PROFILE_STATE_CONNECTED) + // { + // if(pbap_pce_get_device_connect_state(bd_addr)==PROFILE_STATE_DISCONNECTED) + // uapi_connect_pbap_pce(); + // else + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"pbap_pce_get_device_connect_state(int): %X\n", pbap_pce_get_device_connect_state(bd_addr)); + + // } + + + + } + + + + } static void BtA2dpSnkStartStreamReqCb(bd_addr_t *bd_addr) @@ -1223,14 +1612,28 @@ static void BtA2dpSnkStartStreamReqCb(bd_addr_t *bd_addr) WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "addr: ****%02x%02x%02x%02x \n", bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0]); /* 3 2 1 0 idx */ BtA2dpSnkAudioCreate(); + + uapi_save_runtime_log(RUNTIME_LOG_BR_A2DP_SNK_START_STREAM); + + if(PlayersModel::GetInstance()->GetMusicSource())//如果是手机音乐才更新显示 + GraphicService::GetInstance()->PostGraphicEvent(std::bind(&OHOS::PlayersModel::set_player_state, OHOS::PlayersModel::GetInstance(),true)); + // PlayersModel::GetInstance()->get_avrcp_ct_get_element_attributes(); } static void BtA2dpSnkPlayingStateChangedCb(bd_addr_t *bd_addr, int playing_state) { WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "addr: ****%02x%02x%02x%02x playing_state: %x\n", bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0], playing_state); /* 3 2 1 0 idx */ + if (playing_state == A2DP_NOT_PLAYING) { + if(PlayersModel::GetInstance()->GetMusicSource())//如果是手机音乐才更新显示 + GraphicService::GetInstance()->PostGraphicEvent(std::bind(&OHOS::PlayersModel::set_player_state, OHOS::PlayersModel::GetInstance(),false)); BtA2dpSnkAudioDestroy(); + uapi_save_runtime_log(RUNTIME_LOG_BR_A2DP_SNK_NOT_PLAYING); + } + else + { + uapi_save_runtime_log(RUNTIME_LOG_BR_A2DP_SNK_PLAYING); } } @@ -1287,9 +1690,48 @@ static a2dp_snk_callbacks_t g_a2dp_snk_callbacks = { BtA2dpSnkPlayingStateChangedCb, BtA2dpSnkConfigChangedCb }; +void BtA2dpInit(void) +{ + /* a2dp source */ + g_a2dpSrcCallbacks.connectstate_changed_cb = A2dpSrcConnectstateChanged; + g_a2dpSrcCallbacks.configuration_changed_cb = A2dpSrcConfigureChanged; + g_a2dpSrcCallbacks.playing_state_changed_cb = A2dpSrcPlayingStateChanged; + a2dp_src_register_callbacks(&g_a2dpSrcCallbacks); + /* a2dp sink */ + a2dp_snk_register_callbacks(&g_a2dp_snk_callbacks); +} + +void BtA2dpDeInit(void) +{ + a2dp_src_deregister_callbacks(&g_a2dpSrcCallbacks); + a2dp_snk_deregister_callbacks(&g_a2dp_snk_callbacks); + +} +static void sample_gap_state_changed_callback(const int transport, const int status) +{ + printf("gap_state_changed_callback transport: %d status: %d\n", transport, status); +} -void BtInitCallBacks() +static void sample_gap_scan_mode_changed_callback(int mode) { + printf("gap_scan_mode_changed_callback mode: %d\n", mode); + + if ((gap_get_device_class(&ACL_bdAdd) & 0x200) != 0) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sample_gap_scan_mode_changed_callback: Mobile Phone Device"); + if(bt_is_acl_connected(&ACL_bdAdd) && mode!=GAP_SCAN_MODE_NONE) + { + gap_br_set_bt_scan_mode(GAP_SCAN_MODE_NONE, 0); + } + } + + +} + +void BtInitCallBacks(void) +{ + g_btGapCallBacks .scan_mode_changed_callback=sample_gap_scan_mode_changed_callback; + g_btGapCallBacks.state_change_callback=sample_gap_state_changed_callback; g_btGapCallBacks.discovery_result_callback = BtGapDiscoveryResultCallback; g_btGapCallBacks.discovery_state_changed_callback = BtGapDiscoveryStateChangedCallback; g_btGapCallBacks.acl_state_changed_callbak = GapAclStateChangedCallback; @@ -1301,13 +1743,6 @@ void BtInitCallBacks() g_btGapCallBacks.pair_confiremed_callback = BtGapPairConfirmedCallback; gap_register_callbacks(&g_btGapCallBacks); - g_a2dpSrcCallbacks.connectstate_changed_cb = A2dpSrcConnectstateChanged; - g_a2dpSrcCallbacks.configuration_changed_cb = A2dpSrcConfigureChanged; - g_a2dpSrcCallbacks.playing_state_changed_cb = A2dpSrcPlayingStateChanged; - a2dp_src_register_callbacks(&g_a2dpSrcCallbacks); - - /* a2dp sink */ - a2dp_snk_register_callbacks(&g_a2dp_snk_callbacks); } void BtInitCallBacksEx() @@ -1315,8 +1750,8 @@ void BtInitCallBacksEx() g_gapBleCallbacks.conn_state_change_cb = BleConnStateChangeCallback; g_gapBleCallbacks.start_adv_cb = BleAdvStartCallback; g_gapBleCallbacks.stop_adv_cb = BleAdvStopCallback; - g_gapBleCallbacks.terminate_adv_cb = BleAdvTerminateCallback; - wrapper_gap_ble_register_callbacks(&g_gapBleCallbacks); + g_gapBleCallbacks.terminate_adv_cb = BleAdvTerminateCallback; + wrapper_gap_ble_register_callbacks(&g_gapBleCallbacks); g_btGattsCallbacks.add_service_cb = BtGattsServiceAddCallback; g_btGattsCallbacks.add_characteristic_cb = BtGattsCharacteristicAddCallback; @@ -1332,8 +1767,8 @@ void BtInitCallBacksEx() void BtInitGatts(void) { - uint16_t id = 0xF01F; - uint16_t ser_id = 0xFF1F; + uint16_t id = 0x1FF0; + uint16_t ser_id = 0x1FFF; uint8_t serverId = 0; bt_uuid_t uuid; int ret; @@ -1347,8 +1782,6 @@ void BtInitGatts(void) memcpy_s(uuid.uuid, sizeof(uuid.uuid), (char *)&id, sizeof(id)); ret = wrapper_gatts_add_service(serverId, &uuid, true); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "gatts_add_service ret: 0x%x", ret); - - wrapper_gatts_service_start(); } static uint8_t Char2Num(int8_t c) @@ -1461,16 +1894,227 @@ void BleAdvStart(void) } gap_ble_adv_params_t adv_para; memset_s(&adv_para, sizeof(gap_ble_adv_params_t), 0, sizeof(gap_ble_adv_params_t)); - adv_para.min_interval = 0x30; - adv_para.max_interval = 0x60; + adv_para.min_interval = 0x30;//140;//0x30; + adv_para.max_interval = 0x60;//160;//0x60; adv_para.adv_type = GAP_BLE_ADV_CONN_SCAN_UNDIR; adv_para.channel_map = 0x7; adv_para.duration = 0; + gap_ble_set_adv_param(advId, &adv_para); gap_ble_set_local_appearance(GAP_BLE_APPEARANCE_TYPE_GENERIC_WATCH); errcode_t ret = gap_ble_start_adv(advId); WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "BleAdvStart bt gap_ble_start_adv ret = 0x%x", ret); } +//////////////////////////////////A2DP sink端 代码/////////////////////////////////////////////// + +int get_BT_is_init() +{ + return g_bluetooth_initialled; +} + +int uapi_a2dp_snk_get_device_connect_state() +{ + if(get_BT_is_init()==0) + { + return 0; + } + + int ret = a2dp_snk_get_device_connect_state(&g_bd_addr); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP,"state(int): %d\n", ret); + + if(ret==PROFILE_STATE_CONNECTING || ret==PROFILE_STATE_CONNECTED) + return 1; + else + return 0; +} + + +void uapi_get_br_address(bd_addr_t *bdaddr) +{ + #ifdef SUPPORT_BLE_SERVICE + if(BtGapPair_bdAddr.addr[0]==0 && BtGapPair_bdAddr.addr[1]==0 && + BtGapPair_bdAddr.addr[2]==0 && BtGapPair_bdAddr.addr[3]==0 ) + { + uint8_t MacType = 0; + uint8_t mac_data[6]; + memset(mac_data,0,6); + GetwatchSaveMac(mac_data,&MacType); + BtGapPair_bdAddr.addr[0]=mac_data[0]; + BtGapPair_bdAddr.addr[1]=mac_data[1]; + BtGapPair_bdAddr.addr[2]=mac_data[2]; + BtGapPair_bdAddr.addr[3]=mac_data[3]; + BtGapPair_bdAddr.addr[4]=mac_data[4]; + BtGapPair_bdAddr.addr[5]=mac_data[5]; + BtGapPair_bdAddr.type=MacType; + } + memcpy(bdaddr,&BtGapPair_bdAddr,sizeof(bd_addr_t)); +#endif + + +} + +void uapi_set_br_address(bd_addr_t *bdaddr) +{ + memcpy(&BtGapPair_bdAddr,bdaddr,sizeof(bd_addr_t)); +} + +static uint8_t br_cmd=0; +int uapi_a2dp_snk_connect() +{ + br_cmd=BR_A2DP_CONNECT; + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_BR_CONNECT,&br_cmd,sizeof(br_cmd)); + return 0; + +} + + +int uapi_a2dp_snk_connect_() +{ + + if(get_BT_is_init()==0) + { + return 0; + } + + bd_addr_t bdaddr={0}; + uapi_get_br_address(&bdaddr); + + int ret = a2dp_snk_connect(&bdaddr); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "addr: ****%02x%02x%02x%02x g_bd_addr.type: %x\n", + bdaddr.addr[3], bdaddr.addr[2], bdaddr.addr[1], bdaddr.addr[0], bdaddr.type); /* 3 2 1 0 idx */ + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"state(int): %x\n", ret); + return ret; +} + +int uapi_a2dp_snk_disconnect() +{ + br_cmd=BR_A2DP_DISCONNECT; + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_BR_CONNECT,&br_cmd,sizeof(br_cmd)); + return 0; +} + + +int uapi_a2dp_snk_disconnect_() +{ + if(get_BT_is_init()==0) + { + return 0; + } + + bd_addr_t bdaddr={0}; + uapi_get_br_address(&bdaddr); + + int ret = a2dp_snk_disconnect(&bdaddr); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"state(int): %X\n", ret); + return ret; +} + +// int uapi_disconnect_remote_device_() +// { +// do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_BR_CONNECT,&br_cmd,sizeof(br_cmd)); +// return 0; +// } + + +int uapi_disconnect_remote_device() +{ + bd_addr_t bdaddr={0}; + uapi_get_br_address(&bdaddr); + + if (bt_is_acl_connected(&bdaddr)) + { + + int ret = gap_disconnect_remote_device(&bdaddr); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetooth_close_all gap_disconnect_remote_device ret = %u", ret); + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bt_is_acl_connected bt_acl_is True"); + } + return 0; +} + + +int uapi_get_acl_connect_state() +{ + bd_addr_t bdaddr={0}; + uapi_get_br_address(&bdaddr); + if (bt_is_acl_connected(&bdaddr)) + { + return 1; + } + else + { + return 0; + } +} + +int uapi_set_acl_connect_hfp() +{ + ALC_connect_hfp_flag=1; + return 0; +} + +int uapi_set_acl_connect_A2DP() +{ + ALC_connect_A2DP_flag=1; + return 0; +} + + +int uapi_reconnect_() +{ + + br_cmd=BR_RECONNECT; + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_BR_CONNECT,&br_cmd,sizeof(br_cmd)); + return 0; +} + + +int uapi_reconnect(void) +{ + bd_addr_t bdaddr={0}; + uapi_get_br_address(&bdaddr); + int ret=gap_reconnect_media_device(&bdaddr); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,"ret(int): %X\n", ret); + + return 0; +} + +int uapi_close_br_scan(void) +{ + gap_br_set_bt_scan_mode(GAP_SCAN_MODE_NONE, 0); + return 0; +} + +int uapi_open_br_scan(void) +{ + gap_br_set_bt_scan_mode(GAP_SCAN_MODE_CONNECTABLE, 0); + return 0; +} + +// /////////////////////////////////////////HFP hf端 代码/////////////////////////////////////////////////// + +// int uapi_HFP_hf_connect() +// { +// int ret = hfp_hf_connect(&g_bd_addr); +// WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP,"state(int): %d\n", ret); +// return ret; +// } + +// int uapi_a2dp_snk_disconnect() +// { +// int ret = a2dp_snk_disconnect(&g_bd_addr); +// WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP,"state(int): %d\n", ret); +// return ret; +// } + + +void cm_initBluetoothDeviceList(void) +{ + BluetoothModel::GetInstance()->Init(); +} #ifdef __cplusplus } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothOptionsView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothOptionsView.cpp index a2c367198..97f68abf4 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothOptionsView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothOptionsView.cpp @@ -4,224 +4,413 @@ * 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 (unpairLabel) + { + delete unpairLabel; + unpairLabel = 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->SetStyle(STYLE_TEXT_FONT,30); + titleLabel->SetStyle(STYLE_LINE_HEIGHT,35); + titleLabel->SetRollSpeed(23); + 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_EN, 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)); + 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); + /* -------------------------------------------------------------------------- */ + if (unpairLabel == nullptr) + { + unpairLabel = new UILabelExt(); + if (unpairLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "unpairLabel new fail"); + return false; + } + } + unpairLabel->SetPosition(173, unpairButton->GetY() + 33, 120, 35); + unpairLabel->SetStyle(STYLE_TEXT_FONT, 30); + unpairLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + unpairLabel->SetTextId(STR_UNPAIR); // 取消配对 + unpairLabel->SetTextColor(Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff)); + unpairLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + unpairLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + unpairLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + // unpairLabel->SetRollSpeed(23); + /* -------------------------------------------------------------------------- */ + 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; + } } - group->SetPosition(0, 0); - group->SetWidth(HORIZONTAL_RESOLUTION); - group->SetHeight(VERTICAL_RESOLUTION); + 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; + } + 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(unpairLabel); + 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/fd230/nativeapp/nativeui/bluetooth/src/BluetoothPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothPresenter.cpp index bcb1aa3bb..38e09e7ce 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothPresenter.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothPresenter.cpp @@ -10,12 +10,16 @@ #include "BluetoothPresenter.h" #include "BluetoothReconnectView.h" #include "MainBluetoothView.h" -#include "NativeRegisterManager.h" #include "UiConfig.h" +#include "BluetoothModel.h" +#include "custom_utils.h" +#include "common/key_code.h" -namespace OHOS { +#include "NativeRegisterManager.h" +namespace OHOS +{ -REGIST_SLICE(VIEW_BLUETOOTH_EARPHONE, MainBluetoothView, BluetoothPresenter); + REGIST_SLICE(VIEW_BLUETOOTH_EARPHONE, MainBluetoothView, BluetoothPresenter); static BluetoothPresenter *g_pBluetoothPresenter = nullptr; @@ -32,6 +36,16 @@ BluetoothPresenter::~BluetoothPresenter() WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::~BluetoothPresenter"); } +void BluetoothPresenter::OnStart() +{ + Presenter::OnStart(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::On Start "); +} + +void BluetoothPresenter::OnPause(void) {} + +void BluetoothPresenter::OnResume(void) {} + void BluetoothPresenter::OnStop(void) { BluetoothEarPhoneView *bluetoothEarPhoneView = BluetoothEarPhoneView::GetInstance(); @@ -61,6 +75,7 @@ void BluetoothPresenter::ClickNewEquipmentButton(void) view_->ChangeView(BLUETOOTHDEVICELISTVIEW, BLUETOOTHEARPHONEVIEW); } +//点击取消连接按钮 void BluetoothPresenter::ClickCancelConnedRequestButton(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_CANCELCONNEDREQUEST_BUTTON"); @@ -94,9 +109,10 @@ void BluetoothPresenter::ClickCancelConnedRequestButton(void) pbItermView->ConnectAnimatorStop(); bluetoothMode_->SetConnectionView(nullptr); bluetoothEarListView->SetNewEquipmentButtonAdd(); - RootView::GetInstance()->Invalidate(); + } +//点击取消配对 void BluetoothPresenter::ClickUnpairButton(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_UNPAIR_BUTTON"); @@ -127,6 +143,7 @@ void BluetoothPresenter::ClickUnpairButton(void) view_->ChangeView(BLUETOOTHEOPTIONSVIEW, BLUETOOTHDEVICELISTVIEW); } +/*已连接的蓝牙耳机设备视图中【重新连接或断开连接】按钮*/ void BluetoothPresenter::ClickOptionsOneButton(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnClick BLUETOOTH_OPTIONONE_BUTTON"); @@ -138,7 +155,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); @@ -147,9 +164,6 @@ void BluetoothPresenter::ClickOptionsOneButton(void) // 判断是否已有连接 bd_addr_t *lastAddr = bluetoothMode_->GetLastConnedAddr(); if (bt_is_acl_connected(lastAddr)) { - WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "LastDevice addr: %02x%02x%02x%02x%02x%02x is connected", - lastAddr->addr[5], lastAddr->addr[4], lastAddr->addr[3], - lastAddr->addr[2], lastAddr->addr[1], lastAddr->addr[0]); bluetoothMode_->SetTagConnectNew(true); bluetoothOptionsView->SetBtDisconnect(); } else { @@ -181,10 +195,25 @@ void BluetoothPresenter::ClickConnfailBackButton(void) WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClickConnfailBackButton ConnectRemoteDevice retVal = %d", retVal); } -bool BluetoothPresenter::OnDragEnd(UIView& view, const DragEvent& event) +bool BluetoothPresenter::OnDrag(UIView& view, const DragEvent& event) { if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { + int16_t deltaX; + int16_t deltaY; + deltaX = event.GetDeltaX(); + deltaY = event.GetDeltaY(); + if (MATH_ABS(deltaX) >= MATH_ABS(deltaY) && MATH_ABS(deltaX) > 30) { + X_DRAG_FLAG = true; + } + } + return true; +} + +bool BluetoothPresenter::OnDragEnd(UIView& view, const DragEvent& event) +{ + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) { view_->DropView(view); + X_DRAG_FLAG = false; } return true; } @@ -193,22 +222,46 @@ bool BluetoothPresenter::OnClick(UIView &view, const ClickEvent &event) { UNUSED(event); if (strcmp(view.GetViewId(), BLUETOOTH_RESCAN_BUTTON) == 0) { - ClickRescanButton(); + ClickRescanButton();//扫描出的耳机列表界面中的[重新扫描按钮]被点击 } else if (strcmp(view.GetViewId(), BLUETOOTH_NEWEQUIPMENT_BUTTON) == 0) { - ClickNewEquipmentButton(); + ClickNewEquipmentButton();//已连接设备列表界面中的[重新扫描按钮]被点击 } else if (strcmp(view.GetViewId(), BLUETOOTH_CANCELCONNEDREQUEST_BUTTON) == 0) { ClickCancelConnedRequestButton(); } else if (strcmp(view.GetViewId(), BLUETOOTH_UNPAIR_BUTTON) == 0) { - ClickUnpairButton(); + ClickUnpairButton();//查看已连接的蓝牙耳机设备界面的[取消配对按]钮被点击 } else if (strcmp(view.GetViewId(), BLUETOOTH_OPTIONONE_BUTTON) == 0) { ClickOptionsOneButton(); } else if (strcmp(view.GetViewId(), BLUETOOTH_SUCC_BACK_BUTTON) == 0) { - ClickSuccBackButton(); + ClickSuccBackButton();//点击连接成功的确定按钮 } else if (strcmp(view.GetViewId(), BLUETOOTH_FAIL_BACK_BUTTON) == 0) { - ClickFailBackButton(); + ClickFailBackButton(); //点击重新搜索按钮 } else if (strcmp(view.GetViewId(), BLUETOOTH_CONN_FAIL_BACK_BUTTON) == 0) { - ClickConnfailBackButton(); + ClickConnfailBackButton();//连接失败的重试按钮 + } + return true; +} + +bool BluetoothPresenter::OnKeyAct(UIView &view, const KeyEvent &event) +{ + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16 keyState = event.GetState(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + //如果是按键退出,退出时需要做一些清理工作 + BluetoothEarPhoneView *bluetoothEarPhoneView = BluetoothEarPhoneView::GetInstance(); + if(bluetoothEarPhoneView) + { + bluetoothEarPhoneView->BtAnimatorStop(); //停止搜索动画 + bluetoothEarPhoneView->StopBtDiscovery();//停止定时器 + BluetoothModel::GetInstance()->SetTagConnectView(false); //清除标志位 + BluetoothModel::GetInstance()->SetTagScanDeviceClicked(false); + } + NativeAbility::GetInstance().Back(); } return true; } + + }; diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothReconnectView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothReconnectView.cpp index ad2334248..df336f54c 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothReconnectView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothReconnectView.cpp @@ -11,15 +11,20 @@ #include "PlayersPresenter.h" #include "BluetoothPresenter.h" #include "common/image_cache_manager.h" - +#include "uicomponents/UIComponents.h" +#include +#include "graphic_service.h" +#include namespace OHOS { static BluetoothReconnectView *g_pBluetoothReconnectView{nullptr}; -#define BLUETOOTH_IMAGE_X 175 -#define BLUETOOTH_IMAGE_Y 125 -#define BLUETOOTH_IMAGE_WIDTH 104 -#define BLUETOOTH_IMAGE_HEIGHT 104 -#define BLUETOOTH_DELAY 200 - +#define BLUETOOTH_IMAGE_X 183 +#define BLUETOOTH_IMAGE_Y 153 +#define BLUETOOTH_IMAGE_WIDTH 100 +#define BLUETOOTH_IMAGE_HEIGHT 120 +#define BLUETOOTH_DELAY 50 +static constexpr const char *reconnectImagePaths = "/user/res/connect/"; +osTimerId_t g_stopConnectHandle = nullptr; +static constexpr uint64_t MS_CONN_TIME = 15000; BluetoothReconnectView::BluetoothReconnectView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothReconnectView::BluetoothReconnectView"); @@ -29,22 +34,32 @@ BluetoothReconnectView::BluetoothReconnectView() BluetoothReconnectView::~BluetoothReconnectView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothReconnectView::~BluetoothReconnectView"); - group->RemoveAll(); - delete titleLabel; - titleLabel = nullptr; - delete bluetoothNameLabel; - bluetoothNameLabel = nullptr; - delete reconnectAnimator; - reconnectAnimator = nullptr; - delete group; - group = nullptr; + if(group){ + group->RemoveAll(); + if(titleLabel){ + delete titleLabel; + titleLabel = nullptr; + } + if(bluetoothNameLabel){ + delete bluetoothNameLabel; + bluetoothNameLabel = nullptr; + } + if(reconnectAnimator){ + reconnectAnimator->Stop(); + delete reconnectAnimator; + reconnectAnimator = nullptr; + if(reconnectPathsArray != nullptr) + FreeImageInfoArray(reconnectPathsArray, reconnectImagePaths, BLUETOOTH_RECONNECT_IMAGE_NUM); + } + delete group; + group = nullptr; + } + ScreenTurnOff(); + stop_connect_timer(); g_pBluetoothReconnectView = nullptr; } -bd_addr_t BluetoothReconnectView::GetcurrentBdAddr(void) -{ - return currentBdAddr; -} + BluetoothReconnectView *BluetoothReconnectView::GetInstance() { @@ -65,6 +80,7 @@ void BluetoothReconnectView::ShowUpTitleLabel() 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); + titleLabel->SetVisible(false); group->Add(titleLabel); } if (bluetoothNameLabel == nullptr) { @@ -80,20 +96,11 @@ void BluetoothReconnectView::ShowUpTitleLabel() bluetoothNameLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_THIRTY_SIZE); bluetoothNameLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); bluetoothNameLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + bluetoothNameLabel->SetVisible(false); group->Add(bluetoothNameLabel); } } -void BluetoothReconnectView::BtReconnectStart(void) -{ - reconnectAnimator->Start(); -} - -void BluetoothReconnectView::BtReconnectStop(void) -{ - reconnectAnimator->Stop(); -} - UIViewGroup *BluetoothReconnectView::InitShowUpView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothReconnectView init"); @@ -115,10 +122,11 @@ UIViewGroup *BluetoothReconnectView::InitShowUpView() WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "reDragListener GetInstance fail"); return nullptr; } + /* ------------------------------ 连接过程动画不能右滑退出 ------------------------------ */ if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { - group->SetOnDragListener(reDragListener); + // group->SetOnDragListener(reDragListener); } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) { - group->SetOnDragListener(reDragListener2); + // group->SetOnDragListener(reDragListener2); } group->SetViewId(BLUETOOTH_RECONNECT_VIEW); group->SetDraggable(true); @@ -140,6 +148,7 @@ void BluetoothReconnectView::RefreshBluetoothNameLabel() void BluetoothReconnectView::BtReconnectImageAnimator() { +#if 0 const char *reconnectImagePath[BLUETOOTH_RECONNECT_IMAGE_NUM] = { PNG_A019_080_IMAGE_PATH, PNG_A019_081_IMAGE_PATH, @@ -169,6 +178,131 @@ void BluetoothReconnectView::BtReconnectImageAnimator() reconnectAnimator->SetRepeat(true); group->Add(reconnectAnimator); } +#endif + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtScanImageAnimator init"); + reconnectPathsArray = CreateImageInfoArray(reconnectImagePaths, BLUETOOTH_RECONNECT_IMAGE_NUM); + if (reconnectAnimator == nullptr) + { + reconnectAnimator = new UIImageAnimatorView(); + if (reconnectAnimator == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "reconnectAnimator new fail"); + return; + } + for (uint8_t i = 0; i < BLUETOOTH_RECONNECT_IMAGE_NUM; i++) + { + reconnetImageInfo[i].imageInfo = (reconnectPathsArray[i]); + reconnetImageInfo[i].imageType = IMG_SRC_IMAGE_INFO; + reconnetImageInfo[i].pos.x = BLUETOOTH_IMAGE_X; + reconnetImageInfo[i].pos.y = BLUETOOTH_IMAGE_Y; + reconnetImageInfo[i].width = BLUETOOTH_IMAGE_WIDTH; + reconnetImageInfo[i].height = BLUETOOTH_IMAGE_HEIGHT; + } + reconnectAnimator->SetPosition(BLUETOOTH_IMAGE_X, BLUETOOTH_IMAGE_Y, BLUETOOTH_IMAGE_WIDTH, BLUETOOTH_IMAGE_HEIGHT); + reconnectAnimator->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + reconnectAnimator->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + reconnectAnimator->SetImageAnimatorSrc(reconnetImageInfo, BLUETOOTH_RECONNECT_IMAGE_NUM, BLUETOOTH_DELAY); + reconnectAnimator->SetRepeat(true); + reconnectAnimator->SetSizeFixed(true); + group->Add(reconnectAnimator); + } } +bd_addr_t BluetoothReconnectView::GetcurrentBdAddr(void) +{ + return currentBdAddr; +} + +void BluetoothReconnectView::BtReconnectStart(void) +{ + // ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); //动画启动,常亮屏 + ScreenTurnOn(20*1000); + reconnectAnimator->Start(); + start_connect_timer(); +} + +void BluetoothReconnectView::BtReconnectStop(void) +{ + /* ---------------------------------- 取消定时器 --------------------------------- */ + // ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON);//动画停止,取消常亮屏 + reconnectAnimator->Stop(); + stop_connect_timer(); +} + +// 定时器回调函数 +static void ConnectTimerCallbackProc(int data) +{ + (void)data; + + MainBluetoothView *mainBluetoothView = MainBluetoothView::GetInstance(); + if (mainBluetoothView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainBluetoothView GetInstance fail"); + return; + } + mainBluetoothView->ChangeView(BluetoothModel::GetInstance()->GetCurView(), TIPSCONNFAILMESSAGEVIEW); + + TipsConnFailMessageView *tipsConnFailMessageView = TipsConnFailMessageView::GetInstance(); + if (tipsConnFailMessageView == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ACLConnectionFail tipsConnFailMessageView GetInstance fail"); + return; + } + BluetoothCaseInfo *bluetoothInfo_= BluetoothModel::GetInstance()->GetTempMacValue(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "device name = %s",bluetoothInfo_->deviceName); + bd_addr_t addr; + (void)memcpy_s(addr.addr, BD_ADDR_LEN, bluetoothInfo_->addr, BD_ADDR_LEN); + tipsConnFailMessageView->RefreshNameLabel(addr); +} + +static void ConnectTimerCallback(int data) +{ + GraphicService::GetInstance()->PostGraphicEvent(std::bind(ConnectTimerCallbackProc, data)); +} +//开启第一个重连动画的定时器 +void BluetoothReconnectView::start_connect_timer() +{ + /*开启定时器*/ + if (g_stopConnectHandle != nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable g_stopConnectHandle != nullptr"); + return; + } + g_stopConnectHandle = osTimerNew((osTimerFunc_t)ConnectTimerCallback, osTimerPeriodic, nullptr, nullptr); + if (g_stopConnectHandle == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable osTimerNew failed!!"); + return; + } + uint32 tick = osMs2Tick(MS_CONN_TIME); + osStatus_t retTimer = osTimerStart(g_stopConnectHandle, tick); + if (retTimer != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable osTimerStart failed, ret = %lx!!", retTimer); + if (g_stopConnectHandle != nullptr) + { + retTimer = osTimerDelete(g_stopConnectHandle); + if (retTimer != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::BtEnable osTimerDelete ret = %lx!!", retTimer); + return; + } + g_stopConnectHandle = nullptr; + } + return; + } +} +//停止定时器 +void BluetoothReconnectView::stop_connect_timer() +{ + if (g_stopConnectHandle != nullptr) + { + osTimerStop(g_stopConnectHandle); + osStatus_t ret = osTimerDelete(g_stopConnectHandle); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret); + return; + } + g_stopConnectHandle = nullptr; + } +} } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothWrapper.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothWrapper.cpp index 22e85a984..92ff850aa 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothWrapper.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/BluetoothWrapper.cpp @@ -11,6 +11,7 @@ #ifdef __cplusplus extern "C" { #endif +#include "custom_utils.h" static bool gatts_register_flag = false; static uint8_t gatts_server_id = 0; @@ -201,8 +202,10 @@ void wrapper_gatts_start_service_callback(uint8_t server_id, uint16_t handle, er callback.start_service_cb(server_id, handle, status); } } + // printf("wrapper_gatts_start_service_callback server_id %d,handle %d, status %x , g_svr_handle_list.size %d\r\n",server_id,handle,status,g_svr_handle_list.size()); g_uuid_list.pop_front(); - wrapper_gatts_service_start(); + wrapper_gatts_service_start(); + // do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_BLE_WRAPPERSTART,NULL,0); } } void wrapper_gatts_stop_service_callback(uint8_t server_id, uint16_t handle, errcode_t status) @@ -301,18 +304,36 @@ errcode_t wrapper_gatts_add_service(uint8_t server_id, bt_uuid_t *service_uuid, g_uuid_list.push_back(*service_uuid); return ERRCODE_SUCC; } - +#include "debug_print.h" +extern "C" void custom_ble_service_start(void); void wrapper_gatts_service_start(void) { + // printf("wrapper_gatts_service_start \n"); if (!g_uuid_list.empty()) { bt_uuid_t &uuid = g_uuid_list.front(); + bt_uuid_t uuid_tmp={0}; + memcpy(&uuid_tmp,&uuid,sizeof(bt_uuid_t)); // 服务异步添加,需要保证当前服务start后,再添加下一个服务 - (void)gatts_add_service(gatts_server_id, &uuid, true); + // g_uuid_list.pop_front(); + errcode_t ret = gatts_add_service(gatts_server_id, &uuid_tmp, true); + // printf("wrapper_gatts_service_start gatts_add_service uuid len %x [0x%02X%02X],gatts_server_id %u, ret 0x%x, g_uuid_list.size %d\n", + // uuid_tmp.uuid_len,uuid_tmp.uuid[0],uuid_tmp.uuid[1],gatts_server_id,ret,g_uuid_list.size()); + } else { g_svr_handle_list.clear(); + // printf("wrapper_gatts_service_start g_uuid_list empty,start adv \n"); + /**开始ble广播*/ + custom_ble_service_start(); } -} + // printf("wrapper_gatts_service_start end\n"); +} +void wrapper_gatts_clear_service(void) +{ + if (!g_uuid_list.empty()) g_uuid_list.clear(); + if (!g_svr_handle_list.empty()) g_svr_handle_list.clear(); + gatts_register_flag = false; +} #ifdef __cplusplus } #endif diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/Bluetooyhpabpserver.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/Bluetooyhpabpserver.cpp new file mode 100644 index 000000000..b09d34de4 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/Bluetooyhpabpserver.cpp @@ -0,0 +1,809 @@ +/* + * Copyright (c) @CompanyNameMagicTag 2022. All rights reserved. + * Description: This module include test function of BT PBAP Service module. + */ + +#include "Bluetooyhpabpserver.h" +#include +#include +#include "securec.h" +#include "errcode.h" +#include "bts_br_gap.h" +#include "bts_pbap.h" +// #include "sample_common.h" +#include "debug_print.h" +#include "graphic_service.h" +#include "msg_center.h" +#include "bts_def.h" +#include "bts_gatt_stru.h" +#include "bts_a2dp_source.h" +#include "bts_gatt_server.h" +#include "bts_le_gap.h" +#include "bts_spp.h" +#include "osal_task.h" +#ifdef SUPPORT_BLE_SERVICE +#include +#include "bleService.h" +#endif +#include "BluetoothModel.h" +#include "CallerLogModel.h" + +#ifdef __cplusplus +extern "C" { +#endif + + +#define SAMPLE_PBAP_TASK_STACK_SIZE 0x400 +#define PBAP_APP_FOLDER_MAXLENGTH 40 +static bd_addr_t g_pbap_curr_addr; + +typedef enum { + PBAP_VCF_PB = 0, + PBAP_VCF_ICH, + PBAP_VCF_OCH, + PBAP_VCF_MCH, + PBAP_VCF_CCH, + PBAP_VCF_SPD, + PBAP_VCF_FAV, +} pbap_vcf_files; + +static void sample_pbap_print_addr(const bd_addr_t *bd_addr) +{ + if (bd_addr != NULL) { + printf("addr: ****%02x%02x%02x%02x ", + bd_addr->addr[3], bd_addr->addr[2], bd_addr->addr[1], bd_addr->addr[0]); /* addr 下标 3 2 1 0 */ + } +} + +static void sample_pbap_conn_state(const bd_addr_t *bd_addr, profile_connect_state_t state) +{ + sample_pbap_print_addr(bd_addr); + printf("sample_pbap_conn_state %d\n", state); + if(state==PROFILE_STATE_CONNECTED) + { + uapi_pbap_cmd_pull_phonebook(); + } + return; +} +//接收数据回调 +static void sample_pbap_receive_data(const bd_addr_t *bd_addr, const uint8_t* data, int32_t len) +{ + sample_pbap_print_addr(bd_addr); + + printf("receive %d bytes(%s)\n", len, data); + if(strstr((char*)data,"vcard-listing.dtd")) + { + if(strstr((char*)data,"name")) + { + char * name_str=strstr((char*)data,"name"); + char *name_=strtok(name_str,"\""); + name_=strtok(NULL,"\""); + OHOS:: CallerLogModel::GetInstance()->Setphonebname(name_,strlen(name_)); + printf("name_ : %s\r\n",name_); + GraphicService::GetInstance()->PostGraphicEvent( + std::bind(calllognameupdate)); + + + } + + } + + return; +} + +//传输完成回调 +static void sample_pbap_transfer_complete(const bd_addr_t *bd_addr) +{ + sample_pbap_print_addr(bd_addr); + printf("\n"); + return; +} + +static void sample_pbap_get_phonebook_size(const bd_addr_t *bd_addr, uint16_t size) +{ + sample_pbap_print_addr(bd_addr); + + printf("%u\n", size); + return; +} + +typedef struct { + uint32_t bts_code; + td_char print_message[20]; /* 字符串长度20 */ +} sample_pbap_code_print; + +static sample_pbap_code_print g_pbap_error_pair[] = { + {PBAP_ERROR_OK, "OK"}, + {PBAP_ERROR_BAD_REQUEST, "BAD REQUEST"}, + {PBAP_ERROR_NOT_IMPLEMENTED, "NOT IMPLEMENTED"}, + {PBAP_ERROR_UNAUTHORIZED, "UNAUTHORIZED"}, + {PBAP_ERROR_PRECONDITION_FAILED, "PRECONDITION FAILED"}, + {PBAP_ERROR_NOT_FOUND, "NOT FOUND"}, + {PBAP_ERROR_NOT_ACCEPTABLE, "NOT ACCEPTABLE"}, + {PBAP_ERROR_SERVICE_UNAVAILABLE, "SERVICE UNAVAILABLE"}, + {PBAP_ERROR_FORBIDDEN, "FORBIDDEN"}, +}; + +static td_char* sample_pbap_print_error(uint32_t code) +{ + for (uint32_t i = 0; i < sizeof(g_pbap_error_pair) / sizeof(g_pbap_error_pair[0]); i++) { + if (code == g_pbap_error_pair[i].bts_code) { + return g_pbap_error_pair[i].print_message; + } + } + return NULL; +} + +static void sample_pbap_handle_error_code(const bd_addr_t *bd_addr, int32_t code) +{ + sample_pbap_print_addr(bd_addr); + printf("0x%x %s\n", code, sample_pbap_print_error((uint32_t)code)); +} + +static bool sample_pbap_is_null_pointer(uint16_t sample_mode, uint8_t index) +{ + return ((sample_mode & (1 << index)) != 0); +} + +/* 蓝牙电话簿注册回调 */ +void uapi_pbap_pce_reg_callback(void) +{ + errcode_t ret = ERRCODE_BT_SUCCESS; + pbap_pce_callbacks_t callbacks = { + sample_pbap_conn_state, + sample_pbap_get_phonebook_size, + sample_pbap_transfer_complete, + sample_pbap_receive_data, + sample_pbap_handle_error_code, + }; + ret = (errcode_t)pbap_pce_register_callbacks(&callbacks); + printf("uapi_pbap_pce_reg_callback ret=0x%x\n", ret); +} + + + +static int32_t sample_pbap_connect_task_body(const void *bd_addr) +{ + uint32_t result = (uint32_t)pbap_pce_connect((bd_addr_t*)bd_addr); + if (result != ERRCODE_BT_SUCCESS) { + printf("Connect to PBAP service failed\n"); + } + printf("sample_pbap_connect_task_body [Line: %d] finish, result: 0x%x!\n", __LINE__, result); + return 0; +} + +static void sample_pbap_create_conn_task(const bd_addr_t *bd_addr) +{ + osal_task *task = osal_kthread_create((osal_kthread_handler)sample_pbap_connect_task_body, (void *)bd_addr, "sample_pbap_connect_task", + SAMPLE_PBAP_TASK_STACK_SIZE); + if (task == NULL) { + printf("create task fail\n"); + return; + } +} + +/* start a pbap client */ + void uapi_pbap_cmd_start_client() +{ + // if (params_cnt != 2) { /* 2个参数 */ + // printf("params cnt err: %d!\n", params_cnt); + // return; + // } + + // uint32_t sample_mode; + // if (sscanf_s(params[0], "%x", &sample_mode) <= 0) { + // printf("get sample_mode fail\n"); + // return; + // } + // bd_addr_t* bd_addr = NULL; + // if (!sample_pbap_is_null_pointer((uint16_t)sample_mode, 0)) { + // bd_addr = sample_pbap_parse_addr(params[1]); + bd_addr_t bdaddr={0}; + OHOS::uapi_get_br_address(&bdaddr); + // } + sample_pbap_create_conn_task((const bd_addr_t*)&bdaddr); +} + +void uapi_pbap_cmd_stop_client() +{ + bd_addr_t bdaddr={0}; + OHOS::uapi_get_br_address(&bdaddr); + + uint32_t ret = (uint32_t)pbap_pce_disconnect(&bdaddr); + printf("[Line: %d] finish, ret: %u\n", __LINE__, ret); +} + +static int32_t sample_pbap_set_folder_vcf(uint8_t* name, uint8_t vcf, bool is_pull_phone_book) +{ + if (name == NULL) { + return -1; + } + switch (vcf) { + case PBAP_VCF_PB: /* Main Phone book */ + (void)strcat_s((char *)name, PBAP_APP_FOLDER_MAXLENGTH, "pb"); + break; + case PBAP_VCF_ICH: /* Incoming Calls History */ + (void)strcat_s((char *)name, PBAP_APP_FOLDER_MAXLENGTH, "ich"); + break; + case PBAP_VCF_OCH: /* Outgoing Calls History */ + (void)strcat_s((char *)name, PBAP_APP_FOLDER_MAXLENGTH, "och"); + break; + case PBAP_VCF_MCH: /* Missed Calls History */ + (void)strcat_s((char *)name, PBAP_APP_FOLDER_MAXLENGTH, "mch"); + break; + case PBAP_VCF_CCH: /* Combined Calls History */ + (void)strcat_s((char *)name, PBAP_APP_FOLDER_MAXLENGTH, "cch"); + break; + case PBAP_VCF_SPD: /* Speed Dial */ + (void)strcat_s((char *)name, PBAP_APP_FOLDER_MAXLENGTH, "spd"); + break; + case PBAP_VCF_FAV: /* Favorite Contacts */ + (void)strcat_s((char *)name, PBAP_APP_FOLDER_MAXLENGTH, "fav"); + break; + default: + printf("no vcf file be seleted.\n"); + return -1; + } + if (is_pull_phone_book) { + (void)strcat_s((char *)name, PBAP_APP_FOLDER_MAXLENGTH, ".vcf"); + } + return 0; +} + +static void sample_pbap_filter_composer(uint8_t filter[PBAP_MASK_LEN], uint8_t flag) +{ + uint8_t *temp = NULL; + uint8_t bytes = 0; + uint8_t bits = 0; + + if (filter && (flag < 64)) { /* flag最大值64 */ + bytes = (uint8_t)(flag >> 3); /* 右移3位判断填入哪个字节 */ + bits = (uint8_t)(flag & 0x07); /* 求余数判断填入哪一位 */ + temp = filter + PBAP_MASK_LEN - 1 - bytes; + *temp |= (1 << bits); + } +} + +static void sample_pbap_set_property(uint8_t pro_arr[PBAP_MASK_LEN], uint32_t property) +{ + uint8_t cur_bit = 0; + uint32_t temp = property; + while (temp != 0) { + if ((temp & 0x01) != 0) { + sample_pbap_filter_composer(pro_arr, cur_bit); + } + temp = temp >> 1; + cur_bit++; + } +} + +static bool sample_pbap_set_pull_phone_book_name(uint8_t folder, uint8_t vcf, uint8_t* name) +{ + if (name == NULL) { + printf("empty name.\n"); + return false; + } + if (folder == PBAP_REPOSITORY_LOCAL) { + (void)strcpy_s((char *)name, PBAP_APP_FOLDER_MAXLENGTH, "telecom/"); + } else if (folder == PBAP_REPOSITORY_SIM) { + (void)strcpy_s((char *)name, PBAP_APP_FOLDER_MAXLENGTH, "SIM1/telecom/"); + } else { + printf("no folder be seleted.\n"); + return false; + } + + if (sample_pbap_set_folder_vcf(name, vcf, true) != 0) { + return false; + } + return true; +} + +static bool wstp_pbap_check_param_valid( + uint8_t folder, uint8_t vcf, uint16_t max_list_count, uint16_t list_offset, uint8_t format) +{ + // bts_unused(max_list_count); + // bts_unused(list_offset); + bool res = true; + if (folder == 1) { /* folder 1 */ + if (vcf > 6) { /* vcf num 6 */ + res = false; + } + } else if (folder == 2) { /* folder 2 */ + if (vcf > 4) { /* vcf num 4 */ + res = false; + } + } else { + res = false; + } + + if (format > 1) { + res = false; + } + + return res; +} +//PBAP_VCF_PB 10 1 0 +/* get phone book */ +void uapi_pbap_cmd_pull_phonebook() +{ + printf("uapi_pbap_cmd_pull_phonebook\n"); + uint8_t folder=PBAP_REPOSITORY_LOCAL;//写死只拿手机的,不拿SIM卡的 + uint8_t vcf=PBAP_VCF_PB;//写死 电话簿 + uint16_t max_list_count=0xFFFF;//最大数量 + uint16_t list_offset=0; + uint8_t format=1;//编码格式 + + if (!wstp_pbap_check_param_valid(folder, vcf, max_list_count, list_offset, format)) { + printf("pbap param invalid\n"); + return; + } + + pbap_pce_pull_phone_book_param_t *thr_par = + (pbap_pce_pull_phone_book_param_t*)(void *)malloc(sizeof(pbap_pce_pull_phone_book_param_t)); + if (thr_par == NULL) { + printf("pbap param malloc failed\n"); + return; + } + (void)memset_s(thr_par, sizeof(pbap_pce_pull_phone_book_param_t), 0, sizeof(pbap_pce_pull_phone_book_param_t)); + thr_par->name = (unsigned char *)(void *)malloc(PBAP_APP_FOLDER_MAXLENGTH); + if (thr_par->name == NULL) { + printf("pbap name malloc failed\n"); + free(thr_par); + return; + } + (void)memset_s(thr_par->name, PBAP_APP_FOLDER_MAXLENGTH, 0, PBAP_APP_FOLDER_MAXLENGTH); + /* 为0时代表查询对应记录大小 */ + thr_par->max_list_count = max_list_count; + thr_par->list_offset = list_offset; + thr_par->format = format; + uint32_t property =PBAP_PROPERTY_MASK_TEL | PBAP_PROPERTY_MASK_FN|PBAP_PROPERTY_MASK_UID; + sample_pbap_set_property(thr_par->property_selector, property); + uint8_t filter = 0; + if (filter != 0) { + sample_pbap_filter_composer(thr_par->property_selector, PBAP_PROPERTY_MASK_FILTER); + } + + if (sample_pbap_set_pull_phone_book_name(folder, vcf, thr_par->name)) { + printf("pbap_pce_pull_phone_book name=%s\n", thr_par->name); + pbap_pce_pull_phone_book(NULL, thr_par); + } + free(thr_par->name); + free(thr_par); +} + +/* get phone book */ +static void sample_pbap_cmd_pull_phonebook(const char **params, int32_t params_cnt) +{ + // if (params_cnt != 9) { /* 9个参数 */ + // printf("params cnt err: %d!\n", params_cnt); + // return; + // } + + // uint32_t sample_mode; + // if (sscanf_s(params[0], "%x", &sample_mode) <= 0) { + // printf("get sample_mode fail\n"); + // return; + // } + // bd_addr_t* bd_addr = NULL; + // if (!sample_pbap_is_null_pointer((uint16_t)sample_mode, 0)) { + // bd_addr = sample_pbap_parse_addr(params[1]); + // } + + // if (pbap_pce_get_device_connect_state(bd_addr) != PROFILE_STATE_CONNECTED) { + // printf("No PBAP connection selected!\n"); + // return; + // } + // pbap_pce_pull_phone_book_param_t *thr_par = + // (pbap_pce_pull_phone_book_param_t*)(void *)bt_os_new(sizeof(pbap_pce_pull_phone_book_param_t)); + // if (thr_par == NULL) { + // printf("pbap param malloc failed\n"); + // return; + // } + // (void)memset_s(thr_par, sizeof(pbap_pce_pull_phone_book_param_t), 0, sizeof(pbap_pce_pull_phone_book_param_t)); + // thr_par->name = (unsigned char *)(void *)bt_os_new(PBAP_APP_FOLDER_MAXLENGTH); + // if (thr_par->name == NULL) { + // printf("pbap name malloc failed\n"); + // bt_os_free(thr_par); + // return; + // } + // (void)memset_s(thr_par->name, PBAP_APP_FOLDER_MAXLENGTH, 0, PBAP_APP_FOLDER_MAXLENGTH); + // thr_par->max_list_count = (unsigned short)atoi(params[4]); /* index = 4 */ + // thr_par->list_offset = (unsigned short)atoi(params[5]); /* index = 5 */ + // thr_par->format = (unsigned char)atoi(params[6]); /* index = 6 */ + // uint32_t property = (uint32_t)atoi(params[7]); /* index = 7 */ + // sample_pbap_set_property(thr_par->property_selector, property); + // int filter = atoi(params[8]); /* index = 8 */ + // if (filter != 0) { + // sample_pbap_filter_composer(thr_par->property_selector, PBAP_PROPERTY_MASK_FILTER); + // } + + // uint8_t folder = (uint8_t)atoi(params[2]); /* index = 2 */ + // uint8_t vcf = (uint8_t)atoi(params[3]); /* index = 3 */ + // if (sample_pbap_set_pull_phone_book_name(folder, vcf, thr_par->name)) { + // pbap_pce_pull_phone_book(bd_addr, thr_par); + // } + // bt_os_free(thr_par->name); + // bt_os_free(thr_par); +} + +static bool sample_pbap_set_vcard_listing_name(bd_addr_t* bd_addr, uint8_t folder, uint8_t vcf, uint8_t* name) +{ + printf("folder=%u vcf=%u\n", folder, vcf); + uint8_t tel_name[8] = "telecom"; + uint8_t sim_name[5] = "SIM1"; + if (name == NULL) { + printf("empty name.\n"); + return false; + } + uint32_t ret = (uint32_t)pbap_pce_set_phone_book(bd_addr, NULL); + if (ret != ERRCODE_BT_SUCCESS) { + printf("0x%x %s\n", ret, sample_pbap_print_error(ret)); + return false; + } + if (folder == PBAP_REPOSITORY_LOCAL) { + ret = (uint32_t)pbap_pce_set_phone_book(bd_addr, tel_name); + if (ret != ERRCODE_BT_SUCCESS) { + printf("0x%x %s\n", ret, sample_pbap_print_error(ret)); + return false; + } + } else if (folder == PBAP_REPOSITORY_SIM) { + ret = (uint32_t)pbap_pce_set_phone_book(bd_addr, sim_name); + if (ret != ERRCODE_BT_SUCCESS) { + printf("0x%x %s\n", ret, sample_pbap_print_error(ret)); + return false; + } + ret = (uint32_t)pbap_pce_set_phone_book(bd_addr, tel_name); + if (ret != ERRCODE_BT_SUCCESS) { + printf("0x%x %s\n", ret, sample_pbap_print_error(ret)); + return false; + } + } else { + printf("no folder be seleted.\n"); + return false; + } + if (sample_pbap_set_folder_vcf(name, vcf, false)) { + return false; + } + return true; +} + +/* get phone vCard-Listing */ +void uapi_pbap_cmd_pull_vcard_listing(unsigned char *tell,uint8_t len) +{ + uint8_t folder=1; + uint8_t vcf=PBAP_VCF_PB; + uint16_t max_list_count=0xffff; + uint16_t list_offset=0; + uint8_t order=0; + + OHOS:: CallerLogModel::GetInstance()->Setphonebname("",0); + + OHOS:: CallerLogModel::GetInstance()->Setphonenumber((char *)tell,len); + + unsigned char *tell_=(unsigned char *)malloc(len+1); + if(tell_==NULL) + { + return; + } + memset_s(tell_,30,0,len); + memcpy_s(tell_,30,tell,len); + + if (!wstp_pbap_check_param_valid(folder, vcf, max_list_count, list_offset, 0)) { + printf("pbap param invalid\n"); + return; + } + + bd_addr_t* bd_addr = NULL; + + pbap_pce_pull_vcard_listing_param_t *thr_par = + (pbap_pce_pull_vcard_listing_param_t*)(void *)malloc(sizeof(pbap_pce_pull_vcard_listing_param_t)); + if (thr_par == NULL) { + printf("pbap param malloc failed\n"); + free(tell_); + return; + } + + (void)memset_s( + thr_par, sizeof(pbap_pce_pull_vcard_listing_param_t), 0, sizeof(pbap_pce_pull_vcard_listing_param_t)); + thr_par->name = (uint8_t *)(void *)malloc(PBAP_APP_FOLDER_MAXLENGTH); + if (thr_par->name == NULL) { + printf("pbap param name malloc failed\n"); + free(thr_par); + free(tell_); + return; + } + (void)memset_s(thr_par->name, PBAP_APP_FOLDER_MAXLENGTH, 0, PBAP_APP_FOLDER_MAXLENGTH); + + thr_par->search_property=PBAP_SEARCH_PROPERTY_NUMBER; + thr_par->search_value=tell_; + thr_par->max_list_count = max_list_count; + thr_par->list_offset = list_offset; /* index = 5 */ + /* 0:索引序 1:字典序 */ + thr_par->order = order; + + if (sample_pbap_set_vcard_listing_name(bd_addr, folder, vcf, thr_par->name)) { + printf("pbap_pce_pull_vcard_listing name=%s\n", thr_par->name); + pbap_pce_pull_vcard_listing(bd_addr, thr_par); + } + free(thr_par->name); + free(thr_par); + free(tell_); +} + +/* get phone vCard-Listing */ +static void sample_pbap_cmd_pull_vcard_listing(const char **params, int32_t params_cnt) +{ + // if (params_cnt != 7) { /* 7个参数 */ + // printf("params cnt err: %d!\n", params_cnt); + // return; + // } + + // uint32_t sample_mode; + // if (sscanf_s(params[0], "%x", &sample_mode) <= 0) { + // printf("get sample_mode fail\n"); + // return; + // } + // bd_addr_t* bd_addr = NULL; + // if (!sample_pbap_is_null_pointer((uint16_t)sample_mode, 0)) { + // bd_addr = sample_pbap_parse_addr(params[1]); + // } + + // if (pbap_pce_get_device_connect_state(bd_addr) != PROFILE_STATE_CONNECTED) { + // printf("No PBAP connection selected!\n"); + // return; + // } + + // pbap_pce_pull_vcard_listing_param_t *thr_par = + // (pbap_pce_pull_vcard_listing_param_t*)(void *)bt_os_new(sizeof(pbap_pce_pull_vcard_listing_param_t)); + // if (thr_par == NULL) { + // printf("pbap param malloc failed\n"); + // return; + // } + + // (void)memset_s( + // thr_par, sizeof(pbap_pce_pull_vcard_listing_param_t), 0, sizeof(pbap_pce_pull_vcard_listing_param_t)); + // thr_par->name = (uint8_t *)(void *)bt_os_new(PBAP_APP_FOLDER_MAXLENGTH); + // if (thr_par->name == NULL) { + // printf("pbap param name malloc failed\n"); + // bt_os_free(thr_par); + // return; + // } + // (void)memset_s(thr_par->name, PBAP_APP_FOLDER_MAXLENGTH, 0, PBAP_APP_FOLDER_MAXLENGTH); + // uint8_t folder = (uint8_t)atoi(params[2]); /* index = 2 */ + // uint8_t vcf = (uint8_t)atoi(params[3]); /* index = 3 */ + // thr_par->max_list_count = (unsigned short)atoi(params[4]); /* index = 4 */ + // thr_par->list_offset = (unsigned short)atoi(params[5]); /* index = 5 */ + // thr_par->order = (unsigned char)atoi(params[6]); /* index = 6 */ + + // if (sample_pbap_set_vcard_listing_name(bd_addr, folder, vcf, thr_par->name)) { + // pbap_pce_pull_vcard_listing(bd_addr, thr_par); + // } + // bt_os_free(thr_par->name); + // bt_os_free(thr_par); +} + +static bool sample_pbap_set_vcard_entry_name( + bd_addr_t *bd_addr, uint8_t folder, uint8_t vcf, const td_char *vcf_name, uint8_t *name) +{ + if (name == NULL) { + printf("empty name.\n"); + return false; + } + uint8_t tel_name[8] = "telecom"; + uint8_t sim_name[5] = "SIM1"; + uint32_t ret = (uint32_t)pbap_pce_set_phone_book(bd_addr, NULL); + if (ret != ERRCODE_BT_SUCCESS) { + printf("0x%x %s\n", ret, sample_pbap_print_error(ret)); + return false; + } + if (folder == PBAP_REPOSITORY_LOCAL) { + ret = (uint32_t)pbap_pce_set_phone_book(bd_addr, tel_name); + if (ret != ERRCODE_BT_SUCCESS) { + printf("0x%x %s\n", ret, sample_pbap_print_error(ret)); + return false; + } + } else if (folder == PBAP_REPOSITORY_SIM) { + ret = (uint32_t)pbap_pce_set_phone_book(bd_addr, sim_name); + if (ret != ERRCODE_BT_SUCCESS) { + printf("0x%x %s\n", ret, sample_pbap_print_error(ret)); + return false; + } + ret = (uint32_t)pbap_pce_set_phone_book(bd_addr, tel_name); + if (ret != ERRCODE_BT_SUCCESS) { + printf("0x%x %s\n", ret, sample_pbap_print_error(ret)); + return false; + } + } else { + printf("no folder be seleted.\n"); + return false; + } + if (sample_pbap_set_folder_vcf(name, vcf, false)) { + return false; + } else { + ret = (uint32_t)pbap_pce_set_phone_book(bd_addr, name); + if (ret != ERRCODE_BT_SUCCESS) { + printf("0x%x %s\n", ret, sample_pbap_print_error(ret)); + return false; + } + } + + if (strcpy_s((char *)name, PBAP_APP_FOLDER_MAXLENGTH, vcf_name) != EOK) { + printf("strcpy_s vcf_name fail\n"); + return false; + } + return true; +} + +/* get phone vCard-Entry */ +void uapi_pbap_cmd_pull_vcard_entry(td_char *vcf_name) +{ + printf("uapi_pbap_cmd_pull_vcard_entry: %s\r\n",vcf_name); + bd_addr_t bdaddr={0}; + OHOS::uapi_get_br_address(&bdaddr); + + uint8_t format=1; + uint8_t vcf=PBAP_VCF_PB; + uint8_t folder=1; + if (!wstp_pbap_check_param_valid(folder, vcf, 0, 0, format)) { + printf("pbap param invalid\n"); + return; + } + + pbap_pce_pull_vcard_entry_param_t *thr_par = + (pbap_pce_pull_vcard_entry_param_t*)(void *)malloc(sizeof(pbap_pce_pull_vcard_entry_param_t)); + if (thr_par == NULL) { + printf("pbap param malloc failed\n"); + return; + } + (void)memset_s(thr_par, sizeof(pbap_pce_pull_vcard_entry_param_t), 0, sizeof(pbap_pce_pull_vcard_entry_param_t)); + thr_par->name = (uint8_t*)(void *)malloc(PBAP_APP_FOLDER_MAXLENGTH); + if (thr_par->name == NULL) { + printf("pbap param name malloc failed\n"); + free(thr_par); + return; + } + (void)memset_s(thr_par->name, PBAP_APP_FOLDER_MAXLENGTH, 0, PBAP_APP_FOLDER_MAXLENGTH); + + thr_par->format = format; /* index = 5 */ + uint32_t property = PBAP_PROPERTY_MASK_TEL | PBAP_PROPERTY_MASK_FN; /* index = 6 */ + sample_pbap_set_property(thr_par->property_selector, property); + uint8_t filter = 0; /* index = 7 */ + if (filter != 0) { + sample_pbap_filter_composer(thr_par->property_selector, PBAP_PROPERTY_MASK_FILTER); + } + + if (sample_pbap_set_vcard_entry_name(&bdaddr, folder, vcf, vcf_name, thr_par->name)) { + pbap_pce_pull_vcard_entry(&bdaddr, thr_par); + } + free(thr_par->name); + free(thr_par); + printf("uapi_pbap_cmd_pull_vcard_entry\n"); +} + +/* get phone vCard-Entry */ +static void sample_pbap_cmd_pull_vcard_entry(const char **params, int32_t params_cnt) +{ + // if (params_cnt != 8) { /* 8个参数 */ + // printf("params cnt err: %d!\n", params_cnt); + // return; + // } + + // uint32_t sample_mode; + // if (sscanf_s(params[0], "%x", &sample_mode) <= 0) { + // printf("get sample_mode fail\n"); + // return; + // } + // bd_addr_t* bd_addr = NULL; + // if (!sample_pbap_is_null_pointer((uint16_t)sample_mode, 0)) { + // bd_addr = sample_pbap_parse_addr(params[1]); + // } + + // if (pbap_pce_get_device_connect_state(bd_addr) != PROFILE_STATE_CONNECTED) { + // printf("No PBAP connection selected!\n"); + // return; + // } + + // pbap_pce_pull_vcard_entry_param_t *thr_par = + // (pbap_pce_pull_vcard_entry_param_t*)(void *)bt_os_new(sizeof(pbap_pce_pull_vcard_entry_param_t)); + // if (thr_par == NULL) { + // printf("pbap param malloc failed\n"); + // return; + // } + // (void)memset_s(thr_par, sizeof(pbap_pce_pull_vcard_entry_param_t), 0, sizeof(pbap_pce_pull_vcard_entry_param_t)); + // thr_par->name = (uint8_t*)(void *)bt_os_new(PBAP_APP_FOLDER_MAXLENGTH); + // if (thr_par->name == NULL) { + // printf("pbap param name malloc failed\n"); + // bt_os_free(thr_par); + // return; + // } + // (void)memset_s(thr_par->name, PBAP_APP_FOLDER_MAXLENGTH, 0, PBAP_APP_FOLDER_MAXLENGTH); + // thr_par->format = (unsigned char)atoi(params[5]); /* index = 5 */ + // uint32_t property = (uint32_t)atoi(params[6]); /* index = 6 */ + // sample_pbap_set_property(thr_par->property_selector, property); + // int filter = atoi(params[7]); /* index = 7 */ + // if (filter != 0) { + // sample_pbap_filter_composer(thr_par->property_selector, PBAP_PROPERTY_MASK_FILTER); + // } + // uint8_t folder = (uint8_t)atoi(params[2]); /* index = 2 */ + // uint8_t vcf = (uint8_t)atoi(params[3]); /* index = 3 */ + // const td_char* vcf_name = params[4]; /* index = 4 */ + + // if (sample_pbap_set_vcard_entry_name(bd_addr, folder, vcf, vcf_name, thr_par->name)) { + // pbap_pce_pull_vcard_entry(bd_addr, thr_par); + // } + // bt_os_free(thr_par->name); + // bt_os_free(thr_par); +} + +/* pbap abort operation */ + void uapi_pbap_cmd_stop_trans(void) +{ + + bd_addr_t bdaddr={0}; + OHOS::uapi_get_br_address(&bdaddr); + + if (pbap_pce_get_device_connect_state(&bdaddr) != PROFILE_STATE_CONNECTED) { + printf("No PBAP connection selected!\n"); + return; + } + uint32_t result = (uint32_t)pbap_pce_stop_trans(&bdaddr); + printf("[Line: %d] finish, ret: 0x%x\n", __LINE__, result); +} + +/* pbap get connect status */ +void uapi_pbap_amd_get_conn_state(void) +{ + bd_addr_t bdaddr={0}; + OHOS::uapi_get_br_address(&bdaddr); + + uint32_t result = (uint32_t)pbap_pce_get_device_connect_state(&bdaddr); + printf("[Line: %d] finish, conn state: 0x%x\n", __LINE__, result); +} + +/* PBAP service test cmd id */ +typedef enum { + SAMPLE_PBAP_CMD_REG_CALLBACK, /* 注册回调 */ + SAMPLE_PBAP_CMD_START_CLIENT, /* 启动PBAP客户端 */ + SAMPLE_PBAP_CMD_STOP_CLIENT, /* 关闭PBAP客户端 */ + SAMPLE_PBAP_CMD_PULL_PHONEBOOK, /* 下载电话簿 */ + SAMPLE_PBAP_CMD_PULL_VCARD_LISTING, /* 下载vcard列表 */ + SAMPLE_PBAP_CMD_PULL_VCARD_ENTRY, /* 下载vcard条目 */ + SAMPLE_PBAP_CMD_STOP_TRANS, /* 中断传输 */ + SAMPLE_PBAP_CMD_GET_CONN_STATE, /* 获取连接状态 */ +} sample_pbap_cmd_id; + +typedef void (*pbap_sample_cmd_handle_func)(const char **params, int32_t params_cnt); + +typedef struct { + sample_pbap_cmd_id id; + pbap_sample_cmd_handle_func func; +} sample_pbap_hdl_info; + +// sample_pbap_hdl_info g_sample_pbap_hdls[] = { +// { SAMPLE_PBAP_CMD_REG_CALLBACK, sample_pbap_cmd_reg_callback }, +// { SAMPLE_PBAP_CMD_START_CLIENT, sample_pbap_cmd_start_client }, +// { SAMPLE_PBAP_CMD_STOP_CLIENT, sample_pbap_cmd_stop_client }, +// { SAMPLE_PBAP_CMD_PULL_PHONEBOOK, sample_pbap_cmd_pull_phonebook }, +// { SAMPLE_PBAP_CMD_PULL_VCARD_LISTING, sample_pbap_cmd_pull_vcard_listing }, +// { SAMPLE_PBAP_CMD_PULL_VCARD_ENTRY, sample_pbap_cmd_pull_vcard_entry }, +// { SAMPLE_PBAP_CMD_STOP_TRANS, sample_pbap_cmd_stop_trans }, +// { SAMPLE_PBAP_CMD_GET_CONN_STATE, sample_pbap_amd_get_conn_state }, +// }; + +// void bt_pbap_service_sample_cmd(uint32_t cmd_id, const char **params, int32_t params_cnt) +// { +// printf("id: %u\n", cmd_id); +// uint32_t hdl_cnt = sizeof(g_sample_pbap_hdls) / sizeof(sample_pbap_hdl_info); +// for (uint32_t i = 0; i < hdl_cnt; i++) { +// if (g_sample_pbap_hdls[i].id == cmd_id) { +// g_sample_pbap_hdls[i].func(params, params_cnt); +// return; +// } +// } +// printf("invalid cmd_id = %d \n", cmd_id); +// } + +#ifdef __cplusplus +} +#endif + diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/MainBluetoothView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/MainBluetoothView.cpp index 5e1ca8918..bd59fb640 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/MainBluetoothView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/MainBluetoothView.cpp @@ -57,6 +57,9 @@ MainBluetoothView *MainBluetoothView::GetInstance() void MainBluetoothView::OnStart() { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::~OnStart"); + + BluetoothModel *bluetoothModel = BluetoothModel::GetInstance(); if (bluetoothModel == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothEarPhoneView::InitView bluetoothModel nullptr err"); @@ -69,14 +72,16 @@ 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);//若一个都没有连接过就进行搜索 } - Draw(); + RootView::GetInstance()->Invalidate(); return; } + +/*跳转到已连接过的蓝牙设备列表视图*/ bool MainBluetoothView::ChangeBluetoothDeviceListView(int16_t hideView, int16_t thisView) { UNUSED(hideView); @@ -87,24 +92,26 @@ bool MainBluetoothView::ChangeBluetoothDeviceListView(int16_t hideView, int16_t WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothDeviceListView new fail"); return false; } - // init view - UIViewGroup *group = bluetoothDeviceListView->InitShowUpView(); + UIViewGroup *group = bluetoothDeviceListView->CreateBluetoothDeviceListView(); if (group == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Device group nullptr fail"); return false; } container[thisView] = group; - AddViewToRootContainer(container[thisView]); - } else { - // 刷新列表 - UIList *deviceList = bluetoothDeviceListView->GetDeviceUIList(); - if (deviceList == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick deviceList nullptr"); - return false; - } - deviceList->RefreshList(); + RootView::GetInstance()->Add(container[thisView]); + } + // else { + // // 刷新列表 + // UIList *deviceList = bluetoothDeviceListView->GetDeviceUIList(); + // if (deviceList == nullptr) { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick deviceList nullptr"); + // return false; + // } + // deviceList->RefreshList(); + // } + if(bluetoothDeviceListView) { + bluetoothDeviceListView->RefreshBluetoothDeviceListView(); } - bluetoothDeviceListView->RefreshText(); return true; } @@ -119,13 +126,13 @@ bool MainBluetoothView::ChangeTipsFailMessageView(int16_t hideView, int16_t this return false; } // init view - UIViewGroup *group = tipsFailMessageView->ShowUpViewInit(); + UIViewGroup *group = tipsFailMessageView->CreateTipsFailMessageView(); if (group == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); return false; } container[thisView] = group; - AddViewToRootContainer(container[thisView]); + RootView::GetInstance()->Add(container[thisView]); } return true; } @@ -147,7 +154,7 @@ bool MainBluetoothView::ChangeTipsConnFailMessageView(int16_t hideView, int16_t return false; } container[thisView] = group; - AddViewToRootContainer(container[thisView]); + RootView::GetInstance()->Add(container[thisView]); } if (bluetoothReconnectView == nullptr) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GapAclStateChangedCallback bluetoothReconnectView == nullptr"); @@ -158,6 +165,7 @@ bool MainBluetoothView::ChangeTipsConnFailMessageView(int16_t hideView, int16_t return true; } +//连接成功界面 bool MainBluetoothView::ChangeTipsSuccMessageView(int16_t hideView, int16_t thisView) { UNUSED(hideView); @@ -175,11 +183,12 @@ bool MainBluetoothView::ChangeTipsSuccMessageView(int16_t hideView, int16_t this return false; } container[thisView] = group; - AddViewToRootContainer(container[thisView]); + RootView::GetInstance()->Add(container[thisView]); } return true; } +//搜索界面 bool MainBluetoothView::ChangeBluetoothEarPhoneView(int16_t hideView, int16_t thisView) { UNUSED(hideView); @@ -196,7 +205,7 @@ bool MainBluetoothView::ChangeBluetoothEarPhoneView(int16_t hideView, int16_t th return false; } container[thisView] = group; - AddViewToRootContainer(container[thisView]); + RootView::GetInstance()->Add(container[thisView]); } // 动画开始 bluetoothEarPhoneView->BtAnimatorStart(); @@ -205,6 +214,7 @@ bool MainBluetoothView::ChangeBluetoothEarPhoneView(int16_t hideView, int16_t th return true; } +//扫描出来的设备列表界面 bool MainBluetoothView::ChangeBluetoothEarListView(int16_t hideView, int16_t thisView) { if (container[thisView] == nullptr) { @@ -220,17 +230,21 @@ bool MainBluetoothView::ChangeBluetoothEarListView(int16_t hideView, int16_t thi return false; } container[thisView] = group; - AddViewToRootContainer(container[thisView]); - } else { - // 刷新列表 - UIList *scanList = bluetoothEarListView->GetScanUIList(); - if (scanList == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick scanList nullptr"); - return false; - } - scanList->RefreshList(); + RootView::GetInstance()->Add(container[thisView]); + } + // else { + // // 刷新列表 + // UIList *scanList = bluetoothEarListView->GetScanUIList(); + // if (scanList == nullptr) { + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick scanList nullptr"); + // return false; + // } + // scanList->RefreshList(); + // } + // ResetEarListView(hideView); + if(bluetoothEarListView) { + bluetoothEarListView->RefreshBluetoothEarListView(); } - ResetEarListView(hideView); return true; } @@ -245,17 +259,18 @@ 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; } container[thisView] = group; - AddViewToRootContainer(container[thisView]); + RootView::GetInstance()->Add(container[thisView]); } return true; } +//重新连接界面 bool MainBluetoothView::ChangeBluetoothReconnectView(int16_t hideView, int16_t thisView) { UNUSED(hideView); @@ -272,7 +287,7 @@ bool MainBluetoothView::ChangeBluetoothReconnectView(int16_t hideView, int16_t t return false; } container[thisView] = group; - AddViewToRootContainer(container[thisView]); + RootView::GetInstance()->Add(container[thisView]); } BluetoothModel::GetInstance()->SetTagDisconnectView(true); bluetoothReconnectView->RefreshBluetoothNameLabel(); @@ -280,6 +295,7 @@ bool MainBluetoothView::ChangeBluetoothReconnectView(int16_t hideView, int16_t t return true; } +/*连接失败和蓝牙重连视图都跳转到已连接的蓝牙设备列表视图*/ void MainBluetoothView::CorrespondingJump(int16_t hideView) { BluetoothModel *bluetoothModel = BluetoothModel::GetInstance(); @@ -287,17 +303,19 @@ void MainBluetoothView::CorrespondingJump(int16_t hideView) WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView bluetoothModel == nullptr"); return; } - if (bluetoothModel->GetTagReconnectJump()) { - ChangeView(hideView, BLUETOOTHEOPTIONSVIEW); - } else { - std::list &bluetoothScanList = BluetoothModel::GetInstance()->GetCase(); - bool ret = bluetoothScanList.empty(); - if (!ret) { - ChangeView(hideView, BLUETOOTHEARLISTVIEW); - } else { - ChangeView(hideView, BLUETOOTHEARPHONEVIEW); - } - } + ChangeView(hideView, BLUETOOTHDEVICELISTVIEW);/*查看已连接过的蓝牙耳机设备视图*/ + + // if (bluetoothModel->GetTagReconnectJump()) { + // ChangeView(hideView, BLUETOOTHEOPTIONSVIEW);/*查看已连接过的蓝牙耳机设备视图*/ + // } else { + // std::list &bluetoothScanList = BluetoothModel::GetInstance()->GetCase(); + // bool ret = bluetoothScanList.empty(); + // if (!ret) { + // ChangeView(hideView, BLUETOOTHEARLISTVIEW);/*扫描出的耳机列表界面*/ + // } else { + // ChangeView(hideView, BLUETOOTHEARPHONEVIEW);/*搜索界面*/ + // } + // } return; } @@ -306,7 +324,8 @@ void MainBluetoothView::ChangeSettingView() WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::ChangeSettingView"); BluetoothModel::GetInstance()->SetTagConnectView(false); BluetoothModel::GetInstance()->SetTagScanDeviceClicked(false); - NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); + // NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); + NativeAbility::GetInstance().Back(); } void MainBluetoothView::DropEarPhoneView() @@ -319,9 +338,9 @@ void MainBluetoothView::DropEarPhoneView() bluetoothEarPhoneView->StopBtDiscovery(); bool ret = BluetoothModel::GetInstance()->IsTagReturnToDeviceListView(); if (ret) { - ChangeView(BLUETOOTHEARPHONEVIEW, BLUETOOTHDEVICELISTVIEW); + ChangeView(BLUETOOTHEARPHONEVIEW, BLUETOOTHDEVICELISTVIEW);//返回到已连接的设备列表界面 } else { - ChangeSettingView(); + ChangeSettingView(); //退出蓝牙耳机界面 } } @@ -353,32 +372,33 @@ void MainBluetoothView::DropEarListView() void MainBluetoothView::DropView(UIView& view) { - if (&view == container[BLUETOOTHEARPHONEVIEW]) { + if (&view == container[BLUETOOTHEARPHONEVIEW]) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[BLUETOOTHEARPHONEVIEW]"); - DropEarPhoneView(); + DropEarPhoneView();//搜索界面右滑退出操作 } else if (&view == container[BLUETOOTHEOPTIONSVIEW]) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[BLUETOOTHEOPTIONSVIEW]"); - ChangeView(BLUETOOTHEOPTIONSVIEW, BLUETOOTHDEVICELISTVIEW); + ChangeView(BLUETOOTHEOPTIONSVIEW, BLUETOOTHDEVICELISTVIEW);//查看已连接过的蓝牙耳机设备视图->已连接过的蓝牙耳机设备视图 } else if (&view == container[TIPSCONNFAILMESSAGEVIEW]) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[TIPSCONNFAILMESSAGEVIEW]"); - CorrespondingJump(TIPSCONNFAILMESSAGEVIEW); + ChangeView(TIPSCONNFAILMESSAGEVIEW, BLUETOOTHDEVICELISTVIEW);/*连接失败的提示视图 ->已连接过的蓝牙耳机设备视图*/ } else if (&view == container[TIPSSUCCMESSAGEVIEW]) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[TIPSSUCCMESSAGEVIEW]"); - ChangeView(TIPSSUCCMESSAGEVIEW, BLUETOOTHDEVICELISTVIEW); + ChangeView(TIPSSUCCMESSAGEVIEW, BLUETOOTHDEVICELISTVIEW);//连接成功的提示视图->已连接过的蓝牙设备列表视图 } else if (&view == container[TIPSFAILMESSAGEVIEW]) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[TIPSFAILMESSAGEVIEW]"); - ChangeView(TIPSFAILMESSAGEVIEW, BLUETOOTHEARPHONEVIEW); + // ChangeView(TIPSFAILMESSAGEVIEW, BLUETOOTHEARPHONEVIEW);//未搜索到蓝牙耳机界面->搜索界面 + ChangeSettingView();//未搜索到蓝牙耳机界面->退出蓝牙耳机界面 } else if (&view == container[BLUETOOTHEARLISTVIEW]) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[BLUETOOTHEARLISTVIEW]"); DropEarListView(); } else if (&view == container[BLUETOOTHDEVICELISTVIEW]) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[BLUETOOTHDEVICELISTVIEW]"); - ChangeSettingView(); + ChangeSettingView();//已连接过的蓝牙设备列表视图 -> 退出蓝牙耳机界面 } else if (&view == container[BLUETOOTHRECONNECTVIEW]) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::DropView::container[BLUETOOTHRECONNECTVIEW]"); - CorrespondingJump(BLUETOOTHRECONNECTVIEW); BluetoothModel::GetInstance()->SetTagDisconnectView(false); - bluetoothReconnectView->BtReconnectStop(); + CorrespondingJump(BLUETOOTHRECONNECTVIEW); + bluetoothReconnectView->BtReconnectStop();/*停止动画*/ } } @@ -395,7 +415,7 @@ void MainBluetoothView::ResetEarListView(int16_t hideView) } else if (hideView == TIPSCONNFAILMESSAGEVIEW) { bluetoothEarListView->SetTitleLabel("扫描完成"); bluetoothEarListView->SetNewEquipmentButtonAdd(); - Draw(); + RootView::GetInstance()->Invalidate(); } } @@ -441,7 +461,7 @@ void MainBluetoothView::ChangeView(int16_t hideView, int16_t showView) } container[showView]->SetVisible(true); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView:: ChangeView end!!!%d", showView); - Draw(); + RootView::GetInstance()->Invalidate(); BluetoothModel::GetInstance()->SetCurView(showView); } } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/TipsConnFailMessageView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/TipsConnFailMessageView.cpp index 552f968aa..78a9d0752 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/TipsConnFailMessageView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/TipsConnFailMessageView.cpp @@ -10,193 +10,279 @@ #include "UiConfig.h" #include "PlayersPresenter.h" #include "BluetoothPresenter.h" - -namespace OHOS { -static TipsConnFailMessageView *g_pConnFailMessageView{nullptr}; -TipsConnFailMessageView::TipsConnFailMessageView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView::TipsConnFailMessageView"); - g_pConnFailMessageView = this; -} - -TipsConnFailMessageView::~TipsConnFailMessageView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView::~TipsConnFailMessageView"); - group->RemoveAll(); - delete titleLabel; - titleLabel = nullptr; - delete backButton; - backButton = nullptr; - delete group; - group = nullptr; - delete tipImg; - tipImg = nullptr; - delete tipLabel; - tipLabel = nullptr; - delete tipTwoLabel; - tipTwoLabel = nullptr; - g_pConnFailMessageView = nullptr; -} - -TipsConnFailMessageView *TipsConnFailMessageView::GetInstance() +#include "ui_resource_string.h" +namespace OHOS { - return g_pConnFailMessageView; -} - -void TipsConnFailMessageView::ShowUpTipLabel() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView::ShowUpTipLabel"); - if (tipLabel == nullptr) { - tipLabel = new UILabel(); - if (tipLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView tipLabel new fail"); - return; - } - tipLabel->SetPosition(0, 247, HORIZONTAL_RESOLUTION, 35); // 0:x 247:y 454:width 35:height. - tipLabel->SetText("请确认该设备在通信范"); - tipLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30:font data - tipLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); - tipLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, - UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); - group->Add(tipLabel); + static TipsConnFailMessageView *g_pConnFailMessageView{nullptr}; + TipsConnFailMessageView::TipsConnFailMessageView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView::TipsConnFailMessageView"); + g_pConnFailMessageView = this; } - if (tipTwoLabel == nullptr) { - tipTwoLabel = new UILabel(); - if (tipTwoLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView tipTwoLabel new fail"); - return; + + TipsConnFailMessageView::~TipsConnFailMessageView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView::~TipsConnFailMessageView"); + if (group) + { + group->RemoveAll(); + if (titleLabel) + { + delete titleLabel; + titleLabel = nullptr; + } + if (tipImg) + { + delete tipImg; + tipImg = nullptr; + } + if (backButton) + { + delete backButton; + backButton = nullptr; + } + if (tipLabel) + { + delete tipLabel; + tipLabel = nullptr; + } + if (conn_fail_Label) + { + delete conn_fail_Label; + conn_fail_Label = nullptr; + } + if (bluetoothNameLabel) + { + delete bluetoothNameLabel; + bluetoothNameLabel = nullptr; + } + delete group; + group = nullptr; } - tipTwoLabel->SetPosition(0, 300, HORIZONTAL_RESOLUTION, 34); // 0:x 300:y 454:width 34:height. - tipTwoLabel->SetText("围内且处于待配对状态。"); - tipTwoLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30:font data - tipTwoLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); - tipTwoLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, - UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); - group->Add(tipTwoLabel); + g_pConnFailMessageView = nullptr; } - return; -} -void TipsConnFailMessageView::InitNameLabel(void) -{ - if (bluetoothNameLabel == nullptr) { - bluetoothNameLabel = new UILabel(); - if (bluetoothNameLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothNameLabel new fail"); - return; - } - bluetoothNameLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); - bluetoothNameLabel->SetPosition(60, 139, 333, 45); // 60:x 139:y 333:width 45:height - bluetoothNameLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_THIRTY_SIZE); - bluetoothNameLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); - bluetoothNameLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, - UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); - group->Add(bluetoothNameLabel); + TipsConnFailMessageView *TipsConnFailMessageView::GetInstance() + { + return g_pConnFailMessageView; } -} -void TipsConnFailMessageView::ShowUpButtonBack() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView::ShowUpButtonBack"); - if (backButton == nullptr) { - backButton = new UILabelButton(); - if (backButton == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView backButton new fail"); - return; + void TipsConnFailMessageView::ShowUpTipLabel() + { +#if 0 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView::ShowUpTipLabel"); + if (tipLabel == nullptr) + { + tipLabel = new UILabel(); + if (tipLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView tipLabel new fail"); + return; + } + tipLabel->SetPosition(0, 247, HORIZONTAL_RESOLUTION, 35); // 0:x 247:y 454:width 35:height. + tipLabel->SetText("请确认该设备在通信范"); + tipLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30:font data + tipLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); + tipLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, + UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + group->Add(tipLabel); } - 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 (tipTwoLabel == nullptr) + { + tipTwoLabel = new UILabel(); + if (tipTwoLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView tipTwoLabel new fail"); + return; + } + tipTwoLabel->SetPosition(0, 300, HORIZONTAL_RESOLUTION, 34); // 0:x 300:y 454:width 34:height. + tipTwoLabel->SetText("围内且处于待配对状态。"); + tipTwoLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 30:font data + tipTwoLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); + tipTwoLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, + UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + group->Add(tipTwoLabel); } - backButton->SetPosition(65, 359, 324, 101); // 65:x, 359:y, 324:width 101:height. - backButton->SetText("重试"); - backButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); // 40:font data - backButton->SetImageSrc(PNG_NEW_DEVICE, PNG_NEW_DEVICE); - backButton->SetViewId(BLUETOOTH_CONN_FAIL_BACK_BUTTON); - if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { - backButton->SetTextColor(Color::Red()); - backButton->SetOnClickListener(clickListener); - } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) { - backButton->SetTextColor(Color::Blue()); - backButton->SetOnClickListener(clickListener2); - } - group->Add(backButton); +#endif + return; } - if (tipImg == nullptr) { - tipImg = new UIImageView(); - if (tipImg == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView tipImg new fail"); - return; + + UIViewGroup *TipsConnFailMessageView::ShowUpViewInit(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView::ShowUpViewInit"); + 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 *tipsDragListener = (UIView::OnDragListener *)OHOS::PlayerOnDragListener::GetInstance(); + UIView::OnDragListener *tipsDragListener2 = (UIView::OnDragListener *)OHOS::BluetoothPresenter::GetInstance(); + if ((tipsDragListener == nullptr) && (tipsDragListener2 == nullptr)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tipsDragListener GetInstance fail"); + return nullptr; + } + if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) + { + group->SetOnDragListener(tipsDragListener); + } + else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) + { + group->SetOnDragListener(tipsDragListener2); + } + group->SetViewId(TIPS_CONN_FAIL_MESSAGE_VIEW); + group->SetDraggable(true); + group->SetTouchable(true); + /* -------------------------------------------------------------------------- */ + if (titleLabel == nullptr) + { + titleLabel = new UILabelExt(); + if (titleLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView titleLabel new fail"); + return nullptr; + } + titleLabel->SetPosition(83, 50, 300, 35); + titleLabel->SetTextId(STR_BLUETOOTH_HEADPHONES); // 蓝牙耳机 + titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + titleLabel->SetStyle(STYLE_TEXT_FONT, 30); + titleLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + titleLabel->SetRollSpeed(23); + titleLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + } + /* --------------------------------- tipImg --------------------------------- */ + if (tipImg == nullptr) + { + tipImg = new UIImageView(); + if (tipImg == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView tipImg new fail"); + return nullptr; + } + tipImg->SetPosition(193, 121, 80, 80); + tipImg->SetSrc(PNG_ATTENTION_IMAGE); + } + /* --------------------------- bluetoothNameLabel --------------------------- */ + if (bluetoothNameLabel == nullptr) + { + bluetoothNameLabel = new UILabelExt(); + if (bluetoothNameLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothNameLabel new fail"); + return nullptr; + } + bluetoothNameLabel->SetPosition(53, 235, 360, 35); + bluetoothNameLabel->SetStyle(STYLE_TEXT_FONT, 30); + bluetoothNameLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + bluetoothNameLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + bluetoothNameLabel->SetRollSpeed(23); + bluetoothNameLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30); + bluetoothNameLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + } + /* ----------------------------- conn_fail_Label ---------------------------- */ + if (conn_fail_Label == nullptr) + { + conn_fail_Label = new UILabelExt(); + if (conn_fail_Label == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView conn_fail_Label new fail"); + return nullptr; + } + conn_fail_Label->SetPosition(53, bluetoothNameLabel->GetY() + bluetoothNameLabel->GetHeight(), 360, 35); + conn_fail_Label->SetTextId(STR_CONNECTION_FAIL); + conn_fail_Label->SetStyle(STYLE_TEXT_FONT, 30); + conn_fail_Label->SetStyle(STYLE_LINE_HEIGHT, 35); + conn_fail_Label->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + conn_fail_Label->SetRollSpeed(23); + conn_fail_Label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + conn_fail_Label->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + conn_fail_Label->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); + } + /* -------------------------------- tipLabel -------------------------------- */ + if (tipLabel == nullptr) + { + tipLabel = new UILabelExt(); + if (tipLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView tipLabel new fail"); + return nullptr; + } + tipLabel->SetPosition(53, conn_fail_Label->GetY() + conn_fail_Label->GetHeight(), 360, 35); + tipLabel->SetTextId(STR_CONNECTION_FAIL); + tipLabel->SetStyle(STYLE_TEXT_FONT, 30); + tipLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + // tipLabel->SetText("请确认该设备在通信范围内且处于待配对状态"); + tipLabel->SetTextId(STR_BTEARPHONE_CONN_FAIL_TIP); + tipLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + // tipLabel->SetRollSpeed(23); + tipLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + tipLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + tipLabel->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); + } + /* ------------------------------- backButton ------------------------------- */ + if (backButton == nullptr) + { + backButton = new UILabelButtonExt(); + if (backButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView backButton new fail"); + return nullptr; + } + 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 nullptr; + } + backButton->SetPosition(0, 366, 466, 100); + backButton->SetTextId(STR_RETRY); // 重试 + backButton->SetStyle(STYLE_LINE_HEIGHT, 35); + backButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + backButton->SetImageSrc(PNG_BUTTON_466x100_IMAGE, PNG_BUTTON_466x100_IMAGE); + backButton->SetViewId(BLUETOOTH_CONN_FAIL_BACK_BUTTON); + if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) + { + backButton->SetOnClickListener(clickListener); + } + else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) + { + backButton->SetOnClickListener(clickListener2); + } + } + group->Add(titleLabel); + group->Add(tipImg); + group->Add(bluetoothNameLabel); + group->Add(conn_fail_Label); + group->Add(tipLabel); + group->Add(backButton); } - tipImg->SetPosition(178, 20, 90, 90); // 178:x 20:y 90:width 90:height. - tipImg->SetSrc(PNG_GANTAN); - group->Add(tipImg); + return group; } - return; -} -UIViewGroup *TipsConnFailMessageView::ShowUpViewInit(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView::ShowUpViewInit"); - if (group == nullptr) { - group = new UIViewGroup(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); - return nullptr; + // 刷新设备名称 + void TipsConnFailMessageView::RefreshNameLabel(const bd_addr_t &bdAddr) + { + BluetoothCaseInfo caseInfo; + (void)memcpy_s(caseInfo.addr, BD_ADDR_LEN, bdAddr.addr, BD_ADDR_LEN); + bool ret = BluetoothModel::GetInstance()->FindNameFromList(&caseInfo); + if (!ret) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView FindNameFromList fail"); + return; } - 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, "TipsConnFailMessageView titleLabel new fail"); - return nullptr; + if (bluetoothNameLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView::RefreshNameLabel bluetoothNameLabel == nullptr"); + return; } - titleLabel->SetPosition(0, 189, HORIZONTAL_RESOLUTION, 45); // 0:x 189:y 454:width 45:height. - titleLabel->SetText("连接失败"); - titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); // 40:font data - titleLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); - titleLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, - UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); - group->Add(titleLabel); - } - ShowUpButtonBack(); - ShowUpTipLabel(); - InitNameLabel(); - UIView::OnDragListener *tipsDragListener = (UIView::OnDragListener *)OHOS::PlayerOnDragListener::GetInstance(); - UIView::OnDragListener *tipsDragListener2 = (UIView::OnDragListener *)OHOS::BluetoothPresenter::GetInstance(); - if ((tipsDragListener == nullptr) && (tipsDragListener2 == nullptr)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tipsDragListener GetInstance fail"); - return nullptr; - } - if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { - group->SetOnDragListener(tipsDragListener); - } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) { - group->SetOnDragListener(tipsDragListener2); - } - group->SetViewId(TIPS_CONN_FAIL_MESSAGE_VIEW); - group->SetDraggable(true); - group->SetTouchable(true); - return group; -} - -void TipsConnFailMessageView::RefreshNameLabel(const bd_addr_t &bdAddr) -{ - BluetoothCaseInfo caseInfo; - (void)memcpy_s(caseInfo.addr, BD_ADDR_LEN, bdAddr.addr, BD_ADDR_LEN); - bool ret = BluetoothModel::GetInstance()->FindNameFromList(&caseInfo); - if (!ret) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView FindNameFromList fail"); - return; - } - if (bluetoothNameLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsConnFailMessageView::RefreshNameLabel bluetoothNameLabel == nullptr"); - return; + bluetoothNameLabel->SetText(reinterpret_cast(caseInfo.deviceName)); } - bluetoothNameLabel->SetText(reinterpret_cast(caseInfo.deviceName)); -} } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/TipsFailMessageView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/TipsFailMessageView.cpp index 4d732b85d..c8bd18943 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/TipsFailMessageView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/TipsFailMessageView.cpp @@ -8,120 +8,208 @@ #include "BluetoothModel.h" #include "wearable_log.h" #include "UiConfig.h" -#include "PlayersPresenter.h" -#include "BluetoothPresenter.h" +#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 { -static TipsFailMessageView *g_pFailMessageView{nullptr}; -TipsFailMessageView::TipsFailMessageView() +namespace OHOS { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsFailMessageView::TipsFailMessageView"); - g_pFailMessageView = this; -} + static TipsFailMessageView *g_pFailMessageView{nullptr}; + TipsFailMessageView::TipsFailMessageView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsFailMessageView::TipsFailMessageView"); + g_pFailMessageView = this; + } -TipsFailMessageView::~TipsFailMessageView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsFailMessageView::~TipsFailMessageView"); - group->RemoveAll(); - delete titleLabel; - titleLabel = nullptr; - delete backButton; - backButton = nullptr; - delete group; - group = nullptr; - delete tipImg; - tipImg = nullptr; - g_pFailMessageView = nullptr; -} + TipsFailMessageView::~TipsFailMessageView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsFailMessageView::~TipsFailMessageView"); + if (group != nullptr) + { + group->RemoveAll(); + if (titleLabel) + { + delete titleLabel; + titleLabel = nullptr; + } + if (btIconImage) + { + delete btIconImage; + btIconImage = nullptr; + ImageCacheManager::GetInstance().UnloadOneInMultiRes(PLAYER_BLUETOOTH_GRAY, PLAYER_IAMGES); + } + if (btHeadsetNotFoundLabel) + { + delete btHeadsetNotFoundLabel; + btHeadsetNotFoundLabel = nullptr; + } + if (rescanButton) + { + delete rescanButton; + rescanButton = nullptr; + } + delete group; + group = nullptr; + } + g_pFailMessageView = nullptr; + } -TipsFailMessageView *TipsFailMessageView::GetInstance() -{ - return g_pFailMessageView; -} + TipsFailMessageView *TipsFailMessageView::GetInstance() + { + return g_pFailMessageView; + } -int TipsFailMessageView::ShowUpButtonBack() -{ - if (backButton == nullptr) { - backButton = new UILabelButton(); - if (backButton == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsFailMessageView backButton new fail"); - return OHOS_FAILURE; + bool TipsFailMessageView::CreateTipsFailMessageLabelView(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsFailMessageView::CreateTipsFailMessageLabelView"); + /* ------------------------------- titleLabel ------------------------------- */ + if (titleLabel == nullptr) + { + titleLabel = new UILabelExt(); + if (titleLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel new fail"); + return false; + } } - 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 OHOS_FAILURE; + 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); + /* ------------------------- btHeadsetNotFoundLabel ------------------------- */ + if (btHeadsetNotFoundLabel == nullptr) + { + btHeadsetNotFoundLabel = new UILabelExt(); + if (btHeadsetNotFoundLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel new fail"); + return false; + } } - backButton->SetPosition(65, 359, 324, 101); // 65:x, 359:y, 324:width 101:height - backButton->SetText("重试"); - backButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); // 40:font data - backButton->SetImageSrc(PNG_NEW_DEVICE, PNG_NEW_DEVICE); - backButton->SetViewId(BLUETOOTH_FAIL_BACK_BUTTON); - if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { - backButton->SetTextColor(Color::Red()); - backButton->SetOnClickListener(clickListener); - } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) { - backButton->SetTextColor(Color::Blue()); - backButton->SetOnClickListener(clickListener2); + btHeadsetNotFoundLabel->SetPosition(53, 305, 360, 30); + btHeadsetNotFoundLabel->SetStyle(STYLE_TEXT_FONT, 26); + btHeadsetNotFoundLabel->SetStyle(STYLE_LINE_HEIGHT, 30); + btHeadsetNotFoundLabel->SetTextId(STR_BT_HEADSET_NOFOND); /*当前搜索不到耳机蓝牙设备*/ + btHeadsetNotFoundLabel->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); + btHeadsetNotFoundLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + btHeadsetNotFoundLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + btHeadsetNotFoundLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); + + return true; + } + + bool TipsFailMessageView::CreateTipsFailMessageImageView(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsFailMessageView::CreateTipsFailMessageImageView"); + if (btIconImage == nullptr) + { + btIconImage = new UIImageView(); + if (btIconImage == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); + return false; + } + btIconImage->SetPosition(163, 126, 140, 140); + btIconImage->SetAutoEnable(false); + btIconImage->SetResizeMode(UIImageView::CENTER); + if (!PlayersView::LoadPlayerImage(btIconImage, PLAYER_BLUETOOTH_GRAY)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "btIconImage LoadPlayerImage fail"); + return false; + } } - group->Add(backButton); + return true; } - if (tipImg == nullptr) { - tipImg = new UIImageView(); - if (tipImg == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsFailMessageView tipImg new fail"); - return OHOS_FAILURE; + + bool TipsFailMessageView::CreateTipsFailMessageLabelButton() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsFailMessageView::CreateTipsFailMessageLabelButton"); + if (rescanButton == nullptr) + { + rescanButton = new UILabelExt(); + if (rescanButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsFailMessageView rescanButton new fail"); + return false; + } + 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; + } + rescanButton->SetPosition(73, 350, 320, 100); + rescanButton->SetTextId(STR_BT_HEADSET_RESCAN); /*重新搜索*/ + rescanButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + rescanButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + rescanButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + rescanButton->SetViewId(BLUETOOTH_FAIL_BACK_BUTTON); + rescanButton->SetTextColor(Color::GetColorFromRGBA(0x35, 0x49, 0xff, 0xff)); + // rescanButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); + rescanButton->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + rescanButton->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + rescanButton->SetTouchable(true); + if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) + { + rescanButton->SetOnClickListener(clickListener); + } + else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) + { + rescanButton->SetOnClickListener(clickListener2); + } } - tipImg->SetPosition(181, 111, 90, 90); // 181:x 111:y 90:width 90:height - tipImg->SetSrc(PNG_GANTAN); - group->Add(tipImg); + return true; } - return OHOS_SUCCESS; -} -UIViewGroup *TipsFailMessageView::ShowUpViewInit(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsFailMessageView::ShowUpViewInit"); - if (group == nullptr) { - group = new UIViewGroup(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); + UIViewGroup *TipsFailMessageView::CreateTipsFailMessageView(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsFailMessageView::CreateTipsFailMessageView"); + if (group == nullptr) + { + group = new UIViewGroup(); + if (group == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); + return nullptr; + } + group->SetPosition(0, 0, 466, 466); + } + UIView::OnDragListener *tipsDragListener = (UIView::OnDragListener *)OHOS::PlayerOnDragListener::GetInstance(); + UIView::OnDragListener *tipsDragListener2 = (UIView::OnDragListener *)OHOS::BluetoothPresenter::GetInstance(); + if ((tipsDragListener == nullptr) && (tipsDragListener2 == nullptr)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tipsDragListener GetInstance 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, "TipsFailMessageView titleLabel new fail"); + if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) + { + group->SetOnDragListener(tipsDragListener); + } + else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) + { + group->SetOnDragListener(tipsDragListener2); + } + group->SetViewId(TIPS_FAIL_MESSAGE_VIEW); + group->SetDraggable(true); + group->SetTouchable(true); + /* -------------------------------------------------------------------------- */ + if (!CreateTipsFailMessageLabelView() || !CreateTipsFailMessageImageView() || !CreateTipsFailMessageLabelButton()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsFailMessageView::CreateTipsFailMessageView fail!!"); return nullptr; } - titleLabel->SetPosition(0, 234, HORIZONTAL_RESOLUTION, 45); // 0:x 234:y 454:width 45:height - titleLabel->SetText("未发现蓝牙耳机"); - titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); // 40:font data - titleLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); - titleLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, - UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + /* ----------------------------------- Add ---------------------------------- */ group->Add(titleLabel); + group->Add(btIconImage); + group->Add(btHeadsetNotFoundLabel); + group->Add(rescanButton); + /* -------------------------------------------------------------------------- */ + return group; } - ShowUpButtonBack(); - UIView::OnDragListener *tipsDragListener = (UIView::OnDragListener *)OHOS::PlayerOnDragListener::GetInstance(); - UIView::OnDragListener *tipsDragListener2 = (UIView::OnDragListener *)OHOS::BluetoothPresenter::GetInstance(); - if ((tipsDragListener == nullptr) && (tipsDragListener2 == nullptr)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tipsDragListener GetInstance fail"); - return nullptr; - } - if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { - group->SetOnDragListener(tipsDragListener); - } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) { - group->SetOnDragListener(tipsDragListener2); - } - group->SetViewId(TIPS_FAIL_MESSAGE_VIEW); - group->SetDraggable(true); - group->SetTouchable(true); - return group; -} } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/TipsSuccMessageView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/TipsSuccMessageView.cpp index 9bab50fa8..89fb0151a 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/TipsSuccMessageView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/bluetooth/src/TipsSuccMessageView.cpp @@ -10,153 +10,214 @@ #include "UiConfig.h" #include "PlayersPresenter.h" #include "BluetoothPresenter.h" - -namespace OHOS { -static TipsSuccMessageView *g_pSuccMessageView{nullptr}; -TipsSuccMessageView::TipsSuccMessageView() -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView::TipsSuccMessageView"); - g_pSuccMessageView = this; -} - -TipsSuccMessageView::~TipsSuccMessageView() +#include "ui_resource_string.h" +namespace OHOS { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView::~TipsSuccMessageView"); - group->RemoveAll(); - delete titleLabel; - titleLabel = nullptr; - delete backButton; - backButton = nullptr; - delete group; - group = nullptr; - delete tipImg; - tipImg = nullptr; - g_pSuccMessageView = nullptr; -} - -TipsSuccMessageView *TipsSuccMessageView::GetInstance() -{ - return g_pSuccMessageView; -} + static TipsSuccMessageView *g_pSuccMessageView{nullptr}; + TipsSuccMessageView::TipsSuccMessageView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView::TipsSuccMessageView"); + g_pSuccMessageView = this; + } -void TipsSuccMessageView::InitNameLabel(void) -{ - if (bluetoothNameLabel == nullptr) { - bluetoothNameLabel = new UILabel(); - if (bluetoothNameLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothNameLabel new fail"); - return; + TipsSuccMessageView::~TipsSuccMessageView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView::~TipsSuccMessageView"); + if (group) + { + group->RemoveAll(); + if (titleLabel) + { + delete titleLabel; + titleLabel = nullptr; + } + if (tipImg) + { + delete tipImg; + tipImg = nullptr; + } + if (bluetoothNameLabel) + { + delete bluetoothNameLabel; + bluetoothNameLabel = nullptr; + } + if (conn_succ_Label) + { + delete conn_succ_Label; + conn_succ_Label = nullptr; + } + if (backButton) + { + delete backButton; + backButton = nullptr; + } + delete group; + group = nullptr; } - bluetoothNameLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); - bluetoothNameLabel->SetPosition(60, 180, 333, 45); // 60:x 180:y 333:width 45:height - bluetoothNameLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_THIRTY_SIZE); - bluetoothNameLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); - bluetoothNameLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, - UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); - group->Add(bluetoothNameLabel); + g_pSuccMessageView = nullptr; } -} -void TipsSuccMessageView::ShowUpButtonBack() -{ - if (backButton == nullptr) { - backButton = new UILabelButton(); - if (backButton == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView backButton new fail"); - return; - } - 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; - } - backButton->SetPosition(65, 359, 324, 101); // 65:x, 359:y, 324:width 101:height - backButton->SetText("确定"); - backButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); // 40:font data - backButton->SetImageSrc(PNG_NEW_DEVICE, PNG_NEW_DEVICE); - backButton->SetViewId(BLUETOOTH_SUCC_BACK_BUTTON); - if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { - backButton->SetTextColor(Color::Red()); - backButton->SetOnClickListener(clickListener); - } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) { - backButton->SetTextColor(Color::Blue()); - backButton->SetOnClickListener(clickListener2); - } - group->Add(backButton); + TipsSuccMessageView *TipsSuccMessageView::GetInstance() + { + return g_pSuccMessageView; } - if (tipImg == nullptr) { - tipImg = new UIImageView(); - if (tipImg == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView tipImg new fail"); - return; + + UIViewGroup *TipsSuccMessageView::ShowUpViewInit(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView::ShowUpViewInit"); + 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 *tipsDragListener = (UIView::OnDragListener *)OHOS::PlayerOnDragListener::GetInstance(); + UIView::OnDragListener *tipsDragListener2 = (UIView::OnDragListener *)OHOS::BluetoothPresenter::GetInstance(); + if ((tipsDragListener == nullptr) && (tipsDragListener2 == nullptr)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tipsDragListener GetInstance fail"); + return nullptr; + } + if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) + { + group->SetOnDragListener(tipsDragListener); + } + else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) + { + group->SetOnDragListener(tipsDragListener2); + } + group->SetViewId(TIPS_SUCC_MESSAGE_VIEW); + group->SetDraggable(true); + group->SetTouchable(true); + /* ------------------------------- titleLabel ------------------------------- */ + if (titleLabel == nullptr) + { + titleLabel = new UILabelExt(); + if (titleLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothDeviceListView titleLabel new fail"); + return nullptr; + } + titleLabel->SetPosition(83, 50, 300, 35); + titleLabel->SetTextId(STR_BLUETOOTH_HEADPHONES); // 蓝牙耳机 + titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + titleLabel->SetStyle(STYLE_TEXT_FONT, 30); + titleLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + titleLabel->SetRollSpeed(23); + titleLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + } + /* --------------------------------- tipImg --------------------------------- */ + if (tipImg == nullptr) + { + tipImg = new UIImageView(); + if (tipImg == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView tipImg new fail"); + return nullptr; + } + tipImg->SetPosition(193, 121, 80, 80); + tipImg->SetSrc("/user/res/OK.bin"); + } + /* --------------------------- bluetoothNameLabel --------------------------- */ + if (bluetoothNameLabel == nullptr) + { + bluetoothNameLabel = new UILabelExt(); + if (bluetoothNameLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothNameLabel new fail"); + return nullptr; + } + bluetoothNameLabel->SetPosition(53, 235, 360, 35); + bluetoothNameLabel->SetStyle(STYLE_TEXT_FONT, 30); + bluetoothNameLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + bluetoothNameLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + bluetoothNameLabel->SetRollSpeed(23); + bluetoothNameLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30); + bluetoothNameLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + } + /* ----------------------------- conn_succ_Label ---------------------------- */ + if (conn_succ_Label == nullptr) + { + conn_succ_Label = new UILabelExt(); + if (conn_succ_Label == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView conn_succ_Label new fail"); + return nullptr; + } + conn_succ_Label->SetPosition(53, bluetoothNameLabel->GetY() + bluetoothNameLabel->GetHeight(), 360, 35); + // conn_succ_Label->SetText("连接成功"); + conn_succ_Label->SetTextId(STR_CONNECTION_SUCC); + conn_succ_Label->SetStyle(STYLE_TEXT_FONT, 30); + conn_succ_Label->SetStyle(STYLE_LINE_HEIGHT, 35); + conn_succ_Label->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + conn_succ_Label->SetRollSpeed(23); + conn_succ_Label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + conn_succ_Label->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); + conn_succ_Label->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); + } + /* ------------------------------- backButton ------------------------------- */ + if (backButton == nullptr) + { + backButton = new UILabelButtonExt(); + if (backButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView backButton new fail"); + return nullptr; + } + 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 nullptr; + } + backButton->SetPosition(0, 366, 466, 100); + backButton->SetTextId(STR_OK); // 确定 + backButton->SetStyle(STYLE_LINE_HEIGHT, 35); + backButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + backButton->SetImageSrc(PNG_BUTTON_466x100_IMAGE, PNG_BUTTON_466x100_IMAGE); + backButton->SetViewId(BLUETOOTH_SUCC_BACK_BUTTON); + backButton->SetTextColor(Color::GetColorFromRGBA(0x35, 0x49, 0xff, 0xff)); + if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) + { + backButton->SetOnClickListener(clickListener); + } + else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) + { + backButton->SetOnClickListener(clickListener2); + } + } + group->Add(titleLabel); + group->Add(tipImg); + group->Add(bluetoothNameLabel); + group->Add(conn_succ_Label); + group->Add(backButton); } - tipImg->SetPosition(181, 78, 90, 90); // 181:x 78:y 90:width 90:height - tipImg->SetSrc(PNG_RIGHT); - group->Add(tipImg); + return group; } - return; -} -UIViewGroup *TipsSuccMessageView::ShowUpViewInit(void) -{ - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView::ShowUpViewInit"); - if (group == nullptr) { - group = new UIViewGroup(); - if (group == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail"); - return nullptr; + // 刷新设备名称 + void TipsSuccMessageView::RefreshNameLabel(const bd_addr_t &bdAddr) + { + BluetoothCaseInfo caseInfo; + (void)memcpy_s(caseInfo.addr, BD_ADDR_LEN, bdAddr.addr, BD_ADDR_LEN); + bool ret = BluetoothModel::GetInstance()->FindNameFromList(&caseInfo); + if (!ret) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView FindNameFromList fail"); + return; } - 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, "TipsSuccMessageView titleLabel new fail"); - return nullptr; + if (bluetoothNameLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView::RefreshNameLabel bluetoothNameLabel == nullptr"); + return; } - titleLabel->SetPosition(0, 244, HORIZONTAL_RESOLUTION, 45); // 0:x 244:y 454:width 45:height - titleLabel->SetText("连接成功"); - titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); // 40:font data - titleLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE); - titleLabel->SetAlign(UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER, - UITextLanguageAlignment::TEXT_ALIGNMENT_CENTER); - group->Add(titleLabel); - } - InitNameLabel(); - ShowUpButtonBack(); - UIView::OnDragListener *tipsDragListener = (UIView::OnDragListener *)OHOS::PlayerOnDragListener::GetInstance(); - UIView::OnDragListener *tipsDragListener2 = (UIView::OnDragListener *)OHOS::BluetoothPresenter::GetInstance(); - if ((tipsDragListener == nullptr) && (tipsDragListener2 == nullptr)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tipsDragListener GetInstance fail"); - return nullptr; - } - if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERPLAYERS) { - group->SetOnDragListener(tipsDragListener); - } else if (BluetoothModel::GetInstance()->GetBluetoothCalleridStatus() == CALLERSETTING) { - group->SetOnDragListener(tipsDragListener2); - } - group->SetViewId(TIPS_SUCC_MESSAGE_VIEW); - group->SetDraggable(true); - group->SetTouchable(true); - return group; -} - -void TipsSuccMessageView::RefreshNameLabel(const bd_addr_t &bdAddr) -{ - BluetoothCaseInfo caseInfo; - (void)memcpy_s(caseInfo.addr, BD_ADDR_LEN, bdAddr.addr, BD_ADDR_LEN); - bool ret = BluetoothModel::GetInstance()->FindNameFromList(&caseInfo); - if (!ret) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView FindNameFromList fail"); - return; - } - if (bluetoothNameLabel == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TipsSuccMessageView::RefreshNameLabel bluetoothNameLabel == nullptr"); - return; + bluetoothNameLabel->SetText(reinterpret_cast(caseInfo.deviceName)); } - bluetoothNameLabel->SetText(reinterpret_cast(caseInfo.deviceName)); -} } \ No newline at end of file -- 2.17.1