2 * @Author: luozheng 1732036298@qq.com
3 * @Date: 2024-04-19 10:08:31
4 * @LastEditors: luozheng 1732036298@qq.com
5 * @LastEditTime: 2024-09-13 18:31:03
6 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp
8 #include "soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h"
9 #include "soundandvibration/include/SoundAndVibrationVolumeSettingC.h"
10 #include "wearable_log.h"
11 #include <audio_manager.h>
12 #include <custom_utils.h>
13 #include "phoneservice/include/PhoneAudio.h"
14 #include "phoneservice/include/PhoneService.h"
15 #include "../../../../../../middleware/services/media/foundation/audiomanager/frameworks/audioservice/include/audio_service.h"
16 #include "vibrator_service.h"
17 #include "ConfigModel.h"
22 static constexpr int16_t VOLUMEVALUE_CHANGE = 10;
24 class LowerVolumeStrategy : public VolumeChangeStrategy
27 void ApplyChange(SoundAndVibrationVolumeSettingView *view, UISlider *slider, int32_t value) override
29 uint16_t newVolumeValue = slider->GetValue() - VOLUMEVALUE_CHANGE;
30 if (newVolumeValue < VOLUME_MIN)
32 newVolumeValue = VOLUME_MIN;
34 if (view->GetVolumeType() == SYSTEM_VOLUME)
36 do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_SYSTEM_VOLUME, (void *)(&value), sizeof(value));
38 else if (view->GetVolumeType() == CALL_VOLUME)
40 do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_CALL_VOLUME, (void *)(&value), sizeof(value));
42 slider->SetValue(newVolumeValue);
46 class ElevateVolumeStrategy : public VolumeChangeStrategy
49 void ApplyChange(SoundAndVibrationVolumeSettingView *view, UISlider *slider, int32_t value) override
51 uint16_t newVolumeValue = slider->GetValue() + VOLUMEVALUE_CHANGE;
52 if (newVolumeValue > VOLUME_MAX)
54 newVolumeValue = VOLUME_MAX;
56 if (view->GetVolumeType() == SYSTEM_VOLUME)
58 do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_SYSTEM_VOLUME, (void *)(&value), sizeof(value));
60 else if (view->GetVolumeType() == CALL_VOLUME)
62 do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_CALL_VOLUME, (void *)(&value), sizeof(value));
64 slider->SetValue(newVolumeValue);
68 class DragVolumeStrategy : public VolumeChangeStrategy
71 void ApplyChange(SoundAndVibrationVolumeSettingView *view, UISlider *slider, int32_t value) override
73 if (view->GetVolumeType() == SYSTEM_VOLUME)
75 do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_SYSTEM_VOLUME, (void *)(&value), sizeof(value));
77 else if (view->GetVolumeType() == CALL_VOLUME)
80 do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_CALL_VOLUME, (void *)(&value), sizeof(value));
82 slider->SetValue(value);
86 /* --------------------- VoumeProcessSliderEventListener -------------------- */
87 static VoumeProcessSliderEventListener *g_pVoumeProcessSliderEventListener{nullptr};
88 VoumeProcessSliderEventListener::VoumeProcessSliderEventListener()
90 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::VoumeProcessSliderEventListener");
91 // 步骤 3: 创建一个映射表将状态映射到策略
92 strategyMap[VOLUMEREDUCE] = std::make_shared<LowerVolumeStrategy>();
93 strategyMap[VOLUMEADD] = std::make_shared<ElevateVolumeStrategy>();
94 strategyMap[OTHER] = std::make_shared<DragVolumeStrategy>();
95 g_pVoumeProcessSliderEventListener = this;
98 VoumeProcessSliderEventListener::~VoumeProcessSliderEventListener()
100 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::~VoumeProcessSliderEventListener");
101 g_pVoumeProcessSliderEventListener = nullptr;
104 VoumeProcessSliderEventListener *VoumeProcessSliderEventListener::GetInstance(void)
106 return g_pVoumeProcessSliderEventListener;
109 void VoumeProcessSliderEventListener::FindAndApplyStrategy(uint8_t status, int32_t value)
111 auto it = strategyMap.find(status);
112 if (it != strategyMap.end())
114 SoundAndVibrationVolumeSettingView *view = SoundAndVibrationVolumeSettingView::GetInstance();
115 UISlider *slider = view ? view->GetVolumeProcess() : nullptr;
118 it->second->ApplyChange(view, slider, value);
123 void VoumeProcessSliderEventListener::ChangeVolumeValue(uint8_t status, int32_t value)
125 FindAndApplyStrategy(status, value);
129 void VoumeProcessSliderEventListener::OnChange(int32_t value)
131 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnChange %d", value);
132 if (isOnClickSlider && !isDragSlider && !isRotateSlider)
134 ChangeVolumeValue(OTHER, value);
139 void VoumeProcessSliderEventListener::OnRelease(int32_t value)
141 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnRelease %d", value);
142 ChangeVolumeValue(OTHER, value);
146 bool VoumeProcessSliderEventListener::OnClick(UIView &view, const ClickEvent &event)
149 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::OnClick");
150 UISlider *slider = dynamic_cast<UISlider *>(&view);
151 SoundAndVibrationVolumeSettingView *soundAndVibrationVolumeSettingView = SoundAndVibrationVolumeSettingView::GetInstance();
152 if (slider != nullptr && soundAndVibrationVolumeSettingView != nullptr)
154 if (slider == soundAndVibrationVolumeSettingView->GetVolumeProcess())
156 isOnClickSlider = true;
157 isDragSlider = false;
158 isRotateSlider = false;
165 bool VoumeProcessSliderEventListener::OnDrag(UIView &view, const DragEvent &event)
168 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::OnDrag");
169 UISlider *slider = dynamic_cast<UISlider *>(&view);
170 SoundAndVibrationVolumeSettingView *soundAndVibrationVolumeSettingView = SoundAndVibrationVolumeSettingView::GetInstance();
171 if (slider != nullptr && soundAndVibrationVolumeSettingView != nullptr)
173 if (slider == soundAndVibrationVolumeSettingView->GetVolumeProcess())
175 isOnClickSlider = false;
177 isRotateSlider = false;
184 bool VoumeProcessSliderEventListener::OnRotateEnd(UIView &view, const RotateEvent &event)
186 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::OnRotateEnd");
187 UISlider *slider = dynamic_cast<UISlider *>(&view);
188 SoundAndVibrationVolumeSettingView *soundAndVibrationVolumeSettingView = SoundAndVibrationVolumeSettingView::GetInstance();
189 if (slider != nullptr && soundAndVibrationVolumeSettingView != nullptr)
191 if (slider == soundAndVibrationVolumeSettingView->GetVolumeProcess())
193 isDragSlider = false;
194 isOnClickSlider = false;
195 isRotateSlider = true;
197 int value = slider->GetValue();
198 ChangeVolumeValue(OTHER, value);
208 #endif /* __cplusplus */
209 #endif /* __cplusplus */
211 extern void custom_VibratorFunc_int(int vibratorType);
215 void SystemVolumeSet(int32_t sounding)
217 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemVolumeSet %d", sounding);
218 Audio::AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, sounding); // 系统音量设置
221 int SystemVolumeGet(void)
223 return Audio::AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC);
229 void CallVolumeSet(int32_t sounding)
231 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallVolumeSet %d", sounding);
232 // Audio::AudioManager::GetInstance().SetVolume(AUDIO_STREAM_VOICE_CALL_BT_SCO, sounding); // 通话音量设置
233 // Audio::AudioManager::GetInstance().SetVolume(AUDIO_STREAM_VOICE_CALL_VOLTE, sounding); // 通话音量设置
234 set_speaker_volume(sounding,AUDIO_STREAM_VOICE_CALL_BT_SCO);
235 set_speaker_volume(sounding,AUDIO_STREAM_VOICE_CALL_VOLTE);
238 int CallVolumeGet(void)
240 // return Audio::AudioManager::GetInstance().GetVolume(AUDIO_STREAM_VOICE_CALL_BT_SCO);
241 return GetCallCurrVolume();
247 void SilentModelSet(bool isopen)
249 AudioServiceSetMasterMute(isopen);
254 #endif /* __cplusplus */
255 #endif /* __cplusplus */