#声音与震动
${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/SoundAndVibrationModel.cpp
${CMAKE_CURRENT_SOURCE_DIR}/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingView.cpp
${CMAKE_CURRENT_SOURCE_DIR}/nativeui/soundandvibration/src/SystemVolumePresenter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/nativeui/soundandvibration/src/SystemVolumeView.cpp
--- /dev/null
+#ifndef SOUND_AND_VIBRATION_MODEL_H
+#define SOUND_AND_VIBRATION_MODEL_H
+
+namespace OHOS
+{
+ class SoundAndVibrationModel
+ {
+ public:
+ static SoundAndVibrationModel *GetInstance(void);
+
+ void SetVibrationReminderToggleButtonStaus(bool value);
+ bool VibrationReminderToggleButtonStatusInit(void);
+ void SetSilentModeToggleButtonStatus(bool value);
+ bool SilentModeToggleButtonStatusInit(void);
+
+ private:
+ SoundAndVibrationModel();
+ SoundAndVibrationModel(const SoundAndVibrationModel &);
+ SoundAndVibrationModel &operator=(const SoundAndVibrationModel &);
+ virtual ~SoundAndVibrationModel();
+
+ private:
+ bool VibrationReminderToggleButtonState{false}; // “震动提醒”切换按钮状态
+ bool SilentModeToggleButtonState{false}; // “静音模式”切换按钮状态
+ };
+}
+
+#endif
\ No newline at end of file
\r
#include "Presenter.h"\r
#include "SoundAndVibrationView.h"\r
- \r
+\r
namespace OHOS\r
{\r
+ class SoundAndVibrationViewOnChangeListener : public UICheckBox::OnChangeListener\r
+ {\r
+ public:\r
+ SoundAndVibrationViewOnChangeListener(UIView *view)\r
+ {\r
+ view_ = view;\r
+ }\r
+\r
+ ~SoundAndVibrationViewOnChangeListener() {}\r
+\r
+ bool OnChange(UICheckBox::UICheckBoxState state) override;\r
+\r
+ private:\r
+ UIView *view_{nullptr};\r
+ };\r
+\r
class SoundAndVibrationView;\r
- \r
class SoundAndVibrationPresenter : public Presenter<SoundAndVibrationView>,\r
- public UIView::OnClickListener,\r
- public UIView::OnDragListener\r
+ public UIView::OnClickListener,\r
+ public UIView::OnDragListener\r
{\r
public:\r
SoundAndVibrationPresenter();\r
virtual ~SoundAndVibrationPresenter();\r
- \r
- void OnStart() override; \r
- void OnPause() override; \r
- void OnResume() override; \r
- void OnStop() override; \r
- \r
- static SoundAndVibrationPresenter *GetInstance(); \r
- \r
- private:\r
- //因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承;\r
- bool OnClick(UIView &view, const ClickEvent &event) override; \r
- bool OnDrag(UIView &view, const DragEvent &event) override; \r
- };\r
-} //namespace OHOS\r
-\r
\r
+ void OnStart() override;\r
+ void OnPause() override;\r
+ void OnResume() override;\r
+ void OnStop() override;\r
\r
+ static SoundAndVibrationPresenter *GetInstance();\r
+ void VibrationReminderToggleButtonStateSetting(bool value);\r
+ void SilentModeToggleButtonStateSetting(bool value);\r
+ private:\r
+ // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承;\r
+ bool OnClick(UIView &view, const ClickEvent &event) override;\r
+ bool OnDrag(UIView &view, const DragEvent &event) override;\r
+ bool OnDragEnd(UIView &view, const DragEvent &event) override;\r
+ private:\r
+ UIView *view_{nullptr};\r
+ };\r
+} // namespace OHOS\r
\r
#endif
\ No newline at end of file
static const char *SYSTEM_VOLUME_BUTTON = "SystemVolumeButton"; // 系统音量按钮ID\r
static const char *CALL_VOLUME_BUTTON = "CallVolumeButton"; // 通话音量按钮ID\r
static const char *MEDIA_VOLUME_BUTTON = "MediaVolumeButton"; // 媒体音量按钮ID\r
- static const char *VIBRATION_REMINDER_TOGGLEBUTTON = "VibrationReminderToggleButton"; // 震动提醒\r
- static const char *SILENT_MODEL_TOGGLEBUTTON = "SilentModeToggleButton"; // 静音模式\r
class SoundAndVibrationPresenter;\r
class SoundAndVibrationView : public View<SoundAndVibrationPresenter>\r
{\r
virtual ~SoundAndVibrationView();\r
static SoundAndVibrationView *GetInstance(void);\r
\r
+ void SetVibrationReminderToggleButtonState(bool value);\r
+ void SetSilentModeToggleButtonState(bool value);\r
+ bool GetVibrationReminderToggleButtonState(void);\r
+ bool GetSilentModeToggleButtonState(void);\r
+ UIToggleButton * GetVibrationReminderToggleButton();\r
+ UIToggleButton * GetSilentModeToggleButton();\r
+\r
void OnStart() override;\r
void OnSetUpView() override;\r
void OnTearDownView() override;\r
UIImageView *SilentModeImageView{nullptr}; //\r
UIToggleButton *VibrationReminderToggleButton{nullptr}; // 震动提醒切换按钮\r
UIToggleButton *SilentModeToggleButton{nullptr}; // 静音模式切换按钮\r
+ UICheckBox::OnChangeListener *VibrationReminderToggleButtonChangeListener{nullptr};\r
+ UICheckBox::OnChangeListener *SilentModeToggleButtonChangeListener{nullptr};\r
bool initViewStatus{false};\r
};\r
} // namespace OHOS\r
--- /dev/null
+#include "soundandvibration/include/SoundAndVibrationModel.h"
+#include "soundandvibration/include/SoundAndVibrationPresenter.h"
+#include "wearable_log.h"
+namespace OHOS
+{
+
+ SoundAndVibrationModel::SoundAndVibrationModel() {}
+
+ SoundAndVibrationModel::~SoundAndVibrationModel() {}
+
+ SoundAndVibrationModel *SoundAndVibrationModel::GetInstance(void)
+ {
+ static SoundAndVibrationModel instance;
+ return &instance;
+ }
+
+ /// @brief 设置“震动提醒”是否开启
+ /// @param value
+ void SoundAndVibrationModel::SetVibrationReminderToggleButtonStaus(bool value)
+ {
+ VibrationReminderToggleButtonState = value;
+ }
+
+ /// @brief “震动提醒”切换按钮状态初始化
+ /// @param void
+ /// @return true 初始化成功 false 初始化失败
+ bool SoundAndVibrationModel::VibrationReminderToggleButtonStatusInit(void)
+ {
+ SoundAndVibrationPresenter *p_SoundAndVibrationPresenter = SoundAndVibrationPresenter::GetInstance();
+ if (p_SoundAndVibrationPresenter == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VibrationReminderToggleButtonStatusInit SoundAndVibrationPresenter GetInstance fail!");
+ return false;
+ }
+ p_SoundAndVibrationPresenter->VibrationReminderToggleButtonStateSetting(VibrationReminderToggleButtonState);
+ return true;
+ }
+
+ /// @brief 设置“静音模式”是否开启
+ /// @param value
+ void SoundAndVibrationModel::SetSilentModeToggleButtonStatus(bool value)
+ {
+ SilentModeToggleButtonState = value;
+ }
+
+ /// @brief “静音模式”切换按钮状态初始化
+ /// @param void
+ /// @return true 初始化成功 false 初始化失败
+ bool SoundAndVibrationModel::SilentModeToggleButtonStatusInit(void)
+ {
+ SoundAndVibrationPresenter *p_SoundAndVibrationPresenter = SoundAndVibrationPresenter::GetInstance();
+ if (p_SoundAndVibrationPresenter == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SilentModeToggleButtonStatusInit SoundAndVibrationPresenter GetInstance fail!");
+ return false;
+ }
+ p_SoundAndVibrationPresenter->SilentModeToggleButtonStateSetting(SilentModeToggleButtonState);
+ return true;
+ }
+
+}
#include "graphic_math.h"\r
#include "string.h"\r
#include "soundandvibration/include/SoundAndVibrationPresenter.h"\r
- \r
-namespace OHOS{\r
- \r
- //当前Presenter属性实例化的内存指针\r
- static SoundAndVibrationPresenter *g_pSoundAndVibrationPresenter = nullptr; \r
- \r
- SoundAndVibrationPresenter::SoundAndVibrationPresenter(){\r
- \r
+#include "soundandvibration/include/SoundAndVibrationModel.h"\r
+namespace OHOS\r
+{\r
+\r
+ // 当前Presenter属性实例化的内存指针\r
+ static SoundAndVibrationPresenter *g_pSoundAndVibrationPresenter = nullptr;\r
+\r
+ SoundAndVibrationPresenter::SoundAndVibrationPresenter()\r
+ {\r
+\r
g_pSoundAndVibrationPresenter = this;\r
}\r
- \r
- SoundAndVibrationPresenter::~SoundAndVibrationPresenter(){\r
- \r
+\r
+ SoundAndVibrationPresenter::~SoundAndVibrationPresenter()\r
+ {\r
+\r
g_pSoundAndVibrationPresenter = nullptr;\r
}\r
- \r
- SoundAndVibrationPresenter *SoundAndVibrationPresenter::GetInstance(){\r
- \r
+\r
+ SoundAndVibrationPresenter *SoundAndVibrationPresenter::GetInstance()\r
+ {\r
+\r
return g_pSoundAndVibrationPresenter;\r
}\r
- \r
- void SoundAndVibrationPresenter::OnStart(){\r
- \r
- Presenter<SoundAndVibrationView>::OnStart(); \r
+\r
+ /// @brief "震动提醒"按钮状态设置\r
+ /// @param value true 开启 false 关闭\r
+ void SoundAndVibrationPresenter::VibrationReminderToggleButtonStateSetting(bool value)\r
+ {\r
+ SoundAndVibrationView *p_SoundAndVibrationView = SoundAndVibrationView::GetInstance();\r
+ if (p_SoundAndVibrationView == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VibrationReminderToggleButtonStateSetting SoundAndVibrationView GetInstance fail!");\r
+ return;\r
+ }\r
+ if (value != false)\r
+ {\r
+ p_SoundAndVibrationView->SetVibrationReminderToggleButtonState(true);\r
+ SoundAndVibrationModel::GetInstance()->SetVibrationReminderToggleButtonStaus(false); // 将Model层保存的状态清除\r
+ }\r
+ }\r
+\r
+ /// @brief "静音模式"按钮状态设置\r
+ /// @param value true 开启 false 关闭\r
+ void SoundAndVibrationPresenter::SilentModeToggleButtonStateSetting(bool value)\r
+ {\r
+ SoundAndVibrationView *p_SoundAndVibrationView = SoundAndVibrationView::GetInstance();\r
+ if (p_SoundAndVibrationView == nullptr)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SilentModeToggleButtonStateSetting SoundAndVibrationView GetInstance fail!");\r
+ return;\r
+ }\r
+ if (value != false)\r
+ {\r
+ p_SoundAndVibrationView->SetSilentModeToggleButtonState(true);\r
+ SoundAndVibrationModel::GetInstance()->SetSilentModeToggleButtonStatus(false); // 将Model层保存的状态清除\r
+ }\r
}\r
- \r
- void SoundAndVibrationPresenter::OnPause(void){\r
- \r
+\r
+ void SoundAndVibrationPresenter::OnStart()\r
+ {\r
+\r
+ Presenter<SoundAndVibrationView>::OnStart();\r
+ }\r
+\r
+ void SoundAndVibrationPresenter::OnPause(void)\r
+ {\r
+\r
Presenter<SoundAndVibrationView>::OnPause();\r
}\r
- \r
- void SoundAndVibrationPresenter::OnResume(void){\r
- \r
+\r
+ void SoundAndVibrationPresenter::OnResume(void)\r
+ {\r
+\r
Presenter<SoundAndVibrationView>::OnResume();\r
}\r
- \r
- void SoundAndVibrationPresenter::OnStop(void){\r
- \r
- Presenter<SoundAndVibrationView>::OnStop(); \r
+\r
+ void SoundAndVibrationPresenter::OnStop(void)\r
+ {\r
+\r
+ Presenter<SoundAndVibrationView>::OnStop();\r
+ }\r
+\r
+ bool SoundAndVibrationPresenter::OnDrag(UIView &view, const DragEvent &event)\r
+ {\r
+ return true;\r
}\r
- \r
- bool SoundAndVibrationPresenter::OnDrag(UIView &view, const DragEvent &event){\r
- \r
- if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT &&\r
- (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY()))))\r
+\r
+ bool SoundAndVibrationPresenter::OnDragEnd(UIView &view, const DragEvent &event)\r
+ {\r
+ if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)\r
{\r
NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING);\r
- return true;\r
}\r
- return false;\r
+ return true;\r
}\r
- \r
- bool SoundAndVibrationPresenter::OnClick(UIView &view, const ClickEvent &event){\r
- \r
+\r
+ bool SoundAndVibrationPresenter::OnClick(UIView &view, const ClickEvent &event)\r
+ {\r
+\r
// 根据控件id查找是哪个控件触发了点击回调\r
UNUSED(event);\r
if (strcmp(view.GetViewId(), SYSTEM_VOLUME_BUTTON) == 0)\r
NativeAbility::GetInstance().ChangeSlice(VIEW_SYSTEM_VOLUME);\r
return true;\r
}\r
- else if(strcmp(view.GetViewId(), CALL_VOLUME_BUTTON) == 0)\r
+ else if (strcmp(view.GetViewId(), CALL_VOLUME_BUTTON) == 0)\r
{\r
NativeAbility::GetInstance().ChangeSlice(VIEW_SYSTEM_VOLUME);\r
return true;\r
- }else if(strcmp(view.GetViewId(), MEDIA_VOLUME_BUTTON) == 0)\r
+ }\r
+ else if (strcmp(view.GetViewId(), MEDIA_VOLUME_BUTTON) == 0)\r
{\r
NativeAbility::GetInstance().ChangeSlice(VIEW_SYSTEM_VOLUME);\r
return true;\r
}\r
- else if(strcmp(view.GetViewId(), VIBRATION_REMINDER_TOGGLEBUTTON) == 0)\r
+ return false;\r
+ }\r
+\r
+ bool SoundAndVibrationViewOnChangeListener::OnChange(UICheckBox::UICheckBoxState state)\r
+ {\r
+ SoundAndVibrationView *p_SoundAndVibrationView = SoundAndVibrationView::GetInstance();\r
+ if (p_SoundAndVibrationView == nullptr)\r
{\r
- return true;\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::GetInstance fail!");\r
+ return false;\r
}\r
- else if(strcmp(view.GetViewId(), SILENT_MODEL_TOGGLEBUTTON) == 0)\r
+\r
+ switch (state)\r
{\r
- return true;\r
+ case UICheckBox::SELECTED:\r
+ if (p_SoundAndVibrationView->GetVibrationReminderToggleButton() == (UIView *)view_)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VibrationReminder is enable!");\r
+\r
+ return true;\r
+ }\r
+ else if (p_SoundAndVibrationView->GetSilentModeToggleButton() == (UIView *)view_)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SilentMode is enable!");\r
+\r
+ return true;\r
+ }\r
+ break;\r
+ case UICheckBox::UNSELECTED:\r
+ if (p_SoundAndVibrationView->GetVibrationReminderToggleButton() == (UIView *)view_)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VibrationReminder is disable!");\r
+\r
+ return true;\r
+ }\r
+ else if (p_SoundAndVibrationView->GetSilentModeToggleButton() == (UIView *)view_)\r
+ {\r
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SilentMode is disable!");\r
+\r
+ return true;\r
+ }\r
+ break;\r
+ default:\r
+ break;\r
}\r
return false;\r
}\r
+\r
}
\ No newline at end of file
#include "soundandvibration/include/SoundAndVibrationView.h"\r
#include "soundandvibration/include/SoundAndVibrationPresenter.h"\r
+#include "soundandvibration/include/SoundAndVibrationModel.h"\r
#include "wearable_log.h"\r
/*\r
按优先级分为\r
if (initViewStatus == true)\r
{\r
SoundAndVibrationScrollView->RemoveAll();\r
+\r
+ bool state = GetVibrationReminderToggleButtonState();\r
+ if (state == true)\r
+ {\r
+ SoundAndVibrationModel::GetInstance()->SetVibrationReminderToggleButtonStaus(true);\r
+ }\r
+ state = GetSilentModeToggleButtonState();\r
+\r
+ if (state == true)\r
+ {\r
+ SoundAndVibrationModel::GetInstance()->SetSilentModeToggleButtonStatus(true);\r
+ }\r
+\r
delete Title;\r
Title = nullptr;\r
+\r
delete SystemVolumeButton;\r
SystemVolumeButton = nullptr;\r
\r
VibrationReminderImageView = nullptr;\r
\r
delete SilentModeImageView;\r
- SilentModeImageView;\r
+ SilentModeImageView = nullptr;\r
+\r
+ delete VibrationReminderToggleButtonChangeListener;\r
+ VibrationReminderToggleButtonChangeListener = nullptr;\r
+\r
+ delete SilentModeToggleButtonChangeListener;\r
+ SilentModeToggleButtonChangeListener = nullptr;\r
\r
delete VibrationReminderToggleButton;\r
VibrationReminderToggleButton = nullptr;\r
{417, "音乐、录音、训练"},\r
{657, "系统音量不受影响"},\r
};\r
- for (int i = 0; i < sizeof(labelInfo) / sizeof(labelInfo[0]); i++)\r
+ for (int i = 0; i < (int)(sizeof(labelInfo) / sizeof(labelInfo[0])); i++)\r
{\r
LabelConfig labelConfig = {\r
.left = 90,\r
\r
bool SoundAndVibrationView::InitSoundAndVibrationToggleButton(void)\r
{\r
- UIView::OnClickListener *ButtonClick = static_cast<UIView::OnClickListener *>(SoundAndVibrationPresenter::GetInstance());\r
/* ---------------------- VibrationReminderToggleButton --------------------- */\r
VibrationReminderToggleButton = new UIToggleButton();\r
if (VibrationReminderToggleButton == nullptr)\r
return false;\r
}\r
VibrationReminderToggleButton->SetPosition(298, 505, 100, 50);\r
- VibrationReminderToggleButton->SetViewId(VIBRATION_REMINDER_TOGGLEBUTTON);\r
VibrationReminderToggleButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00);\r
VibrationReminderToggleButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);\r
const char *ToggleButtonSelect = "/user/res/TOGGLEBUTTON_ON.bin";\r
const char *ToggleButtonUnSelect = "/user/res/TOGGLEBUTTON_OFF.bin";\r
VibrationReminderToggleButton->SetImages(ToggleButtonSelect, ToggleButtonUnSelect);\r
- VibrationReminderToggleButton->SetOnClickListener(ButtonClick);\r
+ VibrationReminderToggleButtonChangeListener = new SoundAndVibrationViewOnChangeListener(reinterpret_cast<UIView *>(VibrationReminderToggleButton));\r
+ VibrationReminderToggleButton->SetOnChangeListener(VibrationReminderToggleButtonChangeListener);\r
/* ------------------------- SilentModeToggleButton ------------------------- */\r
SilentModeToggleButton = new UIToggleButton();\r
if (SilentModeToggleButton == nullptr)\r
return false;\r
}\r
SilentModeToggleButton->SetPosition(298, 625, 100, 50);\r
- SilentModeToggleButton->SetViewId(SILENT_MODEL_TOGGLEBUTTON);\r
SilentModeToggleButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00);\r
SilentModeToggleButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);\r
SilentModeToggleButton->SetImages(ToggleButtonSelect, ToggleButtonUnSelect);\r
- SilentModeToggleButton->SetOnClickListener(ButtonClick);\r
+ SilentModeToggleButtonChangeListener = new SoundAndVibrationViewOnChangeListener(reinterpret_cast<UIView *>(SilentModeToggleButton));\r
+ SilentModeToggleButton->SetOnChangeListener(SilentModeToggleButtonChangeListener);\r
return true;\r
}\r
\r
+ /// @brief 获取"震动提醒"按钮开,关状态\r
+ /// @param void\r
+ /// @return true 开 false 关\r
+ bool SoundAndVibrationView::GetVibrationReminderToggleButtonState(void)\r
+ {\r
+ return VibrationReminderToggleButton->GetState();\r
+ }\r
+\r
+ /// @brief 获取"静音模式"按钮开,关状态\r
+ /// @param void\r
+ /// @return true 开 false 关\r
+ bool SoundAndVibrationView::GetSilentModeToggleButtonState(void)\r
+ {\r
+ return SilentModeToggleButton->GetState();\r
+ }\r
+\r
+ /// @brief 设置"震动提醒"按钮开,关状态\r
+ /// @param value\r
+ void SoundAndVibrationView::SetVibrationReminderToggleButtonState(bool value)\r
+ {\r
+ VibrationReminderToggleButton->SetState(value);\r
+ }\r
+\r
+ /// @brief 设置"静音模式"按钮开,关状态\r
+ /// @param value\r
+ void SoundAndVibrationView::SetSilentModeToggleButtonState(bool value)\r
+ {\r
+ SilentModeToggleButton->SetState(value);\r
+ }\r
+\r
+ /// @brief 获取"震动提醒"切换按钮\r
+ UIToggleButton *SoundAndVibrationView::GetVibrationReminderToggleButton(void)\r
+ {\r
+ return VibrationReminderToggleButton;\r
+ }\r
+\r
+ /// @brief 获取"静音模式"切换按钮\r
+ UIToggleButton *SoundAndVibrationView::GetSilentModeToggleButton(void)\r
+ {\r
+ return SilentModeToggleButton;\r
+ }\r
+\r
void SoundAndVibrationView::InitView(void)\r
{\r
if (InitSoundAndVibrationScrollView() == false)\r
{\r
return;\r
}\r
+ if (SoundAndVibrationModel::GetInstance()->VibrationReminderToggleButtonStatusInit() == false)\r
+ {\r
+ return;\r
+ }\r
+ if (SoundAndVibrationModel::GetInstance()->SilentModeToggleButtonStatusInit() == false)\r
+ {\r
+ return;\r
+ }\r
initViewStatus = true;\r
}\r
\r