解决#1189拨号盘风格,编码器旋转震动一次跳两个图标。旋转一个图标不会震动bug
authorluozheng <1732036298@qq.com>
Fri, 22 Nov 2024 10:01:29 +0000 (18:01 +0800)
committerluozheng <1732036298@qq.com>
Fri, 22 Nov 2024 10:01:29 +0000 (18:01 +0800)
code/sdk/application/wearable/fd230app/nativeui/applist/include/ApplistView.h
code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistView.cpp

index e957f26..f2024da 100644 (file)
@@ -166,6 +166,7 @@ private:
     UIImageView * PointImage{nullptr};
     UIImageView * CircleListSelectImage{nullptr};
     UIPicker * CircleListPicker{nullptr};
+    UIScrollView * CircleListScrollView{nullptr};
     int CircleListAPPNum{0};
 };
 }
index 5772aeb..9afda89 100644 (file)
@@ -14,6 +14,7 @@
 #include "themestyle/include/ThemeStyleModel.h"
 #include "ModelListenerSample.h"
 #include "cmath"
+#include "../../../../../../drivers/peripheral/vibrator/service/vibrator_service.h"
 
 namespace OHOS {
 static constexpr int16 NUM_2 = 2;
@@ -113,6 +114,11 @@ ApplistView::~ApplistView()
         delete CircleListPicker;
         CircleListPicker = nullptr;
     }
+    if(CircleListScrollView)
+    {
+        delete CircleListScrollView;
+        CircleListScrollView = nullptr;
+    }
     for(int i = 0;i < CircleListAPPNum;i++)
     {
         if(nullptr != CircleListAPP[i])
@@ -377,7 +383,7 @@ static const double PI_OVER_180 = M_PI / 180.0;         // 180度对应的弧度
 static const int native_big_app_size = 90;              //大图标
 static const int native_small_app_size = 72;            //小图标
 static int native_app_position_update_startflag = 0;    //native_app_position_update函数开始更新的标志位
-static constexpr int angleIncrement = 5;
+static constexpr int angleIncrement = 6;
 
 // 圆形表的圆心坐标和半径
 static const int CIRCLE_CENTER_X = 233;
@@ -1266,6 +1272,9 @@ public:
 
     bool OnDrag(UIView& view, const DragEvent& event) override
     {
+        isEncoderEvent = false;
+        isDragEvent = true;
+
         int curX = event.GetCurrentPos().x;
         int curY = event.GetCurrentPos().y;
         int deltaX = abs(curX - preX);
@@ -1332,6 +1341,11 @@ public:
             if(angle % 30 == 0) //不需要补偿角度
             {
                 OnDragEndFlag = 0;
+                if(isEncoderEvent) {
+                    isEncoderEvent = false;
+                    WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "震动一次");
+                    ui_api_vibrate_once_func();
+                }
             }
             else
             {
@@ -1364,22 +1378,41 @@ public:
 #endif
     }
 
+    bool OnRotateStart(UIView& view, const RotateEvent& event)
+    {
+        return false;
+    }
+
     bool OnRotate(UIView& view, const RotateEvent& event)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AppCircleListOnDragListener::OnRotate %d",event.GetRotate());
-        if(event.GetRotate() > 0)
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnRotate回调次数%d",++RotateReportedCount);
+        isEncoderEvent = true;
+        isDragEvent = false;
+        if(RotateReportedCount > 4) 
         {
-            isDirectRotateFlag = true;
-            angle += angleIncrement;
-            native_app_position_update(CircleListAPP,CircleListAPPNum,CircleListSelectImage,angle,isDirectRotateFlag);
-        }
-        else
-        {
-            isDirectRotateFlag = false;
-            angle -= angleIncrement;
-            native_app_position_update(CircleListAPP,CircleListAPPNum,CircleListSelectImage,angle,isDirectRotateFlag);
+            if(event.GetRotate() > 0)
+            {
+                isDirectRotateFlag = true;
+                angle += angleIncrement;
+                native_app_position_update(CircleListAPP,CircleListAPPNum,CircleListSelectImage,angle,isDirectRotateFlag);
+            }
+            else
+            {
+                isDirectRotateFlag = false;
+                angle -= angleIncrement;
+                native_app_position_update(CircleListAPP,CircleListAPPNum,CircleListSelectImage,angle,isDirectRotateFlag);
+            }
+
+            rotateangle += angleIncrement;
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "rotateangle:%d",rotateangle);
+            if(rotateangle >= 30 || rotateangle <= -30)
+            {
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "震动一次");
+                rotateangle = 0;
+                ui_api_vibrate_once_func();
+            }
         }
-        
         return false;
     }
     bool OnRotateEnd(UIView& view, const RotateEvent& event)
@@ -1393,6 +1426,8 @@ public:
         {
             OnDragEndFlag = 1;
         }
+        RotateReportedCount = 0;
+        rotateangle = 0;
         return false;
     }
 
@@ -1406,6 +1441,10 @@ public:
         bool isDirectRotateFlag{false};                 //是否是正向旋转的标志
         int preX{0}; 
         int preY{0};
+
+        bool isEncoderEvent{false};                     //是否为编码器事件                
+        bool isDragEvent{false};                        //是否为拖拽事件
+        int RotateReportedCount{0};
 };
 
 void ApplistView::CircleListStyleOnStart(void)
@@ -1450,7 +1489,24 @@ void ApplistView::CircleListStyleOnStart(void)
             int end = 3;
             CircleListPicker->SetValues(start,end);
             // printf("---%d\n",CircleListPicker->GetSelected());
-            CircleListGroup_->Add(CircleListPicker);
+            // CircleListGroup_->Add(CircleListPicker);
+        }
+        /* -------------------------------------------------------------------------- */
+        if(CircleListScrollView == nullptr)
+        {
+            CircleListScrollView = new UIScrollView();
+            if(nullptr == CircleListScrollView)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApplistView::CircleListScrollView failed!! [%d]", __LINE__);
+                return;
+            }
+            CircleListScrollView->SetPosition(213, 213, 40, 40);
+            CircleListScrollView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);
+            CircleListScrollView->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
+            CircleListScrollView->SetStyle(STYLE_BORDER_RADIUS, 150);
+            CircleListScrollView->SetRotateFactor(1.0);
+            CircleListScrollView->RequestFocus();
+            CircleListGroup_->Add(CircleListScrollView);
         }
         /* -------------------------------------------------------------------------- */
         // if(CircleListImage1 == nullptr)
@@ -1562,7 +1618,7 @@ void ApplistView::CircleListStyleOnStart(void)
             }
         }
         CircleListGroup_->SetOnDragListener(static_cast<UIView::OnDragListener*>(AppCircleListOnDragListener_));
-        CircleListPicker->SetOnRotateListener(static_cast<UIView::OnRotateListener *>(AppCircleListOnDragListener_));
+        CircleListScrollView->SetOnRotateListener(static_cast<UIView::OnRotateListener *>(AppCircleListOnDragListener_));
         /* -------------------------------------------------------------------------- */
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApplistView::CircleListStyleOnStart success!! [%d]", __LINE__);
     }