From: 罗正yun <1732036298@qq.com> Date: Tue, 23 Jan 2024 09:41:56 +0000 (+0800) Subject: 添加声音与震动视图 X-Git-Tag: release_V1.2.70_20241020_135402~1336^2~3 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=1cd65197d9d712918749a72f5662815009fdc304;p=mirrors%2FFD230.git 添加声音与震动视图 --- diff --git a/code/sdk/application/wearable/nativeapp/CMakeLists.txt b/code/sdk/application/wearable/nativeapp/CMakeLists.txt index 80418d008..319d1d1e0 100755 --- a/code/sdk/application/wearable/nativeapp/CMakeLists.txt +++ b/code/sdk/application/wearable/nativeapp/CMakeLists.txt @@ -221,7 +221,16 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/system/src/SystemFactoryResetPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/system/src/SystemFactoryResetView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/soundandvibration/src/SoundAndVibrationView.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/compass/src/CompassControlView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/compass/src/CompassCalibrationView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/compass/src/CompassModel.cpp diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h index 6ef0c96c5..37384b148 100755 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h @@ -24,7 +24,7 @@ */ typedef enum : uint16_t { - VIEW_INVALID = 0, // 无效视图 + VIEW_INVALID = 0, // 无效视图 /* ----------------------------- 每一个id对应一个slice ----------------------------- */ VIEW_MAIN = 1, // 主界面 VIEW_SETTING, // 设置 @@ -47,14 +47,18 @@ typedef enum : uint16_t VIEW_SYSTEM, // 系统 VIEW_SYSTEM_SYSTEM_LANGUAGE, // 系统:系统语言 VIEW_SYSTEM_FACTORY_RESET, // 系统:恢复出厂设置 + VIEW_SOUND_VIBRATION, // 声音与震动 + VIEW_SYSTEM_VOLUME, // 系统音量 + VIEW_CALL_VOLUME, // 通话音量 + VIEW_MEDIA_VOLUME, // 媒体音量 /* -------------------------------------------------------------------------- */ - VIEW_MAIN_TEMP, // 体温界面(暂时不用) - VIEW_OFFLINEVOICE, // 语音助手界面(暂时不用) - VIEW_MAIN_ACTIVITY, // 记录步数界面(暂时不用) - VIEW_UISAMPLE, // 示例(暂时不用) + VIEW_MAIN_TEMP, // 体温界面(暂时不用) + VIEW_OFFLINEVOICE, // 语音助手界面(暂时不用) + VIEW_MAIN_ACTIVITY, // 记录步数界面(暂时不用) + VIEW_UISAMPLE, // 示例(暂时不用) /* -------------------------------------------------------------------------- */ - VIEW_MAX_INTER_APP, // 在此之前添加native应用ID. - VIEW_EXTERN_APP = 0xFFFE, // 三方应用 + VIEW_MAX_INTER_APP, // 在此之前添加native应用ID. + VIEW_EXTERN_APP = 0xFFFE, // 三方应用 VIEW_INVALIDE_APP = 0xFFFF, } AppViewId; diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h index 30dc708be..e4b8c4585 100755 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h @@ -1,15 +1,14 @@ -/*** +/*** * @Author: Caisking 3449750381@qq.com * @Date: 2023-12-13 19:33:14 * @LastEditors: Caisking 3449750381@qq.com * @LastEditTime: 2024-01-22 16:32:42 * @FilePath: /FD230/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h - * @Description: + * @Description: * @ - * @Copyright (c) 2024 by Caisking , All Rights Reserved. + * @Copyright (c) 2024 by Caisking , All Rights Reserved. */ - #ifndef NATIVE_LAUNCHER_H #define NATIVE_LAUNCHER_H #include "AppViewIDs.h" @@ -43,13 +42,18 @@ namespace OHOS void InitDialSlice(void); /* ----------------------------------- 天气 ----------------------------------- */ void InitWeatherSlice(void); - void InitWeatherReportSlice(void); - void InitFutureWeatherSlice(void); + void InitWeatherReportSlice(void); + void InitFutureWeatherSlice(void); void InitGetWeatherDataErrorSlice(void); /* -------------------------------------------------------------------------- */ - void InitSystemSlice(void); - void InitSystemLanguageSlice(void); - void InitSystemFactoryResetSlice(void); + void InitSystemSlice(void); + void InitSystemLanguageSlice(void); + void InitSystemFactoryResetSlice(void); + /* -------------------------------------------------------------------------- */ + void InitSoundAndVibrationSlice(void); + void InitSystemVolumeSlice(void); + void InitCallVolumeSlice(void); + void InitMediaVolumeSlice(void); private: void InitAllNativeSlices(void); diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/UiConfig.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/UiConfig.h index cd08d0ed8..3362b9131 100755 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/UiConfig.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/UiConfig.h @@ -200,13 +200,12 @@ namespace OHOS static constexpr const char *PNG_SETTINGS_SOUND_VIBRATION = APP_RES_PATH "/settings/SETTINGS_SOUND_VIBRATION.bin"; // 声音与震动 static constexpr const char *PNG_SETTINGS_SECONDARY_FUNCTION = APP_RES_PATH "/settings/SETTINGS_QUICK_ACCESS.bin"; // 辅助功能 static constexpr const char *PNG_SETTINGS_SYSTEM = APP_RES_PATH "/settings/SETTINGS_SYSTEM.bin"; // 系统 + static constexpr const char *PNG_SETTINGS_SETTINGS_POWER_CONTROL = APP_RES_PATH "/settings/SETTINGS_POWER_CONTROL.bin"; // 关机和重启 /* ---------------------------------- 消息中心 ---------------------------------- */ static constexpr const char *PNG_Message_System = APP_RES_PATH "/message/system-icon.bin"; // 系统消息 static constexpr const char *PNG_Message_Note = APP_RES_PATH "/message/message-icon.bin"; // 短信 static constexpr const char *PNG_Message_Wechat = APP_RES_PATH "/message/WeChat-icon.bin"; // 微信消息 static constexpr const char *PNG_Message_QQ = APP_RES_PATH "/message/QQ-icon.bin"; // QQ消息 - /* -------------------------------------------------------------------------- */ - static constexpr const char *PNG_SETTINGS_SETTINGS_POWER_CONTROL = APP_RES_PATH "/settings/SETTINGS_POWER_CONTROL.bin"; // 关机和重启 /* ---------------------------------- 通用图片 ---------------------------------- */ static constexpr const char *PNG_CHECKBOX_OFF_IMAGE = APP_RES_PATH "/CHECKBOX_OFF.bin"; // checkbox未选中图片 static constexpr const char *PNG_CHECKBOX_ON_IMAGE = APP_RES_PATH "/CHECKBOX_ON.bin"; // checkbox选中图片 @@ -215,6 +214,11 @@ namespace OHOS static constexpr const char *PNG_VOLUME_CONTROL_VECTOR = APP_RES_PATH "/VolumeControlVector.bin"; // 调节音量图片 static constexpr const char *PNG_SYSTEM_CHECK_ON_IMAGE = APP_RES_PATH "/SYSTEM_CheckOn.bin"; // 勾 static constexpr const char *PNG_SYSTEM_CHECK_OFF_IMAGE = APP_RES_PATH "/SYSTEM_CheckOff.bin"; // 叉 + static constexpr const char *PNG_TOGGLEBUTTON_OFF_IMAGE = APP_RES_PATH "/TOGGLEBUTTON_OFF.bin"; // togglebuttton未选中图片 + static constexpr const char *PNG_TOGGLEBUTTON_ON_IMAGE = APP_RES_PATH "/TOGGLEBUTTON_ON.bin"; // togglebuttton选中图片 + static constexpr const char *PNG_SYSTEM_VOLUME_IMAGE = APP_RES_PATH "/SYSTEM_VOLUME.bin"; // 系统音量 + static constexpr const char *PNG_CALL_VOLUME_IMAGE = APP_RES_PATH "/CALL_VOLUME.bin"; // 通话音量 + static constexpr const char *PNG_MEDIA_VOLUME_IMAGE = APP_RES_PATH "/MEDIA_VOLUME.bin"; // 媒体音量 static constexpr const char *PNG_ANIMATOR1_IMAGE = APP_RES_PATH "/Record/animator1.bin"; static constexpr const char *PNG_ANIMATOR2_IMAGE = APP_RES_PATH "/Record/animator2.bin"; /* -------------------------------- 已删除的不必要图片 ------------------------------- */ diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp index 6ad398e5c..ffa316c8d 100755 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp @@ -76,6 +76,11 @@ #include "system/include/SystemFactoryResetPresenter.h" #include "system/include/SystemFactoryResetView.h" +#include "soundandvibration/include/SoundAndVibrationPresenter.h" +#include "soundandvibration/include/SoundAndVibrationView.h" +#include "soundandvibration/include/SystemVolumePresenter.h" +#include "soundandvibration/include/SystemVolumeView.h" + #include "BluetoothHeadsetEvent.h" #include "graphic_hardware_config.h" #include "graphic_service.h" @@ -117,6 +122,8 @@ namespace OHOS {VIEW_SYSTEM, &NativeLauncher::InitSystemSlice}, // 系统实例化地址 {VIEW_SYSTEM_SYSTEM_LANGUAGE, &NativeLauncher::InitSystemLanguageSlice}, // 系统:系统语言实例化地址 {VIEW_SYSTEM_FACTORY_RESET, &NativeLauncher::InitSystemFactoryResetSlice}, // 系统:恢复出厂设置实例化地址 + {VIEW_SOUND_VIBRATION, &NativeLauncher::InitSoundAndVibrationSlice}, // 声音与震动实例化地址 + {VIEW_SYSTEM_VOLUME, &NativeLauncher::InitSystemVolumeSlice}, // 系统音量 //{VIEW_MAIN_ACTIVITY, &NativeLauncher::InitActivitySlice}, //{VIEW_OFFLINEVOICE, &NativeLauncher::InitOfflineVoice}, //{VIEW_MAIN_TEMP, &NativeLauncher::InitMainTempSlice}, @@ -469,4 +476,25 @@ namespace OHOS } NativeAbility::GetInstance().AddSliceProxy(VIEW_SYSTEM_FACTORY_RESET, systemfactoryreset); } + + void NativeLauncher::InitSoundAndVibrationSlice(void) // 声音与震动 + { + SliceProxy *SoundAndVibration = new AbilitySliceProxy; + if (SoundAndVibration == nullptr) + { + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_SOUND_VIBRATION, SoundAndVibration); + } + + void NativeLauncher::InitSystemVolumeSlice(void) // 系统音量 + { + SliceProxy *systemvolume = new AbilitySliceProxy; + if (systemvolume == nullptr) + { + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_SYSTEM_VOLUME, systemvolume); + } + } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingModel.cpp index abe5d7371..d9164dad7 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingModel.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/settings/src/SettingModel.cpp @@ -30,7 +30,7 @@ namespace OHOS settings[5] = {SETTING_ITEM_FIVE, PNG_SETTINGS_SETTINGS_POWER_CONTROL, "关机和重启", true}; settingIdToViewId.insert(std::pair(SETTING_ITEM_ZERO, VIEW_SHUTDOWN_OR_REBOOT)); settingIdToViewId.insert(std::pair(SETTING_ITEM_ONE, VIEW_BLUETOOTH_EARPHONE)); - settingIdToViewId.insert(std::pair(SETTING_ITEM_TWO, VIEW_SYSTEM)); + settingIdToViewId.insert(std::pair(SETTING_ITEM_TWO, VIEW_SOUND_VIBRATION)); settingIdToViewId.insert(std::pair(SETTING_ITEM_THREE, VIEW_SYSTEM)); settingIdToViewId.insert(std::pair(SETTING_ITEM_FOUR, VIEW_SYSTEM)); settingIdToViewId.insert(std::pair(SETTING_ITEM_FIVE, VIEW_SHUTDOWN_OR_REBOOT)); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/CallVolumePresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/CallVolumePresenter.h new file mode 100644 index 000000000..a53ad4430 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/CallVolumePresenter.h @@ -0,0 +1,33 @@ +#ifndef CALL_VOLUME_PRESENTER_H +#define CALL_VOLUME_PRESENTER_H + +#include "Presenter.h" +#include "CallVolumeView.h" + +namespace OHOS +{ + class CallVolumeView; + + class CallVolumePresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + CallVolumePresenter(); + virtual ~CallVolumePresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static CallVolumePresenter *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/nativeapp/nativeui/soundandvibration/include/CallVolumeView.h b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/CallVolumeView.h new file mode 100644 index 000000000..501bac093 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/CallVolumeView.h @@ -0,0 +1,40 @@ +#ifndef CALL_VOLUME_VIEW_H +#define CALL_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 *CALL_VOLUME_SLIDER = "CallVolumeSlider"; + + class CallVolumePresenter; + class CallVolumeView : public View + { + + public: + CallVolumeView(); + virtual ~CallVolumeView(); + static CallVolumeView *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 *CallVolumeslider = nullptr; + UIImageView *CallVolumeimageicon = nullptr; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/MediaVolumePresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/MediaVolumePresenter.h new file mode 100644 index 000000000..fb7f05916 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/MediaVolumePresenter.h @@ -0,0 +1,33 @@ +#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/nativeapp/nativeui/soundandvibration/include/MediaVolumeView.h b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/MediaVolumeView.h new file mode 100644 index 000000000..210b93daf --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/MediaVolumeView.h @@ -0,0 +1,40 @@ +#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/nativeapp/nativeui/soundandvibration/include/SoundAndVibrationPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/SoundAndVibrationPresenter.h new file mode 100644 index 000000000..b8931cddb --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/SoundAndVibrationPresenter.h @@ -0,0 +1,36 @@ +#ifndef SOUND_AND_VIBRATION_PRESENTER_H +#define SOUND_AND_VIBRATION_PRESENTER_H + +#include "Presenter.h" +#include "SoundAndVibrationView.h" + +namespace OHOS +{ + class SoundAndVibrationView; + + class SoundAndVibrationPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + SoundAndVibrationPresenter(); + virtual ~SoundAndVibrationPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static SoundAndVibrationPresenter *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/nativeapp/nativeui/soundandvibration/include/SoundAndVibrationView.h b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/SoundAndVibrationView.h new file mode 100644 index 000000000..cc4d90ac4 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/SoundAndVibrationView.h @@ -0,0 +1,57 @@ +#ifndef SOUND_AND_VIBRATION_VIEW_H +#define SOUND_AND_VIBRATION_VIEW_H + +#include "BaseView.h" +#include "View.h" + +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_button.h" +#include "components/ui_image_view.h" +#include "components/ui_toggle_button.h" +namespace OHOS +{ + static const char * SYSTEM_VOLUME_BUTTON = "SystemVolumeButton"; //系统音量 + static const char * CALL_VOLUME_BUTTON = "CallVolumeButton"; //通话音量 + static const char * MEDIAVOLUMEBUTTON = "MediaVolumeButton"; //媒体音量 + static const char * VIBRATION_REMINDER_TOGGLEBUTTON = "VibrationReminderToggleButton";//震动提醒 + static const char * SILENT_MODEL_TOGGLEBUTTON = "SilentModeToggleButton"; //静音模式 + class SoundAndVibrationPresenter; + class SoundAndVibrationView : public View + { + + public: + SoundAndVibrationView(); + virtual ~SoundAndVibrationView(); + static SoundAndVibrationView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + private: + void InitView(void); + void DeInit(void); + + private: + UIViewGroup *container_ = nullptr; + UIScrollView *SoundAndVibrationScrollView = nullptr; + UILabel *SoundAndVibrationLabel = nullptr; + UIButton *SystemVolumeButton = nullptr; + UIButton *CallVolumeButton = nullptr; + UIImageView *image1 = nullptr; + UIImageView *image2 = nullptr; + UIImageView *SilentModeImage = nullptr; + UILabel *SilentModeLabe_ = nullptr; + UIToggleButton * VibrationReminderToggleButton = nullptr; + UILabel *SilentModeLabel = nullptr; + UIImageView *VibrationReminderImage = nullptr; + UIToggleButton *SilentModeToggleButton = nullptr; + UILabel *VibrationReminderLabel = nullptr; + UIButton *MediaVolumeButton = nullptr; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/SystemVolumePresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/SystemVolumePresenter.h new file mode 100644 index 000000000..0d77621e7 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/SystemVolumePresenter.h @@ -0,0 +1,34 @@ +#ifndef SYSTEM_VOLUME_PRESENTER_H +#define SYSTEM_VOLUME_PRESENTER_H + +#include "Presenter.h" + +#include "SystemVolumeView.h" + +namespace OHOS +{ + class SystemVolumeView; + + class SystemVolumePresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + SystemVolumePresenter(); + virtual ~SystemVolumePresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static SystemVolumePresenter *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/nativeapp/nativeui/soundandvibration/include/SystemVolumeView.h b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/SystemVolumeView.h new file mode 100644 index 000000000..aa5ba647f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/include/SystemVolumeView.h @@ -0,0 +1,40 @@ +#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" +namespace OHOS +{ + static const char *SYSTEM_VOLUME_SLIDER = "SystemVolumeSlider"; + + class SystemVolumePresenter; + class SystemVolumeView : public View + { + + public: + SystemVolumeView(); + virtual ~SystemVolumeView(); + static SystemVolumeView *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 *SystemVolumeslider = nullptr; + UIImageView *SystemVolumeimageicon = nullptr; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/CallVolumePresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/CallVolumePresenter.cpp new file mode 100644 index 000000000..067f39a68 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/CallVolumePresenter.cpp @@ -0,0 +1,75 @@ +#include "AppViewIDs.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(){ + + g_pCallVolumePresenter = this; + } + + CallVolumePresenter::~CallVolumePresenter(){ + + g_pCallVolumePresenter = nullptr; + } + + CallVolumePresenter *CallVolumePresenter::GetInstance(){ + + return g_pCallVolumePresenter; + } + + void CallVolumePresenter::OnStart(){ + + Presenter::OnStart(); + } + + void CallVolumePresenter::OnPause(void){ + + Presenter::OnPause(); + } + + void CallVolumePresenter::OnResume(void){ + + Presenter::OnResume(); + } + + void CallVolumePresenter::OnStop(void){ + + Presenter::OnStop(); + } + + bool CallVolumePresenter::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 CallVolumePresenter::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/nativeapp/nativeui/soundandvibration/src/CallVolumeView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/CallVolumeView.cpp new file mode 100644 index 000000000..19cd72c0a --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/CallVolumeView.cpp @@ -0,0 +1,125 @@ +#include "soundandvibration/include/CallVolumeView.h" +#include "soundandvibration/include/CallVolumePresenter.h" +#include "UiConfig.h" + +/* +通话音量: +闹钟,计时器,秒表的音量 +*/ + +namespace OHOS +{ + + static CallVolumeView *g_pCallVolumeView{nullptr}; + + CallVolumeView::CallVolumeView() + { + g_pCallVolumeView = this; + } + + CallVolumeView::~CallVolumeView() + { + 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) + { + 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(CallVolumePresenter::GetInstance()); + container_->SetOnDragListener(draglistener); + container_->SetTouchable(true); + container_->SetDraggable(true); + /********************************************************************************************************/ + if (CallVolumeslider == nullptr) + { + CallVolumeslider = new UISlider(); + } + 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) + { + CallVolumeimageicon = new UIImageView(); + } + 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); + } + + void CallVolumeView::OnStart() + { + View::OnStart(); + InitView(); + RootView::GetInstance()->Add(container_); + } + + void CallVolumeView::OnSetUpView() + { + View::OnSetUpView(); + Draw(); + } + + void CallVolumeView::OnTearDownView() + { + View::OnTearDownView(); + return; + } + + void CallVolumeView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/MediaVolumePresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/MediaVolumePresenter.cpp new file mode 100644 index 000000000..f76bb1726 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/MediaVolumePresenter.cpp @@ -0,0 +1,75 @@ +#include "AppViewIDs.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/nativeapp/nativeui/soundandvibration/src/MediaVolumeView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/MediaVolumeView.cpp new file mode 100644 index 000000000..e3b94b2c9 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/MediaVolumeView.cpp @@ -0,0 +1,125 @@ +#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/nativeapp/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp new file mode 100644 index 000000000..6eacd8b40 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp @@ -0,0 +1,86 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "graphic_math.h" +#include "string.h" +#include "soundandvibration/include/SoundAndVibrationPresenter.h" + +namespace OHOS{ + + //当前Presenter属性实例化的内存指针 + static SoundAndVibrationPresenter *g_pSoundAndVibrationPresenter = nullptr; + + SoundAndVibrationPresenter::SoundAndVibrationPresenter(){ + + g_pSoundAndVibrationPresenter = this; + } + + SoundAndVibrationPresenter::~SoundAndVibrationPresenter(){ + + g_pSoundAndVibrationPresenter = nullptr; + } + + SoundAndVibrationPresenter *SoundAndVibrationPresenter::GetInstance(){ + + return g_pSoundAndVibrationPresenter; + } + + void SoundAndVibrationPresenter::OnStart(){ + + Presenter::OnStart(); + } + + void SoundAndVibrationPresenter::OnPause(void){ + + Presenter::OnPause(); + } + + void SoundAndVibrationPresenter::OnResume(void){ + + Presenter::OnResume(); + } + + void SoundAndVibrationPresenter::OnStop(void){ + + Presenter::OnStop(); + } + + bool SoundAndVibrationPresenter::OnDrag(UIView &view, const DragEvent &event){ + + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); + return true; + } + return false; + } + + bool SoundAndVibrationPresenter::OnClick(UIView &view, const ClickEvent &event){ + + // 根据控件id查找是哪个控件触发了点击回调 + UNUSED(event); + if (strcmp(view.GetViewId(), SYSTEM_VOLUME_BUTTON) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_SYSTEM_VOLUME); + return true; + } + else if(strcmp(view.GetViewId(), CALL_VOLUME_BUTTON) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_SYSTEM_VOLUME); + return true; + }else if(strcmp(view.GetViewId(), MEDIAVOLUMEBUTTON) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_SYSTEM_VOLUME); + return true; + } + else if(strcmp(view.GetViewId(), VIBRATION_REMINDER_TOGGLEBUTTON) == 0) + { + return true; + } + else if(strcmp(view.GetViewId(), SILENT_MODEL_TOGGLEBUTTON) == 0) + { + return true; + } + return false; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/SoundAndVibrationView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/SoundAndVibrationView.cpp new file mode 100644 index 000000000..f897635e6 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/SoundAndVibrationView.cpp @@ -0,0 +1,411 @@ +#include "common/image_cache_manager.h" +#include "UiConfig.h" +#include "ui_resource_image.h" + +#include "soundandvibration/include/SoundAndVibrationView.h" +#include "soundandvibration/include/SoundAndVibrationPresenter.h" + +/* +按优先级分为 +1.系统音量 +2通话音量 +3.媒体音量 + +震动提醒 +开/关 + +静音模式 +系统音量不受影响 + +*/ + +namespace OHOS +{ + + static SoundAndVibrationView *g_pSoundAndVibrationView{nullptr}; + + SoundAndVibrationView::SoundAndVibrationView() + { + g_pSoundAndVibrationView = this; + } + + SoundAndVibrationView::~SoundAndVibrationView() + { + DeInit(); + g_pSoundAndVibrationView = nullptr; + } + + SoundAndVibrationView *SoundAndVibrationView::GetInstance() + { + + return g_pSoundAndVibrationView; + } + void SoundAndVibrationView::InitView(void) + { + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, 466, 466); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + UIView::OnDragListener *draglistener = static_cast(SoundAndVibrationPresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + container_->SetTouchable(true); + container_->SetDraggable(true); + } + /***********************************************************************************************************/ + // Add ScrollView to App + if (SoundAndVibrationScrollView == nullptr) + { + SoundAndVibrationScrollView = new UIScrollView(); + } + SoundAndVibrationScrollView->SetPosition(0, 0); + SoundAndVibrationScrollView->Resize(466, 466); + SoundAndVibrationScrollView->SetViewId("SoundAndVibrationScrollView"); + SoundAndVibrationScrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + // Add to rootView + container_->Add(SoundAndVibrationScrollView); + SoundAndVibrationScrollView->SetVisible(true); + /***********************************************************************************************************/ + // Add Label to App + if (SoundAndVibrationLabel == nullptr) + { + SoundAndVibrationLabel = new UILabel(); + } + SoundAndVibrationLabel->SetPosition(158, 52); + SoundAndVibrationLabel->Resize(200, 60); + SoundAndVibrationLabel->SetViewId("SoundAndVibrationLabel"); + SoundAndVibrationLabel->SetStyle(STYLE_TEXT_FONT, 30); + SoundAndVibrationLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + // Set additional property + SoundAndVibrationLabel->SetText("声音与震动"); + SoundAndVibrationLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + SoundAndVibrationLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + SoundAndVibrationLabel->SetRollSpeed(6); + SoundAndVibrationLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + // Add to scrollView + SoundAndVibrationScrollView->Add(SoundAndVibrationLabel); + SoundAndVibrationLabel->SetVisible(true); + /***********************************************************************************************************/ + // Add SystemVolumeButton to App + if (SystemVolumeButton == nullptr) + { + SystemVolumeButton = new UIButton(); + } + SystemVolumeButton->SetPosition(43, 120); + SystemVolumeButton->Resize(380, 100); + SystemVolumeButton->SetViewId(SYSTEM_VOLUME_BUTTON); + SystemVolumeButton->SetStyle(STYLE_BORDER_RADIUS, 50); + // Set additional property + SystemVolumeButton->SetImageSrc(PNG_SYSTEM_VOLUME_IMAGE, nullptr); + SystemVolumeButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + SystemVolumeButton->SetStyleForState(STYLE_BORDER_RADIUS, 50, UIButton::PRESSED); + + // Add the CallBack about events + UIView::OnClickListener *SystemVolumeButtonClick = static_cast(SoundAndVibrationPresenter::GetInstance()); + SystemVolumeButton->SetOnClickListener(SystemVolumeButtonClick); + // Add to scrollView1 + SoundAndVibrationScrollView->Add(SystemVolumeButton); + SystemVolumeButton->SetVisible(true); + /***********************************************************************************************************/ + // Add CallVolumeButton to App + if (CallVolumeButton == nullptr) + { + CallVolumeButton = new UIButton(); + } + CallVolumeButton->SetPosition(43, 240); + CallVolumeButton->Resize(380, 100); + CallVolumeButton->SetViewId(CALL_VOLUME_BUTTON); + CallVolumeButton->SetStyle(STYLE_BORDER_RADIUS, 50); + CallVolumeButton->SetImageSrc(PNG_CALL_VOLUME_IMAGE, nullptr); + CallVolumeButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + CallVolumeButton->SetStyleForState(STYLE_BORDER_RADIUS, 50, UIButton::PRESSED); + // Add the CallBack about events + UIView::OnClickListener *CallVolumeButtonClick = static_cast(SoundAndVibrationPresenter::GetInstance()); + CallVolumeButton->SetOnClickListener(CallVolumeButtonClick); + // Add to SoundAndVibrationScrollView + SoundAndVibrationScrollView->Add(CallVolumeButton); + CallVolumeButton->SetVisible(true); + /***********************************************************************************************************/ + // Add MediaVolumeButton to App + if (MediaVolumeButton == nullptr) + { + MediaVolumeButton = new UIButton(); + } + MediaVolumeButton->SetPosition(43, 360); + MediaVolumeButton->Resize(380, 100); + MediaVolumeButton->SetViewId(MEDIAVOLUMEBUTTON); + + MediaVolumeButton->SetImageSrc(PNG_MEDIA_VOLUME_IMAGE, nullptr); + MediaVolumeButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + + // Add the CallBack about events + UIView::OnClickListener *MediaVolumeButtonClick = static_cast(SoundAndVibrationPresenter::GetInstance()); + MediaVolumeButton->SetOnClickListener(MediaVolumeButtonClick); + // Add to scrollView1 + SoundAndVibrationScrollView->Add(MediaVolumeButton); + MediaVolumeButton->SetVisible(true); + /***********************************************************************************************************/ + if (VibrationReminderImage == nullptr) + { + VibrationReminderImage = new UIImageView(); + } + VibrationReminderImage->SetPosition(43, 480); + VibrationReminderImage->Resize(100, 100); + VibrationReminderImage->SetViewId("VibrationReminderImage"); + VibrationReminderImage->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + VibrationReminderImage->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + VibrationReminderImage->SetStyle(STYLE_BORDER_RADIUS, 50); + VibrationReminderImage->SetSrc(PNG_SETTING_BACKGROUND_IMAGE); + SoundAndVibrationScrollView->Add(VibrationReminderImage); + VibrationReminderImage->SetVisible(true); + /***********************************************************************************************************/ + // Add Label to App + if (VibrationReminderLabel == nullptr) + { + VibrationReminderLabel = new UILabel(); + } + VibrationReminderLabel->SetPosition(90, 513); // widget's left position and top position + VibrationReminderLabel->Resize(120, 35); // widget's width and height + VibrationReminderLabel->SetViewId("VibrationReminderLabel"); // Set style + VibrationReminderLabel->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + VibrationReminderLabel->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + VibrationReminderLabel->SetStyle(STYLE_TEXT_FONT, 30); + VibrationReminderLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + // Set additional property + VibrationReminderLabel->SetText("震动提醒"); + VibrationReminderLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + VibrationReminderLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + VibrationReminderLabel->SetRollSpeed(6); + VibrationReminderLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + // Add to SoundAndVibrationScrollView + SoundAndVibrationScrollView->Add(VibrationReminderLabel); + VibrationReminderLabel->SetVisible(true); + /***********************************************************************************************************/ + // Add ToggleButton to App + if (VibrationReminderToggleButton == nullptr) + { + VibrationReminderToggleButton = new UIToggleButton(); + } + VibrationReminderToggleButton->SetPosition(298, 505); + VibrationReminderToggleButton->Resize(100, 50); + VibrationReminderToggleButton->SetViewId(VIBRATION_REMINDER_TOGGLEBUTTON); + VibrationReminderToggleButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + VibrationReminderToggleButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + VibrationReminderToggleButton->SetImages(PNG_TOGGLEBUTTON_ON_IMAGE,PNG_TOGGLEBUTTON_OFF_IMAGE); + // Add the CallBack about events + UIView::OnClickListener *VibrationReminderToggleButtonClick = static_cast(SoundAndVibrationPresenter::GetInstance()); + VibrationReminderToggleButton->SetOnClickListener(VibrationReminderToggleButtonClick); + // Add to SoundAndVibrationScrollView + SoundAndVibrationScrollView->Add(VibrationReminderToggleButton); + VibrationReminderToggleButton->SetVisible(true); + /***********************************************************************************************************/ + // Add ImageView to App + if (SilentModeImage == nullptr) + { + SilentModeImage = new UIImageView(); + } + SilentModeImage->SetPosition(43, 600); + SilentModeImage->Resize(380, 100); + SilentModeImage->SetViewId("SilentModeImage"); + SilentModeImage->SetStyle(STYLE_BORDER_RADIUS, 50); + SilentModeImage->SetSrc(PNG_SETTING_BACKGROUND_IMAGE); + // Add to scrollView1 + SoundAndVibrationScrollView->Add(SilentModeImage); + SilentModeImage->SetVisible(true); + /***********************************************************************************************************/ + if (SilentModeLabel == nullptr) + { + SilentModeLabel = new UILabel(); + } + SilentModeLabel->SetPosition(90, 620); + SilentModeLabel->Resize(120, 35); + SilentModeLabel->SetViewId("SilentModeLabel"); + SilentModeLabel->SetStyle(STYLE_TEXT_FONT, 30); + SilentModeLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + // Set additional property + SilentModeLabel->SetText("静音模式"); + SilentModeLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + SilentModeLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + SilentModeLabel->SetRollSpeed(6); + SilentModeLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + // Add to SoundAndVibrationScrollView + SoundAndVibrationScrollView->Add(SilentModeLabel); + SilentModeLabel->SetVisible(true); + /***********************************************************************************************************/ + if (SilentModeLabe_ == nullptr) + { + SilentModeLabe_ = new UILabel(); + } + SilentModeLabe_->SetPosition(90, 657); + SilentModeLabe_->Resize(160, 23); + SilentModeLabe_->SetViewId("label9"); + SilentModeLabe_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + SilentModeLabe_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + SilentModeLabe_->SetStyle(STYLE_TEXT_FONT, 20); + SilentModeLabe_->SetStyle(STYLE_LINE_HEIGHT, 23); + // Set additional property + SilentModeLabe_->SetText("系统音量不受影响"); + SilentModeLabe_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + SilentModeLabe_->SetTextColor(Color::GetColorFromRGBA(0xfd, 0xfd, 0xfd, 0x7f)); + SilentModeLabe_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + SilentModeLabe_->SetRollSpeed(6); + SilentModeLabe_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); + // Add to SoundAndVibrationScrollView + SoundAndVibrationScrollView->Add(SilentModeLabe_); + SilentModeLabe_->SetVisible(true); + /***********************************************************************************************************/ + // Add SilentModeToggleButton to App + if (SilentModeToggleButton == nullptr) + { + SilentModeToggleButton = new UIToggleButton(); + } + SilentModeToggleButton->SetPosition(298, 625); + SilentModeToggleButton->Resize(100, 50); + SilentModeToggleButton->SetViewId(SILENT_MODEL_TOGGLEBUTTON); + SilentModeToggleButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + SilentModeToggleButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + SilentModeToggleButton->SetImages(PNG_TOGGLEBUTTON_ON_IMAGE,PNG_TOGGLEBUTTON_OFF_IMAGE); + UIView::OnClickListener *SilentModeToggleButtonClick = static_cast(SoundAndVibrationPresenter::GetInstance()); + SilentModeToggleButton->SetOnClickListener(SilentModeToggleButtonClick); + // Add to scrollView1 + SoundAndVibrationScrollView->Add(SilentModeToggleButton); + SilentModeToggleButton->SetVisible(true); + /***********************************************************************************************************/ + // Add ImageView to App + if (image1 == nullptr) + { + image1 = new UIImageView(); + } + image1->SetPosition(183, 18); + image1->Resize(100, 100); + image1->SetViewId("image1"); + + SoundAndVibrationScrollView->Add(image1); + image1->SetVisible(true); + /***********************************************************************************************************/ + // Add ImageView to App + if (image2 == nullptr) + { + image2 = new UIImageView(); + } + image2->SetPosition(183, 668); + image2->Resize(100, 100); + image2->SetViewId("image2"); + + SoundAndVibrationScrollView->Add(image2); + image2->SetVisible(true); + } + + void SoundAndVibrationView::DeInit() + { + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + if (SoundAndVibrationScrollView != nullptr) + { + delete SoundAndVibrationScrollView; + SoundAndVibrationScrollView = nullptr; + } + if (SoundAndVibrationLabel != nullptr) + { + delete SoundAndVibrationLabel; + SoundAndVibrationLabel = nullptr; + } + if (SystemVolumeButton != nullptr) + { + delete SystemVolumeButton; + SystemVolumeButton = nullptr; + } + if (CallVolumeButton != nullptr) + { + delete CallVolumeButton; + CallVolumeButton = nullptr; + } + if (image1 != nullptr) + { + delete image1; + image1 = nullptr; + } + if (image2 != nullptr) + { + delete image2; + image2 = nullptr; + } + if (SilentModeImage != nullptr) + { + delete SilentModeImage; + SilentModeImage = nullptr; + } + if (SilentModeLabe_ != nullptr) + { + delete SilentModeLabe_; + SilentModeLabe_ = nullptr; + } + if (VibrationReminderToggleButton != nullptr) + { + delete VibrationReminderToggleButton; + VibrationReminderToggleButton = nullptr; + } + if (SilentModeLabel != nullptr) + { + delete SilentModeLabel; + SilentModeLabel = nullptr; + } + if (VibrationReminderImage != nullptr) + { + delete VibrationReminderImage; + VibrationReminderImage = nullptr; + } + if (SilentModeToggleButton != nullptr) + { + delete SilentModeToggleButton; + SilentModeToggleButton = nullptr; + } + if (VibrationReminderLabel != nullptr) + { + delete VibrationReminderLabel; + VibrationReminderLabel = nullptr; + } + if (MediaVolumeButton != nullptr) + { + delete MediaVolumeButton; + MediaVolumeButton = nullptr; + } + } + + void SoundAndVibrationView::OnStart() + { + View::OnStart(); + InitView(); + RootView::GetInstance()->Add(container_); + } + + void SoundAndVibrationView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void SoundAndVibrationView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void SoundAndVibrationView::OnStop() + { + + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/SystemVolumePresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/SystemVolumePresenter.cpp new file mode 100644 index 000000000..e688e1bf7 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/SystemVolumePresenter.cpp @@ -0,0 +1,75 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "graphic_math.h" +#include "string.h" +#include "soundandvibration/include/SystemVolumePresenter.h" +//系统音量 +namespace OHOS{ + + //当前Presenter属性实例化的内存指针 + static SystemVolumePresenter *g_pSystemVolumePresenter = nullptr; + + SystemVolumePresenter::SystemVolumePresenter(){ + + g_pSystemVolumePresenter = this; + } + + SystemVolumePresenter::~SystemVolumePresenter(){ + + g_pSystemVolumePresenter = nullptr; + } + + SystemVolumePresenter *SystemVolumePresenter::GetInstance(){ + + return g_pSystemVolumePresenter; + } + + void SystemVolumePresenter::OnStart(){ + + Presenter::OnStart(); + } + + void SystemVolumePresenter::OnPause(void){ + + Presenter::OnPause(); + } + + void SystemVolumePresenter::OnResume(void){ + + Presenter::OnResume(); + } + + void SystemVolumePresenter::OnStop(void){ + + Presenter::OnStop(); + } + + bool SystemVolumePresenter::OnDrag(UIView &view, const DragEvent &event){ + + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + (event.GetDeltaX() > 30) && (event.GetDeltaX() > (3 * MATH_ABS(event.GetDeltaY())))) + { + //NativeAbility::GetInstance().ChangeSlice(VIEW_SOUND_VIBRATION); + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); + } + return true; + } + + bool SystemVolumePresenter::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/nativeapp/nativeui/soundandvibration/src/SystemVolumeView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/SystemVolumeView.cpp new file mode 100644 index 000000000..a781c47a8 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/soundandvibration/src/SystemVolumeView.cpp @@ -0,0 +1,125 @@ +#include "soundandvibration/include/SystemVolumeView.h" +#include "soundandvibration/include/SystemVolumePresenter.h" +#include "UiConfig.h" + +/* +系统音量: +通话,提醒,查找手表的音量 +*/ + +namespace OHOS +{ + + static SystemVolumeView *g_pSystemVolumeView{nullptr}; + + SystemVolumeView::SystemVolumeView() + { + g_pSystemVolumeView = this; + } + + SystemVolumeView::~SystemVolumeView() + { + g_pSystemVolumeView = nullptr; + if (container_ != nullptr) + { + delete container_; + container_ = nullptr; + } + if (SystemVolumeslider != nullptr) + { + delete SystemVolumeslider; + SystemVolumeslider = nullptr; + } + if (SystemVolumeimageicon != nullptr) + { + delete SystemVolumeimageicon; + SystemVolumeimageicon = nullptr; + } + } + + SystemVolumeView *SystemVolumeView::GetInstance() + { + + return g_pSystemVolumeView; + } + void SystemVolumeView::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(SystemVolumePresenter::GetInstance()); + container_->SetOnDragListener(draglistener); + container_->SetTouchable(true); + container_->SetDraggable(true); + /********************************************************************************************************/ + if (SystemVolumeslider == nullptr) + { + SystemVolumeslider = new UISlider(); + } + SystemVolumeslider->SetPosition(167, 77); + SystemVolumeslider->Resize(130, 310); + SystemVolumeslider->SetViewId(SYSTEM_VOLUME_SLIDER); + SystemVolumeslider->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + SystemVolumeslider->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + SystemVolumeslider->SetStyle(STYLE_BORDER_OPA, 0x19); + SystemVolumeslider->SetStyle(STYLE_BORDER_RADIUS, 100); + SystemVolumeslider->SetDirection(UISlider::Direction::DIR_BOTTOM_TO_TOP); + SystemVolumeslider->SetValue(50); + SystemVolumeslider->SetSliderColor(Color::GetColorFromRGBA(0x19, 0x19, 0x19, 0xff), Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); + SystemVolumeslider->SetKnobStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + SystemVolumeslider->SetForegroundStyle(STYLE_BACKGROUND_OPA, 0xff); + SystemVolumeslider->SetBackgroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND); // 圆帽式 + SystemVolumeslider->SetForegroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND); // 设置进度条的前景样式。圆帽式 + SystemVolumeslider->SetStyle(STYLE_BORDER_COLOR, Color::Black().full); + SystemVolumeslider->SetStyle(STYLE_BORDER_WIDTH,2); + sliderClick = static_cast(SystemVolumePresenter::GetInstance()); // 用来处理之后点击slider的点击事件 + SystemVolumeslider->SetOnClickListener(sliderClick); + sliderDrag = static_cast(SystemVolumePresenter::GetInstance()); // 用来处理之后拖动slider的拖动事件 + SystemVolumeslider->SetOnDragListener(sliderDrag); + container_->Add(SystemVolumeslider); + SystemVolumeslider->SetVisible(true); + /********************************************************************************************************/ + if (SystemVolumeimageicon == nullptr) + { + SystemVolumeimageicon = new UIImageView(); + } + SystemVolumeimageicon->SetPosition(213, 213); // widget's left position and top position + SystemVolumeimageicon->Resize(100, 100); // widget's width and height + SystemVolumeimageicon->SetViewId("SystemVolumeimageicon"); // Set style + SystemVolumeimageicon->SetStyle(STYLE_BORDER_COLOR, 0xffAAAAAA); + SystemVolumeimageicon->SetSrc(PNG_VOLUME_CONTROL_VECTOR); + + container_->Add(SystemVolumeimageicon); + SystemVolumeimageicon->SetVisible(true); + } + + void SystemVolumeView::OnStart() + { + View::OnStart(); + InitView(); + RootView::GetInstance()->Add(container_); + } + + void SystemVolumeView::OnSetUpView() + { + View::OnSetUpView(); + Draw(); + } + + void SystemVolumeView::OnTearDownView() + { + View::OnTearDownView(); + return; + } + + void SystemVolumeView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +}