From: luozheng <1732036298@qq.com> Date: Tue, 20 Feb 2024 09:57:18 +0000 (+0800) Subject: 设置视图中将蓝牙耳机Slice修改为蓝牙Slice,蓝牙耳机界面可以通过蓝牙界面进入,并且蓝牙界面配置了开启传统蓝牙按钮,但需要开启蓝牙设备接口 X-Git-Tag: release_V1.2.70_20241020_135402~1298^2~22^2 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=fa9a7b915bd957407f5bc0d062cb1280709c4571;p=mirrors%2FFD230.git 设置视图中将蓝牙耳机Slice修改为蓝牙Slice,蓝牙耳机界面可以通过蓝牙界面进入,并且蓝牙界面配置了开启传统蓝牙按钮,但需要开启蓝牙设备接口 --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index cc7c97296..b8cebe032 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -294,6 +294,11 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/compass/src/MainCompassView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/compass/src/MainCompassPresenter.cpp + #经典蓝牙 + ${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/message/src/MessageAdapter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/message/src/MessageItemView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/message/src/MessageModel.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index df179b59f..cd06e398b 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -33,6 +33,7 @@ typedef enum : uint16_t VIEW_MAIN_ALARM, // 闹钟 VIEW_ALARM_POP_UP, // 闹铃界面 VIEW_BLUETOOTH_EARPHONE, // 连接蓝牙耳机界面 + VIEW_CLASSIC_BLUETOOTH, // 经典蓝牙 VIEW_CALLER_LOG, // 通话记录界面 VIEW_INCOMING_CALL, // 来电界面 VIEW_BLOODOXY, // 血氧饱和度界面 diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index 7a699f59d..725c8f8b9 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -67,6 +67,8 @@ namespace OHOS void InitMessageSlice(void); /* -------------------------------------------------------------------------- */ void InitDisplayBrightnessSlice(void); + /* --------------------------------- 经典蓝牙界面 --------------------------------- */ + void InitClassicBluetoothSlice(void); /* --------------------------------测试界面------------------------------------ */ void InitBloodSlice(void); diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index 437c34acc..f6f7ed1d7 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -57,7 +57,6 @@ #include "UISampleView.h" #include "UISamplePresenter.h" - #include "blood/include/BloodCardView.h" #include "weather/include/MainWeatherPresenter.h" @@ -95,6 +94,9 @@ #include "secondaryfunction/include/QuickAccessPresenter.h" #include "secondaryfunction/include/QuickAccessView.h" +#include "classicbluetooth/include/ClassicBlueToothPresenter.h" +#include "classicbluetooth/include/ClassicBlueToothView.h" + #include "BluetoothHeadsetEvent.h" #include "graphic_hardware_config.h" #include "graphic_service.h" @@ -141,8 +143,8 @@ namespace OHOS {VIEW_SYSTEM, &NativeLauncher::InitSystemSlice}, // 系统实例化地址 {VIEW_SOUND_VIBRATION, &NativeLauncher::InitSoundAndVibrationSlice}, // 声音与震动实例化地址 {VIEW_SYSTEM_VOLUME, &NativeLauncher::InitSystemVolumeSlice}, // 系统音量 - - {VIEW_DISPLAY_BRIGHTNESS, &NativeLauncher::InitDisplayBrightnessSlice}, // 显示与亮度的实例化地址 + {VIEW_CLASSIC_BLUETOOTH, &NativeLauncher::InitClassicBluetoothSlice}, // 经典蓝牙slice + {VIEW_DISPLAY_BRIGHTNESS, &NativeLauncher::InitDisplayBrightnessSlice}, // 显示与亮度的实例化地址 {VIEW_SECONDARY_FUNCTION, &NativeLauncher::InitSecondaryFunction}, {VIEW_QUICK_ACCESS, &NativeLauncher::InitQuickAccessSlice}, // 快速访问实例化地址 {VIEW_FAST_TRAINING, &NativeLauncher::InitFastTrainingSlice}, @@ -443,7 +445,6 @@ namespace OHOS NativeAbility::GetInstance().AddSliceProxy(VIEW_UISAMPLE, uisampleView); } - void NativeLauncher::InitWeatherSlice(void) // 天气 { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitWeatherSlice"); @@ -544,7 +545,6 @@ namespace OHOS NativeAbility::GetInstance().AddSliceProxy(VIEW_DISPLAY_BRIGHTNESS, uidisplaybrightnessView); } - void NativeLauncher::InitSecondaryFunction(void) // 辅助功能 { SliceProxy *secondaryfunction = new AbilitySliceProxy; @@ -585,4 +585,16 @@ namespace OHOS NativeAbility::GetInstance().AddSliceProxy(VIEW_FAST_TRAINING_ATTENTION, fasttrainingattention); } + void NativeLauncher::InitClassicBluetoothSlice(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitClassicBluetoothSlice"); + SliceProxy *classicbluetooth = new AbilitySliceProxy; + if (classicbluetooth == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "classicbluetooth"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_CLASSIC_BLUETOOTH, classicbluetooth); + } + } 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 7fbbc729b..820589c8e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/MainBluetoothView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bluetooth/src/MainBluetoothView.cpp @@ -343,7 +343,7 @@ 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_CLASSIC_BLUETOOTH); } void MainBluetoothView::DropEarPhoneView() diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothModel.h b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothModel.h new file mode 100644 index 000000000..7201aae94 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothModel.h @@ -0,0 +1,26 @@ +#ifndef CLASSIC_BLUETOOTH_MODEL_H +#define CLASSIC_BLUETOOTH_MODEL_H + +#include "wearable_log.h" + +namespace OHOS +{ + class ClassicBlueToothModel + { + public: + static ClassicBlueToothModel *GetInstance(void); + void MarkTradionalBlueToothToggleButtonStatus(bool value); + bool TradionalBlueToothToggleButtonStatusInit(); + + private: + ClassicBlueToothModel(); + ClassicBlueToothModel(const ClassicBlueToothModel &); + ClassicBlueToothModel &operator=(const ClassicBlueToothModel &); + virtual ~ClassicBlueToothModel(); + + private: + // 用来记录蓝牙开关状态,默认关闭状态 + bool TradionalBlueToothToggleButtonState{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 new file mode 100644 index 000000000..ce00c6853 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothPresenter.h @@ -0,0 +1,34 @@ +#ifndef CLASSIC_BLUETOOTH_PRESENTER_H +#define CLASSIC_BLUETOOTH_PRESENTER_H +#include "Presenter.h" +#include "ClassicBlueToothView.h" +#include "wearable_log.h" +namespace OHOS +{ + class ClassicBlueToothView; + class ClassicBlueToothPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener, + public UICheckBox::OnChangeListener + { + public: + ClassicBlueToothPresenter(); + virtual ~ClassicBlueToothPresenter(); + + virtual void OnStart() override; + virtual void OnPause() override; + virtual void OnResume() override; + virtual void OnStop() override; + + static ClassicBlueToothPresenter *GetInstance(); + void SetBluetoothDeviceSwitchState(bool value); + 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 OnChange(UICheckBox::UICheckBoxState state) override; + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothView.h b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothView.h new file mode 100644 index 000000000..da44ba774 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/include/ClassicBlueToothView.h @@ -0,0 +1,64 @@ +#ifndef CLASSIC_BLUETOOTH_VIEW_H +#define CLASSIC_BLUETOOTH_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "components/root_view.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_button.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 + // 返回setting视图界面 + class ClassicBlueToothPresenter; + class ClassicBlueToothView : 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; // 断行模式。 + }; + ClassicBlueToothView(); + virtual ~ClassicBlueToothView(); + static ClassicBlueToothView *GetInstance(void); + void ClassicBlueToothViewInit(void); + void ClearAll(void); + bool GetTradionalBlueToothToggleButtonState(void); + void SetTradionalBlueToothToggleButtonState(bool state); + + public: + virtual void OnStart() override; + virtual void OnSetUpView() override; + virtual void OnTearDownView() override; + virtual void OnStop() override; + + private: + bool SetUpBlueToothScrollView(void); + UILabel *SetClassicBlueToothViewLabel(LabelConfig &labelconfig); + bool SetUpBlueToothLabel(void); + bool SetUpBlueToothEarPhoneButton(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; + UIToggleButton *TradionalBlueToothToggleButton = nullptr; + bool initViewStatus{false}; + }; +} +#endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothModel.cpp new file mode 100644 index 000000000..85ef8b67e --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothModel.cpp @@ -0,0 +1,36 @@ +#include "classicbluetooth/include/ClassicBlueToothModel.h" +#include "classicbluetooth/include/ClassicBlueToothPresenter.h" + +namespace OHOS +{ + ClassicBlueToothModel::ClassicBlueToothModel() {} + + ClassicBlueToothModel::~ClassicBlueToothModel() {} + + ClassicBlueToothModel *ClassicBlueToothModel::GetInstance(void) + { + static ClassicBlueToothModel instance; + return &instance; + } + + /// @brief 标记蓝牙开关的状态 + /// @param value true 开启状态 false 关闭状态 + void ClassicBlueToothModel::MarkTradionalBlueToothToggleButtonStatus(bool value) + { + TradionalBlueToothToggleButtonState = 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(TradionalBlueToothToggleButtonState); // 蓝牙开关状态 + 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 new file mode 100644 index 000000000..483364274 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp @@ -0,0 +1,125 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "graphic_math.h" +#include "classicbluetooth/include/ClassicBlueToothPresenter.h" +#include "classicbluetooth/include/ClassicBlueToothModel.h" +namespace OHOS +{ + // 当前Presenter属性实例化的内存指针 + static ClassicBlueToothPresenter *g_pClassicBlueToothPresenter = nullptr; + + ClassicBlueToothPresenter::ClassicBlueToothPresenter() + { + g_pClassicBlueToothPresenter = this; + } + + ClassicBlueToothPresenter::~ClassicBlueToothPresenter() + { + g_pClassicBlueToothPresenter = nullptr; + } + + ClassicBlueToothPresenter *ClassicBlueToothPresenter::GetInstance() + { + return g_pClassicBlueToothPresenter; + } + + void ClassicBlueToothPresenter::OnStart() + { + Presenter::OnStart(); + } + + void ClassicBlueToothPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void ClassicBlueToothPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void ClassicBlueToothPresenter::OnStop(void) + { + 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->SetTradionalBlueToothToggleButtonState(true); + ClassicBlueToothModel::GetInstance()->MarkTradionalBlueToothToggleButtonStatus(false); // 将Model层保存的状态清除 + } + } + + bool ClassicBlueToothPresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + 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); + } + + return true; + } + + bool ClassicBlueToothPresenter::OnDrag(UIView &view, const DragEvent &event) + { + return true; + } + + bool ClassicBlueToothPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + 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); + } + } + + return true; + } + + bool ClassicBlueToothPresenter::OnChange(UICheckBox::UICheckBoxState state) + { + switch (state) + { + case UICheckBox::SELECTED: + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BlueTooth Capability Is Enabled"); + + break; + case UICheckBox::UNSELECTED: + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BlueTooth Capability Is Disabled"); + + break; + default: + break; + } + 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 new file mode 100644 index 000000000..e1e0ec766 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp @@ -0,0 +1,327 @@ +#include "classicbluetooth/include/ClassicBlueToothView.h" +#include "classicbluetooth/include/ClassicBlueToothPresenter.h" +#include "classicbluetooth/include/ClassicBlueToothModel.h" + +namespace OHOS +{ + static ClassicBlueToothView *g_pClassicBlueToothView{nullptr}; + + ClassicBlueToothView::ClassicBlueToothView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::ClassicBlueToothView"); + g_pClassicBlueToothView = this; + } + + ClassicBlueToothView::~ClassicBlueToothView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "~ClassicBlueToothView::ClassicBlueToothView"); + ClearAll(); + g_pClassicBlueToothView = nullptr; + } + + ClassicBlueToothView *ClassicBlueToothView::GetInstance() + { + return g_pClassicBlueToothView; + } + + void ClassicBlueToothView::ClearAll() + { + if (initViewStatus == true) + { + BlueToothScrollView->RemoveAll(); + + bool state = GetTradionalBlueToothToggleButtonState(); + if (state == true) + { + ClassicBlueToothModel::GetInstance()->MarkTradionalBlueToothToggleButtonStatus(true); + } + + delete Title; + Title = nullptr; + + delete BlueToothEarPhoneLabel; + BlueToothEarPhoneLabel = nullptr; + + delete TradionalBlueToothLabel; + TradionalBlueToothLabel = nullptr; + + 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; + + delete BlueToothScrollView; + BlueToothScrollView = nullptr; + } + } + + bool ClassicBlueToothView::SetUpBlueToothScrollView(void) + { + BlueToothScrollView = new UIScrollView(); + if (BlueToothScrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::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(ClassicBlueToothPresenter::GetInstance()); + if (draglistener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::draglistener can not be nullptr!"); + return false; + } + BlueToothScrollView->SetOnDragListener(draglistener); + BlueToothScrollView->SetTouchable(true); + BlueToothScrollView->SetDraggable(true); + + return true; + } + + // 标签配置 + UILabel *ClassicBlueToothView::SetClassicBlueToothViewLabel(LabelConfig &labelconfig) + { + UILabel *label = new UILabel(); + 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->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); + return label; + } + + // 标签初始化 + bool ClassicBlueToothView::SetUpBlueToothLabel(void) + { + LabelConfig labelconfig = { + .left = 203, + .top = 52, + .width = 65, + .height = 35, + .fontSize = 30, + .lineHeigh = 35, + .text = "蓝牙", + .lineBreakMode = UILabel::LINE_BREAK_ADAPT, + }; + Title = SetClassicBlueToothViewLabel(labelconfig); + if (nullptr == Title) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::Title is nullptr!"); + return false; + } + labelconfig = { + .left = 90, + .top = 153, + .width = 120, + .height = 35, + .fontSize = 30, + .lineHeigh = 35, + .text = "蓝牙耳机", + .lineBreakMode = UILabel::LINE_BREAK_ADAPT, + }; + BlueToothEarPhoneLabel = SetClassicBlueToothViewLabel(labelconfig); + if (nullptr == BlueToothEarPhoneLabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::BlueToothEarPhoneLabel is nullptr!"); + return false; + } + labelconfig.top = 273; + labelconfig.text = "传统蓝牙"; + TradionalBlueToothLabel = SetClassicBlueToothViewLabel(labelconfig); + if (nullptr == TradionalBlueToothLabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::TradionalBlueToothLabel is nullptr!"); + return false; + } + + labelconfig = { + .left = 53, + .top = 379, + .width = 360, + .height = 180, + .fontSize = 20, + .lineHeigh = 30, + .text = "注:开启后10分钟没连接成功会自动关闭,因为传统蓝牙长时间打开会增加电耗,建议在有需要的时候使用\n\n(该功能主要用于电话拨打/通知、音乐控制/传输等)", + .lineBreakMode = UILabel::LINE_BREAK_WRAP, + }; + AttentionLabel = SetClassicBlueToothViewLabel(labelconfig); + if (nullptr == AttentionLabel) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::AttentionLabel is nullptr!"); + return false; + } + + return true; + } + + // 蓝牙耳机按钮 + bool ClassicBlueToothView::SetUpBlueToothEarPhoneButton(void) + { + BlueToothEarPhoneButton = new UIButton(); + if (BlueToothEarPhoneButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " ClassicBlueToothView::BlueToothEarPhoneButton new fail!"); + return false; + } + 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); + + UIView::OnClickListener *clickListener = static_cast(ClassicBlueToothPresenter::GetInstance()); + BlueToothEarPhoneButton->SetOnClickListener(clickListener); + + return true; + } + + // 手表蓝牙开关按钮 + bool ClassicBlueToothView::SetUpBlueToothToggleButton() + { + TradionalBlueToothToggleButton = new UIToggleButton(); + if (nullptr == TradionalBlueToothToggleButton) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " ClassicBlueToothView::BlueToothEarPhoneButton new fail!"); + return false; + } + TradionalBlueToothToggleButton->SetPosition(298, 265, 100, 50); + TradionalBlueToothToggleButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + TradionalBlueToothToggleButton->SetImages("/user/res/TOGGLEBUTTON_ON.bin", "/user/res/TOGGLEBUTTON_OFF.bin"); + UICheckBox::OnChangeListener *changeListener = static_cast(ClassicBlueToothPresenter::GetInstance()); + TradionalBlueToothToggleButton->SetOnChangeListener(changeListener); + return true; + } + + bool ClassicBlueToothView::SetUpImageView(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::GetTradionalBlueToothToggleButtonState(void) + { + return TradionalBlueToothToggleButton->GetState(); + } + + /// @brief 设置蓝牙切换按钮的状态 + /// @param state true 开启 false 关闭 + void ClassicBlueToothView::SetTradionalBlueToothToggleButtonState(bool state) + { + if (TradionalBlueToothToggleButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TradionalBlueToothToggleButton is nullptr!"); + return; + } + TradionalBlueToothToggleButton->SetState(state); + } + + /// @brief 蓝牙界面初始化 + /// @param void + void ClassicBlueToothView::ClassicBlueToothViewInit(void) + { + if (!SetUpBlueToothScrollView()) + { + return; + } + + if (!SetUpBlueToothLabel()) + { + return; + } + + if (!SetUpBlueToothEarPhoneButton()) + { + return; + } + + if (!SetUpBlueToothToggleButton()) + { + return; + } + + if (!SetUpImageView()) + { + return; + } + ClassicBlueToothModel::GetInstance()->TradionalBlueToothToggleButtonStatusInit(); + initViewStatus = true; + } + + void ClassicBlueToothView::OnStart() + { + View::OnStart(); + ClassicBlueToothViewInit(); + } + + void ClassicBlueToothView::OnSetUpView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::OnSetUpView"); + View::OnSetUpView(); + BlueToothScrollView->Add(Title); + BlueToothScrollView->Add(BlueToothEarPhoneButton); + BlueToothScrollView->Add(image[0]); + BlueToothScrollView->Add(image[1]); + BlueToothScrollView->Add(BlueToothEarPhoneLabel); + BlueToothScrollView->Add(TradionalBlueToothLabel); + BlueToothScrollView->Add(AttentionLabel); + BlueToothScrollView->Add(TradionalBlueToothToggleButton); + RootView::GetInstance()->Add(BlueToothScrollView); + Draw(); + } + + void ClassicBlueToothView::OnTearDownView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::OnTearDownView"); + View::OnTearDownView(); + RootView::GetInstance()->RemoveAll(); + return; + } + + void ClassicBlueToothView::OnStop() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothView::OnStop"); + View::OnStop(); + return; + } + +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp index 43ac836d3..15f1df87d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp @@ -34,7 +34,7 @@ namespace OHOS DisplayBrightnessPresenter *displayBrightnessPresent = DisplayBrightnessPresenter::GetInstance(); if (displayBrightnessPresent == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RaiseToBrightnessCheckBoxButtonStateInit DisplayBrightnessPresenter GetInstance fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessViewAndSubViewComponentsStatusInit DisplayBrightnessPresenter GetInstance fail"); return false; } displayBrightnessPresent->SetRaiseToBrightnessState(RaiseToBrightnessCheckBoxButtonState); // 抬腕按钮的状态 diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp index eaa17ee47..c5f92ac6c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp @@ -35,7 +35,7 @@ namespace OHOS DisplayBrightnessView *displayBrightnessView = DisplayBrightnessView::GetInstance(); if (displayBrightnessView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetPlayerState playersView GetInstance fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetRaiseToBrightnessState displayBrightnessView GetInstance fail"); return; } if (value != false) diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp index f6e03d8b3..1c7580dcd 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp @@ -381,7 +381,7 @@ namespace OHOS { if (RaiseToBrightnessCheckBoxButton == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PlayersView::SetPlayerButtonState playerButton NULL"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RaiseToBrightnessCheckBoxButton is nullptr!"); return; } RaiseToBrightnessCheckBoxButton->SetState(state); diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp index 3672941f9..af86ed727 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp @@ -32,12 +32,8 @@ namespace OHOS { map g_jumpView = { - {MAIN_CLICK_WEATHER, VIEW_MAIN}, // 天气界面 - {MAIN_CLICK_ACTIVITY, VIEW_MAIN_ACTIVITY}, // 活动记录界面 - {MAIN_CLICK_MESSAGE, VIEW_MAIN}, // 消息app - {MAIN_CLICK_HEARTRATE, VIEW_MAIN}, // 心率界面 {DROPDOWN_CLICK_SETTING, VIEW_SETTING}, // 设置 - {DROPDOWN_CLICK_BLUETOOTH, VIEW_BLUETOOTH_EARPHONE}, // 蓝牙 + {DROPDOWN_CLICK_BLUETOOTH, VIEW_CLASSIC_BLUETOOTH}, // 蓝牙 }; // map g_chanColor = { { DROPDOWN_CLICK_FINDMYPHONE, DROPDOWN_DROPDOWN_FIND_PHONE_B }, @@ -143,12 +139,11 @@ namespace OHOS SendMsgToUIService(SCREEN_OFF_ENABLE_TO_UI, 0, &enable, sizeof(int32_t)); } } - + #endif if (g_jumpView.count(curViewId) != 0) { NativeAbility::GetInstance().ChangeSlice(g_jumpView[curViewId]); } -#endif return true; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp index 3dda499fe..06bc0472b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingModel.cpp @@ -29,7 +29,7 @@ namespace OHOS settings[4] = {SETTING_ITEM_FOUR, PNG_SETTINGS_SYSTEM, "系统", true}; settings[5] = {SETTING_ITEM_FIVE, PNG_SETTINGS_SETTINGS_POWER_CONTROL, "关机和重启", true}; settingIdToViewId.insert(std::pair(SETTING_ITEM_ZERO, VIEW_DISPLAY_BRIGHTNESS)); - settingIdToViewId.insert(std::pair(SETTING_ITEM_ONE, VIEW_BLUETOOTH_EARPHONE)); + settingIdToViewId.insert(std::pair(SETTING_ITEM_ONE, VIEW_CLASSIC_BLUETOOTH)); settingIdToViewId.insert(std::pair(SETTING_ITEM_TWO, VIEW_SOUND_VIBRATION)); settingIdToViewId.insert(std::pair(SETTING_ITEM_THREE, VIEW_SECONDARY_FUNCTION)); settingIdToViewId.insert(std::pair(SETTING_ITEM_FOUR, VIEW_SYSTEM));