From 0bd44c9f94459229cc0059e1622d42e42ff27297 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Thu, 20 Feb 2025 15:51:56 +0800 Subject: [PATCH] =?utf8?q?#1188=E6=8B=A8=E5=8F=B7=E7=9B=98=E9=A3=8E?= =?utf8?q?=E6=A0=BC=E6=BB=91=E5=8A=A8=E6=B2=A1=E6=9C=89=E6=83=AF=E6=80=A7?= =?utf8?q?=EF=BC=8C=E6=96=B9=E6=A1=88=E8=AF=B4=E5=90=8E=E7=BB=AD=E4=BC=98?= =?utf8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/applist/src/ApplistView.cpp | 136 ++++++++++++++---- 1 file changed, 111 insertions(+), 25 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistView.cpp b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistView.cpp index 1f4754958..968e85fec 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistView.cpp @@ -383,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 = 6; +static int angleIncrement = 10; // 圆形表的圆心坐标和半径 static const int CIRCLE_CENTER_X = 233; @@ -1272,6 +1272,7 @@ public: prepoint = convertToRelativeCoordinates(event.GetStartPoint()); preX = event.GetStartPoint().x; preY = event.GetStartPoint().y; + dragstartTimeStamp = event.GetTimeStamp(); return true; } @@ -1312,17 +1313,17 @@ public: isDirectRotateFlag = isDirectRotate(event);//获取是否是正向旋转的标志 } #endif - if(angle % 30 == 0) //不需要补偿角度 - { - OnDragEndFlag = 0; - } - else - { - OnDragEndFlag = 1; - } + dragendTimeStamp = event.GetTimeStamp(); + dragDuration = dragendTimeStamp - dragstartTimeStamp; + // OnDragEndFlag = (dragDuration >= 25 ? 1 : 0);//点击应用的时候容易产生滑动,小于25ms的屏蔽 + OnDragEndFlag = 1; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "dragDuration:%d,dragstartTimeStamp:%d,dragendTimeStamp:%d",dragDuration,dragstartTimeStamp,dragendTimeStamp); + int deltaX = abs(event.GetLastPoint().x - event.GetStartPoint().x); + int deltaY = abs(event.GetLastPoint().y - event.GetStartPoint().y); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "拖动时间:%d 毫秒,deltaX:%d,deltaY:%d",dragDuration,deltaX,deltaY); return true; } - +#if 0 void Notify() override { #if 0 @@ -1382,9 +1383,85 @@ public: return; #endif } +#endif + + void ResetState() + { + OnDragEndFlag = 0; + isInitialized = false; + inertiaDragAngle = 0; + if (isEncoderEvent) + { + angleIncrement = 10;//还原为drag的角度 + isEncoderEvent = false; + ui_api_vibrate_once_func(); + } + } + + void Notify() override + { + if (!OnDragEndFlag) { + return; // Early return if there's no drag end + } + static int targetAngle = 0;// 目标角度:就是等下惯性要滑多少角度 + static int timeIndex = 0; + + if(!isInitialized) { + isInitialized = true; + + // Define target angles based on drag duration + std::vector targetAngles = {0, 30, 60, 90, 150,180,210,240,270,300}; + // 根据滑动时间确定对应的目标角度索引 + uint32_t minDragDuration = 0; // 假设的最短滑动时间,单位:毫秒,可调整 + uint32_t maxDragDuration = 1400; // 假设的最长滑动时间,单位:毫秒,可调整 + + if (dragDuration < minDragDuration) { + // dragDuration = minDragDuration; // 时间过短,按最短时间处理,避免索引越界等问题 + } else if (dragDuration > maxDragDuration) { + dragDuration = maxDragDuration; // 时间过长,按最长时间处理 + } + uint32_t durationRange = maxDragDuration - minDragDuration; + + + // Calculate the target angle index + timeIndex = (dragDuration) / (durationRange / targetAngles.size()); + timeIndex = std::min(timeIndex, static_cast(targetAngles.size() - 1)); // 防止越界 + targetAngle = targetAngles[timeIndex]; + } + + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "拖动时间:%d 毫秒,当前角度:%d,目标角度:%d,时间索引:%d", dragDuration, angle, targetAngle, timeIndex); + // 根据旋转方向确定角度增量的正负以及计算角度增量大小 + int angleIncrementSign = isDirectRotateFlag ? 1 : -1; + + if(targetAngle != 0) { + if(inertiaDragAngle != targetAngle) { + angle += (angleIncrementSign * angleIncrement); + inertiaDragAngle += abs(angleIncrementSign * angleIncrement); + } else if(inertiaDragAngle == targetAngle && angle % 30 != 0) { + angle += (angleIncrementSign * angleIncrement); //还要再次补充角度 + } else if(inertiaDragAngle == targetAngle && angle % 30 == 0) { + // Reset state when target angle is reached + ResetState(); + return; + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "inertiaDragAngle:%d,angle:%d",inertiaDragAngle,angle); + // 调用视图更新函数,实时更新界面显示 + native_app_position_update(CircleListAPP, CircleListAPPNum, CircleListSelectImage, angle, isDirectRotateFlag); + } else { + if(angle % 30 == 0) { + ResetState(); + } else { + angle += (isDirectRotateFlag? angleIncrement : -angleIncrement); + native_app_position_update(CircleListAPP,CircleListAPPNum,CircleListSelectImage,angle,isDirectRotateFlag); + } + } + return; + } bool OnRotateStart(UIView& view, const RotateEvent& event) { + angleIncrement = 15; + preRotateAngle = angle; return false; } @@ -1410,30 +1487,32 @@ public: 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(); - } + // 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) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AppCircleListOnDragListener::OnRotateEnd %d",event.GetRotate()); - if(angle % 30 == 0) //不需要补偿角度 - { - OnDragEndFlag = 0; - } - else - { + if(angle % 30 == 0) { + angleIncrement = 10; //还原为drag的角度 + OnDragEndFlag = 0; //不需要补偿角度 + if(preRotateAngle != angle) { + ui_api_vibrate_once_func(); + } + } else { OnDragEndFlag = 1; } RotateReportedCount = 0; rotateangle = 0; + dragDuration = 0; return false; } @@ -1451,6 +1530,13 @@ public: bool isEncoderEvent{false}; //是否为编码器事件 bool isDragEvent{false}; //是否为拖拽事件 int RotateReportedCount{0}; + + uint32_t dragstartTimeStamp{0}; //开始拖拽时的时间戳 + uint32_t dragendTimeStamp{0}; //拖拽结束时的时间戳 + uint32_t dragDuration{0}; //拖拽时间 + int inertiaDragAngle{0}; //惯性拖拽角度 + bool isInitialized {false}; + int preRotateAngle{0}; }; void ApplistView::CircleListStyleOnStart(void) @@ -1510,7 +1596,7 @@ void ApplistView::CircleListStyleOnStart(void) CircleListScrollView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); CircleListScrollView->SetStyle(STYLE_BACKGROUND_OPA, 0x00); CircleListScrollView->SetStyle(STYLE_BORDER_RADIUS, 150); - CircleListScrollView->SetRotateFactor(1.0); + CircleListScrollView->SetRotateFactor(30.0); CircleListScrollView->RequestFocus(); CircleListGroup_->Add(CircleListScrollView); } -- 2.17.1