声音与震动视图的系统音量已经可以调节系统
authorluozheng <1732036298@qq.com>
Thu, 14 Mar 2024 03:50:23 +0000 (11:50 +0800)
committerluozheng <1732036298@qq.com>
Thu, 14 Mar 2024 03:50:23 +0000 (11:50 +0800)
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumeView.h
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumePresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumeView.cpp

index 4a72e8f..b057643 100644 (file)
@@ -24,11 +24,14 @@ namespace OHOS
         void OnTearDownView() override;\r
         void OnStop() override;\r
 \r
-        UIScrollView * SystemVolumeViewInit(void);\r
+        UIScrollView *SystemVolumeViewInit(void);\r
+        void ClearAll();\r
 \r
     private:\r
         UIScrollView *SystemVolumeScrollView{nullptr};\r
         SoundAndVibrationVolumeSettingView *p_SoundAndVibrationVolumeSettingView{nullptr};\r
+        UIView::OnDragListener *volumeDragListener{nullptr};\r
+        bool initViewStatus{false};\r
     };\r
 } // namespace OHOS\r
 \r
index 31d1ee3..cd2beb8 100644 (file)
@@ -56,9 +56,9 @@ namespace OHOS
 \r
     bool SystemVolumePresenter::OnDrag(UIView &view, const DragEvent &event)\r
     {\r
-\r
+        UNUSED(view);\r
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT &&\r
-            (event.GetDeltaX() > 30) && (event.GetDeltaX() > (3 * MATH_ABS(event.GetDeltaY()))))\r
+            (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY()))))\r
         {\r
             // NativeAbility::GetInstance().ChangeSlice(VIEW_SOUND_VIBRATION);\r
             uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();\r
@@ -69,13 +69,8 @@ namespace OHOS
 \r
     bool SystemVolumePresenter::OnClick(UIView &view, const ClickEvent &event)\r
     {\r
-\r
-        // 根据控件id查找是哪个控件触发了点击回调\r
-        // if (strcmp(view.GetViewId(), 控件ID) == 0)\r
-        // if(strcmp(view.GetViewId(), BRIGHTNESS_CONTROL_SLIDER))\r
-        // {\r
-\r
-        // }\r
+        UNUSED(view);\r
+        UNUSED(event);\r
         return true;\r
     }\r
 \r
index 2ff1653..2e9f089 100644 (file)
@@ -1,6 +1,7 @@
 #include "soundandvibration/include/SystemVolumeView.h"\r
 #include "soundandvibration/include/SystemVolumePresenter.h"\r
 #include "wearable_log.h"\r
+#include <audio_manager.h>\r
 /*\r
 系统音量:\r
 通话,提醒,查找手表的音量\r
@@ -13,20 +14,34 @@ namespace OHOS
 \r
     SystemVolumeView::SystemVolumeView()\r
     {\r
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemVolumeView::SystemVolumeView");\r
         g_pSystemVolumeView = this;\r
     }\r
 \r
     SystemVolumeView::~SystemVolumeView()\r
     {\r
-        delete p_SoundAndVibrationVolumeSettingView;\r
-        p_SoundAndVibrationVolumeSettingView = nullptr;\r
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemVolumeView::~SystemVolumeView");\r
+        ClearAll();\r
+        g_pSystemVolumeView = nullptr;\r
     }\r
 \r
     SystemVolumeView *SystemVolumeView::GetInstance()\r
     {\r
-\r
         return g_pSystemVolumeView;\r
     }\r
+\r
+    void SystemVolumeView::ClearAll()\r
+    {\r
+        if (initViewStatus == true)\r
+        {\r
+            delete volumeDragListener;\r
+            volumeDragListener = nullptr;\r
+\r
+            delete p_SoundAndVibrationVolumeSettingView;\r
+            p_SoundAndVibrationVolumeSettingView = nullptr;\r
+        }\r
+    }\r
+\r
     UIScrollView *SystemVolumeView::SystemVolumeViewInit(void)\r
     {\r
         p_SoundAndVibrationVolumeSettingView = new SoundAndVibrationVolumeSettingView();\r
@@ -42,6 +57,22 @@ namespace OHOS
             return nullptr;\r
         }\r
 \r
+        volumeDragListener = static_cast<UIView::OnDragListener *>(SystemVolumePresenter::GetInstance());\r
+        if (volumeDragListener == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RecordingPresenter GetInstance fail");\r
+            return nullptr;\r
+        }\r
+        SystemVolumeScrollView->SetOnDragListener(volumeDragListener);\r
+        if (SystemVolumeScrollView == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_SoundAndVibrationVolumeSettingView->SetUpVolumeProcess fail!!");\r
+            return nullptr;\r
+        }\r
+\r
+        p_SoundAndVibrationVolumeSettingView->GetVolumeProcess()->SetValue(Audio::AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC));\r
+\r
+        initViewStatus = true;\r
         return SystemVolumeScrollView;\r
     }\r
 \r