1.解决slider和scrollview旋转编码器一直震动问题
authorluozheng <1732036298@qq.com>
Fri, 27 Sep 2024 07:53:52 +0000 (15:53 +0800)
committerluozheng <1732036298@qq.com>
Fri, 27 Sep 2024 07:53:52 +0000 (15:53 +0800)
2.解决slider旋转编码器方向是反的问题
3.slider添加旋转结束监听,结束后震动一次(受设置中震动强度影响)

code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/BrightnessControlView.h
code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/BrightnessControlView.cpp
code/sdk/application/wearable/fd230app/nativeui/main/src/VolumeSettingPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp
code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_scroll_view.cpp
code/sdk/middleware/services/gui/uikit/ui/frameworks/components/ui_slider.cpp

index f03208a..711250a 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com\r
  * @Date: 2024-01-29 15:37:44\r
  * @LastEditors: luozheng 1732036298@qq.com\r
- * @LastEditTime: 2024-04-18 14:52:47\r
+ * @LastEditTime: 2024-09-27 15:07:34\r
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/BrightnessControlView.h\r
  */\r
 #ifndef BRIGHTNESS_CONTROL_VIEW_H\r
@@ -33,7 +33,8 @@ namespace OHOS
     static const char *BRIGHTNESS_CONTROL_SLIDER = "BrightnessControlViewSlider";\r
     class BrightnessSliderEventListener : public UISlider::UISliderEventListener,\r
                                           public UIView::OnClickListener,\r
-                                          public UIView::OnDragListener\r
+                                          public UIView::OnDragListener,\r
+                                          public UIView::OnRotateListener\r
     {\r
     public:\r
         BrightnessSliderEventListener();\r
@@ -44,6 +45,7 @@ namespace OHOS
         void OnRelease(int32_t value) override;\r
         bool OnClick(UIView &view, const ClickEvent &event) override;\r
         bool OnDrag(UIView &view, const DragEvent &event) override;\r
+        bool OnRotateEnd(UIView& view, const RotateEvent& event);\r
 \r
     private:\r
         std::map<uint8_t, std::shared_ptr<BrightnessChangeStrategy>> strategyMap;\r
index 35515ff..1ae94dd 100644 (file)
@@ -6,6 +6,7 @@
 #include "ConfigModel.h"\r
 #include "map"\r
 #include "iostream"\r
+#include "vibrator_service.h"\r
 namespace OHOS\r
 {\r
     static BrightnessControlView *g_pBrightnessControlView{nullptr};\r
@@ -99,6 +100,7 @@ namespace OHOS
         BrightnessControlViewSlider->SetSliderEventListener(rawPointer);\r
         BrightnessControlViewSlider->SetOnClickListener(rawPointer);\r
         BrightnessControlViewSlider->SetOnDragListener(rawPointer);\r
+        BrightnessControlViewSlider->SetOnRotateListener(rawPointer);\r
         BrightnessControlViewSlider->SetKnobStyle(StyleDefault::GetSliderKnobStyle());\r
         return true;\r
     }\r
@@ -291,4 +293,11 @@ namespace OHOS
         UNUSED(view);\r
         return true;\r
     }\r
+\r
+    bool BrightnessSliderEventListener::OnRotateEnd(UIView& view, const RotateEvent& event)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnRotateEnd %d", value);\r
+        ui_api_vibrate_once_func();//受设置中震动强度控制\r
+        return true;\r
+    }\r
 }\r
index 89b71bc..6353de1 100644 (file)
@@ -19,6 +19,7 @@
 #include "BluetoothHeadsetEvent.h"
 #include "bts_avrcp_controller.h"
 #include "ConfigModel.h"
+#include "vibrator_service.h"
 
 namespace OHOS {
 
@@ -173,6 +174,7 @@ bool VolumeSliderEventListener::OnRotateEnd(UIView& view, const RotateEvent& eve
         if (slider == progress)
         {
             ChangeVolume(VOLUMEDRAG);
+            ui_api_vibrate_once_func();//受设置中震动强度控制
         }
     }
     return true;
index 954a2b7..76d63fa 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-19 10:08:21
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-09-06 14:11:01
+ * @LastEditTime: 2024-09-27 14:16:52
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h
  */
 #ifndef SOUND_AND_VIBRATION_VOLUME_SETTING_PRESENTER_H
@@ -48,6 +48,7 @@ namespace OHOS
         void OnRelease(int32_t value) override;
         bool OnClick(UIView &view, const ClickEvent &event) override;
         bool OnDrag(UIView &view, const DragEvent &event) override;
+        bool OnRotate(UIView& view, const RotateEvent& event);
         bool OnRotateEnd(UIView& view, const RotateEvent& event);
 
     private:
index eda49f1..863643b 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-19 10:08:31
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-09-14 18:27:21
+ * @LastEditTime: 2024-09-27 15:08:56
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationVolumeSettingPresenter.cpp
  */
 #include "soundandvibration/include/SoundAndVibrationVolumeSettingPresenter.h"
@@ -15,6 +15,7 @@
 #include "../../../../../../middleware/services/media/foundation/audiomanager/frameworks/audioservice/include/audio_service.h"
 #include "vibrator_service.h"
 #include "ConfigModel.h"
+#include <custom_runtime.h>
 
 namespace OHOS
 {
@@ -181,9 +182,9 @@ namespace OHOS
     }
 
     // 滑块旋转结束事件处理
-    bool VoumeProcessSliderEventListener::OnRotateEnd(UIView &view, const RotateEvent &event)
+    bool VoumeProcessSliderEventListener::OnRotate(UIView &view, const RotateEvent &event)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::OnRotateEnd");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::OnRotate,%d",event.GetRotate());
         UISlider *slider = dynamic_cast<UISlider *>(&view);
         SoundAndVibrationVolumeSettingView *soundAndVibrationVolumeSettingView = SoundAndVibrationVolumeSettingView::GetInstance();
         if (slider != nullptr && soundAndVibrationVolumeSettingView != nullptr)
@@ -200,6 +201,12 @@ namespace OHOS
         }
         return true;
     }
+    bool VoumeProcessSliderEventListener::OnRotateEnd(UIView& view, const RotateEvent& event)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "VoumeProcessSliderEventListener::OnRotateEnd,%d",event.GetRotate());
+        ui_api_vibrate_once_func();//受设置中震动强度控制
+        return true;
+    }
 }
 #ifdef __cplusplus
 #if __cplusplus
index ebfa86a..1735310 100755 (executable)
@@ -139,14 +139,14 @@ bool UIScrollView::OnRotateEvent(const RotateEvent& event)
             uint16_t vibrationCnt = rotateLen / DEFAULT_SCROLL_VIEW_VIBRATION_LEN;
             for (uint16_t i = 0; i < vibrationCnt; i++) {
                 GRAPHIC_LOGI("UIScrollView::OnRotateEvent calls TYPE_ONE vibrator");
-                vibratorFunc(VibratorType::VIBRATOR_TYPE_ONE);
+                // vibratorFunc(VibratorType::VIBRATOR_TYPE_ONE);
             }
             lastVibratorRotateLen_ = totalRotateLen_;
         }
     }
     if (vibratorFunc != nullptr && (!lastIsEdge && isEdge)) {
         GRAPHIC_LOGI("UIScrollView::OnRotateEvent calls TYPE_THREE vibrator");
-        vibratorFunc(VibratorType::VIBRATOR_TYPE_THREE);
+        // vibratorFunc(VibratorType::VIBRATOR_TYPE_THREE);
     }
 #endif
     return UIView::OnRotateEvent(event);
index 98c5720..7833ee8 100755 (executable)
@@ -363,7 +363,9 @@ bool UISlider::OnDragEndEvent(const DragEvent& event)
 bool UISlider::OnRotateEvent(const RotateEvent& event)
 {
     int32_t realRotation = 0;
-    cachedRotation_ += event.GetRotate() * rotateFactor_;
+    int16_t invertedRotate = -event.GetRotate();//对旋转量取反
+    cachedRotation_ += invertedRotate * rotateFactor_;
+    // cachedRotation_ += event.GetRotate() * rotateFactor_;
     realRotation = static_cast<int32_t>(cachedRotation_);
     if (realRotation == 0) {
         return UIView::OnRotateEvent(event);
@@ -381,12 +383,12 @@ bool UISlider::OnRotateEvent(const RotateEvent& event)
     if (vibratorFunc != nullptr && lastValue != curValue_) {
         if (curValue_ == rangeMin_ || curValue_ == rangeMax_) {
             GRAPHIC_LOGI("UISlider::OnRotateEvent calls TYPE_THREE vibrator");
-            vibratorFunc(VibratorType::VIBRATOR_TYPE_THREE);
+            // vibratorFunc(VibratorType::VIBRATOR_TYPE_THREE);
         } else {
             int32_t changedValue = MATH_ABS(curValue_ - lastValue);
             for (int32_t i = 0; i < changedValue; i++) {
                 GRAPHIC_LOGI("UISlider::OnRotateEvent calls TYPE_TWO vibrator");
-                vibratorFunc(VibratorType::VIBRATOR_TYPE_TWO);
+                // vibratorFunc(VibratorType::VIBRATOR_TYPE_TWO);
             }
         }
     }