From d3ba9a4b45a792b752fe4956244f8d581ccdbf23 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Wed, 24 Jul 2024 17:57:31 +0800 Subject: [PATCH] =?utf8?q?=E5=A3=B0=E9=9F=B3=E4=B8=8E=E9=9C=87=E5=8A=A8Sli?= =?utf8?q?ce=E4=BC=98=E5=8C=96=EF=BC=9A=201.=E8=A7=A3=E5=86=B3=E5=A6=82?= =?utf8?q?=E6=9E=9C=E6=98=AF=E7=82=B9=E5=87=BB=E8=AE=BE=E7=BD=AE=E9=9F=B3?= =?utf8?q?=E9=87=8F=E9=80=80=E5=87=BASlice=E6=9C=AA=E5=B0=86=E9=9F=B3?= =?utf8?q?=E9=87=8F=E5=80=BC=E4=BF=9D=E5=AD=98=E7=9A=84=E9=97=AE=E9=A2=98?= =?utf8?q?=202.=E4=BC=98=E5=8C=96=E4=BA=86=E5=A6=82=E6=9E=9C=E6=98=AF?= =?utf8?q?=E6=8B=96=E6=8B=BD=E8=AE=BE=E7=BD=AE=E8=87=B4=E4=BD=BF=E5=A4=9A?= =?utf8?q?=E6=AC=A1=E8=B0=83=E7=94=A8OnChange=EF=BC=8C=E5=AE=9E=E9=99=85?= =?utf8?q?=E4=B8=8A=E6=88=91=E4=BB=AC=E5=8F=AA=E8=A6=81=E6=88=91=E4=BB=AC?= =?utf8?q?=E6=89=8B=E6=8C=87=E7=A6=BB=E5=BC=80=E5=B1=8F=E5=B9=95=E6=9C=80?= =?utf8?q?=E5=90=8E=E8=AE=BE=E7=BD=AE=E7=9A=84=E5=80=BC=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../src/RebootAndShutdownView.cpp | 6 +- .../include/SoundAndVibrationView.h | 21 ++- .../SoundAndVibrationVolumeSettingPresenter.h | 10 +- .../soundandvibration/src/CallVolumeView.cpp | 5 + .../src/SoundAndVibrationView.cpp | 172 ++++++++++++++---- ...oundAndVibrationVolumeSettingPresenter.cpp | 91 +++++++-- .../SoundAndVibrationVolumeSettingView.cpp | 44 +++-- .../src/SystemVolumeView.cpp | 7 +- .../src/VibrationModeView.cpp | 9 +- 9 files changed, 282 insertions(+), 83 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownView.cpp b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownView.cpp index 19caa9591..f7cea52ec 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-07-18 14:26:08 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-20 15:09:36 + * @LastEditTime: 2024-07-24 17:35:57 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownView.cpp */ @@ -498,13 +498,13 @@ namespace OHOS { if (showView < 0 || showView >= REBOOTANDSHUTDOWN_MAX) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "REBOOTANDSHUTDOWN_MAX::CheckViewParam showView err."); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RebootAndShutdownView::CheckViewParam showView err."); return false; } if (hideView < 0 || hideView > REBOOTANDSHUTDOWN_MAX) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "REBOOTANDSHUTDOWN_MAX::CheckViewParam hideView err."); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RebootAndShutdownView::CheckViewParam hideView err."); return false; } 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 b8c021bac..44ec1d184 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-19 21:03:26 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-19 17:44:40 + * @LastEditTime: 2024-07-24 17:33:52 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationView.h */ #ifndef SOUND_AND_VIBRATION_VIEW_H @@ -43,15 +43,26 @@ namespace OHOS int16_t w; int16_t h; const char *ViewId; - // std::string Text; int16_t TextId; }; + struct LabelConfig + { + int16_t left; + int16_t top; + int16_t width; + int16_t height; + int16_t fontSize; + int16_t lineHeigh; + int16_t textId; + uint8_t lineBreakMode; + }; SoundAndVibrationView(); virtual ~SoundAndVibrationView(); static SoundAndVibrationView *GetInstance(void); bool ChangeSoundAndVibrationView(int16_t thisView); bool ChangeVibrationModeView(int16_t thisView); bool ClickFunc(int16_t interface); + bool CheckViewParam(int16_t hideView, int16_t showView); void ChangeView(int16_t hideView, int16_t showView); VibrationModeView *GetVibrationModeView(void); bool UpdateSilentModeSwitchStatus(void); @@ -68,6 +79,7 @@ namespace OHOS void CreateSoundAndVibrationView(void); void ClearAll(void); UILabelButtonExt *SetUpButton_Ext(ButtonConfig &buttonconfig, bool nextImgVisible); + UILabelExt *SetUpLabel_Ext(LabelConfig &labelConfig); bool InitSoundAndVibrationScrollView(void); bool InitSoundAndVibrationViewTitleLabel(void); bool InitSoundAndVibrationButtonView(void); @@ -80,7 +92,12 @@ namespace OHOS UILabelButtonExt *CallVolumeButton{nullptr}; // 通话音量按钮 UILabelButtonExt *VibrationReminderButton{nullptr}; // 震动提醒按钮 UILabelButtonExt *SilentModeButton{nullptr}; // 静音模式按钮 + UILabelExt *SystemVolumeLabel{nullptr}; // 系统音量标签 + UILabelExt *CallVolumeLabel{nullptr}; // 通话音量标签 + UILabelExt *VibrationReminderLabel{nullptr}; // 震动提醒标签 + UILabelExt *SilentModeLabel{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 index 30eb50fe7..f3f398e0f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-19 10:08:21 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-19 19:01:46 + * @LastEditTime: 2024-07-24 16:35:52 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h */ #ifndef SOUND_AND_VIBRATION_VOLUME_SETTING_PRESENTER_H @@ -35,20 +35,26 @@ namespace OHOS */ class VoumeProcessSliderEventListener : public UISlider::UISliderEventListener, public UIView::OnClickListener, - public UIView::OnDragListener + public UIView::OnDragListener, + public UIView::OnRotateListener { public: VoumeProcessSliderEventListener(); ~VoumeProcessSliderEventListener(); static VoumeProcessSliderEventListener *GetInstance(void); + void FindAndApplyStrategy(uint8_t status, uint8_t value); void ChangeVolumeValue(uint8_t status, uint8_t value); 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; + bool OnRotateEnd(UIView& view, const RotateEvent& event); private: std::map> strategyMap; + bool isOnClickSlider{true}; + bool isDragSlider{false}; + bool isRotateSlider{false}; }; } 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 bc93bc85d..d05d2edbf 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumeView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/CallVolumeView.cpp @@ -67,6 +67,11 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CallVolumeView::OnStart"); View::OnStart(); SetContainerView(new UIViewGroup()); + if (GetContainer() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetContainerView fail!!"); + return; + } container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); container_->SetTouchable(true); container_->SetDraggable(true); 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 251303ec2..54c3c6dda 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-02-19 10:39:14 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-20 18:03:01 + * @LastEditTime: 2024-07-24 17:48:13 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationView.cpp */ #include "soundandvibration/include/SoundAndVibrationView.h" @@ -56,30 +56,45 @@ namespace OHOS container_ = nullptr; } - if (SoundAndVibrationScrollView[SOUNDANDVIBRATIONVIEW] != nullptr) + if (initViewStatus) { - SoundAndVibrationScrollView[SOUNDANDVIBRATIONVIEW]->RemoveAll(); + if (SoundAndVibrationScrollView[SOUNDANDVIBRATIONVIEW] != nullptr) + { + SoundAndVibrationScrollView[SOUNDANDVIBRATIONVIEW]->RemoveAll(); + + delete Title; + Title = nullptr; + + delete SystemVolumeButton; + SystemVolumeButton = nullptr; - delete Title; - Title = nullptr; + delete CallVolumeButton; + CallVolumeButton = nullptr; - delete SystemVolumeButton; - SystemVolumeButton = nullptr; + delete VibrationReminderButton; + VibrationReminderButton = nullptr; - delete CallVolumeButton; - CallVolumeButton = nullptr; + delete SilentModeButton; + SilentModeButton = nullptr; - delete VibrationReminderButton; - VibrationReminderButton = nullptr; + delete SilentModeToggleButton; + SilentModeToggleButton = nullptr; - delete SilentModeButton; - SilentModeButton = nullptr; + delete SystemVolumeLabel; + SystemVolumeLabel = nullptr; - delete SilentModeToggleButton; - SilentModeToggleButton = nullptr; + delete CallVolumeLabel; + CallVolumeLabel = nullptr; - delete SoundAndVibrationScrollView[SOUNDANDVIBRATIONVIEW]; - SoundAndVibrationScrollView[SOUNDANDVIBRATIONVIEW] = nullptr; + delete VibrationReminderLabel; + VibrationReminderLabel = nullptr; + + delete SilentModeLabel; + SilentModeLabel = nullptr; + + delete SoundAndVibrationScrollView[SOUNDANDVIBRATIONVIEW]; + SoundAndVibrationScrollView[SOUNDANDVIBRATIONVIEW] = nullptr; + } } if (vibrationModeView != nullptr) @@ -109,11 +124,31 @@ namespace OHOS SoundAndVibrationScrollView[SOUNDANDVIBRATIONVIEW]->SetThrowDrag(true); SoundAndVibrationScrollView[SOUNDANDVIBRATIONVIEW]->SetTouchable(true); SoundAndVibrationScrollView[SOUNDANDVIBRATIONVIEW]->SetDraggable(true); + SoundAndVibrationScrollView[SOUNDANDVIBRATIONVIEW]->RequestFocus(); + SoundAndVibrationScrollView[SOUNDANDVIBRATIONVIEW]->SetRotateFactor(2.0); container_->Add(SoundAndVibrationScrollView[SOUNDANDVIBRATIONVIEW]); return true; } + UILabelExt *SoundAndVibrationView::SetUpLabel_Ext(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->SetTextId(labelconfig.textId); + label->SetLineBreakMode(labelconfig.lineBreakMode); + label->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + label->SetRollSpeed(70); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); + return label; + } + /// @brief 声音与震动视图"标题"标签初始化 /// @param void /// @return true 初始化成功 false 初始化失败 @@ -125,15 +160,49 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::Title new fail!"); return false; } - Title->SetPosition(83, 52, 300, 35); + Title->SetPosition(83, 50, 300, 35); Title->SetStyle(STYLE_TEXT_FONT, 30); Title->SetStyle(STYLE_LINE_HEIGHT, 35); Title->SetTextId(STR_SOUND_AND_VIBRATION); // 声音与震动 - Title->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + Title->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + Title->SetRollSpeed(70); Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); SoundAndVibrationScrollView[SOUNDANDVIBRATIONVIEW]->Add(Title); - + /* -------------------------------------------------------------------------- */ + LabelConfig labelConfig; + struct LabelSetup + { + int16_t y; + const int16_t textId; + }; + LabelSetup labelSetups[] = { + {152, STR_SYSTEM_VOLUME}, + {272, STR_CALL_VOLUME}, + {392, STR_VIBRATION_MODE}, + {512, STR_SILENT_MODE}, + }; + UILabelExt *labelPointers[] = {SystemVolumeLabel, CallVolumeLabel, VibrationReminderLabel, SilentModeLabel}; + for (int i = 0; i < sizeof(labelSetups) / sizeof(labelSetups[0]); ++i) + { + labelConfig = { + .left = 90, + .top = labelSetups[i].y, + .width = 240, + .height = 35, + .fontSize = 30, + .lineHeigh = 35, + .textId = labelSetups[i].textId, + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, + }; + labelPointers[i] = SetUpLabel_Ext(labelConfig); + if (labelPointers[i] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::labelPointers[%d] new fail!", i); + return false; + } + SoundAndVibrationScrollView[SOUNDANDVIBRATIONVIEW]->Add(labelPointers[i]); + } return true; } @@ -156,12 +225,12 @@ namespace OHOS labelButton->SetImageSrc(PNG_SETTING_NEXT_IMAGE, PNG_SETTING_NEXT_IMAGE); labelButton->SetImagePosition(326, 37); } - labelButton->SetTextId(buttonconfig.TextId); - 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->SetTextId(buttonconfig.TextId); + // 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, nextImgVisible ? 0xff000000 : 0xff191919, UIButton::PRESSED); return labelButton; @@ -175,15 +244,15 @@ namespace OHOS { int y; const char *viewId; - const int16_t textId; bool clickEffect; }; ButtonSetup buttonSetups[] = { - {120, SYSTEM_VOLUME_BUTTON, STR_SYSTEM_VOLUME, true}, - {240, CALL_VOLUME_BUTTON, STR_CALL_VOLUME, true}, - {360, VIBRATION_REMINDER_BUTTON, STR_VIBRATION_MODE, true}, - {480, SILENT_MODE_BUTTON, STR_SILENT_MODE, false}}; + {120, SYSTEM_VOLUME_BUTTON, true}, + {240, CALL_VOLUME_BUTTON, true}, + {360, VIBRATION_REMINDER_BUTTON, true}, + {480, SILENT_MODE_BUTTON, false}, + }; UILabelButtonExt *buttonPointers[] = {SystemVolumeButton, CallVolumeButton, VibrationReminderButton, SilentModeButton}; @@ -195,7 +264,7 @@ namespace OHOS .w = 380, .h = 100, .ViewId = buttonSetups[i].viewId, - .TextId = buttonSetups[i].textId}; + }; buttonPointers[i] = SetUpButton_Ext(buttonconfig, buttonSetups[i].clickEffect); if (buttonPointers[i] == nullptr) { @@ -231,12 +300,13 @@ namespace OHOS void SoundAndVibrationView::CreateSoundAndVibrationView(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::CreateSoundAndVibrationView"); - if (!InitSoundAndVibrationScrollView() || !InitSoundAndVibrationViewTitleLabel() || - !InitSoundAndVibrationButtonView() || !InitSoundAndVibrationToggleButton()) + if (!InitSoundAndVibrationScrollView() || !InitSoundAndVibrationButtonView() || + !InitSoundAndVibrationViewTitleLabel() || !InitSoundAndVibrationToggleButton()) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::CreateSoundAndVibrationView fail!!"); return; } + initViewStatus = true; } void SoundAndVibrationView::OnStart() @@ -244,12 +314,20 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::OnStart"); View::OnStart(); SetContainerView(new UIViewGroup()); + if (GetContainer() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetContainerView fail!!"); + return; + } container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); container_->SetOnDragListener(presenter_); container_->SetTouchable(true); container_->SetDraggable(true); - CreateSoundAndVibrationView(); + if (!initViewStatus) + { + CreateSoundAndVibrationView(); + } RootView::GetInstance()->SetOnKeyActListener(presenter_); } @@ -334,11 +412,29 @@ namespace OHOS return false; } + /*检查传入的两个视图参数 hideView 和 showView 的有效性。*/ + bool SoundAndVibrationView::CheckViewParam(int16_t hideView, int16_t showView) + { + if (showView < 0 || showView >= MAX_SOUNDANDVIBRATIONVIEWID) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::CheckViewParam showView err."); + return false; + } + + if (hideView < 0 || hideView > MAX_SOUNDANDVIBRATIONVIEWID) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::CheckViewParam hideView err."); + return false; + } + + return true; + } + void SoundAndVibrationView::ChangeView(int16_t hideView, int16_t showView) { - if (hideView > MAX_SOUNDANDVIBRATIONVIEWID) + if (!CheckViewParam(hideView, showView)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " Overstep ones bounds"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::CheckViewParam failed."); return; } SoundAndVibrationScrollView[hideView]->SetVisible(false); @@ -353,7 +449,7 @@ namespace OHOS return vibrationModeView; } - //更新静音模式开关状态 + // 更新静音模式开关状态 bool SoundAndVibrationView::UpdateSilentModeSwitchStatus(void) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationView::UpdateSilentModeSwitchStatus"); diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp index bfd70a139..33636122b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-19 10:08:31 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-22 20:26:10 + * @LastEditTime: 2024-07-24 16:37:37 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp */ #include "soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h" @@ -87,7 +87,7 @@ namespace OHOS static VoumeProcessSliderEventListener *g_pVoumeProcessSliderEventListener{nullptr}; VoumeProcessSliderEventListener::VoumeProcessSliderEventListener() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::VoumeProcessSliderEventListener"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::VoumeProcessSliderEventListener"); // 步骤 3: 创建一个映射表将状态映射到策略 strategyMap[VOLUMEREDUCE] = std::make_shared(); strategyMap[VOLUMEADD] = std::make_shared(); @@ -97,7 +97,7 @@ namespace OHOS VoumeProcessSliderEventListener::~VoumeProcessSliderEventListener() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::~VoumeProcessSliderEventListener"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::~VoumeProcessSliderEventListener"); g_pVoumeProcessSliderEventListener = nullptr; } @@ -106,7 +106,7 @@ namespace OHOS return g_pVoumeProcessSliderEventListener; } - void VoumeProcessSliderEventListener::ChangeVolumeValue(uint8_t status, uint8_t value) + void VoumeProcessSliderEventListener::FindAndApplyStrategy(uint8_t status, uint8_t value) { auto it = strategyMap.find(status); if (it != strategyMap.end()) @@ -120,38 +120,97 @@ namespace OHOS } } + void VoumeProcessSliderEventListener::ChangeVolumeValue(uint8_t status, uint8_t value) + { + FindAndApplyStrategy(status, value); + + SoundAndVibrationVolumeSettingView *view = SoundAndVibrationVolumeSettingView::GetInstance(); + if (view) + { + if (view->GetVolumeType() == SYSTEM_VOLUME) + { + ConfigModel::GetInstance()->SetSystemVolume(value); + } + else if (view->GetVolumeType() == CALL_VOLUME) + { + ConfigModel::GetInstance()->SetCallVolume(value); + } + } + } + + // 滑块变化事件处理 void VoumeProcessSliderEventListener::OnChange(int32_t value) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnChange %d", value); - ChangeVolumeValue(OTHER, value); + if (isOnClickSlider && !isDragSlider && !isRotateSlider) + { + ChangeVolumeValue(OTHER, value); + } } + // 滑块释放事件处理 void VoumeProcessSliderEventListener::OnRelease(int32_t value) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnRelease %d", value); ChangeVolumeValue(OTHER, value); - - if ( SoundAndVibrationVolumeSettingView::GetInstance()->GetVolumeType() == SYSTEM_VOLUME) - { - ConfigModel::GetInstance()->SetSystemVolume(value); - } - else if (SoundAndVibrationVolumeSettingView::GetInstance()->GetVolumeType() == CALL_VOLUME) - { - ConfigModel::GetInstance()->SetCallVolume(value); - } } + // 滑块点击事件处理 bool VoumeProcessSliderEventListener::OnClick(UIView &view, const ClickEvent &event) { UNUSED(event); - UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::OnClick"); + UISlider *slider = dynamic_cast(&view); + SoundAndVibrationVolumeSettingView *soundAndVibrationVolumeSettingView = SoundAndVibrationVolumeSettingView::GetInstance(); + if (slider != nullptr && soundAndVibrationVolumeSettingView != nullptr) + { + if (slider == soundAndVibrationVolumeSettingView->GetVolumeProcess()) + { + isOnClickSlider = true; + isDragSlider = false; + isRotateSlider = false; + } + } return true; } + // 滑块拖动事件处理 bool VoumeProcessSliderEventListener::OnDrag(UIView &view, const DragEvent &event) { UNUSED(event); - UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::OnDrag"); + UISlider *slider = dynamic_cast(&view); + SoundAndVibrationVolumeSettingView *soundAndVibrationVolumeSettingView = SoundAndVibrationVolumeSettingView::GetInstance(); + if (slider != nullptr && soundAndVibrationVolumeSettingView != nullptr) + { + if (slider == soundAndVibrationVolumeSettingView->GetVolumeProcess()) + { + isOnClickSlider = false; + isDragSlider = true; + isRotateSlider = false; + } + } + return true; + } + + // 滑块旋转结束事件处理 + bool VoumeProcessSliderEventListener::OnRotateEnd(UIView &view, const RotateEvent &event) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::OnRotateEnd"); + UISlider *slider = dynamic_cast(&view); + SoundAndVibrationVolumeSettingView *soundAndVibrationVolumeSettingView = SoundAndVibrationVolumeSettingView::GetInstance(); + if (slider != nullptr && soundAndVibrationVolumeSettingView != nullptr) + { + if (slider == soundAndVibrationVolumeSettingView->GetVolumeProcess()) + { + isDragSlider = false; + isOnClickSlider = false; + isRotateSlider = true; + + int value = slider->GetValue(); + ChangeVolumeValue(OTHER, value); + } + } return true; } } 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 eea2125ba..f4254f40d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingView.cpp @@ -11,14 +11,14 @@ namespace OHOS SoundAndVibrationVolumeSettingView::SoundAndVibrationVolumeSettingView(uint8_t VolumeType) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationVolumeSettingView::SoundAndVibrationVolumeSettingView,VolumeType = %d", VolumeType); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationVolumeSettingView::SoundAndVibrationVolumeSettingView,VolumeType = %d", VolumeType); m_VolumeType = VolumeType; g_pSoundAndVibrationVolumeSettingView = this; } SoundAndVibrationVolumeSettingView::~SoundAndVibrationVolumeSettingView() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationVolumeSettingView::~SoundAndVibrationVolumeSettingView"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationVolumeSettingView::~SoundAndVibrationVolumeSettingView"); ClearAll(); g_pSoundAndVibrationVolumeSettingView = nullptr; } @@ -32,19 +32,27 @@ namespace OHOS { if (initViewStatus == true) { - ScrollView->RemoveAll(); - - delete VolumeProcess; - VolumeProcess = nullptr; - - delete VolumeVetor; - VolumeVetor = nullptr; - - delete listener; - listener = nullptr; - - delete ScrollView; - ScrollView = nullptr; + if (ScrollView != nullptr) + { + ScrollView->RemoveAll(); + if (VolumeProcess != nullptr) + { + delete VolumeProcess; + VolumeProcess = nullptr; + } + if (VolumeVetor != nullptr) + { + delete VolumeVetor; + VolumeVetor = nullptr; + } + if (listener != nullptr) + { + delete listener; + listener = nullptr; + } + delete ScrollView; + ScrollView = nullptr; + } } } @@ -96,6 +104,8 @@ namespace OHOS VolumeProcess->SetSliderColor(Color::GetColorFromRGBA(0x19, 0x19, 0x19, 0xff), Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); VolumeProcess->SetForegroundStyle(STYLE_BACKGROUND_OPA, 0xff); VolumeProcess->SetKnobStyle(StyleDefault::GetSliderKnobStyle()); + VolumeProcess->RequestFocus(); + VolumeProcess->SetRotateFactor(1.0); /* ------------------------------- VolumeVetor ------------------------------ */ VolumeVetor = new UIImageView(); if (VolumeVetor == nullptr) @@ -118,12 +128,12 @@ namespace OHOS VolumeProcess->SetSliderEventListener(listener); VolumeProcess->SetOnClickListener(listener); VolumeProcess->SetOnDragListener(listener); - VolumeProcess->SetKnobStyle(StyleDefault::GetSliderKnobStyle()); + VolumeProcess->SetOnRotateListener(listener); ScrollView->Add(VolumeProcess); ScrollView->Add(VolumeVetor); initViewStatus = true; - + return ScrollView; } 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 8b4a5674b..30db85266 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumeView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumeView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-12 11:44:04 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-19 18:21:36 + * @LastEditTime: 2024-07-23 16:58:58 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumeView.cpp */ #include "soundandvibration/include/SystemVolumeView.h" @@ -77,6 +77,11 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemVolumeView::OnStart"); View::OnStart(); SetContainerView(new UIViewGroup()); + if (GetContainer() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetContainerView fail!!"); + return; + } container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); container_->SetTouchable(true); container_->SetDraggable(true); diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/VibrationModeView.cpp b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/VibrationModeView.cpp index b5512d6a3..4cbd6c264 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/VibrationModeView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/VibrationModeView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-22 14:35:22 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-19 15:31:31 + * @LastEditTime: 2024-07-24 17:49:58 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/VibrationModeView.cpp */ #include "soundandvibration/include/VibrationModeView.h" @@ -14,7 +14,7 @@ namespace OHOS { - static constexpr uint8_t ROTATEFACTOR = 2; + static constexpr const float ROTATEFACTOR = 1.0; static VibrationModeView *g_pVibrationModeView{nullptr}; @@ -94,11 +94,12 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VibrationModeView::Title is nullptr!"); return nullptr; } - Title->SetPosition(93, 52, 280, 40); + Title->SetPosition(93, 50, 280, 40); Title->SetStyle(STYLE_TEXT_FONT, 30); Title->SetStyle(STYLE_LINE_HEIGHT, 35); Title->SetTextId(STR_VIBRATION_MODE); // 震动模式 - Title->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + Title->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + Title->SetRollSpeed(70); Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); scrollView->Add(Title); -- 2.17.1