From: luozheng <1732036298@qq.com> Date: Fri, 19 Apr 2024 12:46:23 +0000 (+0800) Subject: 添加通话音量和系统音量,并将其声音调整放进线程中 X-Git-Tag: release_V1.2.70_20241020_135402~1162^2~4 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=7301e97d27b2409836a8da62a201cf6b0f2bde7e;p=mirrors%2FFD230.git 添加通话音量和系统音量,并将其声音调整放进线程中 --- diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index 7d4794d36..73afedd13 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -76,6 +76,8 @@ #include "soundandvibration/include/SoundAndVibrationView.h" #include "soundandvibration/include/SystemVolumePresenter.h" #include "soundandvibration/include/SystemVolumeView.h" +#include "soundandvibration/include/CallVolumePresenter.h" +#include "soundandvibration/include/CallVolumeView.h" #include "displaybrightness/include/DisplayBrightnessPresenter.h" #include "displaybrightness/include/DisplayBrightnessView.h" @@ -261,6 +263,7 @@ namespace OHOS {VIEW_SYSTEM, &NativeLauncher::InitSystemSlice}, // 系统实例化地址 {VIEW_SOUND_VIBRATION, &NativeLauncher::InitSoundAndVibrationSlice}, // 声音与震动实例化地址 {VIEW_SYSTEM_VOLUME, &NativeLauncher::InitSystemVolumeSlice}, // 系统音量 + {VIEW_CALL_VOLUME, &NativeLauncher::InitCallVolumeSlice}, // 系统音量 {VIEW_CLASSIC_BLUETOOTH, &NativeLauncher::InitClassicBluetoothSlice}, // 经典蓝牙slice {VIEW_DISPLAY_BRIGHTNESS, &NativeLauncher::InitDisplayBrightnessSlice}, // 显示与亮度的实例化地址 {VIEW_SECONDARY_FUNCTION, &NativeLauncher::InitSecondaryFunction}, @@ -707,6 +710,17 @@ namespace OHOS NativeAbility::GetInstance().AddSliceProxy(VIEW_SYSTEM_VOLUME, systemvolume); } + void NativeLauncher::InitCallVolumeSlice(void) // 系统音量 + { + SliceProxy *callVolume = new AbilitySliceProxy; + if (callVolume == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "callVolume"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_CALL_VOLUME, callVolume); + } + // DisplayBrightness的实例化 void NativeLauncher::InitDisplayBrightnessSlice(void) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumePresenter.h b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumePresenter.h index e009bcc56..918a9e9b8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumePresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumePresenter.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-01-29 16:24:23 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-19 09:48:42 + * @LastEditTime: 2024-04-19 15:17:28 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumePresenter.h */ #ifndef CALL_VOLUME_PRESENTER_H @@ -63,6 +63,7 @@ namespace OHOS // 因为继承了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); bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumeView.h b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumeView.h index ab271c75c..14562a9ea 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumeView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumeView.h @@ -2,11 +2,11 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-01-29 15:37:44 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-19 09:41:56 + * @LastEditTime: 2024-04-19 15:11:50 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumeView.h */ -#ifndef SYSTEM_VOLUME_VIEW_H -#define SYSTEM_VOLUME_VIEW_H +#ifndef CALL_VOLUME_VIEW_H +#define CALL_VOLUME_VIEW_H #include "BaseView.h" #include "View.h" @@ -14,7 +14,6 @@ #include "soundandvibration/include/SoundAndVibrationVolumeSettingView.h" namespace OHOS { - static const char *SYSTEM_VOLUME_SLIDER = "CallVolumeSlider"; class SoundAndVibrationVolumeSettingView; class CallVolumePresenter; diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingC.h b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingC.h new file mode 100644 index 000000000..0c0648612 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingC.h @@ -0,0 +1,27 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-19 18:59:49 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-19 19:08:01 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingC.h + */ +#ifndef SOUND_AND_VIBRATION_VOLUME_SETTINGC_H +#define SOUND_AND_VIBRATION_VOLUME_SETTINGC_H + +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif +#endif +#include + + void SystemVolumeSet(int16_t sounding); + void CallVolumeSet(int16_t sounding); + +#ifdef __cplusplus +#if __cplusplus +} +#endif +#endif +#endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h index aad267d17..30eb50fe7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h @@ -2,13 +2,16 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-19 10:08:21 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-19 10:22:53 + * @LastEditTime: 2024-04-19 19:01:46 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h */ #ifndef SOUND_AND_VIBRATION_VOLUME_SETTING_PRESENTER_H #define SOUND_AND_VIBRATION_VOLUME_SETTING_PRESENTER_H #include #include "components/ui_slider.h" +#include "soundandvibration/include/SoundAndVibrationVolumeSettingView.h" +#include "map" +#include "memory" namespace OHOS { typedef enum : uint8_t @@ -18,6 +21,15 @@ namespace OHOS OTHER = 2, // 其他 } VolumeStatusChange; + // 步骤 1: 定义策略接口.定义一个策略接口,所有的声音调整策略都需要实现这个接口 + class SoundAndVibrationVolumeSettingView; + class VolumeChangeStrategy + { + public: + virtual void ApplyChange(SoundAndVibrationVolumeSettingView *view, UISlider *slider, uint8_t value) = 0; + virtual ~VolumeChangeStrategy() = default; + }; + /* * @brief 声音进度条的事件监听类 */ @@ -30,15 +42,13 @@ namespace OHOS ~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; // 声音值 - uint8_t m_VolumeType; + std::map> strategyMap; }; } 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 bd17b2e0b..04f2fdaeb 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-01-29 15:41:49 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-19 10:40:30 + * @LastEditTime: 2024-04-19 15:22:04 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingView.h */ #ifndef SOUND_AND_VIBRATION_VOLUME_SETTING_H @@ -37,6 +37,7 @@ namespace OHOS UIScrollView *SetUpVolumeProcess(void); void ClearAll(void); UISlider *GetVolumeProcess(void); + int GetVolumeType(void); int CurrentVolumeValue{0}; private: 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 9e802cc3d..b8b70dadf 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumeView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumeView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-01-29 15:37:44 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-19 10:17:28 + * @LastEditTime: 2024-04-19 15:11:54 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumeView.h */ #ifndef SYSTEM_VOLUME_VIEW_H @@ -14,7 +14,6 @@ #include "soundandvibration/include/SoundAndVibrationVolumeSettingView.h" namespace OHOS { - static const char *SYSTEM_VOLUME_SLIDER = "SystemVolumeSlider"; class SoundAndVibrationVolumeSettingView; class SystemVolumePresenter; diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumePresenter.cpp index 748e8adbd..04b36061b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumePresenter.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-30 09:14:38 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-19 10:24:13 + * @LastEditTime: 2024-04-19 15:17:16 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumePresenter.cpp */ #include "AppViewIDs.h" @@ -67,6 +67,7 @@ namespace OHOS bool CallVolumePresenter::OnDrag(UIView &view, const DragEvent &event) { UNUSED(view); + UNUSED(event); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) { @@ -75,6 +76,17 @@ namespace OHOS return true; } + bool CallVolumePresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationPresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + { + NativeAbility::GetInstance().Back(); + } + return true; + } + bool CallVolumePresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 { UNUSED(view); diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumeView.cpp b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumeView.cpp index fb3443725..1f3221933 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumeView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumeView.cpp @@ -2,6 +2,8 @@ #include "soundandvibration/include/CallVolumePresenter.h" #include "wearable_log.h" #include +#include "phoneservice/include/PhoneAudio.h" +#include "phoneservice/include/PhoneService.h" namespace OHOS { @@ -63,8 +65,10 @@ namespace OHOS return nullptr; } - p_SoundAndVibrationVolumeSettingView->GetVolumeProcess()->SetValue(Audio::AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC)); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Audio::AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC) = %d",Audio::AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC)); + // p_SoundAndVibrationVolumeSettingView->GetVolumeProcess()->SetValue(PhoneAudioGetVolume()); + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallVolume = %d", PhoneAudioGetVolume()); + p_SoundAndVibrationVolumeSettingView->GetVolumeProcess()->SetValue(GetCallCurrVolume()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallVolume = %d", GetCallCurrVolume()); initViewStatus = true; return CallVolumeScrollView; @@ -73,7 +77,7 @@ namespace OHOS void CallVolumeView::OnStart() { View::OnStart(); - + CallVolumeViewInit(); RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::CallVolumePresenter::GetInstance(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp index 8e5caf0e2..a6eac7657 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-02-19 10:39:11 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-19 14:53:16 + * @LastEditTime: 2024-04-19 15:10:49 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp */ @@ -124,7 +124,7 @@ namespace OHOS } else if (strcmp(view.GetViewId(), CALL_VOLUME_BUTTON) == 0) { - NativeAbility::GetInstance().EnterSlice(VIEW_SYSTEM_VOLUME); + NativeAbility::GetInstance().EnterSlice(VIEW_CALL_VOLUME); } else if (strcmp(view.GetViewId(), VIBRATION_REMINDER_BUTTON) == 0) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp index 094bca637..5752ebfb1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp @@ -2,23 +2,92 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-19 10:08:31 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-19 10:14:03 + * @LastEditTime: 2024-04-19 19:01:17 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp */ #include "soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h" -#include "soundandvibration/include/SoundAndVibrationVolumeSettingView.h" +#include "soundandvibration/include/SoundAndVibrationVolumeSettingC.h" #include "wearable_log.h" #include +#include +#include "phoneservice/include/PhoneAudio.h" +#include "phoneservice/include/PhoneService.h" namespace OHOS { - /* --------------------- VoumeProcessSliderEventListener -------------------- */ - constexpr int16_t VOLUMEVALUE_CHANGE = 10; + static constexpr int16_t VOLUMEVALUE_CHANGE = 10; + // 步骤 2: 实现具体的策略 + class LowerVolumeStrategy : public VolumeChangeStrategy + { + public: + void ApplyChange(SoundAndVibrationVolumeSettingView *view, UISlider *slider, uint8_t value) override + { + uint16_t newVolumeValue = slider->GetValue() - VOLUMEVALUE_CHANGE; + if (newVolumeValue < VOLUME_MIN) + { + newVolumeValue = VOLUME_MIN; + } + if (view->GetVolumeType() == SYSTEM_VOLUME) + { + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_SYSTEM_VOLUME, (void *)(value), sizeof(value)); + } + else if (view->GetVolumeType() == CALL_VOLUME) + { + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_CALL_VOLUME, (void *)(value), sizeof(value)); + } + slider->SetValue(newVolumeValue); + } + }; + + class ElevateVolumeStrategy : public VolumeChangeStrategy + { + public: + void ApplyChange(SoundAndVibrationVolumeSettingView *view, UISlider *slider, uint8_t value) override + { + uint16_t newVolumeValue = slider->GetValue() + VOLUMEVALUE_CHANGE; + if (newVolumeValue > VOLUME_MAX) + { + newVolumeValue = VOLUME_MAX; + } + if (view->GetVolumeType() == SYSTEM_VOLUME) + { + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_SYSTEM_VOLUME, (void *)(value), sizeof(value)); + } + else if (view->GetVolumeType() == CALL_VOLUME) + { + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_CALL_VOLUME, (void *)(value), sizeof(value)); + } + slider->SetValue(newVolumeValue); + } + }; + class DragVolumeStrategy : public VolumeChangeStrategy + { + public: + void ApplyChange(SoundAndVibrationVolumeSettingView *view, UISlider *slider, uint8_t value) override + { + if (view->GetVolumeType() == SYSTEM_VOLUME) + { + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_SYSTEM_VOLUME, (void *)(value), sizeof(value)); + } + else if (view->GetVolumeType() == CALL_VOLUME) + { + + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_CALL_VOLUME, (void *)(value), sizeof(value)); + } + slider->SetValue(value); + } + }; + + /* --------------------- VoumeProcessSliderEventListener -------------------- */ static VoumeProcessSliderEventListener *g_pVoumeProcessSliderEventListener{nullptr}; VoumeProcessSliderEventListener::VoumeProcessSliderEventListener() { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::VoumeProcessSliderEventListener"); + // 步骤 3: 创建一个映射表将状态映射到策略 + strategyMap[VOLUMEREDUCE] = std::make_shared(); + strategyMap[VOLUMEADD] = std::make_shared(); + strategyMap[OTHER] = std::make_shared(); g_pVoumeProcessSliderEventListener = this; } @@ -35,70 +104,21 @@ namespace OHOS 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) + auto it = strategyMap.find(status); + if (it != strategyMap.end()) { - case VOLUMEREDUCE: - /* code */ - p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue = progress->GetValue() - VOLUMEVALUE_CHANGE; - if (p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue < VOLUME_MIN) + SoundAndVibrationVolumeSettingView *view = SoundAndVibrationVolumeSettingView::GetInstance(); + UISlider *slider = view ? view->GetVolumeProcess() : nullptr; + if (view && slider) { - p_SoundAndVibrationVolumeSettingView->CurrentVolumeValue = VOLUME_MIN; + it->second->ApplyChange(view, slider, value); } - 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, "LocalVolumeSet %d", sounding); - Audio::AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, sounding); // 本地音量设置 } void VoumeProcessSliderEventListener::OnChange(int32_t value) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnChange %d", value); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnChange %d", value); ChangeVolumeValue(OTHER, value); } @@ -121,5 +141,35 @@ namespace OHOS UNUSED(view); return true; } +} +#ifdef __cplusplus +#if __cplusplus +extern "C" +{ +#endif /* __cplusplus */ +#endif /* __cplusplus */ + + /* + * @brief 系统音量设置 + */ + void SystemVolumeSet(int16_t sounding) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemVolumeSet %d", sounding); + Audio::AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, sounding); // 系统音量设置 + } + + /* + * @brief 通话音量设置 + */ + void CallVolumeSet(int16_t sounding) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallVolumeSet %d", sounding); + // PhoneAudioSetVolume(sounding); // 通话音量音量设置 + SetSpeakerVolume(sounding); + } -} \ No newline at end of file +#ifdef __cplusplus +#if __cplusplus +} +#endif /* __cplusplus */ +#endif /* __cplusplus */ \ No newline at end of file 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 b2c110645..4b99b238a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingView.cpp @@ -8,7 +8,7 @@ namespace OHOS SoundAndVibrationVolumeSettingView::SoundAndVibrationVolumeSettingView(uint8_t VolumeType) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationVolumeSettingView::SoundAndVibrationVolumeSettingView,VolumeType = %d",VolumeType); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationVolumeSettingView::SoundAndVibrationVolumeSettingView,VolumeType = %d", VolumeType); m_VolumeType = VolumeType; g_pSoundAndVibrationVolumeSettingView = this; } @@ -53,6 +53,15 @@ namespace OHOS return VolumeProcess; } + /* + * @brief 获取声音类型 + * @return 返回 0 系统音量,返回 1 通话音量 + */ + int SoundAndVibrationVolumeSettingView::GetVolumeType(void) + { + return m_VolumeType; + } + UIScrollView *SoundAndVibrationVolumeSettingView::SetUpVolumeProcess(void) { ScrollView = new UIScrollView(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumeView.cpp b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumeView.cpp index c5fab2050..038860f4d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumeView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumeView.cpp @@ -68,8 +68,8 @@ namespace OHOS } p_SoundAndVibrationVolumeSettingView->GetVolumeProcess()->SetValue(Audio::AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC)); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Audio::AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC) = %d", Audio::AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC)); - + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemVolume = %d", Audio::AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC)); + initViewStatus = true; return SystemVolumeScrollView; } diff --git a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ctl.cpp b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ctl.cpp index 984ee9c45..8b1fa5e02 100644 --- a/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ctl.cpp +++ b/code/sdk/drivers/peripheral/slip/cat1Service/cat1_ctl.cpp @@ -104,7 +104,7 @@ void cat1_ring_isr_callback(pin_t pin, uintptr_t param) { WEARABLE_LOGW(WEARABLE_LOG_MODULE_MAIN_SERVICE,"cat1_ring_isr_callback %d 0x%X\n",pin,param); uapi_cat1_add_cat1_vote(); - do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_REMOVE_CAT1VOTE); + do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_REMOVE_CAT1VOTE,NULL,0); } void uapi_cat1_wakeup_cat1(uint8_t wakeup) diff --git a/code/sdk/drivers/peripheral/utils/custom_cmd_service.c b/code/sdk/drivers/peripheral/utils/custom_cmd_service.c index 6574e81a8..3110e1cb3 100644 --- a/code/sdk/drivers/peripheral/utils/custom_cmd_service.c +++ b/code/sdk/drivers/peripheral/utils/custom_cmd_service.c @@ -34,7 +34,7 @@ typedef struct { uint8_t cmd; - // uint8_t data[2]; + uint8_t data[50]; } custom_cmd_cmd_t; /*** * 其他cmd在Header里定义,对外开放 @@ -43,18 +43,28 @@ typedef struct static bool g_bat_timer_is_running = false; static unsigned long g_custom_cmd_queue; - - static bool custom_cmd_service_running_stat = false; -void do_custom_cmd_service_check_msg(int cmd) +void do_custom_cmd_service_check_msg(int cmd, void *params, int paramlen) { int ret; + // 检查参数长度是否合法 + if (paramlen > sizeof(custom_cmd_cmd_t) - sizeof(uint8_t)) + { + PRINT("Error: 参数长度超过最大限制! \r\n"); + return; + } + custom_cmd_cmd_t mail = {0}; - mail.cmd = cmd; - // mail.data[0] = data[0]; - // mail.data[1] = data[1]; + mail.cmd = (uint8_t)cmd; + + // 将参数数据复制到结构体中 + if (params && paramlen > 0) + { + memcpy(mail.data, params, paramlen); + } + ret = osal_msg_queue_write_copy(g_custom_cmd_queue, (void *)&mail, sizeof(custom_cmd_cmd_t), 0); if (ret != OSAL_SUCCESS) { @@ -64,12 +74,12 @@ void do_custom_cmd_service_check_msg(int cmd) static void custom_cmd_service_check_task(void const *arg) { - unused(arg); + int32_t ret; custom_cmd_cmd_t mail; uint32_t msgsize = (uint32_t)sizeof(custom_cmd_cmd_t); custom_cmd_service_running_stat = true; - + while (1) { ret = osal_msg_queue_read_copy(g_custom_cmd_queue, (void *)&mail, &msgsize, @@ -79,14 +89,24 @@ static void custom_cmd_service_check_task(void const *arg) continue; } - if (mail.cmd == CUSTOM_CMD_MSG_TYPE_REMOVE_CAT1VOTE) + // 根据邮件中的命令进行相应的处理 + switch (mail.cmd) { + case CUSTOM_CMD_MSG_TYPE_REMOVE_CAT1VOTE: restart_sleep_cat1_timer(); + break; + case CUSTOM_CMD_MSG_TYPE_CHANGE_SYSTEM_VOLUME: + //printf("mail.data: %d\n", *mail.data); + uapi_systemVolumeSet(mail.data); + break; + case CUSTOM_CMD_MSG_TYPE_CHANGE_CALL_VOLUME: + //printf("mail.data: %d\n", *mail.data); + uapi_callVolumeSet(mail.data); + break; + default: + PRINT("Unknown CUSTOM_CMD_MSG cmd 0x%02X \r\n", mail.cmd); + break; } - else - { - PRINT("unknown CUSTOM_CMD_MSG cmd 0x%2X \r\n",mail.cmd); - } } } #define CUSTOM_CMD_APP_BOARD_MSG_COUNT 10 diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 76a18277e..71207dd6d 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -23,6 +23,7 @@ #include "errcode.h" #include "power_display_service.h" #include "config/include/ConfigModelC.h" +#include "soundandvibration/include/SoundAndVibrationVolumeSettingC.h" #define SUPPORT_NV @@ -602,6 +603,18 @@ int32_t uapi_get_screen_state(void) return display_api->get_screen_state(); } +/*系统声音设置*/ +void uapi_systemVolumeSet(int16_t sounding) +{ + SystemVolumeSet(sounding); +} + +//通话音量设置 +void uapi_callVolumeSet(int16_t sounding) +{ + CallVolumeSet(sounding); +} + #include "bts_le_gap.h" diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index 606da3ab1..38d084202 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -57,6 +57,9 @@ void uapi_setScreenDuration(int32_t time); int32_t uapi_get_screen_state(void); +void uapi_systemVolumeSet(int16_t sounding); +void uapi_callVolumeSet(int16_t sounding); + errcode_t uapi_get_btaddr(uint8_t *buf_btaddr, uint32_t *len_btaddr); errcode_t uapi_get_btname(uint8_t *buf_btname, uint32_t *len_btname); errcode_t uapi_get_nv_btaddr(uint8_t *buf_btaddr, uint32_t *len_btaddr); @@ -133,8 +136,10 @@ uint32_t uapi_calendar_store_date(void); #define CUSTOM_CMD_MSG_TYPE_REMOVE_CAT1VOTE 0x01 +#define CUSTOM_CMD_MSG_TYPE_CHANGE_SYSTEM_VOLUME 0x02 +#define CUSTOM_CMD_MSG_TYPE_CHANGE_CALL_VOLUME 0x03 errcode_t uapi_custom_cmd_service_init(void); -void do_custom_cmd_service_check_msg(int cmd); +void do_custom_cmd_service_check_msg(int cmd, void *params, int paramlen); #ifdef __cplusplus }