From: luozheng <1732036298@qq.com> Date: Fri, 19 Apr 2024 07:06:03 +0000 (+0800) Subject: 优化声音与设置视图 X-Git-Tag: release_V1.2.70_20241020_135402~1162^2~6 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=54b857be710e0a7f9e3be3eb12b1f8c582134909;p=mirrors%2FFD230.git 优化声音与设置视图 --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index bdad07ba9..9c504b9d6 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -355,12 +355,11 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/soundandvibration/src/SoundAndVibrationView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/soundandvibration/src/SoundAndVibrationModel.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/soundandvibration/src/SystemVolumePresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/soundandvibration/src/SystemVolumeView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/soundandvibration/src/CallVolumePresenter.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/soundandvibration/src/CallVolumeView.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/soundandvibration/src/MediaVolumePresenter.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/soundandvibration/src/MediaVolumeView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/soundandvibration/src/CallVolumeView.cpp #显示与亮度 ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/displaybrightness/src/DisplayBrightnessModel.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index 40775edee..0219c80d3 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -47,7 +47,6 @@ typedef enum : uint16_t VIEW_SOUND_VIBRATION, // 声音与震动 VIEW_SYSTEM_VOLUME, // 系统音量 VIEW_CALL_VOLUME, // 通话音量 - VIEW_MEDIA_VOLUME, // 媒体音量 VIEW_DISPLAY_BRIGHTNESS, // 屏幕与亮度 VIEW_SECONDARY_FUNCTION, // 辅助功能 VIEW_FAST_TRAINING, // 快速训练 diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index 8abf4e203..7d4794d36 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -690,6 +690,7 @@ namespace OHOS SliceProxy *SoundAndVibration = new AbilitySliceProxy; if (SoundAndVibration == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibration"); return; } NativeAbility::GetInstance().AddSliceProxy(VIEW_SOUND_VIBRATION, SoundAndVibration); @@ -700,6 +701,7 @@ namespace OHOS SliceProxy *systemvolume = new AbilitySliceProxy; if (systemvolume == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "systemvolume"); return; } NativeAbility::GetInstance().AddSliceProxy(VIEW_SYSTEM_VOLUME, systemvolume); diff --git a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingVolumeSettingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingVolumeSettingView.cpp index 5c08bd8d9..83c9b4bf2 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingVolumeSettingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingVolumeSettingView.cpp @@ -1,3 +1,10 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-13 17:38:18 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-19 15:02:48 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/record/src/RecordingVolumeSettingView.cpp + */ #include "record/include/RecordingVolumeSettingView.h" #include "record/include/RecordingPresenter.h" @@ -39,7 +46,7 @@ namespace OHOS UIScrollView *RecordingVolumeSettingView::RecordingVolumeSettingViewInit(void) { - p_SoundAndVibrationVolumeSettingView = new SoundAndVibrationVolumeSettingView(); + p_SoundAndVibrationVolumeSettingView = new SoundAndVibrationVolumeSettingView(SYSTEM_VOLUME); if (p_SoundAndVibrationVolumeSettingView == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_SoundAndVibrationVolumeSettingView nullptr err"); 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 a53ad4430..e009bcc56 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumePresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumePresenter.h @@ -1,3 +1,10 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 16:24:23 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-19 09:48:42 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumePresenter.h + */ #ifndef CALL_VOLUME_PRESENTER_H #define CALL_VOLUME_PRESENTER_H @@ -6,11 +13,40 @@ namespace OHOS { - class CallVolumeView; + 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 CallVolumeView; class CallVolumePresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener + public UIView::OnClickListener, + public RootView::OnKeyActListener, + public UIView::OnDragListener { public: CallVolumePresenter(); @@ -27,6 +63,7 @@ namespace OHOS // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView &view, const DragEvent &event) override; + 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 501bac093..ab271c75c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumeView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumeView.h @@ -1,16 +1,22 @@ -#ifndef CALL_VOLUME_VIEW_H -#define CALL_VOLUME_VIEW_H +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-19 09:41:56 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/CallVolumeView.h + */ +#ifndef SYSTEM_VOLUME_VIEW_H +#define SYSTEM_VOLUME_VIEW_H #include "BaseView.h" #include "View.h" - -#include "components/ui_view_group.h" -#include "components/ui_slider.h" -#include "components/ui_image_view.h" +#include "components/ui_scroll_view.h" +#include "soundandvibration/include/SoundAndVibrationVolumeSettingView.h" namespace OHOS { - static const char *CALL_VOLUME_SLIDER = "CallVolumeSlider"; + static const char *SYSTEM_VOLUME_SLIDER = "CallVolumeSlider"; + class SoundAndVibrationVolumeSettingView; class CallVolumePresenter; class CallVolumeView : public View { @@ -25,15 +31,14 @@ namespace OHOS void OnTearDownView() override; void OnStop() override; - private: - UIView::OnDragListener *draglistener{nullptr}; - UIView::OnClickListener *sliderClick{nullptr}; - UIView::OnDragListener *sliderDrag{nullptr}; - void InitView(void); + UIScrollView *CallVolumeViewInit(void); + void ClearAll(); - UIViewGroup *container_ = nullptr; - UISlider *CallVolumeslider = nullptr; - UIImageView *CallVolumeimageicon = nullptr; + private: + UIScrollView *CallVolumeScrollView{nullptr}; + SoundAndVibrationVolumeSettingView *p_SoundAndVibrationVolumeSettingView{nullptr}; + UIView::OnDragListener *volumeDragListener{nullptr}; + bool initViewStatus{false}; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/MediaVolumePresenter.h b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/MediaVolumePresenter.h deleted file mode 100644 index fb7f05916..000000000 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/MediaVolumePresenter.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef MEDIA_VOLUME_PRESENTER_H -#define MEDIA_VOLUME_PRESENTER_H - -#include "Presenter.h" -#include "MediaVolumeView.h" - -namespace OHOS -{ - class MediaVolumeView; - - class MediaVolumePresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener - { - public: - MediaVolumePresenter(); - virtual ~MediaVolumePresenter(); - - void OnStart() override; - void OnPause() override; - void OnResume() override; - void OnStop() override; - - static MediaVolumePresenter *GetInstance(); - - private: - // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; - bool OnClick(UIView &view, const ClickEvent &event) override; - bool OnDrag(UIView &view, const DragEvent &event) override; - }; -} // namespace OHOS - -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/MediaVolumeView.h b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/MediaVolumeView.h deleted file mode 100644 index 210b93daf..000000000 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/MediaVolumeView.h +++ /dev/null @@ -1,40 +0,0 @@ -#ifndef MEDIA_VOLUME_VIEW_H -#define MEDIA_VOLUME_VIEW_H - -#include "BaseView.h" -#include "View.h" - -#include "components/ui_view_group.h" -#include "components/ui_slider.h" -#include "components/ui_image_view.h" -namespace OHOS -{ - static const char *MEDIA_VOLUME_SLIDER = "MediaVolumeSlider"; - - class MediaVolumePresenter; - class MediaVolumeView : public View - { - - public: - MediaVolumeView(); - virtual ~MediaVolumeView(); - static MediaVolumeView *GetInstance(void); - - void OnStart() override; - void OnSetUpView() override; - void OnTearDownView() override; - void OnStop() override; - - private: - UIView::OnDragListener *draglistener{nullptr}; - UIView::OnClickListener *sliderClick{nullptr}; - UIView::OnDragListener *sliderDrag{nullptr}; - void InitView(void); - - UIViewGroup *container_ = nullptr; - UISlider *MediaVolumeslider = nullptr; - UIImageView *MediaVolumeimageicon = nullptr; - }; -} // namespace OHOS - -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationView.h b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationView.h index ad40dc3d4..5bdef0ae1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationView.h @@ -4,54 +4,30 @@ #include "BaseView.h" #include "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_image_view.h" +#include "components/ui_label_button_ext.h" #include "components/ui_toggle_button.h" #include "iostream" namespace OHOS { - /* ----------------------------------- 图片 ----------------------------------- */ - static constexpr const char *PNG_SYSTEM_VOLUME_IMAGE = "/user/res/SoundAndVibration/SYSTEM_VOLUME.bin"; // 系统音量图片 - static constexpr const char *PNG_CALL_VOLUME_IMAGE = "/user/res/SoundAndVibration/CALL_VOLUME.bin"; // 通话音量图片 - static constexpr const char *PNG_MEDIA_VOLUME_IMAGE = "/user/res/SoundAndVibration/MEDIA_VOLUME.bin"; // 媒体音量图片 /* ---------------------------------- 组件ID ---------------------------------- */ - static const char *SYSTEM_VOLUME_BUTTON = "SystemVolumeButton"; // 系统音量按钮ID - static const char *CALL_VOLUME_BUTTON = "CallVolumeButton"; // 通话音量按钮ID - static const char *VIBRATION_REMINDER_BUTTON = "VibrationReminderButton"; // 震动模式按钮ID + static constexpr const char *SYSTEM_VOLUME_BUTTON = "SystemVolumeButton"; // 系统音量按钮ID + static constexpr const char *CALL_VOLUME_BUTTON = "CallVolumeButton"; // 通话音量按钮ID + static constexpr const char *VIBRATION_REMINDER_BUTTON = "VibrationReminderButton"; // 震动模式按钮ID + static constexpr const char *SILENT_MODE_BUTTON = "SilentModeButton"; // 静音模式按钮ID class SoundAndVibrationPresenter; class SoundAndVibrationView : public View { public: - struct ImageConfig - { - int16_t x; - int16_t y; - int16_t w; - int16_t h; - const char *ImageSrc; - }; - struct LabelConfig - { - int16_t left; - int16_t top; - int16_t width; - int16_t height; - int16_t fontSize; // 字体大小 - int16_t lineHeigh; // 行高 - std::string text; // 文本 - uint8_t lineBreakMode; // 断行模式。 - }; struct ButtonConfig { int16_t x; int16_t y; int16_t w; int16_t h; - const char *ViewId; - int64_t BackgroundColorValue; // 按钮背景颜色值 + const char * ViewId; + std::string Text; }; SoundAndVibrationView(); virtual ~SoundAndVibrationView(); @@ -69,33 +45,20 @@ namespace OHOS private: void InitView(void); void ClearAll(void); - UIButton *SetUpButton(ButtonConfig &buttonconfig, UIView::OnClickListener *clickListener); - UIImageView *SetUpImageVIew(ImageConfig &imageconfig); - UILabelExt *SetUpLabel(LabelConfig &labelConfig); + UILabelButtonExt *SetUpButton_Ext(ButtonConfig &buttonconfig, bool nextImgVisible); bool InitSoundAndVibrationScrollView(void); bool InitSoundAndVibrationViewTitleLabel(void); bool InitSoundAndVibrationButtonView(void); - bool SetUpButtonAndCheck(const char *viewId, int x, int y, UIButton *&button, UIView::OnClickListener *listener); - bool InitSoundAndVibrationImageView(void); - bool InitSoundAndVibrationLabel(void); bool InitSoundAndVibrationToggleButton(void); private: UIScrollView *SoundAndVibrationScrollView{nullptr}; - UILabelExt *Title{nullptr}; // 标题:“声音与震动” - UIButton *SystemVolumeButton{nullptr}; // 系统音量按钮 - UIButton *CallVolumeButton{nullptr}; // 通话音量按钮 - UIButton *VibrationReminderButton{nullptr}; // 震动提醒按钮 - UILabelExt *SystemVolumeLabel{nullptr}; // 系统音量标签 - UILabelExt *CallVolumeLabel{nullptr}; // 通话音量标签 - UILabelExt *VibrationReminderLabel{nullptr}; // 震动提醒标签 - UILabelExt *SilentModeLabel{nullptr}; // 静音模式标签 - // UILabelExt *reminder[4]{nullptr}; // 提示标签 - UIImageView *nextImageView[3]{nullptr}; // 箭头图片 - UIImageView *VibrationReminderImageView{nullptr}; // - UIImageView *SilentModeImageView{nullptr}; // + UILabelExt *Title{nullptr}; // 标题:“声音与震动” + UILabelButtonExt *SystemVolumeButton{nullptr}; // 系统音量按钮 + UILabelButtonExt *CallVolumeButton{nullptr}; // 通话音量按钮 + UILabelButtonExt *VibrationReminderButton{nullptr}; // 震动提醒按钮 + UILabelButtonExt *SilentModeButton{nullptr}; // 静音模式按钮 UIToggleButton *SilentModeToggleButton{nullptr}; // 静音模式切换按钮 - bool initViewStatus{false}; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h new file mode 100644 index 000000000..aad267d17 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h @@ -0,0 +1,45 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-19 10:08:21 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-19 10:22:53 + * @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" +namespace OHOS +{ + 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; // 声音值 + uint8_t m_VolumeType; + }; +} + +#endif \ 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 0dbc17609..bd17b2e0b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingView.h @@ -1,3 +1,10 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:41:49 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-19 10:40:30 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingView.h + */ #ifndef SOUND_AND_VIBRATION_VOLUME_SETTING_H #define SOUND_AND_VIBRATION_VOLUME_SETTING_H @@ -6,7 +13,6 @@ #include "components/ui_scroll_view.h" #include "components/ui_slider.h" #include "components/ui_image_view.h" -#include "soundandvibration/include/SystemVolumePresenter.h" /* 声音与震动的声音设置视图 @@ -18,22 +24,27 @@ namespace OHOS #define VOLUME_MAX 100 #define VOLUME_PROGRESS "progress" +#define SYSTEM_VOLUME 0 +#define CALL_VOLUME 1 + class VoumeProcessSliderEventListener; class SoundAndVibrationVolumeSettingView { public: - SoundAndVibrationVolumeSettingView(); + SoundAndVibrationVolumeSettingView(uint8_t VolumeType); ~SoundAndVibrationVolumeSettingView(); static SoundAndVibrationVolumeSettingView *GetInstance(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; + uint8_t m_VolumeType; 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 42e23dd98..a2fedbf47 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumePresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumePresenter.h @@ -1,40 +1,20 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 16:24:30 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-19 14:53:45 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumePresenter.h + */ #ifndef SYSTEM_VOLUME_PRESENTER_H #define SYSTEM_VOLUME_PRESENTER_H #include "Presenter.h" +#include "View.h" #include "SystemVolumeView.h" #include "wearable_log.h" -#include "KeyInputListener.h" namespace OHOS { - 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, @@ -54,9 +34,9 @@ namespace OHOS static SystemVolumePresenter *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); bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 }; } // namespace OHOS 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 b05764327..9e802cc3d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumeView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumeView.h @@ -1,3 +1,10 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-19 10:17:28 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumeView.h + */ #ifndef SYSTEM_VOLUME_VIEW_H #define SYSTEM_VOLUME_VIEW_H @@ -30,7 +37,6 @@ namespace OHOS private: UIScrollView *SystemVolumeScrollView{nullptr}; SoundAndVibrationVolumeSettingView *p_SoundAndVibrationVolumeSettingView{nullptr}; - UIView::OnDragListener *volumeDragListener{nullptr}; bool initViewStatus{false}; }; } // namespace OHOS 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 69e7f0fa2..748e8adbd 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumePresenter.cpp @@ -1,77 +1,99 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-19 10:24:13 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumePresenter.cpp + */ #include "AppViewIDs.h" #include "components/ui_label_ext.h" -#include"language/font/ui_resource_string.h" +#include "language/font/ui_resource_string.h" #include "NativeAbility.h" #include "graphic_math.h" -#include "string.h" #include "soundandvibration/include/CallVolumePresenter.h" -//系统音量 -namespace OHOS{ - - //当前Presenter属性实例化的内存指针 - static CallVolumePresenter *g_pCallVolumePresenter = nullptr; - - CallVolumePresenter::CallVolumePresenter(){ - +#include "common/key_code.h" +#include "custom_utils.h" +#include + +// 系统音量 +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static CallVolumePresenter *g_pCallVolumePresenter = nullptr; + + CallVolumePresenter::CallVolumePresenter() + { + g_pCallVolumePresenter = this; } - - CallVolumePresenter::~CallVolumePresenter(){ - + + CallVolumePresenter::~CallVolumePresenter() + { + g_pCallVolumePresenter = nullptr; } - - CallVolumePresenter *CallVolumePresenter::GetInstance(){ - + + CallVolumePresenter *CallVolumePresenter::GetInstance() + { + return g_pCallVolumePresenter; } - - void CallVolumePresenter::OnStart(){ - - Presenter::OnStart(); + + void CallVolumePresenter::OnStart() + { + + Presenter::OnStart(); } - - void CallVolumePresenter::OnPause(void){ - + + void CallVolumePresenter::OnPause(void) + { + Presenter::OnPause(); } - - void CallVolumePresenter::OnResume(void){ - + + void CallVolumePresenter::OnResume(void) + { + Presenter::OnResume(); } - - void CallVolumePresenter::OnStop(void){ - - Presenter::OnStop(); + + void CallVolumePresenter::OnStop(void) + { + + Presenter::OnStop(); } - - bool CallVolumePresenter::OnDrag(UIView &view, const DragEvent &event){ - + + bool CallVolumePresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && - (event.GetDeltaX() > 30) && (event.GetDeltaX() > (3 * MATH_ABS(event.GetDeltaY())))) + (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) { - //NativeAbility::GetInstance().ChangeSlice(VIEW_SOUND_VIBRATION); - uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - NativeAbility::GetInstance().ChangeSlice(preSlice); + NativeAbility::GetInstance().Back(); } return true; } - - bool CallVolumePresenter::OnClick(UIView &view, const ClickEvent &event){ - - // 根据控件id查找是哪个控件触发了点击回调 - // if (strcmp(view.GetViewId(), 控件ID) == 0) - // if(strcmp(view.GetViewId(), BRIGHTNESS_CONTROL_SLIDER)) - // { - - // } + + bool CallVolumePresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CallVolumePresenter::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; } -} - - - - + bool CallVolumePresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(view); + UNUSED(event); + return true; + } +} 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 19cd72c0a..fb3443725 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumeView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumeView.cpp @@ -1,11 +1,7 @@ #include "soundandvibration/include/CallVolumeView.h" #include "soundandvibration/include/CallVolumePresenter.h" -#include "UiConfig.h" - -/* -通话音量: -闹钟,计时器,秒表的音量 -*/ +#include "wearable_log.h" +#include namespace OHOS { @@ -14,99 +10,80 @@ namespace OHOS CallVolumeView::CallVolumeView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallVolumeView::CallVolumeView"); g_pCallVolumeView = this; } CallVolumeView::~CallVolumeView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallVolumeView::~CallVolumeView"); + ClearAll(); g_pCallVolumeView = nullptr; - if (container_ != nullptr) - { - delete container_; - container_ = nullptr; - } - if (CallVolumeslider != nullptr) - { - delete CallVolumeslider; - CallVolumeslider = nullptr; - } - if (CallVolumeimageicon != nullptr) - { - delete CallVolumeimageicon; - CallVolumeimageicon = nullptr; - } } CallVolumeView *CallVolumeView::GetInstance() { - return g_pCallVolumeView; } - void CallVolumeView::InitView(void) + + void CallVolumeView::ClearAll() { - if (container_ == nullptr) + if (initViewStatus == true) { - container_ = new UIViewGroup(); - container_->SetPosition(0, 0, 466, 466); - container_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - container_->SetStyle(STYLE_BACKGROUND_COLOR, 0x000000); + delete p_SoundAndVibrationVolumeSettingView; + p_SoundAndVibrationVolumeSettingView = nullptr; } - draglistener = static_cast(CallVolumePresenter::GetInstance()); - container_->SetOnDragListener(draglistener); - container_->SetTouchable(true); - container_->SetDraggable(true); - /********************************************************************************************************/ - if (CallVolumeslider == nullptr) + } + + UIScrollView *CallVolumeView::CallVolumeViewInit(void) + { + p_SoundAndVibrationVolumeSettingView = new SoundAndVibrationVolumeSettingView(CALL_VOLUME); + if (p_SoundAndVibrationVolumeSettingView == nullptr) { - CallVolumeslider = new UISlider(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallVolumeView::p_SoundAndVibrationVolumeSettingView is nullptr!"); + return nullptr; } - CallVolumeslider->SetPosition(167, 77); - CallVolumeslider->Resize(130, 310); - CallVolumeslider->SetViewId(CALL_VOLUME_SLIDER); - CallVolumeslider->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); - CallVolumeslider->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - CallVolumeslider->SetStyle(STYLE_BORDER_OPA, 0x19); - CallVolumeslider->SetStyle(STYLE_BORDER_RADIUS, 100); - CallVolumeslider->SetDirection(UISlider::Direction::DIR_BOTTOM_TO_TOP); - CallVolumeslider->SetValue(50); - CallVolumeslider->SetSliderColor(Color::GetColorFromRGBA(0x19, 0x19, 0x19, 0xff), Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); - CallVolumeslider->SetKnobStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); - CallVolumeslider->SetForegroundStyle(STYLE_BACKGROUND_OPA, 0xff); - CallVolumeslider->SetBackgroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND); // 圆帽式 - CallVolumeslider->SetForegroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND); // 设置进度条的前景样式。圆帽式 - CallVolumeslider->SetStyle(STYLE_BORDER_COLOR, Color::Black().full); - CallVolumeslider->SetStyle(STYLE_BORDER_WIDTH,2); - sliderClick = static_cast(CallVolumePresenter::GetInstance()); // 用来处理之后点击slider的点击事件 - CallVolumeslider->SetOnClickListener(sliderClick); - sliderDrag = static_cast(CallVolumePresenter::GetInstance()); // 用来处理之后拖动slider的拖动事件 - CallVolumeslider->SetOnDragListener(sliderDrag); - container_->Add(CallVolumeslider); - CallVolumeslider->SetVisible(true); - /********************************************************************************************************/ - if (CallVolumeimageicon == nullptr) + CallVolumeScrollView = p_SoundAndVibrationVolumeSettingView->SetUpVolumeProcess(); + if (CallVolumeScrollView == nullptr) { - CallVolumeimageicon = new UIImageView(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CallVolumeView::CallVolumeScrollView is nullptr!"); + return nullptr; } - CallVolumeimageicon->SetPosition(213, 213); // widget's left position and top position - CallVolumeimageicon->Resize(100, 100); // widget's width and height - CallVolumeimageicon->SetViewId("CallVolumeimageicon"); // Set style - CallVolumeimageicon->SetStyle(STYLE_BORDER_COLOR, 0xffAAAAAA); - CallVolumeimageicon->SetSrc(PNG_VOLUME_CONTROL_VECTOR); - container_->Add(CallVolumeimageicon); - CallVolumeimageicon->SetVisible(true); + UIView::OnDragListener *volumeDragListener = static_cast(CallVolumePresenter::GetInstance()); + if (volumeDragListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingPresenter GetInstance fail"); + return nullptr; + } + CallVolumeScrollView->SetOnDragListener(volumeDragListener); + if (CallVolumeScrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_SoundAndVibrationVolumeSettingView->SetUpVolumeProcess fail!!"); + 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)); + + initViewStatus = true; + return CallVolumeScrollView; } void CallVolumeView::OnStart() { View::OnStart(); - InitView(); - RootView::GetInstance()->Add(container_); + + CallVolumeViewInit(); + + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::CallVolumePresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); } void CallVolumeView::OnSetUpView() { View::OnSetUpView(); + RootView::GetInstance()->Add(CallVolumeScrollView); Draw(); } @@ -119,6 +96,7 @@ namespace OHOS void CallVolumeView::OnStop() { View::OnStop(); + RootView::GetInstance()->ClearOnKeyActListener(); RootView::GetInstance()->RemoveAll(); return; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/MediaVolumePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/MediaVolumePresenter.cpp deleted file mode 100644 index 84bde0789..000000000 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/MediaVolumePresenter.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "AppViewIDs.h" -#include "components/ui_label_ext.h" -#include"language/font/ui_resource_string.h" -#include "NativeAbility.h" -#include "graphic_math.h" -#include "string.h" -#include "soundandvibration/include/MediaVolumePresenter.h" -//系统音量 -namespace OHOS{ - - //当前Presenter属性实例化的内存指针 - static MediaVolumePresenter *g_pMediaVolumePresenter = nullptr; - - MediaVolumePresenter::MediaVolumePresenter(){ - - g_pMediaVolumePresenter = this; - } - - MediaVolumePresenter::~MediaVolumePresenter(){ - - g_pMediaVolumePresenter = nullptr; - } - - MediaVolumePresenter *MediaVolumePresenter::GetInstance(){ - - return g_pMediaVolumePresenter; - } - - void MediaVolumePresenter::OnStart(){ - - Presenter::OnStart(); - } - - void MediaVolumePresenter::OnPause(void){ - - Presenter::OnPause(); - } - - void MediaVolumePresenter::OnResume(void){ - - Presenter::OnResume(); - } - - void MediaVolumePresenter::OnStop(void){ - - Presenter::OnStop(); - } - - bool MediaVolumePresenter::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); - uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - NativeAbility::GetInstance().ChangeSlice(preSlice); - } - return true; - } - - bool MediaVolumePresenter::OnClick(UIView &view, const ClickEvent &event){ - - // 根据控件id查找是哪个控件触发了点击回调 - // if (strcmp(view.GetViewId(), 控件ID) == 0) - // if(strcmp(view.GetViewId(), BRIGHTNESS_CONTROL_SLIDER)) - // { - - // } - return true; - } -} - - - - - - diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/MediaVolumeView.cpp b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/MediaVolumeView.cpp deleted file mode 100644 index e3b94b2c9..000000000 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/MediaVolumeView.cpp +++ /dev/null @@ -1,125 +0,0 @@ -#include "soundandvibration/include/MediaVolumeView.h" -#include "soundandvibration/include/MediaVolumePresenter.h" -#include "UiConfig.h" - -/* -媒体音量: -音量,录音,训练的音量 -*/ - -namespace OHOS -{ - - static MediaVolumeView *g_pMediaVolumeView{nullptr}; - - MediaVolumeView::MediaVolumeView() - { - g_pMediaVolumeView = this; - } - - MediaVolumeView::~MediaVolumeView() - { - g_pMediaVolumeView = nullptr; - if (container_ != nullptr) - { - delete container_; - container_ = nullptr; - } - if (MediaVolumeslider != nullptr) - { - delete MediaVolumeslider; - MediaVolumeslider = nullptr; - } - if (MediaVolumeimageicon != nullptr) - { - delete MediaVolumeimageicon; - MediaVolumeimageicon = nullptr; - } - } - - MediaVolumeView *MediaVolumeView::GetInstance() - { - - return g_pMediaVolumeView; - } - void MediaVolumeView::InitView(void) - { - if (container_ == nullptr) - { - container_ = new UIViewGroup(); - container_->SetPosition(0, 0, 466, 466); - container_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - container_->SetStyle(STYLE_BACKGROUND_COLOR, 0x000000); - } - draglistener = static_cast(MediaVolumePresenter::GetInstance()); - container_->SetOnDragListener(draglistener); - container_->SetTouchable(true); - container_->SetDraggable(true); - /********************************************************************************************************/ - if (MediaVolumeslider == nullptr) - { - MediaVolumeslider = new UISlider(); - } - MediaVolumeslider->SetPosition(167, 77); - MediaVolumeslider->Resize(130, 310); - MediaVolumeslider->SetViewId(MEDIA_VOLUME_SLIDER); - MediaVolumeslider->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); - MediaVolumeslider->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - MediaVolumeslider->SetStyle(STYLE_BORDER_OPA, 0x19); - MediaVolumeslider->SetStyle(STYLE_BORDER_RADIUS, 100); - MediaVolumeslider->SetDirection(UISlider::Direction::DIR_BOTTOM_TO_TOP); - MediaVolumeslider->SetValue(50); - MediaVolumeslider->SetSliderColor(Color::GetColorFromRGBA(0x19, 0x19, 0x19, 0xff), Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); - MediaVolumeslider->SetKnobStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); - MediaVolumeslider->SetForegroundStyle(STYLE_BACKGROUND_OPA, 0xff); - MediaVolumeslider->SetBackgroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND); // 圆帽式 - MediaVolumeslider->SetForegroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND); // 设置进度条的前景样式。圆帽式 - MediaVolumeslider->SetStyle(STYLE_BORDER_COLOR, Color::Black().full); - MediaVolumeslider->SetStyle(STYLE_BORDER_WIDTH,2); - sliderClick = static_cast(MediaVolumePresenter::GetInstance()); // 用来处理之后点击slider的点击事件 - MediaVolumeslider->SetOnClickListener(sliderClick); - sliderDrag = static_cast(MediaVolumePresenter::GetInstance()); // 用来处理之后拖动slider的拖动事件 - MediaVolumeslider->SetOnDragListener(sliderDrag); - container_->Add(MediaVolumeslider); - MediaVolumeslider->SetVisible(true); - /********************************************************************************************************/ - if (MediaVolumeimageicon == nullptr) - { - MediaVolumeimageicon = new UIImageView(); - } - MediaVolumeimageicon->SetPosition(213, 213); // widget's left position and top position - MediaVolumeimageicon->Resize(100, 100); // widget's width and height - MediaVolumeimageicon->SetViewId("MediaVolumeimageicon"); // Set style - MediaVolumeimageicon->SetStyle(STYLE_BORDER_COLOR, 0xffAAAAAA); - MediaVolumeimageicon->SetSrc(PNG_VOLUME_CONTROL_VECTOR); - - container_->Add(MediaVolumeimageicon); - MediaVolumeimageicon->SetVisible(true); - } - - void MediaVolumeView::OnStart() - { - View::OnStart(); - InitView(); - RootView::GetInstance()->Add(container_); - } - - void MediaVolumeView::OnSetUpView() - { - View::OnSetUpView(); - Draw(); - } - - void MediaVolumeView::OnTearDownView() - { - View::OnTearDownView(); - return; - } - - void MediaVolumeView::OnStop() - { - View::OnStop(); - RootView::GetInstance()->RemoveAll(); - return; - } -} 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 020791821..8e5caf0e2 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-18 18:08:44 + * @LastEditTime: 2024-04-19 14:53:16 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp */ @@ -84,6 +84,8 @@ namespace OHOS bool SoundAndVibrationPresenter::OnDrag(UIView &view, const DragEvent &event) { + UNUSED(view); + UNUSED(event); return true; } @@ -117,6 +119,7 @@ namespace OHOS UNUSED(event); if (strcmp(view.GetViewId(), SYSTEM_VOLUME_BUTTON) == 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SYSTEM_VOLUME_BUTTON"); NativeAbility::GetInstance().EnterSlice(VIEW_SYSTEM_VOLUME); } else if (strcmp(view.GetViewId(), CALL_VOLUME_BUTTON) == 0) diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationView.cpp b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationView.cpp index d9df73e63..fb491dc75 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationView.cpp @@ -1,3 +1,10 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-02-19 10:39:14 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-19 14:58:25 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationView.cpp + */ #include "soundandvibration/include/SoundAndVibrationView.h" #include "soundandvibration/include/SoundAndVibrationPresenter.h" #include "soundandvibration/include/SoundAndVibrationModel.h" @@ -41,7 +48,7 @@ namespace OHOS void SoundAndVibrationView::ClearAll() { - if (initViewStatus == true) + if (SoundAndVibrationScrollView != nullptr) { SoundAndVibrationScrollView->RemoveAll(); @@ -57,35 +64,8 @@ namespace OHOS delete VibrationReminderButton; VibrationReminderButton = nullptr; - delete SystemVolumeLabel; - SystemVolumeLabel = nullptr; - - delete CallVolumeLabel; - CallVolumeLabel = nullptr; - - delete VibrationReminderLabel; - VibrationReminderLabel = nullptr; - - delete SilentModeLabel; - SilentModeLabel = nullptr; - - // for (int i = 0; i < 4; i++) - // { - // delete reminder[i]; - // reminder[i] = nullptr; - // } - - for (int i = 0; i < 3; i++) - { - delete nextImageView[i]; - nextImageView[i] = nullptr; - } - - delete VibrationReminderImageView; - VibrationReminderImageView = nullptr; - - delete SilentModeImageView; - SilentModeImageView = nullptr; + delete SilentModeButton; + SilentModeButton = nullptr; delete SilentModeToggleButton; SilentModeToggleButton = nullptr; @@ -95,57 +75,6 @@ namespace OHOS } } - /// @brief 设置按钮 - /// @param button - /// @return true 设置成功,false 失败 - UIButton *SoundAndVibrationView::SetUpButton(ButtonConfig &buttonconfig, UIView::OnClickListener *clickListener) - { - UIButton *button = new UIButton(); - if (button == nullptr) - { - return nullptr; - } - button->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h); - button->SetViewId(buttonconfig.ViewId); - button->SetStyle(STYLE_BACKGROUND_COLOR, buttonconfig.BackgroundColorValue); - button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffffff, UIButton::PRESSED); - button->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); - button->SetOnClickListener(clickListener); - return button; - } - - // 设置图片 - UIImageView *SoundAndVibrationView::SetUpImageVIew(ImageConfig &imageconfig) - { - UIImageView *Image = new UIImageView(); - if (Image == nullptr) - { - return nullptr; - } - Image->SetPosition(imageconfig.x, imageconfig.y, imageconfig.w, imageconfig.h); - Image->SetSrc(imageconfig.ImageSrc); - return Image; - } - - // 设置标签 - UILabelExt *SoundAndVibrationView::SetUpLabel(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.c_str()); // 内容 - label->SetLineBreakMode(labelConfig.lineBreakMode); // 断行模式。 - //label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label->SetRollSpeed(40); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelConfig.fontSize); - return label; - } - /// @brief 声音与震动视图"scrollView"视图初始化 /// @param void /// @return true 初始化成功 false 初始化失败 @@ -197,99 +126,70 @@ namespace OHOS return true; } - /// @brief 声音与震动视图"按钮"初始化 - /// @param void - /// @return true 初始化成功 false 初始化失败 - bool SoundAndVibrationView::InitSoundAndVibrationButtonView(void) + /// @brief 设置按钮 + /// @param button + /// @return true 设置成功,false 失败 + UILabelButtonExt *SoundAndVibrationView::SetUpButton_Ext(ButtonConfig &buttonconfig, bool nextImgVisible) { - UIView::OnClickListener *ButtonClick = static_cast(SoundAndVibrationPresenter::GetInstance()); - if (ButtonClick == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SoundAndVibrationPresenter::GetInstance() fail!"); - return false; - } - /* --------------------------- SystemVolumeButton --------------------------- */ - if (!SetUpButtonAndCheck(SYSTEM_VOLUME_BUTTON, 43, 120, SystemVolumeButton, ButtonClick)) + UILabelButtonExt *labelButton = new UILabelButtonExt(); + if (labelButton == nullptr) { - return false; + return nullptr; } - - /* ---------------------------- CallVolumeButton ---------------------------- */ - if (!SetUpButtonAndCheck(CALL_VOLUME_BUTTON, 43, 240, CallVolumeButton, ButtonClick)) + labelButton->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h); + labelButton->SetViewId(buttonconfig.ViewId); + labelButton->SetOnClickListener(static_cast(SoundAndVibrationPresenter::GetInstance())); + labelButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + if (nextImgVisible) { - return false; + const char *NextImgSrc = "/user/res/SETTING_NEXT.bin"; + labelButton->SetImageSrc(NextImgSrc, NextImgSrc); + labelButton->SetImagePosition(326, 37); } - - /* ---------------------------- VibrationReminderButton --------------------------- */ - if (!SetUpButtonAndCheck(VIBRATION_REMINDER_BUTTON, 43, 360, VibrationReminderButton, ButtonClick)) - { - return false; - } - - return true; + labelButton->SetText(buttonconfig.Text.c_str()); + labelButton->SetAlign(TEXT_ALIGNMENT_LEFT); + labelButton->SetLabelPosition(47, 0); + labelButton->SetStyle(STYLE_TEXT_FONT, 30); + labelButton->SetStyle(STYLE_LINE_HEIGHT, 35); + labelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + labelButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED); + labelButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff191919, UIButton::PRESSED); + return labelButton; } - - /// @brief 为指定的按钮设置属性并进行错误检查 - bool SoundAndVibrationView::SetUpButtonAndCheck(const char *viewId, int x, int y, UIButton *&button, UIView::OnClickListener *listener) + /// @brief 声音与震动视图"按钮"初始化 + /// @param void + /// @return true 初始化成功 false 初始化失败 + bool SoundAndVibrationView::InitSoundAndVibrationButtonView(void) { - ButtonConfig buttonconfig = { - .x = x, - .y = y, - .w = 380, - .h = 100, - .ViewId = viewId, - .BackgroundColorValue = 0xff191919, - }; - - button = SetUpButton(buttonconfig, listener); - if (button == nullptr) + struct ButtonSetup { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SoundAndVibrationView::SetUpButtonAndCheck: Button is nullptr!"); - return false; - } - return true; - } - - /*初始化声音与震动视图图片*/ - bool SoundAndVibrationView::InitSoundAndVibrationImageView() - { - ImageConfig imageconfig = { - .x = 43, - .y = 360, - .w = 380, - .h = 100, - .ImageSrc = "/user/res/SETTING_BACKGROUND.bin", + int y; + const char * viewId; + const char *text; + bool clickEffect; }; - VibrationReminderImageView = SetUpImageVIew(imageconfig); - if (VibrationReminderImageView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::VibrationReminderImageView is nullptr!"); - return false; - } + ButtonSetup buttonSetups[] = { + {120, SYSTEM_VOLUME_BUTTON, "系统音量", true}, + {240, CALL_VOLUME_BUTTON, "通话音量", true}, + {360, VIBRATION_REMINDER_BUTTON, "震动模式", true}, + {480, SILENT_MODE_BUTTON, "静音模式", false}}; - imageconfig.y = 480; - SilentModeImageView = SetUpImageVIew(imageconfig); - if (SilentModeImageView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::SilentModeImageView is nullptr!"); - return false; - } + UILabelButtonExt **buttonPointers[] = {&SystemVolumeButton, &CallVolumeButton, &VibrationReminderButton, &SilentModeButton}; - imageconfig = { - .x = 369, - .w = 14, - .h = 26, - .ImageSrc = "/user/res/SETTING_NEXT.bin", - }; - - for (int i = 0; i < 3; i++) + for (int i = 0; i < sizeof(buttonSetups) / sizeof(buttonSetups[0]); ++i) { - imageconfig.y = 157 + 120 * i; - nextImageView[i] = SetUpImageVIew(imageconfig); - if (nextImageView[i] == nullptr) + ButtonConfig buttonconfig = { + .x = 43, + .y = buttonSetups[i].y, + .w = 380, + .h = 100, + .ViewId = buttonSetups[i].viewId, + .Text = buttonSetups[i].text}; + *buttonPointers[i] = SetUpButton_Ext(buttonconfig, buttonSetups[i].clickEffect); + if (*buttonPointers[i] == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView:: nextImageView[%d] is nullptr!", i); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::%s Button new fail!", buttonSetups[i].text); return false; } } @@ -297,93 +197,6 @@ namespace OHOS return true; } - /*初始化声音与震动视图标签*/ - bool SoundAndVibrationView::InitSoundAndVibrationLabel(void) - { - LabelConfig labelConfig = { - .left = 90, - .top = 152, - .width = 250, - .height = 40, - .fontSize = 30, - .lineHeigh = 35, - .lineBreakMode = UILabel::LINE_BREAK_MARQUEE, - }; - /* ---------------------------- SystemVolumeLabel --------------------------- */ - labelConfig.text = "系统音量"; - SystemVolumeLabel = SetUpLabel(labelConfig); - if (SystemVolumeLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::SystemVolumeLabel is nullptr!"); - return false; - } - /* ----------------------------- CallVolumeLabel ---------------------------- */ - labelConfig.top = 272; - labelConfig.text = "通话音量"; - CallVolumeLabel = SetUpLabel(labelConfig); - if (CallVolumeLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::CallVolumeLabel is nullptr!"); - return false; - } - /* ---------------------------- VibrationReminderLabel ---------------------------- */ - labelConfig.top = 392; - labelConfig.text = "震动模式"; - VibrationReminderLabel = SetUpLabel(labelConfig); - if (VibrationReminderLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::VibrationReminderLabel is nullptr!"); - return false; - } - /* ----------------------------- SilentModeLabel ---------------------------- */ - labelConfig.top = 512; - labelConfig.text = "静音模式"; - SilentModeLabel = SetUpLabel(labelConfig); - if (SilentModeLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::SilentModeLabel is nullptr!"); - return false; - } - /* -------------------------------------------------------------------------- */ - // typedef struct - // { - // int top; - // char text[100]; - // } LabelInfo; - - // LabelInfo labelInfo[] = { - // {177, "闹钟、提醒、查找手表"}, - // {297, "手表通话"}, - // {417, "音乐、录音、训练"}, - // {657, "系统音量不受影响"}, - // }; - // for (int i = 0; i < (int)(sizeof(labelInfo) / sizeof(labelInfo[0])); i++) - // { - // LabelConfig labelConfig = { - // .left = 90, - // .top = labelInfo[i].top, - // .width = 300, - // .height = 35, - // .fontSize = 20, - // .lineHeigh = 23, - // .text = labelInfo[i].text, - // .lineBreakMode = UILabel::LINE_BREAK_ADAPT, - // }; - - // reminder[i] = SetUpLabel(labelConfig); - // if (reminder[i] == nullptr) - // { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::reminder[%d] is nullptr!", i); - // return false; - // } - - // reminder[i]->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - // reminder[i]->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - // reminder[i]->SetTextColor(Color::GetColorFromRGBA(0xfd, 0xfd, 0xfd, 0x7f)); - // } - return true; - } - bool SoundAndVibrationView::InitSoundAndVibrationToggleButton(void) { /* ------------------------- SilentModeToggleButton ------------------------- */ @@ -399,12 +212,11 @@ namespace OHOS const char *ToggleButtonSelect = "/user/res/TOGGLEBUTTON_ON.bin"; const char *ToggleButtonUnSelect = "/user/res/TOGGLEBUTTON_OFF.bin"; SilentModeToggleButton->SetImages(ToggleButtonSelect, ToggleButtonUnSelect); - UICheckBox::OnChangeListener * SilentModeToggleButtonChangeListener = static_cast(SoundAndVibrationPresenter::GetInstance()); + UICheckBox::OnChangeListener *SilentModeToggleButtonChangeListener = static_cast(SoundAndVibrationPresenter::GetInstance()); SilentModeToggleButton->SetOnChangeListener(SilentModeToggleButtonChangeListener); return true; } - /// @brief 获取"静音模式"按钮开,关状态 /// @param void /// @return true 开 false 关 @@ -413,7 +225,6 @@ namespace OHOS return SilentModeToggleButton->GetState(); } - /// @brief 设置"静音模式"按钮开,关状态 /// @param value void SoundAndVibrationView::SetSilentModeToggleButtonState(bool value) @@ -421,7 +232,6 @@ namespace OHOS SilentModeToggleButton->SetState(value); } - /// @brief 获取"静音模式"切换按钮 UIToggleButton *SoundAndVibrationView::GetSilentModeToggleButton(void) { @@ -442,23 +252,14 @@ namespace OHOS { return; } - if (InitSoundAndVibrationImageView() == false) - { - return; - } if (InitSoundAndVibrationToggleButton() == false) { return; } - if (InitSoundAndVibrationLabel() == false) - { - return; - } - if (SoundAndVibrationModel::GetInstance()->SilentModeToggleButtonStatusInit() == false) - { - return; - } - initViewStatus = true; + // if (SoundAndVibrationModel::GetInstance()->SilentModeToggleButtonStatusInit() == false) + // { + // return; + // } } void SoundAndVibrationView::OnStart() @@ -476,20 +277,7 @@ namespace OHOS SoundAndVibrationScrollView->Add(SystemVolumeButton); SoundAndVibrationScrollView->Add(CallVolumeButton); SoundAndVibrationScrollView->Add(VibrationReminderButton); - SoundAndVibrationScrollView->Add(VibrationReminderImageView); - SoundAndVibrationScrollView->Add(SilentModeImageView); - SoundAndVibrationScrollView->Add(SystemVolumeLabel); - SoundAndVibrationScrollView->Add(CallVolumeLabel); - SoundAndVibrationScrollView->Add(VibrationReminderLabel); - SoundAndVibrationScrollView->Add(VibrationReminderLabel); - SoundAndVibrationScrollView->Add(SilentModeLabel); - // SoundAndVibrationScrollView->Add(reminder[0]); - // SoundAndVibrationScrollView->Add(reminder[1]); - // SoundAndVibrationScrollView->Add(reminder[2]); - // SoundAndVibrationScrollView->Add(reminder[3]); - SoundAndVibrationScrollView->Add(nextImageView[0]); - SoundAndVibrationScrollView->Add(nextImageView[1]); - SoundAndVibrationScrollView->Add(nextImageView[2]); + SoundAndVibrationScrollView->Add(SilentModeButton); SoundAndVibrationScrollView->Add(SilentModeToggleButton); RootView::GetInstance()->Add(SoundAndVibrationScrollView); Draw(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp new file mode 100644 index 000000000..094bca637 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp @@ -0,0 +1,125 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-19 10:08:31 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-19 10:14:03 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp + */ +#include "soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h" +#include "soundandvibration/include/SoundAndVibrationVolumeSettingView.h" +#include "wearable_log.h" +#include +namespace OHOS +{ + + /* --------------------- 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, "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); + 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; + } + +} \ 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 65c436a12..b2c110645 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingView.cpp @@ -1,15 +1,15 @@ #include "soundandvibration/include/SoundAndVibrationVolumeSettingView.h" -#include "soundandvibration/include/SoundAndVibrationPresenter.h" +#include "soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h" #include "wearable_log.h" namespace OHOS { static SoundAndVibrationVolumeSettingView *g_pSoundAndVibrationVolumeSettingView{nullptr}; - SoundAndVibrationVolumeSettingView::SoundAndVibrationVolumeSettingView() + SoundAndVibrationVolumeSettingView::SoundAndVibrationVolumeSettingView(uint8_t VolumeType) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationVolumeSettingView::SoundAndVibrationVolumeSettingView"); - + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationVolumeSettingView::SoundAndVibrationVolumeSettingView,VolumeType = %d",VolumeType); + m_VolumeType = VolumeType; g_pSoundAndVibrationVolumeSettingView = this; } 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 86590a32e..fd140561c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumePresenter.cpp @@ -1,13 +1,22 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-19 14:53:24 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumePresenter.cpp + * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE + */ #include "AppViewIDs.h" #include "components/ui_label_ext.h" -#include"language/font/ui_resource_string.h" +#include "language/font/ui_resource_string.h" #include "NativeAbility.h" #include "graphic_math.h" #include "string.h" #include "soundandvibration/include/SystemVolumePresenter.h" -#include + #include "common/key_code.h" #include "custom_utils.h" +#include // 系统音量 namespace OHOS @@ -61,12 +70,17 @@ namespace OHOS bool SystemVolumePresenter::OnDrag(UIView &view, const DragEvent &event) { UNUSED(view); - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && - (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + UNUSED(event); + return true; + } + + bool SystemVolumePresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemVolumePresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { - // NativeAbility::GetInstance().ChangeSlice(VIEW_SOUND_VIBRATION); - uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - NativeAbility::GetInstance().ChangeSlice(preSlice); + NativeAbility::GetInstance().Back(); } return true; } @@ -80,8 +94,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(); - NativeAbility::GetInstance().ChangeSlice(preSlice); + NativeAbility::GetInstance().Back(); } return true; } @@ -92,115 +105,4 @@ namespace OHOS UNUSED(event); 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, "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); - 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; - } } 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 47e7cc963..c5fab2050 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumeView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumeView.cpp @@ -34,9 +34,6 @@ namespace OHOS { if (initViewStatus == true) { - delete volumeDragListener; - volumeDragListener = nullptr; - delete p_SoundAndVibrationVolumeSettingView; p_SoundAndVibrationVolumeSettingView = nullptr; } @@ -44,7 +41,7 @@ namespace OHOS UIScrollView *SystemVolumeView::SystemVolumeViewInit(void) { - p_SoundAndVibrationVolumeSettingView = new SoundAndVibrationVolumeSettingView(); + p_SoundAndVibrationVolumeSettingView = new SoundAndVibrationVolumeSettingView(SYSTEM_VOLUME); if (p_SoundAndVibrationVolumeSettingView == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemVolumeView::p_SoundAndVibrationVolumeSettingView is nullptr!"); @@ -57,7 +54,7 @@ namespace OHOS return nullptr; } - volumeDragListener = static_cast(SystemVolumePresenter::GetInstance()); + UIView::OnDragListener *volumeDragListener = static_cast(SystemVolumePresenter::GetInstance()); if (volumeDragListener == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingPresenter GetInstance fail"); @@ -71,7 +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)); + initViewStatus = true; return SystemVolumeScrollView; }