From: luozheng <1732036298@qq.com> Date: Thu, 25 Apr 2024 08:21:49 +0000 (+0800) Subject: 蓝牙Slice增加蓝牙服务选项Sliceq X-Git-Tag: release_V1.2.70_20241020_135402~1025^2~72 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=d5501ff833bbe511e980c20957098c510a9ab96b;p=mirrors%2FFD230.git 蓝牙Slice增加蓝牙服务选项Sliceq --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 42dcaae76..2ba6f5478 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -404,6 +404,8 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/classicbluetooth/src/ClassicBlueToothModel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp #录音 ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordDeleteView.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index ede6b3404..d7ec73eea 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -36,6 +36,7 @@ typedef enum : uint16_t VIEW_ALARM_POP_UP, // 闹铃界面 VIEW_BLUETOOTH_EARPHONE, // 连接蓝牙耳机界面 VIEW_CLASSIC_BLUETOOTH, // 经典蓝牙 + VIEW_BLUETOOTH_SERVICE_OPTIONS,// 蓝牙服务选项 VIEW_CALLER_LOG, // 通话记录界面 VIEW_INCOMING_CALL, // 来电界面 VIEW_COMPASS, // 指南针界面 diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index 8af622f47..2fbaa41e3 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -47,6 +47,7 @@ namespace OHOS void InitMediaVolumeSlice(void); void InitDisplayBrightnessSlice(void); void InitClassicBluetoothSlice(void); + void InitBluetoothServiceOptionsSlice(void); void InitFindPhoneSlice(void); void InitLanguageSwitchSlice(void); void InitMainStopWatchSlice(void); diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h index f2bf91cc1..9f6e50fe0 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h @@ -264,6 +264,7 @@ namespace OHOS static constexpr const char *PNG_APPLIST_BRIGHTNESSLEVEL_IMAGE = APP_LIST_PATH "/lighting.bin"; // 亮度调节 static constexpr const char *PNG_APPLIST_SAVEELE_IMAGE = APP_LIST_PATH "/save.bin"; // 省电模式 static constexpr const char *PNG_APPLIST_MESSAGE_IMAGE = APP_LIST_PATH "/message.bin"; // 消息通知 + static constexpr const char *PNG_APPLIST_BLUETOOTH_IMAGE = APP_LIST_PATH "/Bluetooth.bin"; // 蓝牙 /* ---------------------------------- 快速训练 ---------------------------------- */ static constexpr const char *PNG_TRAING_BOUTTONMORE_IMAGE = APP_RES_PATH "/Training/More.bin"; static constexpr const char *PNG_TRAING_BUTTONGRONG_IMAGE = APP_RES_PATH "/Training/Bouttonground.bin"; diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index 38660a6ce..2c5672532 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -97,6 +97,8 @@ #include "classicbluetooth/include/ClassicBlueToothPresenter.h" #include "classicbluetooth/include/ClassicBlueToothView.h" +#include "classicbluetooth/include/BluetoothServiceOptionsView.h" +#include "classicbluetooth/include/BluetoothServiceOptionsPresenter.h" #include "record/include/RecordingPresenter.h" #include "record/include/RecordingView.h" @@ -248,6 +250,7 @@ namespace OHOS {VIEW_SYSTEM_VOLUME, &NativeLauncher::InitSystemVolumeSlice}, // 系统音量 {VIEW_CALL_VOLUME, &NativeLauncher::InitCallVolumeSlice}, // 系统音量 {VIEW_CLASSIC_BLUETOOTH, &NativeLauncher::InitClassicBluetoothSlice}, // 经典蓝牙slice + {VIEW_BLUETOOTH_SERVICE_OPTIONS, &NativeLauncher::InitBluetoothServiceOptionsSlice}, // 蓝牙服务slice {VIEW_DISPLAY_BRIGHTNESS, &NativeLauncher::InitDisplayBrightnessSlice}, // 显示与亮度的实例化地址 {VIEW_NETWORKANDCALL, &NativeLauncher::InitNetworkAndCallSlice}, // 网络与通话 {VIEW_MOTION_RECOGNITION, &NativeLauncher::InitMotionRecognitionSlice}, // 网络与通话 @@ -756,6 +759,7 @@ namespace OHOS // } // NativeAbility::GetInstance().AddSliceProxy(VIEW_DIALUPDATE, dialupdate); // } + //传统蓝牙 void NativeLauncher::InitClassicBluetoothSlice(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitClassicBluetoothSlice"); @@ -768,6 +772,19 @@ namespace OHOS NativeAbility::GetInstance().AddSliceProxy(VIEW_CLASSIC_BLUETOOTH, classicbluetooth); } + // 蓝牙服务选项 + void NativeLauncher::InitBluetoothServiceOptionsSlice(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitClassicBluetoothSlice"); + SliceProxy *bluetoothserviceoptions = new AbilitySliceProxy; + if (bluetoothserviceoptions == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bluetoothserviceoptions"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_BLUETOOTH_SERVICE_OPTIONS, bluetoothserviceoptions); + } + void NativeLauncher::InitRecordingSlice(void) // 录音 { SliceProxy *record = new AbilitySliceProxy; diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp index 79d6c138c..4ce02bcbc 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp @@ -40,6 +40,7 @@ namespace OHOS {VIEW_SET_DESKTOP, PNG_APPLIST_THEME_IMAGE, PNG_APPLIST_THEME_IMAGE, "主题样式", nullptr}, {VIEW_SET_CARD, PNG_APPLIST_CARDSET_IMAGE, PNG_APPLIST_CARDSET_IMAGE, "卡片管理", nullptr}, {VIEW_SET_DIAL, PNG_APPLIST_CHANGEDIAL_IMAGE, PNG_APPLIST_CHANGEDIAL_IMAGE, "切换表盘", nullptr}, + {VIEW_CLASSIC_BLUETOOTH, PNG_APPLIST_BLUETOOTH_IMAGE, PNG_APPLIST_BLUETOOTH_IMAGE, "蓝牙", nullptr}, {VIEW_DNOTDISTURB, PNG_APPLIST_DISTURB_IMAGE, PNG_APPLIST_DISTURB_IMAGE, "勿扰模式", nullptr}, {VIEW_FLASHLIGHT, PNG_APPLIST_FLASHLIGHT_IMAGE, PNG_APPLIST_FLASHLIGHT_IMAGE, "手电筒", nullptr}, {VIEW_BRIGHTNESSLEVEL, PNG_APPLIST_BRIGHTNESSLEVEL_IMAGE, PNG_APPLIST_BRIGHTNESSLEVEL_IMAGE, "亮度调节", nullptr}, diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothPresenter.h index 88c64a2dc..05f05028e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/include/BluetoothPresenter.h @@ -8,6 +8,7 @@ #define BLUETOOTH_PRESENTER_H #include "Presenter.h" +#include "View.h" #include "MainBluetoothView.h" #include "components/ui_view.h" #include "components/ui_image_view.h" @@ -18,7 +19,6 @@ #include "UiViewId.h" #include "cmsis_os.h" -#include "KeyInputListener.h" #include "common/key_code.h" namespace OHOS { enum BluetoothPresenterNum : uint8_t { diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothPresenter.cpp index ffe860548..fd2c47b3c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/BluetoothPresenter.cpp @@ -12,6 +12,8 @@ #include "MainBluetoothView.h" #include "UiConfig.h" #include "bluetooth/include/BluetoothModel.h" +#include "custom_utils.h" +#include "common/key_code.h" namespace OHOS { static BluetoothPresenter *g_pBluetoothPresenter = nullptr; @@ -220,11 +222,11 @@ 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)) + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0) { - uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - NativeAbility::GetInstance().ChangeSlice(preSlice); + NativeAbility::GetInstance().Back(); } return true; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/MainBluetoothView.cpp b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/MainBluetoothView.cpp index 09692c12e..f2294ce16 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/MainBluetoothView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/MainBluetoothView.cpp @@ -62,8 +62,8 @@ void MainBluetoothView::OnStart() BaseView::RootView(Color::Black().full); // 增加按键监听 - //RootView::OnKeyActListener *keyactListener =(RootView::OnKeyActListener *)OHOS::BluetoothPresenter::GetInstance(); - //RootView::GetInstance()->SetOnKeyActListener(keyactListener); + RootView::OnKeyActListener *keyactListener =(RootView::OnKeyActListener *)OHOS::BluetoothPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); BluetoothModel *bluetoothModel = BluetoothModel::GetInstance(); if (bluetoothModel == nullptr) { @@ -348,7 +348,8 @@ void MainBluetoothView::ChangeSettingView() WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainBluetoothView::ChangeSettingView"); BluetoothModel::GetInstance()->SetTagConnectView(false); BluetoothModel::GetInstance()->SetTagScanDeviceClicked(false); - NativeAbility::GetInstance().ChangeSlice(VIEW_CLASSIC_BLUETOOTH); + //NativeAbility::GetInstance().ChangeSlice(VIEW_CLASSIC_BLUETOOTH); + NativeAbility::GetInstance().Back(); } void MainBluetoothView::DropEarPhoneView() diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/BluetoothServiceOptionsPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/BluetoothServiceOptionsPresenter.h new file mode 100644 index 000000000..0d0f2824d --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/BluetoothServiceOptionsPresenter.h @@ -0,0 +1,42 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-02-20 10:27:30 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-25 14:18:02 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/BluetoothServiceOptionsPresenter.h + */ +#ifndef BLUETOOTH_SERVICE_OPTIONS_PRESENTER_H +#define BLUETOOTH_SERVICE_OPTIONS_PRESENTER_H + +#include "Presenter.h" +#include "View.h" + +namespace OHOS +{ + class BluetoothServiceOptionsView; + class BluetoothServiceOptionsPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener, + public RootView::OnKeyActListener + { + public: + BluetoothServiceOptionsPresenter(); + virtual ~BluetoothServiceOptionsPresenter(); + + virtual void OnStart() override; + virtual void OnPause() override; + virtual void OnResume() override; + virtual void OnStop() override; + + static BluetoothServiceOptionsPresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/BluetoothServiceOptionsView.h b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/BluetoothServiceOptionsView.h new file mode 100644 index 000000000..3c997a1fc --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/BluetoothServiceOptionsView.h @@ -0,0 +1,69 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-25 11:49:58 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-25 15:14:34 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/BluetoothServiceOptionsView.h + */ + +#ifndef BLUETOOTH_SERVICE_OPTIONS_VIEW_H +#define BLUETOOTH_SERVICE_OPTIONS_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "components/root_view.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_button.h" +#include "components/ui_image_view.h" +#include "components/ui_toggle_button.h" +namespace OHOS +{ + // 返回setting视图界面 + class BluetoothServiceOptionsPresenter; + class BluetoothServiceOptionsView : public View + { + public: + struct LabelConfig + { + int16_t left; + int16_t top; + int16_t width; + int16_t height; + int16_t fontSize; // 字体大小 + int16_t lineHeigh; // 行高 + const char *text; // 文本 + uint8_t lineBreakMode; // 断行模式。 + }; + BluetoothServiceOptionsView(); + virtual ~BluetoothServiceOptionsView(); + static BluetoothServiceOptionsView *GetInstance(void); + void BluetoothServiceOptionsViewInit(void); + void ClearAll(void); + UIToggleButton *GetHFP_ToggleButton(void); + UIToggleButton *GetA2DP_ToggleButton(void); + + public: + virtual void OnStart() override; + virtual void OnSetUpView() override; + virtual void OnTearDownView() override; + virtual void OnStop() override; + + private: + bool SetUpBlueToothScrollView(void); + UILabelExt *SetBluetoothServiceOptionsViewLabel(LabelConfig &labelconfig); + bool SetUpBlueToothLabel(void); + bool SetUpBlueToothToggleButton(void); + bool SetUpBlueToothImageView(void); + UIScrollView *BlueToothScrollView = nullptr; + UILabelExt *Title = nullptr; + UILabelExt *HFP_Label{nullptr}; + UILabelExt *A2DP_Label{nullptr}; + UIImageView *HFP_Image{nullptr}; + UIImageView *A2DP_Image{nullptr}; + UIToggleButton *HFP_ToggleButton{nullptr}; // HFP + UIToggleButton *A2DP_ToggleButton{nullptr}; // A2DP + bool initViewStatus{false}; + }; +} +#endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothModel.h b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothModel.h index c7f80f841..27573aad3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothModel.h @@ -9,18 +9,12 @@ namespace OHOS { public: static ClassicBlueToothModel *GetInstance(void); - void MarkTradionalBlueToothToggleButtonStatus(bool value); - bool TradionalBlueToothToggleButtonStatusInit(); private: ClassicBlueToothModel(); - ClassicBlueToothModel(const ClassicBlueToothModel &); - ClassicBlueToothModel &operator=(const ClassicBlueToothModel &); + ClassicBlueToothModel(const ClassicBlueToothModel &) = delete; + ClassicBlueToothModel &operator=(const ClassicBlueToothModel &) = delete; virtual ~ClassicBlueToothModel(); - - private: - // 用来记录蓝牙开关状态,默认关闭状态 - bool ClassicBlueToothState{false}; }; } // namespace OHOS #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothPresenter.h index 1d5dcf0c8..06f9536a4 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothPresenter.h @@ -1,11 +1,9 @@ #ifndef CLASSIC_BLUETOOTH_PRESENTER_H #define CLASSIC_BLUETOOTH_PRESENTER_H #include "Presenter.h" -#include "ClassicBlueToothView.h" -#include "wearable_log.h" +#include "View.h" +#include "classicbluetooth/include/ClassicBlueToothView.h" -#include "KeyInputListener.h" -#include "common/key_code.h" namespace OHOS { class ClassicBlueToothView; @@ -25,7 +23,7 @@ namespace OHOS virtual void OnStop() override; static ClassicBlueToothPresenter *GetInstance(); - void SetBluetoothDeviceSwitchState(bool value); + private: // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; bool OnClick(UIView &view, const ClickEvent &event) override; diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothView.h b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothView.h index 2e57752ab..9cad993b9 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothView.h @@ -5,15 +5,16 @@ #include "View.h" #include "components/root_view.h" #include "components/ui_scroll_view.h" -#include "components/ui_label.h" #include "components/ui_label_ext.h" -#include "components/ui_button.h" +#include "components/ui_label_button_ext.h" #include "components/ui_image_view.h" #include "components/ui_toggle_button.h" #include "wearable_log.h" namespace OHOS { - static const char *BLUETOOTHEARPHONEBUTTON = "BlueToothEarPhoneButton"; // 蓝牙耳机按钮ID + static constexpr const char *BLUETOOTHEARPHONEBUTTON = "BlueToothEarPhoneButton"; // 蓝牙耳机按钮ID + static constexpr const char *TRADIONALBLUETOOTHBUTTON = "TradionalBluetoothButton"; // 传统蓝牙服按钮ID + static constexpr const char *BLUETOOTHSERVICEOPTIONSBUTTON = "BluetoothServiceOptionsButton"; // 蓝牙服务选项按钮ID // 返回setting视图界面 class ClassicBlueToothPresenter; class ClassicBlueToothView : public View @@ -35,8 +36,7 @@ namespace OHOS static ClassicBlueToothView *GetInstance(void); void ClassicBlueToothViewInit(void); void ClearAll(void); - bool GetClassicBlueToothState(void); - void SetClassicBlueToothState(bool state); + UIToggleButton * GetTradionalBlueToothToggleButton(void); public: virtual void OnStart() override; @@ -46,18 +46,19 @@ namespace OHOS private: bool SetUpBlueToothScrollView(void); - UILabel *SetClassicBlueToothViewLabel(LabelConfig &labelconfig); + UILabelExt *SetClassicBlueToothViewLabel(LabelConfig &labelconfig); bool SetUpBlueToothLabel(void); - bool SetUpBlueToothEarPhoneButton(void); + bool SetUpBlueToothButton(void); bool SetUpBlueToothToggleButton(void); - bool SetUpImageView(void); UIScrollView *BlueToothScrollView = nullptr; - UILabel *Title = nullptr; - UILabel *BlueToothEarPhoneLabel = nullptr; - UILabel *TradionalBlueToothLabel = nullptr; - UILabel *AttentionLabel = nullptr; - UIImageView *image[2]{nullptr}; - UIButton *BlueToothEarPhoneButton = nullptr; + UILabelExt *Title = nullptr; + UILabelButtonExt *BlueToothEarPhoneButton = nullptr; // 蓝牙耳机按钮 + UILabelButtonExt *TradionalBlueToothButton = nullptr; // 传统蓝牙按钮 + UILabelButtonExt *BluetoothServiceOptionsButton = nullptr; // 蓝牙服务选项按钮 + UILabelExt *BlueToothEarPhoneLabel = nullptr; // 蓝牙耳机 + UILabelExt *TradionalBlueToothLabel = nullptr; // 传统蓝牙 + UILabelExt *BluetoothServiceOptionsLabel = nullptr; // 蓝牙服务选项 + UILabelExt *AttentionLabel = nullptr; UIToggleButton *TradionalBlueToothToggleButton = nullptr; bool initViewStatus{false}; }; diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp new file mode 100644 index 000000000..19adeb548 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsPresenter.cpp @@ -0,0 +1,140 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "common/key_code.h" +#include +#include +#include "wearable_log.h" +#include "config/include/ConfigModel.h" +#include "iostream" +#include "map" +#include "classicbluetooth/include/BluetoothServiceOptionsPresenter.h" +#include "classicbluetooth/include/BluetoothServiceOptionsView.h" + +namespace OHOS +{ + // 当前Presenter属性实例化的内存指针 + static BluetoothServiceOptionsPresenter *g_pBluetoothServiceOptionsPresenter = nullptr; + + BluetoothServiceOptionsPresenter::BluetoothServiceOptionsPresenter() + { + g_pBluetoothServiceOptionsPresenter = this; + } + + BluetoothServiceOptionsPresenter::~BluetoothServiceOptionsPresenter() + { + g_pBluetoothServiceOptionsPresenter = nullptr; + } + + BluetoothServiceOptionsPresenter *BluetoothServiceOptionsPresenter::GetInstance() + { + return g_pBluetoothServiceOptionsPresenter; + } + + void BluetoothServiceOptionsPresenter::OnStart() + { + Presenter::OnStart(); + } + + void BluetoothServiceOptionsPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void BluetoothServiceOptionsPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void BluetoothServiceOptionsPresenter::OnStop(void) + { + Presenter::OnStop(); + } + + bool BluetoothServiceOptionsPresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::OnClick"); + BluetoothServiceOptionsView *classicBlueToothView = BluetoothServiceOptionsView::GetInstance(); + if (classicBlueToothView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::GetInstance"); + return false; + } + + std::map buttonMap = { + {classicBlueToothView->GetHFP_ToggleButton(), "HFP"}, + { + classicBlueToothView->GetA2DP_ToggleButton(), + "A2DP", + }}; + + auto it = buttonMap.find(&view); + if (it != buttonMap.end()) + { + UIToggleButton *toggleButton = dynamic_cast(&view); + if (toggleButton != nullptr) + { + if (toggleButton->GetState() == true) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s is enable!", it->second.c_str()); + if (it->second == "HFP") + { + ConfigModel::GetInstance()->SetHFPState(true); + } + else if (it->second == "A2DP") + { + ConfigModel::GetInstance()->SetA2DPState(true); + } + } + else + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s is disable!", it->second.c_str()); + if (it->second == "HFP") + { + ConfigModel::GetInstance()->SetHFPState(false); + } + else if (it->second == "A2DP") + { + ConfigModel::GetInstance()->SetA2DPState(false); + } + } + } + + return true; + } + } + + bool BluetoothServiceOptionsPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + UNUSED(event); + return true; + } + + bool BluetoothServiceOptionsPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsPresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + { + NativeAbility::GetInstance().Back(); + } + + return true; + } + + bool BluetoothServiceOptionsPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16 keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0) + { + NativeAbility::GetInstance().Back(); + } + return true; + } +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp new file mode 100644 index 000000000..d8002210f --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/BluetoothServiceOptionsView.cpp @@ -0,0 +1,288 @@ +#include "classicbluetooth/include/BluetoothServiceOptionsView.h" +#include "classicbluetooth/include/BluetoothServiceOptionsPresenter.h" +#include "config/include/ConfigModel.h" +#include "UiConfig.h" +#include "wearable_log.h" + +namespace OHOS +{ + static BluetoothServiceOptionsView *g_pBluetoothServiceOptionsView{nullptr}; + + BluetoothServiceOptionsView::BluetoothServiceOptionsView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::BluetoothServiceOptionsView"); + g_pBluetoothServiceOptionsView = this; + } + + BluetoothServiceOptionsView::~BluetoothServiceOptionsView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "~BluetoothServiceOptionsView::BluetoothServiceOptionsView"); + ClearAll(); + g_pBluetoothServiceOptionsView = nullptr; + } + + BluetoothServiceOptionsView *BluetoothServiceOptionsView::GetInstance() + { + return g_pBluetoothServiceOptionsView; + } + + void BluetoothServiceOptionsView::ClearAll() + { + if (initViewStatus == true) + { + BlueToothScrollView->RemoveAll(); + + delete Title; + Title = nullptr; + + delete HFP_Image; + HFP_Image = nullptr; + + delete A2DP_Image; + A2DP_Image = nullptr; + + delete HFP_Label; + HFP_Label = nullptr; + + delete A2DP_Label; + A2DP_Label = nullptr; + + delete HFP_ToggleButton; + HFP_ToggleButton = nullptr; + + delete A2DP_ToggleButton; + A2DP_ToggleButton = nullptr; + + delete BlueToothScrollView; + BlueToothScrollView = nullptr; + } + } + + bool BluetoothServiceOptionsView::SetUpBlueToothScrollView(void) + { + BlueToothScrollView = new UIScrollView(); + if (BlueToothScrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::BlueToothScrollView new fail!"); + return false; + } + BlueToothScrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + BlueToothScrollView->SetScrollBlankSize(35); + BlueToothScrollView->SetReboundSize(50); + BlueToothScrollView->SetDirection(1); + UIView::OnDragListener *draglistener = static_cast(BluetoothServiceOptionsPresenter::GetInstance()); + if (draglistener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::draglistener can not be nullptr!"); + return false; + } + BlueToothScrollView->SetOnDragListener(draglistener); + BlueToothScrollView->SetTouchable(true); + BlueToothScrollView->SetDraggable(true); + + return true; + } + + // 标签配置 + UILabelExt *BluetoothServiceOptionsView::SetBluetoothServiceOptionsViewLabel(LabelConfig &labelconfig) + { + UILabelExt *label = new UILabelExt(); + if (label == nullptr) + { + return nullptr; + } + label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); // 位置大小 + label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); // 字体大小 + label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); // 字体行高 + label->SetText(labelconfig.text); // 内容 + label->SetLineBreakMode(labelconfig.lineBreakMode); // 断行模式。 + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); + return label; + } + + // 标签初始化 + bool BluetoothServiceOptionsView::SetUpBlueToothLabel(void) + { + LabelConfig labelconfig = { + .left = 93, + .top = 52, + .width = 280, + .height = 40, + .fontSize = 30, + .lineHeigh = 35, + .text = "蓝牙服务选项", + .lineBreakMode = UILabel::LINE_BREAK_MARQUEE, + }; + Title = SetBluetoothServiceOptionsViewLabel(labelconfig); + if (nullptr == Title) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::Title is nullptr!"); + return false; + } + Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + /* -------------------------------------------------------------------------- */ + labelconfig = { + .left = 90, + .top = 153, + .width = 180, + .height = 40, + .fontSize = 30, + .lineHeigh = 35, + .text = "通话蓝牙", + .lineBreakMode = UILabel::LINE_BREAK_MARQUEE, + }; + HFP_Label = SetBluetoothServiceOptionsViewLabel(labelconfig); + if (nullptr == HFP_Label) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::HFP_Label is nullptr!"); + return false; + } + labelconfig.top = 273; + labelconfig.text = "媒体蓝牙"; + A2DP_Label = SetBluetoothServiceOptionsViewLabel(labelconfig); + if (nullptr == A2DP_Label) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::A2DP_Label is nullptr!"); + return false; + } + + return true; + } + + // ToggleButton初始化 + bool BluetoothServiceOptionsView::SetUpBlueToothToggleButton() + { + HFP_ToggleButton = new UIToggleButton(); + if (nullptr == HFP_ToggleButton) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " BluetoothServiceOptionsView::BlueToothEarPhoneButton new fail!"); + return false; + } + HFP_ToggleButton->SetPosition(298, 145, 100, 50); + HFP_ToggleButton->SetState(ConfigModel::GetInstance()->GetHFPState()); + HFP_ToggleButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + HFP_ToggleButton->SetImages(PNG_TOGGLEBUTTON_ON_IMAGE, PNG_TOGGLEBUTTON_OFF_IMAGE); + /* -------------------------------------------------------------------------- */ + A2DP_ToggleButton = new UIToggleButton(); + if (A2DP_ToggleButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LanguageSwitchView::A2DP_ToggleButton is nullptr!"); + return false; + } + A2DP_ToggleButton->SetPosition(298, 265, 100, 50); + A2DP_ToggleButton->SetState(ConfigModel::GetInstance()->GetA2DPState()); + A2DP_ToggleButton->SetStyle(STYLE_BACKGROUND_OPA, 0xffffffff); + A2DP_ToggleButton->SetImages(PNG_TOGGLEBUTTON_ON_IMAGE, PNG_TOGGLEBUTTON_OFF_IMAGE); + /* -------------------------------------------------------------------------- */ + UIView::OnClickListener *clickListener = static_cast(BluetoothServiceOptionsPresenter::GetInstance()); + HFP_ToggleButton->SetOnClickListener(clickListener); + A2DP_ToggleButton->SetOnClickListener(clickListener); + + return true; + } + + // 图片初始化 + bool BluetoothServiceOptionsView::SetUpBlueToothImageView(void) + { + HFP_Image = new UIImageView(); + if (nullptr == HFP_Image) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " BluetoothServiceOptionsView::HFP_Image new fail!"); + return false; + } + HFP_Image->SetPosition(43, 120, 380, 100); + HFP_Image->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + HFP_Image->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + HFP_Image->SetStyle(STYLE_BORDER_RADIUS, 100); + /* -------------------------------------------------------------------------- */ + A2DP_Image = new UIImageView(); + if (nullptr == A2DP_Image) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " BluetoothServiceOptionsView::A2DP_Image new fail!"); + return false; + } + A2DP_Image->SetPosition(43, 240, 380, 100); + A2DP_Image->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + A2DP_Image->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + A2DP_Image->SetStyle(STYLE_BORDER_RADIUS, 100); + return true; + } + + UIToggleButton *BluetoothServiceOptionsView::GetHFP_ToggleButton(void) + { + return HFP_ToggleButton; + } + UIToggleButton *BluetoothServiceOptionsView::GetA2DP_ToggleButton(void) + { + return A2DP_ToggleButton; + } + + /// @brief 蓝牙界面初始化 + /// @param void + void BluetoothServiceOptionsView::BluetoothServiceOptionsViewInit(void) + { + if (!SetUpBlueToothScrollView()) + { + return; + } + + if (!SetUpBlueToothImageView()) + { + return; + } + + if (!SetUpBlueToothLabel()) + { + return; + } + + if (!SetUpBlueToothToggleButton()) + { + return; + } + + initViewStatus = true; + } + + void BluetoothServiceOptionsView::OnStart() + { + View::OnStart(); + BluetoothServiceOptionsViewInit(); + + // 增加按键监听 + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::BluetoothServiceOptionsPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); + } + + void BluetoothServiceOptionsView::OnSetUpView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::OnSetUpView"); + View::OnSetUpView(); + BlueToothScrollView->Add(Title); + BlueToothScrollView->Add(HFP_Image); + BlueToothScrollView->Add(A2DP_Image); + BlueToothScrollView->Add(HFP_Label); + BlueToothScrollView->Add(A2DP_Label); + BlueToothScrollView->Add(HFP_ToggleButton); + BlueToothScrollView->Add(A2DP_ToggleButton); + RootView::GetInstance()->Add(BlueToothScrollView); + Draw(); + } + + void BluetoothServiceOptionsView::OnTearDownView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::OnTearDownView"); + View::OnTearDownView(); + return; + } + + void BluetoothServiceOptionsView::OnStop() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BluetoothServiceOptionsView::OnStop"); + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + RootView::GetInstance()->ClearOnKeyActListener(); + return; + } + +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothModel.cpp index b12dace38..746bcbe63 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothModel.cpp @@ -1,13 +1,7 @@ #include "classicbluetooth/include/ClassicBlueToothModel.h" -#include "classicbluetooth/include/ClassicBlueToothPresenter.h" - namespace OHOS { - ClassicBlueToothModel::ClassicBlueToothModel() - { - ConfigModel *p_ConfigModel = ConfigModel::GetInstance(); - ClassicBlueToothState = p_ConfigModel->GetClassicBlueToothState(); - } + ClassicBlueToothModel::ClassicBlueToothModel() {} ClassicBlueToothModel::~ClassicBlueToothModel() {} @@ -17,24 +11,4 @@ namespace OHOS return &instance; } - /// @brief 标记蓝牙开关的状态 - /// @param value true 开启状态 false 关闭状态 - void ClassicBlueToothModel::MarkTradionalBlueToothToggleButtonStatus(bool value) - { - ClassicBlueToothState = value; - } - - /// @brief 根据标记蓝牙开关的状态来确定蓝牙切换按钮是"开"还是"关状态 - /// @return true 初始化成功 false 初始化失败 - bool ClassicBlueToothModel::TradionalBlueToothToggleButtonStatusInit(void) - { - ClassicBlueToothPresenter *Classicbluetoothpresenter = ClassicBlueToothPresenter::GetInstance(); - if (Classicbluetoothpresenter == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TradionalBlueToothToggleButtonStatusInit ClassicBlueToothPresenter GetInstance fail"); - return false; - } - Classicbluetoothpresenter->SetBluetoothDeviceSwitchState(ClassicBlueToothState); // 蓝牙开关状态 - return true; - } } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp index a10e505cc..23adfee7b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp @@ -1,11 +1,19 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-25 11:50:57 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-25 15:54:05 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp + */ +#include "classicbluetooth/include/ClassicBlueToothPresenter.h" +#include "classicbluetooth/include/ClassicBlueToothView.h" #include "AppViewIDs.h" -#include "components/ui_label_ext.h" -#include"language/font/ui_resource_string.h" #include "NativeAbility.h" -#include "graphic_math.h" -#include "classicbluetooth/include/ClassicBlueToothPresenter.h" -#include "classicbluetooth/include/ClassicBlueToothModel.h" #include "custom_utils.h" +#include "common/key_code.h" +#include +#include "wearable_log.h" +#include "config/include/ConfigModel.h" namespace OHOS { // 当前Presenter属性实例化的内存指针 @@ -48,36 +56,27 @@ namespace OHOS Presenter::OnStop(); } - /// @brief 设置蓝牙设备的开关状态 - /// @param value true 开启蓝牙 false 关闭蓝牙 - void ClassicBlueToothPresenter::SetBluetoothDeviceSwitchState(bool value) - { - ClassicBlueToothView *classicBlueToothView = ClassicBlueToothView::GetInstance(); - if (classicBlueToothView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetBluetoothDeviceSwitchState ClassicBlueToothView GetInstance fail"); - return; - } - if (value != false) - { - classicBlueToothView->SetClassicBlueToothState(true); - ClassicBlueToothModel::GetInstance()->MarkTradionalBlueToothToggleButtonStatus(false); // 将Model层保存的状态清除 - } - } - bool ClassicBlueToothPresenter::OnClick(UIView &view, const ClickEvent &event) { UNUSED(event); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnClick"); ClassicBlueToothView *classicBlueToothView = ClassicBlueToothView::GetInstance(); if (classicBlueToothView == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::GetInstance"); return false; } - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::OnClick"); + if (strcmp(view.GetViewId(), BLUETOOTHEARPHONEBUTTON) == 0) { - NativeAbility::GetInstance().ChangeSlice(VIEW_BLUETOOTH_EARPHONE); + NativeAbility::GetInstance().EnterSlice(VIEW_BLUETOOTH_EARPHONE); + } + else if (strcmp(view.GetViewId(), BLUETOOTHSERVICEOPTIONSBUTTON) == 0) + { + if (classicBlueToothView->GetTradionalBlueToothToggleButton()->GetState() == true) + { + NativeAbility::GetInstance().EnterSlice(VIEW_BLUETOOTH_SERVICE_OPTIONS); + } } return true; @@ -85,24 +84,19 @@ namespace OHOS bool ClassicBlueToothPresenter::OnDrag(UIView &view, const DragEvent &event) { + UNUSED(view); + UNUSED(event); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnDrag"); return true; } bool ClassicBlueToothPresenter::OnDragEnd(UIView &view, const DragEvent &event) { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnDragEnd"); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); // 上一个SliceId - uint16_t currentSlice = NativeAbility::GetInstance().GetCurSliceId(); // 当前SliceId - - if (preSlice == VIEW_MAIN) - { - NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); - } - else - { - NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); - } + NativeAbility::GetInstance().Back(); } return true; @@ -110,27 +104,29 @@ namespace OHOS extern "C" { - void closeBle(void);//主动关闭蓝牙 - void openBle(void);//主动开启蓝牙 - bool get_ble_status(void);//获取蓝牙是否关闭还是开启 1就是开启 0关闭 一开机默认是开启蓝牙 + void closeBle(void); // 主动关闭蓝牙 + void openBle(void); // 主动开启蓝牙 + bool get_ble_status(void); // 获取蓝牙是否关闭还是开启 1就是开启 0关闭 一开机默认是开启蓝牙 void getDeviceState(void); } bool ClassicBlueToothPresenter::OnChange(UICheckBox::UICheckBoxState state) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnChange"); switch (state) { case UICheckBox::SELECTED: WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BlueTooth Capability Is Enabled"); - ConfigModel::GetInstance()->set_condigData_Bool(ConfigModel::ConfigItem::CONFIGMODEL_ITEM_CLASSIC_BT_SERVICE_ON,true); + start_custom_ble_service(); // 主动开启蓝牙 - start_custom_ble_service();//主动开启蓝牙 + ConfigModel::GetInstance()->SetClassicBlueToothState(true); break; case UICheckBox::UNSELECTED: WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BlueTooth Capability Is Disabled"); - ConfigModel::GetInstance()->set_condigData_Bool(ConfigModel::ConfigItem::CONFIGMODEL_ITEM_CLASSIC_BT_SERVICE_ON,false); stop_custom_ble_service(); + + ConfigModel::GetInstance()->SetClassicBlueToothState(false); break; default: break; @@ -146,15 +142,7 @@ namespace OHOS // 如果是power键,且是亮屏状态,按键释放就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0) { - uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - if (preSlice == VIEW_SETTING || VIEW_BLUETOOTH_EARPHONE) - { - NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); - } - else - { - NativeAbility::GetInstance().ChangeSlice(preSlice); - } + NativeAbility::GetInstance().Back(); } return true; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp index aee7a4a7d..f4957a018 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp @@ -1,7 +1,7 @@ #include "classicbluetooth/include/ClassicBlueToothView.h" #include "classicbluetooth/include/ClassicBlueToothPresenter.h" -#include "classicbluetooth/include/ClassicBlueToothModel.h" - +#include "config/include/ConfigModel.h" +#include "UiConfig.h" namespace OHOS { static ClassicBlueToothView *g_pClassicBlueToothView{nullptr}; @@ -30,22 +30,18 @@ namespace OHOS { BlueToothScrollView->RemoveAll(); - bool state = GetClassicBlueToothState(); - if (state == true) - { - ClassicBlueToothModel::GetInstance()->MarkTradionalBlueToothToggleButtonStatus(true); - // ConfigModel::GetInstance()->set_condigData_Bool(ConfigModel::ConfigItem::CONFIGMODEL_ITEM_CLASSIC_BT_SERVICE_ON,true); - // ConfigModel::GetInstance()->WriteJsonData_Bool(ConfigModel::GetInstance()->GetcJSON(), "ClassicBlueToothState", true); - } - else - { - ClassicBlueToothModel::GetInstance()->MarkTradionalBlueToothToggleButtonStatus(false); - // ConfigModel::GetInstance()->WriteJsonData_Bool(ConfigModel::GetInstance()->GetcJSON(), "ClassicBlueToothState", false); - } - delete Title; Title = nullptr; + delete BlueToothEarPhoneButton; + BlueToothEarPhoneButton = nullptr; + + delete TradionalBlueToothButton; + TradionalBlueToothButton = nullptr; + + delete BluetoothServiceOptionsButton; + BluetoothServiceOptionsButton = nullptr; + delete BlueToothEarPhoneLabel; BlueToothEarPhoneLabel = nullptr; @@ -55,15 +51,6 @@ namespace OHOS delete AttentionLabel; AttentionLabel = nullptr; - for (int i = 0; i < 2; i++) - { - delete image[i]; - image[i] = nullptr; - } - - delete BlueToothEarPhoneButton; - BlueToothEarPhoneButton = nullptr; - delete TradionalBlueToothToggleButton; TradionalBlueToothToggleButton = nullptr; @@ -98,9 +85,9 @@ namespace OHOS } // 标签配置 - UILabel *ClassicBlueToothView::SetClassicBlueToothViewLabel(LabelConfig &labelconfig) + UILabelExt *ClassicBlueToothView::SetClassicBlueToothViewLabel(LabelConfig &labelconfig) { - UILabel *label = new UILabel(); + UILabelExt *label = new UILabelExt(); if (label == nullptr) { return nullptr; @@ -110,7 +97,6 @@ namespace OHOS label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); // 字体行高 label->SetText(labelconfig.text); // 内容 label->SetLineBreakMode(labelconfig.lineBreakMode); // 断行模式。 - label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); return label; } @@ -119,14 +105,14 @@ namespace OHOS bool ClassicBlueToothView::SetUpBlueToothLabel(void) { LabelConfig labelconfig = { - .left = 203, + .left = 93, .top = 52, - .width = 65, - .height = 35, + .width = 280, + .height = 40, .fontSize = 30, .lineHeigh = 35, .text = "蓝牙", - .lineBreakMode = UILabel::LINE_BREAK_ADAPT, + .lineBreakMode = UILabel::LINE_BREAK_MARQUEE, }; Title = SetClassicBlueToothViewLabel(labelconfig); if (nullptr == Title) @@ -134,15 +120,17 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::Title is nullptr!"); return false; } + Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + /* -------------------------------------------------------------------------- */ labelconfig = { .left = 90, .top = 153, - .width = 120, - .height = 35, + .width = 180, + .height = 40, .fontSize = 30, .lineHeigh = 35, .text = "蓝牙耳机", - .lineBreakMode = UILabel::LINE_BREAK_ADAPT, + .lineBreakMode = UILabel::LINE_BREAK_MARQUEE, }; BlueToothEarPhoneLabel = SetClassicBlueToothViewLabel(labelconfig); if (nullptr == BlueToothEarPhoneLabel) @@ -150,6 +138,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::BlueToothEarPhoneLabel is nullptr!"); return false; } + /* -------------------------------------------------------------------------- */ labelconfig.top = 273; labelconfig.text = "传统蓝牙"; TradionalBlueToothLabel = SetClassicBlueToothViewLabel(labelconfig); @@ -158,10 +147,19 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::TradionalBlueToothLabel is nullptr!"); return false; } - + /* -------------------------------------------------------------------------- */ + labelconfig.top = 393; + labelconfig.text = "蓝牙服务选项"; + BluetoothServiceOptionsLabel = SetClassicBlueToothViewLabel(labelconfig); + if (nullptr == BluetoothServiceOptionsLabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::BluetoothServiceOptionsLabel is nullptr!"); + return false; + } + /* -------------------------------------------------------------------------- */ labelconfig = { .left = 53, - .top = 379, + .top = 499, .width = 360, .height = 180, .fontSize = 20, @@ -179,10 +177,10 @@ namespace OHOS return true; } - // 蓝牙耳机按钮 - bool ClassicBlueToothView::SetUpBlueToothEarPhoneButton(void) + // 按钮初始化 + bool ClassicBlueToothView::SetUpBlueToothButton(void) { - BlueToothEarPhoneButton = new UIButton(); + BlueToothEarPhoneButton = new UILabelButtonExt(); if (BlueToothEarPhoneButton == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " ClassicBlueToothView::BlueToothEarPhoneButton new fail!"); @@ -191,17 +189,43 @@ namespace OHOS BlueToothEarPhoneButton->SetPosition(43, 120, 380, 100); BlueToothEarPhoneButton->SetViewId(BLUETOOTHEARPHONEBUTTON); BlueToothEarPhoneButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - BlueToothEarPhoneButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff4fc34c, UIButton::PRESSED); - BlueToothEarPhoneButton->SetStyleForState(STYLE_BORDER_COLOR, 0xffffffff, UIButton::PRESSED); - BlueToothEarPhoneButton->SetStyleForState(STYLE_BORDER_OPA, 0x00, UIButton::PRESSED); - + BlueToothEarPhoneButton->SetImagePosition(326, 37); + BlueToothEarPhoneButton->SetImageSrc(PNG_SETTING_NEXT_IMAGE, PNG_SETTING_NEXT_IMAGE); + BlueToothEarPhoneButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED); + /* -------------------------------------------------------------------------- */ + TradionalBlueToothButton = new UILabelButtonExt(); + if (TradionalBlueToothButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " ClassicBlueToothView::TradionalBlueToothButton new fail!"); + return false; + } + TradionalBlueToothButton->SetPosition(43, 240,380,100); + TradionalBlueToothButton->SetViewId(TRADIONALBLUETOOTHBUTTON); + TradionalBlueToothButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + TradionalBlueToothButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 16); + TradionalBlueToothButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED); + /* -------------------------------------------------------------------------- */ + BluetoothServiceOptionsButton = new UILabelButtonExt(); + if (BluetoothServiceOptionsButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " ClassicBlueToothView::BluetoothServiceOptionsButton new fail!"); + return false; + } + BluetoothServiceOptionsButton->SetPosition(43, 360, 380, 100); + BluetoothServiceOptionsButton->SetViewId(BLUETOOTHSERVICEOPTIONSBUTTON); + BluetoothServiceOptionsButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + BluetoothServiceOptionsButton->SetImagePosition(326, 37); + BluetoothServiceOptionsButton->SetImageSrc(PNG_SETTING_NEXT_IMAGE, PNG_SETTING_NEXT_IMAGE); + BluetoothServiceOptionsButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED); + /* -------------------------------------------------------------------------- */ UIView::OnClickListener *clickListener = static_cast(ClassicBlueToothPresenter::GetInstance()); BlueToothEarPhoneButton->SetOnClickListener(clickListener); + BluetoothServiceOptionsButton->SetOnClickListener(clickListener); return true; } - // 手表蓝牙开关按钮 + // 传统蓝牙开关按钮 bool ClassicBlueToothView::SetUpBlueToothToggleButton() { TradionalBlueToothToggleButton = new UIToggleButton(); @@ -211,55 +235,17 @@ namespace OHOS return false; } TradionalBlueToothToggleButton->SetPosition(298, 265, 100, 50); + TradionalBlueToothToggleButton->SetState(ConfigModel::GetInstance()->GetClassicBlueToothState()); TradionalBlueToothToggleButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); - TradionalBlueToothToggleButton->SetImages("/user/res/TOGGLEBUTTON_ON.bin", "/user/res/TOGGLEBUTTON_OFF.bin"); + TradionalBlueToothToggleButton->SetImages(PNG_TOGGLEBUTTON_ON_IMAGE, PNG_TOGGLEBUTTON_OFF_IMAGE); UICheckBox::OnChangeListener *changeListener = static_cast(ClassicBlueToothPresenter::GetInstance()); TradionalBlueToothToggleButton->SetOnChangeListener(changeListener); return true; } - bool ClassicBlueToothView::SetUpImageView(void) + UIToggleButton * ClassicBlueToothView::GetTradionalBlueToothToggleButton(void) { - image[0] = new UIImageView(); - if (nullptr == image[0]) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " ClassicBlueToothView::image[0] new fail!"); - return false; - } - image[0]->SetPosition(369, 157, 14, 26); - image[0]->SetSrc("/user/res/SETTING_NEXT.bin"); - - image[1] = new UIImageView(); - if (nullptr == image[1]) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " ClassicBlueToothView::image[1] new fail!"); - return false; - } - image[1]->SetPosition(43, 240, 380, 100); - image[1]->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - image[1]->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - image[1]->SetStyle(STYLE_BORDER_RADIUS, 100); - return true; - } - - /// @brief 获取蓝牙切换按钮的状态 - /// @param void - /// @return true 表示开启状态 false 表示开启状态 - bool ClassicBlueToothView::GetClassicBlueToothState(void) - { - return TradionalBlueToothToggleButton->GetState(); - } - - /// @brief 设置蓝牙切换按钮的状态 - /// @param state true 开启 false 关闭 - void ClassicBlueToothView::SetClassicBlueToothState(bool state) - { - if (TradionalBlueToothToggleButton == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TradionalBlueToothToggleButton is nullptr!"); - return; - } - TradionalBlueToothToggleButton->SetState(state); + return TradionalBlueToothToggleButton; } /// @brief 蓝牙界面初始化 @@ -271,12 +257,12 @@ namespace OHOS return; } - if (!SetUpBlueToothLabel()) + if (!SetUpBlueToothButton()) { return; } - if (!SetUpBlueToothEarPhoneButton()) + if (!SetUpBlueToothLabel()) { return; } @@ -286,11 +272,6 @@ namespace OHOS return; } - if (!SetUpImageView()) - { - return; - } - ClassicBlueToothModel::GetInstance()->TradionalBlueToothToggleButtonStatusInit(); initViewStatus = true; } @@ -310,10 +291,11 @@ namespace OHOS View::OnSetUpView(); BlueToothScrollView->Add(Title); BlueToothScrollView->Add(BlueToothEarPhoneButton); - BlueToothScrollView->Add(image[0]); - BlueToothScrollView->Add(image[1]); + BlueToothScrollView->Add(TradionalBlueToothButton); + BlueToothScrollView->Add(BluetoothServiceOptionsButton); BlueToothScrollView->Add(BlueToothEarPhoneLabel); BlueToothScrollView->Add(TradionalBlueToothLabel); + BlueToothScrollView->Add(BluetoothServiceOptionsLabel); BlueToothScrollView->Add(AttentionLabel); BlueToothScrollView->Add(TradionalBlueToothToggleButton); RootView::GetInstance()->Add(BlueToothScrollView); diff --git a/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h b/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h index 344f3ecbb..da87c301b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/config/include/ConfigModel.h @@ -69,6 +69,8 @@ namespace OHOS CONFIGMODEL_ITEM_CALL_VOLUME,//通话音量 CONFIGMODEL_ITEM_VOLTE_CALL,//VoLTE通话 CONFIGMODEL_ITEM_MOTIONRECOGNITION,//运动识别 + CONFIGMODEL_ITEM_HFP, //通话蓝牙开关 + CONFIGMODEL_ITEM_A2DP,//媒体蓝牙开关 CONFIGMODEL_ITEM_MAX, } ; @@ -110,7 +112,6 @@ namespace OHOS /* --------------------------------自定义封装 set与get方法 ------------------------------- */ - bool GetClassicBlueToothState(void); void SetLanguage(int languageid); int GetLanguage(); @@ -158,6 +159,17 @@ namespace OHOS void SetSilentMode(bool state); bool GetSilentMode(void); + + /* ------------------------------- 蓝牙相关set与get ------------------------------ */ + void SetClassicBlueToothState(bool value); + bool GetClassicBlueToothState(void); + + void SetHFPState(bool value); + bool GetHFPState(void); + + void SetA2DPState(bool value); + bool GetA2DPState(void); + /* ---------------------------------- 运动识别相关set与get ---------------------------------- */ void SetMotionRecognition(bool state); bool GetMotionRecognition(void); @@ -203,6 +215,8 @@ namespace OHOS {ConfigDataType::DATATYPE_INT, "CallVolume", "100" },// CONFIGMODEL_ITEM_CALL_VOLUME // {ConfigDataType::DATATYPE_BOOL, "VoLTECall", "false" },// CONFIGMODEL_ITEM_VOLTE_CALL {ConfigDataType::DATATYPE_BOOL, "MotionRecognition", "false" },// CONFIGMODEL_ITEM_MOTIONRECOGNITION + {ConfigDataType::DATATYPE_BOOL, "HFP", "false" },// CONFIGMODEL_ITEM_HFP + {ConfigDataType::DATATYPE_BOOL, "A2DP", "false" },// CONFIGMODEL_ITEM_A2DP }; ConfigModel(); // 私有构造函数,确保无法在外部实例化 ConfigModel(const ConfigModel &) = delete; // 禁止拷贝构造 diff --git a/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp index 50e53425b..19035b2db 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/config/src/ConfigModel.cpp @@ -518,12 +518,42 @@ namespace OHOS return get_configData_int(CONFIGMODEL_ITEM_SCREEN_OFF_TIMEOUT_VALUE); } + /// @brief 设置蓝牙开关状态 + void ConfigModel::SetClassicBlueToothState(bool value) + { + set_condigData_Bool(CONFIGMODEL_ITEM_CLASSIC_BT_SERVICE_ON,value); + } + /// @brief 获取蓝牙开关状态 bool ConfigModel::GetClassicBlueToothState(void) { return get_configData_bool(CONFIGMODEL_ITEM_CLASSIC_BT_SERVICE_ON); } + // 设置HFP开启状态 + void ConfigModel::SetHFPState(bool value) + { + set_condigData_Bool(CONFIGMODEL_ITEM_HFP,value); + } + + //获取HFP开启状态 + bool ConfigModel::GetHFPState(void) + { + return get_configData_bool(CONFIGMODEL_ITEM_HFP); + } + + //设置A2DP开启状态 + void ConfigModel::SetA2DPState(bool value) + { + set_condigData_Bool(CONFIGMODEL_ITEM_A2DP,value); + } + + //获取A2DP开启状态 + bool ConfigModel::GetA2DPState(void) + { + return get_configData_bool(CONFIGMODEL_ITEM_A2DP); + } + /* -------------------------------------------------------------------------- */ void ConfigModel::SetLanguage(int language) { diff --git a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/settings/SETTINGS_SHUTDOWN_AND_RESTART.bin b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/settings/SETTINGS_SHUTDOWN_AND_RESTART.bin index cb55abecb..7331b61cf 100644 Binary files a/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/settings/SETTINGS_SHUTDOWN_AND_RESTART.bin and b/code/sdk/build/config/target_config/brandy/mk_fs_image/fd230/fs/user/res/settings/SETTINGS_SHUTDOWN_AND_RESTART.bin differ