From fae7b033d2b2ddc1cf6b902be25cb98ceaa8ecfe Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Wed, 13 Mar 2024 20:34:34 +0800 Subject: [PATCH] =?utf8?q?=E5=BD=95=E9=9F=B3=E7=95=8C=E9=9D=A2=E5=AE=9E?= =?utf8?q?=E7=8E=B0=E5=A3=B0=E9=9F=B3=E8=B0=83=E8=8A=82=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../wearable/fd230app/CMakeLists.txt | 1 + .../record/include/RecordingPresenter.h | 11 +- .../nativeui/record/include/RecordingView.h | 13 +- .../include/RecordingVolumeSettingView.h | 24 +++ .../record/src/RecordingPresenter.cpp | 6 +- .../nativeui/record/src/RecordingView.cpp | 27 +++ .../record/src/RecordingVolumeSettingView.cpp | 65 ++++++ .../SoundAndVibrationVolumeSettingView.h | 9 +- .../include/SystemVolumePresenter.h | 36 +++- .../include/SystemVolumeView.h | 1 + .../SoundAndVibrationVolumeSettingView.cpp | 51 ++--- .../src/SystemVolumePresenter.cpp | 191 ++++++++++++++---- 12 files changed, 358 insertions(+), 77 deletions(-) create mode 100644 code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingVolumeSettingView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingVolumeSettingView.cpp diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 1cf81a615..66a9a9f4d 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -326,6 +326,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordingPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordingView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordingModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/record/src/RecordingVolumeSettingView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/message/src/MessageAdapter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/message/src/MessageItemView.cpp diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingPresenter.h index 5bec3da31..b7d718e6c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingPresenter.h @@ -11,11 +11,12 @@ namespace OHOS { typedef enum { - RECORDINGVIEW = 0, // 录音视图(slice) - RECORDINGLISTVIEW, // 录音列表视图(subView) - RECORDGOINGVIEW, // 正在录音视图(subView) - RECORDINGPLAYERVIEW, // 录音播放视图(subView) - RECORDINGDELETEVIEW, // 录音删除视图(subView) + RECORDINGVIEW = 0, // 录音视图(slice) + RECORDINGLISTVIEW, // 录音列表视图(subView) + RECORDGOINGVIEW, // 正在录音视图(subView) + RECORDINGPLAYERVIEW, // 录音播放视图(subView) + RECORDINGDELETEVIEW, // 录音删除视图(subView) + RECORDINGVOLUMESETTINGVIEW, // 声音设置视图(subView) MAX_RECORDINGVIEWID, } RECORDINGVIEWID; diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingView.h b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingView.h index 846eb1ada..99ea39276 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingView.h @@ -15,6 +15,7 @@ #include "record/include/RecordGoingView.h" #include "record/include/RecordingPlayerView.h" #include "record/include/RecordDeleteView.h" +#include "record/include/RecordingVolumeSettingView.h" #define NUM_MAX_RECORDINGVIEWSCROLLVIEW 10 namespace OHOS @@ -37,11 +38,12 @@ namespace OHOS virtual ~RecordingView(); static RecordingView *GetInstance(void); - bool ChangeRecordingView(int16_t thisView); // 切换到“录音”视图slice - bool ChangeRecordListView(int16_t thisView); // 切换到"录音列表"视图 - bool ChangeRecordGoingView(int16_t thisView); // 切换到“正在录音”视图 - bool ChangeRecordingPlayerView(int16_t thisView); // 切换到“录音播放”视图 - bool ChangeRecordDeleteView(int16_t thisView); // 切换到“录音删除”视图 + bool ChangeRecordingView(int16_t thisView); // 切换到“录音”视图slice + bool ChangeRecordListView(int16_t thisView); // 切换到"录音列表"视图 + bool ChangeRecordGoingView(int16_t thisView); // 切换到“正在录音”视图 + bool ChangeRecordingPlayerView(int16_t thisView); // 切换到“录音播放”视图 + bool ChangeRecordDeleteView(int16_t thisView); // 切换到“录音删除”视图 + bool ChangeRecordVolumeSettingView(int16_t thisView); // 切换到“声音设置”视图 bool ClickFunc(int16_t interface); void ChangeView(int16_t hideView, int16_t showView); UIScrollView *GetRecordingViewScrollView(int i); @@ -57,6 +59,7 @@ namespace OHOS RecordGoingView *p_RecordGoingView{nullptr}; RecordingPlayerView *p_RecordingPlayerView{nullptr}; RecordDeleteView *p_RecordDeleteView{nullptr}; + RecordingVolumeSettingView *p_RecordingVolumeSettingView{nullptr}; private: void RecordingViewInit(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingVolumeSettingView.h b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingVolumeSettingView.h new file mode 100644 index 000000000..92e6421ee --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/record/include/RecordingVolumeSettingView.h @@ -0,0 +1,24 @@ +#ifndef RECORDING_VOLUME_SETTING_VIEW_H +#define RECORDING_VOLUME_SETTING_VIEW_H + +#include "soundandvibration/include/SoundAndVibrationVolumeSettingView.h" +#include "components/ui_scroll_view.h" +namespace OHOS +{ + class RecordingVolumeSettingView + { + public: + RecordingVolumeSettingView(); + ~RecordingVolumeSettingView(); + static RecordingVolumeSettingView *GetInstance(); + UIScrollView *RecordingVolumeSettingViewInit(void); + void ClearAll(void); + private: + SoundAndVibrationVolumeSettingView *p_SoundAndVibrationVolumeSettingView{nullptr}; + UIScrollView *RecordingVolumeSettingViewScrollView{nullptr}; + bool initViewStatus{false}; + }; + +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPresenter.cpp index 2b856c7d2..51455329f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingPresenter.cpp @@ -94,6 +94,10 @@ namespace OHOS { p_RecordingView->ChangeView(i, RECORDINGLISTVIEW); } + else if(i == RECORDINGVOLUMESETTINGVIEW) + { + p_RecordingView->ChangeView(i, RECORDINGPLAYERVIEW); + } else { p_RecordingView->ChangeView(i, RECORDINGVIEW); @@ -408,7 +412,7 @@ namespace OHOS else if (strcmp(view.GetViewId(), RECORD_PLAY_VOLUME_BUTTON_VIEWID) == 0) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "recording player volume button being clicked!"); - NativeAbility::GetInstance().ChangeSlice(VIEW_SYSTEM_VOLUME); + p_RecordingView->ChangeView(RECORDINGPLAYERVIEW, RECORDINGVOLUMESETTINGVIEW); } return true; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingView.cpp index 681d47f0f..7893cc7b5 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingView.cpp @@ -74,6 +74,12 @@ namespace OHOS p_RecordDeleteView = nullptr; } + if (p_RecordingVolumeSettingView != nullptr) + { + delete p_RecordingVolumeSettingView; + p_RecordingVolumeSettingView = nullptr; + } + delete RecordingViewScrollView[RECORDINGVIEW]; RecordingViewScrollView[RECORDINGVIEW] = nullptr; } @@ -309,6 +315,26 @@ namespace OHOS } return true; } + + /* + * @brief 切换到“声音设置”视图 + */ + bool RecordingView::ChangeRecordVolumeSettingView(int16_t thisView) // 切换到“声音设置”视图 + { + if (RecordingViewScrollView[thisView] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView::ChangeRecordVolumeSettingView"); + p_RecordingVolumeSettingView = new RecordingVolumeSettingView(); + if (p_RecordingVolumeSettingView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingView:: new scrollView[%d] fail", thisView); + return false; + } + RecordingViewScrollView[thisView] = p_RecordingVolumeSettingView->RecordingVolumeSettingViewInit(); + RootView::GetInstance()->Add(RecordingViewScrollView[thisView]); + } + return true; + } /* -------------------------------------------------------------------------- */ // 1.RecordingViewMapper:结构体定义了一个将视图ID映射到特定成员函数指针的映射表。 struct RecordingViewMapper @@ -324,6 +350,7 @@ namespace OHOS {RECORDGOINGVIEW, &RecordingView::ChangeRecordGoingView}, {RECORDINGPLAYERVIEW, &RecordingView::ChangeRecordingPlayerView}, {RECORDINGDELETEVIEW, &RecordingView::ChangeRecordDeleteView}, + {RECORDINGVOLUMESETTINGVIEW, &RecordingView::ChangeRecordVolumeSettingView}, }; // 3.根据传入的interface参数执行相应视图ID关联的成员函数。 diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingVolumeSettingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingVolumeSettingView.cpp new file mode 100644 index 000000000..32f5edfad --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingVolumeSettingView.cpp @@ -0,0 +1,65 @@ +#include "record/include/RecordingVolumeSettingView.h" +#include "record/include/RecordingPresenter.h" + +namespace OHOS +{ + + static RecordingVolumeSettingView *g_pRecordingVolumeSettingView{nullptr}; + RecordingVolumeSettingView::RecordingVolumeSettingView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingVolumeSettingView::RecordingVolumeSettingView"); + + g_pRecordingVolumeSettingView = this; + } + + RecordingVolumeSettingView::~RecordingVolumeSettingView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingVolumeSettingView::~RecordingVolumeSettingView"); + + g_pRecordingVolumeSettingView = nullptr; + } + + RecordingVolumeSettingView *RecordingVolumeSettingView::GetInstance() + { + return g_pRecordingVolumeSettingView; + } + + void RecordingVolumeSettingView::ClearAll(void) + { + if (initViewStatus == true) + { + delete p_SoundAndVibrationVolumeSettingView; + p_SoundAndVibrationVolumeSettingView = nullptr; + } + } + + UIScrollView *RecordingVolumeSettingView::RecordingVolumeSettingViewInit(void) + { + + p_SoundAndVibrationVolumeSettingView = new SoundAndVibrationVolumeSettingView(); + if (p_SoundAndVibrationVolumeSettingView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_SoundAndVibrationVolumeSettingView nullptr err"); + return nullptr; + } + RecordingVolumeSettingViewScrollView = p_SoundAndVibrationVolumeSettingView->SetUpVolumeProcess(); + UIView::OnDragListener *volumeDragListener = (UIView::OnDragListener *)OHOS::RecordingPresenter::GetInstance(); + if (volumeDragListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingPresenter GetInstance fail"); + return nullptr; + } + RecordingVolumeSettingViewScrollView->SetOnDragListener(volumeDragListener); + if (RecordingVolumeSettingViewScrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_SoundAndVibrationVolumeSettingView->SetUpVolumeProcess fail!!"); + return nullptr; + } + + p_SoundAndVibrationVolumeSettingView->GetVolumeProcess()->SetValue(AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC)); + + initViewStatus = true; + return RecordingVolumeSettingViewScrollView; + } + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingView.h b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingView.h index 7aa75ea4f..0dbc17609 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingView.h @@ -6,6 +6,7 @@ #include "components/ui_scroll_view.h" #include "components/ui_slider.h" #include "components/ui_image_view.h" +#include "soundandvibration/include/SystemVolumePresenter.h" /* 声音与震动的声音设置视图 @@ -17,18 +18,22 @@ namespace OHOS #define VOLUME_MAX 100 #define VOLUME_PROGRESS "progress" - class SoundAndVibrationVolumeSettingView + class VoumeProcessSliderEventListener; + class SoundAndVibrationVolumeSettingView { public: SoundAndVibrationVolumeSettingView(); ~SoundAndVibrationVolumeSettingView(); static SoundAndVibrationVolumeSettingView *GetInstance(void); - UIScrollView * SetUpVolumeProcess(void); + UIScrollView *SetUpVolumeProcess(void); void ClearAll(void); + UISlider *GetVolumeProcess(void); + int CurrentVolumeValue{0}; private: UIScrollView *ScrollView{nullptr}; UISlider *VolumeProcess{nullptr}; UIImageView *VolumeVetor{nullptr}; + VoumeProcessSliderEventListener *listener = nullptr; bool initViewStatus{false}; }; diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumePresenter.h b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumePresenter.h index 0d77621e7..85810c04e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumePresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumePresenter.h @@ -2,16 +2,44 @@ #define SYSTEM_VOLUME_PRESENTER_H #include "Presenter.h" - #include "SystemVolumeView.h" +#include "wearable_log.h" namespace OHOS { - class SystemVolumeView; + typedef enum : uint8_t + { + VOLUMEREDUCE = 0, // 声音降低 + VOLUMEADD = 1, // 声音增加 + OTHER = 2, // 其他 + } VolumeStatusChange; + + /* + * @brief 声音进度条的事件监听类 + */ + class VoumeProcessSliderEventListener : public UISlider::UISliderEventListener, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + VoumeProcessSliderEventListener(); + ~VoumeProcessSliderEventListener(); + static VoumeProcessSliderEventListener *GetInstance(void); + void ChangeVolumeValue(uint8_t status, uint8_t value); + void LocalVolumeSet(int16_t sounding); + void OnChange(int32_t value) override; + void OnRelease(int32_t value) override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + private: + int32_t VolumeValue; // 声音值 + }; + + class SystemVolumeView; class SystemVolumePresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener + public UIView::OnClickListener, + public UIView::OnDragListener { public: SystemVolumePresenter(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumeView.h b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumeView.h index af359213e..4a72e8f11 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumeView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumeView.h @@ -9,6 +9,7 @@ namespace OHOS { static const char *SYSTEM_VOLUME_SLIDER = "SystemVolumeSlider"; + class SoundAndVibrationVolumeSettingView; class SystemVolumePresenter; class SystemVolumeView : public View { diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingView.cpp index dc16bb2ef..65c436a12 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingView.cpp @@ -1,6 +1,5 @@ #include "soundandvibration/include/SoundAndVibrationVolumeSettingView.h" #include "soundandvibration/include/SoundAndVibrationPresenter.h" -#include "soundandvibration/include/SystemVolumePresenter.h" #include "wearable_log.h" namespace OHOS @@ -31,15 +30,29 @@ namespace OHOS if (initViewStatus == true) { ScrollView->RemoveAll(); + delete VolumeProcess; VolumeProcess = nullptr; + delete VolumeVetor; VolumeVetor = nullptr; + + delete listener; + listener = nullptr; + delete ScrollView; ScrollView = nullptr; } } + /* + * @brief 获取声音进度条 + */ + UISlider *SoundAndVibrationVolumeSettingView::GetVolumeProcess(void) + { + return VolumeProcess; + } + UIScrollView *SoundAndVibrationVolumeSettingView::SetUpVolumeProcess(void) { ScrollView = new UIScrollView(); @@ -49,13 +62,6 @@ namespace OHOS return nullptr; } ScrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - UIView::OnDragListener *volumeDragListener = (UIView::OnDragListener *)OHOS::SystemVolumePresenter::GetInstance(); - if (volumeDragListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemVolumePresenter GetInstance fail"); - return nullptr; - } - ScrollView->SetOnDragListener(volumeDragListener); ScrollView->SetDraggable(true); ScrollView->SetTouchable(true); /* ------------------------------ VolumeProcess ----------------------------- */ @@ -88,21 +94,20 @@ namespace OHOS const char *image = "/user/res/VolumeControlVector.bin"; VolumeVetor->SetSrc(image); - // if (listener == nullptr) - // { - // listener = new VolumeSliderEventListener(); - // if (listener == nullptr) - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "listener new fail"); - // return false; - // } - // } - // progress->SetSliderEventListener(listener); - // progress->SetOnClickListener(listener); - // progress->SetOnDragListener(listener); - // progress->SetKnobStyle(StyleDefault::GetSliderKnobStyle()); - // - // SetViewId(VOLUME_VIEW); + if (listener == nullptr) + { + listener = new VoumeProcessSliderEventListener(); + if (listener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Listener new fail!"); + return nullptr; + } + } + VolumeProcess->SetSliderEventListener(listener); + VolumeProcess->SetOnClickListener(listener); + VolumeProcess->SetOnDragListener(listener); + VolumeProcess->SetKnobStyle(StyleDefault::GetSliderKnobStyle()); + ScrollView->Add(VolumeProcess); ScrollView->Add(VolumeVetor); initViewStatus = true; diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumePresenter.cpp index e688e1bf7..63f6517ce 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumePresenter.cpp @@ -3,73 +3,190 @@ #include "graphic_math.h" #include "string.h" #include "soundandvibration/include/SystemVolumePresenter.h" -//系统音量 -namespace OHOS{ - - //当前Presenter属性实例化的内存指针 - static SystemVolumePresenter *g_pSystemVolumePresenter = nullptr; - - SystemVolumePresenter::SystemVolumePresenter(){ - + +#include +// 系统音量 +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static SystemVolumePresenter *g_pSystemVolumePresenter = nullptr; + + SystemVolumePresenter::SystemVolumePresenter() + { + g_pSystemVolumePresenter = this; } - - SystemVolumePresenter::~SystemVolumePresenter(){ - + + SystemVolumePresenter::~SystemVolumePresenter() + { + g_pSystemVolumePresenter = nullptr; } - - SystemVolumePresenter *SystemVolumePresenter::GetInstance(){ - + + SystemVolumePresenter *SystemVolumePresenter::GetInstance() + { + return g_pSystemVolumePresenter; } - - void SystemVolumePresenter::OnStart(){ - - Presenter::OnStart(); + + void SystemVolumePresenter::OnStart() + { + + Presenter::OnStart(); } - - void SystemVolumePresenter::OnPause(void){ - + + void SystemVolumePresenter::OnPause(void) + { + Presenter::OnPause(); } - - void SystemVolumePresenter::OnResume(void){ - + + void SystemVolumePresenter::OnResume(void) + { + Presenter::OnResume(); } - - void SystemVolumePresenter::OnStop(void){ - - Presenter::OnStop(); + + void SystemVolumePresenter::OnStop(void) + { + + Presenter::OnStop(); } - - bool SystemVolumePresenter::OnDrag(UIView &view, const DragEvent &event){ - + + bool SystemVolumePresenter::OnDrag(UIView &view, const DragEvent &event) + { + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && (event.GetDeltaX() > 30) && (event.GetDeltaX() > (3 * MATH_ABS(event.GetDeltaY())))) { - //NativeAbility::GetInstance().ChangeSlice(VIEW_SOUND_VIBRATION); + // NativeAbility::GetInstance().ChangeSlice(VIEW_SOUND_VIBRATION); uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); NativeAbility::GetInstance().ChangeSlice(preSlice); } return true; } - - bool SystemVolumePresenter::OnClick(UIView &view, const ClickEvent &event){ - + + bool SystemVolumePresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 // if (strcmp(view.GetViewId(), 控件ID) == 0) // if(strcmp(view.GetViewId(), BRIGHTNESS_CONTROL_SLIDER)) // { - + // } return true; } -} + /* --------------------- VoumeProcessSliderEventListener -------------------- */ + constexpr int16_t VOLUMEVALUE_CHANGE = 10; + static VoumeProcessSliderEventListener *g_pVoumeProcessSliderEventListener{nullptr}; + VoumeProcessSliderEventListener::VoumeProcessSliderEventListener() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::VoumeProcessSliderEventListener"); + g_pVoumeProcessSliderEventListener = this; + } + VoumeProcessSliderEventListener::~VoumeProcessSliderEventListener() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::~VoumeProcessSliderEventListener"); + g_pVoumeProcessSliderEventListener = nullptr; + } + VoumeProcessSliderEventListener *VoumeProcessSliderEventListener::GetInstance(void) + { + return g_pVoumeProcessSliderEventListener; + } + void VoumeProcessSliderEventListener::ChangeVolumeValue(uint8_t status, uint8_t value) + { + + SoundAndVibrationVolumeSettingView *p_SoundAndVibrationVolumeSettingView = SoundAndVibrationVolumeSettingView::GetInstance(); + if (p_SoundAndVibrationVolumeSettingView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationVolumeSettingView GetInstance fail!!"); + return; + } + UISlider *progress = p_SoundAndVibrationVolumeSettingView->GetVolumeProcess(); + if (progress == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_SoundAndVibrationVolumeSettingView->GetVolumeProcess() fail"); + return; + } + + VolumeValue = p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue; + + switch (status) + { + case VOLUMEREDUCE: + /* code */ + p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue = progress->GetValue() - VOLUMEVALUE_CHANGE; + if (p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue < VOLUME_MIN) + { + p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue = VOLUME_MIN; + } + break; + case VOLUMEADD: + p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue = progress->GetValue() + VOLUMEVALUE_CHANGE; + if (p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue > VOLUME_MAX) + { + p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue = VOLUME_MAX; + } + break; + case OTHER: + p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue = value; + if (p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue < VOLUME_MIN) + { + p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue = VOLUME_MIN; + } + else if (p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue > VOLUME_MAX) + { + p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue = VOLUME_MAX; + } + break; + default: + break; + } + + progress->SetValue(p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue); + LocalVolumeSet(p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue); + } + + /* + * @brief 本地音量设置 + */ + void VoumeProcessSliderEventListener::LocalVolumeSet(int16_t sounding) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BtAndLocalVolumeSet %d", sounding); + Audio::AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, sounding); // 本地音量设置 + } + + void VoumeProcessSliderEventListener::OnChange(int32_t value) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnChange %d", value); + ChangeVolumeValue(OTHER, value); + } + + void VoumeProcessSliderEventListener::OnRelease(int32_t value) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnRelease %d", value); + ChangeVolumeValue(OTHER, value); + } + + bool VoumeProcessSliderEventListener::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + UNUSED(view); + return true; + } + + bool VoumeProcessSliderEventListener::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(event); + UNUSED(view); + return true; + } +} -- 2.17.1